/* SCRIPTS FOR LOGIN CHECKING ONLY */
// scripts for the login box


function showError() {
oText = myform.elements['userabta'];
oPass = myform.elements['userpass'];
oText.style.borderColor = "#FF0000";
oText.style.backgroundColor = "#CC9999";
oPass.style.borderColor = "#FF0000";
oPass.style.backgroundColor = "#CC9999";
$.msgbox('Login Error: Please check your details.',{
  type : 'error',
  buttons : [
    {type: 'submit', value:' OK '}
  ]
});
}

function setLoginABTA(myABTA) {
oText = myform.elements['userabta'];
oText.value=myABTA;
}

function checkABTA() {
oText = myform.elements['userabta'];
var thisABTA = oText.value;
var thisLength = thisABTA.length;
	if(thisABTA.length==5) {
	doTheCheck(thisABTA);
	}
}

function clearField(theField) {
document.getElementById(theField).value="";
}

function doTheCheck(thisABTA,turnCounter) {
// alert("Checking ABTA of : " + thisABTA + " (" + thisABTA.length + " chars long )");
ajaxPhpFunction('getASStaffCheck',thisABTA,'none','asEmail');
// checkasEmailContent(thisABTA,turnCounter);
}

function checkasEmailContent(resultHTML) {
//alert("Result of Query = " + resultHTML);
if(resultHTML=="0") {
document.getElementById('asEmail').style.display = "none";
document.getElementById('asEmail').innerHTML = 'Email: &nbsp;&nbsp;<input type="hidden" name="userEmail" value="none" "><input type="hidden" name="asAttempt" value="no" ">';
} else {
document.getElementById('asEmail').style.display = "block";
document.getElementById('asEmail').innerHTML = resultHTML;
}
resultHTML = "";
}

function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}

function ajaxPhpFunction(myScript,myVar,myTo,resultsDiv) {
var xmlhttp = new getXMLObject();
if(myTo !="none") {
xmlhttp.open("GET","/global/includes/" + myScript + ".php?dep=" + myVar + "&dest=" + myTo,true);
} else {
// alert("Running /assets/includes/" + myScript + ".php?dep=" + myVar);
xmlhttp.open("GET","/global/includes/" + myScript + ".php?dep=" + myVar,true);
}
 xmlhttp.onreadystatechange=function() {
	if(xmlhttp.readyState==4) {
		var resultHTML =xmlhttp.responseText; //Update the HTML Form element 
     	checkasEmailContent(resultHTML);
  	}
 }
 xmlhttp.send(null);
}
