﻿//获取更多主题
function GetMoreSubject(pageno, ASearchType, ASelectType) {
    SetTabCss(ASelectType, "MoreSubjectTab");
    $.ajax({
        url: "MoreSubjectsRepeater.aspx?PageNo=" + escape(pageno) + "&SearchType=" +escape(ASearchType) + "&PageSize=20" + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            //0-查询结果集，1-总记录数，2-总页数
            if (data != "") {
                var strdata = eval(data);
                $("#More_SubjectResult").html(strdata[0]);
                if (strdata[2] > 1) {
                    $.ChangePage(strdata[1], pageno - 1, 20, MoreSubjectCallback);
                }
                else {
                    $("#Pagination").html("");
                }
            }
            else {
                $("#More_SubjectResult").html("");
            }
        }
    });

    //获取更多主题回调函数
    function MoreSubjectCallback(currentno) {
        GetMoreSubject(currentno + 1, ASearchType, ASelectType)
    }
}

//获取主题下的其他体验
function GetOtherView(Apageno, ASubjectId, AViewId, AUserId,ASortType) {
    $.ajax({
    url: "SubjectRepeater.aspx?PageNo=" + escape(Apageno) + "&PageSize=10" + "&SubjectId=" + ASubjectId + "&ViewId=" + escape(-1) + "&UserId=" + escape(AUserId) + "&SortType=" + escape(ASortType) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            var vOtherSubjectResult = eval(data);
            if (vOtherSubjectResult[2].length > 0) {
                $("#OtherSunView").html(vOtherSubjectResult[2]);
                if ($("#ExpNum")[0]) {
                    $("#ExpNum").html(vOtherSubjectResult[0]);
                }
                if (parseInt(vOtherSubjectResult[0]) <= 10) {
                    $("#OtherSunViewMore").hide();
                    $("#AllNum").hide();
                } else {
                    $("#OtherSunViewMore").show();
                    $("#AllNum").show();
                }

                if (vOtherSubjectResult[1] > 1) {
                    $.ChangePage(vOtherSubjectResult[0], Apageno - 1, 10, OtherViewCallback);
                } else {
                    $("#Pagination").html("");
                }

                if (vOtherSubjectResult[0] > 0) {
                    $("#S_Other_View").css("display", "block");
                }

            } else {
                $("#S_Other_View").css("display", "block");
                $("#OtherSunView").html("<span>你现在还没有发布和这个专题相关的体验哦...</span>");
                $("#Pagination").html("");
            }
        }
    });

    //获取主题下的其他体验的回调函数
    function OtherViewCallback(currentno) {
        GetOtherView(currentno + 1, ASubjectId, AViewId, AUserId, ASortType)
    }
}

//查看专题
function GetRecommendView(ASubjectId) {
    //0-资源数，1-体验数，2-活动数，3-关注人数，4-主题标题，5-输出体验图片，6-体验标题
    //7-体验编号,8-体验内容,9-体验图片数,10-体验回复数,11-体验鲜花数,12-主题创建者,
    //13-主题活动集合,14-所有体验回复数,15-当前用户是否关注主题,16-是否置顶,17-是否发布,18-专题类型
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=RecommendView" + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            var vRecommendResult = eval(data);
            
            // 编辑能修改,非编辑只能修改自己创建的个人专题
            if ((parseInt(vRecommendResult[18]) == 2 && FUserId == vRecommendResult[12]) || FIsEdit == 1) {
                $("#td_ModifySubject").html("<a style='padding-left:10px;' href='javascript:void(0);' onclick=\"ModifySubTitle(-1," + ASubjectId + ", '" + vRecommendResult[4] + "'," + vRecommendResult[18] + ",this);\">\
                                        <span style='font-family:arial'>(</span>修改<span style='font-family:arial'>)</span></a>");
            }
            
            FSubjectName = vRecommendResult[4];

            //体验数为0时隐藏   
            if (parseInt(vRecommendResult[1]) < 1) {
                $("#View_con").css("display", "none");
                $("#View_Count").css("display", "none");
            } else {
                $("#View_Count").html(vRecommendResult[1]);
            }

            //资源数为0时隐藏  
            if (parseInt(vRecommendResult[0]) < 1) {
                $("#Resourse_con").css("display", "none");
                $("#Resourse_Count").css("display", "none");
            } else {
                $("#Resourse_Count").html(vRecommendResult[0]);
            }

            //活动数为0时隐藏  
            if (parseInt(vRecommendResult[2]) < 1) {
                $("#Event_con").css("display", "none");
                $("#Event_Count").css("display", "none");
            } else {
                $("#Event_Count").html(vRecommendResult[2]);
            }

            //关注人数为0时隐藏  
            if (parseInt(vRecommendResult[3]) < 1) {
                $("#Attention_con").css("display", "none");
                $("#Attention_Count").css("display", "none");
            } else {
                $("#Attention_Count").html(vRecommendResult[3]);
            }

            //所有体验数为0时隐藏  
            if (parseInt(vRecommendResult[14]) < 1) {
                $("#Review_con").css("display", "none");
                $("#Review_Count").css("display", "none");
            } else {
                $("#Review_Count").html(vRecommendResult[14]);
            }

            $("#Good_ViewPicture").attr("src", vRecommendResult[5]);
            $("#Good_ViewTitle").html(vRecommendResult[6]);
            $("#Good_ViewTitle").attr("href", GGetViewUrl(vRecommendResult[7]));
            $("#Good_ViewPictureUrl").attr("href", GGetViewUrl(vRecommendResult[7]));
            $("#Good_ViewContent").html(vRecommendResult[8].length > 200 ? vRecommendResult[8].substring(0, 200) + "......" : vRecommendResult[8]);
            $("#Subject_PictureCou").html(vRecommendResult[9]);
            $("#Subject_Flowercou").html(vRecommendResult[11]);
            $("#Subject_Collectioncou").html(vRecommendResult[10]);
            $("#View_Detail").attr("href", GGetViewUrl(vRecommendResult[7]));
            GetConcernSubject(ASubjectId);
            GetSubjectResourse(ASubjectId, 0);
            GetOtherView(1, ASubjectId, vRecommendResult[7], -1,"U");
            $("#Good_Sub_View").css("display", "block");
            $("#Subject_Event").html(vRecommendResult[13]);
            
            // 个人专题
            if(vRecommendResult[18] == 2)
            {
                // 不显示只看我的体验
                $("#LookMyView").css("display", "none");
                
                if(vRecommendResult[12] != FUserId)
                {
                    $("#divSpaceView").css("display", "none");
                    $("#divAddNetResourse").css("display", "none");
                    $("#SAdd_view").css("display", "none");
                    $("#SAdd_Resourse").css("display", "none");
                }
            }
            
            //输出是否订阅
            if (vRecommendResult[15] == 'Y') {
                $("#ActionSubs").html("<span class='button_copy' style='font-size:9pt;'>已关注</span>");
            } else {
                $("#ActionSubs").html("<a id='Subscribe_Subject' href='javascript:void(0)' onclick=\"SubsSubject(" + ASubjectId + ",'N')\" class='button_copy' style='font-size:9pt;'>关注</a>");
            }
            //输出是否置顶
            if (parseInt(vRecommendResult[16]) == 1) {
                $("#SubjectSetTop").html("<a  href='javascript:void(0)' onclick='SingleSetTopSubject(" + ASubjectId + ",0)' class='button_copy' style='font-size:9pt;'>取消置顶</a>");
            }
            else {
                $("#SubjectSetTop").html("<a href='javascript:void(0)' onclick='SingleSetTopSubject(" + ASubjectId + ",1)' class='button_copy' style='font-size:9pt;'>置顶该专题</a>");
            }
            //输出是否发布
            if (FIsEdit == 1) {
                if (parseInt(vRecommendResult[17]) == 1) {
                    $("#SubjectPublish").html("<a  href='javascript:SinglePublishedSubject(" + ASubjectId + ",0);' style='font-size:9pt;'>\
                <span style='font-family:arial'>(</span>取消发布<span style='font-family:arial'>)</span></a>");
                }
                else {
                    $("#SubjectPublish").html("");
                } 
            }
        }
    });
}

