// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
 var obj1;

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
 for (var i=0; i < XmlHttpVersions.length && !xmlHttp; i++)
    {
      try
      {
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);


      }
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else
    return xmlHttp;
}

function process()
{
	 
	 document.getElementById("erroruname").style.display="none";
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // retrieve the name typed by the user on the form
    var uname = encodeURIComponent(document.getElementById("uname").value);
	
	
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "checkUser.php?uname="+uname, true);
    // define the method to handle server responses

    xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second
    setTimeout('process()', 5000);
}

// executed automatically when a message is received from the server
function handleServerResponse()
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4)
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200)
    {
      // extract the XML retrieved from the server
    Response = xmlHttp.responseText;
        
   if(Response==1)
   {
     document.getElementById('response').innerHTML="<font color='#FF0000'>  username not available </font>";
	 document.getElementById('uname').value="";
   }
   else
   document.getElementById('response').innerHTML="<font color='#32cd32'>  username  available </font>";
    

      // restart sequence
     // setTimeout('process()', 5000);
    }
    // a HTTP status different than 200 signals an error
    else
    {
      alert("There was a problem accessing the server: " +
xmlHttp.statusText);
    }
  }
}// JavaScript Document





