//------------------------------------------------------------------------------
// LES DATES
//------------------------------------------------------------------------------
function isDateValid(chaineDate) 
{

//Je regarde tout d'abord si la chaîne n'est pas vide, sinon pas la peine d'aller plus loin
   if (chaineDate == "") return false

// J'utilise split pour créer un tableau dans lequel je récupère les jour mois année
// J'attends bien sûr une date formatée en JJ/MM/AAAA
   var ladate = (chaineDate).split("/")
   //alert(parseInt(ladate[0]));
// Si je n'ai pas récupéré trois éléments ou bien s'il ne s'agit pas d'entiers, pas la peine non plus d'aller plus loin
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false

// Sinon, c'est maintenant que je crée la date correspondante. Attention, les mois sont étalonnés de 0 à 11
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))

// Bug de l'an 2000 oblige, lorsque je récupère l'année, je n'ai pas toujours 4 chiffres selon les navigateurs, je rectifie donc ici le tir.
   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 1900

// Il ne reste plus qu'à vérifier si le jour, le mois et l'année obtenus sont les mêmes que ceux saisis par l'utilisateur.
   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])))
}

function add_day_date(dt_deb,nb_j)
{
   // dt_deb date de debut format jj/mm/aaaa
   // nb_j nombre de jour
   
   // on recupere les elements de la date de debut
   //alert('dans le add :'+nb_j)
   var t_date=dt_deb.split("/");
   //alert(parseInt(t_date[2])+' '+parseInt(t_date[1])+' '+parseInt(t_date[0]));
   //var deb=new Date(parseInt(t_date[1]+' '+t_date[0]+', '+t_date[2]+' 0:0:0');
   var deb=new Date(parseInt(t_date[2]),parseInt(t_date[1]),parseInt(t_date[0]));
   //alert(deb);
   var deb_time=deb.getTime();
   var fin=deb_time+(nb_j*24*3600*1000);
   var dt_fin=new Date();
   dt_fin.setTime(fin);
   //alert(deb_time+' '+fin);
   return str_fill(dt_fin.getDate(),'g','0',2)+'/'+str_fill((dt_fin.getMonth()+1),'g','0',2)+'/'+dt_fin.getFullYear();  
}

function ctrl_dt_deb_fin(dt_deb,dt_fin)
{
   // control si une date de fin est bien superieur a la date de debut
   // format d'entrée jj/mm/aaaa 
   var t_debut=dt_deb.split('/');
   var t_fin=dt_fin.split('/');
   var debut=t_debut[2]+t_debut[1]+t_debut[0];
   var fin=t_fin[2]+t_fin[1]+t_fin[0];
   var ok=(fin>=debut);
   //alert(debut+' '+fin+' '+ok);
   return ok;
}

/*
 * +-------------------------------------+
 * Number.prototype.nombreFormate
 * +-------------------------------------+
 * Params (facultatifs):
 *	- Int decimales: nombre de decimales (exemple: 2)
 *	- String signe: le signe precedent les decimales (exemple: "," ou ".")
 *	- String separateurMilliers: comme son nom l'indique
 * Returns:
 *	- String chaine formatee
 */
Number.prototype.nombreFormate = function (decimales, signe, separateurMilliers) {
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
	if (decimales == undefined) decimales = 2;
	if (signe == undefined) signe = '.';
	if (separateurMilliers == undefined) separateurMilliers = ' ';
	
	function separeMilliers (sNombre) {
		var sRetour = "";
		while (sNombre.length % 3 != 0) {
			sNombre = "0"+sNombre;
		}
		for (i = 0; i < sNombre.length; i += 3) {
			if (i ==  sNombre.length-1) separateurMilliers = '';
			sRetour += sNombre.substr(i, 3)+separateurMilliers;
		}
		while (sRetour.substr(0, 1) == "0") {
			sRetour = sRetour.substr(1);
		}
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
	}
	if (_sNombre.indexOf('.') == -1) {
		for (i = 0; i < decimales; i++) {
			_sDecimales += "0";
		}
		_sRetour = separeMilliers(_sNombre)+signe+_sDecimales;
	} else {
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
		if (sDecimalesTmp.length > decimales) {
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
			var nDiv = 1;
			for (i = 0; i < nDecimalesManquantes; i++) {
				nDiv *= 10;
			}
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
		}
      else {
          _sDecimales = sDecimalesTmp;
          for (i = sDecimalesTmp.length; i < decimales; i++) {
          _sDecimales += "0";
          }     
      }		
		
      _sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales; 
	}
   if(_sRetour.length == decimales + 1){
       _sRetour ='0'+_sRetour;
   }
	
   return _sRetour;
}





