// JavaScript Document
//-------在练习模式下，一般情况下是顺序处理，现在是随机处理-------------------------
function first_lianxi_random(juan_id)
   {
       
		var retstr;
		var readflag;
		var newsubstr='';
		var read_strlen=0;
		
		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+"session_check.php";
		//alert(newurl);
        retstr=openUrl(myurl); 
		retstr=trim(retstr);
		readflag=retstr.substring(0,1);
		read_strlen=strlen(retstr);
		
		newsubstr=retstr.substring(1,read_strlen); 
		//alert(newsubstr);
		newurl="";
		newurl="chklogin_random.php";
		newurl=newurl+"?juan_id="+juan_id;
		
						
        switch(readflag)
	   { 
        
         case "i":      ///如果没有登录，则返回到此，
		        alert(newsubstr);
                window.location.href='login.php'; 
	            break; 
				 
	     case "z":       //如果登录后，点击 顺序练习链接，则执行到此，要执行 login_check2.php 检查数据库
		       alert(newsubstr);
			   expandingWindow(newurl);break;
                //infoBoard.innerHTML='<font color=#000000>数据库中未预设答案！</font>'; 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 = 20; // vertical scrolling speed (higher = slower)
          var widthspeed = 20; // 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;

       }
	   
