//Detection de la version si Netscape, Firefox, ...
function GetVersion1(){
	var Ver = -1;
	
	if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
		var Sfv = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var Des = navigator.plugins["Shockwave Flash" + Sfv].description;
		var Lsd = Des.split(" ");
		var Ls1 = Lsd[2].split(".");
		var Ls2;
		var Ve1 = Ls1[0];
		var Ve2 = Ls1[1];
		
		if(Lsd[3] != ""){
			Ls2 = Lsd[3].split("r");
		}else{
			Ls2 = Lsd[4].split("r");
		}
		var Ve3 = Ls2[1] > 0 ? Ls2[1] : 0;
		Ver = Ve1 + "." + Ve2 + "." + Ve3;
	}
	return Ver;
}
//****
//Detection de la version si MSIE et Windows
function GetVersion2(){
	var Ver;
	var Axo;
	var Err;

	try{
		Axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		Ver = Axo.GetVariable("$version");
	}catch(Err){}
	
	if(!Ver){
		try{
			Axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			Ver = "WIN 6,0,21,0";
			Axo.AllowScriptAccess = "always";
			Ver = Axo.GetVariable("$version");
		}catch(Err){}
	}
	if(!Ver){
		try{
			Axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			Ver = Axo.GetVariable("$version");
		}catch(Err){}
	}
	if(!Ver){
		try{
			Axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			Ver = "WIN 3,0,18,0";
		}catch(Err){}
	}
	if(!Ver){
		try{
			Axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			Ver = "WIN 2,0,0,11";
		}catch(Err){
			Ver = -1;
		}
	}
	return Ver;
}
//****
//Retourne la version du Flash Player
function GetFlashVer(){
	var Ver = -1;
	
	if(navigator.plugins != null && navigator.plugins.length > 0){
		Ver = GetVersion1();
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1){
		Ver = 4;
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1){
		Ver = 3;
	}else if(navigator.userAgent.toLowerCase().indexOf("webtv") != -1){
		Ver = 2;
	}else if(isIE && isWin && !isOpera){
		Ver = GetVersion2();
	}
	
	return Ver;
}
//****
//Detect si le flash player et au mini de la version demandée
function DetectFlashVer(Rmaj, Rmin, Rrev){
	var Vers = GetFlashVer();
	
	if(Vers == -1){
		return false;
	}else if(Vers != 0){
		if(isIE && isWin && !isOpera){
			TmpL = Vers.split(" ");
			TmpS = TmpL[1];
			Vlst = TmpS.split(",");
		}else{
			Vlst = Vers.split(".");
		}
		var Vmaj = Vlst[0];
		var Vmin = Vlst[1];
		var Vrev = Vlst[2];
		var Done = Vmaj > Rmaj || (Vmaj == Rmaj && (Vmin > Rmin || (Vmin == Rmin && Vrev >= Rrev)))
		
		return Done;
	}
}
//Get User Agent
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /msie [56789]/i.test(ua);
var ie7 = ie && /msie 7/i.test(ua);
var moz = !opera && /mozilla\/[56789]/i.test(ua);
var flashActif = ("undefined" != typeof(DetectFlashVer)) ? DetectFlashVer(8, 0, 0) : false;

