

var editor_a=null;
var editor_b=null;
var editor_c=null;
var editor_d=null;
var editor_e=null;
var editor_f = null;
var editor_i = null;
function openEditor(mode,para){
  var search=self.location.search;
  var style = "dialogHeight:560px;dialogWidth:770px;scroll:no;Status:no;help:no";
  //var 
  if ($.browser.msie) {
     if (jQuery.browser.version>6.0)
       style = "dialogHeight:530px;dialogWidth:770px;scroll:no;Status:no;help:no";
  
   }


  switch(mode){
     case "":
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if((editor_e!=null)&&(!editor_e.closed))editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       return;
       break;
     case "a":
       //关闭其他题型窗口
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if((editor_e!=null)&&(!editor_e.closed))editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close(); 
       if((editor_a==null)||(editor_a.closed))
         editor_a = window.showModelessDialog("../../testeditor/editsingletest.aspx"+search,para,style);
       else     
         setEditor(mode,para); 
       break; 
     case "b":
       //关闭其他题型窗口
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if((editor_e!=null)&&(!editor_e.closed))editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       if((editor_b==null)||(editor_b.closed))
         editor_b = window.showModelessDialog("../../testeditor/editmultest.aspx"+search,para,style);
       else     
         setEditor(mode,para); 
       break; 
     case "c":
       //关闭其他题型窗口
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if((editor_e!=null)&&(!editor_e.closed))editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       style = "dialogHeight:600px;dialogWidth:770px;scroll:yeso;Status:no;help:no";
       if((editor_c==null)||(editor_c.closed))
         editor_c = window.showModelessDialog("../../testeditor/editfilltest.aspx"+search,para,style);
       else     
         setEditor(mode,para); 
       break; 
     case "d":
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_e!=null)&&(!editor_e.closed))editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       if((editor_d==null)||(editor_d.closed))
         editor_d = window.showModelessDialog("../../testeditor/editjudgetest.aspx"+search,para,style);
       else     
         setEditor(mode,para); 
       break; 
     case "e":
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       if((editor_e==null)||(editor_e.closed))
         editor_e = window.showModelessDialog("../../testeditor/editanswertest.aspx"+search,para,style);
       else     
         setEditor(mode,para); 
       break;
     case "f":
       if((editor_a!=null)&&(!editor_a.closed))editor_a.close();
       if((editor_b!=null)&&(!editor_b.closed))editor_b.close();
       if((editor_c!=null)&&(!editor_c.closed))editor_c.close();
       if((editor_d!=null)&&(!editor_d.closed))editor_d.close();
       if ((editor_e != null) && (!editor_e.closed)) editor_e.close();
       if ((editor_i != null) && (!editor_i.closed)) editor_i.close();
       if((editor_f==null)||(editor_f.closed))
         editor_f = window.showModelessDialog("../../testeditor/editchoicetest.aspx"+search,para,style);
       else     
         setEditor(mode,para);
       break;
     case "i":
       if ((editor_a != null) && (!editor_a.closed)) editor_a.close();
       if ((editor_b != null) && (!editor_b.closed)) editor_b.close();
       if ((editor_c != null) && (!editor_c.closed)) editor_c.close();
       if ((editor_d != null) && (!editor_d.closed)) editor_d.close();
       if ((editor_e != null) && (!editor_e.closed)) editor_e.close();
       if ((editor_f != null) && (!editor_f.closed)) editor_f.close();
       if ((editor_i == null) || (editor_i.closed))
          editor_i = window.showModelessDialog("../../testeditor/editreadtest.aspx" + search, para, style);
       else
          setEditor(mode, para);
       break; 
  }
}
function setEditor(mode,para){
   var fullScore=para[5];
   var level=para[1];
   var kpIdStr=para[2];
   var score=para[4];
   var test=para[3];
   
   switch(mode){
     case "a":
       if((editor_a!=null)&&(!editor_a.closed)) editor_a.initData(para[6],fullScore,level,kpIdStr,score,test);  
       break;
     case "b":
       if((editor_b!=null)&&(!editor_b.closed)) editor_b.initData(para[7],fullScore,level,kpIdStr,score,test,para[6]);  
       break;
     case "c":
       if((editor_c!=null)&&(!editor_c.closed)) editor_c.initData(para[6],fullScore,level,kpIdStr,score,test);  
       break;
     case "d":
         if ((editor_d != null) && (!editor_d.closed)) editor_d.initData(para[6], fullScore, level, kpIdStr, score, test);  
       break; 
     case "e":
         if ((editor_e != null) && (!editor_e.closed)) editor_e.initData(para[6], fullScore, level, kpIdStr, test);  
       break; 
     case "f":
         if ((editor_f != null) && (!editor_f.closed)) editor_f.initData(para[6], fullScore, level, kpIdStr, score, test);
       break;
     case "i":
       if ((editor_i != null) && (!editor_i.closed)) editor_i.initData(test);
       break;
  }

}
function initEditor(){
  if((editor_a!=null)&&(!editor_a.closed))editor_a.editorFrame.init();
  if((editor_b!=null)&&(!editor_b.closed))editor_b.editorFrame.init();
  if((editor_c!=null)&&(!editor_c.closed))editor_c.editorFrame.init();
  if((editor_d!=null)&&(!editor_d.closed))editor_d.editorFrame.init();
  if((editor_e!=null)&&(!editor_e.closed))editor_e.editorFrame.init();
  if((editor_f!=null)&&(!editor_f.closed))editor_f.editorFrame.init();
}
//添加单选题
var edit=false;var _testId=-1;
function saveSingleTest(note,score,plain,tests,scoreA,scoreB,scoreC,scoreD,scoreE,scoreF,levle,kp1,kp2){
  if(edit)
      send.editSingleTest(note, requestQueryString("paperid"), _testId, score, plain, tests[0], tests[1], tests[2], tests[3], tests[4], tests[5], tests[6], scoreA, scoreB, scoreC, scoreD, scoreE, scoreF, levle, kp1, kp2, saveOk);
  else
      send.addSingleTest(note, requestQueryString("paperid"), toTheme, score, plain, tests[0], tests[1], tests[2], tests[3], tests[4], tests[5], tests[6], scoreA, scoreB, scoreC, scoreD, scoreE, scoreF, levle, kp1, kp2, saveOk);
}
function saveChoiceTest(note, score, plain, tests, scoreA, scoreB, scoreC, scoreD, levle, kp1, kp2) {
  if(edit)
      send.editChoiceTest(note, requestQueryString("paperid"), _testId, score, plain, tests[0], tests[1], tests[2], tests[3], scoreA, scoreB, scoreC, scoreD, levle, kp1, kp2, saveOk);
  else
      send.addChoiceTest(note, requestQueryString("paperid"), toTheme, score, plain, tests[0], tests[1], tests[2], tests[3], scoreA, scoreB, scoreC, scoreD, levle, kp1, kp2, saveOk);
}
//编辑文本题
function saveReadTest(plain, test) {
    
        send.editReadTest(requestQueryString("paperid"), _testId, plain, test, saveOk);
    
}
//添加判断题
function saveJudgeTest(note, score, plain, test, keyArr, levle, kp1, kp2) {
    
  if(edit)
      send.editJudgeTest(note, requestQueryString("paperid"), _testId, score, plain, test, keyArr[0], keyArr[1], levle, kp1, kp2, saveOk);
  else
      send.addJudgeTest(note, requestQueryString("paperid"), toTheme, score, plain, test, keyArr[0], keyArr[1], levle, kp1, kp2, saveOk);
}
function saveRanTest(subjectId,difficulty,kp,count,score){
  if (kp=="")kp="-1";
  if(edit)
      send.editRanTest(requestQueryString("paperid"), _ranTestId, score, subjectId, difficulty, count, kp, saveOk);
  else
      send.addRanTest(requestQueryString("paperid"), toTheme, score, subjectId, difficulty, count, kp, saveOk);
}
function saveAnswerTest(note, score, plain, test, key, levle, kp1, kp2) {
  if(edit)
      send.editAnswerTest(note, requestQueryString("paperid"), _testId, score, plain, test, key, levle, kp1, kp2, saveOk);
  else
      send.addAnswerTest(note, requestQueryString("paperid"), toTheme, score, plain, test, key, levle, kp1, kp2, saveOk);
}
function saveMulTest(note, score, plain, tests, scoreArr, keyArr, levle, kp1, kp2) {
  var scoreA=0;var scoreB=0;var scoreC=0;var scoreD=0;var scoreO=scoreArr[4];
  var k1="";var k2="";var k3="";var k4="";
  for(var i=0;i<keyArr.length;i++){
           switch(i){
             case 0:
               k1=keyArr[i];scoreA=scoreArr[i];
               break;
             case 1:
               k2=keyArr[i];scoreB=scoreArr[i];
               break;
             case 2:
               k3=keyArr[i];scoreC=scoreArr[i];
               break;
             case 3:
               k4=keyArr[i];scoreD=scoreArr[i];
               break;
            
           }
         
  }
  
  
  if(edit)
      send.editMulTest(note, requestQueryString("paperid"), _testId, score, plain, tests[0], tests[1], tests[2], tests[3], tests[4], tests[5], tests[6], scoreA, scoreB, scoreC, scoreD, scoreO, k1, k2, k3, k4, levle, kp1, kp2, saveOk);
  else
      send.addMulTest(note, requestQueryString("paperid"), toTheme, score, plain, tests[0], tests[1], tests[2], tests[3], tests[4], tests[5], tests[6], scoreA, scoreB, scoreC, scoreD, scoreO, k1, k2, k3, k4, levle, kp1, kp2, saveOk);
}
function saveFillTest(note, score, plain, test, keyArr, levle, kp1, kp2) {
    
  if(edit)
      send.editFillTest(note, requestQueryString("paperid"), _testId, score, plain, test, keyArr[0], keyArr[1], levle, kp1, kp2, saveOk);
  else
      send.addFillTest(note, requestQueryString("paperid"), toTheme, score, plain, test, keyArr[0], keyArr[1], levle, kp1, kp2, saveOk);
}


