/*
*************************************************************************************
Fonctions de navigation
*************************************************************************************
*/
function opn_window(page,nom,proprietes){	
	window.open(page,nom,proprietes)
}

/*
*************************************************************************************
Fonctions d'inscription
*************************************************************************************
*/
function act_livraison(action){
		liv_zone = zone_livraison.getElementsByTagName('input');	
		liv_zone2 = zone_livraison.getElementsByTagName('select');	
		if(	(navigator.userAgent.indexOf("Firefox") != -1)||
			(navigator.userAgent.indexOf("Opera") != -1)){
			dsp_block = "table-row";		
		}else{
			dsp_block = "block";
		}	
		switch(action){
			case '1':
				document.getElementById('zone_livraison').style.display = "none";			
				for(i=0;i<liv_zone.length-1;i++){	
					document.forms[document.forms.length-2].elements[liv_zone[i].name].disabled=true;
				}	
				for(i=0;i<liv_zone2.length-1;i++){	
					document.forms[document.forms.length-2].elements[liv_zone2[i].name].disabled=true;
				}		
			break;
			case '0':
				document.getElementById('zone_livraison').style.display = dsp_block;			
				for(i=0;i<liv_zone.length-1;i++){	
					document.forms[document.forms.length-2].elements[liv_zone[i].name].disabled=false;			
				}		
				for(i=0;i<liv_zone2.length-1;i++){	
					document.forms[document.forms.length-2].elements[liv_zone2[i].name].disabled=false;
				}			
			break;
		}		
	}

/*
*************************************************************************************
Fonctions d'inscription
*************************************************************************************
*/

