var time_variable;
 
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'vvvv') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
 
function ajaxFunction() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  
  var programs = "";
  var theprogs = document.getElementsByName("programs");
  var n = theprogs.length;
  var x = 0;
  for(var i=0; i < n; i++) {
	  if (theprogs[i].checked) x++;
  }
  for(var i=0; i < n; i++) {
	  if (theprogs[i].checked) {
		  if (x == 1) programs = programs + theprogs[i].value;
		  else if (x == 2) programs = programs + theprogs[i].value + " and ";
		  else programs = programs + theprogs[i].value + ", ";
		  x--;
	  }
  }
  
  if(xmlhttp) { 
    xmlhttp.open("POST","quotereq.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send("company=" + document.getElementById("company").value + "&name=" + document.getElementById("name").value + "&phone=" + document.getElementById("phone").value + "&email=" + document.getElementById("email").value + "&programs=" + programs + "&comments=" + document.getElementById("comments").value); //Posting to PHP File
  }
}
 
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element 
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
