// requires file js_xmlhttprequest.js to be called first
//Our XmlHttpRequest object - created when page with form is called or refreshed
// if browser is not right version and var cannot by created, rest of fns on this page will not run
var receiveRequest = createXMLHttpRequest();

//Called from an event in the form; Gets the parameters to be POSTed  to the url indicated to evaluate password
// theForm is the form id, weburl is the url to be posted to
function getParams(theForm,weburl) {
 //Set up the parameters of our AJAX call
 var postStr = theForm.passwd.name + "=" + encodeURIComponent( theForm.passwd.value ) + "&" + theForm.username.name + "=" + encodeURIComponent( theForm.username.value ) + "&" + theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
 //Call the function that initiate the AJAX request
 sendRequest(weburl, postStr);
}

//Initiate the AJAX request
function sendRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveRequest.readyState == 4 || receiveRequest.readyState == 0) {
   //Set up the connection to the displayed html file (or page containing form). True sets the request to asyncronous(default) 
   receiveRequest.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveRequest.onreadystatechange = updateTheResponse; 

   receiveRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveRequest.setRequestHeader("Content-length", param.length);
   receiveRequest.setRequestHeader("Connection", "close");

   //Make the request
   receiveRequest.send(param);
 }   
}

//Called every time the response is requested and our XmlHttpRequest objects state changes
function updateTheResponse() {
 //Check if our response is ready
 if (receiveRequest.readyState == 4) {
   //Set the content of the DIV element with the response text
   document.getElementById('check_passwd_output_result').innerHTML = receiveRequest.responseText;
 }
}