
//window.onload =GetExamineeKeyInit;
//得到考生的答卷
function GetExamineeKeyInit() {
    
  //得到用户id


    formReset(); //表单还原
  
  var examinee=""
  examinee=requestQueryString("ek");
  if(examinee=="")return;
  var keypath=""
  keypath="stukey/"+examinee+".u.xml";
  
  
  
 
  //得到考生答案
 
   
   var myKeyXML=new ActiveXObject ("Microsoft.XMLDOM");
   myKeyXML.async = false
   
     myKeyXML.load(keypath)
  if (myKeyXML.parseError.errorCode!=0){
    var examid=requestQueryString("ei");
    myKeyXML.load("/exam/getPublicKey.aspx?ei="+examid+"&ek="+examinee);//答卷还没生成，访问自动生成的连接。
  }
   if (myKeyXML.parseError.errorCode!=0)
    {
     alert("无法得到考生的答案文件!")
 
    }
   else {
       displayEmaineeKey(myKeyXML,true);
       
      displayStandKey()
      
         
    //document.getElementById("msg").innerHTML="<b>考生得分："+totalscore+"<b>";
   
    }
        

}

function formReset(){
document.forms[0].reset();
   var splits=document.getElementsByTagName("div");
   for(var i=0;i<splits.length;i++){
      var id=splits[i].id;
      if(id!=null){
         if(id.substring(0,8)=="judgeDiv"){
             splits[i].style.display="none";
         
         }
      
      }
   
   }
   if (_testFlags) {_testFlags.reset() };
   
}

function sendToServer(a) {
   //设置答案队列
   
 
   
}
function displayStandKey() {

    if (__keys == null) { alert("尚未载入标准答案！请稍后再试。"); return; }
    standKeys = __keys;
    
    for (var i = 0; i < standKeys.count(); i++) {
        var keynode = standKeys.item(i);
        var keyName = keynode.getId();
        //var markImg = document.getElementById("markImg" + keyName);
        //var judgeDiv = document.getElementById("judgeDiv" + keyName);
        //if (judgeDiv != null) judgeDiv.style.display = "block";
        //var scoreDiv = document.getElementById("markScore" + keyName);
        var sdandKeyDiv2 = document.getElementById("keyDiv" + keyName);

        //if (scoreDiv != null) scoreDiv.innerHTML = "0";
        
        //if (markImg != null) markImg.src = "/paperstyle/error.gif"; 
        if (sdandKeyDiv2 != null) sdandKeyDiv2.innerHTML = keynode.getStandardKey();
        var noteDiv2 = document.getElementById("noteDiv" + keyName);
        if ((noteDiv2 != null) && (__notes != null)) { var note = __notes.getNoteById(keyName); if (note != null) noteDiv2.innerHTML = note.textAddHref(); }
        
    }

}
function getTotalScore(){
   //计算分数
    displayStandKey()
   
   var totalscore=0;
   if (_testFlags != null) {
       var t = _testFlags.getItems();
       var keycount = t.length; //得到考生答题数量
      
       for(var i=0;i<keycount;i++){
           var testEle = t[i].clientKey; //得到该考生答案

           var keyName = t[i].keyId;
           if (testEle!=null){

               var score = calculate(keyName, testEle);
               
               //显示评分标记
                  var judgeDiv=document.getElementById("judgeDiv"+keyName);
                  if(judgeDiv!=null)judgeDiv.style.display="block";
                  var markImg=document.getElementById("markImg"+keyName);
                  var scoreDiv=document.getElementById("markScore"+keyName);
                  var sdandKeyDiv=document.getElementById("keyDiv"+keyName);
                  
                  if(score>0){
                      if(scoreDiv!=null)scoreDiv.innerHTML="+"+score;
                    if(markImg!=null) markImg.src="/paperstyle/right.gif";
                  
                  }
                  else{
                     if(markImg!=null)markImg.src="/paperstyle/error.gif";
                     if(scoreDiv!=null)scoreDiv.innerHTML=score;
                  }
                 
                  //显示答案
                  //sdandKeyDiv.innerHTML=keyObj.getStandardKey();
                  

                  totalscore+=score;
               
               //var keynode = keyRoot.selectSingleNode("key[@id='"+keyName+"']");//得到一个答案节点
              //if((keynode!=null)&&(keyArr!=null)){
              //    var keyObj=new key(keynode);
              //    var score=keyObj.cal(keyArr,1,false);
                 
              //}
          }
          
       }
   }
   
  
   if(totalscore<0)totalscore =0;
   return totalscore;
}
var standKeys;
function submitKey(){
   //计算总分
   
   
   
   //var lastS=paperFile.lastIndexOf("?"); 
   //if(lastS>-1)paperFile=paperFile.substring(0,lastS) 

   //var p=paperFile.lastIndexOf("/");
   //if(p<=-1) p=paperFile.lastIndexOf("\\");
  
   
   
   var score=getTotalScore();
   alert("最终得分:"+score);
   
   
   
}

function changeMarke(testId,state){
    
}

 
        //对考生输入的答案进行评分

function calculate(keyId, eKey) {

    var standedKey = standKeys.getKeyById(keyId); 
            if (standedKey ==null)
                return 0;
            else
                return check(eKey, standedKey)
            

        }
