// fonction pour surligner les champs invalides
function surligne(champ, erreur) {
	if(erreur) champ.style.backgroundColor = "#fdf";
	else champ.style.backgroundColor = "";
}

// VERIFICATION DES FORMULAIRES DES POPUP
function verifMail_client(champ) {
	var regex = /^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
	if(champ.value == ""){
		surligne(champ, true);
		document.getElementById('emptymail_client').style.display = "block";
		document.getElementById('errormail_destinataire').style.display = "none";
		return false;
	}
	if(!regex.test(champ.value)) {
		surligne(champ, true);
		document.getElementById('emptymail_client').style.display = "none";
		document.getElementById('errormail_destinataire').style.display = "block";
		return false;
	} else {
		surligne(champ, false);
		document.getElementById('emptymail_client').style.display = "none";
		document.getElementById('errormail_destinataire').style.display = "none";
		return true;
    }
}

function verifMail_destinataire(champ) {
	var regex = /^[a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
	if(champ.value == ""){
		surligne(champ, true);
		document.getElementById('emptymail_destinataire').style.display = "block";
		document.getElementById('errormail_destinataire').style.display = "none";
		return false;
	}
	if(!regex.test(champ.value)) {
		surligne(champ, true);
		document.getElementById('emptymail_destinataire').style.display = "none";
		document.getElementById('errormail_destinataire').style.display = "block";
		return false;
	} else {
		surligne(champ, false);
		document.getElementById('emptymail_destinataire').style.display = "none";
		document.getElementById('errormail_destinataire').style.display = "none";
		return true;
    }
}

function verifmessage(champ) {
	if(champ.value == ""){
		surligne(champ, true);
		document.getElementById('emptymessage').style.display = "block";
		return false;
	} else {
		surligne(champ, false);
		document.getElementById('emptymessage').style.display = "none";
		return true;		
    }	
}

function verifNom_expediteur(champ) {
	if(champ.value == ""){
		surligne(champ, true);
		document.getElementById('emptynom_expediteur').style.display = "block";
		return false;
	} else {
		surligne(champ, false);
		document.getElementById('emptynom_expediteur').style.display = "none";
		return true;		
    }	
}

function verif_commentaire(champ) {
	if(champ.value == ""){
		surligne(champ,true);
		document.getElementById('empty_commentaire').style.display = "block";
		return false;
	} else {
		surligne(champ,false);
		document.getElementById('empty_commentaire').style.display = "none";
		return true;
	}
}

function verifFormMDP(f) {
	var emailOk = verifMail_client(f.email_destinataire);
	   
	if(emailOk) {
		return true;
	} else {
		//alert("Veuillez remplir correctement tous les champs");
		return false;
	}
}

function verifForm(f) {
	var emailOk = verifMail_destinataire(f.email_destinataire);
	var nomExpedOk = verifNom_expediteur(f.nom_expediteur);
	   
	if(emailOk && nomExpedOk) {
		return true;
	} else {
		//alert("Veuillez remplir correctement tous les champs");
		return false;
	}
}

function verifFormCommentaire(f) {
	var commentaireOk = verif_commentaire(f.commentaire);
	
	if(commentaireOk) {
		document.getElementById('empty_commentaire').style.display = "none";
		return true;
	} else {
		document.getElementById('empty_commentaire').style.display = "block";
		//alert("Veuillez saisir un commentaire");
		return false;
	}
}

// POP-UP(s) 
function show_gagner_bon(){ // ENVOI A UN AMI
	close_gagner_bon();
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('gagner_code');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_webcoupon(){
	close_gagner_bon();
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('webcoupon_box');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_transformer_code(){
	close_gagner_bon();
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('transformer_code');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_imprimer_coupon(){
	close_gagner_bon();
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('imprimer_coupon');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_envoyer_mdp(){ // ENVOI A UN AMI
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_envoyer_mdp');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_envoyer_ami(){ // ENVOI A UN AMI
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_envoyer_ami');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_congelo(){ // ENVOI A UN AMI
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_congelo');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_commentaire() { // FAIRE UN COMMENTAIRE
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_commentaire');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_popup_ajout_boite_recettes(){ // AJOUT BOITE A RECETTES
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_ajout_boite_recettes');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_popup_ajout_liste_courses(){ // AJOUT LISTE DE COURSES
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_ajout_liste_courses');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_astuce_jenny(){ // ASTUCE DE JENNY
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_astuce');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

function show_popup_connexion_inscription(){ // POPUP CONNEXION - INSCIPTION
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('popup_connexion_inscription');
	var shad = document.getElementById('shad');
	
	shad.style.display="block"; 	
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);
}

/*function close_popup() {
	var modbox_envoyer_ami = document.getElementById('popup_envoyer_ami');
	var modbox_commentaire = document.getElementById('popup_commentaire');
	var modbox_ajout_recette = document.getElementById('popup_ajout_boite_recettes');
	var modbox_ajout_courses = document.getElementById('popup_ajout_liste_courses');
	var modbox_astuce = document.getElementById('popup_astuce');
	var modbox_connexion = document.getElementById('popup_connexion_inscription');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_connexion.style.display="none"; 
	modbox_envoyer_ami.style.display="none"; 
	modbox_commentaire.style.display="none"; 
	modbox_ajout_recette.style.display="none"; 
	modbox_ajout_courses.style.display="none"; 
	modbox_astuce.style.display="none"; 	
}*/

function close_popup_astuce_jenny() {
	var modbox_envoyer_ami = document.getElementById('popup_astuce');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_gagner_bon() {
	var modbox_envoyer_ami = document.getElementById('gagner_code');
	var webcouponbox = document.getElementById('webcoupon_box');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	if(modbox_envoyer_ami) modbox_envoyer_ami.style.display="none"; 
	if(webcouponbox) webcouponbox.style.display="none"; 
}

function close_transformer_code() {
	var modbox_envoyer_ami = document.getElementById('transformer_code');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_imprimer_coupon() {
	var modbox_envoyer_ami = document.getElementById('imprimer_coupon');
	var shad = document.getElementById('shad');
	
	if(modbox_envoyer_ami){
		if(modbox_envoyer_ami.style.display=="block") {
			var response = ajax_file("ajax/getBonsFidelite.php");
			if (response){		
				document.getElementById("client_point_restant").innerHTML = response;
			}
		}
	}
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_popup_envoyer_mdp() {
	var modbox_envoyer_ami = document.getElementById('popup_envoyer_mdp');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_popup_envoyer_ami() {
	var modbox_envoyer_ami = document.getElementById('popup_envoyer_ami');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_popup_congelo() {
	var modbox_envoyer_ami = document.getElementById('popup_congelo');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_envoyer_ami.style.display="none"; 
}

function close_popup_commentaire() {
	var modbox_commentaire = document.getElementById('popup_commentaire');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_commentaire.style.display="none"; 
}

function close_popup_ajout_recette() {
	var modbox_ajout_recette = document.getElementById('popup_ajout_boite_recettes');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_ajout_recette.style.display="none"; 
}

function close_popup_ajout_courses() {
	var modbox_ajout_courses = document.getElementById('popup_ajout_liste_courses');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_ajout_courses.style.display="none"; 
}

function close_popup_astuce() {
	var modbox_astuce = document.getElementById('popup_astuce');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_astuce.style.display="none"; 	
}

function close_popup_connexion() {
	var modbox_connexion = document.getElementById('popup_connexion_inscription');
	var shad = document.getElementById('shad');
	
	shad.style.display="none";
	modbox_connexion.style.display="none"; 
}

// ONGLETS FICHE RECETTE
function swap_intro() {						
	document.getElementById('img_onglet').src='img/onglet_intro.jpg';
	document.getElementById('wrapper_intro').style.display='block';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function swap_ingredients() {						
	document.getElementById('img_onglet').src='img/onglet_ingredients.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='block';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function swap_mode_emploi() {						
	document.getElementById('img_onglet').src='img/onglet_mode_emploi.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='block';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function swap_commentaires() {						
	document.getElementById('img_onglet').src='img/onglet_commentaires.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='block';
}

function admin_swap_intro() {						
	document.getElementById('img_onglet').src='../img/onglet_intro.jpg';
	document.getElementById('wrapper_intro').style.display='block';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function admin_swap_ingredients() {						
	document.getElementById('img_onglet').src='../img/onglet_ingredients.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='block';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function admin_swap_mode_emploi() {						
	document.getElementById('img_onglet').src='../img/onglet_mode_emploi.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='block';
	document.getElementById('wrapper_commentaires').style.display='none';
}
function admin_swap_commentaires() {						
	document.getElementById('img_onglet').src='../img/onglet_commentaires.jpg';
	document.getElementById('wrapper_intro').style.display='none';
	document.getElementById('wrapper_ingredients').style.display='none';
	document.getElementById('wrapper_mode_emploi').style.display='none';
	document.getElementById('wrapper_commentaires').style.display='block';
}

// ONGLETS NOTRE EQUIPE
function swap_jenny() {						
	document.getElementById('jenny').style.display='block';
	document.getElementById('target_jenny').style.display='block';
	document.getElementById('title_jenny').src='img/jenny_on.png';
	
	document.getElementById('ludivine').style.display='none';
	document.getElementById('target_ludivine').style.display='none';
	document.getElementById('title_ludivine').src='img/ludivine_off.png';
	
	document.getElementById('cedrine').style.display='none';
	document.getElementById('target_cedrine').style.display='none';
	document.getElementById('title_cedrine').src='img/cedrine_off.png';
	
	document.getElementById('thimothee').style.display='none';
	document.getElementById('target_thimothee').style.display='none';
	document.getElementById('title_thimothee').src='img/timothee_off.png';
	
	document.getElementById('benjamin').style.display='none';
	document.getElementById('target_benjamin').style.display='none';
	document.getElementById('title_benjamin').src='img/benjamin_off.png';
	
	document.getElementById('maya').style.display='none';
	document.getElementById('target_maya').style.display='none';
	document.getElementById('title_maya').src='img/maya_et_milo_off.png';
}

function swap_ludivine() {						
	document.getElementById('jenny').style.display='none';
	document.getElementById('target_jenny').style.display='none';
	document.getElementById('title_jenny').src='img/jenny_off.png';
	
	document.getElementById('ludivine').style.display='block';
	document.getElementById('target_ludivine').style.display='block';
	document.getElementById('title_ludivine').src='img/ludivine_on.png';
	
	document.getElementById('cedrine').style.display='none';
	document.getElementById('target_cedrine').style.display='none';
	document.getElementById('title_cedrine').src='img/cedrine_off.png';
	
	document.getElementById('thimothee').style.display='none';
	document.getElementById('target_thimothee').style.display='none';
	document.getElementById('title_thimothee').src='img/timothee_off.png';
	
	document.getElementById('benjamin').style.display='none';
	document.getElementById('target_benjamin').style.display='none';
	document.getElementById('title_benjamin').src='img/benjamin_off.png';
	
	document.getElementById('maya').style.display='none';
	document.getElementById('target_maya').style.display='none';
	document.getElementById('title_maya').src='img/maya_et_milo_off.png';
}

function swap_cedrine() {						
	document.getElementById('jenny').style.display='none';
	document.getElementById('target_jenny').style.display='none';
	document.getElementById('title_jenny').src='img/jenny_off.png';
	
	document.getElementById('ludivine').style.display='none';
	document.getElementById('target_ludivine').style.display='none';
	document.getElementById('title_ludivine').src='img/ludivine_off.png';
	
	document.getElementById('cedrine').style.display='block';
	document.getElementById('target_cedrine').style.display='block';
	document.getElementById('title_cedrine').src='img/cedrine_on.png';
	
	document.getElementById('thimothee').style.display='none';
	document.getElementById('target_thimothee').style.display='none';
	document.getElementById('title_thimothee').src='img/timothee_off.png';
	
	document.getElementById('benjamin').style.display='none';
	document.getElementById('target_benjamin').style.display='none';
	document.getElementById('title_benjamin').src='img/benjamin_off.png';
	
	document.getElementById('maya').style.display='none';
	document.getElementById('target_maya').style.display='none';
	document.getElementById('title_maya').src='img/maya_et_milo_off.png';
}

function swap_thimothee() {						
	document.getElementById('jenny').style.display='none';
	document.getElementById('target_jenny').style.display='none';
	document.getElementById('title_jenny').src='img/jenny_off.png';
	
	document.getElementById('ludivine').style.display='none';
	document.getElementById('target_ludivine').style.display='none';
	document.getElementById('title_ludivine').src='img/ludivine_off.png';
	
	document.getElementById('cedrine').style.display='none';
	document.getElementById('target_cedrine').style.display='none';
	document.getElementById('title_cedrine').src='img/cedrine_off.png';
	
	document.getElementById('thimothee').style.display='block';
	document.getElementById('target_thimothee').style.display='block';
	document.getElementById('title_thimothee').src='img/timothee_on.png';
	
	document.getElementById('benjamin').style.display='none';
	document.getElementById('target_benjamin').style.display='none';
	document.getElementById('title_benjamin').src='img/benjamin_off.png';
	
	document.getElementById('maya').style.display='none';
	document.getElementById('target_maya').style.display='none';
	document.getElementById('title_maya').src='img/maya_et_milo_off.png';
}

function swap_benjamin() {						
	document.getElementById('jenny').style.display='none';
	document.getElementById('target_jenny').style.display='none';
	document.getElementById('title_jenny').src='img/jenny_off.png';
	
	document.getElementById('ludivine').style.display='none';
	document.getElementById('target_ludivine').style.display='none';
	document.getElementById('title_ludivine').src='img/ludivine_off.png';
	
	document.getElementById('cedrine').style.display='none';
	document.getElementById('target_cedrine').style.display='none';
	document.getElementById('title_cedrine').src='img/cedrine_off.png';
	
	document.getElementById('thimothee').style.display='none';
	document.getElementById('target_thimothee').style.display='none';
	document.getElementById('title_thimothee').src='img/timothee_off.png';
	
	document.getElementById('benjamin').style.display='block';
	document.getElementById('target_benjamin').style.display='block';
	document.getElementById('title_benjamin').src='img/benjamin_on.png';
	
	document.getElementById('maya').style.display='none';
	document.getElementById('target_maya').style.display='none';
	document.getElementById('title_maya').src='img/maya_et_milo_off.png';
}

function swap_maya() {						
	document.getElementById('jenny').style.display='none';
	document.getElementById('target_jenny').style.display='none';
	document.getElementById('title_jenny').src='img/jenny_off.png';
	
	document.getElementById('ludivine').style.display='none';
	document.getElementById('target_ludivine').style.display='none';
	document.getElementById('title_ludivine').src='img/ludivine_off.png';
	
	document.getElementById('cedrine').style.display='none';
	document.getElementById('target_cedrine').style.display='none';
	document.getElementById('title_cedrine').src='img/cedrine_off.png';
	
	document.getElementById('thimothee').style.display='none';
	document.getElementById('target_thimothee').style.display='none';
	document.getElementById('title_thimothee').src='img/timothee_off.png';
	
	document.getElementById('benjamin').style.display='none';
	document.getElementById('target_benjamin').style.display='none';
	document.getElementById('title_benjamin').src='img/benjamin_off.png';
	
	document.getElementById('maya').style.display='block';
	document.getElementById('target_maya').style.display='block';
	document.getElementById('title_maya').src='img/maya_et_milo_on.png';
}

/* ONGLETS PRESSBOOK */
function swap_presse() {						
	document.getElementById('menu_presse').style.display='block';
	document.getElementById('wrapper_presse').style.display='block';
	document.getElementById('btn_presse').src='img/btn_presse_on.jpg';
	
	document.getElementById('menu_web').style.display='none';
	document.getElementById('wrapper_web').style.display='none';
	document.getElementById('btn_web').src='img/btn_web_off.jpg';
}


function numTel(n_cible,id_cible,next){
	cible = document.getElementById(n_cible+id_cible);
	
	//alert(cible.value);

	if(cible.value.length>=2){
		
		if(cible.value.length>2) cible.value = cible.value.substr(0,2);
		
		if(id_cible<5){
			next_cible = id_cible+1;
			next_cible = document.getElementById(n_cible+next_cible);
			next_cible.focus();
		}
		else {
			next_cible = document.getElementById(next);
			next_cible.focus();
		}
	}	
}

function toggle(div_cible){
	cible = document.getElementById(div_cible);
	
	if(cible.style.display=='block'){
		cible.style.display = 'none';
	}
	else{
		cible.style.display = 'block';
	}
}

function verfiGetCoupon(){
	var response = ajax_file("ajax/verfiGetCoupon.php");

	if (response){		
		switch(response){
			case "ok":
				window.location.replace("webcoupon/");
			break;
			
			case "nb_point":
				window.alert( "Vous n'avez pas assez de points pour obtenir un coupon." );
			break;
			
			case "connexion":
				window.location.replace("mon_espace_connexion.php");
			break;			
		}		
		//document.getElementById("div_actu_dept").innerHTML = response;
	}
}
