//Actions des pictos
function picto_click(ev)	{
	boite_close_all();
	Obj = check_event(this);
	RgxInf = new RegExp(" picto");
	Pic = Obj;
	if(document.all)
		Pic = Pic.parentNode;
	while(Pic.nextSibling) {
		Pic = Pic.nextSibling;
		if(RgxInf.test(Pic.className) == true) {
			Pic.style.display = "block";
			break;
		}
		if(Pic.nodeName.toLowerCase() == "div") {
			break;
		}
	}
}

//lien "modifier votre saisie" 
function bt_modifier_ou_click(ev){
	var formulaireId = (document.getElementById('formAccueil')) ? 'formAccueil' : 'formHaut';
	var formulaireRecherche = document.getElementById(formulaireId);
	if (formulaireRecherche) {
		formulaireRecherche.ou.value = '';
		formulaireRecherche.ou.focus();
	}
	var ambiguite = document.getElementById('ambiguite');
	if(ambiguite){
		ambiguite.innerHTML = "";
		ambiguite.style.display='none';
	}
}

// Checkbox "Tout sélectionner"
function amb_toutsel_click(ev) {
	Obj = (BrowserDetect.browser == "Explorer") ? event.srcElement : this;
	Ctn = Obj.parentNode;
	while(Ctn.nextSibling) {
		Ctn = Ctn.nextSibling;
		if(Ctn.className == "formulaire") {
			break;
		}
	}
	Ipt = Ctn.getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++) {
		if(Ipt[i].type == "checkbox") {
			Ipt[i].checked = true;
		}
	}
	removeEvent(Obj, "click", amb_toutsel_click, true);
	addEvent(Obj, "click", amb_toutdesel_click, true);
}


// Checkbox "Tout désélectionner"
function amb_toutdesel_click(ev) {
	Obj = (BrowserDetect.browser == "Explorer") ? event.srcElement : this;
	Ctn = Obj.parentNode;
	while(Ctn.nextSibling) {
		Ctn = Ctn.nextSibling;
		if(Ctn.className == "formulaire") {
			break;
		}
	}
	Ipt = Ctn.getElementsByTagName("input");
	for(i=0; i<Ipt.length; i++) {
		if(Ipt[i].type == "checkbox") {
			Ipt[i].checked = false;
		}
	}
	removeEvent(Obj, "click", amb_toutdesel_click, true);
	addEvent(Obj, "click", amb_toutsel_click, true);
}


//Actions envoi par SMS/MMS
function env_click(ev)	{
	Obj = (BrowserDetect.browser == "Explorer") ? event.srcElement : this;
	PpTop  = eval((screen.height / 2) - 240);
	PpLeft = eval((screen.width / 2) - 320);
	window.open(Obj.href, 'PopUp', 'top='+PpTop+',left='+PpLeft+',toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=640,height=463');
}


function env_click2(ev)	{
	Obj = (BrowserDetect.browser == "Explorer") ? event.srcElement : this;
	PpTop  = eval((screen.height / 2) - 240);
	PpLeft = eval((screen.width / 2) - 320);
	window.open(Obj.href, 'PopUp', 'top='+PpTop+',left='+PpLeft+',toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=670,height=490');
}

function plein_ecran_click(ev) {
	window.resizeTo(screen.width, screen.height);
	window.moveTo(0, 0);
}

function reduire_ecran_click(ev) {
	window.resizeTo(680, 550);
	window.moveTo(eval((screen.height / 2) - 240), eval((screen.width / 2) - 320));
}


