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 != 'undefined') {
     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
  if(xmlhttp) {

    	var searchval = document.getElementById("searchval");
	var condition = document.getElementById("condition");
	var category_id = document.getElementById("category_id");
	var status_id = document.getElementById("status_id");	
 
	var send_info = "&searchval=" + searchval.value + "&condition=" + condition.value + "&category_id=" + category_id.value + "&status_id=" + status_id.value;

    	xmlhttp.open("GET","http://www.alvinsofsf.com/admin/cms.php?t=" + Math.random() + send_info,true);
    	xmlhttp.onreadystatechange = handleServerResponse;
	xmlhttp.send();
  }
}

function handleServerResponse() {
   document.getElementById("resultsdiv").innerHTML='<br /><br />Please wait...loading';

   if (xmlhttp.readyState == 0) {

   }
   if (xmlhttp.readyState == 1) {
	
   }
   if (xmlhttp.readyState == 2) {
	
   }
   if (xmlhttp.readyState == 3) {
		
   }
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
		
	document.getElementById("resultsdiv").innerHTML=xmlhttp.responseText; //Update the HTML Form element
     }
     else {
        alert("Sorry, an error has occurred.\n\nPlease try again.");
     }
   }
}

function EmailAjaxFunction() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) {

    var fname = document.getElementById("fname");
	var lname = document.getElementById("lname");
	var email = document.getElementById("email");	
 
	var send_info = "&fname=" + fname.value + "&lname=" + lname.value + "&email=" + email.value;

    	xmlhttp.open("GET","http://www.alvinsofsf.com/global/includes/emaillist.php?t=" + Math.random() + send_info,true);
    	xmlhttp.onreadystatechange = handleServerResponseEmailList;
	xmlhttp.send();
  }
}

function handleServerResponseEmailList() {
   document.getElementById("emaillistdiv").innerHTML='<p>&nbsp;</p><p style=text-align:center;>Please wait...processing</p>';

   if (xmlhttp.readyState == 0) {

   }
   if (xmlhttp.readyState == 1) {
	
   }
   if (xmlhttp.readyState == 2) {
	
   }
   if (xmlhttp.readyState == 3) {
		
   }
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
		
	document.getElementById("emaillistdiv").innerHTML=xmlhttp.responseText; //Update the HTML Form element
     }
     else {
        alert("Sorry, an error has occurred.\n\nPlease refresh this page and try again.");
     }
   }
}