function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}
function selectCL(id,rch){
	document.location.href='/gestion/compte.php?compte='+id+'&rch='+rch;
   }
function selectCL02(id,rch){
	document.location.href='produit.php?compte_liste='+id+'&rch='+rch;
   }
function selectCLPRO(id,rch){
	document.location.href='/gestion/commerciaux.php?compte='+id+'&rch='+rch;
   }   
function selecturl(id,url){
	document.location.href=url + '?modif='+id+'&modifsel=1';
   }
function selectproduitconf(id,nom,zonerch){
	if(zonerch=="zoneproduit"){
		document.getElementById('produitconf').value= id;
		document.getElementById('produitnom').value= nom;
	}
	if(zonerch=="zoneproduitoption"){
		document.getElementById('produitconfoption').value= id;
		document.getElementById('produitnomoption').value= nom;
	}	
	document.getElementById(zonerch).style.display = 'none';
}   
function selectlibconf(id,nom,conseils,domotique,zonerch){

	document.getElementById('libconf').value= id;
	document.getElementById('libnom').value= nom;
	document.getElementById('conseilsconf').innerHTML = conseils;
	document.getElementById('domconf').innerHTML = domotique;
	
	document.getElementById(zonerch).style.display = 'none';
}  
function selectlibconfopt(id,nom,conseils,domotique,zonerch){

	document.getElementById('libconfopt').value= id;
	document.getElementById('libnomopt').value= nom;
	document.getElementById('conseilsconfopt').innerHTML = conseils;
	document.getElementById('domconfopt').innerHTML = domotique;
	
	document.getElementById(zonerch).style.display = 'none';
}  
function razproduit(id,nom){
		document.getElementById(id).value= '';
		document.getElementById(nom).value= '';
		if(document.getElementById(nom).id=='libnomopt'){
		document.getElementById('conseilsconfopt').innerHTML = '';
		document.getElementById('domconfopt').innerHTML = '';			
		}
		if(document.getElementById(nom).id=='libnom'){
		document.getElementById('conseilsconf').innerHTML = '';
		document.getElementById('domconf').innerHTML = '';			
		}		
   }  
   /////////////////////////////////////////////////////////////////
function remplichamp(zonerch,url,champrch)
{ 
    var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              	if(xhr.responseText!=''){
					 document.getElementById(zonerch).style.display = 'block';
					 document.getElementById(zonerch).innerHTML = xhr.responseText;
				}
			}
         }
    }; 
	var rch =document.getElementById(champrch).value;
	if(rch.length>2){
		var script = url;   // local script
		xhr.open("POST", script, true);		
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send("rch=" + rch + "&zonerch=" + zonerch);
	}
}
///////////////////////////////////////////// exploitation résultat recherche//////////////////////////////////////////////////
function selecte(id, zonerch,url,zoneresultat){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
		if(xhr.readyState  != 4)
		         {
					 document.getElementById(zonerch).style.display = 'none';
		}	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  document.getElementById(zoneresultat).style.display = 'block';
					  document.getElementById(zoneresultat).innerHTML = xhr.responseText;
			}
      }
};   

	xhr.open("POST", url, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" +id);
	   
   }
/////////////////////////////////////////////////////////////////////////////////////////////////
function lister_champs(theform)//icic la fonction qui va gÚnÚrer les ÚlÚments a envoyer
{
   var url='';
   for (i=0; i<theform.elements.length; i++)
   {
       if(((theform.elements[i].type=='radio' ||theform.elements[i].type=='checkbox') && theform.elements[i].checked==true) || (theform.elements[i].type!='radio' &&theform.elements[i].type!='checkbox'))//control si c'est des radio ou check box et incrÚmente le rÚsultat QUE si c'est cochÚ (sans þa il prendrais les deux)
           {
   if(theform.elements[i].type=='select-multiple' || theform.elements[i].type=='select' )//si c'est un select multiple 
   {
    for(j = theform.elements[i].length-1; j >= 0; j-=1)//on parcours les element du select multiple
       {
          if(theform.elements[i].options[j].selected)//si selectionnÚ on incremente
             {
                             if(url){url+='&';}
           url+=theform.elements[i].name+'='+theform.elements[i].options[j].value;
             }
     }
   }
   if(url){url+='&';}
   if(theform.elements[i].type!='select-multiple'){  url+=theform.elements[i].name+'='+theform.elements[i].value;}
           }
        }
return url;//onretourne le resultat vers la fonction appelÚe
}

