// Fonction de check pour creation client ou retrouver client
// check.js

function checkmail(email,email_confirm,mode){
	// On test la validité de l'email
	var testform = 0;
	var re;

    re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/;
	//mail conforme
	if (re.test(email.value) == false) {
 		document.forms['creeident'].email.value="";
		document.forms['creeident'].email.focus();
		alert("Entrez un email valide sous la forme nom_utilisateur@nom_domaine");
		testform = 1 ;
		return;
    }
	//mail et mail_confirm identique
	if  (email.value==email_confirm.value) {
	     testform = 0 ;
	} else {
	     alert("L'email et sa confirmation sont différents !");
		 testform = 1 ;
	}
	//----------------------------
	if (testform==0){
	   //alert("On y va !");
	   if (mode==1){
	       document.forms['creeident'].submit(); 
	   }
	   if (mode==2){
	       document.forms['recident'].submit();
	   }
	}
}
       
function checkidpass(cli_ident,cli_pass){
// a faire verification de l'id et du pass client encore valable ??? 

	var f=document.forms['donneident'];
	var l2 = f.id_client; 
	var l3 = f.erreur_ident;
	
	   var id_client=null;
	   var erreur='';
	   
	   var xhr_object = null; 
	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   } 
	 
	   xhr_object.open("POST","verif_cli.php",true); 
	
	    
	   xhr_object.onreadystatechange = function() {
	      if(xhr_object.readyState == 4){
		     //alert('id client'+id_client);
		     //alert(xhr_object.responseText);
		   	 eval(xhr_object.responseText);
			 l3.value=erreur;
			 if (id_client!=''){
			 			 l2.value=id_client;
						 f.submit();
			}			 
		  } 
	   }
	   
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   // data a passer = l'id de la commune.
	   var data = "cli_ident="+cli_ident.value+"&cli_pass="+cli_pass.value;
	   xhr_object.send(data); 

}

function checkidpasspro(clipro_ident,clipro_pass,mode){
// a faire verification de l'id et du pass du professionnel	 acces base de donnée en js?
	var f=document.forms['donneident'];
	var l2 = f.id_clipro; 
	var l3 = f.erreur_ident;
	var l4 = f.mode_clipro;
	var l5 = f.credit_clipro;
	
	   var id_clipro=null;
	   var erreur='';
	   var autorisation=null;
	   
	   var xhr_object = null; 
	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   } 
	 
	   xhr_object.open("POST","verif_clipro.php",true); 
	
	    
	   xhr_object.onreadystatechange = function() {
	      if(xhr_object.readyState == 4){
		  	 //alert(xhr_object.responseText);
		   	 eval(xhr_object.responseText);
			 //alert('id clientpro'+id_clientpro);
			 l3.value=erreur;
			 l4.value=mode_client;
			 l5.value=credit;
			// if (id_clipro && autorisation){
			 if (autorisation==1){
			 			 //alert("go");
			 			 l2.value=id_clipro;
						 f.submit();
			
			} 
		  } 
	   }
	   
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   // data a passer 
	   
	   var data = "clipro_ident="+clipro_ident.value+"&clipro_pass="+clipro_pass.value+"&mode="+mode;
	   //alert(data);
	   xhr_object.send(data); 

	   
}

function checkidpropdf(clipro_ident){
//alert("checkidpropdf");
// a faire verification de l'id et du pass du professionnel	 acces base de donnée en js?
	var f=document.forms['id_pdf'];
	var l2 = f.id_clipro; 
	var l3 = f.erreur_ident;
	
	   var id_clipro=null;
	   var erreur='';
	   var autorisation=null;
	   
	   var xhr_object = null; 


	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   } 
	   
  
	   
	   xhr_object.open("POST","verif_clipro_pdf.php",true); 
	

		    
	   xhr_object.onreadystatechange = function() {
	      if(xhr_object.readyState == 4){
		  	 //alert(xhr_object.responseText);
		   	 eval(xhr_object.responseText);
			 //alert('id clientpro'+id_clientpro);
			 l3.value=erreur;
			 if (id_clipro && autorisation){
			 			 //alert("go");
			 			 l2.value=id_clipro;
						 f.submit();
			
			} 
		  } 
	   }
	   
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   // data a passer = l'id de la commune.
	   var data = "clipro_ident="+clipro_ident.value;
	   //alert (data);
	   xhr_object.send(data); 

	   
}

