/**************************************************************页面js***********************************************************/
$(function () {
    $('.editordiv').wysiwyg();
    $(".ui-sortable").sortable({ dropOnEmpty: true, start: function (event, ui) {
        // QuesDivCheck($("#" + ui.item.context.id));
    }
    });
});
//得到事件
function getEvent() {
    if (window.event) { return window.event; }
    func = getEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if ((arg0.constructor == Event || arg0.constructor == MouseEvent
                || arg0.constructor == KeyboardEvent)
                || (typeof (arg0) == "object" && arg0.preventDefault
                && arg0.stopPropagation)) {
                return arg0;
            }
        }
        func = func.caller;
    }
    return null;
}
//阻止冒泡
function cancelBubble() {
    var e = getEvent();
    if (window.event) {
        //e.returnValue=false;//阻止自身行为
        e.cancelBubble = true; //阻止冒泡
    } else if (e.preventDefault) {
        //e.preventDefault();//阻止自身行为
        e.stopPropagation(); //阻止冒泡
    }
}

//选项卡
//$('#myTab a').click(function (e) {
//    e.preventDefault()
//    $(this).tab('show')
//});

///添加字段展现
function QuesAndBtnShow() {
    if ($("#FormQuesTypelist").is(":hidden")) {
        $("#FormAddBtn").hide();
        $("#FormQuesTypelist").show();
    } else {
        $("#FormAddBtn").show();
        $("#FormQuesTypelist").hide();
    }
}

///是否开启问卷密码
function IsOpenPwd() {
    if ($("#AskVolume_OpenPwd").val() > 0) {
        $("#AskVolume_PwdText").hide();
        $("#AskVolume_Pwd").hide();
    } else {
        $("#AskVolume_PwdText").show();
        $("#AskVolume_Pwd").show();
    }
}

function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}
///初始化右侧html
function ClearRigHtml() {
    cancelBubble();
    $("#Radio_ShortRadio").find(".RadioOption").remove();
    if ($("#right_div").is(":hidden")) {
        $("#right_div").show();
    } else {
        if (!confirm("尚未保存右侧属性设置，是否退出右侧设置?")) {
            $("#FormAddBtn").show();
            $("#FormQuesTypelist").hide();
            return false;
        }
    }
    $(".Rtype").each(
    function () {
        $(this).hide();
    });
    $("#QuesDiv").find("div").each(
    function () {
        $(this).removeClass("panel-primary");
    });
    return true;
}
///选题方法
function AddQuest(objtype) {
    if (!ClearRigHtml()) { return; }
    if (objtype != 5) {//题目
        AddShortanswer(null, objtype);
    } else {//标题
        AddShortDivTit(null);
    }
    QuesAndBtnShow();
}
///绑定每道题的点击
function QuesDivCheck(obj) {
    if (!ClearRigHtml()) { return; }
    var quesid = $(obj).attr("id");
    var data = $(obj).attr("data");

    $("#" + quesid).addClass("panel-primary");
    if (parseInt(data) != 5) {//题目
        AddShortanswer(quesid, data);
    } else {//标题
        AddShortDivTit(quesid);
    }
}
///显示获取层次
function GetShortDivTit() {
    var str = "<option value=\"0\">无</option>";
    $("#QuesDiv").find(".Lv").each(function () {
        if ($(this).attr("title") != null) {
            str += "<option value=\"" + $(this).attr("id") + "\">" + $(this).attr("title") + "</option>";
        }
    });
    return str;
}
///是否开启逻辑跳转

