// stores the reference to the XMLHttpRequest object
var xmlHttp = create_XmlHttpRequest_Object();

// retrieves the XMLHttpRequest object
function create_XmlHttpRequest_Object()
{
   // will store the reference to the XMLHttpRequest object
   var xmlHttp;
   // if running Internet Explorer
   if(window.ActiveXObject)
   {
      try
      {
         // Initialize the Microsoft XMLHTTP object
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // if running Mozilla or other browsers
   else
   {
      try
      {
         xmlHttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // return the created object or display an error message
   if (!xmlHttp)
      alert("Error creating the XMLHttpRequest object.");
   else
      return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object
function Send_Newsletter_Registration()
{
   // 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
     // name = encodeURIComponent(document.getElementById("name").value);
          email=encodeURIComponent(document.getElementById("email").value);
      // execute the quickstart.php page from the server
      xmlHttp.open("GET", "http://www.countryclubofbillerica.com/newsletter/signup.php?email="+email, true);
      // define the method to handle server responses
      xmlHttp.onreadystatechange = Server_Response;
      // make the server request
      xmlHttp.send(null);
   }
   else
      // if the connection is busy, try again after one second
      setTimeout('Send_Newsletter_Registration()', 1000);
}

// executed automatically when a message is received from the server
function Server_Response()
{
   // 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;
         // Get the first element from the document which is <response> and read its content.
         helloMessage = xmlResponse.documentElement.firstChild.data;
         
         //create an object that represents the row in which the results are to be output
         var obj= document.getElementById('Status');
         obj.innerHTML=helloMessage;
      }
      else
      {
         alert("There was a problem accessing the server: " + xmlHttp.statusText);
      }
   }
}