
var m_QrGroupId = "";//快捷回复组ID
var m_QrId = "";//快捷回复ID
var m_JsonResult = [];//快捷回复缓存
var m_groupname = "";//储存选中知识问答库回复组的名称
var m_qname = "";//储存选中知识问答库回复标签的名称
var m_frist = 1;//初始化界面时，第一个标签组展开（1为初次加载页面）
var m_isGroupSubmit = true;//判断组顺序是否提交过,提交过true，没提交过false
var isSelectIndex = -1;//移动组内回答时，当前所在的组的下标,用于设置改组展开状态
var m_Parentid = "";//选中组内回复的ID
$(function () {
    //charout();
    $("#myPageAlert").hide();
    DataBind();
    PageLoadTrees();

});

function DataBind() {
    $(".loading").show();
    $(".loadingcover").show();
    var strParaJson = $.toJSON({
        question: '',
        source: 0
    });
    manageObj.getquiztreelist(strParaJson);
}

//获取快捷回复树型菜单结果回调方法
function AsyncGetQuizTreeListResult(jsonTree) {
    if (jsonTree.success) {
        $("#divTree").html(ResultShow(jsonTree));
        if (isSelectIndex != -1) {
            $("#group" + isSelectIndex).removeClass().addClass("inactive-m inactives-m");
            $("#quiz" + isSelectIndex).attr("style", "display: block;");
        }
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonTree.error);
    }

    PageLoadTrees();
    if (m_Parentid != "") {
        $("#selectGroup").val(m_Parentid);
    }
    $(".loadingcover").hide();
    $(".loading").hide();
}

