﻿var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F5b1276396990328a615e6c905324abca' type='text/javascript'%3E%3C/script%3E"));

_GDomainName = "http://www.xiaohuasheng.cn/";
_GSuffixName = ".html";

function GGetViewUrl(AViewId)
{
    return _GDomainName + "view_" + AViewId + _GSuffixName;
}

function GGetModifyViewUrl(AViewId)
{
    return _GDomainName + "modifyview_" + AViewId + _GSuffixName;
}

function GGetSubjectUrl(ASubjectId)
{
    return _GDomainName + "subject_" + ASubjectId + _GSuffixName;
}

function GGetClubUrl(AClubId, AType)
{
    return _GDomainName + "club_" + AClubId + "_" + AType + _GSuffixName;
}

function GGetEventUrl(AEventId)
{
    return _GDomainName + "event_" + AEventId + _GSuffixName;
}

function GGetEssayUrl(AEssayId, AClubId)
{
    return _GDomainName + "essay_" + AEssayId + "_" + AClubId + _GSuffixName;
}

function GGetOtherSpaceUrl(AUserId)
{
    return _GDomainName + "otherspace_" + AUserId + _GSuffixName;
}

//获取教育专题
function GetUrlEducation() 
{
    return "http://www.xiaohuasheng.cn/subject_82" + _GSuffixName;
}

//获取花生杂谈专题
function GetUrlPeanut() 
{
    return "http://www.xiaohuasheng.cn/subject_27" + _GSuffixName;
}

//字符串格式化方法
String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}


