	

var xhr = null; 



function getXhr(){

	if(window.XMLHttpRequest) // Firefox et autres

	   xhr = new XMLHttpRequest(); 

	else if(window.ActiveXObject){ // Internet Explorer 

	   try {

				xhr = new ActiveXObject("Msxml2.XMLHTTP");

			} catch (e) {

				xhr = new ActiveXObject("Microsoft.XMLHTTP");

			}

	}

	else { // XMLHttpRequest non supporté par le navigateur 

	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 

	   xhr = false; 

	} 

}



//------------------------------------------ 

// Methode qui controle si numerique ou non

// renvoi true si numerique

//-------------------------------------------

function is_numeric(num)

{

	var exp = new RegExp("^[0-9-.]+$","g");

	return exp.test(num);

}



//--------------------------------------------------------------

// MISE EN SESSION DU FORMULAIRE

//--------------------------------------------------------------

function verif_form(){

		

		document.getElementById('inputNom').style.background="#FFFFFF";

		document.getElementById('inputPrenom').style.background="#FFFFFF";

		document.getElementById('inputTel').style.background="#FFFFFF";

		document.getElementById('inputEmail').style.background="#FFFFFF";

		document.getElementById('inputMessage').style.background="#FFFFFF";

		

		

		var bool = true;

		

		if (document.getElementById('inputNom').value== "" || 

      document.getElementById('inputNom')== null){

		

		  //alert("Le champ du nom n'a pas été renseigné !");

		  document.getElementById('inputNom').style.background="#999999";

		  document.getElementById('champsObligatoires').style.color="#000000";

		  

		  bool = false;

		 

    }	

    

    if (document.getElementById('inputPrenom').value== "" || 

      document.getElementById('inputPrenom')== null){

		

		  //alert("Le champ du prenom n'a pas été renseigné !");

		  document.getElementById('inputPrenom').style.background="#999999";

		  document.getElementById('champsObligatoires').style.color="#000000";

		  

		  bool = false;

		 

    }

    

    if (document.getElementById('inputTel').value== "" || 

      document.getElementById('inputTel')== null){

		

		  //alert("Le champ du téléphone n'a pas été renseigné !");

		  document.getElementById('inputTel').style.background="#999999";

		  document.getElementById('champsObligatoires').style.color="#000000";

		 

     bool = false; 

		 

    }

    

    if (document.getElementById('inputEmail').value== "" || 

      document.getElementById('inputEmail')== null){

		

		  //alert("Le champ de l'email n'a pas été renseigné !");

			document.getElementById('inputEmail').style.background="#999999";

			document.getElementById('champsObligatoires').style.color="#000000";

			

			bool = false; 



    }

    

    if (document.getElementById('inputEmail').value.indexOf("@") == "-1" ||

			  document.getElementById('inputEmail').value.indexOf(".") == "-1" ||

			  document.getElementById('inputEmail').value == ""){

		

		  //alert("L'adresse email n'est pas au bon format !");

		  document.getElementById('inputEmail').style.background="#999999";

		  document.getElementById('champsObligatoires').style.color="#000000";

		  

		  bool = false; 

		 

    }

        

    if (document.getElementById('inputMessage').value== "" || 

      document.getElementById('inputMessage')== null){

		

		  //alert("Le champ de la demande n'a pas été renseigné 2 !");

		  document.getElementById('inputMessage').style.background="#999999";

		  document.getElementById('champsObligatoires').style.color="#000000";

		  

		  bool = false; 

		 

    }

        

    if (bool){

    

    getXhr();

		// 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){

				leselect = xhr.responseText;

				// On se sert de innerHTML pour rajouter les options a la liste

				document.getElementById('erreurForm').innerHTML = leselect;

			}

		}

		xhr.open("POST","fonctions/sendMails.php",true);

		// ne pas oublier ça pour le post

		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    

    var varNom       = document.getElementById('inputNom').value;

		var varPrenom    = document.getElementById('inputPrenom').value;

		var varSociete   = document.getElementById('inputSociete').value;

		var varFonction  = document.getElementById('inputFonction').value;

		var varAdresse   = document.getElementById('inputAdresse').value;

		var varCp        = document.getElementById('inputCp').value;

		var varVille     = document.getElementById('inputVille').value;

		var varTel       = document.getElementById('inputTel').value;

		var varFax       = document.getElementById('inputFax').value;

		var varEmail     = document.getElementById('inputEmail').value;

		var varDemande   = document.getElementById('inputMessage').value;

		

    xhr.send("validDemande=ok&pNom=" + varNom + "&pPrenom=" + varPrenom + 

              "&pSociete=" + varSociete + "&pFonction=" + varFonction + 

              "&pAdresse=" + varAdresse + "&pCp=" + varCp + "&pVille=" + varVille + 

              "&pTel=" + varTel + "&pFax=" + varFax + "&pEmail=" + varEmail + "&pDemande=" + varDemande);

              						

		
/*
		alert("validDemande=ok&pNom=" + varNom + "&pPrenom=" + varPrenom + 

              "&pSociete=" + varSociete + "&pFonction=" + varFonction + 

              "&pAdresse=" + varAdresse + "&pCp=" + varCp + "&pVille=" + varVille + 

              "&pTel=" + varTel + "&pFax=" + varFax + "&pEmail=" + varEmail + "&pDemande=" + varDemande);
*/
             						



    }     

}





		




