// JavaScript Document
// Script functions to redirect buttons and combo boxes to AJAX

var xmlHttp;

function pop_disp(st,pg,ct)
{
	if (ct)
	{
		pop_cat(st,pg);
	}
	else
	{
		pop_search(st,pg);
	}
}

// Set stock category combo box based on vehicle selected
function pop_cat(st,pg)
{ 
document.body.style.cursor = 'wait';
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="ajax/pop_cat.php";
url=url+"?st="+st;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function() {stateChanged("mainPage");};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

// Populate search result area
function pop_search(st,pg)
{ 
document.body.style.cursor = 'wait';
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="ajax/pop_search.php";
url=url+"?st="+st;
url=url+"&pg="+pg;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function() {stateChanged("mainPage");};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

// Check for PHP script completed
function stateChanged(blk) 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.getElementById(blk).innerHTML=xmlHttp.responseText;
  document.body.style.cursor = 'default';
 }
}

// Check if appropriate browser is in use for AJAX and determine best method to suit
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
