var xhr=null;

function getXhr(){
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest();
  else if(window.ActiveXObject){
    try{
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }else{
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre _  jour");
    xhr = false;
  }
}

function load(){
  getXhr();
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 &&  xhr.status== 200){
      document.getElementById("Espece").innerHTML=xhr.responseText;
      document.getElementById("Machine").innerHTML="";
      document.getElementById("Nb_Chariot").innerHTML="";
      document.getElementById("Total").innerHTML="";
     }
  }
  xhr.open("POST",'load.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send(); 
}
function espece(selectionE){
  selectionE=document.getElementById(selectionE).value;
  getXhr();
  if(selectionE!=""){
  	xhr.onreadystatechange = function(){
    	if(xhr.readyState == 4 &&  xhr.status== 200){
      	document.getElementById("Machine").innerHTML=xhr.responseText;
      	document.getElementById("Nb_Chariot").innerHTML="";
      	document.getElementById("Total").innerHTML="";
     	}
  	}
  	xhr.open("POST",'espece.php',true);
  	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	xhr.send("selection="+selectionE);
	}else{
	  document.getElementById("Machine").innerHTML =""
  	document.getElementById("Nb_Chariot").innerHTML="";
  	document.getElementById("Total").innerHTML=""; 
 	}
}
function machine(selectionM,selectionE){
  selectionM=document.getElementById(selectionM).value;
  selectionE=document.getElementById(selectionE).value;
  getXhr();
  if(selectionM!=""){
  	xhr.onreadystatechange = function(){
    	if(xhr.readyState == 4 &&  xhr.status== 200){
      	document.getElementById("Nb_Chariot").innerHTML=xhr.responseText;
      	document.getElementById("Total").innerHTML="";
     	}
  	}
  	xhr.open("POST",'machine.php',true);
  	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	xhr.send("selection="+selectionM+"&selectionE="+selectionE);
	}else{
	  document.getElementById("Nb_Chariot").innerHTML="";
  	document.getElementById("Total").innerHTML=""; 
 	} 
}
function modele(selectionMo,selectionE){
  selectionMo=document.getElementById(selectionMo).value;
  selectionE=document.getElementById(selectionE).value;
  getXhr();
  if(selectionMo!=""){
  	xhr.onreadystatechange = function(){
    	if(xhr.readyState == 4 &&  xhr.status== 200){
      	document.getElementById("Total").innerHTML=xhr.responseText;
     	}
  	}
  	xhr.open("POST",'modele.php',true);
  	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	xhr.send("selection="+selectionMo+"&selectionE="+selectionE);
	} 
}