//查询关注的主题
function GetConcernSubject(ASubjectId) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=ConcernSubject" + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
                var Result = eval(data);
                var strConcernSubject = "";
                if (Result.length > 0) {
                    $("#RelaSub").show();
                    //是否有取消关注主题的权限 
                    var IsCancelConcernSubject = FIsEdit == 1;
                    for (i = 0; i < Result.length; i++) {
                        strConcernSubject += '<div id="CancelsubFavorite_' + Result[i].ConcernSubjectId + '"><a href="' + GGetSubjectUrl(Result[i].ConcernSubjectId) + '" style="padding-right:5px">' + Result[i].ConcernSubjectTitle + '</a>&nbsp;';
                        strConcernSubject += IsCancelConcernSubject || Result[i].UserId == FUserId ? '<a href="javascript:void(0)" style="font-size:14px; font-family: 宋体;" title="取消关联" onclick="CancelConcernSubject(' + FUserId + ',' + ASubjectId + ',' + Result[i].ConcernSubjectId + ')"><span style="font-size:9pt;color:#ABABAB;font-family:Arial">x</span></a>' : "";
                        strConcernSubject += '<br /></div>';
                        strConcernSubject += '<div><div class="pad"></div><div class="linegrx"></div><div class="pad"></div></div>';
                    }
                } else {
                    $("#RelaSub").hide();
                }
                $("#Concern_Subject").html(strConcernSubject);
            } else {
                $("#RelaSub").css("display", "none");
            }
        }
    });
}

//查询主题资源
function GetSubjectResourse(ASubjectId, AShowCount) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=SubjectResourse" + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
                var Result = eval(data);
                var strSubjectResourse = "";
                var ResultCount = AShowCount == 0 && Result.length > 3 ? 3 : Result.length;

                if (Result.length > 0) {
                    $("#Res_Num").html(Result.length + "条");
                }

                for (i = 0; i < ResultCount; i++) {
                    var vLink = Result[i].uid == FUserId ? 'MySpace.aspx' : GGetOtherSpaceUrl(Result[i].uid);
                    var x = Result[i].rr.toString().length > 65 ? (Result[i].rr.toString().substring(0, 65) + '...') : Result[i].rr.toString();
                    var n = Result[i].rn.toString().length > 50 ? (Result[i].rn.toString().substring(0, 50) + '...') : Result[i].rn.toString();
                    strSubjectResourse += '<tr><td colspan="2" width="100%" style="height:5px;clear:both;"></td></tr>';
                    strSubjectResourse += '<tr valign="middle"><td colspan="2" width="100%"><a href="' + Result[i].ru + '" target="_blank" style="font-size:10pt;font-weight:bold" title="' + Result[i].rn + '">' + n + '</a>　　<span style="color:#5F5F5F;cursor: pointer;" title="' + Result[i].rr + '">' + x + '</span></td></tr>';
                    strSubjectResourse += '<tr valign="middle">';
                    strSubjectResourse += '<td width="480px">';
                    strSubjectResourse += '<span class="from_color">来自</span> <a href="' + vLink + '" class="name_color">' + Result[i].un + '</a> <span class="date_style">' + Result[i].cts + '</span>';
                    strSubjectResourse += Result[i].uid == FUserId || FIsEdit == 1 ? '<a href="ModifySource.aspx?SubjectId=' + FSubjectId + '&ResourceId=' + Result[i].srid + '"style="padding-right:5px;color:#ABABAB;padding-left:20px">修改</a><a style="color:#ABABAB;" href="javascript:void(0)" onclick="DelSubjectResourse(' + Result[i].srid + ')">删除</a>' : "";
                    strSubjectResourse += '</td>';
                    if (Result[i].rvn > 0) {
                        strSubjectResourse += '<td align="right"><span class="num_font"><img id="SocreFlower' + Result[i].srid + '" src="images/arrow_up.gif" style="cursor: pointer;height:11px;width:11px;" title="有用，推荐一下" onclick="SubjectResScore(' + Result[i].srid + ',1)" alt="" /><spanid="SocreFlower' + Result[i].srid + '">推荐</span><span class="num_font" id="Flower' + Result[i].srid + '">' + Result[i].rvn + '</span></span>&nbsp;';
                    } else {
                        strSubjectResourse += '<td align="right"><span class="num_font"><img src="images/arrow_up.gif" style="cursor: pointer;height:11px;width:11px;" title="有用，推荐一下" onclick="SubjectResScore(' + Result[i].srid + ',1)" alt="" /><spanid="SocreFlower' + Result[i].srid + '" >推荐</span></span>&nbsp;';
                    }
                    strSubjectResourse += '<img src="images/arrow_down.gif" style="cursor: pointer;height:11px;width:11px;" title="报个错：和专题不符、广告或虚假嫌疑" onclick="SubjectResScore(' + Result[i].srid + ',0)" alt=""/><span id="Flag' + Result[i].srid + '" class="num_font">举报</span>';
                    strSubjectResourse += '</td></tr>';
                    strSubjectResourse += '<tr><td colspan="2" width="100%" style="height:1px;"></td></tr>';
                    strSubjectResourse += '<tr valign="middle"><td colspan="2" width="100%"><div class="linegrx"></div></td></tr>';
                    strSubjectResourse += '<tr><td colspan="2" width="100%" style="height:1px;"></td></tr>';
                }

                if ($("#Subject_Resourse")[0]) {
                    $("#Subject_Resourse").html(strSubjectResourse);
                }
                if ($("#All_Subject_Resourse")[0]) {
                    $("#All_Subject_Resourse").css("display", "block");
                }
            }
            else {
                if ($("#All_Subject_Resourse")[0]) {
                    $("#All_Subject_Resourse").css("display", "none");
                }
            }
        }
    });
}

//删除主题网络资源
function DelSubjectResourse(ASubjectResourseId) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=RemoveSubResourse" + "&UserId=" + escape(FUserId) + "&SubjectResourseId=" + ASubjectResourseId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                GetSubjectResourse(FSubjectId, 0);
            }
            else {
                alert(data);
            }
        }
    });
}

