/// <reference path="../../../../jslib/jquery/jquery-lastest.js" />

function appendInputs() {
    var left = $("#tb_left").val();

    var top = $("#tb_top").val();
    var count = parseInt($("#s_inputCount").val());
    var inputType = $("#s_inputType").val();
    var key = $.trim($("#tb_key_2").val());
    var score = parseFloat($("#tb_score_2").val());
    if (score <= 0) {alert("分值不能为0，请重新选择分数。");return; }
   //列举性答案，检查答案合法性
    if (checkKeyScore(key, count)) {

        send.appendInputs(inputType, left, top, count, key, score);
    };
    
};
function fillTypeChanged(src) {

    if (src.value == "1") { $("#s_inputCount").attr("disabled", "disabled"); $("#s_inputCount").val("1"); } else {$("#s_inputCount").removeAttr("disabled"); $("#s_inputCount").val("2");}
    

};
function fillCountChanged(src) {
    if (($("#s_inputType").val() == "2") && ($("#s_inputCount").val() == "1")) { $("#s_inputCount").val("2") }

}


function displayKeys() {

    $("textarea").each(function(i) {

        if (this.id.substr(0, 1) == "e") {
            var testId = this.id.substr(1);
            if (__keys == null) {  return false; }
            var key = __keys.getKeyById(testId);
            if (key == null) return false;
            var s = key.getStandardKey(); $(this).val(s); saveKeyToArr(4,this); return true;
        }

    });

    var keyCount = __keys.count();var s = 0;
    for (var i = 0; i < keyCount; i++) {
        var k = __keys.item(i);
        s += k.getScore();
    };
    $("#page_fullScore").text("满分：" + s);

}
function displayCheckboxUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;

    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendCheckbox").modal({ persist: true });
};
function displayRadioUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;
    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendRadio").modal({ persist: true });
};
function displayDropUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;
    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendDrop").modal({ persist: true});
};

function displayInputUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;
    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendInput").modal({ persist: true });
};
function displayTextUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;
    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendText").modal({ persist: true });
};
function displayMediaUI(left, top) {
    if (left == null) left = 2;
    if (top == null) top = $(window).scrollTop() - $('.paperArea').offset().top + 100;
    $("#tb_left").val(left);
    $("#tb_top").val(top);
    $("#appendMedia").modal({ persist: true });
};
function OpenServerBrowser() {
    //var url = "/richedit/editor/filemanager/browser/default/browser.html?Type=Media&Connector=%2Frichedit%2Feditor%2Ffilemanager%2Fconnectors%2Faspx%2Fconnector.aspx";
    var url = "/secure/serverFiles/Navigation.htm";
    var width = 550;
    var height = 400;
    
    var iLeft = ($(window).width() - width) / 2;
    var iTop = ($(window).height() - height) / 2;

    var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes";
    sOptions += ",width=" + width;
    sOptions += ",height=" + height;
    sOptions += ",left=" + iLeft;
    sOptions += ",top=" + iTop;
    var oWindow = window.open(url, "FCKBrowseWindow", sOptions, sOptions);
    oWindow.opener = window;

    };
    function SetUrl(url, width, height) {
        document.getElementById('txtUrl').value = url; document.getElementById('tb_txtUrl').value = url;
        
        if (width)
            document.getElementById('txtWidth').value = width;

        if (height)
            document.getElementById('txtHeight').value = height;

        //UpdatePreview() ;

        //dialog.SetSelectedTab( 'Info' ) ;
    }
function copyNodes(o) {
   
    send.copyNodes(o);
}
function updateKey_c(groupName) {
   var value ="";
   $("#editKey_check input[type='checkbox']").each(function(i){
       if ((this.style.visibility != "hidden") && (this.checked)) value+=this.value;
   });

   var score = parseFloat($("#p_tb_score_1").val()); if ((score <= 0)||(value == "")) { alert("请输入答案和分数"); return };


    send.editCheckScore(groupName, value, score);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};
function updateMp3(groupName) {
    var url = $("#tb_txtUrl").val();
   if (url == "") { alert("请输入地址！"); return };


    send.editMusicUrl(groupName, url);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};
function updateKey_R(groupName) {
    var score = [];var key = [];
    $("#div_editRadio input[id^='tb_socreRadio_']").each(function (i) {
        if (this.style.visibility != "hidden") {
            if (this.value != "0") {
                score[score.length] = parseFloat(this.value);
                key[key.length] = this.data;
            };
            

        }
    });
    
    if (score.length==0) { alert("请输入答案和分数"); return };


    send.editRadioScore(groupName, key, score);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};
function updateKey_T(groupName) {
    var score = $("#tb_editScore_t").val(); var key =$.trim($("#tb_editKey_t").val());

    if (key == "") { alert("请输入答案"); return };
    if (score== "0") { alert("请输入分数"); return };


    send.editTextareaScore(groupName, key, score);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};
function updateKey_D(groupName) {
    var score = []; var key = [];
    $("#div_editDrop input[id^='tb_socreDrop_']").each(function (i) {
        if (this.style.visibility != "hidden") {
            if (this.value != "0") {

                score[score.length] = parseFloat(this.value);
                key[key.length] = this.data;
            };


        }
    });

    if (score.length == 0) { alert("请输入答案和分数"); return };


    send.editDropScore(groupName, key, score);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};
function updateKey_i(groupName) {
    var value = $.trim($("#tb_editKey_i").val());
    var key = value.split(" ");
    if (key.length < document.getElementsByName("c" + groupName).length) { alert("答案的数量不能小于填空点的数量"); return; };
    var score = parseFloat($("#tb_editScore_i").val()); if ((score <= 0) || (value == "")) { alert("请输入答案和分数"); return };


    send.editInputScore(groupName, key, score);

    //document.getElementById("tb_editChoiceScore").parentNode.parentNode.style.display = "none";
};