//Application des fonctionnalités au chargement de la page
window.onload = function() {
	// Eléments réactifs
	Btns = getElementsByClassName(document, "img", "close");
	BtnsW = getElementsByClassName(document, "img", "closewindow");
	BtnsP = getElementsByClassName(document, "img", "closepopup");
	Hlps = getElementsByClassName(document, "a", "N4_form_aide");
	Txts = getElementsByClassName(document, "input", "N4_form_txt");
	Txt = document.getElementById("quoiQui");
	Flts = getElementsByClassName(document, "a", "N3_filtres_affiner_a");
	Cmps = getElementsByClassName(document, "a", "N6_comprehension_a");
	Ttsl = getElementsByClassName(document, "input", "boite_toutsel");
	FltsVr = getElementsByClassName(document, "a", "N5_filtres_sel_a");
	FltsAc = getElementsByClassName(document, "div", "filtre_activite");
	FltsPc = getElementsByClassName(document, "a", "boite_pluscriteres");
	FrmsExp = getElementsByClassName(document, "form", "N2_formulaire_express");
	FrmAnn = document.getElementById("AnnonceurForm");
	FrmsDet = getElementsByClassName(document, "form", "N2_formulaire_detaille");
	SavoirP = getElementsByClassName(document, "a", "N4_bloc_parution_produits_savoirplus");
	PleinE = getElementsByClassName(document, "a", "pleinecran");
	ReducE = getElementsByClassName(document, "a", "reduireecran");
	BtModOu = getElementsByClassName(document, "a", "boite_modifier_ou");
	BtMod = getElementsByClassName(document, "a", "boite_modifier");
	Pictos = getElementsByClassName(document, "a", "N7_bloc_parution_communication_picto");
	
	
	// Actions sur les boutons de fermeture des boîtes de dialogue
	for(i=0; i<Btns.length; i++) {
		addEvent(Btns[i], "mouseover", btn_mouseover, true);
		addEvent(Btns[i], "mouseout", btn_mouseout, true);
		addEvent(Btns[i], "click", btn_click, true);
		Btns[i].onclick = function() {return false;}
	}
	for(i=0; i<BtnsP.length; i++) {
		addEvent(BtnsP[i], "mouseover", btnp_mouseover, true);
		addEvent(BtnsP[i], "mouseout", btnp_mouseout, true);
	}
	for(i=0; i<BtnsW.length; i++) {
		removeEvent(BtnsW[i], "click", btn_click, true);
		addEvent(BtnsW[i], "click", btn_click_w, true);
		BtnsW[i].onclick = function() {return false;}
	}
	
	// Actions des filtres
	for(i=0; i<Flts.length; i++) {
		addEvent(Flts[i], "click", flt_click, true);
		Flts[i].onclick = function() {return false;}
	}
	
	// Actions des pictos
	for(i=0; i<Pictos.length; i++) {
		addEvent(Pictos[i], "click", picto_click, true);
		Pictos[i].onclick = function() {return false;}
	}
	
	// Actions compréhension
	for(i=0; i<Cmps.length; i++) {
		addEvent(Cmps[i], "click", cmp_click, true);
		Cmps[i].onclick = function() {return false;}
	}
	
	// Actions des champs textes
	if (Txts) {
		for(i=0; i<Txts.length; i++) {
			addEvent(Txts[i], "keyup", txt_keyup, true);
		}
	}
	if (Txt) {
		addEvent(Txt, "keyup", txt_keyup, true);
	}
	
	// Actions voir les filtres
	for(i=0; i<FltsVr.length; i++) {
		addEvent(FltsVr[i], "click", flt_voir_click, true);
		FltsVr[i].onclick = function() {return false;}
	}
	
	// DHTML sur les filtre d'activités
	for(i=0; i<FltsAc.length; i++) {
		Uls = FltsAc[i].getElementsByTagName("ul");
		for(k=0; k<Uls.length; k++) {
			Lis = Uls[k].getElementsByTagName("li");
			for(j=0; j<Lis.length; j++) {
				if(j<15) {Lis[j].style.display = "list-item";}
				else 	 {Lis[j].style.display = "none";}
			}
		}
	}
	for(i=0; i<FltsPc.length; i++) {
		addEvent(FltsPc[i], "click", flt_pluscriteres_click, true);
		FltsPc[i].onclick = function() {return false;}
	}
	
	// Checkbox tout selectionné
	for(i=0; i<Ttsl.length; i++) {
		addEvent(Ttsl[i], "click", amb_toutsel_click, true);
	}
	
	// Modifiez vote saisie
	for(i=0; i<BtModOu.length; i++) {
		addEvent(BtModOu[i], "click", bt_modifier_ou_click, true);
	}
	
	// Actions des formulaires
	if(FrmsExp.length > 0) {
		for(i=0; i<FrmsExp.length; i++) {
			FrmsExp[i].onsubmit = frm_exp_submit;
		}
	}
	if(FrmsDet.length > 0) {
		for(i=0; i<FrmsDet.length; i++) {
			FrmsDet[i].onsubmit = frm_det_submit;
		}
	}
	
	if (this.document.getElementById('quoiQui') && FrmAnn) {
		FrmAnn.onsubmit = frm_exp_annonceur_submit;
	}
	
	// Actions Plein Ecran
	for(i=0; i<PleinE.length; i++) {
		addEvent(PleinE[i], "click", plein_ecran_click, true);
	}
	// Actions Reduire Ecran
	for(i=0; i<ReducE.length; i++) {
		addEvent(ReducE[i], "click", reduire_ecran_click, true);
	}
	
	// Modifiez vote saisie
	for(i=0; i<BtMod.length; i++) {
		addEvent(BtMod[i], "click", bt_modifier_click, true);
	}
	
	
	// Tri Savoir +
	if(document.getElementById("N1_tris")!=null){
		if(document.getElementById("N1_tris").getElementsByTagName("UL").length==2){
			liover = document.getElementById("N1_tris").getElementsByTagName("UL")[1].parentNode;
			liover.onmouseover = function(){
				if(this.refclass==null)
					this.refclass = this.className;
 		this.className = 'N2_tris_over';
 	}
			liover.onmouseout = function(e){
				if(document.all){
					if(this.contains(event.toElement))
						return;
				}
				else if(e){
					o = e.relatedTarget;
					while(o.tagName!="BODY"){
						if(o.parentNode==this)
							return;
						o = o.parentNode;
					}
				}
 		this.className = this.refclass;
 	}
	}
}

	// Mes liens pratiques
	if(document.getElementById("N3_onglets_mesliens")!=null){
		theobj = document.getElementById("N3_onglets_mesliens");
		theobj.onblur = function(){
			this.blur();
		}
		theprt = theobj.parentNode.parentNode;
		themenu = theprt.getElementsByTagName("DIV")[0];
		themenu.prt = theprt;
		theobj.menu = theprt.menu = themenu;
		theobj.onclick = function(){
			if(theobj.className == 'N3_onglets_mesliens_on'){
				theobj.className = 'N3_onglets_mesliens_off';
				this.menu.style.display = 'none';
			}
			else{
				theobj.className = 'N3_onglets_mesliens_on';
				this.menu.style.display = 'block';
			}
			
			return false;
		}
		theobj.onfocus = function(e){
			if(document.all){
				if(this.contains(event.toElement))
					return;
			}
			else if(e){
				if(e.relatedTarget!=null){
					o = e.relatedTarget;
					while(o.tagName!="HTML"){
						if(o.parentNode==this)
							return;
						o = o.parentNode;
					}
				}
			}
			this.menu.style.display = 'none';
			theobj.className = 'N3_onglets_mesliens_off';
		}
	}
}