function TopicOption_JumpShow(obj, val, Option) {//对象 自己题目id 选项id
    var Jump = $(obj).val();
    if (Jump == "0") {
        $(obj).parent().parent().find(".JumpTopic_Div").each(function () {
            $(this).show();
            //显示题目列表
            $("#" + Option + "_TopicOption_JumpTopic_ID").html("");
            $("#" + Option + "_TopicOption_JumpTopic_ID").append("<option value=\"0\">请选择</option>");
            var VolumeTopicArray = GetAllAskVolumeTopicArray();
            $(VolumeTopicArray).each(function (i, obj) {
                if (obj.AskVolumeTopic_ID != val) {
                    $("#" + Option + "_TopicOption_JumpTopic_ID").append("<option value=\"" + obj.AskVolumeTopic_ID + "\">" + obj.AskVolumeTopic_Name + "</option>");
                }
            });
        });
    } else {
        $(obj).parent().parent().find(".JumpTopic_Div").each(function () {
            $(this).hide();
        });
    }
    cancelBubble();
}

///逻辑跳转保存
function TopicOption_JumpSave(obj, optionId) {
    var val = $(obj).val();
    if (val != "0") {
        var option = GetTKS_AskVolumeTopicOptionArrayByTopicOption_ID(optionId);
        option.TopicOption_JumpTopic_ID = val;
        option.TopicOption_Jump = 0;
        EditTKS_AskVolumeTopicOptionArray(option);

    }
}

///Html添加题目选项
function AddTopicOptionInHtml(type) {
    $("#Radio_ShortRadio").append("<div  class=\"input-group mr5 RadioOption\"><span class=\"input-group-addon \">选项</span><input type=\"text\" class=\"form-control\"><span class=\"input-group-addon btn-default \" onclick=\"RemoveTopicOptionInHtml(this);\"><span class=\"glyphicon glyphicon-remove\"></span></span></div>");
}
///Html删除题目选项
function RemoveTopicOptionInHtml(obj) {
    if (confirm("是否删除此选项？")) {
        $(obj).parent().remove();
    }
}

/***********************************************************************标题*******************************************************************************/
///根据标题对象 生成html  参数:对象
function GetAddTKS_AskVolumeTitleHtml(obj, oldFid) {
    var AskVolumeTitle_Title = obj.AskVolumeTitle_Name;
    var fid = obj.AskVolumeTitle_Fid;
    if ($("#" + obj.AskVolumeTitle_ID).length == 0) {//新增
        if (fid != "0") {
            $("<div id=\"" + obj.AskVolumeTitle_ID + "\" data=\"5\"   class=\"panel panel-primary ui-sortable Lv w95auto\" title=\"" + obj.AskVolumeTitle_Name + "\" ><span id=\"" + obj.AskVolumeTitle_ID + "_AskVolumeTitle_Title\" class=\"bg-info\"\>" + obj.AskVolumeTitle_Name + "</span>  <span onclick=\"DeleteAsk(2,'" + obj.AskVolumeTitle_ID + "');\" class=\"glyphicon glyphicon-remove\"></span><button title=\"设置\" class=\"btn  btn-sm btn-primary pull-right\" onclick=\"QuesDivCheck($('#" + obj.AskVolumeTitle_ID + "'));\"><span class=\"glyphicon glyphicon-cog \"></span></button></div>").appendTo($("#" + fid));
        } else {
            $("#QuesDiv").append("<div id=\"" + obj.AskVolumeTitle_ID + "\" data=\"5\"  class=\"panel panel-primary ui-sortable Lv w95auto\" title=\"" + obj.AskVolumeTitle_Name + "\" ><span id=\"" + obj.AskVolumeTitle_ID + "_AskVolumeTitle_Title\" class=\"bg-info\"\>" + obj.AskVolumeTitle_Name + "</span><span onclick=\"DeleteAsk(2,'" + obj.AskVolumeTitle_ID + "');\" class=\"glyphicon glyphicon-remove\"></span> <button title=\"设置\" class=\"btn  btn-sm btn-primary pull-right\" onclick=\"QuesDivCheck($('#" + obj.AskVolumeTitle_ID + "'));\"><span class=\"glyphicon glyphicon-cog \"></span></button></div>");
        }
    } else {//修改
        if (oldFid != fid) {
            var to = $("#" + obj.AskVolumeTitle_ID).clone(true, true);
            $("#" + obj.AskVolumeTitle_ID).remove();
            if (fid != "0") {//加入层次
                $(to).appendTo($("#" + fid));
            } else {
                $(to).appendTo($("#QuesDiv"));
            }
        }
        $("#" + obj.AskVolumeTitle_ID + "_AskVolumeTitle_Title").html(obj.AskVolumeTitle_Name);
    }

}
///添加标题
function AddShortDivTit(id) {
    $("#AskVolumeTitle_Fid").empty();
    $("#AskVolumeTitle_Fid").append(GetShortDivTit());
    $("#Right_ShortType5").show();
    var oldFid = "";
    if (id != null && id != "null" && id != "") {
        var TKS_AskVolumeTitle = GetTKS_AskVolumeTitleArrayByID(id);
        $("#AskVolumeTitle_Title").val(TKS_AskVolumeTitle.AskVolumeTitle_Name);
        $("#AskVolumeTitle_Fid").val(TKS_AskVolumeTitle.AskVolumeTitle_Fid);
        oldFid = TKS_AskVolumeTitle.AskVolumeTitle_Fid;
    }
    $("#BtnQuesType5").attr("onclick", "IsOkEveryQues(5,'" + id + "','" + oldFid + "');");
}