function editFileUrl(id,url) {

    var keyboxs = $("#tb_txtUrl").val(url);
   
    $("#div_editMp3").modal({ persist: true });

};
function checkKeyScore(key,minLen) { 
   if (key == "") { alert("答案不能为空");return false;};
   var kvArr = key.split(" ");
   if (kvArr.length < minLen) { alert("答案数量过少！"); return false; };
   /*for (var i = 0; i < kvArr.length; i++) {
       var kv = kvArr[i].split(":");
       if ((i == 0) && (kv.length == 1)) { alert("第一个答案后面必须以冒号相隔输入分值！"); return false; };
       if (kv[0] == "") { alert("某个答案分值对中缺少答案！"); return false; };
       if (kv.length ==2) {
           if (kv[1] == "") { alert("某个答案分值对中缺少分值！"); return false; };
           if (isNaN(kv[1])) { alert("某个答案分值对中分值错误！"); return false; };
       
       
       
   };*/
   return true;
};

function copyRadio() {
    var groupName = $("#l_testNum").text();
    var value = $("#l_Choice").text();
    
    send.copyNode(groupName, value);
};
function copyCheck() {
    var groupName = $("#l_testNum_c").text();
    var value = $("#l_Choice_c").text();
     send.copyNode(groupName, value);

 };
 function delNodes(float) {
     var delArr = [];
     if ($(float).children(".selectHandler").hasClass("ui-selected")) {
         //删除所有已经选择的容器
         if (!confirm("该操作将删除所有已选单元，确定进行吗？")) return;
         $(".ui-selected").each(function (i) {
             var id = this.parentNode.id;
             id = id.substring(id.indexOf("_") + 1);
             id = id.substring(id.indexOf("_") + 1);
             var group = id;
             if (group.indexOf("_") != -1) group = group.substring(0,group.indexOf("_"));
             if ($.inArray(group, delArr) == -1) delArr.push(group);
             
         });
     } else {
         //仅删除本容器
         if (!confirm("该操作将删除此项，确定进行吗？")) return;
         var id = float.id;
         id = id.substring(id.indexOf("_") + 1);
         id = id.substring(id.indexOf("_") + 1);
         var group = id;
         if (group.indexOf("_") != -1) group = group.substring(0, group.indexOf("_"));
         if ($.inArray(group, delArr) == -1) delArr.push(group);
     }
     send.delNodes(delArr);
 };

function appendCheckboxs() {
    var left = $("#tb_left").val();

    var top = $("#tb_top").val();
    var key = "";
     $("input[name='cb_1']").each(function (i) {
         if ((this.style.visibility != "hidden") && (this.checked)) key += this.value;
   });
   if (key == "") {
       alert("请选择答案"); return;
   }
    var score_1 =parseFloat( $('#tb_score_1').val());
    var rtl = $('#listType_s_1').val();
    var count = parseInt($('#choiceCount_s_1').val());
    
    send.appendCheckboxs(rtl,left,top,count,key, score_1);
};
function appendMedia() {
    var left = $("#tb_left").val();

    var top = $("#tb_top").val();


    var url = $('#txtUrl').val();

    if (url == "") { alert("请输入地址");return; };
    send.appendMedia(url, left, top);
};
function checkKeyScores(score_1, rtl, count) {

    if (score_1.indexOf(":") == -1) { alert("答案分值对不是合法格式！"); return false; };
    var keyScoreArr = score_1.split(",");

    for (var i = 0; i < keyScoreArr.length; i++) {//是否是合法分值
        var s = keyScoreArr[i].split(":")[1]; //分值
        if (s=="") { alert("分值不是合法数字！"); return false; }
        if (isNaN(s)) { alert("分值不是合法数字！"); return false; }
        if (s == "0") { alert("分值不能是零！"); return false; }

    }
    for (var i = 0; i < keyScoreArr.length; i++) {//是否存在重复的答案
        var s1 = keyScoreArr[i].split(":")[0]; //答案
        for (var j = i + 1; j < keyScoreArr.length; j++) {
            var s2 = keyScoreArr[j].split(":")[0]; //答案

            if (s1.toLowerCase() == s2.toLowerCase()) { alert("不能存在重复的答案！"); return false; } //忽略大小写

        }
    }
    var hfxx1 = ["A", "B", "C", "D", "E", "F"];
    var hfxx2 = ["a", "b", "c", "d", "e", "f"];
    var hfxx6 = ["1", "2", "3", "4", "5", "6"];
    var hfxx = null;
    if (rtl == "1") { hfxx = hfxx1; score_1 = score_1.toUpperCase(); } if (rtl == "2") { hfxx = hfxx2; score_1 = score_1.toLowerCase(); } if (rtl == "6") hfxx = hfxx6;
    for (var i = 0; i < keyScoreArr.length; i++) {//是否是合法答案
        var s = keyScoreArr[i].split(":")[0]; //答案
        if (s.length > count) { alert("答案字符数超过选项数！"); return false; }
        for (var j = 0; j < s.length; j++) {
            var sChar = s.substr(j, 1);
            var hfzz = false;
            for (var k = 0; k < count; k++) { if (sChar.toLowerCase() == hfxx[k].toLowerCase()) hfzz = true; }
            if (!hfzz) { alert("答案中的字符不是上述指定选项编号！"); return false; }
        }

    }
    return true;

}
function disabledDeck(disabled) {
    var d = "";
    if (disabled) d = "disabled";
    $("#dock").attr("disabled", d);
    $("#dock a").attr("disabled", d); 
    $("#dock input").attr("disabled", d); 
    $("#dock input[type='input']").val("0");
    

};
//添加新的一组单选按钮
function appendRadio() {
    var left = $("#tb_left").val();
   
    var top= $("#tb_top").val();

    var score_1 = $('#tb_scoreChoice_1').val();
    var score_2 = $('#tb_scoreChoice_2').val();
    var score_3 = $('#tb_scoreChoice_3').val();
    var score_4 = $('#tb_scoreChoice_4').val();
    var score_5 = $('#tb_scoreChoice_5').val();
    var score_6 = $('#tb_scoreChoice_6').val();
    var sArr = [score_1,score_2,score_3,score_4,score_5,score_6];
    var rtl = $('#listType_s').val();
    var count = parseInt($('#choiceCount_s').val());
    var checkScore = false;
    for (var i = 0; i < count; i++) {
        if (sArr[i] != "0") checkScore = true;
    
    }
    if (!checkScore) { alert("必须有不为零的分值！"); return; };
    send.appendRadio(rtl, left, top, count, score_1, score_2, score_3, score_4, score_5, score_6);
};