$.extend({
    //分页方法
    ChangePage: function(Aallrecords, Acurrentno, ApageCount, ACallBack) {
        $("#Pagination").pagination(Aallrecords, {
            callback: ACallBack,
            prev_text: '上一页',
            next_text: '下一页',
            items_per_page: ApageCount,
            num_display_entries: 6,
            current_page: Acurrentno,
            link_to: "#",
            num_edge_entries: 2
        });
    },
    //全选方法(AStrikeId-触发全选的checkbox的标签id，ASelectClass-需要全选的checkbox的类名)
    CheckAll: function(AStrikeId, ASelectClass) {
        if ($("#" + AStrikeId).attr("checked") == true) {
            $("." + ASelectClass).attr("checked", true);
        }
        else {
            $("." + ASelectClass).attr("checked", false);
        }
    },
    // 获取Check框选中的内容
    // AType-操作类型(-1-所有,相应操作对应的值)
    // ContainItermsId-包含容器的id
    // AActionId-操作项的标签名
    GetSelectIterms: function(AType, ContainItermsId, AActionId) {
        var vSelectIterms = "";
        $("#" + ContainItermsId + " input:checkbox:checked").each(
                               function() {
                                   if (AType == -1) {
                                       vSelectIterms += this.value + ",";
                                   } else {
                                       if ($.trim($("#" + AActionId + this.value).html()) == AType) {
                                           vSelectIterms += this.value + ",";
                                       }
                                   }
                               });
        return vSelectIterms.length == 0 ? "" : vSelectIterms.substring(0, vSelectIterms.length - 1);
    },
    //灯箱(编辑图片)
    EditPicture: function(AClassId, AhrefId, AWidth) {
        $("#cb_ViewOrEdit").attr("href", "stylesheets/colorbox.css");
        $("." + AClassId).colorbox({
            width: AWidth,
            inline: true,
            href: AhrefId,
            overlayClose: false,
            close: "close",
            opacity: 0,
            transition: "elastic",
            scrolling: false
        });
    },
    //灯箱(查看图片)
    ViewPicture: function(ARel) {
        $("#cb_ViewOrEdit").attr("href", "stylesheets/ViewPicture.css");
        $("a[rel='" + ARel + "']").colorbox({
            overlayClose: false,
            transition: 'elastic',
            speed: 100,
            current: "图片 {current} 共 {total}"
        });
    },
    //从指定字符出截取字符串
    GetAppointString: function(AContent, AAppointStr) {
        var GetAppointStrIndex = AContent.lastIndexOf(AAppointStr) + 1;
        var GetSubStr = AContent.substring(GetAppointStrIndex);
        var GetSubContent = GetSubStr.split('.');
        return GetSubContent[0];
    },
    //弹出层
    alertlayer: function(title, width, height, VcontentHtml) {
        var vwidth = width - 40;
        //标题栏
        var vTitleHtml = "<table>\
                            <tr>\
                                <td id='StyleTitle'>\
                                <div style='background-color:#EBF5EB;\
                                      text-align:left;\
                                      padding:10px 8px 5px 8px;\
                                      margin:0px;\
                                      font-size: 10.5pt;\
                                      width:" + vwidth + "px;\
                                      height;25px;\
                                      color:#C00000;'>" + title + "</div>\
                                </td>\
                            </tr>\
                            <tr>\
                                <td>" + VcontentHtml + "</td>\
                            </tr>\
                     </table>";
        $("#Modify_ClubPicEdit").html(vTitleHtml);
        $("#cb_ViewOrEdit").attr("href", "stylesheets/colorbox.css");
        $(".Edit_ClibPic").colorbox({
            width: width + 'px',
            height: height + 'px',
            inline: true,
            href: "#Modify_ClubPicEdit",
            overlayClose: false,
            close: "close",
            opacity: 0,
            transition: "none"
        });
    },
    //编辑框（elelm-调用对象，width-弹出框宽度，hight-弹出框高度，VcontentHtml-弹出框内部html）
    EditBox: function(elem, title, width, height, VcontentHtml) {
        var vwidth = width - 40;
        //标题栏
        var vTitleHtml = "<table>\
                            <tr>\
                                <td id='StyleTitle'>\
                                <div style='background-color:#EBF5EB;\
                                      text-align:left;\
                                      padding:10px 8px 5px 8px;\
                                      margin:0px;\
                                      font-size: 10.5pt;\
                                      width:" + vwidth + "px;\
                                      height;25px;\
                                      color:#C00000;'>" + title + "</div>\
                                </td>\
                            </tr>\
                            <tr>\
                                <td>" + VcontentHtml + "</td>\
                            </tr>\
                     </table>";
        $("#Modify_ClubPicEdit").html(vTitleHtml);
        PicLoadCss("stylesheets/colorbox");
        $(elem).colorbox({
            width: width + 'px',
            height: height + 'px',
            inline: true,
            href: "#Modify_ClubPicEdit",
            overlayClose: false,
            close: "close",
            opacity: 0,
            transition: "none"
        });
    },
    //展开和收起内容
    ShowAll: function(Aid) {
        var vShowState = $.trim($("#ShowState" + Aid).html());
        if (vShowState == 0) {
            $("#AllPic" + Aid).css("display", "block");
            $("#PartPic" + Aid).css("display", "none");
            $("#imgShowAll" + Aid).attr("src", "images/arrow2_1.PNG");
            $("#imgShowAll" + Aid).attr("title", "收起");
            $("#ShowState" + Aid).html(1);
        }
        else {
            $("#AllPic" + Aid).css("display", "none");
            $("#PartPic" + Aid).css("display", "block");
            $("#imgShowAll" + Aid).attr("src", "images/arrow3.PNG");
            $("#imgShowAll" + Aid).attr("title", "展开全文");
            $("#ShowState" + Aid).html(0);
        }
    },
    // 获取用户空间链接
    GetUserSpaceUrl: function(AUserId) {
        if (FUserId == AUserId) {
            return "MySpace.aspx";
        }

        return GGetOtherSpaceUrl(AUserId);
    }
});

function PicLoadCss(file) {
    var cssTag = document.getElementById('cb_ViewOrEdit');
    var head = document.getElementsByTagName('head').item(0);
    if (cssTag) head.removeChild(cssTag);
    css = document.createElement('link');
    css.href = file + ".css";
    css.rel = 'stylesheet';
    css.type = 'text/css';
    css.id = 'cb_ViewOrEdit';
    head.appendChild(css);
}

//登录验证
function JudgeLogin(AuserId, Aurl) {
    if (arguments.length == 1) {
        return JudgeLoginNoUrl.apply(this, arguments);
    }
    else {
        return JudgeLoginContainUrl.apply(this, arguments);
    }
    return false;
}

//不含Url的登录验证
function JudgeLoginNoUrl(AUserId) {
    if (AUserId == -1) {
        alertLoginWin("登录小花生", 320, 300);
        return false;
    }
    return true;
}

//包含url的登录验证
function JudgeLoginContainUrl(AuserId, Aurl) {
    if (AuserId == -1) {
        alertLoginWin("登录小花生", 320, 300);
        return false;
    }
    window.location.href = encodeURI(Aurl);
    return true;
}

