

<!-- //

////////////////////////////////////////////////////////////////////////////////////////////////
// name: login_user
// purpose: Just a place holder function so we can get the value of the email entered into
//          the text box on the HTML page
////////////////////////////////////////////////////////////////////////////////////////////////
function login_user()
{
	//alert(document.getElementById('username').value);
	
	do_the_login(document.getElementById('username').value, document.getElementById('password').value);
}

////////////////////////////////////////////////////////////////////////////////////////////////
// name: do_the_login
// purpose: Calls the PHP script that checks for an existing email address, if the PHP script
//          finds a valid email address then the PHP script will send out the username/password
//          to the given email address on file.  The callback funciton below will parse any
//          response, success or error from the PHP script's XML output
////////////////////////////////////////////////////////////////////////////////////////////////
function do_the_login(username, password) 
{
	//var req;
	
	var url = 'scripts/login_user.php?username=' + username + '&password=' + password;
	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processUserLogin;		
        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 = processUserLogin;
            req.open("GET", url, true);
            req.send();
        }
    }

}


////////////////////////////////////////////////////////////////////////////////////////////////
// name: processUserLogin
// purpose: this is the callback function, it takes the results from the XML output of the PHP 
//          script and parses the elements in order to write the success or error message
//          directly to the original HTML page
////////////////////////////////////////////////////////////////////////////////////////////////
function processUserLogin() 
{
	//alert('got here');

	mdiv = document.getElementById("login_message");
	mdiv.innerHTML = "<font color=blue>Processing....</font>";

    // only if req shows "complete"
    if (req.readyState == 4) {
      // only if "OK" 
	  //alert('got inside');
	  
	  
      if (req.status == 200) {
			
	  //alert('got here NOW');
      response  = req.responseXML.documentElement;

      error_code    = response.getElementsByTagName('error_code')[0].firstChild.data;
	  userID	    = response.getElementsByTagName('userID')[0].firstChild.data;
      message 	    = response.getElementsByTagName('message')[0].firstChild.data;
	  
	  if(error_code == 0) // If there was an error
	  	mdiv.innerHTML = message;
	  
	  else if(error_code == 1) // Login was a success, redirect user to the home page
		window.location="login.php?userID=" + userID; // location of the object that will set the cookie for the user
	  
      } else {
            //alert("There was a problem retrieving the XML data:\n" + message);
      }
    }
}


// -->