//Actions du formulaire express
function frm_exp_submit(){
	boite_close_all();
	Ok = true;
	var form = this;
	
	if(form){	
		razAlerteClassique(form);
		cleanForm(form);
		if(form.flashInactif){
			form.flashInactif.value=!flashActif;
		}
		var champQuoi = form.quoiqui;
		var champOu = form.ou;
		//Expressions régulières
		RgxAlert = new RegExp("^alerte");
		if(champOu.value == ""){
			var alerte = champOu.parentNode.parentNode;
			masqueAfficherAlert(alerte, "block");
			if(champQuoi.value == ""){
				if(champQuoi.focus){
					champQuoi.blur();
				}
				alerte = champQuoi.parentNode.parentNode;
				masqueAfficherAlert(alerte, "block");
			}
			Ok = false;
		}
		//alerte si une chaine de caracteres du champs 'ou' dépasse 50
		if((new RegExp('\\S{50}')).test(champOu.value)){
			var elt = document.getElementById("alerteOuTropLong");
			if(elt != null){
				elt.style.display = "block";
				Ok = false;
			}
		}
		// stats aladin
		if (trim(champQuoi.value) != "" && trim(champOu.value) == "") {
			var oDate = new Date();
			var sUrl = DocumentBase() + "genstat.do?typeService=YES&typeRequete=RECHERCHE_DEUX_CHAMPS&typeAction=RECHERCHE&typeReponse=ALERT_OU&requeteQuiQuoi=" + champQuoi.value + "&_pjTs="+oDate.getTime();
			_pjStatWriteImg( sUrl,false,'pjStatAlertOuImg' );
		}
	}
	
	return Ok;
}
//Actions du formulaire détaillé
function frm_det_submit(){
	boite_close_all();
	Ok = true;
	var form = this;
	if(form){
		razAlerteAvance(form);//masquage des alertes dejà présentes
		cleanForm(form);
		if(form.flashInactif){
			form.flashInactif.value=!flashActif;
		}
		//récupération des champs du formulaire
		var champActivite = form.activite;
		var champNom = form.nom;
		var champAdresse = form.adresse;
		var champLocalite = form.localite;
		var champDepartement = form.depreg;
		var champProxi = form.proximite;
		//initalisation des alertes
		var alerteLocaliteDepAccueil =  getElementsByClassName(form, "div", "al_departement")[0];
		var alerteLocaliteDep =  getElementsByClassName(form, "div", "al_departement_liste")[0];
		var alerteActivite = champActivite.parentNode.parentNode;
		var alertGlobal = getElementsByClassName(form, "div", "al_general_liste")[0];
		var alertGlobalDet = getElementsByClassName(form, "div", "al_general_liste")[1];
		var alertGlobalAccueil = getElementsByClassName(form, "div", "al_general")[0];
		if (trim(champActivite.value)=="" && trim(champNom.value)=="" && (trim(champAdresse.value)=="" && trim(champLocalite.value)=="" && trim(champDepartement.value)=="")){
			//tous les champs sont vides
			if(alertGlobal){
				alertGlobal.style.display = 'block';
			}
			if(alertGlobalAccueil){
				alertGlobalAccueil.style.display = 'block';
			}
			Ok = false;
		}else if((trim(champActivite.value)!="" || trim(champNom.value)!="") && trim(champAdresse.value)=="" && trim(champLocalite.value)=="" && trim(champDepartement.value)==""){
			//les champs du où sont vides : erreur où
			if(alerteLocaliteDepAccueil){
				alerteLocaliteDepAccueil.style.display = 'block';
			}else if(alerteLocaliteDep){
				alerteLocaliteDep.style.display = 'block';
			}
			Ok = false;
		}else if(trim(champActivite.value)=="" && trim(champNom.value)=="" && trim(champAdresse.value)=="" && (trim(champLocalite.value)!="" || trim(champDepartement.value)!="")){
			//les champs du quoi ne sont pas renseignés et l'adresse est vide : erreur quoiqui
			if(alerteActivite){
				masqueAfficherAlert(alerteActivite,'block');
			}
			Ok = false;
		}else if(trim(champActivite.value)=="" && trim(champNom.value)=="" && trim(champLocalite.value)==""){
			//les champs du quoi, où et localité ne sont pas renseignés
			if(alertGlobal){
				alertGlobal.style.display = 'block';
			}
			if(alertGlobalDet){
				alertGlobalDet.style.display = 'block';
			}
			if(alertGlobalAccueil){
				alertGlobalAccueil.style.display = 'block';
			}
			Ok = false;
		}
		// stats aladin
		if ((trim(champActivite.value) != "" || trim(champNom.value) != "" ) && 
				trim(champAdresse.value) == "" && 
				trim(champLocalite.value) == "" &&
				trim(champDepartement.value) == "" ) {
			var oDate = new Date();
			var sUrl = DocumentBase() + "genstat.do?typeService=YES&typeRequete=RECHERCHE_CINQ_CHAMPS&typeAction=RECHERCHE&typeReponse=ALERT_OU&requeteActivite=" + champActivite.value + "&requeteNom=" + champNom.value + "&_pjTs="+oDate.getTime();
			_pjStatWriteImg( sUrl,false,'pjStatAlertOuImg' );
		}
	}
	return Ok;
}
//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;
		}
	}
}
bINITFORMS = false;
function PJ_init_forms(iScan){
    if(bINITFORMS == false){
		var maxScan = 5;
		var lvScan = (typeof(iScan) != 'undefined' ) ? iScan : 0;
		PJ_init_boites();
		Hlps = getElementsByClassName(document, "a", "N4_form_aide");
		for(i=0; i<Hlps.length; i++){
			if( typeof(Hlps[i].onclick) != 'function' ){
				var oDate = new Date();
				Hlps[i].id = "a" + Math.floor( Math.random() * i + oDate.getTime() ) + 1;
				addEvent(Hlps[i], "click", hlp_click, true);
				Hlps[i].onclick = _false;
			}
		}
		Txts = getElementsByClassName(document, "input", "N4_form_txt");
		for(i=0; i<Txts.length; i++){
			if( typeof(Txts[i].onkeyup) != 'function' ){
				addEvent(Txts[i], "keyup", txt_keyup, true);
			}
		}
		FrmsExp = getElementsByClassName(document, "form", "N2_formulaire_express");
		if(FrmsExp.length > 0){
			for(i=0; i<FrmsExp.length; i++){
				if( typeof(FrmsExp[i].onsubmit) != 'function' ){
					FrmsExp[i].onsubmit = frm_exp_submit;
				}
			}
		}
		FrmsDet = getElementsByClassName(document, "form", "N2_formulaire_detaille");
		if(FrmsDet.length > 0){
			for(i=0; i<FrmsDet.length; i++){
				if( typeof(FrmsDet[i].onsubmit) != 'function' ){
					if(FrmsDet[i].name == 'rechercherAvanceForm'){
						FrmsDet[i].onsubmit = frm_det_submit;
					}else if(FrmsDet[i].name == 'formqui'){ 
						FrmsDet[i].onsubmit = frm_detAJ_submit;
					}else if(FrmsDet[i].id == 'formAvanceHaut'){ 
						FrmsDet[i].onsubmit = frm_det_submit;
					}
				}
			}
		}
		objFormCarte = document.getElementById("formCarte");
		if( objFormCarte && typeof(objFormCarte.onsubmit) != 'function' ){
			objFormCarte.onsubmit = frm_carte_submit;
		}
		objbtnFormCarte = document.getElementById("buttonFormCarte");
		if( objbtnFormCarte && typeof(objbtnFormCarte.onclick) != 'function' ){
			objbtnFormCarte.onclick = frm_carte_submit;
		}
		if((FrmsExp.length <= 0) && (FrmsDet.length <= 0) && (lvScan < maxScan)){
			window.setTimeout(function(){
				lvScan++;
				PJ_init_forms(lvScan);
			}, 200);
		}else{
	        bINITFORMS = true;
		}
		Ttsl = getElementsByClassName(document, "input", "boite_toutsel");
		for(i=0; i<Ttsl.length; i++){
			if( typeof(Ttsl[i].onclick) != 'function' ){				Ttsl[i].onclick = amb_toutsel_click;
			}
		}
	}
}
/*DONNE LE FOCUS A UN CHAMP*/
//Variable globale d'enregistrement de l'id du champ texte recevant le focus
var vgInputFocused = "";
//Initialisation du focus sur le champ par défaut
function focusToInput(sInputId, iScan){
	saveFocusedInputId();
	
	var maxScan = 10;//nbre max de recherche
	var lvScan = (typeof(iScan) != 'undefined') ? iScan : 0;//compteur de recherche
	var bOdjLoaded = false;
	_sInputId = (vgInputFocused == "") ? sInputId : vgInputFocused;
	var oInput = document.getElementById(_sInputId);
	
	if(oInput){
		oInput.focus();
		oInput.value = oInput.value;
		bOdjLoaded = true;
		return;
	}else{
		if(!bOdjLoaded && (lvScan < maxScan)){
			window.setTimeout(function(){
				lvScan++;
				focusToInput(_sInputId, lvScan);
			}, 500);
		}else{
			return false;
		}
	}
}
//****
//PAGES BLANCHES
//Formulaire classique Accueil et Liste réponses
function pbFocusToInput(){
	if(document.body != null){
		if(/PB/.test(document.body.className)){
			focusToInput('nom');
			return true;
		}else{
			return false;
		}
	}else{
		window.setTimeout("pbFocusToInput()", 200);
	}
}
pbFocusToInput();
if(!pbFocusToInput()){
	if(getQueryVariable('avance') == 'true'){
		//Formulaire avancé Accueil
		focusToInput('activite');
	}else if(getQueryVariable('rechercheAvance') == 'true'){
		//Formulaire avancé Liste réponses
		focusToInput('activiteh');
	}else if(/annoncesJaunes.do/.test(document.location)){
		//Formulaire annonces jaunes
		focusToInput('quoi');
	}else if(/quiDonc.do/.test(document.location)){
		//Formulaire Qui Donc
		focusToInput('FRM_TEL');
	}else if(/voila.do/.test(document.location)){
		//Formulaire Voila
		focusToInput('voila');
	}else{//Formulaire classique PJ Accueil et Liste réponses+VED
		if(/villeendirect/.test(document.location) == false){
			focusToInput('quoiqui');
		}
	}
	//Initialisation des evts forms
	PJ_init_forms();
}
function saveFocusedInputId(){
	var oFormContainer = (document.getElementById("N1_formulaire")) ? document.getElementById("N1_formulaire") : document.getElementById("N1_form_haut");
	if(oFormContainer){
		var oForm = oFormContainer.getElementsByTagName("FORM")[0];
		if(oForm){
			var aInput = oForm.getElementsByTagName("INPUT");
			for(var i = 0; i < aInput.length; i++){
				if(aInput[i].type == "text"){
					aInput[i].onfocus = function(){
						vgInputFocused = this.id;
					}
				}
			}
		}
	}
}
/*GESTION PB LEVEE D'AMBIGUITE*/
var vgTimer = null;
var fYes = null;
var fVed = null;
var fYesDet = null;
loadingForm(0);
//Gestion du chargement des objets
function loadingForm(iScan){
	var maxScan = 10;//nbre max de recherche
	var lvScan = (typeof(iScan) != 'undefined' ) ? iScan : 0;//compteur de recherche
	var bFormLoaded = false;
	//Récupération des fomulaires concernés
	fYes = document.getElementById("formClassiqueHaut");
	fVed = document.getElementById("formulaire_express");
	fYesDet = document.getElementById("formAvanceHaut");
	if(fYes != null || fVed != null || fYesDet != null){
		bFormLoaded = true;
		window.clearTimeout(vgTimer);
		vgTimer = null;
		var champ = null;
		//récupération du champ concerné par la lévée d'ambiguité
		if(fYes || fVed){
			champ = document.getElementById("quoiqui");
		}else if(fYesDet){
			champ = document.getElementById("activite");
			if(champ == null){
				champ = document.getElementById("activiteh");
			}
		}
		//on attache la fonction isKeyPress sur l'évenement onkeypress du champ sélectionné
		champ.onkeypress = function(event){
			isKeyPress(event, this);
		}
		return;
	}else{
		//timer permettant de traiter la fonction dès que les éléments recherchés sont chargés
		window.clearTimeout(vgTimer);
		if(!bFormLoaded && (lvScan<maxScan)){
			vgTimer = window.setTimeout(function(){
				lvScan++;
				loadingForm(lvScan);
			}, 500);
		}
	}
}