function appendDrop() {
    var left = $("#tb_left").val();

    var top = $("#tb_top").val();

    var score_1 = $('#tb_scoreChoice_1_d').val();
    var score_2 = $('#tb_scoreChoice_2_d').val();
    var score_3 = $('#tb_scoreChoice_3_d').val();
    var score_4 = $('#tb_scoreChoice_4_d').val();
    var score_5 = $('#tb_scoreChoice_5_d').val();
    var score_6 = $('#tb_scoreChoice_6_d').val();
    var sArr = [score_1, score_2, score_3, score_4, score_5, score_6];
    var rtl = $('#listType_s_d').val();
    var count = parseInt($('#choiceCount_s_d').val());
    var checkScore = false;
    for (var i = 0; i < count; i++) {
        if (sArr[i] != "0") checkScore = true;
        
    }
    if (!checkScore) { alert("必须有不为零的分值！"); return; };
    send.appendDrop(rtl, left, top, count, score_1, score_2, score_3, score_4, score_5, score_6);
};

//添加新的问答题
function appendText() {
    var left = $("#tb_left").val();

    var top = $("#tb_top").val();

    var score = $('#tb_score_4').val();
    var key = $('#tb_key_4').val();
    if (key == '') { alert("答案不能为空！"); return; }
    if (score == '0') { alert("分值不能为零！"); return; }
    send.appendTextarea(left, top, key, score);

};
function changeSize(id, width, height) {

    send.changeNodes([id]);

};
function changeSizeForClient(width, height,save) {
    var sl = $(".ui-selected")[0].parentNode;
    if (width) sl.style.width = width + "px";
    if (height) sl.style.height = height + "px";
   
        var ids = sl.id;
        
        var id = ids.substr(ids.lastIndexOf("_") + 1);
        send.changeNodesSize(id, parseInt(sl.style.width), parseInt(sl.style.height)); 
    
};
function changePositionForClient(top, left, save) {
    var sl = $(".ui-selected")[0].parentNode;
    if (top) sl.style.top = top + "px";
    if (left) sl.style.left = left + "px";

    
        send.moveNodes(["#"+sl.id]);
  
};
function disabledSaveUI(disabled) {
    if (disabled) { $("#saveUI").attr("disabled", "disabled");$("#saveUIImg").attr("src", "/paperStyle/images/save0.png"); }
    else { $("#saveUI").attr("disabled", ""); $("#saveUIImg").attr("src", "/paperStyle/images/save.png"); }

};
window.onunload = function () {
    if ($("#saveUI").attr("disabled") != "disabled") {
         send.save();

    };


};

function showEditMP3(id) {
    $("#l_testNum_m").text(id);return true;
}

function showKey(testGroupName) {
    
    if (__keys == null) { return true; }
    var key = __keys.getKeyById(testGroupName);
    if (key == null) return true;
    var children = key.children();


    $("#showKey").empty();
    var childrenCount = children.count();
    if (childrenCount == 0) {
        
        $("#showKey").append("<li>" + key.getStandardKey() +" "+ key.getScore() + "分</li>");
    } else {
        for (var i = 0; i < childrenCount; i++) {
            var k = children.item(i);
            $("#showKey").append("<li>" + k.getStandardKey() + " " + k.getScore() + "分</li>");
        };
    }
    return true;
};

