/* modifSQLI - 200700703 = mise à jour CI-WEB 2G */
// Actions des champs textes
function txt_keyup(ev)	{
	Obj = (ie) ? event.srcElement : this;
	RgxAlert = new RegExp("^alerte");
	Alert = Obj.parentNode.parentNode;
	
	while(Alert.previousSibling) {
		Alert = Alert.previousSibling;
		if(RgxAlert.test(Alert.className) == true && Obj.value.length < 56) {
			Alert.style.display = "none";
			break;
		}
	}
	
	var AlertGalPb;
	var indexF = 0;
	switch (Obj.form.id) {
		case "formAccueil" :
			AlertGalPb = getElementsByClassName(document, "div", "al_pb_general");		
			break;
		case "formHaut" :
			AlertGalPb = getElementsByClassName(document, "div", "al_pbi_general");		
			break;
		default :
			AlertGalPb = getElementsByClassName(document, "div", "al_pbi_general");
			indexF = 1;
	}
	
	if (AlertGalPb.length > 0) {
		AlertGalPb[indexF].style.display = 'none';
	}
	
	
// On cache "à la main" le div d'alerte 55 caractères pour le champ localité.
	// En effet, le traitement précédent ne détecte que le div "al_pb_localite"
	AlertTailleLoc = getElementsByClassName(document, "div", "al_pb_55carac_localite");
	if (Obj.form.id != "formAccueil") {
		AlertTailleLoc = getElementsByClassName(document, "div", "al_pbi_55carac_localite");
	}
	form = Obj.form;
	if (AlertTailleLoc.length > 0 && form.localiteLibelle.value.length < 56) {
		AlertTailleLoc[indexF].style.display = 'none';
	}
}
/* fin modifSQLI - 200700703 */

/* Modif 20070529 */
function txt_keyup_next(ev)	{
	Obj = (ie) ? event.srcElement : this;
	RgxAlert = new RegExp("^alerte");
	Alert = Obj.parentNode.parentNode;
	while(Alert.nextSibling) {
		Alert = Alert.nextSibling;
		if(RgxAlert.test(Alert.className) == true) {
			Alert.style.display = "none";
			break;
		}
	}
}
/* /Modif 20070529 */
	
// Actions du formulaire express
function frm_exp_submit()	{
	boite_close_all();
	Ok = true;
	Ipt = this.getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++) {
		// Bloquage du formulaire si un champs obligatoire est vide
		if( (Ipt[i].name == "quoiqui") || (Ipt[i].name == "ou") || (Ipt[i].name == "quoiquih") || (Ipt[i].name == "ouh") || (Ipt[i].name == "quoiquib") || (Ipt[i].name == "oub") )	{
			
			// Expressions régulières
			RgxAlert = new RegExp("^alerte");
			RgxBtddg = new RegExp("^boite ambiguite");
			RgxGuide = new RegExp("^boite guide");
				
			// Affichage des alertes si un champs obligatoire est vide
			if(Ipt[i].value == "") {
				Alert = Ipt[i].parentNode.parentNode;
				while(Alert.previousSibling) {
					Alert = Alert.previousSibling;
					if(RgxAlert.test(Alert.className) == true) {
						Alert.style.display = "block";
						break;
					}
					if(Alert.nodeName.toLowerCase() == "div") {
						break;
					}
				}
				// Return du formulaire
				Ok = false;
			}
			
			// Affichage des ambiguités si le champ "Où" est rempli
			else if( (Ipt[i].name == "ou") || (Ipt[i].name == "ouh") || (Ipt[i].name == "oub") ) {
				Btddg = Ipt[i].parentNode.parentNode;
				while(Btddg.nextSibling) {
					Btddg = Btddg.nextSibling;
					if(RgxBtddg.test(Btddg.className) == true) {
						Btddg.style.display = "block";
						break;
					}
					if( (Btddg.nodeName.toLowerCase() == "div") && (RgxGuide.test(Btddg.className) == false) ) {
						break;
					}
				}
			}
			
		} // Fin if champs obligatoire	
		
	} // Fin for boucle sur les champs	
	
	return Ok;
} // Fin function