//主题网络资源评分（0-无用,1-有用）
function SubjectResScore(ASubjectResourseId, AScoreType) {
    if (JudgeLogin(FUserId)) {
        $.ajax({
            url: "SubjectHandler.ashx?UserId=" + escape(FUserId) + "&SubjectResourseId=" + escape(ASubjectResourseId) + "&ScoreType=" + escape(AScoreType) + "&ActionName=SubjectResScore" + "&time=" + new Date().toString(),
            type: 'GET',
            success: function(data) {
                if (data == "SUCCESS" && AScoreType == 1) {
                    if ($("#Flower" + ASubjectResourseId)[0]) {
                        var vFlowerCount = parseInt($("#Flower" + ASubjectResourseId).html());
                        $("#Flower" + ASubjectResourseId).html(vFlowerCount + 1);
                    }
                    else if ($("#ResourseFlower" + ASubjectResourseId)[0]) {
                        var ResourseCount = $("#ResourseFlower" + ASubjectResourseId).html();
                            $("#ResourseFlower" + ASubjectResourseId).html(parseInt(ResourseCount)+1);
                    }
                    else {
                        var html = "<span class='num_font' id='Flower" + ASubjectResourseId + "'>1</span>";
                        $(html).insertAfter("#SocreFlower" + ASubjectResourseId);
                    }
                }

                else if (data == "SUCCESS" && AScoreType == 0) {
                    alert("系统已经录入你的提示，我们会尽快处理，谢谢");
                }
                else {
                    alert(data);
                }
            }
        });
    }
}

//展示所有主题网络资源
function ShowAllResSubject(AId) {
    var vStateValue = $.trim($("#hideResourceValue").html());
    if (vStateValue == 0) {
        $("#" + AId).html("<span id='Show_All_Res'>收起</span>");
        $("#hideResourceValue").html(1);
        GetSubjectResourse(FSubjectId, 1);
    }
    else {
        $("#" + AId).html("<span id='Show_All_Res'>展开全部</span>");
        $("#hideResourceValue").html(0);
        GetSubjectResourse(FSubjectId, 0);
    }
}

//取消主题关注
function CancelConcernSubject(AUserId, ASubjectId, AConcernSubjectId) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=CancelConcernSubject" + "&UserId=" + AUserId + "&ConcernSubjectId=" + AConcernSubjectId + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                $("#CancelsubFavorite_" + AConcernSubjectId).css("display", "none");
            }
            else {
                alert(data);
            }
        }
    });
}

//查询我感兴趣的专题的结果
function QuerySubjectData(AType) {
    switch (AType) {
        case "MyCreateSubject":
            MyCreateSubject(1);
            break;
        case "MyInterestedSubject":
            MyInterestedSubject(1);
            break;
        case "MySubscribeSubject":
            MySubscribeSubject(1);
            break;
        default:
            alert("操作出现异常");
            break;
    }
}

//取消订阅主题(ASubjectId-专题编号，ASubscribeType-订阅专题类型，APageType-调用页面类型)
function CancelSubscribeSubject(ASubjectId, ASubscribeType,APageType,Me) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=CancelSubscribeSubject" + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                switch (APageType) {
                    case "Interested":
                        QuerySubjectData(ASubscribeType);
                        break;
                    case "Search":
                        $(Me).empty();
                        $(Me).css("display", "none");
                        $(Me).after("<a href='javascript:void(0)' onclick=\"SubsSubjectSubSearch(" + ASubjectId + ",'','" + APageType + "',this)\" \
                                         style='font-family:宋体;font-size:9pt;color:#F60;' title='添加关注'>添加关注</a>");
                                         
                        var ConcernCount = $("#SubjectConcertCount" + ASubjectId).html();
                        $("#SubjectConcertCount" + ASubjectId).html(parseInt(ConcernCount) -1);
                        break;
                }
            }
            else {
                alert(data);
            }
        }
    });
}

//订阅主题(Type Y-订阅成功显示提示信息(在单个专题中使用),N-订阅成功不显示信息)
function SubsSubject(ASubjectId,AType) {
    if (JudgeLogin(FUserId)) {
        if (!JudgePrivilegeClubUser(FClubAdmin)) {
            return;
        }
        $.ajax({
            url: "SubjectHandler.ashx?ActionName=SubscribeSubject" + "&UserId=" + escape(FUserId) + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
            type: 'GET',
            success: function(data) {
//                if (AType == "Y") {
//                    alert("“" + FSubjectName + "”\r这颗花生苗只有在大家共同培养灌溉下才能茁\r壮成长。关注后，如果有和这个专题相关的体\r验和资源，别忘了回到这里分享一下。");
//                }

                if (data == "SUCCESS") {
                    if ($("#Subscribe_Subject")[0]) {
                        $("#Subscribe_Subject").css("display", "none").after("<span class='button_copy' style='font-size:9pt;'>已关注</span>");
                    } else {
                        if ($("#IndexSub")[0]) {
                            $("#IndexSub").html("<span class='button_copy' style='font-size:9pt;'>已关注</span>");
                        }
                        else {
                            alert("关注成功");
                        }
                    }
                }
                else {
                    if ($("#Subscribe_Subject")[0]) {
                        $("#Subscribe_Subject").empty();
                        $("#Subscribe_Subject").html("<span>已关注</span>");
                    } else {
                        alert("已关注过");
                    }
                }
            }
        });
    }
}

//订阅主题(ASubjectId-专题编号，ASubscribeType-订阅专题类型，APageType-调用页面类型)
function SubsSubjectSubSearch(ASubjectId, ASubscribeType,APageType,Me) {
    if (JudgeLogin(FUserId)) {
        if (!JudgePrivilegeClubUser(FClubAdmin)) {
            return;
        }
        $.ajax({
            url: "SubjectHandler.ashx?ActionName=SubscribeSubject" + "&SubjectId=" + ASubjectId + "&time=" + new Date().toString(),
            type: 'GET',
            success: function(data) {
                if (data == "SUCCESS") {
                    switch (APageType) {
                        case "Interested":
                            QuerySubjectData(ASubscribeType);
                            break;
                        case "Search":
                            $(Me).empty();
                            $(Me).css("display", "none");
                            $(Me).after("<a href='javascript:void(0)' onclick=\"CancelSubscribeSubject(" + ASubjectId + ",'','" + APageType + "',this)\" \
                                          style='font-family:宋体;font-size:9pt;color:#ababab;' title='取消关注'>取消关注</a>");
                            var ConcernCount = $("#SubjectConcertCount" + ASubjectId).html();
                            $("#SubjectConcertCount" + ASubjectId).html(parseInt(ConcernCount) + 1);
                            break;
                    }
                } else {
                    alert(data);
                }
            }
        });
    }
}

