// JavaScript Document
function  change_act(addr)
{
	document.form1.action=addr;
}

  
function test()
{
	document.getElementById('next').click();
} 
	 

function trim(str)
{
  return str.replace(/(^\s*)|(\s*$)/g,"");
}

function checkCheckBox_select(objName,objid)
{ 
   //
    var obj=document.getElementsByName(objName); //
    var objLen= obj.length; //
    var objYN; //
    var i;
	var user_select='';
    objYN=false;
	
    for (i=0;i<objLen;i++)
	{
       if (obj[i].checked==true) 
	   {
          if (i==0) 
		      user_select=user_select+"1";
		  if (i==1) 
		      user_select=user_select+"2";
		  if (i==2) 
		      user_select=user_select+"3";
		  if (i==3) 
		      user_select=user_select+"4";	  	  	  
        }
    }
	
	//jscheck_corrent_answer(objid,user_select);
	alert(objName);
	alert(user_select);
	return user_select;
	
}



function jscheck_corrent_answer_d(id,d_cur_ti_num,dnum,mode)
{
        
		var get_id;
		var retCode;
						
		objName='d'+id;
		var obj=document.getElementsByName(objName); //
    	var objLen= obj.length; //
    	var objYN; //
    	var i;
		var user_select='';
		var answer_obj;
		
    	objYN=false;
	
    	for (i=0;i<objLen;i++)
		{
       		if (obj[i].checked==true) 
	   		{
         		 if (i==0) 
		      		user_select=user_select+"1";
		  		 if (i==1) 
		      		user_select=user_select+"2";
		  		 if (i==2) 
		      		user_select=user_select+"3";
		  		 if (i==3) 
		           user_select=user_select+"4";	  	  	  
            }
         }
		 
		var url;
	    url=window.location.href;
        //alert(window.location.href);
        var point;
	    point=url.lastIndexOf('/')+1;
        var strstr= url.substring(0,point);
        //url 除过最后的文件------------------
	    //alert(str);
		//alert(user_select);
		
		get_id=id;
		
		infoBoard=document.getElementById("d_answer"+id); 
        infoBoard.innerText='保存中...'; 
		
        myurl=strstr+"check_correct_answer_d.php?id="+get_id;
        myurl=myurl+"&answer="+user_select;
		myurl=myurl+"&zong_sele_num="+dnum;
		myurl=myurl+"&page="+d_cur_ti_num;
		myurl=myurl+"&mode="+mode;
		//alert(myurl);
		
        retCode=openUrl(myurl); 
		retCode=trim(retCode);
        //alert("服务器返回值："+retCode);
		newretcode=retCode.substring(0,1);
		newsublen=strlen(retCode);
		newsub=retCode.substring(1,newsublen);
		
		
		if (mode=='0')
		{ 
				
       		 switch(newretcode)
	    	{ 
		
         		case "-2": 
                	 infoBoard.innerHTML='<font color=#ff0000>抱歉,查询失败</font>';
					 break; 
         		case "1": 
			   		 //回答正确-----------
					 //infoBoard.innerHTML='<font color=#009933><b> 回答正确 '+newsub+'</b></font>';
					 infoBoard.innerHTML='<font color=#ff0000><b> 已保存 </b></font>';
               		 break; 
				
        		case "0":
				     //回答错误 
               		 //infoBoard.innerHTML='<font color=#ff0000>回答错误  正确答案:'+newsub+'</font>'; 
					 infoBoard.innerHTML='<font color=#ff0000><b> 已保存</b> </font>'; 
					 //setTimeout('test()',1000);//延时1秒
					 //infoBoard.innerHTML='<font color=red>延时1秒！</font>';
					 break;
		 		case "3":
		             infoBoard.innerHTML='<font color=#ff0000><b> 已保存</b></font>'; 
				
             } 
		}
	   
	   
	   if (mode=='1')
	   {
		      infoBoard.innerHTML='<font color=#ff0000></b>已保存</b></font>'; 
	   }
	   
       return; 
	   
	   
	   
	   
	   /*
	   if (newretcode=="0")
		{
			   newsublen=strlen(retCode);
		       //alert(newsublen);
		       newsub=retCode.substring(1,newsublen); 
		}  
		
        switch(newretcode){ 
		
        case "1": 
                infoBoard.innerHTML='<font color=red>恭喜!正确！</font>';
				setTimeout('test()',1000);//延时1秒
				//infoBoard.innerHTML=="延时1秒";
				break; 
        case "0": 
                infoBoard.innerHTML='<font color=red>回答错误！正确答案是：'+newsub+'</font>';
				//setTimeout('test()',1000);//延时1秒
				//infoBoard.innerHTML=="延时1秒";
				break; 
	    default: 
                infoBoard.innerHTML='<font color=red>抱歉</font>,查询失败';
			
       } 
	   
	   */
	   
} 