function getCover(){
 var cover=document.getElementById("cover");
  
 if(cover==null){
   var doc=document;
   
   var div=doc.createElement("div");
   div.style.zIndex="10000";
   div.style.top="0";
   div.style.left="0";
   div.style.position="absolute";
   div.style.background="#808080";
   div.style.filter="alpha(opacity=90)";
   div.style.width="100%";
   div.style.height="100%";
   div.id="cover";
   
   
   doc.paperForm.appendChild(div);
   cover=div;
  }
  else{
    //cover.innerHTML="";
  
  }
 return cover;
}
function removeChildren(parentEle,eleId){
 for (var i=0;i<parentEle.childNodes.length;i++){
   var child=parentEle.childNodes[i];
   if(child.id!=eleId)parentEle.removeChild(child) 
 
 
  }

}
function getEditTxt(parentEle,cmd){
 removeChildren(parentEle,"front_editTxt")
 var front=document.getElementById("front_editTxt");
 if(front==null){
   var doc=document;
  
   var div=doc.createElement("div");
   //div.style.zIndex="10000";
   div.style.top="50%";
   div.style.left="50%";
   div.style.position="absolute";
   div.style.background="#fff";
   div.style.marginTop ="-100px";
   div.style.marginLeft="-150px";
   div.style.width="350px";
   div.style.height="200px";
   div.style.padding ="0";
   div.style.border ="4px outset #808080";
   div.id="front_editTxt";
   
   
   parentEle.appendChild(div);
   front=div;
  }
  var htm="<img src='../../images/msgClose.jpg' style='float:right;top:0;' onclick=\"parent.getCover().style.display='none'\" />"
   htm+="<h3 style='padding:0 0 30 0;margin:5px'>请输入新值</h3><div><input id='TB_editTxt' type='text' style='width:100%;' /></div>";
   htm+="<div style='margin:50 0 0 0;text-align:center'><input type='button' onclick='javascript:eval(\"parent."+cmd+"\")' value='保存' style='margin:10;width:100px;height:30px;font-weight:bold' />";
   htm+="<input type='button' onclick=\"javascript:parent.getCover().style.display='none'\" value=\"取消\" style='margin:10;width:50px;height:30px;' /></div>";

   front.innerHTML=htm;
 return front;

}
function editTxt(txt,themeId){

  var newTxt=window.showModalDialog("edittxt.htm",txt,"dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
  if(newTxt==null)return;if(newTxt=="")return;
  if(themeId!=null)send.updateTheme(requestQueryString("paperid"),themeId,newTxt,saveOk);
  else send.editTitle(requestQueryString("paperid"),newTxt,saveOk);
 
  
}
var _ranTestId=-1;
function editSingleTest(testId,fullScore,level,kpIdStr,plain){
  _testId=testId;
  var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  var testStr=testNode.selectSingleNode("text").text;
  var xxa=testNode.selectSingleNode("choice[@key='a']").text;
  var xxb=testNode.selectSingleNode("choice[@key='b']").text;
  var xxc="";var xxd="";var xxe="";var xxf="";
  var xxcNode=testNode.selectSingleNode("choice[@key='c']");
  if(xxcNode)xxc=xxcNode.text;
  var xxdNode=testNode.selectSingleNode("choice[@key='d']");
  if(xxdNode)xxd=xxdNode.text;
  var xxeNode=testNode.selectSingleNode("choice[@key='e']");
  if(xxeNode)xxe=xxeNode.text;
  var xxfNode=testNode.selectSingleNode("choice[@key='f']");
  if(xxfNode)xxf=xxfNode.text;
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0]=testStr;
  
  test[1]=xxa;
  test[2]=xxb;
  test[3]=xxc;
  test[4]=xxd;
  test[5]=xxe;
  test[6]=xxf;
  test[7]=plain;
  sara[3]=test;//试题
  
  var score=new Array();
  score[0] = 0; score[1] = 0; score[2] = 0; score[3] = 0; score[4] = 0; score[5] = 0;
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
  var keyObj=__keys.getKeyById(testId)
  var keys=keyObj.children();
  if(keys.count()==0){
     var key=keyObj.getStandardKey();
     var ss=keyObj.getInpro();
     switch (key){
       case "a":
         score[0]=ss;break;
       case "b":
         score[1]=ss;break;
       case "c":
         score[2]=ss;break;
       case "d":
         score[3]=ss;break;
       case "e":
         score[4]=ss;break;
       case "f":
         score[5]=ss;break;
     
     }
  
  }
  else{
    for(var j=0;j<keys.count();j++){
      var key=keys.item(j).getStandardKey();
      var ss=keys.item(j).getInpro();
      switch (key){
       case "a":
         score[0]=ss;break;
       case "b":
         score[1]=ss;break;
       case "c":
         score[2]=ss;break;
       case "d":
         score[3]=ss;break;
       case "e":
         score[4]=ss;break;
       case "f":
         score[5]=ss;break;
     
      }
    }
  
  
  }
  sara[4]=score;//分值
  sara[5] = fullScore; //满分
  if (__notes != null) {
     var noteObj=__notes.getNoteById(testId);
     if(noteObj !=null)
         sara[6] = noteObj.text();
  };
  edit = true; 
  openEditor("a",sara);

}