function verif_theForm(formulaire,lng){
	oForm = document.forms[formulaire];
	switch(lng){
		case '1':			
			txt_alert_email					= "Veuillez saisir E-mail";
			txt_alert_email_inc 			= "E-mail invalide\nvérifiez la syntaxe";			
			txt_alert_nom 					= "Veuillez saisir votre nom";
			txt_alert_societe 				= "Veuillez saisir le champ société";
			txt_alert_prenom 				= "Veuillez saisir votre prénom";
			txt_alert_adresse 				= "Veuillez saisir votre adresse";
			txt_alert_code_postal 			= "Veuillez saisir votre code postal";			
			txt_alert_ville					= "Veuillez saisir votre ville";
			txt_alert_tel 					= "Veuillez saisir votre n° de téléphone";
			txt_rangement					= "Veuillez sélectionner le type de rangement";
						
			txt_alert_nom_liv 				= "Veuillez saisir votre nom";
			txt_alert_prenom_liv 			= "Veuillez saisir votre prénom";
			txt_alert_adresse_liv 			= "Veuillez saisir votre adresse";
			txt_alert_code_postal_liv 		= "Veuillez saisir votre code postal";
			txt_alert_code_ville_liv 		= "Veuillez saisir votre ville";
			txt_alert_code_tel_liv 			= "Veuillez saisir votre n° de téléphone";
			
			txt_alert_lieulivraison			= "Veuillez sélectionner votre lieu de livraison";
			txt_checkRangement				= "Veuillez sélectionner un type de rangement";
		break;
		case '2':
			txt_alert_email					= "Please type your E-mail";
			txt_alert_email_inc 			= "Incorrect E-mail ";			
			txt_alert_nom 					= "Please type your last name";
			txt_alert_prenom 				= "Please type your first name";
			txt_alert_societe 				= "Please type the company";
			txt_alert_adresse 				= "Please type your adress";
			txt_alert_code_postal 			= "Please type your zip code";
			txt_alert_code_ville			= "Please type your city";
			txt_alert_code_tel 				= "Please type your phine number";
			txt_alert_fax					= "Veuillez saisir votre n° de fax";
			txt_alert_besoins				= "please specify your needs";
			txt_checkRangement				= "Veuillez sélectionner un type de rangement";
		break;
		case '3':
			txt_alert_email					= "Please type your E-mail";
			txt_alert_email_inc 			= "Incorrect E-mail ";			
			txt_alert_nom 					= "Please type your last name";
			txt_alert_prenom 				= "Please type your first name";
			txt_alert_societe 				= "Please type the company";
			txt_alert_adresse 				= "Please type your adress";
			txt_alert_code_postal 			= "Please type your zip code";
			txt_alert_code_ville			= "Please type your city";
			txt_alert_code_tel 				= "Please type your phine number";
			txt_alert_fax					= "Veuillez saisir votre n° de fax";
			txt_alert_besoins				= "please specify your needs";
			txt_checkRangement				= "Veuillez sélectionner un type de rangement";
		break;
	}	
	switch(formulaire){		
		case 'devis':			
					
			/*if(!oForm.societe.value){
				alert(txt_alert_societe)
				oForm.societe.focus();
				return false
			}*/
			
			if(!oForm.nom.value){
				alert(txt_alert_nom)
				oForm.nom.focus();
				return false
			}
			
			/*if(!oForm.prenom.value){
				alert(txt_alert_prenom)
				oForm.prenom.focus();
				return false
			}			
			
			if(!oForm.adresse.value){
				alert(txt_alert_adresse)
				oForm.adresse.focus();
				return false
			}*/
			
			if(!oForm.telephone.value){
				alert(txt_alert_tel)
				oForm.telephone.focus();
				return false
			}
			
			/*if(!oForm.ville.value){
				alert(txt_alert_ville)
				oForm.ville.focus();
				return false
			}
			
			if(!oForm.code_postal.value){
				alert(txt_alert_code_postal)
				oForm.code_postal.focus();
				return false
			}
			
			if(!oForm.ville.value){
				alert(txt_alert_code_ville)
				oForm.ville.focus();
				return false
			}*/
			
			if(!oForm.email.value){
				alert(txt_alert_email)
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}	
			
			check_b = oForm.elements['rangement[]'];
			is_check = 0;
			for(i=0;i<check_b.length;i++){
				if(check_b[i].checked == true){
					is_check = 1;
				}
			}
			if(is_check == 0){
				alert(txt_checkRangement)
				return false
			}
			/*if(!oForm.rangement.checked == true){
				alert(txt_rangement);				
				return false;
			}*/
		break;
		case 'mailing':
			if(!oForm.nom.value){
				alert(txt_alert_nom)
				oForm.nom.focus();
				return false
			}
			
			if(!oForm.prenom.value){
				alert(txt_alert_prenom)
				oForm.prenom.focus();
				return false
			}
			
			if(!oForm.email.value){
				alert(txt_alert_email)
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}		
		break;
	}
}
/*
*************************************************************************************
Fonctions d'inscription
*************************************************************************************
*/
function verif_seach(formulaire,lng){
	switch(lng){
		case '1':	
			txt_alert_mot					= "Veuillez saisir un mot clé";
		break;
		case '2':
			txt_alert_mot					= "Please type a key word";
		break;
	}
	oForm = document.forms[formulaire]
	if(!oForm.mot.value){	
		alert(txt_alert_mot)
		oForm.mot.focus()
		return false
	}
}


function ouvrir_fenetre(page,nom,proprietes){
	/*largeur = 600;
	hauteur = 420;
	M_largeur = (screen.width /2)-(largeur/2);
	M_hauteur = 185;	
	window.open(page,nom,"width="+largeur+" height="+hauteur+" top="+M_hauteur+" left="+M_largeur+"status=1 scrollbars=yes")*/
		window.open(page,nom,proprietes)
}

function echanger(img1,img2){
	if(document.images){
		img1.src = img2
	}
}

function verif_list(formulaire,champ,active_td,champ_active){
	oForm = document.forms[formulaire];
	switch(formulaire){
		case 'devis':
			switch(champ){
				case 'fonction':
					if(oForm.elements[champ].selectedIndex == oForm.elements[champ].options.length-1){
						active_cell(active_td,'1')
						oForm.elements[champ_active].disabled = false
					}else{
						active_cell(active_td,'0')
						oForm.elements[champ_active].disabled = true
					}
				break;
			}
		break;
	}	
}