function checkCheckBox_select(objName,objid)
{ 
   //
    var obj=document.getElementsById(objName); //
    var objLen= obj.length; //
    var objYN; //
    var i;
	var user_select='';
    objYN=false;
	
    for (i=0;i<objLen;i++)
	{
       if (obj[i].checked==true) 
	   {
          if (i==0) 
		      user_select=user_select+"1";
		  if (i==1) 
		      user_select=user_select+"2";
		  if (i==2) 
		      user_select=user_select+"3";
		  if (i==3) 
		      user_select=user_select+"4";	  	  	  
        }
    }
	
	//jscheck_corrent_answer(objid,user_select);
	alert(objName);
	alert(user_select);
	return user_select;
	
}



function js_check_div(id)
{
        
		var get_id;
		var retCode;
						
		var objName;
		
		var obj;
		
		var obj_a; 
		var obj_b; 
		var obj_c; 
		var obj_d; 
    	
    			
		var sele_obj1;
		var sele_value1;
		
		var sele_obj2;
		var sele_value2;
				
				
		var sele_obj3;
		var sele_value3;
				
		var sele_obj4;
		var sele_value4;
		
		obj=document.getElementsByName("d"+id); 
	    	
		//------------a---------------	
		sele_obj1=document.getElementById("d_sele"+id+"a");
		sele_value1=document.getElementById("d_sele"+id+"a").innerText;
		sele_obj1.innerHTML="<font color=#000000>"+sele_value1+"</font>";
		
		sele_obj2=document.getElementById("d_sele"+id+"b");
		sele_value2=document.getElementById("d_sele"+id+"b").innerText;
		sele_obj2.innerHTML="<font color=#000000>"+sele_value2+"</font>";
		
		
        sele_obj3=document.getElementById("d_sele"+id+"c");
		sele_value3=document.getElementById("d_sele"+id+"c").innerText;
		sele_obj3.innerHTML="<font color=#000000>"+sele_value3+"</font>";
		
		
		sele_obj4=document.getElementById("d_sele"+id+"d");
		sele_value4=document.getElementById("d_sele"+id+"d").innerText;
		sele_obj4.innerHTML="<font color=#000000>"+sele_value4+"</font>";
		
		if  (obj[0].checked)
		{
			sele_obj1.innerHTML="<font color=#ff0000>"+sele_value1+"</font>";
		}
		else
		{   
		    sele_obj1.innerHTML="<font color=#000000>"+sele_value1+"</font>";
		}
		
		if  (obj[1].checked)
		{
			sele_obj2.innerHTML="<font color=#ff0000>"+sele_value2+"</font>";
		}
		else
		{   
		   sele_obj2.innerHTML="<font color=#000000>"+sele_value2+"</font>";
		}
		
		//-------------c---------------	
		
		if  (obj[2].checked==true)
		{
			sele_obj3.innerHTML="<font color=#ff0000>"+sele_value3+"</font>";
		}
		else
		{   
		    sele_obj3.innerHTML="<font color=#000000>"+sele_value3+"</font>";
			
		}
		//-------------d---------------	
	
		if  (obj[3].checked==true)
		{
			sele_obj4.innerHTML="<font color=#ff0000>"+sele_value4+"</font>";
		}
		else
		{   
		   sele_obj4.innerHTML="<font color=#000000>"+sele_value4+"</font>";
			
		}
		
		
      
	   
} 