//判断俱乐部管理员能进行的操作
function JudgePrivilegeClubUser(AIsClubAdmin) {
    if (AIsClubAdmin == 1) {
        alert("对不起，你暂时没有这个权限");
        return false;
    }
    return true;
}

//搜索不能为空
function JudgeSearchEmpty(content) {
    if ($.trim(content).length == 0 || $.trim(content) == "") {
        alert("请填写搜索对象");
        return false;
    }
    return true;
}

//搜索体验
function SearchExp() {
    var vcontent = $("#txtSearchSubContent").val();
    if (!JudgeSearchEmpty(vcontent)) {
        return;
    }
    document.location.href = encodeURI("ViewSearch.aspx?Content=" + vcontent + "&InputKeyword=1");
}

//搜索主题
function SearchSub(AType, AContent) {
    if (arguments.length == 1) {
        var vcontent = $("#txtSearchSubContent").val();
        if (!JudgeSearchEmpty(vcontent)) {
            return;
        }
        document.location.href = encodeURI("SubjectSearch.aspx?Content=" + vcontent + "&InputKeyword=1" + "&SearchType=" + AType);
    }
    else {
        document.location.href = encodeURI("SubjectSearch.aspx?Content=" + AContent + "&InputKeyword=1" + "&SearchType=" + AType);
    }
}


//搜索用户
function SearchUser() {
    var vcontent = $("#txtSearch").val();
    if (!JudgeSearchEmpty(vcontent)) {
        return;
    }
    document.location.href = encodeURI("MemberSearch.aspx?Content=" + vcontent + "&InputKeyword=1");
}

//搜索俱乐部
function SearchClub() {
    var vContent = $("#txtSearchClubContent").val();
    if (!JudgeSearchEmpty(vContent)) {
        return;
    }
    document.location.href = encodeURI("ClubSearch.aspx?Content=" + vContent);
}

//设置标签样式
function SetTabCss(ASelectedTag, ADivTag) {
    var vSeletedCss = { "font-size": "12px", color: "Black" };
    var vOldSelectedCss = { "font-size": "12px", color: "#106FB5" };

    if ($("#" + ADivTag)[0]) {
        $("#" + ADivTag + " a").each(function() { $(this).css(vOldSelectedCss) });
    }

    $("#" + ASelectedTag).css(vSeletedCss);
}

$.fn.decorateIframe = function(options) {
    if ($.browser.msie && $.browser.version < 7) {
        var opts = $.extend({}, $.fn.decorateIframe.defaults, options);
        $(this).each(function() {
            var $myThis = $(this);
            //创建一个IFRAME
            var divIframe = $("<iframe />");
            divIframe.attr("id", opts.iframeId);
            divIframe.css("position", "absolute");
            divIframe.css("display", "none");
            divIframe.css("display", "block");
            divIframe.css("z-index", opts.iframeZIndex);
            divIframe.css("top", "0");
            divIframe.css("left", "0");
            if (opts.width == 0) {
                divIframe.css("width", $myThis.width() + parseInt($myThis.css("padding")) * 2 + "px");
            }
            if (opts.height == 0) {
                divIframe.css("height", $myThis.height() - 20 + "px");
            }
            divIframe.css("filter", "mask(color=#fff)");
            $myThis.append(divIframe);
        });
    }
}
$.fn.decorateIframe.defaults = {
    iframeId: "decorateIframe1",
    iframeZIndex: -1,
    width: 0,
    height: 0
}

//转帖
function UserRepaste(SouhuUserPic, TengxunUserPic, SinaUserPic) {
    var SinaUrl = "http:\/\/v.t.sina.com.cn\/share\/share.php";
    var SinaTitle = "转发到新浪微博";
    var SinaPic = "\/images\/Sina.ico";
    var SouhuUrl = "http:\/\/t.sohu.com\/third\/post.jsp";
    var SouhuTitle = "转发到搜狐微博";
    var SouhuPic = "\/images\/24icon-png.png";
    var TenxunUrl = "http:\/\/v.t.qq.com\/share\/share.php";
    var TenxunTitle = "转发到腾讯微博";
    var TengxunPic = "\/images\/Tengxun.ico";
    $("#UserRepaste").html(ViewRepasteCtent("SinaRepaste", SinaUrl, SinaTitle, SinaPic, SinaUserPic));
    $("#SinaRepaste").after(ViewRepasteCtent("SouhuRepaste", SouhuUrl, SouhuTitle, SouhuPic, SouhuUserPic));
    $("#SouhuRepaste").after(ViewRepasteCtent("tengxunReaste", TenxunUrl, TenxunTitle, TengxunPic, TengxunUserPic));
}