function exploiteform(form,zonemsg,zone,msg,url,test,action){
   if(typeof form!="object"){form = document.getElementById(form);} //retourne object
	if(test==true){if(document.MM_returnValue==false) return false;}
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
		if(xhr.readyState  != 4)
		         {
					 document.getElementById(zonemsg).style.display = 'block';
					 document.getElementById(zonemsg).innerHTML = msg;
		}	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
				if(action=="0"){
					  document.getElementById(zonemsg).style.display = 'none';
					  document.getElementById(zone).style.display = 'block';
					  document.getElementById(zone).innerHTML = xhr.responseText;
				}
				if(action>"0"){
					document.getElementById(zonemsg).style.display = 'none';
					  document.getElementById(zone).style.display = 'block';
					  document.getElementById(zone).innerHTML = xhr.responseText;
					  if(document.getElementById('drapeau'+action)){document.getElementById('drapeau'+action).innerHTML = '<img src="/img/stock.png">';}
				}
				if(action<"0"){
					document.getElementById(zonemsg).style.display = 'none';
					  document.getElementById(zone).style.display = 'block';
					  document.getElementById(zone).innerHTML = xhr.responseText;
					  action=-1*action;
					  if(document.getElementById('drapeau'+action)){document.getElementById('drapeau'+action).innerHTML = '';}
				}				
			}
      }
};   

	var script = url;   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(lister_champs(form) + "&action=" + action);
	return false;
}

/////////////////////////////////
 function promo(action,id){

	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { document.getElementById('divpromo').innerHTML = xhr.responseText; }
         }
	};   

	var script = 'promotionajax.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("action=" + action + "&id=" + id);
}  

function selcat(ob, cat, divcat)
{ 
	var societe = "";
	id = ob.options[ob.selectedIndex].value
	var xhr = createXHR();
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              if(xhr.responseText!=''){
				  if(document.getElementById(divcat)!=NaN && document.getElementById(divcat)!=null){
								 document.getElementById(divcat).innerHTML = xhr.responseText;
								 document.getElementById(divcat).style.display = 'block';
				  				}
							 }
				 }
         }
    }; 
	var script = "/gestion/selcat.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id +"&cat=" + cat);
}

function list_control_produit(controle, divcont){
		var xhr = createXHR();
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              if(xhr.responseText!=''){
								 document.getElementById(divcont).innerHTML = xhr.responseText;
								 document.getElementById(divcont).style.display = 'block';
							 }
				 }
         }
    }; 
	var script = "/gestion/divcont.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("controle=" + controle);
}
/////////////////////////////////
 function attachprod(action,produit1,produit2){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { document.getElementById('attachprod').innerHTML = xhr.responseText; }
         }
	};   

	var script = '/gestion/attach_prod.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("action=" + action + "&produit1=" + produit1 + "&produit2=" + produit2);
} 
/////////////////////////////////
 function selclientcmd(ob){
	id = ob.options[ob.selectedIndex].value;
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) 
            { 
               document.getElementById('adressecmd').innerHTML = xhr.responseText;
			      document.getElementById('div_validation').style.display='block';
               selzonecmd(id, '');
			   }
         }
	};   

	var script = '/selclientcmd.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id );
}

 function selzonecmd(id, ob, port){
   
   //on test si la ZONE remise_escompte_manuel existe
   var escompte_remise=0;
   var contre_remb_test=0;
   var port_gratuit=0;
   // port gratuit
   if (document.getElementById('port_gratuit'))
   {
      if(document.getElementById('port_gratuit').checked) port_gratuit=1;
   }
   // valeur port
   if (typeof port=='undefined') 
      var port=0;
   else
      port= parseFloat(port.replace(",", "."));
   // remise_escompte
   if (document.getElementById('remise_escompte_manuel'))
   {
      escompte_remise=document.getElementById('remise_escompte_manuel').value;
      //esompte_remise=parseFloat(escompte_remise.replace(",", "."));
      escompte_remise=parseFloat(escompte_remise.replace(",", "."));
      //alert ('**'+escompte_remise);
   }
   // mode de reglement
   if (document.getElementById('mode_reg_id'))
   {
      contre_remb_test=document.getElementById('mode_reg_id').options[document.getElementById('mode_reg_id').selectedIndex].value;
   }   
   // client_id
   // changer en client 
   var client=0;
   if (document.getElementById('client'))
      client=document.getElementById('client').value;
    //alert (id);  
   
   
   
   /*if(ob!=null){pays = ob.options[ob.selectedIndex].value;}
	else{pays='';}*/
	if(typeof ob!="object"){pays=ob;} 
	else{pays = ob.options[ob.selectedIndex].value}
   
   
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { document.getElementById('paniercmd').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/selzonecmd.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id + "&pays=" + pays+'&escompte_remise='+escompte_remise+'&contre_remb_test='+contre_remb_test+'&port='+port+'&port_gratuit='+port_gratuit+'&client='+client);
}
function calculmanuel(tmpmontant, port){
	
   port=parseFloat(port.replace(",", "."));

   
   
   var remise_escompte=0;
   if (document.getElementById('remise_escompte_manuel'))
   {
      remise_escompte=document.getElementById('remise_escompte_manuel').value;
      remise_escompte=parseFloat(remise_escompte.replace(",", "."));

   }

   //alert (tmpmontant+' port: '+port+' remise: '+remise_escompte);
	var montant=((tmpmontant*1)-remise_escompte)+(port*1);
   //alert (montant);
   document.getElementById('montantmanuel').value=montant.nombreFormate(2,',',' ');
	
}





