/////////////////////////////////////////////////////////
function exam$(((id){
	     return document.getElementById(id);
}
/////////////////////////////////////////////////////////
function getRandomNum(num) { 
   return Math.floor(Math.random()*num); 
} 
/////////////////////////////////////////////////////////
var se,m=0,h=0,s=0,ss=1,t="",t1="",t2=""; 
function second(){ 

if((ss%100)==0){s+=1;ss=1;} 
if(s>0 && (s%60)==0){m+=1;s=0;} 
if(m>0 && (m%60)==0){h+=1;m=0;} 
t1=(m<10)?("0"+m):m;
t2=(s<10)?("0"+s):s;
t=t1+":"+t2;
if(t1>50)
{
  SubmitExam()	
}
//t=h+":"+m+":"+s; 
document.getElementById("gettime").innerHTML=t; 
ss+=1; 
} 
se=setInterval("second()",1);
//clearInterval(se);ss=1;m=h=s=0;
/////////////////////////////////////////////////////////
 function randomOrder (targetArray)
{
    var arrayLength = targetArray.length
    //
    //先创建一个正常顺序的数组
    var tempArray1 = new Array();

    for (var i = 0; i < arrayLength; i ++)
    {
        tempArray1 [i] = i
    }
    //
    //再根据上一个数组创建一个随机乱序的数组
    var tempArray2 = new Array();

    for (var i = 0; i < arrayLength; i ++)
    {
        //从正常顺序数组中随机抽出元素
        tempArray2 [i] = tempArray1.splice (Math.floor (Math.random () * tempArray1.length) , 1)
    }
    //
    //最后创建一个临时数组存储 根据上一个乱序的数组从targetArray中取得数据
    var tempArray3 = new Array();

    for (var i = 0; i < arrayLength; i ++)
    {
        tempArray3 [i] = targetArray [tempArray2 [i]]
    }
    //
    //返回最后得出的数组
    return tempArray3
}

//使用实例

//var tmp = ["1", "2", "3", "4"];
//alert(randomOrder(tmp));

var new_question=question;
var current_i=0;
function createajax(){ 
 	var ajax;
	try{
		ajax= new ActiveXObject('Msxml2.XMLHTTP');
	   }
	catch(e)
	   {
		try{
			  ajax= new ActiveXObject('Microsoft.XMLHTTP');
		   }
		catch(e)
		   {
			    try{
				    ajax= new XMLHttpRequest();
			       }
				catch(e){}
		   }
       }
 return ajax;
}

function AJAX(url,divid,loadingnum,method,postdata)
{
 var ajax=createajax();
 var loading=new Array();
 loading[0]="&nbsp;&nbsp;&nbsp;&nbsp;<img src=IMAGES/load.gif align=absmiddle style='margin-top:5px'>";//menu
 loading[1]="<br><br><br><center><img src=IMAGES/loading.gif align=middle></center>";//content
 ajax.onreadystatechange=function(){
	 if (ajax.readyState==0)
          {
             exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==1)
          {
              exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==2)
          {
              exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==3)
          {
             exam$((divid).innerHTML=loading[loadingnum];
          }
	  else if(ajax.readyState==4)
	      {
			if(ajax.status==200)
			    {
				  exam$((divid).innerHTML=ajax.responseText;
		        }
			else
		        {
				alert(ajax.status);
		        }
			ajax=null;
		}
     }
	 if(method=="get")
	  {
        ajax.open("get",url);
        ajax.send(null);
	  }
	 else if(method=="post")
	 {
		 ajax.open("post",url,true);
		 ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		 ajax.send(postdata);
     }
}

function AJAX(url,divid,loadingnum,method,postdata)
{
 var ajax=createajax();
 var loading=new Array();
 loading[0]="&nbsp;&nbsp;&nbsp;&nbsp;<img src=/images/load.gif align=absmiddle style='margin-top:5px'>";//menu
 loading[1]="<br><br><br><center><img src=/images/20070413105655265.gif align=middle></center>";//content
   loading[2]="加载中...";//content
 ajax.onreadystatechange=function(){
	 if (ajax.readyState==0)
          {
              exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==1)
          {
              exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==2)
          {
              exam$((divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==3)
          {
             exam$((divid).innerHTML=loading[loadingnum];
          }
	  else if(ajax.readyState==4)
	      {
			if(ajax.status==200)
			    {
				  exam$((divid).innerHTML=ajax.responseText;
		        }
			else
		        {
				alert(ajax.status);
		        }
			ajax=null;
		}
     }
	 if(method=="get")
	  {
        ajax.open("get",url);
        ajax.send(null);
	  }
	 else if(method=="post")
	 {
		 ajax.open("post",url,true);
		 ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		 ajax.send(postdata);
     }
}

function SubmitExam()
{
  Total=0;
  var ExamCard=document.getElementById("ExamCard");
  ExamCard.style.left =(screen.width-400)/2;
  ExamCard.style.top =(screen.height-500)/2;
  
  ExamCard.style.visibility="hidden"
  ExamCard.filters[0].apply();
  ExamCard.filters[0].play();
  ExamCard.style.visibility="visible"
  var eid="";
  var ean="";
  var postdata="";
  for(ei=0;ei<=new_question.length-1;ei++)
     {
	   	 if(eid=="")
		   {
			   eid=new_question[ei][0];
			   ean=new_question[ei][4];
			}
		  else
		   {
			  eid=eid+","+new_question[ei][0]; 
			  ean=ean+","+new_question[ei][4];
			}
	 }
	// alert(eid);
  var examanswer=document.getElementById("examanswer");
  examanswer.eid.value=eid;
  examanswer.ean.value=ean;
  examanswer.action="exam_answer.asp";
  examanswer.submit();
  //AJAX("/Lib/AjaxShow.asp","card_fen",0,"post","eid=1200"+eid+"&ean=A");
  //AJAX("/Lib/AjaxShow.asp","card_fen",0,"post","eid="+eid+"&ean="+ean);
}

function setanswer(arg)
{
  exam$(("questionanswer").value=arg;
  new_question[current_i][4]=arg;
  exam$(("mylist"+current_i+1).innerHTML=arg;
  if(exam$(("autoanswer").checked)
  {
     getcorrect();
  }
  var autonext=parseInt(exam$(("#autonext")[0].options[exam$(("#autonext")[0].selectedIndex].value);
  switch (autonext)
  {
	 case 0:
	       break;
	 case 3600:
	       next();
		   break;
	 case 1:
	       setTimeout("next()",1000);
	       break;
     case 2:
	       setTimeout("next()",2000);
	       break;
	 case 5:
	       setTimeout("next()",5000);
	       break;
	 case 8:
	       setTimeout("next()",8000);
	       break;
	 case 10:
	       setTimeout("next()",10000);
	       break;
  }
  
}
function getlist(i)
{
  current_i=i;
  showquestion();
}
function init()
{
 showquestion()
 //current_i++;
}
init();
function showquestion()
{
	
	//alert(current_i);
	exam$(("questionanswer").value="";
	exam$(("Myquestion").innerHTML=new_question[current_i][1]; 
	exam$(("Myquestionpic").innerHTML=new_question[current_i][3];
	exam$(("question_type1").style.display=(new_question[current_i][2]=="1")?"block":"none";
	exam$(("question_type2").style.display=(new_question[current_i][2]=="2")?"block":"none";
	exam$(("current_i").innerHTML=current_i+1+"题";
		exam$(("correct").innerHTML="";
	line();
}
function hiddenbotton(b)
{ 
   if(b==1)
     {
		exam$(("btn1").style.display="block";
		exam$(("btn2").style.display="none";
	 }
	else if(b==2)
	 {
		exam$(("btn1").style.display="none";
		exam$(("btn2").style.display="block";
	 }
}
function next()
{ 
  if(current_i+1>new_question.length-1)
   {
	 current_i=new_question.length-1;
	 return;
   }
   else
   {
	 current_i=current_i+1;
	 showquestion();
   }
   
}
function previous()
{	 
  if(current_i<=0)
   {
	 current_i=0;
	 return;    
   }
   else
   {
	 current_i=(current_i<=0)?0:--current_i;  
	 showquestion();
   }
   
}
function getcorrect()
{
AJAX("/Exam/lib/getcorrect.asp?id="+new_question[current_i][0],"correct",2,"get","null");

}
/////////////////////////////////////////////////////////
