<%@ page language="VB" autoeventwireup="false" enabletheming="false" inherits="WebExam.Web.secure_editfilltest, App_Web_w5uoad04" %>
<%@ Register src="../modul/WebMsg.ascx" tagname="WebMsg" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>编辑试题</title>

    <script src="../paperStyle/3.1/key.js" type="text/javascript"></script>

    <link href="../../style/main.css" type="text/css" rel="stylesheet" />
 <script src="/jslib/jquery/jquery-lastest.js" type="text/javascript"></script>
<link type="text/css" href="/jslib/jquery/plugins/SpinButton/JQuerySpinBtn.css" rel="stylesheet" />
    <script type="text/javascript" src="/jslib/jquery/plugins/SpinButton/JQuerySpinBtn.js"></script>
    <style type ="text/css" >
        ol{ list-style-position:inside}
      li{float:left}
      .rightsPace{}
    </style>

</head>
<body onload="return window_onload()"><script type="text/javascript">
       $().ready(
        function() {
            $("#<%= TB_score.ClientId() %>").SpinButton({ min: 0 });
        });
       function getScoreBox(){return document.getElementById('<%= TB_score.ClientID %>');}
      function getKPBox(){return document.getElementById('<%= LB_keyPoint.ClientID %>');}
     
       function degreeBox(){return document.getElementById('<%= DDLdi.ClientID %>');}
       
       function submitInfo(plain,tests) {
       
       
         var kpidstr="";
         var kpidname="";
         var kpBox=getKPBox();
         for(var i=0;i<kpBox.options.length;i++){
           if(kpBox.options[i].selected){
             kpidstr+=","+kpBox.options[i].value;
             kpidname+=","+kpBox.options[i].text;
           }
         }
         if(kpidname.length>0){kpidname =kpidname.substr(1)}
         if (kpidstr.length > 0) { kpidstr = kpidstr.substr(1) }
         
         var test=tests[0].content;
         if(test==""){alert("题目内容必须输入！");return false;};
         
       var score=getScoreBox().value;
       if(parseFloat(score) <=0){
       
         alert("分值不能为0");return false;
     }

     var reg=/\s+/g;
     var fillArr = new Array();
     $("input[id^='fill_point_']").each(function(i) {
        var key=this.value.replace(reg, " ");
        
         fillArr[fillArr.length] = key;
       
       });

       for (var i = 0; i < fillArr.length; i++) {
           if (fillArr[i] == "")
        { alert("请填写答案！"); return false; }
       
       
       };

       var enumArr=new Array();
       $("input[id^='fill_enum_']").each(function(i) {
          if (this.checked) enumArr[enumArr.length]=i;
       });
       if (enumArr.length == 1) {alert("不分先后顺序的填空点不能只有一个！");return false; };
       var keyArr=new Array();
       keyArr[0] = fillArr;
       keyArr[1] = enumArr; 
       var ps=_para[0];
      
       ps.saveFillTest(document.getElementById('<%= TB_note.ClientID %>').value, score, plain, test, keyArr, degreeBox().value, kpidstr, kpidname);
       
       //return true;
      }
       /*
       function setKey(scoreArr,keyArr){
         var SB1=getScoreABox();var SB2=getScoreBBox();var SB3=getScoreCBox();var SB4=getScoreDBox();
         SB1.value=0;SB2.value=0;SB3.value=0;SB4.value=0;
         var KB1=getKBox1();var KB2=getKBox2();var KB3=getKBox3();var KB4=getKBox4();
         KB1.value="";KB2.value="";KB3.value="";KB4.value="";
         for(var i=0;i<keyArr.length;i++){
           switch(i){
             case 0:
               KB1.value=keyArr[i];SB1.value=scoreArr[i];
               break;
             case 1:
               KB2.value=keyArr[i];SB2.value=scoreArr[i];
               break;
             case 2:
               KB3.value=keyArr[i];SB3.value=scoreArr[i];
               break; 
             case 3:
               KB4.value=keyArr[i];SB4.value=scoreArr[i];
               break;
               
           }
         
         }
         
       }
       */