//转帖输出
function ViewRepasteCtent(WeiboName, url, title, pic, userpics) {
    var $SinaRepaste = "<a id='" + WeiboName + "' href='javascript:void(0)' onclick=\"postToWb('" + url + "','" + title + "','" + userpics + "');return false;\" class='tmblog'>\
                            <img width='15px' height='15px' src='" + pic + "' alt='" + title + "' border='0' />\
                        </a>";
    return $SinaRepaste;
}

function postToWb(url, title, userpics) {
    var _t = title == "转发到搜狐微博" ? escape(document.title.substring(0, 76)) : encodeURI(document.title.substring(0, 76));
    var _url = encodeURIComponent(location.href);
    var _appkey = encodeURI('');
    var _pic = encodeURI(unescape(userpics));
    var _site = getRootPath();
    var _u = '' + url + '?title=' + _t + '&url=' + _url + '&appkey=' + _appkey + '&site=' + _site + '&pic=' + _pic;
    window.open(_u, '' + title + '', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');
}

//复制内容到剪切板
function CopyCtent() {
    var clipBoardContent = location.href;

    //ie下赋值内容到剪切板
    if (window.ActiveXObject) {
        if (window.clipboardData) {
            window.clipboardData.setData("Text", clipBoardContent);
            $("#viewpase").empty();
            $("#viewpase").html("<span style='color:#F7BBDE'>网址复制成功");
            return;
        }
    }
    $("#viewpase").empty();
    $("#viewpase").html("<span style='color:#F7BBDE'>你的浏览器不支持此复制功能，请用手动复制");
}

//获取网站地址
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    return (prePath + "/");
}

//成员搜索查询数据
function MemberSearchData(APageIndex, AIsInputKeyword) {
    var SearchContent = $("#txtSearchContent").val();
    if (!JudgeSearchEmpty(SearchContent)) {
        return;
    }
    //将查询关键字输出到客户端页面
    var Content = '<span id="keywords" style="color: red; width:120px; height:20px;">' + SearchContent + '</span>';
    $("#SearchContentID").html(Content);
    $.ajax({
        url: "MemberPart.aspx",
        data: "pageIndex=" + (APageIndex + 1) + "&SearchContent=" + escape(SearchContent) + "&InputKeyword=" + escape(AIsInputKeyword) + "&RecordCount=" + FRecordCount + "&time=" + new Date().getTime(),
        success: function(AResult) {
            var arrResult = eval(AResult);
            if (arrResult[2] != "") {
                var arrHistoryRecord = arrResult[2].toString().split("&");
                //单条历史记录
                var strPerHistory = "";
                //绑定历史记录
                for (i = 0; i < arrHistoryRecord.length; i++) {
                    strPerHistory += '<span  style=" width:120px; height:20px;">' + arrHistoryRecord[i] + '</span><br/> ';
                }
            }
            //将结果输出页面
            $("#MemberSearchResult").html(arrResult[0]);
            $("#ResultCount").html(arrResult[1]);
            $("#HistoryView").html(strPerHistory);
            $.ChangePage(arrResult[1], APageIndex, FRecordCount, MemberSearchCallback);
            if (arrResult[1] <= FRecordCount) {
                $("#Pagination").hide();
            }
            else { $("#Pagination").show(); }
        }
    });

    //通过回调使翻页和数据源产生联动（成员搜索）
    function MemberSearchCallback(APageno) {
        MemberSearchData(APageno, 0);
    }
}