//////////////////////////////////////fiche/////////////////////////////:
function affichefiche(id,zoneresultat){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  document.getElementById(zoneresultat).innerHTML = xhr.responseText;
					  document.getElementById(zoneresultat).style.top= -10 + parseInt(document.body.scrollTop);
					  document.getElementById(zoneresultat).style.display = 'block';
				  				 var w_s=win_size();
                         var div_size= element_w_h(zoneresultat);
                         var div_obj=document.getElementById(zoneresultat);
                         var t_scroll=getScrollPosition();
                         var s_top=(Math.floor(w_s[1]/2)-Math.floor(div_size[1]/2))+t_scroll[1];
                         div_obj.style.top=s_top;   
                         if (s_top<0) 
                           div_obj.style.top=t_scroll[1];
                         //alert ( div_obj.style.top);
                         div_obj.style.left=Math.floor(w_s[0]/2)-Math.floor(921/2); 
                         //alert(div_size[0]+' '+div_size[1]+' '+div_obj.style.top+' '+div_obj.style.left); 
			      }
      }
	};   
   url='_fiche.php';
	xhr.open("POST", url, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" +id);
}
function cachefiche(zoneresultat){
	document.getElementById(zoneresultat).style.display = 'none';
}
/////////////////////////région///////////////////////////
function selregion(ob,region, divregion)
{ 
	if(typeof ob!="object"){id = ob;} 
	else{id = ob.options[ob.selectedIndex].value}
	var xhr = createXHR();
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              if(xhr.responseText!=''){
				  if(document.getElementById(divregion)!=NaN && document.getElementById(divregion)!=null){
								 document.getElementById(divregion).innerHTML = xhr.responseText;
								 document.getElementById(divregion).style.display = 'block';
                          }
							 }
				 }
         }
    }; 
	var script = "/gestion/selregion.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id + "&region=" + region);
}