//Gestion de la fermeture de la boite d'ambiguité selon la touche appuyée
function isKeyPress(evt, obj){
	var charCode = (ie) ? event.keyCode : evt.keyCode;
	//si on a appuyé sur n'importe quelle touche sauf "Enter"
	if(charCode != 13){
		//Fermeture des alertes
		var al_activite = getElementsByClassName(document, "div", "alerte al_activite");
		if(al_activite && al_activite.length>0){
			al_activite[0].style.display='none';
		}
		var alerte_bd = getElementsByClassName(document, "div", "alerte_bd");
		if(alerte_bd && alerte_bd.length>0){
			alerte_bd[0].style.display='none';
		}
		//Fermeture et RAZ de la boite d'ambiguité
		var ambiguite = document.getElementById("ambiguiteQuoi");
		if(ambiguite){
			ambiguite.innerHTML = "";
			ambiguite.style.display = "none";
		}
	}
}
/*GESTION DU FOCUS DU BI-CHAMPS SUR IE6*/
//on vérifie si on est sur IE6
if(ie && !ie7){
	var vgTimer = null;
	var tabChamps = new Array();
	var champsForm = null;
	var formYes = null;
	var formYesDet = null;
	var formPB = null;
	var formQDnum = null;
	var formQDnom = null;
	var bWebAppVed = false;
	var objInputFocused = null;
	
	formLoad(0);
	
	addEvent(window, 'load', function(){
		if(!bWebAppVed && (formYes != null || formYesDet != null || formPB != null || formQDnum != null || formQDnom != null)){
			if(objInputFocused == null){
				if (tabChamps != null && tabChamps.length>0){
					//si aucun champ n'a pris le focus avant la fin du chargement
					if(formYesDet && tabChamps[0].type == "checkbox"){
						//pour le formulaire détaillé, on donne le focus 
						//au 2ème élément du tableau si le premier est un checkbox
						tabChamps[1].focus();
					}else{
						//sinon, on sélectionne le 1er champ du tableau
						tabChamps[0].focus();
					}
				}
			}else{
				//sinon, on sélectionne le champ qui a pris le focus pdt le chargement
				objInputFocused.focus();
			}
		}
	}, false);
}
//Gestion du chargement des objets
function formLoad(iScan){
	var maxScan = 10;
	var lvScan = (typeof(iScan) != 'undefined') ? iScan : 0;
	var bFormLoaded = false;
	formYes = document.getElementById("formClassiqueHaut");
	formYesDet = document.getElementById("formAvanceHaut");
	formPB = document.getElementById("formAccueil");
	if(/aquiestcenumero.do/.test(document.location)){
		formQDnum = document.getElementById("form_numero");
	}else if(/quiportecenom.do/.test(document.location)){
		formQDnom = document.getElementById("form_nom");
	}
	if(formYes != null || formYesDet != null || formPB != null || formQDnum != null || formQDnom != null){
		bFormLoaded = true;
		if(document.body){// Est-on dans la WebApp VED ?
			bWebAppVed = (/^ved /.test(document.body.className));
		}
		window.clearTimeout(vgTimer);
		vgTimer = null;
		var t = 0;
		if(formYes){
			champsForm = formYes.getElementsByTagName("input");
		}else if(formYesDet){
			champsForm = formYesDet.getElementsByTagName("input");
		}else if(formPB){
			champsForm = formPB.getElementsByTagName("input");
		}else if(formQDnum){
			champsForm = formQDnum.getElementsByTagName("input");
		}else if(formQDnom){
			champsForm = formQDnom.getElementsByTagName("input");
		}else{
			champsForm = null;
		}
		if(champsForm != null){
			for(var i=0; i<champsForm.length; i++){
				if(champsForm[i].type == "text" || champsForm[i].type == "checkbox" || champsForm[i].type == "image"){
					attachKeydown(champsForm[i]);
					tabChamps[t] = champsForm[i];
					t++;
				}
			}
		}
		return;
	}else{
		window.clearTimeout(vgTimer);
		if(!bFormLoaded && (lvScan<maxScan)){
			vgTimer = window.setTimeout(function(){
				lvScan++;
				formLoad(lvScan);
			}, 500);
		}
	}
}
//Affectation d'un fonction sur l'évènement "KeyDown"
function attachKeydown(obj){
	obj.onkeydown = function(event){ 
		isEnterKey(event, this);
	}
}
//Gestion du passage du focus entre les champs
function isEnterKey(evt, obj){
	//récupération de l'évènement
	var charCode = (ie) ? event.keyCode : evt.keyCode;
	//si la touche pressée est la tabulation, charCode == 9
	if(charCode == 9){
		var cc=0;
		//on recherche le champ suivant celui sélectionné
		while(cc<tabChamps.length && tabChamps[cc] != obj){
			cc++;
		}
		if(cc>tabChamps.length){
			objInputFocused = null;
		}else{
			//on donne le focus au champ trouvé 
			tabChamps[cc].focus();
			//on enregistre le champ suivant dans une variable globale
			objInputFocused = tabChamps[cc+1];
		}
	}
}
/*FIN*/
//masquage des alerte sur le formulaire classique
function razAlerteClassique(form){
	//Expressions régulières
	RgxAlert = new RegExp("^alerte");
	if(form){
		if(form.quoiqui){
			masqueAfficherAlert(form.quoiqui.parentNode.parentNode, "none");
		}
		if(form.ou){
			masqueAfficherAlert(form.ou.parentNode.parentNode, "none");
		}
		var alertesGlobales = getElementsByClassName(document, "div", "al_general_liste");
		if(alertesGlobales){
			for(i = 0; i < alertesGlobales.length; i++){
				alertesGlobales[i].style.display = "none";
			}
		}
	}
}
//masquage des alertes sur un formulaire detaille
function razAlerteAvance(form){
	//Expressions régulières
	RgxAlert = new RegExp("^alerte");
	if(form){
		var oAlNom = ('undefined' != typeof(form.nom))? form.nom : false;
		if(oAlNom){
			masqueAfficherAlert(oAlNom.parentNode.parentNode, "none");
		}
		var alerteLocaliteDepAccueil = getElementsByClassName(form, "div", "al_departement");
		if(alerteLocaliteDepAccueil && alerteLocaliteDepAccueil[0]){
			alerteLocaliteDepAccueil[0].style.display="none";
		}
		var alerteLocaliteDep = getElementsByClassName(form, "div", "al_departement_liste");
		if(alerteLocaliteDep && alerteLocaliteDep[0]){
			alerteLocaliteDep[0].style.display="none";
		}
		var alerteLocaliteAccueil = getElementsByClassName(form, "div", "al_localite");
		if(alerteLocaliteAccueil && alerteLocaliteAccueil[0]){
			alerteLocaliteAccueil[0].style.display="none";
		}
		var alerteLocalite = getElementsByClassName(form, "div", "al_localite_liste");
		if(alerteLocalite && alerteLocalite[0]){
			alerteLocalite[0].style.display="none";
		}
		var alerteGlobaleAccueil = getElementsByClassName(form, "div", "al_general");
		if(alerteGlobaleAccueil && alerteGlobaleAccueil[0]){
			alerteGlobaleAccueil[0].style.display="none";
		}
		var alertesGlobales = getElementsByClassName(document, "div", "al_general_liste");
		if(alertesGlobales){
			for(i=0;i<alertesGlobales.length;i++){
				alertesGlobales[i].style.display="none";
			}
		}
	}
}
//masquage des alerte au clic sur le bouton close
//des levées d'ambiguité et/ou des aides.
addEvent(window, 'load', function(){
	var aImgs = document.getElementsByTagName("IMG");
	for(var i = 0; i < aImgs.length;i++){
		if(aImgs[i].className == "close"){
			aImgs[i].onclick = function(){
				var alertesGlobales = getElementsByClassName(document, "div", "alerte");
				if(alertesGlobales){
					for(i = 0; i < alertesGlobales.length; i++){
						alertesGlobales[i].style.display = "none";
					}
				}
			}
		}
	}
}, false);
//suppression des espaces et caractères spéciauux sur les champs des formulaires
function cleanForm(pForm){
	var tabInput = pForm.getElementsByTagName("input");
	for(var i = 0; i < tabInput.length; i++){ 
		if(tabInput[i].getAttribute("type") == "text"){
			tabInput[i].value = trim(tabInput[i].value);
		}
	}
}
//Wrap long lines for Ffox
function wrapLongDLForFirefox(){
	var allP = document.getElementsByTagName("p");
	var aBAddr = Array();
	for(var i = 0; i < allP.length; i++){
		if(allP[i].className == "N5_bloc_parution_adresse"){
			aBAddr.push(allP[i]);
		}
	}
	var cpt = 0;
	while(cpt < aBAddr.length){
		var oStg = aBAddr[cpt].getElementsByTagName("STRONG")[0];
		if(oStg){
			var sCt = oStg.innerHTML;
			if(String(sCt).length > 25){
				oStg.innerHTML = wrapLn(sCt, "-");
			}
		}
		cpt++;
	}
}
function wrapLn(sIn, sep){
	var sLgt = 30;
	var i = 1;
	var sOut = sIn;
	while(i < sOut.length){
		if((i >= sLgt) && (i%sLgt == 0)){
			var iSpr = sOut.indexOf(sep, i + 1);
			var s1 = sOut.substr(0, iSpr + 1);
			var s2 = sOut.substring(iSpr + 1);
			if(s1 != "" && s2 != ""){
				sOut = s1 + "<br/>" + s2;
			}
		}
		i++;
	}
	return sOut;
}
if(moz){window.addEventListener('load', wrapLongDLForFirefox, false);}
//****
var GCContener = "Contener";
//****
//Capture des actions pour changement de carte.
var vgActionAnnonceur = getQueryVariable("actionAnnonceur");