function AddSubResourse() {
    var vResouseName = $("#Resourse_Name").val();
    var vResouseUrl = $("#Resourse_Url").val();
    var vResouseReason = $("#Resourse_Reason").val();
    var vSubResourseCount = $("#ExperienceType input:radio:checked").size();
    var vSubResourseType = $("#ExperienceType input:radio:checked").val();

    if (vResouseName == "") {
        $("#DResourse_Name").html("请填写名称或标题");
        $("#Resourse_Name").addClass("InputError");
        return;
    } else {
        $("#DResourse_Name").html("");
        $("#Resourse_Name").removeClass("InputError");
    }

    if (vResouseName.length > 100) {
        $("#DResourse_Name").html("名称或标题不能多于100个字符");
        $("#Resourse_Name").addClass("InputError");
        return;
    } else {
        $("#DResourse_Name").html("");
        $("#Resourse_Name").removeClass("InputError");
    }

    if (vResouseUrl == "http://" || vResouseUrl == "") {
        $("#DResource_url").html("请填写网址");
        $("#Resourse_Url").addClass("InputError");
        return;
    } else {
        $("#DResource_url").html("");
        $("#Resourse_Url").removeClass("InputError");
    }

    if (vResouseReason == "") {
        $("#DResource_Reason").html("请填写推荐理由");
        $("#Resourse_Reason").addClass("InputError");
        return;
    } else {
        $("#DResource_Reason").html("");
        $("#Resourse_Reason").removeClass("InputError");
    }

    if (vResouseReason.length > 300) {
        $("#DResource_Reason").html("推荐理由不能多于300个字符");
        $("#Resourse_Reason").addClass("InputError");
        return;
    } else {
        $("#DResource_Reason").html("");
        $("#Resourse_Reason").removeClass("InputError");
    }

    if (vSubResourseCount <= 0) {
        $("#ExperienceTypeError").html("请填写资源类型");
        $("#idExperienceType").addClass("InputError");
        return;
    }
    else {
        $("#ExperienceTypeError").html("");
        $("#idExperienceType").removeClass("InputError");
     }

    $.ajax({
    url: "SubjectHandler.ashx?ActionName=AddSubResourse" + "&ResourceType=" + escape(vSubResourseType) + "&ResouseName=" + escape(vResouseName) + "&ResouseUrl=" + escape(vResouseUrl) + "&RecommendReason=" + escape(vResouseReason) + "&UserId=" + escape(FUserId) + "&SubjectId=" + escape(FSubjectId) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                window.location.href = GGetSubjectUrl(FSubjectId);
            }
            else {
                alert("资源名称或是推荐理由过长，请做相应的修改");
            }
        }
    });
}

//判断主题添加资源中的必填项
function JudgeSrName() {
    var vResouseName = $("#Resourse_Name").val();

    if (vResouseName.length == 0) {
        $("#DResourse_Name").html("请填写名称或标题");
        $("#Resourse_Name").addClass("InputError");
        return;
    }

    if (vResouseName.length > 100) {
        $("#DResourse_Name").html("名称或标题不能多于100个字符");
        $("#Resourse_Name").addClass("InputError");
        return;
    }
    $("#DResourse_Name").html("");
    $("#Resourse_Name").removeClass("InputError");
}
//判断资源链接
function JudgeSrUrl() {
    var vResouseUrl = $("#Resourse_Url").val();

    if (vResouseUrl == "http://" || vResouseUrl == "") {
        $("#DResource_url").html("请填写网址");
        $("#Resourse_Url").addClass("InputError");
        return;
    } else {
        $("#DResource_url").html("");
        $("#Resourse_Url").removeClass("InputError");
    }
}
//判断原因
function JudgeSrReason() {
    var vResouseReason = $("#Resourse_Reason").val();

    if (vResouseReason.length == 0) {
        $("#DResource_Reason").html("请填写推荐理由");
        $("#Resourse_Reason").addClass("InputError");
        return;
    }

    if (vResouseReason.length > 300) {
        $("#DResource_Reason").html("推荐理由不能多于300个字符");
        $("#Resourse_Reason").addClass("InputError");
        return;
    }

    $("#DResource_Reason").html("");
    $("#Resourse_Reason").removeClass("InputError");
}

//创建专题时写体验
function AddSubjectView() {
    var vExperienceTypeCount = $("#ExperienceType input:radio:checked").size();
    var vViewTitle = $.trim($("#NView_Title").val());
    var vViewContent = $.trim($("#NView_Content").val());
    var vExperienceType=  $("#ExperienceType input:radio:checked").val();
     
    if (vViewTitle == "") {
        alert("请填写体验标题");
        $("#NView_Title").focus();
        return;
    }

    if (vViewContent == "") {
        alert("请填写体验内容");
        $("#NView_Content").focus();
        return;
    }

    if (vExperienceTypeCount <= 0) {
        alert("请填写体验类型");
        $("#ExperienceType1").focus();
        return;
    }
    
    //通过post提交数据
    $.post(
    "SubjectHandler.ashx?ActionName=AddSubjectView",
    {
        SubjectTitle: FSubjectTitle, ViewTitle: vViewTitle, ViewContext: vViewContent,
        UserId: FUserId, SubjectType: FSubjectType, ExperienceType: vExperienceType
    },
    function(data) {
    var strData = eval("[" + data + "]");
        if (strData[0].ReturnInfo == "SUCCESS") {
            location.href = GGetViewUrl(strData[0].ViewId);
        }
        else {
            alert(strData[0].ReturnInfo);
        }
    });
}

//单个主题——添加主题资源，添加体验判断是否登录
function TIsLogin(sheet) {
    if (JudgeLogin(FUserId)) {
        if (!JudgePrivilegeClubUser(FClubAdmin)) {
            return;
        }
        switch (sheet) {
            case "Speak_View":
                window.location.href = encodeURI("AddNewView.aspx?SubjectId=" + FSubjectId + "&SubjectTitle=" + FSubjectName + "&UserId=" + FUserId);
                break;
            case "Add_Inline":
                window.location.href = encodeURI("AddSource.aspx?SubjectId=" + FSubjectId + "&SubjectTitle=" + FSubjectName);
                break;
            case "SAdd_Resourse":
                window.location.href = encodeURI("AddSource.aspx?SubjectId=" + FSubjectId + "&SubjectTitle=" + FSubjectName);
                break;
            case "SAdd_view":
                window.location.href = encodeURI("AddNewView.aspx?SubjectId=" + FSubjectId + "&SubjectTitle=" + FSubjectName);
                break;
            default:
                break;
        }
    }
}

//单个主题——修改体验判断是否登录
function ModifyViewLogin(ACreate, AviewId) {
    if (JudgeLogin(FUserId)) {
        if (FUserId != ACreate) {
            alert("对不起，你没有这个权限");
            return;
        }
        window.location.href = GGetModifyViewUrl(AviewId);
    }
}

//我订阅的主题
function MySubscribeSubject(APageNo) {
    SetTabCss("My_SubscribeSubject", "InrerestedSubjectTab");

    QueryMySubject(APageNo, "MySubscribeSubject", MySubscribeSubjectCallback);

    //获取我感兴趣的全部主题回调函数
    function MySubscribeSubjectCallback(currentno) {
        MySubscribeSubject(currentno + 1);
    }
}

//我创建的主题
function MyCreateSubject(APageNo) {
    SetTabCss("My_CreateSubject", "InrerestedSubjectTab");

    QueryMySubject(APageNo, "MyCreateSubject", MyCreateSubjectCallback);

    //获取我感兴趣的全部主题回调函数
    function MyCreateSubjectCallback(currentno) {
        MyCreateSubject(currentno + 1);
    }
}

//根据输入的类型来输出不同的关注专题（Apageno-页索引，type-关注专题类型，ACallback-回调函数）
function QueryMySubject(APageNo, type, ACallBack) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=" + escape(type) + "&UserId=" + escape(FQueryUserId) + "&PageNo=" + escape(APageNo) + "&PageSize=20" + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
                var strDatas = data.toString().split("|");
                var Result = "";

                if (parseInt(strDatas[0]) > 0) {
                    switch (type) {
                        case "MyInterestedSubject":
                            $("#all").html(strDatas[0]);
                            break;
                        case "MySubscribeSubject":
                            $("#subs").html(strDatas[0]);
                            break;
                        case "MyCreateSubject":
                            $("#add").html(strDatas[0]);
                            break;
                        default:
                            break;
                    }
                    InterestedSubjectOut(APageNo, Result, eval(strDatas[2]), type);
                } else {
                    $("#interested_sub").html("");
                }

                if (parseInt(strDatas[1]) > 1) {
                    $.ChangePage(strDatas[0], APageNo - 1, 20, ACallBack);
                } else {
                    $("#Pagination").html("");
                }
            }
            else {
                $("#interested_sub").html("");
                $("#Pagination").html("");
            }
        }
    });
}

