var xmlHttp;
var auth=0;
var tT=0; 

/*------------------------------------------------------------------------ 
  Function: processData
  Purpose: to send over data collected from input text boxes 
------------------------------------------------------------------------ */
function authAccess(){
    var usern = trim(document.login.usern.value);
    var pass = trim(document.login.pass.value);  	

    if (usern == "" || pass == "" ) { alert ("Username and password must be entered."); return;}
  
    xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return;
  	} 	
  	
    document.getElementById("wait1").innerHTML = "<center><img src='/MainHomePage/cImages/Process.gif' alt='Processing Request, Please wait!'> </center>";
	
var url="MainHomePage/Authenticate.php";
	url +="?usern="+usern;
        url +="&pass="+pass;
	url +="&sid="+Math.random()*9999999999;

	xmlHttp.onreadystatechange=authPage; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

/*------------------------------------------------------------------------ 
  Function: authPage (ajax)
  Purpose: to present information obtained back from data sent 
------------------------------------------------------------------------ */
function authPage() {  
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 		document.getElementById("wait1").innerHTML=xmlHttp.responseText;
                tT = document.getElementById('tries').value;
                auth = document.getElementById('auth').value; 
              if ( auth > 0 ){ loadData(); } 
 	} 
}//end authPage



/*------------------------------------------------------------------------ 
  Function: processData
  Purpose: to send over data collected from input text boxes 
------------------------------------------------------------------------ */
function loadData(year){
    var d = new Date();
	var cyear = (year == null) ? d.getFullYear() : year; 
	
    xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
  		alert ("Browser does not support HTTP Request")
  		return;
  	} 	
  	
	document.getElementById("Data").innerHTML = "<center><img src='/MainHomePage/cImages/Process.gif' alt='Processing Request, Please wait!'> </center>";
	
var url="Directory.php";
	url +="?year="+cyear;
	url +="&sid="+Math.random()*9999999999;
	
	xmlHttp.onreadystatechange=stateChanged; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}


/*------------------------------------------------------------------------ 
  Function: statechanged (ajax)
  Purpose: to present information obtained back from data sent 
------------------------------------------------------------------------ */
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 		document.getElementById("Data").innerHTML=xmlHttp.responseText;  
 	} 
}//end stateChanged

/*------------------------------------------------------------------------ 
  Function: GetXmlHttpObject (ajax)
  Purpose: toCreate object to transfer data 
------------------------------------------------------------------------ */
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
    }
	catch (e){ // Internet Explorer
 	try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
 	catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
 }
 return xmlHttp;
}

/*------------------------------------------------------------------------ 
  Function: trim
  Purpose: to take off spaces at left and right of a string
------------------------------------------------------------------------ */
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function loadType(){
  var authl=0; 
  try {authl = document.form1.auth.value; }
  catch(err){ /*alert(err.description);*/ }  
if ( authl > 0 ) loadData();
}