function active_cell(identifiant,act){
	all_obj=zone_devis.getElementsByTagName("TD");	
	for(i=0;i<all_obj.length;i++){
		if(all_obj[i].id==identifiant){
			switch(act){
				case '0':
					dsp_object = 'none';
				break;
				case '1':
					dsp_object = 'block';	
				break;
			}
		  all_obj[i].style.display=dsp_object;
		}		
	}   
}


function opn_window(page,nom,proprietes){
	window.open(page,nom,proprietes)
}

function dsp_rdv(formulaire,champ,active_td){	
	oForm = document.forms[formulaire]
	if(champ.id == 'rdv'){
		if(champ.checked == true){
			active_cell(active_td,'1')
		}else{
			active_cell(active_td,'0')
		}		
	}
}

function changeTsearch(tSearch){
	document.search.tSearch.value = tSearch
}

function uncheckall(check_elem,activ_f){
	is_checked = document.search.elements[check_elem].checked
	check_s = document.getElementsByName('check_field');
	search_field = document.getElementsByName('search_field');
	
	for(i=0;i<check_s.length;i++){
		check_s[i].checked = false		
	}
	
	for(i=0;i<search_field.length;i++){
		search_field[i].disabled = true
	}
	
	
	switch(is_checked){
		case true:
			document.search.elements[check_elem].checked = true
			document.search.elements[activ_f].disabled = false
		break;
		case false:
			document.search.tSearch.value = ''
		break;
	}
}

function print_page(MID,lng){
	window.open('print_page.php?MID='+MID+'&langue_id='+lng)
}

/*
*************************************************************************************
Envoyer à un ami
*************************************************************************************
*/

	function send_friend(url_ami){
		window.open('/pages/send_friend.php?url_ami='+url_ami,'ami','width=540, height=400')
	}

/*
*************************************************************************************
Panier
*************************************************************************************
*/
function consult_panier(lng){
	window.opener.location.href="../panier-view-"+lng+"-panier.html";
	window.close();
}
	
function goPanier(panier_action,MID,lng,formulaire){
	switch(lng){
		case '1':
			txt_areUsure 		= "Etes vous sur ? ";
			txt_viderP 			= "Etes vous sur de vouloir vider votre panier ?";
		break;
		case '2':
			txt_areUsure 		= "Are your sure ?";
			txt_viderP	 		= "Are your sure to want to erase your basket ?";			
		break;
		case '3':
			txt_areUsure 	 	= "Are your sure ?";
			txt_viderP 		 	= "Are your sure to want to erase your basket ?";
		break;
	}
	switch(panier_action){
		case "view":
			location.href="/index.php?page=panier&panier_action="+panier_action+"&langue_id="+lng;		
		break;
		case "add":		
			QTE = document.forms[''+formulaire+''].FLD_Qte.options[document.forms[''+formulaire+''].FLD_Qte.selectedIndex].value;
			window.open('/pages/panier.php?panier_action=add&MID='+MID+'&F_qte='+QTE+'&langue_id='+lng,'caddy','width=540, height=250, status=yes');						
		break;	
		case "vider":
			if(confirm(txt_viderP)){				
				location.href="/index.php?page=panier&panier_action="+panier_action+"&langue_id="+lng;						
				return false
			}			
		break;
		case "remove_P":
			if(confirm(txt_areUsure)){	
				location.href="index.php?page=panier&panier_action="+panier_action+"&MIDS="+MID+"&langue_id="+lng;		
				return false
			}				
		break;
		case 'inscription':
			location.href="inscription-"+lng+".html";		
		break;
		default:// inscription,mdp,unlogin,login
			location.href="index.php?page=panier&panier_action="+panier_action+"&langue_id="+lng;		
		break;				
	}	
}