//我感兴趣的主题输出
function InterestedSubjectOut(APageNo, RAesult, AData, Atype) {
    function GetCancelSubject(AisAttention, ASubjectId) {
        if (FWho == '他') {
            return "&nbsp;&nbsp;&nbsp;";
        }
        if (FUserId == FQueryUserId) {
            if (AisAttention == "Y") {
                return '　<a href="javascript:void(0)" onclick="CancelSubscribeSubject(' + ASubjectId + ',\'' + Atype + '\',\'Interested\',this)"\
             style="font-family: 宋体;padding-right:5px;font-size:9pt;color:#ababab;" title="取消关注">取消关注</a>';
            } else {
            return '　<a href="javascript:void(0)" onclick="SubsSubjectSubSearch(' + ASubjectId + ',\'' + Atype + '\',\'Interested\',this)"\
             style="font-family: 宋体;padding-right:5px;font-size:9pt;color:#F60;" title="添加关注">添加关注</a>';
            } 
        }

        return "&nbsp;&nbsp;&nbsp;";
    }

    function GetModifySubject(APageNo, ASubjectId, ASubjectTitle, ASubjectType, ASubjectCreatorName) {
        if (FWho == '他') {
            return "";
        }

        // 只在我创建的专题下可以修改
        if (Atype != "MyCreateSubject") {
            return "";
        }

        if ((FUserId == FQueryUserId && ASubjectType == 2) || FIsEditor == 1) {
            return '<a  href="javascript:void(0)" onclick="ModifySubTitle(' + APageNo + ',' + ASubjectId + ',\'' + ASubjectTitle + '\',' + ASubjectType + ',this)"\
         title="修改主题" style="font-size:9pt;color:#ababab;">(修改)</a>';
        }

        return "";
    }

    function GetResult(ANum) {
        if (parseInt(ANum) == 0) {
            return '-';
        }

        return ANum;
    }
    RAesult += '<tr height="15px"><td colspan="7" style="padding-top:10px;"></td></tr>';
    for (i = 0; i < AData.length; i++) {
        RAesult += '<tr style="font-family:Arial;font-size:9pt;text-align:center;height:20px;">';
        RAesult += '<td width="215px" style="padding-left:10px; text-align:left"><a target="_blank" class="othersubjectname" href="' + GGetSubjectUrl(AData[i].SubjectId) + '">' + AData[i].SubjectTitle + '</a>' + GetModifySubject(APageNo, AData[i].SubjectId, AData[i].SubjectTitle, AData[i].SubjectType) + '</td>';
        RAesult += '<td width="55px"><span class="num_style">' + GetResult(AData[i].AttentionCount) + '</span></td>';
        RAesult += '<td width="55px"><span class="num_style">' + GetResult(AData[i].ExperienceCount) + '</span></td>';
        RAesult += '<td width="55px"><span class="num_style">' + GetResult(AData[i].ExperienceReviewCount) + '</span></td>';
        RAesult += '<td width="55px"><span class="num_style">' + GetResult(AData[i].ResourseCount) + '</span></td>';
        RAesult += '<td width="55px"><span class="num_style">' + GetResult(AData[i].ActivitiesCount) + '</span></td>';
        RAesult += '<td width="145px" align="right">';
        
        // 公共专题和自己创建的个人专题才能添加体验
        if(AData[i].SubjectType == 1 || (AData[i].SubjectType == 2 && AData[i].UserId == FUserId))
        {
            RAesult += '<a target="_blank" href="AddNewView.aspx?SubjectId=' + AData[i].SubjectId + '" style="font-size:9pt;color:#F60">添加体验</a>';
        }
        
        RAesult += GetCancelSubject(AData[i].IsAttention, AData[i].SubjectId);
        RAesult += '</tr>';
        RAesult += '<tr><td colspan="7"><div style="height:10px; padding-top:10px"><div class="linegrx"></div></div></td></tr>';
    }
    $("#interested_sub").html(RAesult);
}

//我感兴趣的全部主题
function MyInterestedSubject(APageNo) {

    SetTabCss("My_InterestedSubject", "InrerestedSubjectTab");

    QueryMySubject(APageNo, "MyInterestedSubject", MyInterestedSubjectCallback);

    //获取我感兴趣的全部主题回调函数
    function MyInterestedSubjectCallback(currentno) {
        MyInterestedSubject(currentno + 1);
    }
}

//我感兴趣的主题——主题搜索
function ISearchSubject() {
    var vSearchContent = $.trim($("#ISearch_text").val());
    window.location.href = encodeURI("SubjectSearch.aspx?Content=" + vSearchContent + "&InputKeyword=1" + "&SearchType=N");
}

function GetSizedInterestedSub() {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=SizedInterestedSubject&UserId=" + escape(FUserId) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
                var Result = "";
                var strdata = eval(data);

                for (i = 0; i < strdata.length; i++) {
                    Result += '<a href="' + GGetSubjectUrl(strdata[i].SubjectId) + '">' + strdata[i].SubjectTitle + '</a></br>';
                }

                if ($("#SMyInterestedSub")[0]) {
                    $("#SMyInterestedSub").html(Result);
                }
            }
            else {
                if ($("#SMyInterestedSub")[0]) {
                    $("#SMyInterestedSub").html("");
                }
            }
        }
    });
}

function LocationAddView(ASubjectId, ASubjectTitle) {
    if (FIsClubAdmin == "1") {
        return;
    }
    if (JudgeLogin(FUserId)) {
        window.location.href = encodeURI("AddNewView.aspx?SubjectId=" + ASubjectId + "&SubjectTitle=" + ASubjectTitle + "&UserId=" + FUserId);
    }
}

function ModifySuvSource() {

    var vResourceName = $.trim($("#Resourse_Name").val());
    var vResourceUrl = $.trim($("#Resourse_Url").val());
    var vResourceReason = $.trim($("#Resourse_Reason").val());
    var vSubResourseCount = $("#RsourseType input:radio:checked").size();
    var vSubResourseType = $("#RsourseType input:radio:checked").val();

    if (vResourceName == "") {
        $("#DResourse_Name").html("请填写资源名称或标题");
        $("#Resourse_Name").addClass("InputError");
        return;
    }

    if (vResourceName.length > 100) {
        $("#DResourse_Name").html("不能多于100个字符");
        $("#Resourse_Name").addClass("InputError");
        return;
    }

    if (vResourceUrl == "http://" || vResourceUrl == "") {
        $("#DResource_url").html("请填写资源网址");
        $("#Resourse_Url").addClass("InputError");
        return;
    }

    if (vResourceReason == "") {
        $("#DResource_Reason").html("请填写推荐理由");
        $("#Resourse_Reason").addClass("InputError");
        return;
    }

    if (vResourceReason.length > 300) {
        $("#DResource_Reason").html("推荐理由不能超过300个字符");
        $("#Resourse_Reason").addClass("InputError");
        return;
    }

    if (vSubResourseCount <= 0) {
        $("#RsourseTypeError").html("请填写资源类型");
        $("#idRsourseType").addClass("InputError");
        return;
    }
    else {
        $("#RsourseTypeError").html("");
        $("#idRsourseType").removeClass("InputError");
    }

    $.post(
            "SubjectHandler.ashx?ActionName=ModifySubSource",
             { SubjectId: FSubjectId, SubjectResourseId: FResourceId,
                 ResouseName: vResourceName, ResouseUrl: vResourceUrl,
                 RecommendReason: vResourceReason, ResourseType: vSubResourseType
             },
            function(data) {
                if (data != 'SUCCESS') {
                    alert("资源名称或是推荐理由过长，请做相应的修改");
                }
                else {
                    window.location.href = GGetSubjectUrl(FSubjectId);
                }
            });

}

