var xmlHttp = createXmlHttpRequestObject(); // stores the reference to the XMLHttpRequest object
function createXmlHttpRequestObject() // retrieves the XMLHttpRequest object
{  
  var xmlHttp;  // will store the reference to the XMLHttpRequest object
  if(window.ActiveXObject)  // if running Internet Explorer
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  else  // if running Mozilla or other browsers
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  if (!xmlHttp)  // return the created object or display an error message
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}
function process()// make asynchronous HTTP request using the XMLHttpRequest object 
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)  // proceed only if the xmlHttp object isn't busy
  {
/*    // retrieve the name typed by the user on the form
name = encodeURIComponent(document.getElementById("myName").value);
*/ 
	xmlHttp.open("GET", "./inc/nowdate.php", true);      // execute the quickstart.php page from the server
	xmlHttp.onreadystatechange = handleServerResponse;    // define the method to handle server responses
	xmlHttp.send(null);    // make the server request
  }
  else
    setTimeout('process()', 60000);    // if the connection is busy, try again after one second  
}
function handleServerResponse() // executed automatically when a message is received from the server
{
  if (xmlHttp.readyState == 4)   // move forward only if the transaction has completed
  {
    if (xmlHttp.status == 200)     // status of 200 indicates the transaction completed successfully
    {
      xmlResponse = xmlHttp.responseXML;      // extract the XML retrieved from the server
      xmlDocumentElement = xmlResponse.documentElement;      // obtain the document element (the root element) of the XML structure
      // get the text message, which is in the first child of
      // the the document element
      helloMessage = xmlDocumentElement.firstChild.data;
      // update the client display using the data received from the server
      document.getElementById("datediv").innerHTML = 
                                            '' + helloMessage + '';
      setTimeout('process()', 1000);      // restart sequence
    } 
    else     // a HTTP status different than 200 signals an error
    {
      // alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}