// JavaScript Document
var baseurl="";
var rptcnt = 0;
function doOnLoad()
{
	document.getElementById('applno').focus();
}
function form_reset()
{
	document.getElementById('applno').value="";
	document.getElementById('psw').value="";
}
function afterappno() //on Blur Validation after Application Number
{
   var app=document.getElementById('applno').value;
   var val=isblank(app);
   if(val==true)
   {
       if(rptcnt == 0)
           {
               rptcnt++;
               document.getElementById('applno').focus(); 
	           alert("Enter Form No");              
           } 
   }
   if(!contain_only(app,"~d"))
   {  
       if(rptcnt == 0)
       {
          rptcnt++;
          document.getElementById('applno').disabled=false;
          document.getElementById('applno').focus();
          document.getElementById('applno').select(); 
          alert("Enter Only 0-9");	  	        
       }
   }
   if(Number(app)<0)
   {
       if(rptcnt == 0)
       {
          rptcnt++;
          document.getElementById('applno').disabled=false;
          document.getElementById('applno').focus();
          document.getElementById('applno').select(); 
          alert("Form No. Must Be Positive");	  	        
       }
   }
   rptcnt=0;
}
function afterpass()  //on Blur Validation after Password
{
    var app=document.getElementById('applno').value;
    var val=isblank(app);
    var pass=document.getElementById('psw').value;    
    var val1=isblank(pass);
    //alert(val);
    if(val==false)
    {  
       if(val1==true)
       { 
           if(rptcnt == 0)
           {
               rptcnt++;
               document.getElementById('psw').focus(); 
	       alert("Enter Password ");              
           }             
       }
       else if(!contain_only(pass,"~A~a~d"))
       {
           if(rptcnt == 0)
           {
               rptcnt++;
               document.getElementById('psw').focus();
               document.getElementById('psw').select(); 
               alert("Enter Only a-z,A-Z,0-9");	  	        
           }
       } 
       else if(pass.length<6)
       {
           if(rptcnt == 0)
           {
               rptcnt++;
               document.getElementById('psw').focus(); 
	       alert("Password Must Have 6 Or More Characters");              
           }
       } 
    }
    else if(val==true)
    {
        if(val1==true)
           { 
               if(rptcnt == 0)
               {
                   rptcnt++;
                   document.getElementById('psw').focus(); 
                   alert("Enter Password ");              
               }             
           }
           else if(!contain_only(pass,"~A~a~d"))
           {
               if(rptcnt == 0)
               {
                   rptcnt++;
                   document.getElementById('psw').focus();
                   document.getElementById('psw').select(); 
                   alert("Enter Only a-z,A-Z,0-9");	  	        
               }
           } 
           else if(pass.length<6)
           {
               if(rptcnt == 0)
               {
                   rptcnt++;
                   document.getElementById('psw').focus(); 
                   alert("Password Must Have 6 Or More Characters");              
               }
           } 
           else 
           {
                  document.getElementById('submit').focus();
           }
     

    }
    rptcnt=0;
}
function onsubmit_print()
{
	if(document.getElementById('applno').value=="" || document.getElementById('psw').value=="")
	  return;
	//Call jsp for geting record
      baseurl=document.URL.substring(0,document.URL.lastIndexOf('/'));
	  url=baseurl+"/External_print_validate.jsp?applno="+document.getElementById('applno').value+"&pass="+document.getElementById('psw').value;
	 // alert(url);
	   if (window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
		}
    // branch for IE/Windows ActiveX version
		else if (window.ActiveXObject)
		{
		req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req)
			{
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send(null);
			}
		}
}
function processReqChange()
{
 // only if req shows "complete"
    if (req.readyState == 4)
    {
        // only if "OK"
       // alert(req.status);
	if (req.status == 200)
	{
       // alert(req.responseText);
		if(req.responseText.indexOf('0')!=-1)
		  {
			  alert('Invalid Form No. Or Password Try Again');
			  document.getElementById('psw').value="";
		  }
		  else
		  {
			  document.getElementById('s_applno').value=document.getElementById('applno').value;
			  document.getElementById('s_psw').value=document.getElementById('psw').value;
			  external_exam_form_print();
              //submittoprint.submit();
 			  //location.replace("BBEntrance.jsp?applno="+document.getElementById('applno').value+"&pass="+document.getElementById('psw').value);
		  }
	}
	}
}

function external_exam_form_print() //on Click on Print
{
//   location.replace(baseurl+'printrepo.html?appno='+document.getElementById('applno').value);

   var baseurl=document.URL;	
   var frmno = document.getElementById('applno').value;
  // var entclg = document.examform.entrycollege.value;


   baseurl = document.URL.substring(0,(document.URL.lastIndexOf("/")));

   var url=baseurl+'/Reports/runExternalExamFromReport.jsp?appno='+frmno+'&htm_fromno='+frmno;

	if (window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();
		req.onreadystatechange = processReqChangeExt;
		req.open("GET", url, true);
		req.send(null);
		}
    // branch for IE/Windows ActiveX version
		else if (window.ActiveXObject)
		{
		req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req)
			{
				req.onreadystatechange = processReqChangeExt;
				req.open("GET", url, true);
				req.send(null);
			}
		}

   //location.replace(url);

}
function processReqChangeExt()
{
 // only if req shows "complete"
    if (req.readyState == 4)
    {
        // only if "OK"
       // alert(req.status);
	if (req.status == 200)
	{
       // alert(req.responseText);
       		var path=req.responseText;
       		path=trim(path);
       		var reclist=path.split("#");
		var repfile = document.URL.substring(0,(document.URL.lastIndexOf("/")+1))+"/Reports/temphtml/";
		repfile=trim(repfile);
		repfile=repfile+reclist[1];
		repfile=trim(repfile);
		//alert(repfile);
		location.replace(repfile);
	}
    }
}