function editFillTest(testId, fullScore, level, kpIdStr, plain) {

  _testId=testId;
   var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  var testStr=testNode.selectSingleNode("text").text;
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0]=testStr;test[1]=plain;
  sara[3]=test;//试题
  
  var key="";var key0="";var key1="";
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
  var keyObj=__keys.getKeyById(testId)
  var keys=keyObj.children();
  var keyCount=keys.count();if (keyCount == 0) keyCount = 1;
  var keyArr = keyObj.getOutXML();
  
 
  keyArr[0]=key;keyArr[1]=key0;keyArr[2]=key1; 
  sara[4]=keyArr;//答案
  sara[5]=fullScore/keyCount;//分
  edit = true; if (__notes != null) {
      var noteObj = __notes.getNoteById(testId);
      if (noteObj != null)
          sara[6] = noteObj.text();
  };
  openEditor("c",sara);

}
function editReadTest(themeId,textId, plain) {
    toTheme = themeId;
    _testId = textId;
    var testNode = paperDoc.selectSingleNode("//text[@id='" + textId + "']");
    var testStr = testNode.text;
    var sara = new Array();
    sara[0] = self; //窗体
    sara[1] = null;
    sara[2] = null;
    var test = new Array();
    test[0] = testStr;

    test[1] = plain;
    sara[3] = test; //试题

   

    sara[4] = null; //分值
    sara[5] = 0; //满分
    edit = true;
    openEditor("i", sara);

}
function editJudgeTest(testId,fullScore,level,kpIdStr,plain){

  _testId=testId;
   var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  var testStr=testNode.selectSingleNode("text").text;
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0]=testStr;
  
  test[1]=plain;
  sara[3]=test;//试题
  
  var score=new Array();
  score[0] = 0; score[1] = 0; score[2] = 0;
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
  var keyObj=__keys.getKeyById(testId)
  var key=keyObj.getStandardKey();
  if(key=="0"){score[0]=keyObj.getInpro();score[1]=keyObj.getOtherScore();}else {score[1]=keyObj.getInpro();score[0]=keyObj.getOtherScore();}
  
  
  sara[4]=score;//分值
  sara[5] = fullScore; //满分
  if (__notes != null) {
      var noteObj = __notes.getNoteById(testId);
      if (noteObj != null)
          sara[6] = noteObj.text();
  };
  edit=true;
  openEditor("d",sara);

}
function editAnswerTest(testId,fullScore,level,kpIdStr,plain){
  _testId=testId;
   var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  var testStr=testNode.selectSingleNode("text").text;
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0] = testStr;
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; };
  
  var keyObj=__keys.getKeyById(testId)
  var key=keyObj.getStandardKey();
  test[1]=key;test[2]=plain;
  sara[3]=test;//试题
  
  
  
  sara[4]="";//分值
  sara[5] = fullScore; //满分
  if (__notes != null) {
      var noteObj = __notes.getNoteById(testId);
      if (noteObj != null)
          sara[6] = noteObj.text();
  };
  
  edit=true;
  openEditor("e",sara);

}
function editChoiceTest(testId,fullScore,level,kpIdStr,plain){
  _testId=testId;
   var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  
  var xxa=testNode.selectSingleNode("choice[@key='a']").text;
  var xxb=testNode.selectSingleNode("choice[@key='b']").text;
  var xxc="";var xxd="";
  var xxcNode=testNode.selectSingleNode("choice[@key='c']");
  if(xxcNode)xxc=xxcNode.text;
  var xxdNode=testNode.selectSingleNode("choice[@key='d']");
  if(xxdNode)xxc=xxdNode.text;
  
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0]=xxa;
  
  test[1]=xxb;
  test[2]=xxc;
  test[3]=xxd;
 
 
  test[4]=plain;
  sara[3]=test;//试题
  
  var score=new Array();
  score[0] = 0; score[1] = 0; score[2] = 0; score[3] = 0;
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
  var keyObj=__keys.getKeyById(testId)
  var keys=keyObj.children();
  if(keys.count()==0){
     var key=keyObj.getStandardKey();
     var ss=keyObj.getInpro();
     switch (key){
       case "a":
         score[0]=ss;break;
       case "b":
         score[1]=ss;break;
       case "c":
         score[2]=ss;break;
       case "d":
         score[3]=ss;break;
       
     
     }
  
  }
  else{
    for(var j=0;j<keys.count();j++){
      var key=keys.item(j).getStandardKey();
      var ss=keys.item(j).getInpro();
      switch (key){
       case "a":
         score[0]=ss;break;
       case "b":
         score[1]=ss;break;
       case "c":
         score[2]=ss;break;
       case "d":
         score[3]=ss;break;
      
     
      }
    }
  
  
  }
  sara[4]=score;//分值
  sara[5]=fullScore;//满分
  edit = true; if (__notes != null) {
      var noteObj = __notes.getNoteById(testId);
      if (noteObj != null)
          sara[6] = noteObj.text();
  };
  openEditor("f",sara);

}
//从题库添加
function addFromStore(testClass,appendTo){
  
  var paperId=requestQueryString("paperid");
  var url="addFromStore.aspx?tx="+testClass+"&append="+appendTo+"&paperid="+paperId;
  
  window.open(url,"addFromStore");
}