var tests;var _para;
function window_onload() {
  if((_para==null)&&(window.dialogArguments!=null)) {
     if(window.dialogArguments.length >0){_para=window.dialogArguments;}
        
  }
  
  tests=null;if(_para==null)return ;
  var para=_para;
  if(para.length>1){
     var level=para[1];
     var kpIdStr=para[2];
     tests=para[3];
     var keyArr=para[4];
     var score = para[5]; var note = para[6];
     setdata(note, score, level, kpIdStr, keyArr)
     
  }
  
}
function initData(note, score, level, kpIdStr, keyArr, tests) {
  editorFrame.init(tests);
  setdata(note, score, level, kpIdStr, keyArr)
     

}
function setdata(note, score, level, kpIdStr, keyArr) {
    
    if (note == null) note = "";
    document.getElementById('<%= TB_note.ClientID %>').value = note;


    getScoreBox().value = score;
    if (level == null) level = "0";
    if (level == "") level = "0";
     degreeBox().value=level;
     var kpBox=getKPBox();
     var kpArr=kpIdStr.split(",");
     
     for(var i=0;i<kpBox.options.length;i++){
           var kpid=kpBox.options[i].value;
           var selected=false;
           for(var J=0;J<kpArr.length;J++){
             if(kpArr[J]==kpid){selected =true;break;}
     
           }
         
           kpBox.options[i].selected=selected;
         
    }
    fill_OL(keyArr)
};
function fill_OL(keyStr) {
   
    if (keyStr == "") return;
var keyXML = new ActiveXObject("Microsoft.XMLDOM");
            keyXML.async = false
            keyXML.loadXML("<?xml version='1.0' encoding='utf-8' ?><keys>"+keyStr+"</keys>");
            var keyNode = keyXML.selectSingleNode("/keys/key");
            var subKeys = keyNode.selectNodes("key");
            
            var fillCount = -1;
            for (var i = 0; i < subKeys.length; i++) {
                var subKey = subKeys[i];
                var fork = subKey.getAttribute("for").split(",");
                for (var j = 0; j < fork.length; j++) {
                    var f = fork[j];
                    if (f > fillCount) fillCount = f;

                };
            };
            fillCount++; //填空点的数量
            if (fillCount == 0) fillCount = 1;
            var keyObj =new key(keyNode);
            var keyChildren = keyObj.children();
            var tb = "";
            for (var i = 0; i < fillCount; i++) {
                
                
                var trBody = "<li>";
                trBody += "<input title='如有多个答案请用一个半角空格隔开' id='fill_point_" + i + "' value='' />";
                trBody += "<input type='checkbox' onclick='hasEnumKey()' class='rightsPace' title='与其他选中答案不区分先后顺序' id='fill_enum_" + i + "' value='" + i + "' />";
                trBody += "</li>";
                tb += trBody;
            };

            document.getElementById("fill_ol").innerHTML = tb; 
            //keyTable.innerHTML;
            var keyCount = subKeys.length;
            if (keyCount > 0) {
                for (var j = 0; j < keyCount; j++) {
                    var sk = keyChildren.item(j);
                    var forId = sk.getForKey();

                    for (var k = 0; k < forId.length; k++) {
                        var ddd = sk.children();
                        var input = document.getElementById("fill_point_" + forId[k]);
                        if (forId.length == 1) {
                            input.value = sk.getStandardKey();
                        } else {

                            input.value = ddd.item(k).getStandardKey();
                        };
                        if (forId.length > 1) { if (sk.getScoreMode() == "enum") { document.getElementById("fill_enum_" + forId[k]).checked = true; } else { document.getElementById("fill_enum_" + forId[k]).checked = false; }; };

                    };



                };

            } else {
                //答案数量1;
                var input = document.getElementById("fill_point_0");

                input.value = keyObj.getStandardKey();

            }
            
            //if (fill_ul.childNodes.length == 0) { deleteItemUI.disabled = true; };
            if (fill_ol.childNodes.length <= 1) deleteFillUI.disabled = true; else
                deleteFillUI.disabled = false;
            hasEnumKey()
        };
        function hasEnumKey() {
            var c = false;
            $("input[id^='fill_enum_']").each(function(i){
              if (this.checked) c=true ;
            });
           // if (c) { addItemUI.disabled = false;  } else { addItemUI.disabled = true; deleteItemUI.disabled = true; };
        
        };
        function addItem(v) {
            if (v == null) v = "";
            var i = fill_ul.childNodes.length; 
            var trBody = "<input id='fill_append_" + i + "' value='"+v+"' />";
            //trBody += "<input type='checkbox' id='fill_append_enum_" + i + "' value='" + i + "' />";
            var ele = document.createElement("<li></li>")
            ele.innerHTML = trBody;
            fill_ul.appendChild(ele);
            deleteItemUI.disabled = false;

        };
        function deleteItem() {
            if (fill_ul.childNodes.length == 0) return;
            fill_ul.removeChild(fill_ul.lastChild);
            if (fill_ul.childNodes.length == 0) deleteItemUI.disabled = true;

        };
        function addFillItem() {
            var i = fill_ol.childNodes.length;
            var trBody = "<input title='如有多个答案请用一个半角空格隔开' id='fill_point_" + i + "' value='' />";
            trBody += "<input title='与其他选中答案不区分先后顺序' type='checkbox' onclick='hasEnumKey()' id='fill_enum_" + i + "' value='" + i + "' />";
            var ele = document.createElement("<li></li>")
            ele.innerHTML = trBody;
            fill_ol.appendChild(ele);
            if (fill_ol.childNodes.length <= 1) deleteFillUI.disabled = true; else
                deleteFillUI.disabled = false;

        };
        function deleteFillItem() {
            if (fill_ol.childNodes.length == 0) return;
            fill_ol.removeChild(fill_ol.lastChild);
            if (fill_ol.childNodes.length <= 1) deleteFillUI.disabled = true; else
                deleteFillUI.disabled = false;
        };
