
// Actions de la boite rechercher une autre ville
function flt_choisir_ville_click(ev){
	boite_close_all();
	Obj = getElementsByClassName(document, "div", "boite choix_autre_localite")[0];
	if(Obj) {
		Obj.style.display = "block";
	}
}

// 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;
}

// Actions envoi par SMS/MMS
function env_click(ev){
	Obj = check_event(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 = check_event(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));
}

//-------------------------------------------------
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++;
	}
}
//-------------------------------------------------
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" : "";
			}
		}
	}
}
//------------------------------------------
addEvent( window, "load", initDelFiltres, true );
// -------------------------------------

//==============================================================================
// 								GESTION DE LA PREFERENCE DE RECHERCHE
// -----------------------------------------------------------------------------

// Affichage et masquage des boites d'alerte en passant en 
// param�tre l'objet lien cliqu�. D�duction de l'id de la boite 
// � afficher � partir de l'id du lien. 
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;
}
//******************************************************************************
var sFormPref = GetCookie("myFormPref"); 
var bControlCheck = getQueryVariable("ctrlCheck");

/* control serveur
if(  bControlCheck != "no" && sFormPref == "D" 
		 && /index.do/.test(document.location) 
		 && !/avance=true/.test(document.location) 
		){
	document.location = "index.do?avance=true";
}
*/
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;
			var sCookieExpire = new Date();
					sCookieExpire.setUTCFullYear(2050);
			if( bCheck ){
				SetCookie("myFormPref", "D", sCookieExpire, "/", null, false);
			}else{
				SetCookie("myFormPref", "S", sCookieExpire, "/", 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');
	var sCookieExpire = new Date();
			sCookieExpire.setUTCFullYear(2050);
			
	if( oSubmit ){
		oSubmit.onclick = function(){
			if( oRadioNo && oRadioNo.checked ){
				SetCookie("myFormPref", "S", sCookieExpire, "/", null, false);
				frm_det_submit();
			}
			if( oRadioYes && oRadioYes.checked ){
				oFormPref.checked = true;
				SetCookie("myFormPref", "D", sCookieExpire, "/", null, false);
				frm_det_submit();
			}
		} 
	}
}

//---------------------------------------------
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} 
	else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} 
	else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

/**
 * 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();
    }
}