/***********************************************************************根据初始化题目对象生成html*******************************************************************************/
///根据题目对象 生成html 
function GetAddAskVolumeTopicHtml(obj, oldFid) {
    var AskVolumeTopic_ID = obj.AskVolumeTopic_ID;
    var AskVolumeTopic_Name = obj.AskVolumeTopic_Name;
    var AskVolumeTopic_Dis = obj.AskVolumeTopic_Dis;
    var AskVolumeTopic_IsNull = obj.AskVolumeTopic_IsNull;
    var isnull = "开启";
    if (AskVolumeTopic_IsNull != "0") {
        isnull = "关闭";
    }
    ///判断类型
    var strtype = "";
    switch (parseInt(obj.AskVolumeTopic_Type)) {
        case 1:
            strtype = "(问答题)";
            break;
        case 2:
            strtype = "(单选题)";
            break;
        case 3:
            strtype = "(多选题)";
            break;
    }
    var fid = obj.AskVolumeTopic_Fid;
    if ($("#" + AskVolumeTopic_ID).length == 0)//新增
    {  	//如果有层次
        var setstr = "<span onclick=\"DeleteAsk(1,'" + AskVolumeTopic_ID + "');\" class=\"glyphicon glyphicon-remove\"></span><button onclick=\"QuesDivCheck($('#" + AskVolumeTopic_ID + "'));\"  class=\"btn  btn-sm btn-primary pull-right\" title=\"设置\"><span class=\"glyphicon glyphicon-cog \"></span></button>"
        if (fid != "0") {
            $("<div data=\"" + obj.AskVolumeTopic_Type + "\"  id=\"" + AskVolumeTopic_ID + "\" class=\"input-group form-control panel-primary ques ui-sortable\"><p>标题 " + strtype + setstr + "</p>  <div id=\"" + AskVolumeTopic_ID + "_Topic_Name\" class=\"input-group form-control\">" + AskVolumeTopic_Name + " </div><p>描述</p><div id=\"" + AskVolumeTopic_ID + "_Topic_Dis\" class=\"input-group form-control\">" + AskVolumeTopic_Dis + " </div><div class=\"input-group pt10 \"><span class=\"input-group-addon  \" >是否必填:</span><input id=\"" + AskVolumeTopic_ID + "_IsNull\" type=\"text\" value=\"" + isnull + "\" readonly=\"readonly\" /></div></div>").appendTo($("#" + fid));
        } else {
            $("#QuesDiv").append("<div data=\"" + obj.AskVolumeTopic_Type + "\"   id=\"" + AskVolumeTopic_ID + "\" class=\"input-group form-control panel-primary ques ui-sortable\"><p>标题 " + strtype + setstr + "</p>  <div id=\"" + AskVolumeTopic_ID + "_Topic_Name\" class=\"input-group form-control\">" + AskVolumeTopic_Name + " </div><p>描述</p><div id=\"" + AskVolumeTopic_ID + "_Topic_Dis\" class=\"input-group form-control\">" + AskVolumeTopic_Dis + " </div><div class=\"input-group pt10 \"><span class=\"input-group-addon  \" >是否必填:</span><input id=\"" + AskVolumeTopic_ID + "_IsNull\" type=\"text\" value=\"" + isnull + "\" readonly=\"readonly\" /></div></div>");
        }
    } else {//修改
        if (oldFid != fid) {//层次无变化时
            var to = $("#" + AskVolumeTopic_ID).clone(true, true);
            $("#" + AskVolumeTopic_ID).remove();
            if (fid != "0") {
                $(to).appendTo($("#" + fid));
            } else {
                $(to).appendTo($("#QuesDiv"));
            }
        }
        $("#" + AskVolumeTopic_ID + "_Topic_Name").html(AskVolumeTopic_Name);
        $("#" + AskVolumeTopic_ID + "_Topic_Dis").html(AskVolumeTopic_Dis);
        $("#" + AskVolumeTopic_ID + "_IsNull").val(isnull);
    }
    $("#" + AskVolumeTopic_ID).find(".RadioOption").remove();
    //添加选项
    var OptionArray = GetTKS_AskVolumeTopicOptionArrayByTopic_ID(AskVolumeTopic_ID);
    $.each(OptionArray, function (i, Option) {
        if (Option.TopicOption_Jump == "0") {
            $("#" + AskVolumeTopic_ID + "_Topic_Name").after("<div class=\"panel mr5 RadioOption\"><div class=\"input-group\"><span class=\"input-group-addon \">选项</span><input type=\"text\" id=\"" + Option.TopicOption_ID + "_Option\" value=\"" + Option.TopicOption_Name + "\" readonly=\"readonly\"  class=\"form-control\"> <span class=\"input-group-addon \">是否开启逻辑跳转</span><select class=\"form-control TopicOption_Jump\" onchange=\"TopicOption_JumpShow(this,'" + AskVolumeTopic_ID + "','" + Option.TopicOption_ID + "');\" ><option selected=\"selected\" value=\"0\">开启</option><option  value=\"1\">关闭</option></select></div><div class=\" input-group JumpTopic_Div \"  ><span class=\"input-group-addon \">选择跳转题目</span><select id=\"" + Option.TopicOption_ID + "_TopicOption_JumpTopic_ID\" class=\"form-control TopicOption_JumpTopic_ID\" onchange=\"TopicOption_JumpSave(this,'" + Option.TopicOption_ID + "')\" ><option value=\"" + Option.TopicOption_JumpTopic_ID + "\"></option></select></div></div>");
            var VolumeTopicArray = GetAllAskVolumeTopicArray();
            $(VolumeTopicArray).each(function (i, obj) {
                if (obj.AskVolumeTopic_ID != Option.TopicOption_JumpTopic_ID) {
                    $("#" + Option.TopicOption_ID + "_TopicOption_JumpTopic_ID").append("<option value=\"" + obj.AskVolumeTopic_ID + "\">" + obj.AskVolumeTopic_Name + "</option>");
                } else {
                    $("#" + Option.TopicOption_ID + "_TopicOption_JumpTopic_ID").append("<option selected=\"selected\"value=\"" + obj.AskVolumeTopic_ID + "\">" + obj.AskVolumeTopic_Name + "</option>");
                }
            });
        } else {
            $("#" + AskVolumeTopic_ID + "_Topic_Name").after("<div class=\"panel mr5 RadioOption\"><div class=\"input-group\"><span class=\"input-group-addon \">选项</span><input type=\"text\" id=\"" + Option.TopicOption_ID + "_Option\" value=\"" + Option.TopicOption_Name + "\" readonly=\"readonly\"  class=\"form-control\"> <span class=\"input-group-addon \">是否开启逻辑跳转</span><select class=\"form-control TopicOption_Jump\" onchange=\"TopicOption_JumpShow(this,'" + AskVolumeTopic_ID + "','" + Option.TopicOption_ID + "');\" ><option  value=\"0\">开启</option><option selected=\"selected\" value=\"1\">关闭</option></select></div><div class=\" input-group JumpTopic_Div \"  style=\"display:none;\"><span class=\"input-group-addon \">选择跳转题目</span><select id=\"" + Option.TopicOption_ID + "_TopicOption_JumpTopic_ID\" class=\"form-control TopicOption_JumpTopic_ID\" onchange=\"TopicOption_JumpSave(this,'" + Option.TopicOption_ID + "')\" ></select></div></div>");
        }

    });

}