function ResultShow(jsonTree) {
    var objselectGroup = $("#selectGroup");
    objselectGroup.empty();//清空
    m_JsonResult = jsonTree;
    var strTreeContent = "";//树型菜单内容
    strTreeContent += "<div class=\"input-group\"><input id=\"txttag\"  name=\"txttag\" type=\"text\" class=\"form-control input-txt-l\" placeholder=\"关键字/回复\"><span class=\"input-group-btn\"><button onclick=\"ChangeReplyInput()\" class=\"btn btn-default\" type=\"button\" style=\"border-radius:0\"><i class=\"glyphicon glyphicon-search\"></i></button></span><span class=\"input-group-btn\"><button class=\"btn btn-default\"  onclick=\"resetTag()\" type=\"button\"><i class=\"glyphicon glyphicon-trash\"></i></button></span></div>";
    var strDeptCss = "";
    for (var i = 0; i < jsonTree.result.list.length; i++) {
        //当前没有字段sort的时候，给默认值，解决老版本兼容问题
        if (m_JsonResult.result.list[i].sort == "" || m_JsonResult.result.list[i].sort == undefined || m_JsonResult.result.list[i].sort == null) {
            m_isGroupSubmit = false;//没提交过是false
        } else {
            m_isGroupSubmit = true;//提交过是true
        }

        var jsonItem = jsonTree.result.list[i];
        if (m_frist == 1) {
            strDeptCss = i == 0 ? "inactive-m inactives-m" : "inactive-m";
        } else {
            strDeptCss = "inactive-m";
        }

        strTreeContent += "<ul class=\"yiji-m\">";
        strTreeContent += "<li>";
        strTreeContent += "<a id=\"group" + i + "\" href=\"#divEditDept\" class=\"" + strDeptCss + "\" data-toggle=\"tab\" onclick=\"SetEditGroupBind('" + jsonItem.qgid + "','" + jsonItem.qgname + "');\"><span class=\"pull-left\" style=\"width:108px;\">" + jsonItem.qgname + "</span>";

        //判断组内标签能否向上向下移动
        if (i != 0 && i != m_JsonResult.result.list.length - 1) {
            //所选分组内既不是第一个，也不是最后一个（分组数大于1个）
            strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-up\" style=\"margin-right:5px;\" onclick=\"QuizGroupTop(" + i + ")\"></i>";
            strTreeContent += "<i class=\"fa fa-angle-down\" onclick=\"QuizGroupBottom(" + i + ")\"></i></div>";
        } else if (i == 0 && i != m_JsonResult.result.list.length - 1) {
            //所选分组内标签是当前分组的第一个标签是第一个（分组数大于1个）
            strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-down\" style=\"margin-top: 10px;\" onclick=\"QuizGroupBottom(" + i + ")\"></i></div>";
        } else if (i != 0 && i == m_JsonResult.result.list.length - 1) {
            //所选分组内标签是当前分组内的最后一个标签（分组数大于1个）
            strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-up\" style=\"margin-top: 10px;\" onclick=\"QuizGroupTop(" + i + ")\"></i></div>";
        } else if (i == 0 && i == m_JsonResult.result.list.length - 1) {
            //所选分组内仅有一个标签
        }

        strTreeContent += "<span class=\"label pull-left badge-color\">" + jsonItem.quiz.length + "</span>";
        strTreeContent += "</a>";
        if (m_frist == 1) {
            if (i == 0) {
                strTreeContent += "<ul id=\"quiz" + i + "\" style=\"display: block;\">";
            } else {
                strTreeContent += "<ul id=\"quiz" + i + "\" style=\"display: none;\">";
            }
            m_frist = 2;
        } else {
            strTreeContent += "<ul id=\"quiz" + i + "\" style=\"display: none;\">";
        }
        for (var j = 0; j < jsonItem.quiz.length; j++) {


            var tagItem = jsonItem.quiz[j];
            strTreeContent += "<li><a href=\"#divEditPerson\" data-toggle=\"tab\" onclick=\"SetEditTagBind('" + tagItem.qid + "','" + tagItem.qgid + "','" + tagItem.qquestion + "','" + encodeURI(tagItem.qanswer) + "','" + jsonItem.qgname + "')\">" + tagItem.qquestion;

            //判断组内标签能否向上向下移动
            if (j != 0 && j != jsonItem.quiz.length - 1) {
                //所选分组内既不是第一个，也不是最后一个（分组数大于1个）
                strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-up\" onclick=\"QuizTop(" + i + "," + j + ")\"></i>";
                strTreeContent += "<i class=\"fa fa-angle-down\" onclick=\"QuizBottom(" + i + "," + j + ")\"></i></div>";
            } else if (j == 0 && j != jsonItem.quiz.length - 1) {
                //所选分组内标签是当前分组的第一个标签是第一个（分组数大于1个）
                strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-down\" style=\"margin-top: 10px;\" onclick=\"QuizBottom(" + i + "," + j + ")\"></i></div>";
            } else if (j != 0 && j == jsonItem.quiz.length - 1) {
                //所选分组内标签是当前分组内的最后一个标签（分组数大于1个）
                strTreeContent += "<div class=\"pull-right\"><i class=\"fa fa-angle-up\"  style=\"margin-top: 10px;\" onclick=\"QuizTop(" + i + "," + j + ")\"></i></div>";
            } else if (j == 0 && j == jsonItem.quiz.length - 1) {
                //所选分组内仅有一个标签
            }
            strTreeContent += "</a></li>";
        }

        strTreeContent += "</ul>";
        strTreeContent += "</li>";
        strTreeContent += "</ul>";

        //DDL标签组
        objselectGroup.append("<option value='" + jsonItem.qgid + "'>" + jsonItem.qgname + "</option>");
    }
    return strTreeContent;
}

//树形菜单高度设置
function PageLoadTrees() {
    $(".left-list-l").css({
        height: $(window).height() - 40
    });

    $(".talklist-m").css({
        height: $(window).height() - 100
    });
    $("#right").css({
        height: $(window).height() - 40
    });
    $("#left").css({
        height: $(window).height() - 40
    });
    $(".loadingcover").css({
        height: $(window).height() - 40
    });
    initTree();
}

//选中组时
function SetEditGroupBind(value, name, type) {
    m_QrGroupId = value;//标签组ID
    m_groupname = name;
    if (m_QrGroupId.length == 0) {
        $("#DeleteQuizGroup").hide();
    } else {
        $("#DeleteQuizGroup").show();
    }

    $("#txtGroupName").val(name);
    $("#spDeleteGroupName").html(name);

    $("#txtGroupName").focus();
    if (type == "0") {
        $("#cbxGroupIsAll").prop("checked", true);
    } else {
        $("#cbxGroupIsAll").prop("checked", false);
    }

    $("#divEditGroup").removeClass("tab-pane fade").addClass("tab-pane fade active in");//显示
    $("#divEditTag").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏\
    $("#liCreatQuickTalkGroup").removeClass("active");
    $("#liCreatQuickTalk").removeClass("active");
}