function editKey(keyId) {
    if (__keys == null) { return true; }
    var key = __keys.getKeyById(keyId);
    if (key == null) return true;
    var children = key.children(); var childrenCount = children.count();
    switch (keyId.charAt(0)) {
        case "i":

            var keyStr = ""; var score = 0;
            if (childrenCount == 0) {
                keyStr = key.getStandardKey(); score = key.getScore();

            } else {
                score = children.item(0).getScore();
                for (var i = 0; i < childrenCount; i++) {

                    keyStr += children.item(i).getStandardKey() + " ";
                };
                keyStr = $.trim(keyStr);
            };
            $("#tb_editKey_i").val(keyStr);
            $("#tb_editScore_i").val(score);
            var fillCount = document.getElementsByName("c" + keyId).length;
            if (fillCount > 1) {
                document.getElementById("p_enumKeyMsg").style.display = "block"; document.getElementById("lbl_emumFillCount").innerText = fillCount;
            } else { document.getElementById("p_enumKeyMsg").style.display = "none"; }
            $("#div_editInput").modal({ persist: true });

            break;
        case "c":
            var a = document.getElementsByName("b" + keyId);

            var boxs = $("#editKey_check input[type='checkbox']").css("visibility", "hidden").attr("checked", false);

            var labels = $("#editKey_check label[for]").css("visibility", "hidden");
            for (var i = 0; i < a.length; i++) {
                var v = a[i].value;
                boxs[i].value = v; labels[i].innerHTML = v;
                boxs[i].style.visibility = ""; labels[i].style.visibility = "";
            };
            var keyStr = "";
            if (childrenCount == 0) {
                keyStr = key.getStandardKey();

            } else {
                keyStr = children.item(0).getStandardKey();

            };
            boxs.each(function (i) {

                if (keyStr.indexOf(this.value) != -1) this.checked = true; else this.checked = false;
            });
            $("#p_tb_score_1").val(key.getScore());
            $("#editKey_check").modal({ persist: true });
            break;
        case "d":
            var a = document.getElementsByName("a" + keyId)[0];

            var boxs = $("#div_editDrop input[id^='tb_socreDrop_']").css("visibility", "hidden").val("0");

            var labels = $("#div_editDrop label[id]").css("visibility", "hidden");
            for (var i = 1; i < a.length; i++) {
                var v = a[i].value;
                labels[i-1].innerText = v; $(boxs[i-1]).attr("data", v);
                labels[i - 1].style.visibility = ""; boxs[i - 1].style.visibility = "";
            };
            var keyStr = "";
            if (childrenCount == 0) {
                keyStr = key.getStandardKey();
                boxs.each(function (i) {
                    if ($(this).attr("data") == keyStr) this.value = key.getScore();
                });
            } else {
                for (var k = 0; k < childrenCount; k++) {
                    var cd = children.item(k);
                    keyStr = cd.getStandardKey();
                    boxs.each(function (i) {
                        if ($(this).attr("data") == keyStr) this.value = cd.getScore();
                    });
                };


            };

            $("#div_editDrop").modal({ persist: true });
            break;
        case "r":
            var a = document.getElementsByName("a" + keyId);

            var boxs = $("#div_editRadio input[id^='tb_socreRadio_']").css("visibility", "hidden").val("0");

            var labels = $("#div_editRadio label[id]").css("visibility", "hidden");
            for (var i = 0; i < a.length; i++) {
                var v = a[i].value;
                labels[i].innerText = v; $(boxs[i]).attr("data",v);
                labels[i].style.visibility = ""; boxs[i].style.visibility = "";
            };
            var keyStr = "";
            if (childrenCount == 0) {
                keyStr = key.getStandardKey();
                boxs.each(function (i) {
                    if ($(this).attr("data") == keyStr) this.value = key.getScore(); 
                });
            } else {
                for (var k = 0; k < childrenCount; k++) {
                    var cd = children.item(k);
                    keyStr = cd.getStandardKey(); 
                    boxs.each(function (i) {
                        if ($(this).attr("data") == keyStr) this.value = cd.getScore();
                    });
                };


            };
            
            $("#div_editRadio").modal({ persist: true });
            break;
        case "t":
            
            var keyboxs = $("#tb_editKey_t").val(key.getStandardKey());
            var scoreboxs = $("#tb_editScore_t").val(key.getScore());

            

            $("#div_editText").modal({ persist: true });
            break;
    };
    
};
function getInputStandKey(keyNode,level) {
    var children = keyNode.children();
    level++;
    var childrenCount = children.count();
    var kv = "";
    if (childrenCount == 0) {
        var s = keyNode.getScore();

        return keyNode.getStandardKey() + ":" + s;
    } else {
        var k2 = "";
        for (var i = 0; i < childrenCount; i++) {
            var c = children.item(i);
            k2 += getInputStandKey(c, level) + " ";

        };
        if (level>1)
            k2 = "{" + k2.substr(0, k2.length - 1) + "}";
        else
            k2 = k2.substr(0, k2.length - 1);
        return  k2;
    };


}

function setScore_r(key, value) { 
    var children = key.children();
    var count=children.count();
    if ( count== 0) {
        if (key.getStandardKey() == value) { var s = key.getScore(); $("#tb_editChoiceScore").val(s); }

    }else {
    for (var i = 0; i < count; i++) {

        setScore_r(children.item(i), value);
    }
    
    
    }


};

var xxEnum = [["A", "B", "C", "D", "E", "F"], ["a", "b", "c", "d", "e", "f"], ["1", "2", "3", "4", "5", "6"]];
function setChoiceInDrop(obj, count) {

    $("#" + obj).children().each(function(i) {if (i > 2) return;
        var choice = xxEnum[i]; var t = "";
        $.each(choice, function(i, n) {
            if (i < count) t += choice[i] + ".";
        });
        this.text = t;
        
    }); 
};
function choiceCountChanged(obj) {
    var selectedValue = parseInt(obj.value);
    setChoiceInDrop("listType_s", selectedValue);
    if (selectedValue == 2) {
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
       
    }
    if (selectedValue == 3) {
        $("#tb_scoreChoice_3,#l_3").css("display", "inline");
        $("#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");

    }
    if (selectedValue == 4) {
        $("#tb_scoreChoice_4,#l_4,#tb_scoreChoice_3,#l_3").css("display", "inline");
        $("#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");

    }
    if (selectedValue == 5) {
        $("#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_3,#l_3").css("display", "inline");
        $("#tb_scoreChoice_6,#l_6").css("display", "none");

    }
    
    if (selectedValue == 6) {
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "inline");
        
    }

};
function choiceCountChanged_c(obj) {
    var selectedValue = parseInt(obj.value);
    //setChoiceInDrop("listType_s_1", selectedValue);
    var a = document.getElementById("cb_1_1");
    var b = document.getElementById("cb_1_2");
    var c = document.getElementById("cb_1_3");
    var d = document.getElementById("cb_1_4");
    var e = document.getElementById("cb_1_5");
    var f = document.getElementById("cb_1_6");

    var la = document.getElementById("cb_l_1_1");
    var lb = document.getElementById("cb_l_1_2");
    var lc = document.getElementById("cb_l_1_3");
    var ld = document.getElementById("cb_l_1_4");
    var le = document.getElementById("cb_l_1_5");
    var lf = document.getElementById("cb_l_1_6");
    var arr = [a, b, c, d, e, f];
    var larr = [la, lb, lc, ld, le, lf];
    for (var i = 0; i < arr.length; i++) {
        if (i < selectedValue) { arr[i].style.visibility = "visible"; larr[i].style.visibility = "visible"; } else { arr[i].style.visibility = "hidden"; larr[i].style.visibility = "hidden"; }
  };

};
function choiceCountChanged_d(obj) {
    var selectedValue = parseInt(obj.value); 
    setChoiceInDrop("listType_s_d", selectedValue);
    if (selectedValue == 2) {
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");

    }
    if (selectedValue == 3) {
        $("#tb_scoreChoice_3_d,#l_3_d").css("display", "inline");
        $("#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");

    }
    if (selectedValue == 4) {
        $("#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_3_d,#l_3_d").css("display", "inline");
        $("#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");

    }
    if (selectedValue == 5) {
        $("#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_3_d,#l_3_d").css("display", "inline");
        $("#tb_scoreChoice_6_d,#l_6_d").css("display", "none");

    }

    if (selectedValue == 6) {
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "inline");

    }

};

