// JavaScript Document

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

function getFocus(obj) 
{
    obj.style.color='black';
    obj.style.background='#FFECB3';
}

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

function getBlur(obj) 
{
    obj.style.color='black';
    obj.style.background='white';
}

function jscheck_corrent_answer_t(id)
   {
        var get_id;
		var retCode;
		var newretcode;
		var newsub='';
		var newsublen=0;
		
		get_id=id;
		
		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("t_answer"+id); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"check_correct_answer_t.php?id="+get_id;
        //myurl="http://127.0.0.1:8080/check_correct_answer.asp?id="+get_id;
		//alert(myurl);
        retCode=openUrl(myurl); 
        
		//newretcode=trim(newretcode);
		retCode=trim(retCode);
		
		//alert("服务器返回值："+retCode);
		
		newretcode=retCode.substring(0,1);
				
		newsublen=strlen(retCode);
		//alert(newsublen);
		newsub=retCode.substring(1,newsublen); 
		//alert(newsub);
		
						
        switch(newretcode){ 
        
        case "1": 
                infoBoard.innerHTML='<font color=green>参考答案：'+newsub+'</font>';break; 
        case "0": 
                infoBoard.innerHTML='<font color=#000000>未预设答案</font>'; break; 
	    default: 
                infoBoard.innerHTML='<font color=red>抱歉,查询失败</font>';break; 	
						
       } 
       return; 
} 






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 openUrl(url)
 
 { 
    var objxml=new ActiveXObject("Microsoft.XMLHttp") 
    objxml.open("GET",url,false); 
    objxml.send(); 
	
    retInfo=objxml.responseText; 
    //-----------------------最重要，将%20 解码成空格，Visit W3School!") ==》Visit%20W3School%21
	retInfo=unescape(retInfo);
    if (objxml.status=="200")
	{ 
      return retInfo; 
    } 
    else
	{ 
      return "-2"; 
     } 
}



function fetch_t_next_ti(page,zong_sele_num,id)
{
        
		var get_id;
		var retCode;
		var newpage;
		var user_input_answer;
		var infoboard;
		
		if (page<zong_sele_num)
		{
			 newpage=parseInt(page)+1;
		}
		else
		{
			newpage=1;
		}
		
		var objName='t'+id;
		
		var user_input_answer=document.getElementsByName(objName).item(0).value;
		
		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_t.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_input_answer;
		//alert(myurl);
		retCode=openUrl(myurl); 
		retCode=trim(retCode);
		
		infoBoard=document.getElementById("t_info"+id); 
		infoBoard.innerHTML='<font color=#ff0000>已保存</font>'; 
		
		//alert(retCode);
		
		/**
		infoBoard=document.getElementById("t_all"); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"a0middle_tiankong.php?page="+newpage;
		//alert(page);
		//alert(myurl);
        retCode=openUrl(myurl); 
		retCode=trim(retCode);
        //alert("服务器返回值："+retCode);
		infoBoard.innerHTML=retCode;
		
		**/
	   
       return; 
} 


function fetch_t_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("t_all"); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"a0middle_tiankong.php?page="+newpage;
       
		//alert(page);
		//alert(myurl);
        retCode=openUrl(myurl); 
		retCode=trim(retCode);
        //alert("服务器返回值："+retCode);
		
		infoBoard.innerHTML=retCode;
	   
       return; 
} 

