function ouvrir_envoi_mail() { 
	var lg=500;
	var ht=300;
	var left=(screen.width-lg)/2;
	var top=(screen.height-ht)/2; 
	
	ch = "popup_envoi_ami.php";
	window.open(ch,"fen","top="+top+",left="+left+",width="+lg+",height="+ht+",menubar=no,scrollbars=yes,statusbar=no"); 
	}

function ouvrir_envoi_ami_fiche(id, tbl) { 
	var lg=500;
	var ht=300;
	var left=(screen.width-lg)/2;
	var top=(screen.height-ht)/2; 
	
	ch = "popup_envoi_ami_fiche.php?id=" + id + "&tbl=" + tbl;
	window.open(ch,"fen","top="+top+",left="+left+",width="+lg+",height="+ht+",menubar=no,scrollbars=yes,statusbar=no"); 
	}

	

function ouvrir_contact() { 
	var lg=500;
	var ht=400;
	var left=(screen.width-lg)/2;
	var top=(screen.height-ht)/2; 
	
	ch = "popup_form_contact.php";
	window.open(ch,"fen","top="+top+",left="+left+",width="+lg+",height="+ht+",menubar=no,scrollbars=yes,statusbar=no"); 
	}

function checkEmail(email) {
	email = email + "";
	var reg = /^([_a-z0-9-]+(\.[_a-z0-9-]+)*)@([_a-z0-9-]+(\.[_a-z0-9-]+)*)\.([a-z]{2,6})$/i;
 	return reg.test(email);
}


function _get(obj) { 
	return(document.getElementById(obj)); 
	}
	

////////////////////////////////////////////////////////////	
function verif_ident(url) { 
	d=document.forms['f_ident']; 
	if (d.email_ident.value!="" && d.passe_ident.value!="") { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_ident(xhr,url); };
		xhr.open("GET", "ajax_test_ident.php?email=" + d.email_ident.value + "&passe=" + d.passe_ident.value , true);
		xhr.send(null);
	}
}


////////////////////////////////////////////////////////////	
function verif_ident2() { 
	d=document.forms['redirection']; 
	if (d.email_ident2.value!="" && d.passe_ident2.value!="") { 
		d.submit(); 
	}
}

////////////////////////////////////////////////////////////	
function aller_creer_compte() { 
	d=document.forms['redirection']; 
	d.action = "clients-creer-compte.php"; 
	d.submit(); 
}





function tester_ident(xhr,url) {
	if (xhr.readyState==4) alert_ident(xhr, url);
	}

function alert_ident(xhr,url) {
	if (xhr.responseText=="ok") document.location=url; 
	else alert("Nous n'avons pas pu vous identifier"); 
}

////////////////////////////////////////////////////////////
function envoi_passe() { 
	d=document.forms['f_ident']; 
	if (d.email_ident.value!="") { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_envoi(xhr); };
		xhr.open("GET", "ajax_test_envoi_passe.php?email=" + d.email_ident.value , true);
		xhr.send(null);
	}
	
}

function envoi_passe2() { 
	d=document.forms['redirection']; 
	if (d.email_ident2.value!="") { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_envoi(xhr); };
		xhr.open("GET", "ajax_test_envoi_passe.php?email=" + d.email_ident2.value , true);
		xhr.send(null);
	}
	
}


//////////////////////////////////////////
function tester_envoi(xhr) {
	if (xhr.readyState==4) alert_envoi(xhr);
	}

function alert_envoi(xhr) {
	if (xhr.responseText=="ok") { 
		alert("Votre mot de passe vient de vous etre envoy\351 par e-mail"); 
		setTimeout("fermer_envoi_passe()", 2000); 
		}
	else alert("Adresse e-mail inconnue"); 
}


function verif_doublon() { 
	d=document.forms['f_creer']; 
	if (d.email_rf.value!="") { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_doublon(xhr); };
		xhr.open("GET", "ajax_verif_doublon.php?email=" + d.email_rf.value , true);
		xhr.send(null);
	}
	}

//////////////////////////////////////////
function tester_doublon(xhr) {
	if (xhr.readyState==4) alert_doublon(xhr);
	}

function alert_doublon(xhr) {
	if (xhr.responseText=="ko") { 
		document.forms['f_creer'].email_rf.value="";  
		alert("Cette adresse e-mail est d\351j\340 utilis\351e par un Client"); 
		}
}



/////////////////////////////////////////////
function lancer_rech() { 
	d=document.forms['f_rech']; 
	if (d.mot.value!="") d.submit(); 
	}

/////////////////////////////////////
function aff_liste_gammes(lang) { 
	d=document.forms['f_moteur']; 
	if (d.rech_id_secteur.selectedIndex!=0) { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_liste_gammes(xhr); };
		xhr.open("GET", "ajax_genere_liste_gammes.php?id_secteur=" + d.rech_id_secteur.selectedIndex + "&lang=" + lang , true);
		xhr.send(null);
		}
	else _get('div_liste_gammes').innerHTML = ""; 
	}


//////////////////////////////////////////
function tester_liste_gammes(xhr) {
	if (xhr.readyState==4) alert_liste_gammes(xhr);
	}

function alert_liste_gammes(xhr) {
	_get('div_liste_gammes').innerHTML = xhr.responseText ; 
}


/////////////////////////////////////////////////////////////
function OP_show(j,id_form, champ) {
	//if (ouvert==false) {
		ch = "forms[" + id_form + "]." + champ ;
		debut_show_calendar(ch,j) ;
		ouvert=true;
	//}
	//else ouvert=false ;
}

//////////////////////
function lancer_moteur() { 
	d=document.forms['f_moteur']; 
	d.submit(); 

}