function getActionsCarte(){
	var oN1ActionsCarte = document.getElementById('N1_actions_carte');
	
	if(oN1ActionsCarte){
		var oToolbarContainer = oN1ActionsCarte.getElementsByTagName("UL")[0];
		var aLinks = oToolbarContainer.getElementsByTagName("A");
		var i = 0;
		var aActions = new Array("plan","actionPlan","vue","actionVueAerienne","vue_3D","actionVue3D","iti","actionItineraire","photo","actionPhoto");
		
		while(i < aLinks.length){
			//Initialisation au chargement
			var sLinkCName = aLinks[i].className;
			var j = 0;
			var bActive = false;
			while(j < aActions.length){
				if((sLinkCName.split(" ")[0] == aActions[j]) && vgActionAnnonceur == aActions[j + 1]){
					bActive = true;
					break;
				}
				j += 2;
			}
			setLienActionsCarteActif(aLinks[i], bActive);
			//Gestion du clic
			aLinks[i].onclick = function(){
				var sCName = this.className;
				if((sCName == "plan" || sCName == "vue") && (vgActionAnnonceur == "actionPlan" || vgActionAnnonceur == "actionVueAerienne")){
					vgActionAnnonceur = (sCName == "plan") ? "actionPlan" : "actionVueAerienne";
					getActionsCarte();
				}
			}
			i++
		}
	}
}
function setLienActionsCarteActif(oLink, bActive){
	if(oLink){
		var sCName = String(oLink.className);
		
		if(bActive == false){
			oLink.className = sCName.replace(" lienactif", "");
		}else{
			if(-1 == sCName.indexOf("lienactif")){
				oLink.className = sCName + " lienactif";
			}
		}
	}
}
addEvent(window, "load", getActionsCarte, false);
//****
//Checkbox "Tout sélectionner"
function amb_toutsel_click(ev){
	Obj = check_event(this);
	Ctn = Obj.parentNode;
	while(Ctn.nextSibling){
		Ctn = Ctn.nextSibling;
		if(Ctn.className == "formulaire liste_longue"){
			break;
		}
	}
	Ipt = Ctn.getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++){
		if(Ipt[i].type == "checkbox"){
			Ipt[i].checked = true;
		}
	}
	Obj.onclick = amb_toutdesel_click;
}
//Checkbox "Tout désélectionner"
function amb_toutdesel_click(ev){
	Obj = check_event(this);
	Ctn = Obj.parentNode;
	while(Ctn.nextSibling){
		Ctn = Ctn.nextSibling;
		if(Ctn.className == "formulaire liste_longue"){
			break;
		}
	}
	Ipt = Ctn.getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++){
		if(Ipt[i].type == "checkbox"){
			Ipt[i].checked = false;
		}
	}
	Obj.onclick = amb_toutsel_click;
}
function initDelFiltres(){
	var aForms = new Array("filtre_MOTS_CLES","filtre_RUBRIQUE","filtre_ARRONDISSEMENT","filtre_LOCALITE","filtre_DEPARTEMENT");
	var i = 0;
	
	while(i < aForms.length){
		var oForm = document.getElementById(aForms[i]);
		
		if(oForm){
			var aLinks = oForm.getElementsByTagName("A");
			var aStrongs = oForm.getElementsByTagName("STRONG");
			var k = 0;
			
			for(var j = 0; j < aLinks.length; j++){
				//Gestion des suppressions unique
				if("N4_comprehension_criteres" == aLinks[j].parentNode.className){
					var oLink = aLinks[j];
					oLink.id = "link_" + i + "_" + j;
					
					var bNosup = ("criteres_no" == aStrongs[j].className || "residuel" == aStrongs[j].className)? true : false;
					
					if(bNosup){k += 1;}
					aStrongs[k].id = "str_" + i + "_" + j;
					k++;
					addEvent(oLink, "mouseover", function(){changeCriteresStyle("over", this);},true);
					addEvent(oLink, "mouseout", function(){changeCriteresStyle("out", this);},true);
				}
				//Gestion du lien "Tout supprimer"
				if("N5_filtres_sel_a_suppr" == aLinks[j].className){
					addEvent(aLinks[j], "mouseover",function(){changeAllCriteresStyle("over", this);},true);
					addEvent(aLinks[j], "mouseout",function(){changeAllCriteresStyle("out", this);},true);
				}
			}
		}
		i++;
	}
}
//****
addEvent(window, "load", initDelFiltres, true);
//****
function changeAllCriteresStyle(sAction, objIn){
	if(objIn && objIn.tagName){
		var oForm = objIn.parentNode;
		while("FORM" != oForm.tagName && "BODY" != oForm.tagName){
			oForm = oForm.parentNode;
		}
		var oCont = getElementsByClassName(oForm, "p", "N4_comprehension_criteres")[0];
		if(oCont){
			var aStrongs = oCont.getElementsByTagName("STRONG");
			var i=0;
			while(i < aStrongs.length){
				if(aStrongs[i].id){
					aStrongs[i].className = ("over" == sAction)? "rub" : "";
				}
				i++;
			}
		}
	}
}
function changeCriteresStyle(sAction, objIn){
	if("undefined" != typeof(objIn)){
		if(objIn.tagName){
			var sId = String(objIn.id).replace("link_", "str_");
			var obj = document.getElementById(sId);
			if( obj ){
				obj.className = ("over" == sAction)? "rub" : "";
			}
		}
	}
}
function showHideGuide(oLink){
	if(oLink && oLink.id){
		var sBoiteId = String(oLink.id).replace("a_","boite_");
		var oBoite = document.getElementById(sBoiteId);
		if(oBoite){
			oBoite.style.display = (oBoite.style.display == 'block')? 'none' : 'block';
		}
	}
	return false;
}
//"Internal" function to return the decoded value of a cookie
function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1){
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}
//Function to return the value of the cookie specified by "name"
function GetCookie(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while(i < clen){
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg){
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) break;
	}
	
	return null;
}
function SetCookie(name,value,expires,path,domain,secure){
	document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "") +
	"; expires=Thu, 31-Dec-2050 00:00:00 GMT";
}
//****
var sFormPref = GetCookie("myFormPref");
var bControlCheck = getQueryVariable("ctrlCheck");