/* modifSQLI - 200700703 = mise à jour CI-WEB 2G */
// Actions du formulaire détaillé
function frm_det_submit()	{
	boite_close_all();
	Ok = true;

	localite = this.localiteLibelle;
	departement = this.depRegLibelle;
	adresse = this.voieLibelle;
	// Expressions régulières
	RgxAlert = new RegExp("^alerte");

	// Bloquage du formulaire si un champs obligatoire est vide
	if (is_champ_vide(this)) {
		Ok = false;
if(is_chaine_vide(localite.value)&&(is_chaine_vide(departement.value)|| !is_chaine_vide(adresse))) {
			// Affichage des alertes si un champs obligatoire est vide
			Alert = localite.parentNode.parentNode;
			while(Alert.previousSibling) {
				Alert = Alert.previousSibling;
				if(RgxAlert.test(Alert.className) == true) {
					Alert.style.display = "block";
					break;
				}
				if(Alert.nodeName.toLowerCase() == "div") {
					break;
				}
			}
		} 
	} // Fin if champs obligatoire	
	
	// On recupere la liste des alertes pour les champs dont la taille est supérieur à la limite
	AlertTaille = is_erreur_taille(this);
	var index = 0;
	if (this.id == 'formBas') {
		index = 1;
	}
	if (AlertTaille != null && AlertTaille.length > 0) {
		// On parcourt la liste, on affiche et on envoie les stats
		for(i=0; i < AlertTaille.length; i++) {
			myAlert = AlertTaille[i];
			var monClassName = myAlert[index].className;
			var stat = "";
			if (monClassName == "alerte al_pb_55carac_adresse" || monClassName == "alerte al_pbi_55carac_adresse") {
				stat = '<img ALT="" src="http:\/\/e.pagesjaunes.fr\/m\/web\/231031167783?g=226026167793&&p=PJ-FR-PB-ALERT_GEO_ADR&c=PB&st=0&sjs=0" border=0 width=1 height=1>';
			} else if (monClassName == "alerte al_pb_55carac_localite" || monClassName == "alerte al_pbi_55carac_localite") {
				stat = '<img ALT="" src="http:\/\/e.pagesjaunes.fr\/m\/web\/231031167783?g=226026167793&&p=PJ-FR-PB-ALERT_GEO_LOC&c=PB&st=0&sjs=0" border=0 width=1 height=1>';
			} else if (monClassName == "alerte al_pb_55carac_departement" || monClassName == "alerte al_pbi_dept") {
				stat = '<img ALT="" src="http:\/\/e.pagesjaunes.fr\/m\/web\/231031167783?g=226026167793&&p=PJ-FR-PB-ALERT_GEO_DEPT&c=PB&st=0&sjs=0" border=0 width=1 height=1>';
			}
			if (myAlert[index].innerHTML.match('e.pagesjaunes.fr') == null) {
				myAlert[index].innerHTML = myAlert[index].innerHTML + stat;				
			} else {
				myAlert[index].innerHTML = myAlert[index].innerHTML.substring(1, myAlert[index].innerHTML.length - stat.length - 26) + stat;
			}
			myAlert[index].style.display = "block";
		}
		Ok = false;
	} else {
		// Affichage de l'erreur générale s'il y a au moins une erreur
		AlertGal = getElementsByClassName(document, "div", "al_general");
		AlertGalPb = getElementsByClassName(document, "div", "al_pb_general");
		AlertGalPbi = getElementsByClassName(document, "div", "al_pbi_general");
		AlertGalPbiB = getElementsByClassName(document, "div", "al_pbib_general");
		
		if(Ok == false) {
			if(AlertGal.length > 0) {AlertGal[index].style.display = "block";}
			if(AlertGalPb.length > 0) {AlertGalPb[index].style.display = "block";}
			if(AlertGalPbi.length > 0) {AlertGalPbi[index].style.display = "block";}
			if(AlertGalPbiB.length > 0) {AlertGalPbiB[index].style.display = "block";}
		}
		else {
			if(AlertGal.length > 0) {AlertGal[index].style.display = "none";}
			if(AlertGalPb.length > 0) {AlertGalPb[index].style.display = "none";}
			if(AlertGalPbi.length > 0) {AlertGalPbi[index].style.display = "none";}
			if(AlertGalPbiB.length > 0) {AlertGalPbiB[index].style.display = "none";}
		}
	}
	return Ok;
} // Fin function
/* modifSQLI - 200700703 */

// Actions des boutons d'aide "?"
function hlp_click(ev){
	boite_close_all();
	Obj = check_event(this);
	RgxGde = new RegExp(" guide");
	Gde = Obj;
	while(Gde.parentNode) {
		Gde = Gde.parentNode;
		if( (Gde.nodeName.toLowerCase() == "div") && (Gde.className.toLowerCase().substring(0,6) == "sclear") ) {
			break;
		}
	}
	while(Gde.nextSibling) {
		Gde = Gde.nextSibling;
		if(RgxGde.test(Gde.className) == true) {
			Gde.style.display = "block";
			break;
		}
	}
}

/* modifSQLI - 20070703 = mise à jour CI-WEB 2G */
// Détecte si le formulaire n'est pas correctement renseigné
function is_champ_vide(form) {
	nom = form.nom;
	prenom = form.prenom;
	adresse = form.voieLibelle;
	localite = form.localiteLibelle;
	departement = form.depRegLibelle;
	vide = false;
	if (is_chaine_vide(localite.value)) {
		if (is_chaine_vide(departement.value) || !is_chaine_vide(adresse.value)) {
			vide = true;
		}
		if (vide == false && is_chaine_vide(nom.value)) {
			vide = true;
		}
	} else {
		if (is_chaine_vide(nom.value)) {
			if (!is_chaine_vide(prenom.value) || is_chaine_vide(adresse.value)) {
			vide = true;
		}
	}
	}
	return vide;
}

// Vérifie si une chaine de caractère est vide ou contient que des espace
function is_chaine_vide(x) {
    var i = 0;
    var vide = false;
    while (i<x.length && x.charAt(i)==' ')  i++; 
    if (i==x.length) vide = true; 
	return vide;
}

