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

function first_page_check(juan_id,db_id)
   {
       
		var retstr;
		var readflag;
		var newsubstr='';
		var read_strlen=0;
		
		var studentid;
		var password;
		var ksubject;
		
		var infoBoard;
		var login_str;
		
		var exec_flag=0;
				
		if (document.form1.studentid.value.length==0)
		   {
			   alert('[软件提示]：请填写准考证号。');
		       document.form1.studentid.focus();
			   return false;
		   }
		
		if (document.form1.password.value.length==0)
		   {
			   alert('[软件提示]：请输入密码。');
		       document.form1.password.focus();
			   return false;
		   }
		   
		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("login"); 
        infoBoard.innerHTML='<font color="#009933" size="-1"><b>登录检查中...若错误，修改后请重新选择单选按钮<b></font>'; 
		
		studentid=document.form1.studentid.value;
		password=document.form1.password.value;
		
        myurl=strstr+"first_page_check.php?studentid="+studentid;
        myurl=myurl+"&password="+password;
		myurl=myurl+"&juan_id="+juan_id;
			
		
		newurl="";
		newurl="chklogin.php?studentid="+studentid;
		newurl=newurl+"&password="+password;
		newurl=newurl+"&juan_id="+juan_id;
		newurl=newurl+"&db_id="+db_id;
		
		
		//alert(newurl);
		
        retstr=openUrl(myurl); 
		
		retstr=trim(retstr);
		
		readflag=retstr.substring(0,1);
				
		read_strlen=strlen(retstr);
		
		newsubstr=retstr.substring(1,read_strlen); 
		
						
        switch(readflag){ 
        
        case "a": 
               alert(newsubstr);break; 
			   //infoBoard.innerHTML='<font color=green>参考答案：'+newsub+'</font>';break; 
        case "b": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "c": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "d": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "e": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "f": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "g": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "h": 
		        alert(newsubstr);break; 
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; break; 
		case "i": 
		        alert(newsubstr);
                window.location.href='login.php'; 
	            break; 
	   /////直接登录成功,就是下句--------------------------------------------------------------
	   case "z": 
		       
			   ////不直接登录，屏蔽下句------------------------------------------------------
			   //expandingWindow(newurl);break;
				//alert(newsubstr);break; 
				
				newurl="'"+newurl+"'";
				
				login_str='<div align=center"   style="background-color:#0099FF;color:#FFFFFF;cursor:hand;TEXT-DECORATION:none;>'+
				          '<a href="#" onClick=expandingWindow('+newurl+');>'+
				          '<font color="#FFFFFF"><b>[登陆进入]</b></font>'+
				           '</a></div>';
							
				document.getElementById('login').innerHTML =login_str;
								
				break; 
				
				
	    default: 
		       alert(newsubstr);
               // 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 expandingWindow(targeturl)
	   {
        
		  var heightspeed = 10; // vertical scrolling speed (higher = slower)
          var widthspeed = 10; // horizontal scrolling speed (higher = slower)
          var leftdist = 0; // distance to left edge of window
          var topdist = 0; // distance to top edge of window
          var winwidth = window.screen.availWidth - leftdist;
          var winheight = window.screen.availHeight - topdist;

		
          var newwin = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=1,height=1,scrollbars=yes","_blank");
           
		  newwin.document.write('【软件提示】：正在抽题，请等待...');
         
          for (sizeheight = 1; sizeheight <= winheight; sizeheight += heightspeed)
		  {
               newwin.resizeTo("1", sizeheight);
          }
          
		  for (sizewidth = 1; sizewidth <=winwidth; sizewidth += widthspeed)
		  {
              newwin.resizeTo(sizewidth, sizeheight);
          }
		  
		  newwin.location =targeturl; 
		  top.opener =null;
	      top.close();
		  return;

       }
	   
	   
	   
	   
	   
function  display_buttion(juan_id,maxvalue)
	{
		
		/////--------------------此段程序 在1.9版本后的程序不用了----------------------------------------
		
		var radioes = document.getElementsByName('radio_juan');
        var objvalue;
		var maxv; 
		var k;
		
		maxv=parseInt(maxvalue);
		for(var j=1;j<=maxv;j++)
		    {
				objvalue='ShowButton'+j;
				document.getElementById(''+objvalue+'').innerHTML="";
			}		
		
	    for(var i=0;i<radioes.length;i++)
             {
                if(radioes[i].checked)
			    {
				    k=i+1;
                    objvalue='ShowButton'+k;
					//document.getElementById(''+objvalue+'').innerHTML = '<input type=button name=enter value=kjh   >' ;
					document.getElementById(''+objvalue+'').innerHTML = '<A href=# onclick="return first_page_check('+juan_id+');">[<b>登陆进入</b>]</a>' ;
                 }
            }
			 
    }