//添加、修改组
function EditGroup() {
    var objtxtGroupName = $("#txtGroupName");

    objtxtGroupName.val($.trim(objtxtGroupName.val().replace(/["]/g, '').replace(/[']/g, '')));
    $("#spDeleteGroupName").html(objtxtGroupName.val());
    if (objtxtGroupName.val().length == 0) {
        ShowError("myPageAlert", "组名称不能为空！");
        objtxtGroupName.focus();
        return;
    }

    var jsonResult;

    if (m_QrGroupId.length == 0) {
        var number = 10001
        if (m_JsonResult.result.list.length > 0) {
            //添加查重
            number = m_isGroupSubmit ? Number(m_JsonResult.result.list[m_JsonResult.result.list.length - 1].sort) + 1 : "";
            for (var i = 0; i < m_JsonResult.result.list.length; i++) {
                if ($.trim($("#txtGroupName").val()) == m_JsonResult.result.list[i].qgname) {
                    ShowError("myPageAlert", "该问答组名称已存在！");
                    return;
                }
            }
        }
        $(".loading").show();
        $(".loadingcover").show();
        var strParaJson = $.toJSON({
            qgname: objtxtGroupName.val(), sort: number
        });
        manageObj.addquizkgroup(strParaJson);
    }
    else {
        //修改
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            if ($.trim($("#txtGroupName").val()) == m_JsonResult.result.list[i].qgname && $.trim($("#txtGroupName").val()) != m_groupname) {
                ShowError("myPageAlert", "该问答组名称已存在！");
                return;
            }
        }
        $(".loading").show();
        $(".loadingcover").show();
        var strParaJson = $.toJSON({
            qgid: m_QrGroupId, qgname: objtxtGroupName.val()
        });
        manageObj.updatequizgroup(strParaJson);
    }
}


//显示删除组对话框
function ShowDeleteGroup() {
    if (m_QrGroupId.length == 0) {
        return;
    }
    for (var i = 0; i < m_JsonResult.result.list.length; i++) {
        if (m_JsonResult.result.list[i].qgid == m_QrGroupId) {
            if (m_JsonResult.result.list[i].quiz.length > 0) {
                ShowError("myPageAlert", "此问答组下有问答，不能进行删除操作！");
                return;
            }
        }
    }
    $("#DeleteGroupModal").modal("show");

}
//提交删除组
function CommitGroupDelete() {
    $(".loading").show();
    $(".loadingcover").show();
    var strParaJson = $.toJSON({
        qgid: m_QrGroupId,
    });
    manageObj.deletequizkgroup(strParaJson);
}


//删除快捷回复组回调
function AsyncDeleteQuizGroupResult(jsonResult) {
    if (jsonResult.success) {
        $("#txtGroupName").val("");
        $("#cbxIsAll").attr("checked", false);

        $("#DeleteGroupModal").modal("hide");
        $("#divEditGroup").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏

        ShowMsg("myPageAlert", "操作成功！");

        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}

//变更快捷回复组结果回调方法
function AsyncUpdateQuizGroupResult(jsonResult) {

    if (jsonResult.success) {
        $("#txtGroupName").val("");
        $("#cbxIsAll").attr("checked", false);

        $("#DeleteGroupModal").modal("hide");
        $("#divEditGroup").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏

        ShowMsg("myPageAlert", "操作成功！");

        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}
//添加快捷回复回调
function AsyncAddQuizGroupResult(jsonResult) {
    if (jsonResult.success) {
        $("#txtGroupName").val("");

        $("#DeleteGroupModal").modal("hide");
        $("#divEditGroup").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏

        ShowMsg("myPageAlert", "操作成功！");

        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResulst.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}
//选中快捷回复时
function SetEditTagBind(qrid, parentid, qquestion, qanwser, zname) {
    m_Parentid = parentid;
    m_QrId = qrid;//ID
    m_qname = qquestion;//标签
    m_groupname = zname;//标签组
    var content = decodeURIComponent(qanwser);
    if (m_QrId.length > 0) {
        $("#DeleteQuiz").show();
        $("#spDeleteQuizName").html(qquestion);
        $("#txtTagName").val(qquestion);
        $("#selectGroup").val(parentid);
        $("#txtTagRemark").val(content);
    } else {
        //创建回答时
        $("#DeleteQuiz").hide();
        $("#txtTagName").val("");
        $('#selectGroup option:eq(0)').attr('selected', 'selected');
        $("#txtTagRemark").val("");
    }

    $("#txtTagName").focus();

    $("#divEditTag").removeClass("tab-pane fade").addClass("tab-pane fade active in");//显示
    $("#divEditGroup").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏
    $("#liCreatQuickTalkGroup").removeClass("active");
    $("#liCreatQuickTalk").removeClass("active");
}

//添加问答组
function EditTag() {
    var objtxtTagName = $("#txtTagName");
    var objselectGroup = $("#selectGroup");
    var objtxtTagRemark = $("#txtTagRemark");
    objtxtTagName.val($.trim(Canceller(objtxtTagName.val())));
    objselectGroup.val($.trim(objselectGroup.val()));
    objtxtTagRemark.val($.trim(Canceller(objtxtTagRemark.val())));

    if (m_JsonResult.result.list.length == 0) {
        ShowError("myPageAlert", "没有组，请先创建组!");
        return;
    }
    if (objtxtTagName.val().length == 0) {
        ShowError("myPageAlert", "名称不能为空！");
        objtxtTagName.focus();
        return;
    }
    if (objselectGroup.val() == null) {
        ShowError("myPageAlert", "未选择所属分组，若没有请先创建组");
        objselectGroup.focus();
        return;
    }
    if (objselectGroup.val().length == 0) {
        ShowError("myPageAlert", "，若没有请先创建组");
        objselectGroup.focus();
        return;
    }
    if (objtxtTagRemark.val().length == 0) {
        ShowError("myPageAlert", "回复内容不能为空！");
        objtxtTagRemark.focus();
        return;
    }

    var number = "";//当前组内标签的sort值
    for (var i = 0; i < m_JsonResult.result.list.length; i++) {
        if (m_JsonResult.result.list[i].qgid == objselectGroup.val()) {
            for (var j = 0; j < m_JsonResult.result.list[i].quiz.length; j++) {
                if (m_JsonResult.result.list[i].quiz[j].sort != "" && m_JsonResult.result.list[i].quiz[j].sort != undefined && m_JsonResult.result.list[i].quiz[j].sort != null) {
                    number = Number(m_JsonResult.result.list[i].quiz[m_JsonResult.result.list[i].quiz.length - 1].sort) + 1;
                    break;
                }
            }
            break;
        }
    }

    var jsonResult;

    if (m_QrId.length == 0) {
        //添加
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            var qlist = m_JsonResult.result.list[i];
            if (qlist.qgid == $.trim($("#selectGroup").val())) {
                for (var j = 0; j < qlist.quiz.length; j++) {
                    if ($.trim($("#txtTagName").val()) == qlist.quiz[j].qquestion) {
                        ShowError("myPageAlert", "该问答已存在！");
                        return;
                    }
                }
            }
        }
        $(".loading").show();
        $(".loadingcover").show();
        var strParaJson = $.toJSON({
            qgid: objselectGroup.val(),
            qquestion: $.trim(objtxtTagName.val()),
            qanswer: $.trim(objtxtTagRemark.val().replace(/\n/g, '\r\n')),
            type: 0,
            isopen: 0,
            sleeptime: "",
            sort: number
        });
        manageObj.addquiz(strParaJson);
    }
    else {
        //修改
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            var qlist = m_JsonResult.result.list[i];
            if ($("#selectGroup option:selected").text() == m_groupname && m_groupname == qlist.qgname) {
                for (var j = 0; j < qlist.quiz.length; j++) {
                    if ($.trim($("#txtTagName").val()) == qlist.quiz[j].qquestion && $.trim($("#txtTagName").val()) != m_qname) {
                        ShowError("myPageAlert", "该问答已存在！");
                        return;
                    }
                }
            } else if ($("#selectGroup option:selected").text() == qlist.qgname && $("#selectGroup option:selected").text() != m_groupname) {
                for (var j = 0; j < qlist.quiz.length; j++) {
                    if ($.trim($("#txtTagName").val()) == qlist.quiz[j].qquestion) {
                        ShowError("myPageAlert", "该问答已存在！");
                        return;
                    }
                }
            }
        }

        var strParaJson = $.toJSON({
            qid: m_QrId,
            qgid: objselectGroup.val(),
            qquestion: $.trim(objtxtTagName.val()),
            qanswer: $.trim(objtxtTagRemark.val().replace(/\n/g, '\r\n')),
            isopen: 0,
            sleeptime: "",
            sort: number
        });
        manageObj.updatequiz(strParaJson);
    }
}

//显示删除快捷回复对话框
function ShowDeleteTag() {
    if (m_QrId.length == 0) {
        return;
    }
    $("#DeleteTagModal").modal("show");
}
//提交删除部门
function CommitTagDelete() {
    $(".loading").show();
    $(".loadingcover").show();
    var strParaJson = $.toJSON({
        qid: m_QrId,
    });
    manageObj.deletequiz(strParaJson);
}

//变更快捷回复结果回调方法
function AsyncUpdateQuizResult(jsonResult) {
    if (jsonResult.success) {
        $("#txtTagName").val("");
        $("#txtTagRemark").val("");
        $('#selectGroup option:eq(0)').attr('selected', 'selected');

        $("#DeleteTagModal").modal("hide");
        $("#divEditTag").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏
        ShowMsg("myPageAlert", "操作成功！");
        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}
//删除快捷回复回调
function AsyncDeleteQuizResult(jsonResult) {
    if (jsonResult.success) {
        $("#txtTagName").val("");
        $("#txtTagRemark").val("");
        $('#selectGroup option:eq(0)').attr('selected', 'selected');

        $("#DeleteTagModal").modal("hide");
        $("#divEditTag").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏

        ShowMsg("myPageAlert", "操作成功！");

        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}
//添加快捷回复回调
function AsyncAddQuizResult(jsonResult) {
    if (jsonResult.success) {
        $("#txtTagName").val("");
        $("#txtTagRemark").val("");
        $('#selectGroup option:eq(0)').attr('selected', 'selected');

        $("#DeleteTagModal").modal("hide");
        $("#divEditTag").removeClass("tab-pane fade active in").addClass("tab-pane fade");//隐藏

        ShowMsg("myPageAlert", "操作成功！");

        DataBind();
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
}

//查询
function ChangeReplyInput() {
    var objselectGroup = $("#selectGroup");
    objselectGroup.empty();//清空
    var replaycondition = $.trim(Canceller($("#txttag").val()));
    if (replaycondition.length > 0) {
        var strTreeContent = "";
        strTreeContent += "<div class=\"input-group\"><input id=\"txttag\"  name=\"txttag\" type=\"text\" value=\"" + replaycondition + "\" class=\"form-control input-txt-l\" placeholder=\"关键字\"><span class=\"input-group-btn\"><button onclick=\"ChangeReplyInput()\" class=\"btn btn-default\" type=\"button\" style=\"border-radius:0\"><i class=\"glyphicon glyphicon-search\"></i></button></span><span class=\"input-group-btn\"><button class=\"btn btn-default\"  onclick=\"resetTag()\" type=\"button\"><i class=\"glyphicon glyphicon-trash\"></i></button></span></div>";

        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            var groupname = "";

            var reaplay = m_JsonResult.result.list[i];
            if (reaplay != null) {

                for (var k = 0; k < reaplay.quiz.length; k++) {
                    var itemTagName = reaplay.quiz[k].qanswer;
                    var itemcontent = reaplay.quiz[k].qquestion;
                    var addnum = 0;

                    if (itemTagName.indexOf(replaycondition) != -1 || itemcontent.indexOf(replaycondition) != -1) {
                        addnum++;

                        if (groupname != reaplay.qgname) {
                            strTreeContent += "<ul class=\"yiji-m\">";
                            strTreeContent += "<li>";
                            strTreeContent += "<a href=\"#divEditDept\" class=\"inactive-m\" data-toggle=\"tab\" onclick=\"SetEditGroupBind('" + reaplay.qgid + "','" + reaplay.qgname + "');\">" + reaplay.qgname + "<span class=\"label label-info pull-right badge-color\"></span></a>";
                            strTreeContent += "<ul style=\"display: none;\">";
                            groupname = reaplay.qgname;
                        }

                        var tagItem = reaplay.quiz[k];
                        strTreeContent += "<li><a href=\"#divEditPerson\" data-toggle=\"tab\" onclick=\"SetEditTagBind('" + tagItem.qid + "','" + tagItem.qgid + "','" + tagItem.qquestion + "','" + encodeURI(tagItem.qanswer) + "','" + reaplay.qgname + "')\">" + tagItem.qquestion + "</a></li>";
                    }
                }
                strTreeContent += "</ul>";
                strTreeContent += "</li>";
                strTreeContent += "</ul>";
                objselectGroup.append("<option value='" + reaplay.qgid + "'>" + reaplay.qgname + "</option>");
            }

        }

    }
    else {
        strTreeContent = ResultShow(m_JsonResult);

    }
    $("#divTree").html(strTreeContent);
    PageLoadTrees();
}

//清空按钮
function resetTag() {
    DataBind();
}
$(window).resize(function () {
    PageLoadTrees();
});

//知识问答库是否开启的单击事件
function OpenDelayed() {
    var bisOpen = $("#ckOpenDelayed").is(':checked');
    var strsleeptime = $("#selInterval");
    if (bisOpen) {
        $("#selInterval").removeAttr("disabled");
        if (strsleeptime.val() == null) {
            $("#selInterval").prop('selectedIndex', 0);
        }
    } else {
        $("#selInterval").attr("disabled", true);
        $("#selInterval").val("");
    }
}

///----------------------分组向上向下移动-------------------start
//向上移动  m_JsonResult.result.list
function QuizGroupTop(index) {
    event.cancelBubble = true;//禁止触发父级事件
    $(".loading").show();
    $(".loadingcover").show();
    isSelectIndex = -1;
    //没提交过赋值
    if (!m_isGroupSubmit) {
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            m_JsonResult.result.list[i].sort = 10000 + i + 1;
        }
    }
    var top = m_JsonResult.result.list[index].sort;
    m_JsonResult.result.list[index].sort = m_JsonResult.result.list[index - 1].sort;
    m_JsonResult.result.list[index - 1].sort = top;

    var list = [];
    var jObject = {};
    if (m_isGroupSubmit) {
        jObject.id = m_JsonResult.result.list[index - 1].qgid;
        jObject.sort = m_JsonResult.result.list[index - 1].sort;
        list.push(jObject);
        jObject = {};
        jObject.id = m_JsonResult.result.list[index].qgid;
        jObject.sort = m_JsonResult.result.list[index].sort;
        list.push(jObject);
    } else {
        //没提交过
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            jObject = {};
            jObject.id = m_JsonResult.result.list[i].qgid;
            jObject.sort = m_JsonResult.result.list[i].sort;
            list.push(jObject);
        }
    }
    var json = $.toJSON({
        qglist: list
    });
    manageObj.changequizgroupposition(json);
}
function QuizGroupBottom(index) {
    event.cancelBubble = true;//禁止触发父级事件
    $(".loading").show();
    $(".loadingcover").show();
    isSelectIndex = -1
    //没提交过赋值
    if (!m_isGroupSubmit) {
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            m_JsonResult.result.list[i].sort = 10000 + i + 1;
        }
    }

    var bottom = m_JsonResult.result.list[index].sort;
    m_JsonResult.result.list[index].sort = m_JsonResult.result.list[index + 1].sort;
    m_JsonResult.result.list[index + 1].sort = bottom;
    //当前标签组之前是选中状态的话，重新设置为选中状态

    var list = [];
    var jObject = {};
    if (m_isGroupSubmit) {
        jObject.id = m_JsonResult.result.list[index].qgid;
        jObject.sort = m_JsonResult.result.list[index].sort;
        list.push(jObject);
        jObject = {};
        jObject.id = m_JsonResult.result.list[index + 1].qgid;
        jObject.sort = m_JsonResult.result.list[index + 1].sort;
        list.push(jObject);
    } else {
        //没提交过
        for (var i = 0; i < m_JsonResult.result.list.length; i++) {
            jObject = {};
            jObject.id = m_JsonResult.result.list[i].qgid;
            jObject.sort = m_JsonResult.result.list[i].sort;
            list.push(jObject);
        }
    }
    var json = $.toJSON({
        qglist: list
    });
    manageObj.changequizgroupposition(json);
}

//组上下移动回调
function AsyncChangeQuizGroupPositionResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "操作成功！");
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
    DataBind();
}
///----------------------分组向上向下移动-------------------end

///---------------------分组内标签向上向下移动--------------start
//分组内标签向上移动单击
function QuizTop(GroupIndex, TagIndex) {
    //参数：GroupIndex是所选标签组的下标，TagIndex是所选标签的下标
    event.cancelBubble = true;//禁止触发父级事件
    $(".loading").show();
    $(".loadingcover").show();
    isSelectIndex = GroupIndex;
    var isQuiz = true;//true提交过当前组，false没提交过
    if (m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == "" || m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == undefined || m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == null) {
        for (var i = 0; i < m_JsonResult.result.list[GroupIndex].quiz.length; i++) {
            m_JsonResult.result.list[GroupIndex].quiz[i].sort = 10000 + i + 1;
        }
        isQuiz = false;
    }

    var top = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort;
    m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex - 1].sort;
    m_JsonResult.result.list[GroupIndex].quiz[TagIndex - 1].sort = top;

    var list = [];
    var jObject = {};
    if (!isQuiz) {
        for (var j = 0; j < m_JsonResult.result.list[GroupIndex].quiz.length; j++) {
            jObject = {};
            jObject.id = m_JsonResult.result.list[GroupIndex].quiz[j].qid;
            jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[j].sort;
            list.push(jObject);
        }
    } else {
        jObject.id = m_JsonResult.result.list[GroupIndex].quiz[TagIndex - 1].qid;
        jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex - 1].sort;
        list.push(jObject);
        jObject = {};
        jObject.id = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].qid;
        jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort;
        list.push(jObject);

    }
    var json = $.toJSON({
        qlist: list
    });
    manageObj.changequizposition(json);
}

