var xmlHttp;

function disSubmit(){
	if (document.getElementById('search_annee').value!=""){
		document.getElementById("dis_sub_but").disabled =false;
	}
}

function recherche_a(){
	document.getElementById("the_number").innerHTML="recherche...";
}

function showProductsNo(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="includes/advsearch.php";	
	url=url+"?call=countProducts";
	url=url+"&id_type="+document.getElementById('search_type_id').value;
	url=url+"&id_marque="+document.getElementById('search_marque_id').value;
	url=url+"&cylindree="+document.getElementById('search_cylindree').value;
	url=url+"&id_modele="+document.getElementById('search_modele_id').value;
	url=url+"&annee="+document.getElementById('search_annee').value;
	
	xmlHttp.onreadystatechange=productsNoChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showMarque(){  
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	if (document.getElementById('search_type_id').value=='')
		document.getElementById("dis_sub_but").disabled =true;
	else
		document.getElementById("dis_sub_but").disabled =false;
	recherche_a();	
	document.getElementById("search_marque_id").disabled =false;
	document.getElementById("search_cylindree").disabled =true;
	document.getElementById("search_modele_id").disabled =true;
	document.getElementById("search_annee").disabled =true;
	document.getElementById("search_cylindree").value ="";
	document.getElementById("search_modele_id").value ="";
	document.getElementById("search_annee").value ="";
	
	var url="includes/advsearch.php";
	url=url+"?call=getMarqueList";
	url=url+"&id_type="+document.getElementById('search_type_id').value;
	
	xmlHttp.onreadystatechange=marqueChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showCylindree(){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	recherche_a();	
	document.getElementById("search_cylindree").disabled =false;
	document.getElementById("search_modele_id").disabled =true;
	document.getElementById("search_annee").disabled =true;
	document.getElementById("search_cylindree").value ="";
	document.getElementById("search_modele_id").value ="";
	document.getElementById("search_annee").value ="";

	var url="includes/advsearch.php";
	url=url+"?call=getCylindreeList";
	url=url+"&id_type="+document.getElementById('search_type_id').value;
	url=url+"&id_marque="+document.getElementById('search_marque_id').value;
	
	xmlHttp.onreadystatechange=cylindreeChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showModele(){ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	recherche_a();	
	document.getElementById("search_modele_id").disabled =false;
	document.getElementById("search_annee").disabled =true;
	document.getElementById("search_modele_id").value ="";
	document.getElementById("search_annee").value ="";
	
	var url="includes/advsearch.php";
	url=url+"?call=getModeleList";
	url=url+"&id_type="+document.getElementById('search_type_id').value;
	url=url+"&id_marque="+document.getElementById('search_marque_id').value;
	url=url+"&cylindree="+document.getElementById('search_cylindree').value;
	
	xmlHttp.onreadystatechange=modeleChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showAnnee(){ 		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	recherche_a();		
	document.getElementById("search_annee").value ="";
	document.getElementById("search_annee").disabled =false;

	var url="includes/advsearch.php";
	//var url="advsearch.php";
	url=url+"?call=getAnneeList";
	url=url+"&id_type="+document.getElementById('search_type_id').value;
	url=url+"&id_marque="+document.getElementById('search_marque_id').value;
	url=url+"&cylindree="+document.getElementById('search_cylindree').value;
	url=url+"&id_modele="+document.getElementById('search_modele_id').value;
	
	xmlHttp.onreadystatechange=anneeChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function productsNoChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		document.getElementById("the_number").innerHTML=xmlHttp.responseText;
}

function marqueChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("select_marque").innerHTML=xmlHttp.responseText;
		showProductsNo();
	} 
}

function cylindreeChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("select_cylindree").innerHTML=xmlHttp.responseText;
		showProductsNo();
	}  
}

function modeleChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("select_modele").innerHTML=xmlHttp.responseText;
		showProductsNo();
	} 
}

function anneeChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("select_annee").innerHTML=xmlHttp.responseText;
		showProductsNo();
	} 
}

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;
}
