function focusToLayer(id){ document.getElementById(id).focus(); }
function displayTOther(){ if (document.fm_contact.chckBxProduit[9].checked) document.getElementById('dv_saisieOther').style.display = "block"; else document.getElementById('dv_saisieOther').style.display = "none"; }
function validData(data,regExpress){ var resultat = data.match(regExpress); if ((resultat != null) && (resultat.length == 1)) return true; else return false; }
function validFormMail(){
	/* Tableau de correspondance avecle fichier Excel attendu */
	var paramBonus = new Array (
					 new Array ("Nom",document.fm_contact.saisie_nom.value,1,"Merci de préciser <a href=\"#saisie_nom\" class=\"a_lkModify\" title=\"Modifier votre nom de patronyme\" onClick=\"focusToLayer('saisie_nom');\">votre nom de patronyme</a>"),
					 new Array ("Prenom",document.fm_contact.saisie_prenom.value,1,"Merci de préciser <a href=\"#saisie_prenom\" class=\"a_lkModify\" title=\"Modifier votre prénom\" onClick=\"focusToLayer('saisie_prenom');\">votre prénom</a>"),
					 new Array ("Societe",document.fm_contact.MAILGEN_XSENDER.value,1,"Merci de préciser <a href=\"#MAILGEN_XSENDER\" class=\"a_lkModify\" title=\"Modifier le nom de votre société\" onClick=\"focusToLayer('MAILGEN_XSENDER');\">le nom de votre société</a>"),
					 new Array ("Fonction",document.fm_contact.saisie_fonction.value,1,"Merci de préciser <a href=\"#saisie_fonction\" class=\"a_lkModify\" title=\"Modifier l'intitulé de votre poste\" onClick=\"focusToLayer('saisie_fonction');\">votre fonction</a>"),
					 new Array ("Tel",document.fm_contact.saisie_telephone.value,1,"Merci de préciser <a href=\"#saisie_telephone\" class=\"a_lkModify\" title=\"Modifier le numéro de téléphone où vous êtes facilement joignable\" onClick=\"focusToLayer('saisie_telephone');\">votre téléphone</a>"),
					 new Array ("Adresse",document.fm_contact.saisie_adresse.value,1,"Merci de préciser <a href=\"#saisie_adresse\" class=\"a_lkModify\" title=\"Modifier vos coordonnées postales\" onClick=\"focusToLayer('saisie_adresse');\">votre adresse</a>"),
					 new Array ("Code Postal",document.fm_contact.saisie_cp.value,1,"Merci de préciser <a href=\"#saisie_cp\" class=\"a_lkModify\" title=\"Modifier votre code postal\" onClick=\"focusToLayer('saisie_cp');\">votre code postal</a>"),
					 new Array ("Ville",document.fm_contact.saisie_ville.value,1,"Merci de préciser <a href=\"#saisie_ville\" class=\"a_lkModify\" title=\"Modifier le lieu de votre habitation\" onClick=\"focusToLayer('saisie_ville');\">votre ville</a>"),
					 new Array ("Pays",document.fm_contact.saisie_pays.value,0,""));

	var paramProduit = new Array; var paramInfo = new Array;
	for(n=0;n<10;n++) paramProduit[n] = document.fm_contact.chckBxProduit[n].checked;
	for(n=0;n<2;n++) paramInfo[n] = document.fm_contact.chckBxInfo[n].checked;

	var Error = 0;
	var MsgInterm = "<p class=\"p_alert\">Des erreurs se sont introduites dans la saisie de votre formulaire :</p><ul>";
	document.getElementById('dv_msgErreur').style.display = "none";
	/* Test si case Produit cochée ?? */
	var nbProduit = 0; for(n=0;n<10;n++){ if (paramProduit[n] == true) nbProduit++; }
	if (nbProduit == 0){ Error++; MsgInterm += "<li>Merci de préciser <a href=\"#chckBx_other\" class=\"a_lkModify\" title=\"Modifier la cible produit à mettre en avant\" onClick=\"focusToLayer('chckBx_other');\">le type de produit</a></li>"; }
	/* Test si Autres et champs de saisie renseigné */
	if ((document.fm_contact.chckBxProduit[9].checked) && (document.fm_contact.saisieOther.value == '')){ Error++; MsgInterm += "<li>Merci de préciser <a href=\"#saisieOther\" class=\"a_lkModify\" title=\"Précisez le type de produit à mettre en avant \" onClick=\"focusToLayer('saisieOther');\">votre choix \" Autres \"</a></li>"; }
	/* Test si case Info cochée ?? */
	var nbInfo = 0; for(n=0;n<10;n++){ if (paramInfo[n] == true) nbInfo++; }
	if (nbInfo == 0){ Error++; MsgInterm += "<li>Merci de préciser <a href=\"#chckBx_IG\" class=\"a_lkModify\" title=\"Modifier la prestation souhaitée\" onClick=\"focusToLayer('chckBx_IG');\">l'information souhaitée</a></li>"; }
	/* Test validité des champs */
	for (i=0;i<paramBonus.length;i++){
		if (paramBonus[i][2] == 1){ 
			if ((((paramBonus[i][0].toUpperCase() == 'NOM') || (paramBonus[i][0].toUpperCase() == 'PRENOM') || (paramBonus[i][0].toUpperCase() == 'FONCTION')) && (validData(paramBonus[i][1],/^[a-zA-Z -]+$/g) == false)) || (((paramBonus[i][0].toUpperCase() == 'ADRESSE') || (paramBonus[i][0].toUpperCase() == 'SOCIETE') || (paramBonus[i][0].toUpperCase() == 'FONCTION')) && (validData(paramBonus[i][1],/^[0-9a-zA-Z ,]+$/g) == false)) || ((paramBonus[i][0].toUpperCase() == 'CODE POSTAL') && (validData(paramBonus[i][1],/^([A-Z]+[A-Z]?\-)?[0-9]{1,2} ?[0-9]{3}$/g) == false)) || ((paramBonus[i][0].toUpperCase() == 'TEL') && (validData(paramBonus[i][1],/^[0-9]{10}$/g) == false))){
				Error++; MsgInterm += "<li>" + paramBonus[i][3] + "</li>";
			}
		}
	}
	/* Test Adresse de messagerie */
	if (validData(document.fm_contact.MAILGEN_FROM.value,/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/g) == false){
		Error++; MsgInterm += "<li>Merci de confirmer <a href=\"#chckBx_IG\" class=\"a_lkModify\" title=\"Modifier votre adresse de messagerie\" onClick=\"focusToLayer('chckBx_IG');\">votre adresse de messagerie</a></li>";
	}
	/* Test Commentaires */
	if (document.fm_contact.MAILGEN_TEXT.value.length == 0){
		Error++; MsgInterm += "<li>Merci de préciser <a href=\"#MAILGEN_TEXT\" class=\"a_lkModify\" title=\"Soyez plus précis dans vos attentes\" onClick=\"focusToLayer('MAILGEN_TEXT');\">votre demande</a></li>";
	}
	MsgInterm += "</ul>";
	if (Error > 0){
		document.getElementById('dv_msgErreur').style.display = "block";
		document.getElementById('dv_msgErreur').innerHTML = MsgInterm;
		window.location.href = "#dv_msgErreur";
		return false;
	} else {
		var otherParam = "";
		for(n=0;n<10;n++){ if (paramProduit[n] == true) otherParam += "Produit=" + document.fm_contact.chckBxProduit[n].value + ";"; }
		if (document.fm_contact.chckBxProduit[9].checked) otherParam += "Produit=" + document.fm_contact.saisieOther.value + ";";
		for(n=0;n<2;n++){ if (paramInfo[n] == true) otherParam += "Info=" +  document.fm_contact.chckBxInfo[n].value + ";"; }
		otherParam += "budget=" + document.fm_contact.select_budget.options[document.fm_contact.select_budget.selectedIndex].value + ";";
		otherParam += "delai=" + document.fm_contact.select_temps.options[document.fm_contact.select_temps.selectedIndex].value + ";";
		otherParam += "civilite=" + document.fm_contact.select_civil.options[document.fm_contact.select_civil.selectedIndex].value + ";";
		for(i=0;i<paramBonus.length;i++){
			if (paramBonus[i][0].toUpperCase() != 'SOCIETE') otherParam += paramBonus[i][0] + "=" + paramBonus[i][1] + ";";
		}
		document.fm_contact.MAILGEN_BONUS_FIELDS.value = otherParam;
		return true;
	}
}