function appendToPaper(tx,subjectId,checkList,appendto,paperid){
  var ids=checkList.toString();
  send.appendToPaperFromStore(paperid, subjectId, tx, ids, appendto, saveOk);

}

//显示新的填空题
function showNewFillTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  
  
  var keyArr="";
  
  var tests=new Array()
  tests[0]="";tests[1]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]=keyArr;sara[5]=0;
  openEditor("c",sara);
    
 
}        
//显示新的判断题
function showNewJudgeTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  
  
  var keyArr=new Array();
  keyArr[0]=0;keyArr[1]=0;
  var tests=new Array()
  tests[0]="";tests[1]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]=keyArr;sara[5]=0;
  openEditor("d",sara);
    
 
}
//显示新的问答题
function showNewAnswerTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  
  var tests=new Array()
  tests[0]="";tests[1]="";tests[2]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]="";sara[5]=0;
  openEditor("e",sara);
 
 
}        
function convertFillKeyToStr(keyObj,use0,use1,first){
  var key="";
  var keys=keyObj.children();
  var keyCount=keys.count();
  var y0=null;var y1=null;
  if(keyCount==0){
     key=keyObj.getStandardKey();
     
  }
  else{
    
    var kk=new Array();
    
    for(var j=0;j<keyCount;j++){
      var subKey=keys.item(j);
      var subFor=subKey.getForKey();
      var subKeyChild=subKey.children();
      var subKeyChildCount=subKeyChild.count();
      if(subKeyChildCount==0){
        var k=subKey.getStandardKey();
        for(var jj=0;jj<subFor.length;jj++){
          if(first)kk[subFor[jj]]=k;else kk[j]=k;
        }
      }
      else{
        //var subKey00=subKeyChild.item(j);
        var yy="";
        if(!use0){yy="@0";}else{yy="@1";}
        for(var jj=0;jj<subFor.length;jj++){
          var dd;
          if(first)dd=subFor[jj];else dd=j;
          kk[dd]=yy;
        }
        if(!use0){use0=true;y0=subKey;}else{use1=true;y1=subKey;}
      }
      
      
    }
    
    
    key=kk.join(" "); 
    
    //fullScore=fullScore/keyCount;
  
  }
  var r =new Array();
  //y0=kk.sss
  r[0]=key;r[1]=y0;r[2]=y1;r[3]=use0;r[4]=use1;
  return r;
}
function delTheme(themeId){
  if(confirm("确定要删除吗？")){
    send.delTheme(requestQueryString("paperid"),themeId,saveOk);
  
  }
}
function delTest(testId){
  if(confirm("确定要删除吗？")){
    send.delTest(requestQueryString("paperid"),testId,saveOk);
  
  }

}
function delRanTest(testId){
  if(confirm("确定要删除吗？")){
    send.delRanTest(requestQueryString("paperid"),testId,saveOk);
  
  }

}
//显示新的添加试题界面
var toTheme=-1;
function showNewChoiceTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  var scores=new Array();
  scores[0]=0;scores[1]=0;scores[2]=0;scores[3]=0;
  var tests=new Array()
  tests[0]="";tests[1]="";tests[2]="";tests[3]="";tests[4]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]=scores;sara[5]=0;
  
  openEditor("f",sara);
  
 
}
function showNewSingleTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  var scores=new Array();
  scores[0]=0;scores[1]=0;scores[2]=0;scores[3]=0;scores[4]=0;scores[5]=0;
  var tests=new Array()
  tests[0]="";tests[1]="";tests[2]="";tests[3]="";tests[4]="";tests[5]="";tests[6]="";tests[7]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]=scores;sara[5]=0;
  
  openEditor("a",sara);
  
 
}
//显示新的多选题


