

function obj2str(o) {
    var r = [];
    if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
    if (typeof o == "object") {
        if (!o.sort) {
            for (var i in o)
                r.push(i + ":" + obj2str(o[i]));
            if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                r.push("toString:" + o.toString.toString());
            }
            r = "{" + r.join() + "}"
        } else {
            for (var i = 0; i < o.length; i++)
                r.push(obj2str(o[i]))
            r = "[" + r.join() + "]"
        }
        return r;
    }
    return o.toString();
}

var __editSPaperAjax = function(url) {
if (url == null) url = "/WebService/EditSPaper.asmx/";
    this.url = url;
    
    
    //编辑填空题
    this.editFillTest = function(note, paperId, testId, score, plain, testStr, k1, k2, degree, keyPoint, kpIdName) {

        var url = this.url + "editFillTest";
        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": plain, "testContent": testStr, "k1": k1, "k2": k2, "level": degree, "kpIdStr": keyPoint, "kpIdName": kpIdName };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
               reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                alert(XMLHttpRequest.responseText);
            }
        });

    };
    
    //添加填空题
    this.addFillTest = function(note, paperId, themeId, score, plain, testStr, k1, k2, degree, keyPoint, kpIdName) {

    var url = this.url + "addFillTest";
    var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": plain, "testContent": testStr, "k1": k1, "k2": k2, "level": degree, "kpIdStr": keyPoint, "kpIdName": kpIdName };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                alert(XMLHttpRequest.responseText);
            }
        });

    };
    
    this.editTitle = function (paperId, title) {
        var url = this.url + "editTitle";
        var json_data = { "paperId": paperId, "title": title };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {

                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(XMLHttpRequest.responseText);
            }
        });

    };
    
    this.updateTheme = function (paperId, themeId, themeTxt) {
        var url = this.url + "updateTheme";
        var json_data = { "paperId": paperId, "themeId": themeId, "themeTxt": themeTxt };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {

                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(XMLHttpRequest.responseText);
            }
        });

    };
    
    this.addRanTest = function (paperId, themeId, score, subjectId, difficulty, count, kpId) {
        var url = this.url + "addRanTest";
        var json_data = { "paperId": paperId, "themeId": themeId, "score": score, "subjectId": subjectId, "difficulty": difficulty, "keyScores": score, "count": count, "kpId": kpId };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {

                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(textStatus + "'" + errorThrown);
            }
        });

    };
    
    this.editRanTest = function (paperId, testId, score, subjectId, difficulty, count, kpId) {
        var url = this.url + "editRanTest";
        var json_data = { "paperId": paperId, "testId": testId, "score": score, "subjectId": subjectId, "difficulty": difficulty, "keyScores": score, "count": count, "kpId": kpId };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(textStatus + "'" + errorThrown);
            }
        });

    };
    
    //编辑checkbox的分值
    this.delRanTest = function (paperId, testId) {
        var url = this.url + "delRanTest";
        var json_data = { "paperId": paperId, "testId": testId };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(textStatus + "'" + errorThrown);
            }
        });

    };
    
    //
    this.addTheme = function (paperId, tx, themeTxt, toTheme) {

        var json_data = { "paperId": paperId, "tx": tx, "themeTxt": themeTxt, "toTheme": toTheme };
        var url = this.url + "addTheme";
        
       
        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

                //alert(textStatus + "'" + XMLHttpRequest.responseText);
            }
        });



    };
    this.delTheme = function (paperId, themeId) {

        var json_data = { "paperId": paperId, "themeId": themeId};
        var url = this.url + "delTheme";

        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息


            }
        });



    };
    this.delTest = function (paperId, testId) {

        var json_data = { "paperId": paperId, "testId": testId };
        var url = this.url + "delTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.addSingleTest = function (note, paperId, themeId, score, isPlain, testContent, ta, tb, tc, td, te, tf, sa, sb, sc, sd, se, sf, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": isPlain, "testContent": testContent, "ta": ta, "tb": tb, "tc": tc, "td": td, "te": te, "tf": tf, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "se": se, "sf": sf, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "addSingleTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function(data) {

                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editSingleTest = function (note, paperId, testId, score, isPlain, testContent, ta, tb, tc, td, te, tf, sa, sb, sc, sd, se, sf, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": isPlain, "testContent": testContent, "ta": ta, "tb": tb, "tc": tc, "td": td, "te": te, "tf": tf, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "se": se, "sf": sf, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "editSingleTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.addMulTest = function (note, paperId, themeId, score, isPlain, testContent, ta, tb, tc, td, te, tf, sa, sb, sc, sd, scoreO, k1, k2, k3, k4, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": isPlain, "testContent": testContent, "ta": ta, "tb": tb, "tc": tc, "td": td, "te": te, "tf": tf, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "scoreO": scoreO, "k1": k1, "k2": k2, "k3": k3, "k4": k4, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "addMulTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editMulTest = function (note, paperId, testId, score, isPlain, testContent, ta, tb, tc, td, te, tf, sa, sb, sc, sd, scoreO, k1, k2, k3, k4, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": isPlain, "testContent": testContent, "ta": ta, "tb": tb, "tc": tc, "td": td, "te": te, "tf": tf, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "scoreO": scoreO, "k1": k1, "k2": k2, "k3": k3, "k4": k4, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "editMulTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };

    this.addAnswerTest = function (note, paperId, themeId, score, isPlain, testContent, key, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": isPlain, "testContent": testContent, "key": key, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "addAnswerTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editAnswerTest = function (note, paperId, testId, score, isPlain, testContent, key, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": isPlain, "testContent": testContent, "key": key, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "editAnswerTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.addJudgeTest = function (note, paperId, themeId, score, isPlain, testContent, scoreR, scoreE, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": isPlain, "testContent": testContent, "scoreR": scoreR, "scoreE": scoreE, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "addJudgeTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editJudgeTest = function (note, paperId, testId, score, isPlain, testContent, scoreR, scoreE, level, kpIdStr, kpIdName) {
     
        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": isPlain, "testContent": testContent, "scoreR": scoreR, "scoreE": scoreE, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "editJudgeTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.addChoiceTest = function (note, paperId, themeId, score, isPlain, ta, tb, tc, td, sa, sb, sc, sd, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "themeId": themeId, "score": score, "isPlain": isPlain, "ta": ta, "tb": tb, "tc": tc, "td": td, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "addChoiceTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editChoiceTest = function (note, paperId, testId, score, isPlain, ta, tb, tc, td, sa, sb, sc, sd, level, kpIdStr, kpIdName) {

        var json_data = { "note": note, "paperId": paperId, "testId": testId, "score": score, "isPlain": isPlain, "ta": ta, "tb": tb, "tc": tc, "td": td, "sa": sa, "sb": sb, "sc": sc, "sd": sd, "level": level, "kpIdStr": kpIdStr, "kpIdName": kpIdName };
        var url = this.url + "editChoiceTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    this.editReadTest = function (paperId, textId, isPlain, testContent) {

        var json_data = {"paperId": paperId, "textId": textId, "isPlain": isPlain, "testContent": testContent };
        var url = this.url + "editReadTest";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };

    this.appendToPaperFromStore = function (paperId,subjectId, tx, ids, appendto) {

        var json_data = { "paperId": paperId, "subjectId": subjectId, "tx": tx, "ids": ids, "appendto": appendto };
        var url = this.url + "appendToPaperFromStore";

        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: false,
            contentType: "application/json",
            success: function (data) {

                reloadPage(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });



    };
    //只检查是否已经登录
    function checkLog(data) {
        var d = data.d;
        if (!d.ok) {
            if (d.msgCode == 1) __editSPaperAjax.prototype.logon(); else alert(d.msg)
        };


    };

    
    //刷新页面
    function reloadPage(data) {
        var d = data.d;
        if (d.ok) {
            __SetCookie("scrollTop", $(window).scrollTop());
            window.location.reload();initEditor();
            edit = false;
        }
        else {

            if (d.msgCode == 1) { $.modal.close(); __editSPaperAjax.prototype.logon(); } else alert(d.msg)
        };


    };
    

};

__editSPaperAjax.prototype.logon = function() {
    var src = "/secure/logon_modal.htm";
    $.modal('<iframe src="' + src + '"scrolling="no" height="295" width="645" style="border:0"></iframe>', {

        containerCss: {
            height: 300,
            padding: 0,
            width: 650
        }
    });





};
var send = new __editSPaperAjax();