function initFormPref(){
	var oFormPref = document.getElementById('formPref');
	if(oFormPref){
		//Initialisation du check
		if(sFormPref == "D"){
			oFormPref.checked = true;
		}
		//Gestion du click
		oFormPref.onclick = function(){
			var bCheck = this.checked;
			if(bCheck){
				SetCookie("myFormPref", "D", null, "/", null, false);
			}else{
				SetCookie("myFormPref", "S", null, "/", null, false);
			}
		}
		//Initialisation de l'action sur le submit
		//=test si un premier choix a déjà été fait
		var oFormHaut = document.getElementById('formAvanceHaut');
		if(oFormHaut){
			var oImgSubmit = document.getElementById('imgTrouver');
			if(oImgSubmit){
				oImgSubmit.onclick = function(){
					if(GetCookie("myFormPref") == null){
						var oBteNoChoice = document.getElementById('boite_guide_formPrefNoChoice');
						oBteNoChoice.style.display = "block";
						return false;
					}
				}
				validPrefNoChoice();
			}
		}
	}
}
function validPrefNoChoice(){
	var oFormHaut = document.getElementById('formAvanceHaut');
	var oFormPref = document.getElementById('formPref');
	var oSubmit = document.getElementById('submitPrefNoChoice');
	var oRadioYes = document.getElementById('PrefNoChoiceOui');
	var oRadioNo = document.getElementById('PrefNoChoiceNon');
	if(oSubmit){
		oSubmit.onclick = function(){
			if(oRadioNo && oRadioNo.checked){
				SetCookie("myFormPref", "S", null, "/", null, false);
				frm_det_submit();
			}
			if(oRadioYes && oRadioYes.checked){
				oFormPref.checked = true;
				SetCookie("myFormPref", "D", null, "/", null, false);
				frm_det_submit();
			}
		}
	}
}