//修改资源取消导航
function ModifySourceBack() {
    if (history.length== undefined || history.length ==null || history.length == 0) {
        window.location.href = "AdminResource.aspx";
    }
    else {
        window.history.back();
    }
}

function GetSunResource() {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=GetSunResource" + "&SubjectId=" + FSubjectId + "&SubjectResourseId=" + FResourceId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
                var strdata = eval(data);
                $("#Resourse_Name").val(strdata[0].rn);
                $("#Resourse_Url").val(strdata[0].ru);
                $("#Resourse_Reason").val(strdata[0].rr);
                $("#RsourseType input:radio").each(function() {
                    if (strdata[0].srt == this.value) {
                        $(this).attr("checked", "checked");
                    }
                })
            }
        }
    });
}

//花生百科——近期热门主题
function GetWikihotSubject() {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=GetWikihotSubject" + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            $("#WiKiHotSubject").html(data);
        }
    });
}

//花生百科——近期热门主题
function GetWikihotExperience() {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=GetWikihotExperience" + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            $("#WiKiSubjectView").html(data);
        }
    });
}

//花生百科——近期热门主题
function GetNewSubject() {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=GetNewSubject" + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            $("#PeanutWikiNew").html(data);
        }
    });
}

//置顶和不置顶专题
function SingleSetTopSubject(ASubjectId, ASetType) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=SingleSetTopSubject" + "&SubjectId=" + escape(ASubjectId) + "&SetType=" + escape(ASetType) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                if (parseInt(ASetType) == 1) {
                    $("#SubjectSetTop").html("<a  href='javascript:void(0)' onclick='SingleSetTopSubject(" + ASubjectId + ",0)' class='button_copy' style='font-size:9pt;'>取消置顶</a>");
                }
                else {
                    $("#SubjectSetTop").html("<a id='Subscribe_Subject' href='javascript:void(0)' onclick='SingleSetTopSubject(" + ASubjectId + ",1)' class='button_copy' style='font-size:9pt;'>置顶该专题</a>");
                }
            }
        }
    });
}

//发布和不发布专题
function SinglePublishedSubject(ASubjectId, ASetType) {
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=SinglePublishedSubject" + "&SubjectId=" + escape(ASubjectId) + "&SetType=" + escape(ASetType) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data == "SUCCESS") {
                window.location.href = "Index.aspx";
            }
        }

    });
}

//获取感兴趣的专题(添加体验,为体验添加新专题)
function GetAddInterestSubject(APageSize,AActionName) {
    var Result = "";
    $("#txtSubject").attr("value", "");
    $.ajax({
    url: "SubjectHandler.ashx?ActionName=" + AActionName + "&QueryNum=" + APageSize + "&time=" + new Date().toString(),
        type: 'GET',
        async: false,
        success: function(data) {
            if (data != "") {
                var strdata = eval(data);
                Result += '<table>';
                for (i = 0; i < strdata.length; i++) {
                    var vPaddingLeftValue = (i % 4) == 0 ? "0px" : "10px";
                    Result += i % 4 == 0 ? '<tr>' : "";
                    Result += "<td style='width:150px;padding-top:3px;'>";
                    Result += '<input  name="AddSubject" type="radio"  value="' + strdata[i].Name + '"/><a target="_blank" href="Subject.aspx?SubjectId=' + strdata[i].Id + '"><span style="color:#106FB5;" title="' + strdata[i].Name + '">' + strdata[i].SubName + '</span></a>&nbsp;&nbsp;';
                    Result += "</td>";
                    Result += (i + 1) % 4 == 0 || i == strdata.length - 1 ? "</tr>" : "";
                }
                Result += '</table>';
            }
        }
    });
    return Result;
}

//获取所有专题
function SearchAllSubjectName() {
    var vSubjectName = $("#txtSubject").val();
    if (vSubjectName.length == 0 || vSubjectName == "") {
        $("#SearchError").html("<span style='color:red'>请输入关键字</span>");
        return;
    }
    var Result = "";
    $.ajax({
        url: "SubjectHandler.ashx?ActionName=QueryByName&SubjectName=" + escape(vSubjectName) + "&time=" + new Date().toString(),
        type: 'GET',
        async: false,
        success: function(data) {
            if (data != "") {
                var strdata = eval(data);
                Result += '<div><table>';
                for (i = 0; i < strdata.length; i++) {
                    var vPaddingLeftValue = (i % 4) == 0 ? "0px" : "10px";
                    Result += i % 4 == 0 ? '<tr>' : "";
                    Result += "<td style='width:140px;padding-top:3px;'>";
                    Result += '<input  name="AddSubject" type="radio"  value="' + strdata[i].SubjectTitle + '"/><span style="color:#106FB5" title="' + strdata[i].SubjectTitle + '">' + strdata[i].SubSubjectTitle + '</span>&nbsp;&nbsp;';
                    Result += "</td>";
                    Result += (i + 1) % 4 == 0 || i == strdata.length ? "</tr>" : "";
                }
                Result += '</table></div>';
                Result += "<div class='newsubjectclass' style='padding-top: 15px;padding-bottom:15px'>\
                                        <span>觉得这些专题不太合适？你可以</span><br/>\
                                        <span>A）</span><a class='Edit_ClibPic' href='AddNewSubject.aspx'><span class='newsubjectclass'>创建一个新专题，然后到这个专题下发言</span></a><br/>\
                                        <span>B）<a href='javascript:SubmitAddViewPage(1);' class='newsubjectclass'>发布到“教育杂谈”下</a>（有关教育方面的话题）</span>\
                                        <span>或者，<a href='javascript:SubmitAddViewPage(2);' class='newsubjectclass'>发布到“花生杂谈”下</a>（其它话题）</span></div>";
                                        
                $("#SearchError").html(Result);
            }
            else {
                $("#SearchError").html("<div class='newsubjectclass' style='padding-bottom:15px'>\
                                        <span>对不起，没找到你感兴趣的专题。你可以</span><br/>\
                                        <span>A）</span><a class='Edit_ClibPic' href='AddNewSubject.aspx'><span class='newsubjectclass'>创建一个新专题，然后到这个专题下发言</span></a><br/>\
                                        <span>B）<a href='javascript:SubmitAddViewPage(1);' class='newsubjectclass'>发布到“教育杂谈”下</a>（有关教育方面的话题）</span>\
                                        <span>或者，<a href='javascript:SubmitAddViewPage(2);' class='newsubjectclass'>发布到“花生杂谈”下</a>（其它话题）</span></div>");
            }
        }
    });
}