//分组内标签向下移动单击事件
function QuizBottom(GroupIndex, TagIndex) {
    //参数：GroupIndex是所选标签组的下标，TagIndex是所选标签的下标
    event.cancelBubble = true;//禁止触发父级事件
    $(".loading").show();
    $(".loadingcover").show();
    isSelectIndex = GroupIndex;
    var isQuiz = true;//true提交过当前组，false没提交过
    if (m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == "" || m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == undefined || m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort == null) {
        for (var i = 0; i < m_JsonResult.result.list[GroupIndex].quiz.length; i++) {
            m_JsonResult.result.list[GroupIndex].quiz[i].sort = 10000 + Number(i) + 1;
        }
        isQuiz = false;
    }
    var bottom = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort;
    m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex + 1].sort;
    m_JsonResult.result.list[GroupIndex].quiz[TagIndex + 1].sort = bottom;

    var list = [];
    var jObject = {};
    if (!isQuiz) {
        for (var j = 0; j < m_JsonResult.result.list[GroupIndex].quiz.length; j++) {
            jObject = {};
            jObject.id = m_JsonResult.result.list[GroupIndex].quiz[j].qid;
            jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[j].sort;
            list.push(jObject);
        }
    } else {
        jObject.id = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].qid;
        jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex].sort;
        list.push(jObject);
        jObject = {};
        jObject.id = m_JsonResult.result.list[GroupIndex].quiz[TagIndex + 1].qid;
        jObject.sort = m_JsonResult.result.list[GroupIndex].quiz[TagIndex + 1].sort;
        list.push(jObject);

    }
    var json = $.toJSON({
        qlist: list
    });
    manageObj.changequizposition(json);
}
//组内回答移动回调
function AsyncChangeQuizPositionResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "操作成功！");
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
        $(".loadingcover").hide();
        $(".loading").hide();
    }
    DataBind();
}
///---------------------分组内标签向上向下移动--------------end