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;
}

function fillmanufacture(curVal){
	document.getElementById("divmanu").style.display = "none";
	document.getElementById("divvehi").style.display = "none";		
	document.getElementById("divsearch").style.display = "none";
	if(document.getElementById("divdata") != null)
		document.getElementById("divdata").style.display = "none";
	if(curVal != ""){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="fillvehicalcombo.php";	
		url=url+"?flag=1";
		url=url+"&year="+curVal;
		url=url+"&random="+Math.random()*5;
		xmlHttp.onreadystatechange=fill_boxes1;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function fill_boxes1(){ 
	if (xmlHttp.readyState==4){
		if (xmlHttp.responseText != "FALSE"){
			document.getElementById("divmanu").style.display = "";
			mystring = xmlHttp.responseText.split(",");
			nHTML = '';
			nHTML = nHTML + '<table class="cobtbl" width="50%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">';
			nHTML = nHTML + '<tr>';
					nHTML = nHTML + '<td class="cobhl" width="50%" align="right" bgcolor="#EBEBEB"><strong>Make :</strong></td>';
					nHTML = nHTML + '<td class="cobll" width="50%" bgcolor="#FFFFFF">';
						nHTML = nHTML + '<select name="prodmanufacturer" id="prodmanufacturer" onchange="fillvehicle(this.value)">';
						nHTML = nHTML + '<option value="">Select one...</option>';
						for (i=0;i<mystring.length;i++)
						{
							nHTML = nHTML + '<option value="'+mystring[i]+'">'+mystring[i]+'</option>';
						}
						nHTML = nHTML + '</select>';
					nHTML = nHTML + '</td>';
			nHTML = nHTML + '</tr>';
			nHTML = nHTML + '</table>';
			document.getElementById("divmanu").innerHTML = nHTML;
		}
	}
}

function fillvehicle(curVal){
	document.getElementById("divvehi").style.display = "none";		
	document.getElementById("divsearch").style.display = "none";
	if(document.getElementById("divdata") != null)
		document.getElementById("divdata").style.display = "none";
	if(curVal != "" && document.getElementById("prodyear").value != ""){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="fillvehicalcombo.php";	
		url=url+"?flag=2";
		url=url+"&year="+document.getElementById("prodyear").value;
		url=url+"&manufacturer="+curVal;
		url=url+"&random="+Math.random()*5;
		xmlHttp.onreadystatechange=fill_boxes2;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function fill_boxes2(){ 
	if (xmlHttp.readyState==4){
		if (xmlHttp.responseText != "FALSE"){
			document.getElementById("divvehi").style.display = "";
			mystring = xmlHttp.responseText.split(",");
			nHTML = '';
			nHTML = nHTML + '<table class="cobtbl" width="50%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">';
			nHTML = nHTML + '<tr>';
					nHTML = nHTML + '<td class="cobhl" width="50%" align="right" bgcolor="#EBEBEB"><strong>Model :</strong></td>';
					nHTML = nHTML + '<td class="cobll" width="50%" bgcolor="#FFFFFF">';
						nHTML = nHTML + '<select name="prodvehicle" id="prodvehicle">';
						nHTML = nHTML + '<option value="">Select one...</option>';
						for (i=0;i<mystring.length;i++)
						{
							nHTML = nHTML + '<option value="'+mystring[i]+'">'+mystring[i]+'</option>';
						}
						nHTML = nHTML + '</select>';
					nHTML = nHTML + '</td>';
			nHTML = nHTML + '</tr>';
			nHTML = nHTML + '</table>';
			document.getElementById("divvehi").innerHTML = nHTML;
			document.getElementById("divsearch").style.display = "block";
		}
	}
}

function validateform(thisfrm){
	if(document.getElementById("prodyear").value == ""){
		alert("Please select Year");
		document.getElementById("prodyear").focus();
		return false;
	}
	if(document.getElementById("prodmanufacturer").value == ""){
		alert("Please select Make");
		document.getElementById("prodmanufacturer").focus();
		return false;
	}
	if(document.getElementById("prodvehicle").value == ""){
		alert("Please select Model");
		document.getElementById("prodvehicle").focus();
		return false;
	}
	return true;
}