//****
function lireCookie(p_nomCookie){
	var v_arg=p_nomCookie+"=";
	var v_alen=v_arg.length;
	var v_clen=document.cookie.length;
	var i=0;
	while(i<v_clen){
		var j=i+v_alen;
		if(document.cookie.substring(i, j)==v_arg){
			return getCookieContenu(j);
		}
		i=document.cookie.indexOf(" ",i)+1;
		if(i==0) break;
	}
	return "";
}
//GESTION AMBIGUITE
function choixAmbiguiteActivite(formulaire){
	var form = document.getElementById(formulaire);
	TRubriques = form.rubriquesChoisiesAmbiguite;
	var check = false;
	for(i=0; i<TRubriques.length; i++){
		if(TRubriques[i].checked){
			check = true;
			break;
		}
	}
	if(!check){
		for(i=0; i<TRubriques.length; i++){
			TRubriques[i].checked = true;
		}
	}
	form.submit();
}
function choixAmbiguiteOu(codeLieu, libelle){
	var form = document.getElementById('formClassiqueHaut');
	if(form){
		form.choixAmbiguite.value = true;
		form.codeLieu.value = codeLieu;
		form.ou.value=remettreSpecialChars(libelle);
		form.choixMultiLoc.value = false;
		var ambiguite = document.getElementById('ambiguite');
		if(ambiguite){
			ambiguite.style.display='none';
		}
		form.submit();
	}
}
function choixAmbiguiteToutesLocalites(codesLieu){
	var form = document.getElementById('formClassiqueHaut');
	if(form){
		form.choixAmbiguite.value = true;
		form.codeLieu.value = codesLieu;
		form.choixMultiLoc.value = 'true';
		var ambiguite = document.getElementById('ambiguite');
		if(ambiguite){
			ambiguite.style.display='none';
		}
		form.submit();
	}
}
function choixAmbiguiteLocaliteMulti(codeLieu, libelle){
	var form = document.getElementById('formClassiqueHaut');
	if(form){
		form.ou.value = libelle;
		choixAmbiguiteOu(codeLieu, libelle);
	}
}
function choixAmbiguiteAvance(champOu, codeLieu, libelle, ambiguiteVoie){
	var form = document.getElementById('formAvanceHaut');
	if(form){
		form.ambiguiteVoie.value = ambiguiteVoie;
		form.codeLieu.value = codeLieu;
		form[champOu].value = remettreSpecialChars(libelle);
		form.choixMultiLoc.value = false;
		var ambiguite = document.getElementById('ambiguite');
		if(ambiguite){
			ambiguite.style.display='none';
		}
		form.submit();
	}
}
function choixAmbiguiteArrondissment(champOu, codeLieu, libelle, ambiguiteVoie){
	var form = document.getElementById('formAvanceHaut');
		if(form){
		form.adresse.value = "";
		choixAmbiguiteAvance(champOu, codeLieu, libelle, ambiguiteVoie);
	}
}
function choixAmbiguiteLocalite(champOu, codeLieu, libelle){
	var form = document.getElementById('formAvanceHaut');
	if(form){
		form.departement.value = "";
		form.choixMultiLoc.value = false;
		choixAmbiguiteAvance(champOu, codeLieu, libelle, false);
	}
}
function choixAmbiguiteDepartement(champOu, codeLieu, libelle){
	if(document.getElementById('formAvanceHaut')){
		var form = document.getElementById('formAvanceHaut');
		form.localite.value = "";
		form.choixMultiLoc.value = false;
		choixAmbiguiteAvance(champOu, codeLieu, libelle, false);
	}
}
function remettreSpecialChars(libelle){
	return libelle.replace(/#QUOTE#/g,"'");
}
function choixProximiteCentreLocalite(codeLieu, libelle){
	if(document.getElementById('formClassiqueHaut')){
		choixAmbiguiteOu(codeLieu, libelle);
	}
	var form = document.getElementById('formAvanceHaut');
	if(form){
		form.ambiguiteVoie.value = false;
		form.adresse.value = "";
		form.choixMultiLoc.value = false;
		choixAmbiguiteLocalite("localite", codeLieu, libelle);
	}
}
//Modification saisie Ou
function modifSaisieOu(){
	var formClassiqueHaut = document.getElementById('formClassiqueHaut');
	if(formClassiqueHaut){
		formClassiqueHaut.ou.value = '';
		formClassiqueHaut.ou.focus();
		formClassiqueHaut.choixMultiLoc.value = false;
		var al_ambiguite = getElementsByClassName(document, "div", "alerte al_ambiguite");
		if(al_ambiguite && al_ambiguite.length>0){
			al_ambiguite[0].style.display='none';
		}
	}
	var formAvanceHaut = document.getElementById('formAvanceHaut');
	if(formAvanceHaut){
		formAvanceHaut.adresse.value = '';
		formAvanceHaut.adresse.focus();
		formAvanceHaut.localite.value = '';
		formAvanceHaut.departement.value = '';
		formAvanceHaut.choixMultiLoc.value = false;
		var al_pb_depreg = getElementsByClassName(document, "div", "alerte al_pb_depreg");
		if(al_pb_depreg && al_pb_depreg.length>0){
			al_pb_depreg[0].style.display='none';
		}
	}
	var ambiguite = document.getElementById('ambiguite');
	ambiguite.innerHTML = "";
	ambiguite.style.display='none';
}
//Modification saisie Quoi
function modifSaisieQuoi(){
	var formClassiqueHaut = document.getElementById('formClassiqueHaut');
	if(formClassiqueHaut){
		formClassiqueHaut.quoiqui.value = '';
		formClassiqueHaut.quoiqui.focus();
	}
	var formAvanceHaut = document.getElementById('formAvanceHaut');
	if(formAvanceHaut){
		formAvanceHaut.activite.value = '';
		formAvanceHaut.activite.focus();
	}
	var al_activite = getElementsByClassName(document, "div", "alerte al_activite");
	if(al_activite && al_activite.length>0){
		al_activite[0].style.display='none';
	}
	var alerte_bd = getElementsByClassName(document, "div", "alerte_bd");
	if(alerte_bd && alerte_bd.length>0){
		alerte_bd[0].style.display='none';
	}
	var ambiguite = document.getElementById('ambiguiteQuoi');
	ambiguite.innerHTML = "";
	ambiguite.style.display='none';
}
//---
//GENERATEUR D'IDEE
var ACTION_GENERATEUR_IDEE = staticRootPath + '/genererUneIdee.do';
function genererUneIdee(){
	TRAITEMENT_RETOUR=afficheLIdee;
	appelAjax(ACTION_GENERATEUR_IDEE, "");
}
function afficheLIdee(){
	if(ajax.readyState == '4'){
		if(ajax.responseText){
			var ahrefGenerateur = document.getElementById('generateurIdee');
			//suppression des noeuds fils existants
			if(ahrefGenerateur){
				ahrefGenerateur.innerHTML="";
			}
			ahrefGenerateur.innerHTML=ajax.responseText;
		}
	}
}