function choiceTypeChanged(obj){
    var selectedValue = obj.value;
    $("#choiceCount_s").removeAttr("disabled");
    if (selectedValue == 1) {
        $("#l_1").html("A"); $("#l_2").html("B");
        $("#l_3").html("C"); $("#l_4").html("D");
        $("#l_5").html("E"); $("#l_6").html("F");
    }
    if (selectedValue == 2) {
        $("#l_1").html("a"); $("#l_2").html("b");
        $("#l_3").html("c"); $("#l_4").html("d");
        $("#l_5").html("e"); $("#l_6").html("f");
    }
    if (selectedValue == 6) {
        $("#l_1").html("1"); $("#l_2").html("2");
        $("#l_3").html("3"); $("#l_4").html("4");
        $("#l_5").html("5"); $("#l_6").html("6");
    }
    if (selectedValue == 7) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled","disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("是"); $("#l_2").html("否");
    }
    if (selectedValue == 8) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled", "disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("正确"); $("#l_2").html("错误");
    }
    if (selectedValue == 9) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled", "disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("T"); $("#l_2").html("F");
    }
    if (selectedValue == 10) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled", "disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("True"); $("#l_2").html("False");
    }
    if (selectedValue == 11) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled", "disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("Y"); $("#l_2").html("N");
    }
    if (selectedValue == 12) {
        $("#choiceCount_s").val("2"); $("#choiceCount_s").attr("disabled", "disabled");
        $("#tb_scoreChoice_3,#l_3,#tb_scoreChoice_4,#l_4,#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6").css("display", "none");
        $("#l_1").html("Yes"); $("#l_2").html("No");
    }
};
function choiceTypeChanged_c(obj) {
    var selectedValue = obj.value;
    $("#choiceCount_s_1").removeAttr("disabled");
    if (selectedValue == 1) {
        $("#cb_l_1_1").html("A"); $("#cb_l_1_2").html("B");
        $("#cb_l_1_3").html("C"); $("#cb_l_1_4").html("D");
        $("#cb_l_1_5").html("E"); $("#cb_l_1_6").html("F");
        $("#cb_1_1").val("A"); $("#cb_1_2").val("B");
        $("#cb_1_3").val("C"); $("#cb_1_4").val("D");
        $("#cb_1_5").val("E"); $("#cb_1_6").val("F");
    }
    if (selectedValue == 2) {
        $("#cb_l_1_1").html("a"); $("#cb_l_1_2").html("b");
        $("#cb_l_1_3").html("c"); $("#cb_l_1_4").html("d");
        $("#cb_l_1_5").html("e"); $("#cb_l_1_6").html("f");
        $("#cb_1_1").val("a"); $("#cb_1_2").val("b");
        $("#cb_1_3").val("c"); $("#cb_1_4").val("d");
        $("#cb_1_5").val("e"); $("#cb_1_6").val("f");
    }
    if (selectedValue == 6) {
        $("#cb_l_1_1").html("1"); $("#cb_l_1_2").html("2");
        $("#cb_l_1_3").html("3"); $("#cb_l_1_4").html("4");
        $("#cb_l_1_5").html("5"); $("#cb_l_1_6").html("6");
        $("#cb_1_1").val("1"); $("#cb_1_2").val("2");
        $("#cb_1_3").val("3"); $("#cb_1_4").val("4");
        $("#cb_1_5").val("5"); $("#cb_1_6").val("6");
    }
    
};
function choiceTypeChanged_d(obj) {
    var selectedValue = obj.value;
    $("#choiceCount_s_d").removeAttr("disabled");
    if (selectedValue == 1) {
        $("#l_1_d").html("A"); $("#l_2_d").html("B");
        $("#l_3_d").html("C"); $("#l_4_d").html("D");
        $("#l_5_d").html("E"); $("#l_6_d").html("F");
    }
    if (selectedValue == 2) {
        $("#l_1_d").html("a"); $("#l_2_d").html("b");
        $("#l_3_d").html("c"); $("#l_4_d").html("d");
        $("#l_5_d").html("e"); $("#l_6_d").html("f");
    }
    if (selectedValue == 6) {
        $("#l_1_d").html("1"); $("#l_2_d").html("2");
        $("#l_3_d").html("3"); $("#l_4_d").html("4");
        $("#l_5_d").html("5"); $("#l_6_d").html("6");
    }
    if (selectedValue == 7) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("是（s）"); $("#l_2_d").html("否（f）");
    }
    if (selectedValue == 8) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("正确（z）"); $("#l_2_d").html("错误（c）");
    }
    if (selectedValue == 9) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("T"); $("#l_2_d").html("F");
    }
    if (selectedValue == 10) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("True"); $("#l_2_d").html("False");
    }
    if (selectedValue == 11) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("Y"); $("#l_2_d").html("N");
    }
    if (selectedValue == 12) {
        $("#choiceCount_s_d").val("2"); $("#choiceCount_s_d").attr("disabled", "disabled");
        $("#tb_scoreChoice_3_d,#l_3_d,#tb_scoreChoice_4_d,#l_4_d,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
        $("#l_1_d").html("Yes"); $("#l_2_d").html("No");
    }
};
function editPaper() {

    //localhost/richedit/_samples/html/richedit.htm?testclass=p
    window.location = "/paperStyle/whole_1.0/standard/edit/editTxt.htm" + location.search;
};