function openUrl(url)
 
 { 
    var objxml=new ActiveXObject("Microsoft.XMLHttp") 
    objxml.open("GET",url,false); 
    objxml.send(); 
    retInfo=objxml.responseText;
	retInfo=unescape(retInfo); 
    if (objxml.status=="200")
	{ 
      return retInfo; 
    } 
    else
	{ 
      return "-2"; 
     } 
} 

function strlen(str) 
{
    var len = 0;
    for (var i = 0; i<str.length;i++)
	{
      if (str.charCodeAt(i)>255) len+= 2; 
	  else 
	   len ++;
    }
    return len;
}



function fetch_d_next_ti(page,zong_sele_num,id)
{
        
		var get_id;
		var retCode;
		var newpage;
		var user_select_value;
		
		if (page<zong_sele_num)
		{
			 newpage=parseInt(page)+1;
		}
		else
		{
			newpage=1;
		}
		
		
		
		objName='No'+id+'[]';
		var obj=document.getElementsByName(objName); //
    	var objLen= obj.length; //
    	var objYN; //
    	var i;
		var user_select='';
    	objYN=false;
	
    	for (i=0;i<objLen;i++)
		{
       		if (obj[i].checked==true) 
	   		{
         		 if (i==0) 
		      		user_select=user_select+"1";
		  		 if (i==1) 
		      		user_select=user_select+"2";
		  		 if (i==2) 
		      		user_select=user_select+"3";
		  		 if (i==3) 
		           user_select=user_select+"4";	  	  	  
            }
         }
		 
		 
		var url;
	    url=window.location.href;
        //alert(window.location.href);
        var point;
	    point=url.lastIndexOf('/')+1;
        var strstr= url.substring(0,point);
        //url 除过最后的文件------------------
	    //alert(str);
		
		
		
		myurl=strstr+"save_user_answer_d.php?id="+id;
        //myurl="http://127.0.0.1:8080/check_correct_answer.asp?id="+get_id;
		myurl=myurl+"&page="+page;
		myurl=myurl+"&zong_sele_num="+zong_sele_num;
		myurl=myurl+"&answer="+user_select;
		//alert(myurl);
		retCode=openUrl(myurl); 
		retCode=trim(retCode);
		//alert(retCode);
		
		infoBoard=document.getElementById("d_all"); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"a0middle_d.php?page="+newpage;
		//alert(page);
		//alert(myurl);
        retCode=openUrl(myurl); 
		retCode=trim(retCode);
        //alert("服务器返回值："+retCode);
		infoBoard.innerHTML=retCode;
	   
       return; 
} 


function fetch_d_prior_ti(page,zong_sele_num,id)
{
        
		var get_id;
		var retCode;
		var newpage;
		
		if (page>1)
		{
			 newpage=parseInt(page)-1;
		}
		else
		{
			newpage=zong_sele_num;
		}
		
		var url;
	    url=window.location.href;
        //alert(window.location.href);
        var point;
	    point=url.lastIndexOf('/')+1;
        var strstr= url.substring(0,point);
        //url 除过最后的文件------------------
	    //alert(str);
		
		
		infoBoard=document.getElementById("d_all"); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"a0middle_d.php?page="+newpage;
       
		//alert(page);
		//alert(myurl);
        retCode=openUrl(myurl); 
		retCode=trim(retCode);
        //alert("服务器返回值："+retCode);
		
		infoBoard.innerHTML=retCode;
	   
       return; 
} 