//选中专题提交到新建体验页面
function SubmitAddViewPage(AType) {
    var VCheckSubjectName = "";
    if (arguments.length == 1) {
        if (AType == 1) {
            VCheckSubjectName = "教育杂谈";
        }
        else {
            VCheckSubjectName = "花生杂谈";
         }
    }
    else {
        VCheckSubjectName = $("input:radio:checked").val();
    }

    if (VCheckSubjectName == undefined || VCheckSubjectName == "" || VCheckSubjectName.length == 0) {
        alert("请选择专题");
        return;
    }
    window.location.href = encodeURI("AddView.aspx?SubjectName=" + VCheckSubjectName + "&Type=N");
}

//专题提意见和建议
function AddSubjectSuggest(elem) {
    if (!JudgeLogin(FUserId)) {
        return;
    }
    
    //专题提意见和建议输入html
    var vSubjectSuggestHtml = "<div style='text-align:center'>\
                                 <table style='width: 350px; border:0px solid red;'>\
                                    <tr>\
                                        <td style='padding-top: 10px;padding-left:8px'>\
                                            <div style='font-size: 9pt'>如果对这个专题的名称、内容、参与者有些意见和想法，欢迎在此和管理员沟通（请说明问题在哪里，你有什么建议）：\
                                            </div>\
                                        </td>\
                                    </tr>\
                                    <tr>\
                                        <td style='padding-top: 10px;padding-left:8px'>\
                                            <textarea id='txtSubjectSuggest' rows='2' cols='20' style='width: 225px; height:60px'></textarea>\
                                        </td>\
                                    </tr>\
                                    <tr>\
                                        <td style='padding-left:8px'>\
                                            <span id='SubjectSuggestError' style='font-size: 9pt;padding-left:5px;color:red'></span>\
                                        </td>\
                                    </tr>\
                                    <tr>\
                                        <td style='padding-top: 10px;padding-left:8px'>\
                                            <input id='btnSubjectSuggest' type='button' value='提交' onclick='SubmitSubjectSuggest()' />\
                                            <span style='font-size: 9pt;padding-left:5px'>提交后，管理员会与你站内信联系</span>\
                                        </td>\
                                    </tr>\
                             </table></div>";
                             
    $.EditBox(elem, "修改名称/反馈", 400, 310, vSubjectSuggestHtml);
}

//提交专题意见和建议信息
function SubmitSubjectSuggest() {
    var vSubjectSuggestContent = $.trim($("#txtSubjectSuggest").val());

    if (vSubjectSuggestContent.length == 0 || vSubjectSuggestContent == "") {
        $("#SubjectSuggestError").html("请填写内容");
        $("#txtSubjectSuggest").focus();
        return;
    }

    $.post(
        "SubjectHandler.ashx?ActionName=AddSubjectReport",
        {
            UserId: FUserId, SubjectId: FSubjectId,
            ReportContent: vSubjectSuggestContent
        },
        function(data) {
            if (data = "SUCCESS") {
                $("#cboxClose").click();
            }
            else {
                $("#cboxClose").click();
                alert(data);
            }
        });
    }

//添加分类
    function AddSubjectlables(elem) {
        var vSubjectLablesHtml = "<table cellpadding='0' cellspacing='0' style=' width:380px; height:150px;margin-left:20px;margin-top:10px' >\
                                    <tr>\
                                        <td>\
                                            专题名称：\
                                        </td>\
                                        <td colspan='2' >\
                                            <input id='txtSubjectName' type='text' readonly='readonly' style='width:200px' value='" + FSubjectName + "'/>\
                                        </td>\
                                    </tr>\
                                    <tr id='trSubjectType'>\
                                        <td>\
                                            专题标签：\
                                        </td>\
                                        <td>\
                                            <div class='autoSubjectLablesComplete'>\
                                                <input id='txtSubjectLables' type='text' style='width: 200px'/><br />\
                                                <ul style='width: 200px'>\
                                                    <li></li>\
                                                </ul>\
                                           </div>\
                                        </td>\
                                        <td>\
                                         <a href='javascript:GetLablesType();'><span class='num_style'>></span>查看专题标签类型</a>\
                                        </td>\
                                         <tr>\
                                        <td>\
                                        </td>\
                                        <td colspan='2'>\
                                        <div id='SubjectLablesType' style='color:red'>以下为标签类型，可以先查询填写的标签是否有类型，<br/>在进行添加或修改</div>\
                                        </td>\
                                    </tr>\
                                    </tr>\
                                       <tr>\
                                        <td>\
                                            标签类型：\
                                        </td>\
                                        <td colspan='2'>\
                                          <div id='id_SubjectType'>\
                                          <input id='rbSubjectType0' type='radio' value='-1' name='SubjectType' checked='checked'/>无\
                                            <input id='rbSubjectType1' type='radio' value='1' name='SubjectType'/>教育\
                                            <input id='rbSubjectType2' type='radio' value='2' name='SubjectType'/>文化\
                                            <input id='rbSubjectType3' type='radio' value='3' name='SubjectType'/>游玩\
                                            <input id='rbSubjectType4' type='radio' value='4' name='SubjectType'/>健康\
                                            <input id='rbSubjectType5' type='radio' value='5' name='SubjectType'/>生活\
                                        </div>\
                                        </td>\
                                    </tr>\
                                    <tr>\
                                        <td>\
                                        </td>\
                                        <td colspan='2'>\
                                        <div id='SubjectLablesError' style='color:red'></div>\
                                        </td>\
                                    </tr>\
                                     <tr>\
                                        <td>\
                                        </td>\
                                        <td colspan='2'>\
                                            <input id='SubmitSubjectLables' type='button' value='提交' onclick='SubmitAddSubjectLable()' />\
                                         </td>\
                                    </tr>\
                                </table>";

        $.EditBox(elem, "为专题添加分类", 420, 300, vSubjectLablesHtml);
        SubjectLablesAutoMacth();
    }

    //专题标签自动匹配
    function SubjectLablesAutoMacth() {
        $(".autoSubjectLablesComplete").autoComplete({
            source: null,
            ajax: { url: 'SubjectHandler.ashx?ActionName=QueryAllLable&search=', dataType: 'json', async: false,autotype:'labels'},
            elemCSS: { focus: { 'color': 'black', 'background': '#ccc', 'border': '#ccc' }, blur: { 'color': 'black', 'background': 'transparent'} }
        });
    }

    //提交专题标签数据
    function SubmitAddSubjectLable() {
        var vSubjectLables = $.trim($("#txtSubjectLables").val());
        var vCategoryId = $("#id_SubjectType input:radio:checked").val();
        if (vSubjectLables.length == 0 || vSubjectLables == "") {
            $("#SubjectLablesError").html("请填写专题标签");
            $("#txtSubjectLables").focus();
            return;
        }

        $.post(
        "SubjectHandler.ashx?ActionName=AddSubjectLables",
        {
            UserId: FUserId, SubjectId: FSubjectId,
            LablesName: vSubjectLables, CategoryId: vCategoryId
        },
        function(data) {
            if (data = "SUCCESS") {
                GeneSubjectLables(FSubjectId);
                $("#cboxClose").click();
            }
            else {
                $("#cboxClose").click();
                alert(data);
            }
        });
    }

    //获取标签类型
    function GetLablesType() {
        var vLablesName = $.trim($("#txtSubjectLables").val());
        
        if (vLablesName.length == 0 || vLablesName == "") {
            $("#SubjectLablesType").html("请填写专题标签");
            $("#txtSubjectLables").focus();
            return;
        }

        $.post(
        "SubjectHandler.ashx?ActionName=QueryLablesType",
        {
            LablesName: vLablesName
        },
        function(data) {
            $("#id_SubjectType input:radio").each(function() {
                if (this.value == data) {
                    $(this).attr("checked", "checked");
                } 
            });
        });
    }
    
    //生成专题标签html
    function GeneSubjectLables(ASubjectId) {
        $.post(
        "SubjectHandler.ashx?ActionName=GetSubjectLables",
        {
            SubjectId: FSubjectId
        },
        function(data) {
            if (data.length > 0) {
                var vLablesResult = eval(data);
                var vOutResult = "";
                for (var v = 0; v < vLablesResult.length; v++) {
                    vOutResult += "<a href=\"javascript:SearchSub('LN','" + vLablesResult[v].LabelName + "')\" style='font-size: 10pt; text-decoration: none;' title='" + vLablesResult[v].LabelName + "'>" + vLablesResult[v].SubLabelName + "</a>";
                    vOutResult += FIsEdit == 1 ? "&nbsp;<a href='javascript:DeleteSubjectLables(" + vLablesResult[v].SubjectLabelId + ")' style='font-size: 9pt; text-decoration: none' class='from_color'>x</a>&nbsp;&nbsp;" : "&nbsp;&nbsp;";
                }
                $("#tb_SubjectCategory").html(vOutResult);
            }
        });
    }
    
    //删除专题标签
    function DeleteSubjectLables(ASubjectLabelId) {
        $.post(
        "SubjectHandler.ashx?ActionName=DeleteSubjectLables",
        {
            SubjectLabelId: ASubjectLabelId
        },
        function(data) {
            if (data == "SUCCESS") {
                GeneSubjectLables(FSubjectId);
            }
            else {
                alert(data);
            }
        });
    }

