var http = getXHTTP(); // This executes when the page first loads.

function registerUser(strFName,strLName,strEmail) {  // This function does the AJAX request
 
  //  Set our destination PHP page "ajaxpost.php"…
  http.open("POST", "register.php", true);
  http.onreadystatechange = getHttpRes;

  // Make our POST parameters string…
  var params = "fstname=" + encodeURI(strFName)+
	"&lstname=" + encodeURI(strLName)+
	"&youremail=" + encodeURI(strEmail);

  // Set our POST header correctly…
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");

  // Send the parms data…
  http.send(params);

document.getElementById('fstname').value = "";
document.getElementById('lstname').value = "";
document.getElementById('youremail').value = "";

}

function getHttpRes( ) {
  if (http.readyState == 4 && http.status == 200) { 
    res = http.responseText;  // These following lines get the response and update the page
    document.getElementById('txtHint').innerHTML = res;
  }
}

function getXHTTP( ) {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}

function showUser(strFName,strLName,strEmail)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","register.php?fname="+strFName+"&lname="+strLName+"&email="+strEmail,true);
xmlhttp.send();
}