// Détecte si l'un des champs contient une valeur dont la taille est supérieur à 55 caractères
function is_erreur_taille(form) {
nom = form.nom;
	prenom = form.prenom;
	adresse = form.voieLibelle;
	localite = form.localiteLibelle;
	departement = form.depRegLibelle;
	var AlertTaille = new Array;
	var indice = 0;
	if (nom.value.length > 55) {
		AlertTaille[indice] = getElementsByClassName(document, "div", "al_pb_55carac_nom");
		if (form.id != "formAccueil") {
			AlertTaille[indice] = getElementsByClassName(document, "div", "al_pbi_55carac_nom");
		}
		indice++;
	}
	if (prenom.value.length > 55) {	
		AlertTaille[indice] = getElementsByClassName(document, "div", "al_pb_55carac_prenom");
		if (form.id != "formAccueil") {
			AlertTaille[indice]= getElementsByClassName(document, "div", "al_pbi_55carac_prenom");
		}
		indice++;		
	}		
	if (adresse.value.length > 55) {
		AlertTaille[indice] = getElementsByClassName(document, "div", "al_pb_55carac_adresse");
		if (form.id != "formAccueil") {
			AlertTaille[indice] = getElementsByClassName(document, "div", "al_pbi_55carac_adresse");
		}
		indice++;		
	}
	if (localite.value.length > 55) {
		AlertTaille[indice] = getElementsByClassName(document, "div", "al_pb_55carac_localite");
		AlertLocVide = getElementsByClassName(document, "div", "al_pb_localite");
		i = 0;
		if (form.id != "formAccueil") {
			AlertLocVide = getElementsByClassName(document, "div", "al_pbi_localite");
			AlertTaille[indice] = getElementsByClassName(document, "div", "al_pbi_55carac_localite");
			if (form.id == "formBas") {
				i = 1;
			}
		}
		AlertLocVide[i].style.display = "none";
		indice++;		
	}
	if (departement.value.length > 55) {
		AlertTaille[indice] = getElementsByClassName(document, "div", "al_pb_55carac_departement");
		if (form.id != "formAccueil") {
			AlertTaille[indice] = getElementsByClassName(document, "div", "al_pbi_dept");
		}
		indice++;		
	}	
	
	return AlertTaille;
}

// Levée d'ambiguité
function select_ambiguite(code, libelle, champ) {
	var inputLibelle = document.getElementsByName("localiteLibelle");
	var inputCode = document.getElementsByName("codeLieu");
	
if(champ == "DEPARTEMENT") {
		inputLibelle = document.getElementsByName("depRegLibelle");
	} else if(champ == "REGION") {
		inputLibelle = document.getElementsByName("depRegLibelle");
	}

	inputLibelle[0].value = libelle;
	inputCode[0].value = code;
	
	boite_close_all();
	
	formulaire = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	formulaire[0].submit();
}

function select_ambiguite_voie(code, libelle, numero) {
	document.getElementsByName("voieLibelle")[0].value = libelle;
	document.getElementsByName("codeLieu")[0].value = code;
	document.getElementsByName("numeroVoie")[0].value = numero;
	
	boite_close_all();
	
	formulaire = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	formulaire[0].submit();	
}

// Relance la recherche avec les professionnels seulement
function lance_recherche_professionnel() {
	formulaire = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	formulaire[0].professionel.value = true;
	formulaire[0].submit();
}

// Lance une recherche suite
function afficheAutrePagePB(formulaire, numPage, actionName)
{
	formulaire.actionForwardName.value=actionName;
	formulaire.numPage.value=numPage;
	formulaire.method='POST';
	formulaire.submit();
}

//recherche elargissement
function elargir_recherche(code,param,elargissement) {
	formulaire = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	if (param != null && param != '') {
		if (param == 'regionCode') {
			formulaire[0].regionCode.value = code;
		}
		else if(param == 'departementCode'){
			formulaire[0].departementCode.value = code;
			formulaire[0].listeDepartementCodes.value="";
		}
		else if(param == 'localiteCode'){
			formulaire[0].localiteCode.value = code;
			formulaire[0].codeLieu.value = code;
			formulaire[0].departementCode.value ="";
		}
		
		else if(param == 'numeroArrondissement'){
			formulaire[0].numeroArrondissement.value = code;
		}
	}
	formulaire[0].typeElargissement.value = elargissement;
	formulaire[0].submit();
}

function relance_recherche(relance) {
	formulaire = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	formulaire[0].typeRelance.value = relance;
	formulaire[0].submit();
}

function clean_codelieu(indexForm) {
	lieu = document.getElementsByName("codeLieu");
	lieu[indexForm].value = "";
}
/* fin modifSQLI - 20070703 = mise à jour CI-WEB 2G */

function tagStat(tag){
var maDivStat=document.getElementById("TagStats");
codeStat='<img ALT="" src="http:\/\/e.pagesjaunes.fr\/m\/web\/231031167783?g=226026167793&&p='+tag+'&c=PB&st=0&sjs=0" border=0 width=1 height=1>';
	maDivStat.innerHTML = codeStat;				
}
//-------------------------------------------