//////////////////////
function ajout_favoris(id_client, id, tbl) { 
		var xhr=null;
		if (window.XMLHttpRequest) { 
			xhr = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr.onreadystatechange = function() { tester_ajout_favs(xhr); };
		xhr.open("GET", "ajax_ajouter_fav.php?id_client=" + id_client + "&id=" + id + "&tbl=" + tbl , true);
		xhr.send(null);
	}

function trim (myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 

//////////////////////////////////////////
function tester_ajout_favs(xhr) {
	if (xhr.readyState==4) alert_ajout_favs(xhr);
	}

function alert_ajout_favs(xhr) {
	nb_favs = xhr.responseText ;
	if (nb_favs==0) alert("Ce produit est d\351ja dans votre liste de favoris");
	else { 
		_get('header_nb_favs').innerHTML = trim(nb_favs) ;
		alert("Ce produit a \351t\351 ajout\351 \340 votre liste de favoris");
		}  
}

//////////////////////
function trier(tri, sens) {
	d=document.forms['liste_res']; 
	d.cle_tri.value = tri; 
	d.ordre_tri.value = sens; 
	d.target="_self"; 
	d.no_page.value="1"; 
	d.submit(); 
	}
//////////////////////////
function aller_page(p) {
	d=	document.forms['liste_res']; 
	d.no_page.value= p  ;
	d.submit();
}
//////////////////////////
function aller_page_equipe(p) {
	d=	document.forms['liste_res']; 
	d.no_page.value= p  ;
	d.submit();
}



function aller_page_ident(act, tbl, id) { 
	d=	document.forms['redirection']; 
	d.ACT.value = act ; 
	d.tbl.value = tbl ; 
	d.id.value = id ; 
	d.submit();
	}

ind_cour = 1 ; 
function aller_droite(nb) { 
		ind_cour+=2; 
		for (i=ind_cour; i<=ind_cour+1; i++) { 
			if (i<=nb) { 
				ch = "p" + String(i); 
				_get(ch).style.display = "block"; 
				}
			}

		for (i=1; i<ind_cour; i++) { 
			ch = "p" + String(i); 
			_get(ch).style.display = "none"; 
			}

		ch = "<a href=\"#bas\" onclick=\"javascript:aller_gauche(" + nb +")\"><img src=\"images/fl_g.png\"  /></a>"; 
		_get('fl_g').innerHTML = ch; 

	if (ind_cour+1>=nb)  _get('fl_d').innerHTML = ""; 
	}



function aller_gauche(nb) { 
		for (i=ind_cour-2; i<=ind_cour-1; i++) { 
				ch = "p" + String(i); 
				_get(ch).style.display = "block"; 
			}

		for (i=ind_cour; i<=ind_cour+2; i++) { 
			if (i<=nb) { 
				ch = "p" + String(i); 
				_get(ch).style.display = "none"; 
				}
			}

		ind_cour-=2; 

		ch = "<a href=\"#bas\" onclick=\"javascript:aller_droite(" + nb + ")\"><img src=\"images/fl_d.png\"  /></a>"; 
		_get('fl_d').innerHTML = ch; 

	if (ind_cour==1)  _get('fl_g').innerHTML = ""; 
	}


function aller_tele(obj) { 
	d=	document.forms['f_teles']; 
	d.id_tele.value = d.elements[obj][d.elements[obj].selectedIndex].value; 
	d.submit(); 
	}



function verif_inscrip() { 
	d=document.forms['f_inscrip']; 
	if (d.nom_rf.value=="" || d.prenom_rf.value=="" || d.email_rf.value=="" || d.tel_rf.value=="" || d.societe_rf.value==""){ 
		 alert("Veuillez renseigner les champs obligatoires"); 
		 }
	else { 
		if (checkEmail(d.email_rf.value)==false) alert("L'adresse e-mail est invalide"); 
		else { 
			if (isNaN(d.tel_rf.value)==true) alert("Votre num\351ro de t\351l\351phone est invalide"); 
			else { 
				if (d.cgv.checked==false) alert("Veuillez accepter les Conditions G\351n\351rales de Vente"); 
				else d.submit(); 
			}
			}
		}
	}

function verif_aj_part() { 
	d=document.forms['f_inscrip']; 
	if (d.nom_rf.value=="" || d.prenom_rf.value=="" || d.email_rf.value=="" || d.tel_rf.value=="") alert("Veuillez renseigner les champs obligatoires"); 
	else { 
		if (checkEmail(d.email_rf.value)==false) alert("L'adresse e-mail est invalide"); 
		else { 
			if (isNaN(d.tel_rf.value)==true) alert("Votre num\351ro de t\351l\351phone est invalide"); 
			else { 
				d.ACT.value = "enreg"; 
				d.submit();
			}
			}
		} 
	}

function finaliser_part() { 
	d=document.forms['f_inscrip']; 
	d.action="action_finaliser_inscrip.php"; 
	d.submit();
	}

function verif_creer_compte() { 
	d=document.forms['f_creer']; 
	if (d.nom_rf.value=="" || d.prenom_rf.value=="" || d.email_rf.value=="" || d.tel_rf.value=="" || d.fonction.value=="" || d.societe_rf.value=="") alert("Veuillez renseigner les champs obligatoires"); 
	else { 
		email = d.email_rf.value; 
		if ( checkEmail(email) ==false) alert("Votre adresse e-mail est invalide"); 
		else { 
			if (isNaN(d.tel_rf.value)==true) alert("Votre num\351ro de t\351l\351phone est invalide"); 
			else d.submit(); 
		}
		}
	}