/* *********************************************************************************
	update du panier
	********************************************************************************* */
	function upt_Qte(MID,FQTE,toto,lng){
		location.href="/index.php?page=panier&panier_action=upt_panier&MID="+MID+"&F_Qte="+FQTE+"&langue_id="+lng		
	}
	function upt_Dst(pays_id,lng){
		location.href="index.php?page=panier&panier_action=view&pays_id="+pays_id+"&langue_id="+lng
	}
	function upt_Liv(livraison_id,lng){
		location.href="index.php?page=panier&panier_action=view&livraison_id="+livraison_id+"&langue_id="+lng
	}
	
	function dsp_val(element,valeur){
		document.forms[1].elements[element].value = valeur
	}

function verif_PanierForm(formulaire,lng){
	oForm = document.forms[formulaire];
	switch(lng){
		case '1':			
			txt_alert_email					= "Veuillez saisir E-mail";
			txt_alert_email_inc 			= "E-mail invalide\nvérifiez la syntaxe";			
			txt_alert_mdp					= "Veuillez saisir un mot de passe";
			txt_alert_mdp_confirm			= "Veuillez confirmer votre mot de passe";
			txt_alert_nom 					= "Veuillez saisir votre nom";
			txt_alert_societe 				= "Veuillez saisir le champ société";
			txt_alert_prenom 				= "Veuillez saisir votre prénom";
			txt_alert_adresse 				= "Veuillez saisir votre adresse";
			txt_alert_code_postal 			= "Veuillez saisir votre code postal";
			txt_alert_code_postal_err		= "Code postal invalide ou hors métropole";
			txt_alert_code_ville			= "Veuillez saisir votre ville";
			txt_alert_code_tel 				= "Veuillez saisir votre n° de téléphone";
			txt_alert_fax					= "Veuillez saisir votre n° de fax";
			txt_alert_mobile				= "Veuillez saisir votre n° de mobile";
			txt_cond_ventes					= "Vous devez accepter les conditions générales de ventes";
			
			txt_alert_nom_liv 				= "Veuillez saisir votre nom";
			txt_alert_prenom_liv 			= "Veuillez saisir votre prénom";
			txt_alert_adresse_liv 			= "Veuillez saisir votre adresse";
			txt_alert_code_postal_liv 		= "Veuillez saisir votre code postal";
			txt_alert_code_ville_liv 		= "Veuillez saisir votre ville";
			txt_alert_code_tel_liv 			= "Veuillez saisir votre n° de téléphone";
			
			txt_alert_typeS					= "Veuillez sélection un critère de recherche";
			txt_alert_mot					= "Veuillez saisir un mot clé";
			txt_alert_cat					= "Veuillez sélectionner une catégorie";
			txt_alert_alpha					= "Veuillez sélectionner une lettre";
			txt_alert_incCat				= "Sélection incorrecte";
			// demande de devis
			txt_alert_demande				= "Veuillez saisir votre demande";	
			txt_alert_fonction				= "Veuillez saisir votre fonction"
			txt_alert_besoins				= "Veuillez préciser vos besoins";
			txt_alert_rdv					= "Veuillez précisez une date";
		break;
		case '2':
			txt_alert_email					= "Please type your E-mail";
			txt_alert_email_inc 			= "Incorrect E-mail ";			
			txt_alert_mdp					= "Please type a password";
			txt_alert_mdp_confirm			= "please confirm your password";
			txt_alert_nom 					= "Please type your last name";
			txt_alert_prenom 				= "Please type your first name";
			txt_alert_adresse 				= "Please type your adress";
			txt_alert_code_postal 			= "Please type your zip code";
			txt_alert_code_postal_err		= "Zip Code incorrect or out of France";
			txt_alert_code_ville			= "Please type your city";
			txt_alert_code_tel 				= "Please type your phine number";
			txt_cond_ventes					= "You must be agree with the generals conditions terms";
			
			txt_alert_nom_liv 				= "Please type your last name";
			txt_alert_prenom_liv 			= "Please type your first name";
			txt_alert_adresse_liv 			= "Please type your adress";
			txt_alert_code_postal_liv 		= "Please type your zip code";
			txt_alert_code_ville_liv 		= "Please type your city";
			txt_alert_code_tel_liv 			= "Please type your phine number";
			
			txt_alert_typeS					= "please sélect a search option";
			txt_alert_mot					= "please type a key word";
			txt_alert_cat					= "please select a category";
			txt_alert_alpha					= "please select a letter";
			txt_alert_incCat				= "Incorrect selection";
			// demande de devis
			txt_alert_demande				= "please type your request";	
			txt_alert_fonction				= "please type your function"
			txt_alert_besoins				= "please specify your needs";
			txt_alert_rdv					= "please specify a date";
		break;
	}
	
	
	
	switch(formulaire){		
		case 'mdp':
			if(!oForm.email.value){
				alert(txt_alert_email);
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}		
		break;
		case 'login':
			/*
			if(!oForm.nom.value){
				alert(txt_alert_email)
				oForm.nom.focus();
				return false
			}
			
			if(!oForm.prenom.value){
				alert(txt_alert_email)
				oForm.prenom.focus();
				return false
			}
			*/
			if(!oForm.email.value){
				alert(txt_alert_email)
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}			
			
			if(!oForm.mdp.value){
				alert(txt_alert_mdp)
				oForm.mdp.focus();
				return false
			}
			oForm.panier_action.value="login";
			oForm.submit();
		break;
		case 'mailing':
			if(!oForm.nom.value){
				alert(txt_alert_nom_liv)
				oForm.nom.focus();
				return false
			}
			
			if(!oForm.prenom.value){
				alert(txt_alert_prenom_liv)
				oForm.prenom.focus();
				return false
			}
			
			if(!oForm.email.value){
				alert(txt_alert_email)
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}			
			
		break;
		case 'upt_inscription':
		case 'inscription':			
			if(!oForm.email.value){
				alert(txt_alert_email)
				oForm.email.focus();
				return false
			}
			
			if ((oForm.email.value.indexOf("@",1)>1)&&(oForm.email.value.indexOf(".",1)>0)){			
			}else{
				alert(txt_alert_email_inc);
				oForm.email.focus();
				return false
			}			
			
			if(!oForm.mdp.value){
				alert(txt_alert_mdp)
				oForm.mdp.focus();
				return false
			}
			
			if(!oForm.mdp_confirm.value){
				alert(txt_alert_mdp_confirm)
				oForm.mdp_confirm.focus();
				return false
			}
			
			if(oForm.mdp.value!=oForm.mdp_confirm.value){
				alert(txt_alert_mdp_confirm)
				oForm.mdp_confirm.focus();
				return false
			}
			
			if(!oForm.nom.value){
				alert(txt_alert_nom)
				oForm.nom.focus();
				return false
			}
			
			if(!oForm.prenom.value){
				alert(txt_alert_prenom)
				oForm.prenom.focus();
				return false
			}
			
			if(!oForm.adresse.value){
				alert(txt_alert_adresse)
				oForm.adresse.focus();
				return false
			}
			
			if(!oForm.code_postal.value){
				alert(txt_alert_code_postal)
				oForm.code_postal.focus();
				return false
			}
			
			if(oForm.code_postal.value.substring(0,2) > 95){
				alert(txt_alert_code_postal_err)
				oForm.code_postal.focus();
				return false
			}				
						
			if(!oForm.ville.value){
				alert(txt_alert_code_ville)
				oForm.ville.focus();
				return false
			}			
			
			if(!oForm.tel.value){
				alert(txt_alert_code_tel)
				oForm.tel.focus();
				return false
			}
			
			if(!oForm.acc_cond.checked==true){
				alert(txt_cond_ventes)
				oForm.acc_cond.focus();
				return false
			}		
			
			if(oForm.same_adr[1].checked==1){				
				if(!oForm.nom_liv.value){
					alert(txt_alert_nom_liv)
					oForm.nom_liv.focus();
					return false
				}
				
				if(!oForm.prenom_liv.value){
					alert(txt_alert_prenom_liv)
					oForm.prenom_liv.focus();
					return false
				}
				
				if(!oForm.adresse_liv.value){
					alert(txt_alert_adresse_liv)
					oForm.adresse_liv.focus();
					return false
				}
				
				if(!oForm.code_postal_liv.value){
					alert(txt_alert_code_postal_liv)
					oForm.code_postal_liv.focus();
					return false
				}
				
				if(oForm.code_postal_liv.value.substring(0,2) > 95){
					alert(txt_alert_code_postal_err)
					oForm.code_postal.focus();
					return false
				}
							
				if(!oForm.ville_liv.value){
					alert(txt_alert_code_ville_liv)
					oForm.ville_liv.focus();
					return false
				}			
				
				if(!oForm.tel_liv.value){
					alert(txt_alert_code_tel_liv)
					oForm.tel_liv.focus();
					return false
				}		
				
				if(oForm.email_liv.value){
					if ((oForm.email_liv.value.indexOf("@",1)>1)&&(oForm.email_liv.value.indexOf(".",1)>0)){			
					}else{
						alert(txt_alert_email_inc);
						oForm.email_liv.focus();
						return false
					}	
				}												
			}				
		break;		
	}
}