function showNewMulTest(appendTo){
 toTheme=appendTo;
 var sara=new Array();
  sara[0]=self;
  edit=false;
  
  var scores=new Array();
  scores[0]=0;scores[1]=0;scores[2]=0;scores[3]=0;scores[4]=0;
  var keyArr=new Array();
  keyArr[0]="";keyArr[1]="";keyArr[2]="";keyArr[3]="";
  var tests=new Array()
  tests[0]="";tests[1]="";tests[2]="";tests[3]="";tests[4]="";tests[5]="";tests[6]="";tests[7]=true;
  sara[1]="1";sara[2]="";sara[3]=tests;sara[4]=scores;sara[5]=0;sara[6]=keyArr;
  openEditor("b",sara);
    
 
}

//编辑多选题
function editMulTest(testId,fullScore,level,kpIdStr,plain){
  _testId=testId;
   var testNode=paperDoc.selectSingleNode("//test[@id='"+testId+"']");
  var testStr=testNode.selectSingleNode("text").text;
  var xxa=testNode.selectSingleNode("choice[@key='a']").text;
  var xxb=testNode.selectSingleNode("choice[@key='b']").text;
  var xxc="";var xxd="";var xxe="";var xxf="";
  var xxcNode=testNode.selectSingleNode("choice[@key='c']");
  if(xxcNode)xxc=xxcNode.text;
  var xxdNode=testNode.selectSingleNode("choice[@key='d']");
  if(xxdNode)xxd=xxdNode.text;
  var xxeNode=testNode.selectSingleNode("choice[@key='e']");
  if(xxeNode)xxe=xxeNode.text;
  var xxfNode=testNode.selectSingleNode("choice[@key='f']");
  if(xxfNode)xxf=xxfNode.text;
  var sara=new Array();
  sara[0]=self;//窗体
  sara[1]=level;
  sara[2]=kpIdStr;
  var test=new Array();
  test[0]=testStr;
  
  test[1]=xxa;
  test[2]=xxb;
  test[3]=xxc;
  test[4]=xxd;
  test[5]=xxe;
  test[6]=xxf;
  test[7]=plain;
  sara[3]=test;//试题
  var keyArr=new Array();
  var score=new Array();
  score[0] = 0; score[1] = 0; score[2] = 0; score[3] = 0; score[4] = 0;
  if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
  var keyObj=__keys.getKeyById(testId)
  var keys=keyObj.children();
  score[4]=keyObj.getOtherScore();
  if(keys.count()==0){
     var key=keyObj.getStandardKey();
     var ss=keyObj.getInpro();
     score[0]=ss;
     keyArr[0]=key;
  }
  else{
    for(var j=0;j<keys.count();j++){
      var key=keys.item(j).getStandardKey();
      var ss=keys.item(j).getInpro();
      score[j]=ss;
      keyArr[j]=key;
      
    }
  
  
  }
  sara[4]=score;//分值
  sara[5]=fullScore;//满分
  sara[6] = keyArr; if (__notes != null) {
      var noteObj = __notes.getNoteById(testId);
      if (noteObj != null)
          sara[7] = noteObj.text();
  };
  edit=true;
  openEditor("b",sara);

}
//显示新的大题编辑界面
var preNewTx=null;
function showNewTheme(tx,toTheme){
  if(tx==preNewTx)return;
  switch(tx){
    case "a":
      var txt=window.showModalDialog("edittxt.htm","单选题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(0, txt, toTheme)
      break;
    case "b":
      var txt=window.showModalDialog("edittxt.htm","多选题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(1, txt, toTheme)
      break;
    case "c":
      var txt=window.showModalDialog("edittxt.htm","填空题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(2, txt, toTheme)
      break;
    case "d":
      var txt=window.showModalDialog("edittxt.htm","判断题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(3, txt, toTheme)
      break;
    case "e":
      var txt=window.showModalDialog("edittxt.htm","问答题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(4, txt, toTheme)
      break;
    case "f":
      var txt=window.showModalDialog("edittxt.htm","选项题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(5, txt, toTheme)
      break;
    case "g":
      var txt=window.showModalDialog("edittxt.htm","----随机题","dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(6, txt, toTheme)
      break;
    case "i":
      var txt = window.showModalDialog("edittxt.htm", "阅读理解题", "dialogHeight:180px;dialogWidth:500px;scroll:no;Status:no;help:no");
      addTheme(8, txt, toTheme)
      break;
  }

preNewTx=tx;
}
//保存新建的大题
function addTheme(tx, txt, toTheme) {
  if(txt==null)return;
  if (txt == "") return;
  if (toTheme == null) toTheme = -1;
  else
      if (toTheme == "") toTheme = -1;
  send.addTheme(requestQueryString("paperid"),tx,txt,toTheme,saveOk);

}
var _an="";
function saveOk(result) 
       { if(result==null){alert("服务器无返回，0");return}
         if(result==""){alert("服务器无返回，1");return}
         var r=new Array();
         r=result.split(",");
         if(r[0]=="1"){
            //操作成功
            //location="about:blank";
            _an=r[1];
            //location.replace("loadpaper.aspx"+self.location.search+"&edit=1&b="+Math.random()+"#"+_an);
            //__keys=null;_keyPaper=new loadPaperKey("loadpaper.k.aspx"+self.location.search);
            displayPaper(_an)
            initEditor();
            edit=false;
            //alert(t+"==="+location.href)
            //location.reload();
            //getCover().style.display="none";
         }else{
           //操作失败
           alert (r[1])
         
         }
   }

   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, "");
   }
   var paperDoc = new ActiveXObject("Microsoft.XMLDOM"); paperDoc.load(self.location.href);
   $().ready(function () {
       var top = __GetCookie("scrollTop");
       $(window).scrollTop(top); $(window).scroll(function () { __SetCookie("scrollTop", $(window).scrollTop()); });
      
   
   });