/////////////////////////////////////////////////////////
function $(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=randomOrder(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
 loading[2]="&nbsp;&nbsp;&nbsp;&nbsp;加载中...";//menu
 ajax.onreadystatechange=function(){
	 if (ajax.readyState==0)
          {
             $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==1)
          {
              $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==2)
          {
              $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==3)
          {
             $(divid).innerHTML=loading[loadingnum];
          }
	  else if(ajax.readyState==4)
	      {
			if(ajax.status==200)
			    {
				  $(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)
          {
             $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==1)
          {
              $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==2)
          {
              $(divid).innerHTML=loading[loadingnum];
          }
      else if (ajax.readyState==3)
          {
             $(divid).innerHTML=loading[loadingnum];
          }
	  else if(ajax.readyState==4)
	      {
			if(ajax.status==200)
			    {
				  $(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 eid="";
  var ean="";
  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);
	
	//AJAX("http://www.jsyks.com/HotKey.asp","card_fen",0,"get","postnull");
  //postdata="eid="+eid+"&ean="+ean;
  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)
{
  $("questionanswer").value=arg;
  new_question[current_i][4]=arg;
  $("mylist"+current_i+1).innerHTML=arg;
  if($("autoanswer").checked)
  {
     getcorrect();
  }
  
  //alert(document.all.autonext.options[document.all.autonext.selectedIndex].value);
  var autonext=parseInt($("#autonext")[0].options[$("#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);
	$("questionanswer").value="";
	$("Myquestion").innerHTML=new_question[current_i][1]; 
	$("Myquestionpic").innerHTML=new_question[current_i][3];
	$("question_type1").style.display=(new_question[current_i][2]=="1")?"block":"none";
	$("question_type2").style.display=(new_question[current_i][2]=="2")?"block":"none";
	$("current_i").innerHTML=current_i+1+"题";
	$("correct").innerHTML="";
	line();
}
function hiddenbotton(b)
{ 
   if(b==1)
     {
		$("btn1").style.display="block";
		$("btn2").style.display="none";
	 }
	else if(b==2)
	 {
		$("btn1").style.display="none";
		$("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("/lib/getcorrect.asp?id="+new_question[current_i][0],"correct",2,"get","null");
}
/////////////////////////////////////////////////////////