$().ready(
        function () {
            $("#dock").tabs();
            disabledDeck(true);
            /*
            $("div[name^='test_c_'],div[name^='test_r_'],div[name^='test_i_']").hover(
            function (e) {
            if (event.ctrlKey) {

            $("div[name='" + this.name + "']").addClass("ui-selected overGroup");

            } else {
            $("div[name='" + this.name + "']").addClass("overGroup");
            };
            },
            function (e) {
            $("div[name='" + this.name + "']").removeClass("overGroup");
            }
            );
            */

            $(".dragHandler").hover(
            function () {
                $(this).removeClass("dragHandlerHide");
            },
            function () {
                $(this).addClass("dragHandlerHide");

            }
            );

            $('.textDiv').resizable({
                start: function (event, ui) { $(".paperArea").selectable('disable'); },
                stop: function (event, ui) {
                    var src = event.target;
                    var paraArr = src.id.split("_"); //test_r_g_v
                    changeSize(paraArr[2], $(src).outerWidth(), $(src).innerHeight());
                    $(".paperArea").selectable('enable');
                }
            });
            $('.inputDiv').resizable({
                maxHeight: 20,
                start: function (event, ui) { $(".paperArea").selectable('disable'); },
                stop: function (event, ui) {
                    var src = event.target;
                    var paraArr = src.id.split("_"); //test_r_g_v
                    changeSize(paraArr[2] + "_" + paraArr[3], $(src).outerWidth(), $(src).innerHeight());
                    $(".paperArea").selectable('enable');
                }
            });
            var __dragStartXArr, __dragStartYArr;
            $(".dragDiv").draggable({ handle: '.dragHandler',
                start: function (event, ui) {
                    $(".paperArea").selectable('disable');
                    var dragStartX = parseInt(event.target.style.left);
                    var dragStartY = parseInt(event.target.style.top);
                    __dragStartXArr = new Array();
                    __dragStartYArr = new Array();
                    if ($(event.target).children().filter(".ui-selected").length == 0) {
                        __dragStartXArr[0] = parseInt(event.target.style.left) - dragStartX;
                        __dragStartYArr[0] = parseInt(event.target.style.top) - dragStartY;

                    }

                    else
                        $(".ui-selected").each(function (i) {
                            var t = this;
                            __dragStartXArr[i] = parseInt(this.parentNode.style.left) - dragStartX;
                            __dragStartYArr[i] = parseInt(this.parentNode.style.top) - dragStartY;

                        });
                },
                drag: function (event, ui) {
                    //$(".tooltip").hide();
                    var x = parseInt(ui.position.left); var y = parseInt(ui.position.top);
                    if ($(event.target).children().filter(".ui-selected").length == 1)
                        $(".ui-selected").each(function (i) {
                            var t = this

                            this.parentNode.style.left = x + __dragStartXArr[i];
                            this.parentNode.style.top = y + __dragStartYArr[i];


                        });
                },

                stop: function (event, ui) {

                    var f = event.target.id;
                    f = f.substring(f.indexOf("_") + 1);
                    f = f.substring(f.indexOf("_") + 1);
                    var movedNodeArr = [f]

                    if ($(event.target).children().filter(".ui-selected").length == 1) {
                        setPropertyPanel(event.target);
                        $(".ui-selected").each(function (i) {
                            var id = this.parentNode.id;
                            id = id.substring(id.indexOf("_") + 1);
                            id = id.substring(id.indexOf("_") + 1);

                            if ($.inArray(id, movedNodeArr) == -1) movedNodeArr.push(id);

                        });
                    }

                    send.changeNodes(movedNodeArr);

                    $(".paperArea").selectable('enable');
                    __dragStartXArr = null; __dragStartYArr = null;
                }

            });

            //$(".paperArea").bind("mousedown", function (e) {
            //$(".tooltip").hide();
            //if ($(e.target).hasClass("ui-selected") || $(e.target).parents().hasClass("dragDiv")) $(".paperArea").selectable('disable'); else $(".paperArea").selectable('enable');
            //});
            /* $(".dragDiv").bind("mousedown", function (e) {
            
            if (event.ctrlKey) {

                    

            } else {
            $(".dragDiv").removeClass("ui-selected");
            };
            $("#" + this.id).addClass("ui-selected");
            });
            */
            $(".paperArea").selectable({
                filter: '.selectHandler', autoRefresh: true, cancel: ':.dragHandler',
                selecting: function (event, ui) { setPropertyPanel(ui.selecting.parentNode); },
                unselecting: function (event, ui) { var sl = $(".ui-selected"); if (sl.length == 0) disabledDeck(true) }

            });


            loadPaperKey(false, null, displayKeys)

            var top = __GetCookie("scrollTop");
            $(window).scrollTop(top); $(window).scroll(function () { __SetCookie("scrollTop", $(window).scrollTop()); });
            /*
            $("div[id^='test_r_']").tooltip({ tip: '#tooltip_radio', position: 'top center', delay: 500,
            onShow: function (event, position) {

            var src = event.srcElement;
            while (!$(src).hasClass("dragDiv")) {
            //alert(src.innerHTML)
            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }

            var idstr = src.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.split("_"); //alert(dataArr[0]+","+ dataArr[1]);
            return showEditRadio(dataArr[2], dataArr[3]);

            }
            });
            $("div[id^='test_c_']").tooltip({ tip: '#tooltip_check', position: 'top center', delay: 500,
            onShow: function (event, position) {
            var src = event.srcElement; // alert(src.innerHTML)

            while (!$(src).hasClass("dragDiv")) {

            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }

            var idstr = src.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.split("_"); //alert(dataArr[0]+","+ dataArr[1]);
            return showEditCheck(dataArr[2], dataArr[3]);

            }
            });
            $("div[id^='test_t_']").tooltip({ tip: '#tooltip_text', position: 'top center', delay: 500,
            onShow: function (event, position) {
            //displayKeys();
            var src = event.srcElement; // alert(src.innerHTML)
            while (!$(src).hasClass("dragDiv")) {
            //alert(src.innerHTML)
            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }
            var elements = src.childNodes;
            var ip = null;
            for (var i = 0; elements != null && i < elements.length; i++) {

            if (elements[i].tagName.toLowerCase() == "textarea") { ip = elements[i]; break; }
            }

            if (ip == null) { return false; }
            var idstr = ip.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.substring(1); //alert(dataArr[0]+","+ dataArr[1]);
            return showEditText(dataArr);

            }
            });
            $("div[id^='test_d_']").tooltip({ tip: '#tooltip_drop', position: 'top center', delay: 500,
            onShow: function (event, position) {
            //displayKeys();
            var src = event.srcElement; // alert(src.innerHTML)
            while (!$(src).hasClass("dragDiv")) {
            //alert(src.innerHTML)
            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }
            var elements = src.childNodes;
            var ip = null;
            for (var i = 0; elements != null && i < elements.length; i++) {

            if (elements[i].tagName.toLowerCase() == "select") { ip = elements[i]; break; }
            }

            if (ip == null) { return false; }
            var idstr = ip.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.substring(1); //alert(dataArr[0]+","+ dataArr[1]);
            return showEditDrop(dataArr);

            }
            });
            $("div[id^='test_m_']").tooltip({ tip: '#tooltip_MP3', position: 'top center', delay: 500,
            onShow: function (event, position) {
            //displayKeys();
            var src = event.srcElement; // alert(src.innerHTML)
            while (!$(src).hasClass("dragDiv")) {
            //alert(src.innerHTML)
            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }
            var elements = src.childNodes;
            var ip = null;
            for (var i = 0; elements != null && i < elements.length; i++) {

            if (elements[i].tagName.toLowerCase() == "img") { ip = elements[i]; break; }
            }

            if (ip == null) { return false; }
            var idstr = ip.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.substring(1);
            return showEditMP3(dataArr);

            }
            });
            $("div[id^='test_i_']").tooltip({ tip: '#tooltip_input', position: 'top center', delay: 500,
            onShow: function (event, position) {
            var src = event.srcElement; // alert(src.innerHTML)
            while (!$(src).hasClass("dragDiv")) {
            //alert(src.innerHTML)
            src = src.parentElement;
            if (src == null) return false;
            if (src.tagName.toLowerCase() == "body") return false;
            }
            var elements = src.childNodes;
            var ip = null;
            for (var i = 0; elements != null && i < elements.length; i++) {

            if (elements[i].tagName.toLowerCase() == "input") { ip = elements[i]; break; }
            }

            if (ip == null) { return false; }
            var idstr = ip.id;
            if (idstr == null) { return false; };
            var dataArr = idstr.substring(1); //alert(dataArr[0]+","+ dataArr[1]);

            return showEditInput(dataArr);

            }
            });
            */
            $("#tb_scoreChoice_5,#l_5,#tb_scoreChoice_6,#l_6,#tb_scoreChoice_5_d,#l_5_d,#tb_scoreChoice_6_d,#l_6_d").css("display", "none");
            $("#tb_editChoiceScore").SpinButton(); 

            $("input[id^='tb_scoreChoice_']").SpinButton({ min: -99, max: 999 });
            $("#tb_score_1,#p_tb_score_1,#tb_score_2,#tb_score_4,#tb_editScore_t,#tb_editScore_i,#tb_editScore_t").SpinButton({ min: 0 });
            $("#tb_socreRadio_1,#tb_socreRadio_2,#tb_socreRadio_3,#tb_socreRadio_4,#tb_socreRadio_5,#tb_socreRadio_6,#tb_socreDrop_1,#tb_socreDrop_2,#tb_socreDrop_3,#tb_socreDrop_4,#tb_socreDrop_5,#tb_socreDrop_6").SpinButton();
            $("#tb_choiceCount").SpinButton({ min: 2, max: 6 });

            //****属性面板*****
            $("#attr_top,#attr_left,#attr_width,#attr_height").SpinButton({ min: 0 });



            // $("#tb_scoreChoices").mask("999-99-9999", { completed: function() { alert("You typed the following: " + this.val()); } });

            //右键菜单
            var option = { width: 80, items: [
                            { text: "删除", icon: "/paperStyle/images/delete.png", alias: "1-1a", action: menuAction },
                            { text: "编辑", icon: "/paperStyle/images/edit.png", alias: "1-1", action: menuAction },

                            { type: "splitLine" },
                            { text: "添加", icon: "/paperStyle/images/newear_wiz_16x16.gif", alias: "1-2", type: "group", width: 100, items: [
                                { text: "下拉框", icon: "/paperStyle/images/dropdown.png", alias: "2-5", action: menuAction },
	                            { text: "单选组", icon: "/paperStyle/images/radio_16x16.png", alias: "2-1", action: menuAction },
                                { text: "多选组", icon: "/paperStyle/images/check_obj.gif", alias: "2-2", action: menuAction },
                                { text: "填空组", icon: "/paperStyle/images/input.png", alias: "2-3", action: menuAction },
                                { text: "文本框", icon: "/paperStyle/images/text.png", alias: "2-4", action: menuAction },
                                { text: "MP3", icon: "/paperStyle/images/media.png", alias: "2-6", action: menuAction }
                            ]

                            }

                            ], onShow: applyrule,
                onContextMenu: BeforeContextMenu
            };

            function menuAction(e, target) {//this.data.alias
                var scrollLeft = 0 - $(".paperArea").offset().left;
                var scrollTop = 0 - $(".paperArea").offset().top;
                if (this.data.alias == "1-1a") {delNodes(target) };
                if (this.data.alias == "1-1") { editPaper() };
                if (this.data.alias == "2-1") { displayRadioUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
                if (this.data.alias == "2-2") { displayCheckboxUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
                if (this.data.alias == "2-3") { displayInputUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
                if (this.data.alias == "2-4") { displayTextUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
                if (this.data.alias == "2-5") { displayDropUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
                if (this.data.alias == "2-6") { displayMediaUI(scrollLeft + e.data.pageX, scrollTop + e.data.pageY); };
            }
            function applyrule(menu) {

                if ($(this).hasClass("dragDiv")) {//在浮动元素上
                    menu.applyrule({ name: "target2",
                        disable: true,
                        items: ["1-2", "1-1"]
                    });
                }
                else {//在页面空白区
                    menu.applyrule({ name: "all",
                        disable: true,
                        items: []
                    });
                }
            }
            function BeforeContextMenu() {
                return true;
            }

            $(".paperArea,.dragDiv").contextmenu(option);

        });
        function setPropertyPanel(ob) {
            var sl = $(".ui-selected,.ui-selecting");

            if (sl.length != 1) { disabledDeck(true); return; };
            disabledDeck(false);
    $("#dock").show();
    $("#attr_width").val("0").attr("disabled", "disabled");
    $("#attr_height").val("0").attr("disabled", "disabled");
    if (ob.id != "page_fullScore") {
        var tt = ob.id.substring(5);

        var testGroupName = tt.split("_")[1];
        $("#editKeyHref").attr("href", "javascript:editKey('" + testGroupName + "')");
     
        switch (ob.id.substring(5, 6)) {
            case "c":
                
                $("#btn_upKey_c").unbind();
                $("#btn_upKey_c").bind("click", function () {
                    updateKey_c(testGroupName)
                });

                $("#attr_width").val("0").attr("disabled", "disabled");
                $("#attr_height").val("0").attr("disabled", "disabled");
                break;
            case "r":
                $("#btn_upKey_R").unbind();
                $("#btn_upKey_R").bind("click", function () {
                    updateKey_R(testGroupName)
                });
                $("#attr_width").val("0").attr("disabled", "disabled");
                $("#attr_height").val("0").attr("disabled", "disabled");
                break;
            case "d":
                $("#btn_upKey_D").unbind();
                $("#btn_upKey_D").bind("click", function () {
                    updateKey_D(testGroupName)
                });
                $("#attr_width").val("0").attr("disabled", "disabled");
                $("#attr_height").val("0").attr("disabled", "disabled");
                break;
            case "i":

                $("#btn_upKey_i").unbind();
                $("#btn_upKey_i").bind("click", function () {
                    updateKey_i(testGroupName)
                });

                $("#attr_width").val(parseInt(ob.offsetWidth)).attr("disabled", "");
                $("#attr_height").val("0").attr("disabled", "disabled");
                break;
            case "t":
                $("#btn_upKey_T").unbind();
                $("#btn_upKey_T").bind("click", function () {
                    updateKey_T(testGroupName)
                });
                $("#attr_height").val(parseInt(ob.style.height)).attr("disabled", "");

                $("#attr_width").val(parseInt(ob.style.width)).attr("disabled", "");
                break;
            case "m":
                $("#btn_editMp3").unbind();
                $("#btn_editMp3").bind("click", function () {
                    updateMp3(testGroupName)
                });
                $("#attr_height").val("0").attr("disabled", "disabled");

                $("#attr_width").val("0").attr("disabled", "disabled");
                break;
        };

        if (testGroupName.charAt(0) == "m") {
            $("#showKey").empty();
            $("#editKeyHref").hide();
            $('#div_MPreview').empty().media({
                flashvars: { autostart: 'false', bufferlength: 10 },
                height: 30, width: 150, autoplay: false, src: ob.url
            });
            $("#div_MPreview").append("<p style=\"text-align:right\"><a href=\"javascript:editFileUrl('"+testGroupName+"','" + ob.url + "')\">编辑</a></p>");
            
        } else {
            $("#editKeyHref").show(); $('#div_MPreview').empty()
            showKey(testGroupName);
        }
        
    }
    //设置属性面板
    $("#attr_top").val(parseInt(ob.style.top)); $("#attr_left").val(parseInt(ob.style.left));
    

};

function __SetCookie(sName, sValue) {
    document.cookie = sName + "=" + escape(sValue);
}
function __GetCookie(sName) {
    var aCookie = document.cookie.split(";");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == Trim(aCrumb[0])) {
            return unescape(aCrumb[1]);
        }
    }
    return null;
}

function Trim(strValue) {
    return strValue.replace(/^\s*|\s*$/g, "");
}   