//初始化主题搜索
function InitSubjectSearch(pageno, AIsInputKeyword, ASearchType,AContent) {
    var SearchContent = "";
    if ($("#txtSearchSubContent")[0]) {
        SearchContent = $.trim($("#txtSearchSubContent").val());
    }

    if (AContent.length > 0 && AContent != "") {
        SearchContent = AContent;
    }
    
    if (!JudgeSearchEmpty(SearchContent)) {
        return;
    }
    var SearchResult = '';
    $.ajax({
        url: "SubjectSearchRepeater.aspx?PageNo=" + escape(pageno) + "&SearchType=" + ASearchType + "&InputKeyword=" + escape(AIsInputKeyword) + "&Content=" + escape(SearchContent) + "&PageSize=" + FRecordCount + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            var strDatas = eval(data);
            if (strDatas.length > 1 && strDatas[4] == "0") {
                //输出查询结果
                $("#SubjectSearchResult").empty();
                $("#SubjectSearchResult").html(strDatas[2]);

                //主题搜索历史关键字记录
                if (strDatas[3].length > 0) {
                    var vHistoryRecord = eval(strDatas[3]);
                    var strPerHistory = "";
                    for (i = 0; i < vHistoryRecord.length; i++) {
                        strPerHistory += '<span  style=" width:120px; height:20px;">' + vHistoryRecord[i] + '</span><br/> ';
                    }
                    $("#SubjectHistoryView").html(strPerHistory);
                }
            }
            else {
                document.location.href = GGetSubjectUrl(strDatas);
            }
            if (strDatas[0] > 0) {
                SearchResult = '<span>找到<span style="color:red;font-family:Arial;">' + strDatas[0] + '</span>个结果，符合你的要求</span>';
            } else {
                SearchResult = '<span>没有找到结果</span>';
            }

            $("#SearchSubContentID").empty();
            $("#SearchSubContentID").html($(SearchResult));

            if (strDatas[1] > 1) {
                $.ChangePage(strDatas[0], pageno - 1, FRecordCount, SubjectSearchCallback);
            }
            else {
                $("#Pagination").html("");
            }
        }
    });
    //执行下一页的查询
    function SubjectSearchCallback(currentno) {
        InitSubjectSearch(currentno + 1, 0, ASearchType, AContent);
    }
}

//回车响应
function ClickEnter(event,AbuttontId) {
    e = event ? event : (window.event ? window.event : null);
    if (e.keyCode == 13) {
        $("#" + AbuttontId).click();
        return false;
    }
    return true;
}

// 自动匹配所有专题和标签
function AutoSubjectMacth() {
    $(".autoSubjectComplete").autoComplete({
        source: null,
        ajax: { url: 'SubjectHandler.ashx?ActionName=QueryAllLableAndName&search=', dataType: 'json', async: false , autotype:''},
        elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
    });
}

// 自动匹配所有专题
function AutoAllSubjectMacth() {
    $(".autoAllSubjectComplete").autoComplete({
        source: null,
        ajax: { url: 'SubjectHandler.ashx?ActionName=QueryAllName&search=', dataType: 'json', async: false, autotype: '' },
        elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
    });
}

//自动匹配专题和标签对应的专题
function AutoSubjectLabelsMacth() {
    $("#AutoSubjectLabels").autoComplete({
        source: null,
        ajax: { url: 'SubjectHandler.ashx?ActionName=QueryAllLableAndName&search=', dataType: 'json', async: false, autotype:''},
        elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
    });
}

// 自动匹配能发布体验的专题
function PublishViewAutoMacth() {
    $(".autoComplete").autoComplete({
        source: null,
        ajax: { url: 'SubjectHandler.ashx?ActionName=QueryAllSubjectNamesByCreate&search=', dataType: 'json', async: false, autotype: '' },
        elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
    });
}

// 自动匹配我感兴趣的专题
function IInterestedSubjectAutoMacth() {
    $(".autoComplete").autoComplete({
        source: null,
        ajax: { url: 'SubjectHandler.ashx?ActionName=MatchIInterestedSubject&QueryNum=-1&search=', dataType: 'json', async: false ,autotype:''},
        elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
    });
}

// 去除空格
function IgnoreSpaces(Str) {
    var ResultStr = "";
    Temp = Str.split(" "); //双引号之间是一个空格
    for (i = 0; i < Temp.length; i++) {
        ResultStr += Temp[i];
    }
    return ResultStr;
}

function IndexSubject(AUserId,Aurl) {
    if (!JudgeLoginNoUrl(AUserId)) {
        return;
    }
    window.location.href = Aurl;
}

function LocationUSerSetting(AUserId) {
    $.cookie('SaveUrl', window.location.href);
    window.location.href = "UserSetting.aspx?UserId=" + AUserId;
}