//------------------------------------------------------------------------------
//position du scoll
//------------------------------------------------------------------------------
function getScrollPosition()
{
    return Array((document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop);
}

//------------------------------------------------------------------------------
//taille de l'ecran
//------------------------------------------------------------------------------
function win_size()
{
   var w_s=new Array(2);
   w_s[0]=100; // width
   w_s[1] =100; // height
   
   if (parseInt(navigator.appVersion)>3)
   {
      if (navigator.appName=="Netscape") 
      {
         w_s[0]= window.innerWidth; // width
         w_s[1] = window.innerHeight; // height
      }
      if (navigator.appName.indexOf("Microsoft")!=-1) 
      {
         w_s[0] = document.body.offsetWidth;
         w_s[1] = document.body.offsetHeight;
      }
   }
   return w_s;
}
//------------------------------------------------------------------------------
//talle d'un élémént
//------------------------------------------------------------------------------
function element_w_h(element)
{
   var obj = document.getElementById(element);
   var retour=new Array(0,0);
   if(obj.offsetHeight)
   {
      retour[0]==obj.offsetWidth;
      retour[1]=obj.offsetHeight;
   
   }
   else if(obj.style.pixelHeight)
   {
      retour[0]=obj.style.pixelWidth;
      retour[1]=obj.style.pixelHeight;
   }
   //alert (retour[0]+' '+retour[1]);
   return retour;
}
//------------------------------------------------------------------------------
// deplacement de la fiche produit
//------------------------------------------------------------------------------
var Netscape = (document.layers)? true:false;
var ie = (document.all)? true:false;
var FF = (document.getElementById)? true:false; 
var mouse_down_tr_fiche=false;
var X=0;
var Y=0;
var ob;
var OriX = 0;
var OriY = 0;

function md_tr_fiche()
{
   mouse_down_tr_fiche=true;
   ob=document.getElementById('divfiche').style;
   //document.getElementById('etat').innerHTML="down";
}
function mu_tr_fiche()
{

   mouse_down_tr_fiche=false;
   if (ob) ob=null;
   //document.getElementById('etat').innerHTML="up";
}

function MD(e) 
{
   if (ie) 
   {
        X=event.offsetX;
        Y=event.offsetY;   
        //OriX = ob.pixelLeft; 
        //OriY = ob.pixelTop;
   }
   else  
   {
          X=e.layerX;
          Y=e.layerY;
          //OriX = parseInt(ob.left); 
          //OriY = parseInt(ob.top); 
   }

   //return false;
}

function MM(e) 
{
   if(ob && mouse_down_tr_fiche)
   {
      if (ob && ie ) {
         ob.pixelLeft = event.clientX + document.body.scrollLeft - X;
         ob.pixelTop  = event.clientY + document.body.scrollTop  - Y;
      
         return false; 
         }
         
      if (ob && FF && !ie && mouse_down_tr_fiche) {
         var tmpx = (e.clientX + document.body.scrollLeft - X);
         var tmpy  = (e.clientY + document.body.scrollTop  - Y);
      	   ob.left = (parseInt(tmpx));
      	   ob.top = (parseInt(tmpy));
         return false; 
         }
   }
}
function MU() 
{
  if(ob)
  {
    ob = null;
    mouse_down_tr_fiche=false;
    OriX=0;
   return false;
  }
   //
}


if (Netscape) {
    document.captureEvents(Event.MOUSEMOVE);
    document.captureEvents(Event.MOUSEUP); 
  	document.captureEvents(Event.MOUSEDOWN);
   }

document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;

//------------------------------------------------------------------------------
// function concernant le mode de règlement 
// pour _comande_04.php
//------------------------------------------------------------------------------
function mode_reg_id_click(obj)
{
   if (obj.value==4)
      document.form_reglement.submit();
}

//------------------------------------------------------------------------------
// control de l'existence d'un email 
//------------------------------------------------------------------------------
function verif(email) 
{ // vérif validité email par REGEXP
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
   return (reg.exec(email)!=null)
}


function si_exist_email(client_id,zone,msg_erreur){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  var ok= xhr.responseText;
					  //alert (ok);
                 if (ok!=0)
					  {
                     alert(msg_erreur);
                      z_email=document.getElementById(zone).value='';
                     return false;
                 }
                 else if (ok==0) 
                 {
                  return true;
                 
                 }
			      }
      }
	};   
   var z_email=document.getElementById(zone).value;
	//alert('je passe');
   if (!verif(z_email) )
   {
      alert ('Email error !');
      document.getElementById(zone).value='';
      z_email='';
   }
   if (z_email!='' && z_email!='nomail@bookan.net')
   {
      url='/_si_exist_email.php';
   	xhr.open("POST", url, true);		
   	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   	xhr.send("client_id=" +client_id+"&email="+z_email);
   }
}
//------------------------------------------------------------------------------
// affichage des es exclusivité
//------------------------------------------------------------------------------
function affiche_exclusivite()
{
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  
                 document.getElementById('div_aff_exclusivite').innerHTML= xhr.responseText;
                 document.getElementById('div_aff_exclusivite').style.display='block';
                 document.getElementById('div_aff_btn_suivant').style.display='block'; 
			      }
      }
	};   
   if (document.getElementById('client').value>0)
   {
      url='/verif_client.php';
   	xhr.open("POST", url, true);		
   	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   	xhr.send("controle=cmd&client_id="+document.getElementById('client').value);
   }
}

function cmd_choix_client_change()
{
   if (document.getElementById('client').value>0)
   {
      document.getElementById('div_aff_btn_exclusivite').style.display='block'; 
   }
   else
   {
      document.getElementById('div_aff_btn_exclusivite').style.display='none';
      document.getElementById('div_aff_btn_suivant').style.display='none';  
      document.getElementById('div_aff_exclusivite').style.display='none';
   }



}
