// JavaScript Document// JavaScript Document

// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject(){	
		var xmlHttp;		
		try{
				xmlHttp=new XMLHttpRequest();
		}catch(e){
			var xmlHttpVersions=new Array('Microsoft.XMLHTTP','MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP');
			for(var i=0;i<xmlHttpVersions.length&&!xmlHttp;i++){
				try{
					xmlHttp=new ActiveXObject(xmlHttpVersions[i]);
				}
				catch(e) {}
			}
		}
		if(!xmlHttp)
			alert('Error! Cant not create object xmlHttp!');
			else return xmlHttp;
	}
	
// make asynchronous HTTP request using the XMLHttpRequest object 
function process()
{
  // 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
    id = encodeURIComponent(document.getElementById("user_id").value);
	mail = encodeURIComponent(document.getElementById("mail").value);
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "ssl/check.php?user_id=" + id+'&mail='+mail, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse_check;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('process()', 500);
}

// executed automatically when a message is received from the server
function handleServerResponse_check() 
{
  // 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
      xmlResponse = xmlHttp.responseXML;
      xmlDoc = xmlResponse.documentElement;
	  id_valid=xmlDoc.getElementsByTagName("id")[0].firstChild.data;
	  mail_valid=xmlDoc.getElementsByTagName("mail")[0].firstChild.data;
	  	 	
      document.getElementById("user_id_check").innerHTML = 
                                            '<font color=#FF0000><b>' + id_valid + '</b></font>';
		document.getElementById("mail_check").innerHTML = 
                                            '<font color=#FF0000><b>' + mail_valid + '</b></font>';
      // restart sequence
      setTimeout('process()', 500);
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
