/*####################################################################################*/
/*################################## REQUETES AJAX ###################################*/
/*####################################################################################*/

function getXhr(){
	var xhr = null;
	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..."); 
		xhr = false; 
	} 
	return xhr;
} 

function changeFournisseurs(){
	var xhr = getXhr();
	Idfournisseur = document.getElementById('fournisseurs').options[document.getElementById('fournisseurs').selectedIndex].value;
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){

		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var affich_info=xhr.responseText;
			document.getElementById('lisPdtUnivers').innerHTML = affich_info;
		}
	}
	
	xhr.open("POST","inc/class/search_list.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-1');
	xhr.send("fournisseurId="+Idfournisseur);			
}

function changeTypePdt(){
	var xhr = getXhr();
	IdType = document.getElementById('typePdt').options[document.getElementById('typePdt').selectedIndex].value;
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){

		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
			var affich_info=xhr.responseText;
			document.getElementById('lisPdtUnivers').innerHTML = affich_info;
		}
	}
	
	xhr.open("POST","inc/class/search_list.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-1');
	xhr.send("typeId="+IdType);
}


function ValidMail(){
	var envoie = 1;
	if((document.contact.name.value == '') || (document.contact.name.value == 'Champ obligatoire')) {
			document.contact.name.style.backgroundColor='#FF0000';
			document.contact.name.style.color='#FFFFFF';
			document.contact.name.value ='Champ obligatoire';
			var envoie = 0;
		}
	if((document.contact.email.value == '') || (document.contact.email.value == 'Champ obligatoire')) {
			document.contact.email.style.backgroundColor='#FF0000';
			document.contact.email.style.color='#FFFFFF';
			document.contact.email.value ='Champ obligatoire';
			var envoie = 0;
		}
	if (envoie == 1) {
		document.contact.submit();
	}	
}

/*On remet a blanc les champs obligatoire*/
function reset_oblig1() {
	document.contact.name.style.backgroundColor='#FFFFFF';
	document.contact.name.style.color='#0B547C';
	document.contact.name.value ='';
}
function reset_oblig2() {
	document.contact.email.style.backgroundColor='#FFFFFF';
	document.contact.email.style.color='#0B547C';
	document.contact.email.value ='';
}