/***********************************************************************右侧html属性初始化*******************************************************************************/

function AddShortanswer(id, type) {
    $("#Right_ShortType1").show();
    $("#AskVolumeTopic_FidType1").empty();
    $("#AskVolumeTopic_FidType1").append(GetShortDivTit());
    var oldFid = "";
    if (id != null && id != "null" && id != "") {
        Topic = GetAskVolumeTopicArrayByID(id);
        $("#Right_TopicOption_NameType1").html(Topic.AskVolumeTopic_Name);
        $("#Right_AskVolumeTopic_DisType1").val(Topic.AskVolumeTopic_Dis);
        $("#Right_VolumeTopic_IsNullType1").val(Topic.AskVolumeTopic_IsNull);
        $("#AskVolumeTopic_FidType1").val(Topic.AskVolumeTopic_Fid);
        oldFid = Topic.AskVolumeTopic_Fid;
        //显示选项
        var OptionArray = GetTKS_AskVolumeTopicOptionArrayByTopic_ID(id);
        $.each(OptionArray, function (i, Option) {
            $("#Radio_ShortRadio").append("<div class=\"input-group mr5 RadioOption\"><span class=\"input-group-addon \">选项</span><input type=\"text\" value=\"" + Option.TopicOption_Name + "\" class=\"form-control\"><span class=\"input-group-addon btn-default \" onclick=\"RemoveTopicOptionInHtml(this);\"><span class=\"glyphicon glyphicon-remove\"></span></span></div>");
        });
    }
    switch (parseInt(type)) {
        case 1: //问答
            break;
        case 2: //单选
            $("#Radio_ShortRadio").show();
            break;
        case 3: //多选
            $("#Radio_ShortRadio").show();
            break;
    }
    $("#BtnQuesType1").attr("onclick", "IsOkEveryQues(" + type + ",'" + id + "','" + oldFid + "');");
}
///保存题目对象插入到html
function IsOkEveryQues(type, quesid, oldFid) {
    switch (type) {
        case 1: //问答题
            var VolumeTopic = AddQuesAll(quesid, type);
            GetAddAskVolumeTopicHtml(VolumeTopic, oldFid);
            break;
        case 2: //单选题
            var VolumeTopic = AddQuesAll(quesid, type, oldFid);
            AddAskVolumeTopicOption(VolumeTopic);
            GetAddAskVolumeTopicHtml(VolumeTopic, oldFid);
            $("#Radio_ShortRadio").hide();
            break;
        case 3: //多选题
            var VolumeTopic = AddQuesAll(quesid, type, oldFid);
            AddAskVolumeTopicOption(VolumeTopic);
            $("#Radio_ShortRadio").hide();
            GetAddAskVolumeTopicHtml(VolumeTopic, oldFid);
            break;
        case 5: //标题层次
            var AskVolumeTitle_Title = $("#AskVolumeTitle_Title").val();
            $("#Right_ShortType5").hide();
            var fid = $("#AskVolumeTitle_Fid").val();
            var AskVolumeTitle_Title = $("#AskVolumeTitle_Title").val();
            var fid = $("#AskVolumeTitle_Fid").val();
            if (fid == quesid) {
                showTipsMsg("不能选取层次", 2000, 3);
                return;
            }
            var AskVolumeTitle = new TKS_AskVolumeTitle(quesid, AskVolumeTitle_Title, fid, ""); ///id,标题名,标题父级,标题顺序
            //将对象插入到数组里
            EditTKS_AskVolumeTitleArray(AskVolumeTitle);
            GetAddTKS_AskVolumeTitleHtml(AskVolumeTitle, oldFid);
            $("#Right_ShortType5").hide();
            break;
    }

    $("#right_div").hide();
}
///获取属性设置 初始化题目对象
function AddQuesAll(quesid, type) {
    $("#Right_ShortType1").hide();
    //  $("#" + quesid).removeClass("panel-primary");
    var AskVolumeTopic_Name = $("#Right_TopicOption_NameType1").html();
    var AskVolumeTopic_Dis = $("#Right_AskVolumeTopic_DisType1").val();
    var isnull = $("#Right_VolumeTopic_IsNullType1").val();
    var fid = $("#AskVolumeTopic_FidType1").val();
    ///标题id,题目名,题目顺序,题目描述,题型,是否必填（0：开启，1关闭）,FID（所属层次）
    var VolumeTopic = new AskVolumeTopic(quesid, AskVolumeTopic_Name, "0", AskVolumeTopic_Dis, type, isnull, fid);
    var isok = EditAskVolumeTopicArrayById(VolumeTopic); //先判断是否存在此题目，如果存在 直接修改，不存在 添加
    return VolumeTopic;
}