//------------------------------------
//Ouverture de la pop-up appel InfosHoraire
function OpenInfosHoraires( theURL ) {
params = "toolbar=no,status=no,menubar=no,location=no,resizable=yes,width=670,height=510";
OpenPub(theURL, params);
}

//------------------------------------
//Ouverture de la pop-up appel gratuit
function OpenAppelGratuit( theURL ) {
params = "toolbar=no,status=no,menubar=no,location=no,resizable=yes,width=670,height=780";
OpenPub(theURL, params);
}

//------------------------------------
//Ouverture de la pop-up appel InfosContact
function OpenInfosContact( theURL ) {
params = "toolbar=no,status=no,menubar=no,location=no,resizable=yes,width=670,height=530";
OpenPub(theURL, params);
}


/**
 * Fonction d'ouverture de la popup mail/sms
 */
function openPopupMobileMail(pUrl) {
    var params = "toolbar=no,status=no,menubar=no,location=no,resizable=yes,width=490,height=550";
    OpenPub(pUrl, params);
}
/**
 * Fonction d'ouverture de la popup de carte de voeux
 */
function openPopupCarteVoeux(pUrl) {

    var haut = (screen.height - 730) / 2;
    var Gauche = (screen.width - 845) / 2;

    var params = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=870,height=670,top="+haut+",left="+Gauche;
    WOpen(pUrl, "winCarteVoeux", params);
}


//Afficher / masquer les coordonnees - liste reponse
function _coordonnees(o){
	o.blur();
	po = o.parentNode.parentNode;
	if(po.refc==null){
		po.refc = po.className;
		po.newc = po.refc + ' N4_bloc_parution_coordonnees_show';
	}

	if(po.className==po.refc)
		po.className = po.newc;
	else
		po.className = po.refc;

	return false;
}

/**
 * Permet d'ouvrir une url dans un nouvel onglet (ou fenetre si non supportÃ© par le navigateur)
 * 
 * @param pUrl Url Ã  ouvrir
 * @param pTarget Cible (ouvre un nouvel onglet '_blank' si pas prÃ©cisÃ©)
 * @return
 */
function newTabUrl(pUrl, pTarget, pFocus) {

    var _target = (pTarget != null) ? pTarget : "_blank";
    var external = window.open (pUrl, _target);
    if (pFocus) {
        external.focus();
    }
}