/* *********************************************************************************
	Devis
	********************************************************************************* */

function Devis(){
	check_r = document.getElementsByName('FLD_Rangement[]')
	cpt = 0
	nbr     = check_r.length
	flag_pcd = true
	flag_cbe = true
	max    = 1;
	 for (i=0;i < nbr;i++) {	 
	   if (check_r[i].checked) {	   
	     cpt = cpt + 1;      
	   }	  
	 }
	 if(cpt < max){
	       alert('Veuillez saisir vos rangements');
	       return false
	}	
	if(check_r[0].checked){
		flag_pcd = fctPlacard();
	}
	if(check_r[4].checked){
		flag_cbe = fctChambre();
	}
	if(!check_r[0].checked){
		decocher(document.getElementsByName('FLD_Option_Placard[]'));
	}
	if(!check_r[4].checked){
		decocher(document.getElementsByName('FLD_Option_Chambres[]'));
	}
	
	return flag_pcd && flag_cbe
}

function fctPlacard(){
	check_op = document.getElementsByName('FLD_Option_Placard[]');
	compteur = 0;
	nbop     = check_op.length;
	max    = 1;
	 for (i=0;i < nbop;i++) {	 
	   if (check_op[i].checked) {	   
	     compteur = compteur + 1;      
	   }
	 }
	 if((compteur < max)){
	       alert('Veuillez saisir un type de placard !');
	       return false;
	}				
	
	if((compteur > max)){
	       alert('Vous ne devez choisir qu\'un seul type de placard à la fois !');
	       return false;		
	}
	return true
}	

function fctChambre(){	
	check_oc = document.getElementsByName('FLD_Option_Chambres[]');
	compt = 0;
	nboc     = check_oc.length;
	max    = 1;
	 for (i=0;i < nboc;i++) {	 
	   if (check_oc[i].checked) {	
	     compt = compt + 1;       	    
	   }
	 }
	 if((compt < max)){	
	       alert('Veuillez saisir un type de chambre !');
	       return false;
	}	

	if((compt > max)){
	       alert('Vous ne devez choisir qu\'un seul type de chambre à la fois !');
	       return false;		
	}	
	
	return true
}

function decocher(field) {
	  for (i = 0; i < field.length; i++) {
	  field[i].checked = false; 
	}
}


// fonction pour éviter que lorsqu'on décoche une case, le message de cette case ne s'affiche
function verif(element) {
		// si la case est 'cochée', on lance la fonction d'affichage normale,
    if ( element.status ) {
    document.devis.autre.style.visibility = "visible";
    }
    // sinon on nettoie la zone de texte
    else {
    document.devis.autre.style.visibility = "hidden";
    }
}