//////////////////////////////////////////////
// FUNCTION TO RETURN XMLHTTPREQUEST OBJECT //
//////////////////////////////////////////////
function getXMLHttp()
{
var xmlHttp = null;
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

	if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
		}
return xmlHttp;
}


//////////////////////////////////////////////////////////////
// FUNCTION TO LOAD VEHICLE MODELS ON THE BASIS OF MAKER ID //
//////////////////////////////////////////////////////////////

function search()
{
	var company=document.form1.company.value;
	var userName=document.form1.userName.value;
	if(company=='' && userName=='')
	{	
		alert("Please provide atleast a 3 letter word for search.");

	}
	else
	{
		document.getElementById("searchDiv").style.display="block";
		document.getElementById("account").style.display="none";
	}


	var xmlHttp = new getXMLHttp();
	xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 && xmlHttp.status ==200){
				
				xmlDom = xmlHttp.responseXML;
				modelElements = xmlDom.getElementsByTagName("company");
				modelElements = rootElement[0].getElementsByTagName("category");
				modelsDRP = updateObj;
				modelsDRP.options.length = 0;
				modelsDRP.options[0] = new Option("Select a SubCategory", "-1");
				
				for(i=0; i<modelElements.length; i++){
					nameElement = modelElements[i].getElementsByTagName("name");
					nameElementValue = nameElement[0].firstChild.nodeValue;
					modelsDRP.options[modelsDRP.options.length] = new Option(nameElementValue, modelElements[i].getAttribute("id"));
					}
					//alert(xmlHttp.responseText);
					
			}
		}
	xmlHttp.open('GET', './ajaxResponse.php?company='+company+'&userName='+userName, true);
	xmlHttp.send(null);
}


function loadSubCategory(val, updateObj)
{
	alert(val);
		alert(updateObj);
subCategory = updateObj;
subCategory.options.length = 0;
subCategory.options[0] = new Option("LOADING SUB CATEGORIES", "-1");

	var xmlHttp = new getXMLHttp();
	xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 && xmlHttp.status ==200){
				
				xmlDom = xmlHttp.responseXML;
				rootElement = xmlDom.getElementsByTagName("subCats");
				modelElements = rootElement[0].getElementsByTagName("category");
				modelsDRP = updateObj;
				modelsDRP.options.length = 0;
				modelsDRP.options[0] = new Option("Select a SubCategory", "-1");
				
				for(i=0; i<modelElements.length; i++){
					nameElement = modelElements[i].getElementsByTagName("name");
					nameElementValue = nameElement[0].firstChild.nodeValue;
					modelsDRP.options[modelsDRP.options.length] = new Option(nameElementValue, modelElements[i].getAttribute("id"));
					}
					//alert(xmlHttp.responseText);
					
			}
		}
	xmlHttp.open('GET', '../ajaxResponse.php?get=subCat&pid='+val, true);
	xmlHttp.send(null);
}