</script>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager><uc1:WebMsg ID="WebMsg1" runat="server" />
    <iframe frameborder="0" id="editorFrame" align="center" name="mytext" marginwidth="0"
        marginheight="0" src="../../../richedit/_samples/html/richedit.htm?testclass=c"
        frameborder="no" width="770" height="399" scrolling="no"></iframe>
   
    <table bgcolor="#99FF66"  width="100%">
    <tr><td colspan="3">解析<asp:TextBox ID="TB_note" runat="server" Text="" Width="720"></asp:TextBox></td></tr>
      
        <tr><td colspan="3"><div>
        <ol id="fill_ol"><li><input id='fill_point_0' title='如有多个答案请用一个半角空格隔开' value='' /><input type='checkbox' onclick='hasEnumKey()' title='与其他选中答案不区分先后顺序' id='fill_enum_0' class='rightsPace' value='0' /></li></ol>
        
        </div>
     
        </td></tr>
        <tr>
        <td><a id="addFillUI" href="javascript:addFillItem();">添加填空点</a>
        <a id="deleteFillUI" href="javascript:deleteFillItem();" disabled="disabled">移除填空点</a>
        每空分值<asp:TextBox ID="TB_score" runat="server" Text="1" Width="20"></asp:TextBox>
        
        </td>
        <td>
         难度
                <asp:DropDownList ID="DDLdi" runat="server">
                    <asp:ListItem Value="0">0</asp:ListItem>
                    <asp:ListItem Value="1" Selected="True">1</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="5">5</asp:ListItem>
                </asp:DropDownList>
        </td>
            <td valign="top">
            
               
               选择知识点
                <asp:ListBox ID="LB_keyPoint" runat="server" Height="55px" SelectionMode="Multiple" CssClass="FormText1">
                </asp:ListBox>

                <input type="button" class="bigButton" value="保存" onclick="return editorFrame.getTest();" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
