/*********************************************
*
*
*********************************************/
function GetXmlHttpObject(handler)
{
	var objXMLHttp = null
	if (window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

/*********************************************
*
*
*********************************************/
function LoadSCat(parID,opt){
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=SUBCAT&disOpt=" + opt + "&parID=" + parID;
	
	//window.location = url;
	//alert(url);
	disableSel(0);
	xmlHttp.onreadystatechange=LoadSCatSelect
	xmlHttp.open("GET",url,true)											
	xmlHttp.send(null)
	return 
}

/*********************************************
*
*
*********************************************/
function LoadSCatSelect()
{	
	if(document.getElementById("subcat_search_div"))
	{
		if(xmlHttp.readyState==1){			
			document.getElementById("subcat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==2){			
			document.getElementById("subcat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==3){			
			document.getElementById("subcat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			
			document.getElementById("subcat_search_div").innerHTML = xmlHttp.responseText
		}	
	}
}


/*********************************************
*
*
*********************************************/
function LoadSSCat(parID,opt){
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=SSUBCAT&disOpt=" + opt + "&parID=" + parID ;	
	//alert(url);
	disableSel(1);
	xmlHttp.onreadystatechange=LoadSSCatSelect
	xmlHttp.open("GET",url,true)											
	xmlHttp.send(null)
	return;
}


/*********************************************
*
*
*********************************************/
function LoadSSCatSelect()
{	
	if(document.getElementById("sscat_search_div"))
	{
		if(xmlHttp.readyState==1){			
			document.getElementById("sscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==2){			
			document.getElementById("sscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==3){			
			document.getElementById("sscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			document.getElementById("sscat_search_div").innerHTML = xmlHttp.responseText
		}
	}
}


/*********************************************
*
*
*********************************************/
function LoadSSSCat(parID,opt){
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=SSSUBCAT&disOpt=" + opt + "&parID=" + parID;
	//alert(url);
	disableSel(2);
	xmlHttp.onreadystatechange=LoadSSSCatSelect
	xmlHttp.open("GET",url,true)											
	xmlHttp.send(null)
	return;
}


/*********************************************
*
*
*********************************************/
function LoadSSSCatSelect()
{	
	if(document.getElementById("ssscat_search_div"))
	{
		if(xmlHttp.readyState==1){			
			document.getElementById("ssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==2){			
			document.getElementById("ssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==3){			
			document.getElementById("ssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			document.getElementById("ssscat_search_div").innerHTML = xmlHttp.responseText;		
		}
	}
}


/*********************************************
*
*
*********************************************/
function LoadSSSSCat(parID,opt){
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=SSSSUBCAT&disOpt=" + opt + "&parID=" + parID;
	//window.location.href = url;
	//alert(url);
	disableSel(3);
	xmlHttp.onreadystatechange=LoadSSSSCatSelect
	xmlHttp.open("GET",url,true)											
	xmlHttp.send(null)
	return;
}


/*********************************************
*
*
*********************************************/
function LoadSSSSCatSelect()
{	
	if(document.getElementById("sssscat_search_div"))
	{
		if(xmlHttp.readyState==1){			
			document.getElementById("sssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==2){			
			document.getElementById("sssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttp.readyState==3){			
			document.getElementById("sssscat_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			document.getElementById("sssscat_search_div").innerHTML = xmlHttp.responseText
			//alert(xmlHttp.responseText);
		}	
	}
}


/*********************************************
*
*
*********************************************/
function LoadAttributes(parID,opt){
	xmlHttpA = GetXmlHttpObject()
	
	if (xmlHttpA == null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=ATTRIB&disOpt=" + opt + "&parID=" + parID ;
	//window.location.href = url;
	//alert(url);
	xmlHttpA.onreadystatechange = LoadAttribSelect
	xmlHttpA.open("GET",url,true)											
	xmlHttpA.send(null)
	return;
}

/*********************************************
*
*
*********************************************/
function LoadAttribSelect()
{	
	if(document.getElementById("div_attributes"))
	{
		if(xmlHttpA.readyState==1){			
			document.getElementById("div_attributes").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpA.readyState==2){			
			document.getElementById("div_attributes").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpA.readyState==3){			
			document.getElementById("div_attributes").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttpA.readyState==4 || xmlHttpA.readyState=="complete")	{
			document.getElementById("div_attributes").innerHTML = xmlHttpA.responseText;
			//alert(xmlHttpA.responseText);
		}
	}
}


/*********************************************
*
*
*********************************************/
function LoadAttributeValues(parID,opt){
	xmlHttpA = GetXmlHttpObject()
	
	if (xmlHttpA == null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=ATTRIBVALUE&disOpt=" + opt + "&parID=" + parID ;
	//window.location.href = url;
	//alert(url);
	xmlHttpA.onreadystatechange = LoadAttribValueSelect
	xmlHttpA.open("GET",url,true)											
	xmlHttpA.send(null)
	return;
}

/*********************************************
*
*
*********************************************/
function LoadAttribValueSelect()
{	
	if(document.getElementById("div_AttribValues[]"))
	{
		if(xmlHttpA.readyState==1){			
			document.getElementById("div_AttribValues[]").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpA.readyState==2){			
			document.getElementById("div_AttribValues[]").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpA.readyState==3){			
			document.getElementById("div_AttribValues[]").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttpA.readyState==4 || xmlHttpA.readyState=="complete")	{
			document.getElementById("div_AttribValues[]").innerHTML = xmlHttpA.responseText;
			//alert(xmlHttpA.responseText);
		}
	}
}


/*********************************************
*
*
*********************************************/
function LoadItems(catID,opt){
	xmlHttpIt = GetXmlHttpObject()
	
	if (xmlHttpIt == null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	url = rootPath+"ajx_search.php?Opt=LOADITEMS&disOpt=" + opt + "&catID=" + catID ;
	//window.location.href = url;
	//alert(url);
	xmlHttpIt.onreadystatechange = DisplayItems
	xmlHttpIt.open("GET",url,true)											
	xmlHttpIt.send(null)
	return;
}

/*********************************************
*
*
*********************************************/
function DisplayItems()
{	
	if(document.getElementById("items_search_div"))
	{
		if(xmlHttpIt.readyState==1){			
			document.getElementById("items_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpIt.readyState==2){			
			document.getElementById("items_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if(xmlHttpIt.readyState==3){			
			document.getElementById("items_search_div").innerHTML = "<span style='color:red;'>Loading ...</span>";
		}
		if (xmlHttpIt.readyState==4 || xmlHttp.readyState=="complete")	{
			document.getElementById("items_search_div").innerHTML = xmlHttpIt.responseText;
			//alert(xmlHttpA.responseText);
		}
	}
}


function disableSel(opt)
{
	var lstCnt = Array('subcat_search_div','sscat_search_div','ssscat_search_div','sssscat_search_div');
	var lstSel = Array('selSCat','selSSCat','selSSSCat','selSSSSCat');
	var lstDis = Array('-- Select Vehicle Type --','-- Select Year --', '-- Select Make --','-- Select Model --');
	var i = opt;
	for(;i<lstCnt.length;i++)
	{
		//alert(document.getElementById(lstCnt[i]));
		if(document.getElementById(lstCnt[i]))
		{
			var tmp = '<select name="'+lstSel[i]+'" id="'+lstSel[i]+'" disabled><option value="" selected>'+lstDis[i];
			tmp += '</option></select>'
			document.getElementById(lstCnt[i]).innerHTML = tmp;
		}
	}
	
	if(opt <= 3)
	{
		if(document.getElementById("items_search_div"))
		{
			document.getElementById("items_search_div").innerHTML = '';
		}
		
		if(document.getElementById("div_attributes"))
		{
			document.getElementById("div_attributes").innerHTML = '<select name="selAttribute[]" size="5" multiple id="selAttribute[]" style="width: 200px;"></select>';
		}
	}
	  
}