///获取属性设置 初始化题目选项对象
function AddAskVolumeTopicOption(Quesobj) {
    DelTKS_AskVolumeTopicOptionArrayByTopic_ID(Quesobj.AskVolumeTopic_ID); //删除该题目中的选项
    /// id,题目id,选项名,选项顺序,选项统计数,是否开启跳转(0：开启，1关闭),跳转题目id,选项理由
    var index = 0;
    $("#Radio_ShortRadio").find("input[type='text']").each(
    function () {
        var VolumeTopicOption = new TKS_AskVolumeTopicOption("", Quesobj.AskVolumeTopic_ID, $(this).val(), 0, 0, 1, null, null);
        AddTKS_AskVolumeTopicOptionArray(VolumeTopicOption);
        index++;
    }
    );
    if (index < 2) {
        showTipsMsg('选项至少为2个', 2000, 3);
        return false;
    } else {
        return true;
    }
}
/**************************************************************保存信息***********************************************************/
function BtnSave() {
    SaveTKS_AskVolume();
}
/**************************************************************保存问卷信息***********************************************************/
function SaveTKS_AskVolume() {
    if (!CheckTKS_AskVolume()) {
        return;
    }
    var IsEdit = "";
    var AskVolume_ID = "";
    if (QueryString("key") != "") {
        AskVolume_ID = QueryString("key");
        IsEdit = 1;
    }
    var Topname = $("#Volume_Name").val();
    var Volume_Start = $("#Volume_Start").val();
    var Volume_End = $("#Volume_End").val();
    var AskVolume_OpenPwd = $("#AskVolume_OpenPwd").val();
    var AskVolume_Pwd = $("#AskVolume_Pwd").val();
    var Volume_Dis = $("#Volume_Dis").val();
    var Volume_BtnDis = $("#Volume_BtnDis").val();

    QuesSotr();
    ///问卷名,创建时间,开始时间,结束时间,创建人,创建id,问卷是否开启密码（0：开启，1关闭）,问卷密码,问卷描述,提交说明
    var ask = new TKS_AskVolume(AskVolume_ID, Topname, "", Volume_Start, Volume_End, "", "", AskVolume_OpenPwd, AskVolume_Pwd, Volume_Dis, Volume_BtnDis);
    ask.AskVolumeTopicArray = JSON.stringify(AskVolumeTopicArray);
    ask.TKS_AskVolumeTitleArray = JSON.stringify(TKS_AskVolumeTitleArray);
    ask.TKS_AskVolumeTopicOptionArray = JSON.stringify(TKS_AskVolumeTopicOptionArray);
    var askjson = JSON.stringify(ask);
    var param = "action=AddAskVolume&IsEdit=" + IsEdit + "&askobj=" + askjson;
    $("#imgloading").show();
    getAjax("/Training/AskVolume/AskVolume.ashx", param, function (rs) {
        if (rs == "ok") {
            $("#imgloading").hide();
            showTipsMsg('保存成功', 2000, 4);
            location.href = "/Training/AskVolume/AskVolume_List.aspx";
            //location.reload();
        } else {
            $("#imgloading").hide();
            showTipsMsg('保存失败', 2000, 4);
        }
    });
}
function QuesSotr() {
    //获取题目区第一层数据数据
    $("#QuesDiv").children().each(function (i, obj) {
        var json = null;
        json = GetTKS_AskVolumeTitleArrayByID($(obj).attr("id"));
        if (json != null) {//如果是否为标题 不为空则为标题
            json.SortIndex = i;
            EditTKS_AskVolumeTitleArray(json);
            QuesSotrTo(obj);
        } else {//题目
            json = GetAskVolumeTopicArrayByID($(obj).attr("id"));
            if (json != null) {
                json.SortIndex = i;
                EditAskVolumeTopicArrayById(json);
            }
        }
    });
}
function QuesSotrTo(obj) {
    //获取题目区第一层数据数据
    $(obj).children().each(function (i, obj) {
        var json = "";
        json = GetTKS_AskVolumeTitleArrayByID($(obj).attr("id"));
        if (json != null) {//判断是否为标题 不为空则为标题
            json.SortIndex = i;
            EditTKS_AskVolumeTitleArray(json);
            QuesSotrTo(obj);
        } else {
            json = GetAskVolumeTopicArrayByID($(obj).attr("id"));
            if (json != null) {
                json.SortIndex = i;
                EditAskVolumeTopicArrayById(json);
            }

        }
    });
}
/**************************************************************验证***********************************************************/
//试卷属性验证
function CheckTKS_AskVolume() {
    var isok = true;
    if ($("#Volume_Name").val() == "") {
        showTipsMsg('问卷名不能为空', 2000, 3);
        return false;
    }
    if ($("#AskVolume_OpenPwd") == "0") {
        if ($("#AskVolume_Pwd").val() != "") {
            showTipsMsg('开启密码后，密码项不能为空', 2000, 3);
            isok = false;
            return false;
        }
    }
    
    //验证选项数量
    $(AskVolumeTopicArray).each(function (i, obj) {
        if (parseInt(obj.AskVolumeTopic_Type) != 1) {
            if (GetTKS_AskVolumeTopicOptionArrayCountByTopic_ID(obj.AskVolumeTopic_ID) <= 1) {
                showTipsMsg('选项至少为2个', 2000, 3);
                $(this).css("border", "1px solid red");
                var dqqh = $("#" + obj.AskVolumeTopic_ID).offset().top - 50; // 当前题目高度
                $('html,body').animate({
                    scrollTop: dqqh + 'px'
                }, 400);
                isok = false;
                return false;
            }
        }
    });
    return isok;
}

//删除
function DeleteAsk(AskType, askid) {
    showConfirmMsg("将删除所包含的所有内容。确定删除吗？", function (rs) {
        if (AskType == 1) {//题目
            DelTKS_AskVolumeTopicArrayByTopic_ID(askid);
            $("#" + askid).remove();
        } else {//标题
            DelTitle(askid);
            //获取所包含的标题 并删除
            $("#" + askid).find(".w95auto").each(function () {
                DelTitle($(this).prop("id"));
            });
            $("#" + askid).find(".ques").each(function () {
                DelTKS_AskVolumeTopicArrayByTopic_ID($(this).prop("id"));
            });
            $("#" + askid).remove();
        }
    });
}


