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 __testStoreAjax = function(url) {
    if (url == null) url = "/WebService/editTestStore.asmx/";
    this.url = url;

    
    //编辑填空题
    this.editFillTest = function(testId, subjectid, note, plain, degree, testStr, k1, k2, keyPoint) {
        
        var url = this.url + "editFillTest";
        var json_data = { "testId": testId, "subjectid": subjectid, "note": note, "plain": plain, "degree": degree, "testStr": testStr, "k1": k1, "k2": k2,  "keyPoint": keyPoint };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: true,
            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( subjectid, note, plain, degree, testStr, k1, k2, keyPoint) {

    var url = this.url + "addFillTest";
        var json_data = { "subjectid": subjectid, "note": note, "plain": plain, "degree": degree, "testStr": testStr, "k1": k1, "k2": k2, "keyPoint": keyPoint };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: true,
            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.appendDrop = function(rtl, left, top, count, score_1, score_2, score_3, score_4, score_5, score_6) {
        var url = this.url + "appendDrop";
        var json_data = { "paperFileName": getPaperFile(), "rlt": rtl, "left": left, "top": top, "choiceCount": count, "score_1": score_1, "score_2": score_2, "score_3": score_3, "score_4": score_4, "score_5": score_5, "score_6": score_6 };
        $.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.appendMedia = function(url2, left, top) {
        var url = this.url + "appendMedia";
        var json_data = { "paperFileName": getPaperFile(), "url": url2, "left": left, "top": top };
        $.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);
            }
        });

    };
    //添加checkbox
    this.appendCheckboxs = function(rtl, left, top, count, score) {
        var url = this.url + "appendCheckboxs";
        var json_data = { "paperFileName": getPaperFile(), "rlt": rtl, "left": left, "top": top, "choiceCount": count, "keyScores": score };
        $.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.editCheckScore = function(groupName, value, score) {
        var url = this.url + "editCheckScore";
        var json_data = { "paperFileName": getPaperFile(), "groupName": groupName, "value": value, "keyScores": score };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: true,
            contentType: "application/json",
            success: function(data) {
                reloadKey(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息
                //alert(textStatus + "'" + errorThrown);
            }
        });

    };

    //编辑一组填空节点
    this.editInputScore = function(group, key) {

        var json_data = { "paperFileName": getPaperFile(), "group": group, "key": key };
        var url = this.url + "editInputScore";

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

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



    };
    this.editRadioScore = function(groupName, value, score) {

        var json_data = { "paperFileName": getPaperFile(), "groupName": groupName, "value": value, "score": score };
        var url = this.url + "editRadioScore";

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


            }
        });



    };
    this.editTextareaScore = function(id, key4, score) {

        var json_data = { "paperFileName": getPaperFile(), "id": id, "score": score, "key": key4 };
        var url = this.url + "editTextareaScore";

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

            }
        });



    };
    this.appendTextarea = function(left, top, key, score) {

        var json_data = { "paperFileName": getPaperFile(), "left": left, "top": top, "score": score, "key": key };
        var url = this.url + "appendTextarea";

        $.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.delNodes = function(group) {
        var json_data = { "paperFileName": getPaperFile(), "groupName": group };

        var url = this.url + "delNodes";
        $.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.removeGroupLastNode = function(group) {
        var json_data = { "paperFileName": getPaperFile(), "groupName": group };
        var url = this.url + "removeGroupLastNode";
        $.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.appendInputs = function(inputType, left, top, count, key) {

        var json_data = { "paperFileName": getPaperFile(), "inputType": inputType, "count": count, "key": key, "left": left, "top": top };
        var url = this.url + "appendInputs";

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


            }
        });



    };
    //复制一组节点，限单选、多项g_v
    this.copyNodes = function(nodeId) {
        var url = this.url + "copyNodes";
        var json_data = { "paperFileName": getPaperFile(), "groupName": $("#" + nodeId).text() };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: true,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
                // 只有一个会包含信息

            }
        });

    };
    //复制一节点，限单选、多项g_v
    this.copyNode = function(groupName, value) {
        var url = this.url + "copyNode";
        var json_data = { "paperFileName": getPaperFile(), "groupName": groupName, "value": value };
        $.ajax({
            type: "post",
            url: url,
            data: obj2str(json_data),
            processData: true,
            cache: false,
            async: true,
            contentType: "application/json",
            success: function(data) {
                reloadPage(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name

            }
        });

    };
    //同时移动多个节点"/wcf/EditPaperService.svc/moveNode"
    this.moveNodes = function(nodeObjs) {
        var url = this.url + "moveNodes";
        var moveArr = [];
        nodeObjs.each(function(i) {
            var paraArr = this.id.split("_"); //test_r_g_v
            moveArr.push({ groupName: paraArr[2], value: paraArr[3], left: parseInt(this.style.left), top: parseInt(this.style.top), type: paraArr[1] });
        });

        var json_data = { "paperFileName": getPaperFile(), "nodes": moveArr };
        $.ajax({
            type: "post",
            url: url,
            data: JSON.stringify(json_data),
            processData: false,
            cache: false,
            async: true,
            contentType: "application/json",
            success: function(data) {
                checkLog(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) __testStoreAjax.prototype.logon(); else alert(d.msg)
        };


    };
    //刷新页面
    function reloadPage(data) {
        var d = data.d;
        if (d.ok) {

            self.location = self.location;
        }
        else {

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



    };
    

};

__testStoreAjax.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 __testStoreAjax();