//新建号外  
function AddEditions(elem)
{
 var vHtml = "<table style='width:90%;margin-left:20px;margin-top:20px'>\
            <tr>\
                <td>\
                    <div>\
                        主题：</div>\
                </td>\
                <td>\
                <div>\
                    <input id='txtName' type='text' style='width:260px' /></div>\
                </td>\
            </tr>\
            <tr>\
                <td style='padding-top:10px'>\
                链接：\
                </td>\
                <td style='padding-top:10px'>\
                 <div>\
                    <input id='txtLink' type='text'  style='width:260px'/></div>\
                </td>\
            </tr>\
              <tr>\
                 <td style='padding-top:10px'>\
                </td>\
                <td style='padding-top:10px'><div id='EditionError' style='color:Red'></div></td>\
            </tr>\
             <tr>\
                <td style='padding-top:10px'>\
                </td>\
                <td style='padding-top:10px'>\
                 <div>\
                     <input class='but' id='txtSubmit' type='button' value='发布' onclick=\"SubmitEditions('EditionsAdd',"+-1+")\"/>\
                 </div>\
                </td>\
            </tr>\
        </table>";
            
 $.EditBox(elem, "添加新外号", 400, 230, vHtml);
}

//提交号外信息
function SubmitEditions(AActionName,AEditionsId)
{
 var vEditionsContent = $("#txtName").val();
 var vEditionsLink = $("#txtLink").val();
 
 if(vEditionsContent.length ==0 || vEditionsContent=="")
 {
  $("#EditionError").html("主题不能为空");
  $("#txtName").focus();
  return;
 }
 
  $.post(
        "SubjectHandler.ashx?ActionName="+AActionName,
        {
           EiditionName:vEditionsContent,
           EditionLink:vEditionsLink,
           EditionId:AEditionsId
        },
        function(data) {
            if (data == "SUCCESS") {
               $("#cboxClose").click();
            }
            else {
            $("#EditionError").html(data);
            }
        });
}

function GetSimpleEditionsManege(elem)
{
 var vEditionsName ='';
 var vEditionsLink = '';
if(FEditionsId == -1)
{
  alert("未找到号外编号");
  return;
}

 $.ajax({
        url: "SubjectHandler.ashx?ActionName=GetEditionsManegeById&EditionId=" + FEditionsId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
            if (data != "") {
              var vEditionsResult = $.parseJSON(data);
               vEditionsName = vEditionsResult.EditionsName;
               vEditionsLink =  vEditionsResult.EditionsLink;
               ModifyEditions(elem);
            }
            else
            {
             alert("没有获取到当前号外信息");
            }
        }
    });
    
        //修改号外信息
        function ModifyEditions(elem)
        { 
            var vHtml = "<table style='width:90%;margin-left:20px;margin-top:20px'>\
                    <tr>\
                        <td>\
                            <div>\
                                主题：</div>\
                        </td>\
                        <td>\
                        <div>\
                            <input id='txtName' type='text' style='width:260px' value='"+vEditionsName+"'/></div>\
                        </td>\
                    </tr>\
                    <tr>\
                        <td style='padding-top:10px'>\
                        链接：\
                        </td>\
                        <td style='padding-top:10px'>\
                         <div>\
                            <input id='txtLink' type='text'  style='width:260px' value='"+vEditionsLink+"'/></div>\
                        </td>\
                    </tr>\
                      <tr>\
                         <td style='padding-top:10px'>\
                        </td>\
                        <td style='padding-top:10px'><div id='EditionError' style='color:Red'></div></td>\
                    </tr>\
                     <tr>\
                        <td style='padding-top:10px'>\
                        </td>\
                        <td style='padding-top:10px'>\
                         <div>\
                             <input class='but' id='txtSubmit' type='button' value='发布' onclick=\"SubmitEditions('EditionsModify',"+FEditionsId+")\"/>\
                         </div>\
                        </td>\
                    </tr>\
                </table>";
                    
            $.EditBox(elem, "修改本外号", 400, 230, vHtml);      
        }
}

// 获取最新回复
function GetAllEditionsManege(APageNo) {
  FPageNo = APageNo;
 $.ajax({
        url: "EditionsManegeRepeater.aspx?PageNo=" + escape(APageNo) + "&PageSize=" + escape(50) + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
        if (data !="") {
             var vResult = eval(data);
             $("#content_EditionsManage").html(vResult[2]);
             if (vResult[1] > 0) {
                $.ChangePage(vResult[0], APageNo - 1, vPageSize, EditionsManegeCallBack);
              }
            else {
               $("#Pagination").html("");
            } 
        }
       }
    });
    
    //回调函数 
    function EditionsManegeCallBack(currentno){
      GetAllEditionsManege(currentno + 1);
    }
}

//号外发布
function EditionsPublished(AEditionId)
{
  $.ajax({
        url: "SubjectHandler.ashx?ActionName=EditionsPublished&EditionId=" + AEditionId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
           if (data == "SUCCESS") {
              GetAllEditionsManege(FPageNo);
            }
            else {
            alert(data);
            }
        }
    });
}

//号外不发布
function EditionsNoPulish(AEditionId)
{
 $.ajax({
        url: "SubjectHandler.ashx?ActionName=EditionsNoPulish&EditionId=" + AEditionId + "&time=" + new Date().toString(),
        type: 'GET',
        success: function(data) {
           if (data == "SUCCESS") {
              GetAllEditionsManege(FPageNo);
            }
            else {
            alert(data);
            }
        }
    });
}

//导航到新页面
function LocationNewPage(Url) {
    if (!JudgeLogin(FUserId)) {
        return;
    }

    window.open(Url);
}
