var xmlHttp = createXmlHttpRequestObject(); 

function createXmlHttpRequestObject() 
{	
 var xmlHttp;
 if(window.ActiveXObject){
  try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
  catch (e) {xmlHttp = false;}
 }
 else{
  try {xmlHttp = new XMLHttpRequest();}
  catch (e){xmlHttp = false;}
 }
 if (!xmlHttp)
  alert("Can't use Ajax. You have to allow JavaScript");
 else 
  return xmlHttp;
}

function GetSubMenu(submenuname)
{
 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
  document.getElementById("submenudiv").innerHTML = "Loading...";
  xmlHttp.open("GET", "asubmenu.php?action=getsubmenu&category="+submenuname, true);  
  xmlHttp.onreadystatechange = handleServerResponse;
  xmlHttp.send(null);
 }
 else
  alert("Engine is busy. Try latter");
}

function handleServerResponse() 
{
 if (xmlHttp.readyState == 4) {
  if (xmlHttp.status == 200) {
   tDiv = document.getElementById("submenudiv");
   tDiv.innerHTML = xmlHttp.responseText;
  } 
  else{alert("There was a problem accessing the server: " + xmlHttp.statusText);}
 }
}


function FindSubCategory()
{
 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
  xmlHttp.open("GET", "asubmenu.php?action=getsubcat&category="+document.getElementById("idcategory").value, true);  
  xmlHttp.onreadystatechange = handleCompanyResponse;
  xmlHttp.send(null);
 }
 else
  alert("Engine is busy. Try latter");
}

function handleCompanyResponse()
{
 if (xmlHttp.readyState == 4) {
  if (xmlHttp.status == 200) {
   tDiv = document.getElementById("subcatlist");
   tDiv.innerHTML = xmlHttp.responseText;
  } 
  else{alert("There was a problem accessing the server: " + xmlHttp.statusText);}
 }
}
