

/*-----------------------------------------------------------------*/
// FONCTIONS AFFCIHAGE MOTEUR DE RECHERCHE
/*-----------------------------*/

function sh_affPlusDeCrit(ahref){
	obj = document.getElementById('sh_critSupp');
	if(obj.style.display == 'none'){
		obj.style.display = 'block';
		$('sh_rech_rechBRDbott').style.display = '';
		$('sh_rech_rechBRDright').style.display = '';
		ahref.className = 'sh_moins_crit';
		ahref.innerHTML = 'Afficher moins de critères';
		new Effect.ScrollTo('sh_bloc_idTOP', {duration:2});
		//cachage des img transparente des bloc partenaire gestion de m*** par OAs
		/*$('part_1').style.display = 'none';
		$('part_2').style.display = 'none';*/
	}

	else{
		obj.style.display = 'none';
		$('sh_rech_rechBRDbott').style.display = 'none';
		$('sh_rech_rechBRDright').style.display = 'none';
		ahref.className = 'sh_plus_crit';
		ahref.innerHTML = 'Afficher plus de critères';
		//decachage des img transparente des bloc partenaire gestion de m*** par OAs
		$('part_1').style.display = '';
		$('part_2').style.display = '';
	}
}



function sh_openMap(){ 
	$('sh_map').style.display ='';
}
function sh_closeMap(){
	$('sh_map').style.display ='none';
}

/*-----------------------------*/
// FIN FONCTIONS AFFCIHAGE MOTEUR DE RECHERCHE
/*-----------------------------------------------------------------*/

/*-----------------------------*/
/* GESTION AFFICHAGE MESSAGE ERREUR FORMULAIRE DE RECHERCHE  */
/*-----------------------------------------------------------------*/

var gestionSelectDynamique = function (val,crit,critOrigine){		
   	if (crit != "")
   	{
   		zindex = '';
   		if($('zindex_'+crit)) zindex = parseInt($('zindex_'+crit).value) + 1; 
   		var ajaxSelectDynamique = new Ajax.Request(
   	      urlGestionSelectDynamique,
   	      {
   	        method: 'post',
   	        asynchronous: false,
   	        parameters: {'val': val, 'crit': crit, 'critOrigine': critOrigine, 'categorie':$F('r'), 'zindex': zindex},
   	        onSuccess: afficheSelect
   	      });
   	}
}; // gestionSelectDynamique


var afficheSelect = function (xhr){

    if(xhr.responseText!=''){
   	try {
		var reponse = xhr.responseText;
		var crit = xhr.request.parameters.crit;
		var val = xhr.request.parameters.val;
		
        document.getElementById('div_'+crit).innerHTML = reponse;
		
	} catch (e) {
	}
}

}; // afficheZone

var sh_majCriteresRecherche = function (critere){
	if($(critere)) {
		var ajaxSelectDynamique = new Ajax.Request(
		urlGestionCategorieDynamique,
		{
			method: 'post',
			asynchronous: false,
			parameters: {'codeRubrique': $F(critere), 'critere': 'CRITERES_PRINCIPAUX', 'famille': $F('codeRubrique')},
			onSuccess: majCriteres
		});
		var ajaxSelectDynamique2 = new Ajax.Request(
		urlGestionCategorieDynamique,
		{
			method: 'post',
			asynchronous: false,
			parameters: {'codeRubrique': $F(critere), 'critere': 'CRITERES_SECONDAIRES', 'famille': $F('codeRubrique')},
			onSuccess: majCriteres
		});
	}
}


var majCriteres = function (xhr){

	if(xhr.responseText!=''){
		try {
			var reponse = xhr.responseText;
			var codeRubrique = xhr.request.parameters.codeRubrique;
			var critere = xhr.request.parameters.critere;

			if(critere == 'CRITERES_PRINCIPAUX') {
				document.getElementById('div_criteres_principaux').innerHTML = reponse;
			} else {
				document.getElementById('div_criteres_secondaires').innerHTML = reponse;
			}

		} catch (e) {
		}
	}

}; // majCriteres


/*-----------------------------------------------------------------*/
// FONCTIONS DEFILEMENT DES IMG ACTU
/*-----------------------------*/
var posDep = 1;


function sh_defilActu(idAct, posAct){

deplace = (posDep - posAct)*211;
	var poztop;
	
	if(posAct != posDep){
		new Effect.Move	('sh_actCol', {
			beforeStart: function(){ sh_reinitAct();},
			afterFinish: function(){ sh_reinitAct(); terminado();},
			duration: 0.8, 
			x: 0, 
			y: deplace, 
			queue: { position: 'end', scope: 'movAct', limit: 1 }
			
		});
		
		var monfocus;
		function terminado(){
			if(posAct == 1 ){
				poztop = 0;
				$('sh_actCol').style.top = poztop+'px';
			}
			if(posAct == 2 ){
				poztop = -211;
				$('sh_actCol').style.top = poztop+'px';
			}
			if(posAct == 3 ){
				poztop = -422;
				$('sh_actCol').style.top = poztop+'px';
			}
			
			/*
			if(document.getElementById('sh_txt1').focus() == true){
				$('sh_actCol').style.top = poztop+'px';
				$('sh_bg1').className = "sh_bg_actuInative";
				monfocus = 1;
				alert(monfocus);
			}
			if(document.getElementById('sh_txt2').focus() == true){
				$('sh_actCol').style.top = poztop+'px';
				$('sh_bg2').className = "sh_bg_actuInative";
				monfocus = 2;
				alert(monfocus);
			}
			if(document.getElementById('sh_txt3').focus() == true){
				$('sh_actCol').style.top = poztop+'px';
				$('sh_bg3').className = "sh_bg_actuInative";
				monfocus = 3;
				alert(monfocus);
			}
			
			$('sh_debug').value = posDep;
			$('sh_debug2').value = deplace;
			$('sh_debug3').value = $('sh_actCol').offsetTop;
			$('sh_debug4').value = monfocus;
			*/
		}
		
	}
	
	function sh_reinitAct(){
		posDep = posAct;
		$('sh_actInfo1').style.display = "none";
		$('sh_actInfo2').style.display = "none";
		$('sh_actInfo3').style.display = "none";
		$('sh_actInfo'+posAct).style.display = "";
		
		$('sh_bg1').className = "sh_bg_actuInative";
		$('sh_bg2').className = "sh_bg_actuInative";
		$('sh_bg3').className = "sh_bg_actuInative";
		
		$('sh_bg'+posAct).className = "sh_bg_actuAtive";
		
		
		
	}
	
	function getPositionTop (obj) {
		var curtop = 0;
		if (obj.offsetParent) {
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {curtop += obj.offsetTop;}
		}
		return curtop;
	}
}

/*-----------------------------*/
// FIN FONCTIONS DEFILEMENT DES IMG ACTU
/*-----------------------------------------------------------------*/






/*-----------------------------------------------------------------*/
/* EFFET LIGHTBOX OUVER TURE DE CARTE */
/*-----------------------------*/

function lightboxCustomCLOSE(lyrId){
	new Effect.Fade('overlay', { duration: overlayDuration});
	new Effect.Fade(lyrId, { duration: overlayDuration});
	showSelectBoxes();
	showFlash();
}


function lightboxCustom(lyrId){

	Object.extend(Element, {
		getWidth: function(element) {
		   	element = $(element);
		   	return element.offsetWidth; 
		},
		setWidth: function(element,w) {
		   	element = $(element);
	    	element.style.width = w +"px";
		},
		setHeight: function(element,h) {
	   		element = $(element);
	    	element.style.height = h +"px";
		},
		setTop: function(element,t) {
		   	element = $(element);
	    	element.style.top = t +"px";
		},
		setSrc: function(element,src) {
	    	element = $(element);
	    	element.src = src; 
		},
		setHref: function(element,href) {
	    	element = $(element);
	    	element.href = href; 
		},
		setInnerHTML: function(element,content) {
			element = $(element);
			element.innerHTML = content;
		}
	});


	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() {lightboxCustomCLOSE(lyrId); }
		objBody.appendChild(objOverlay);

	var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','shIDtop');
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = 0+'px';
		objBody.appendChild(objOverlay);
		
		
	hideSelectBoxes();
	hideFlash();

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);

	overlayDuration = 0.9;	// shadow fade in/out duration
	
	new Effect.Appear('overlay', { 
		afterFinish: function(){ $(lyrId).style.display = 'block';},
		duration: overlayDuration,
		from: 0.0, to: 0.8 
	});
	new Effect.ScrollTo('shIDtop', {duration:2});
	//new Effect.Appear('layr_photo', {duration: overlayDuration});

	$('sh_localisation1').value = $('sh_localisation2').value;

}


/* FONCTIONS COMPLEMENTAIRES */
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

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;
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i != flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embeds");
	for (i = 0; i != flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}
}


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}


function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i != flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embeds");
	for (i = 0; i != flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

/*-----------------------------*/
/* FIN EFFET LIGHTBOX OUVER TURE DE CARTE */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* LOCALISATION */
/*-----------------------------*/
var tab_sh_loc = new Array;

function sh_localisation(sh_loc){

	var long_shTab = tab_sh_loc.length;
	var sh_find;
	
	alert('long1 tab : ' +long_shTab);
	
	if(long_shTab > 0){
		for(i=0; i<long_shTab; i++){
			
			//si on trouve un element avec cette valeur
			//on supprime l element du tableau
			if(tab_sh_loc[i] == sh_loc){
				sh_find = 1;
				tab_sh_loc.splice(i,1);
				alert('supp');
				break;
			}
			
			//si on ne trouve d element avec cette valeur
			else{
				sh_find = 0;
			}
		}
	}
	else{
		sh_find = 0;
	}
		
	//si on n a pas trouve un element qui a deja cette valeur
	//on ajoute l element du tableau
	if(sh_find == 0){
		tab_sh_loc[long_shTab] = sh_loc;
	}
	
	
	//ecriture des resultats dans l input text
	var long_shTab2 = tab_sh_loc.length;
	alert('long2 tab : ' +long_shTab2);
	var sh_write_loc = '';
	
	for(j=0; j<long_shTab2; j++){
		alert('element du tab : '+tab_sh_loc[j]);
		sh_write_loc = sh_write_loc+" '"+tab_sh_loc[j]+"'";
	}
	
	alert('ecriture dans le champ : '+sh_write_loc);
	
	$('sh_localisation1').value = sh_write_loc;
	$('sh_localisation2').value = $('sh_localisation1').value;
	
}

/*-----------------------------*/
/* FIN LOCALISATION*/
/*-----------------------------------------------------------------*/






/*-----------------------------------------------------------------*/
/* GESTION LISTES DEROULANTES */
/*-----------------------------*/

last_open = '';
var kelgrizage;
function sh_selectopen(obj, cacheGrisLo){
	objet = document.getElementById(obj);
	rubriqueSousHome = '';
	if($('codeRubrique')) {rubriqueSousHome = $('codeRubrique').value.substring(0, 3);}
	
	if(objet.style.display == 'none'){
		objet.style.display = 'block';
		
		if(last_open != ''){
			last_open.style.display = 'none';
		}
		last_open = objet;

		if(!cacheGrisLo){
			kelgrizage = 0;
		} else {
			if($('sh_grisage1')){
				if($('sh_grisage1').style.display == 'none'){
					kelgrizage = 2;
				}
				else{
					kelgrizage = 1;
				}
				$('sh_grisage'+kelgrizage).style.display = 'none';
			}
		}
		//cachage des img transparente des bloc partenaire gestion de m*** par OAs
		if($('part_1')){
			$('part_1').style.display = 'none';
			$('part_2').style.display = 'none';
		}
	}
	else{
		objet.style.display = 'none';
		last_open = '';
		
		if(kelgrizage != 0){
			$('sh_grisage'+kelgrizage).style.display = '';
		}
		//decachage des img transparente des bloc partenaire gestion de m*** par OAs
		if($('part_1') && $('sh_critSupp').style.display == 'none'){
			$('part_1').style.display = '';
			$('part_2').style.display = '';
		}
	}	
	
}


function sh_selectli(obj, critereName, valeur){
	// Mise à jour du champ avec la valeur saisie
	inputCritereName = document.getElementById(critereName);
	if(inputCritereName) inputCritereName.value = valeur;
	// Mise à jour graphique de la sélection
	objet = obj.parentNode.parentNode.parentNode.parentNode;
	objet.style.display = 'none';
	objet.parentNode.getElementsByTagName('strong')[0].innerHTML = obj.innerHTML;
	
	if(kelgrizage != 0 && $('sh_grisage'+kelgrizage)){
		$('sh_grisage'+kelgrizage).style.display = '';
	}
	kelgrizage = 0;
	last_open = '';

	//decachage des img transparente des bloc partenaire gestion de m*** par OAs
	if($('part_1') && $('sh_critSupp').style.display == 'none'){
		$('part_1').style.display = '';
		$('part_2').style.display = '';
	}
		
	if(critereName == 'r') {
		if($('div_criteres_principaux')) {
			document.getElementById('div_criteres_principaux').innerHTML = '';
		}
		if($('div_criteres_secondaires')) {
			document.getElementById('div_criteres_secondaires').innerHTML = '';
		}
	}
		
}


/*-----------------------------*/
/* GESTION LISTES DEROULANTES */
/*-----------------------------------------------------------------*/







/*-----------------------------------------------------------------*/
/* GESTION AFFICHAGE MESSAGE ERREUR FORMULAIRE DE RECHERCHE */
/*-----------------------------*/
function verificationMoteurRecherche(){
	
	Validation.add('validate-our-annee', 'Ann?e incorrecte', function (v) {
			return Validation.get('IsEmpty').test(v) ||  /^[0-9]{4}$/.test(v);
		});
	
	Validation.add('validate-our-number-positive', 'Nombre n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && !(v<0));
		});
	
	Validation.add('validate-our-integer-positive', 'Nombre non entier ou n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && !/[^\d]/.test(v) && !(v<0));
		});
	
	Validation.add('validate-our-float-positive', 'Nombre non d?cimal ou n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && /\d+(\.\d+)?/.test(v) && !(v<0));
		});
	
	$('sh_ErrMess').style.display = 'none';
	
	var anneeMinOK, anneeMaxOK, surfaceMinOK, surfaceMaxOK;
	var localisations, nbrLocalisationsIncorrectes, localisationsIncorrectes;
	var nbrLocalisationsVilleOuCP;
	var elargissementCoche;
	// init des variables	
	recapErr = "";
	isOK = true;

	// --------------
/*	if ($('px1') && $F('px1') != '' && !Validation.get('validate-our-integer-positive').test($F('px1')) ) {
		display = '';
		if($('sh_rech_px1')) $('sh_rech_px1').style.border = '1px solid #D10019';
		isOK = false;
	} else {
		display = 'none';
		if($('sh_rech_px1')) $('sh_rech_px1').style.border = '1px solid #C0C6CC';
	}	
	$('erreur_prixIncorrect').style.display = display;
*/
	// --------------

	if ($('a0') && $('a1'))
	{
		anneeMinOK = Validation.get('validate-our-annee').test($F('a0'));
		anneeMaxOK = Validation.get('validate-our-annee').test($F('a1'));
		if (!anneeMinOK)
		{
			display = '';
//			$('sh_rech_a0').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_a0').style.border = '1px solid #C0C6CC';
		}
		$('erreur_anneeMinIncorrecte').style.display = display;
		
		if (!anneeMaxOK)
		{
			display = '';
//			$('sh_rech_a1').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_a1').style.border = '1px solid #C0C6CC';
		}
		$('erreur_anneeMaxIncorrecte').style.display = display;

		if (anneeMaxOK && !$F('a1').empty())
		{
			if (parseInt($F('a1'), 10) > new Date().getFullYear())
			{
				display = '';
//				$('sh_rech_a1').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
//				$('sh_rech_a1').style.border = '1px solid #C0C6CC';
			}
			$('erreur_anneeMaxPlusGrandeAnneeCourante').style.display = display;
		}
		if (anneeMinOK && anneeMaxOK && !$F('a0').empty() && !$F('a1').empty())
		{
			if (parseInt($F('a1'), 10) < parseInt($F('a0'), 10))
			{
				display = '';
//				$('sh_rech_a0').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
//				$('sh_rech_a0').style.border = '1px solid #C0C6CC';
			}
			$('erreur_anneeMaxPlusPetiteAnneeMin').style.display = display;
		}
	}	
	// --------------
	if ($('km1'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('km1')))
		{
			display = '';
			$('sh_rech_km1').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_km1').style.border = '1px solid #C0C6CC';
		}
		$('erreur_kilometrageIncorrect').style.display = display;
	}
	// --------------

	// --------------
	if ($('heu'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('heu')))
		{
			display = '';
			$('sh_rech_heu').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_heu').style.border = '1px solid #C0C6CC';
		}
		$('erreur_nombreHeureIncorrect').style.display = display;
	}
	// --------------
	
	if ($('nc0'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('nc0')))
		{
			display = '';
//			$('sh_rech_nc').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_nc').style.border = '1px solid #C0C6CC';
		}
		$('erreur_nombreCouchagesIncorrect').style.display = display;
	}
	// --------------
	
	if ($('lg'))
	{
		if (!Validation.get('validate-our-float-positive').test($F('lg')))
		{
			display = '';
			$('sh_rech_lg').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_lg').style.border = '1px solid #C0C6CC';
		}
		$('erreur_longueurIncorrect').style.display = display;
	}	
	// --------------
//	if ($('lo') && $('sh_grisage2').style.display == 'none')
	if ($('lo'))
	{
		localisations = $F('lo').split(',');

		if (localisations.length > 8)
		{
			display = '';
			$('sh_rech_lo').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_lo').style.border = '1px solid #C0C6CC';
		}
		$('erreur_pasPlus8Localisations2').style.display = display;
		$('erreur_localisationsSepareesVirgules').style.display = display;
	
		nbrLocalisationsIncorrectes = 0;
		nbrLocalisationsVilleOuCP = 0;
		localisationsIncorrectes = [];
		
		var flagBypassPrecision = true;

		localisations.each(function (localisation)
			{
				localisation = localisation.strip();
				if (/\d/.test(localisation))
				{
					if (! /^(_?\d{5})$/.test(localisation) &&
						! /^(\d{2})$/.test(localisation))
					{
						nbrLocalisationsIncorrectes++;
						localisationsIncorrectes.push(localisation);
					}
				}
				else
				{
					nbrLocalisationsVilleOuCP++;
					if(localisation.length != 0){
						flagBypassPrecision = false;
					}
				}
			});
	
		$('erreur_localisationIncorrecte').style.display = 'none';
		$('erreur_localisationsIncorrectes').style.display = 'none';
		$('erreur_localisationsSepareesVirgules').style.display = 'none';
		$('sh_rech_lo').style.border = '1px solid #C0C6CC';
		if (nbrLocalisationsIncorrectes)
		{
			if (nbrLocalisationsIncorrectes == 1)
			{
				$('erreur_localisationIncorrecte').style.display = '';
			}
			else
			{
				$('erreur_localisationsIncorrectes').style.display = '';
			}
			$('erreur_localisationsSepareesVirgules').style.display = '';
			$('sh_rech_lo').style.border = '1px solid #D10019';
			isOK = false;
			// fin modif messerr				
		} 

		if (localisations.length > 1 )
		{
			elargissementCoche = $F('distance1') || $F('distance2') || $F('distance3');
			if (elargissementCoche)
			{
				display = '';
				$('sh_rech_lo').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
				$('sh_rech_lo').style.border = '1px solid #C0C6CC';
			}
			$('erreur_elargissementSeulementPourUneLocalisation2').style.display = display;
		}
		
		//Si aucune localisation nécessitant la précision localisation n'a été saisie, on passe directement à la liste
		//Seulement pour la France
		//Mantis 450 : recherche.js est aussi utilisé lors de la création d'alerte, 
		// il faut donc faire ce test que si on fait un recherche d'annonces
/*
		if($('recherche')){
			if (isOK === true && flagBypassPrecision === true && $('pa').value == 'FR') {
				$('recherche').action = urlListeAnnonce;
			}
		}
*/		
	}
	if(!isOK){
		$('sh_ErrMess').style.display = '';
	}

	return isOK;

}

function verificationMoteurRechercheSinequa(){
	
	Validation.add('validate-our-annee', 'Ann?e incorrecte', function (v) {
			return Validation.get('IsEmpty').test(v) ||  /^[0-9]{4}$/.test(v);
		});
	
	Validation.add('validate-our-number-positive', 'Nombre n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && !(v<0));
		});
	
	Validation.add('validate-our-integer-positive', 'Nombre non entier ou n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && !/[^\d]/.test(v) && !(v<0));
		});
	
	Validation.add('validate-our-float-positive', 'Nombre non d?cimal ou n?gatif', function (v) {
			return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v) && /\d+(\.\d+)?/.test(v) && !(v<0));
		});
	
	$('sh_ErrMess').style.display = 'none';
	
	var anneeMinOK, anneeMaxOK, surfaceMinOK, surfaceMaxOK;
	var localisations, nbrLocalisationsIncorrectes, localisationsIncorrectes;
	var nbrLocalisationsVilleOuCP;
	var elargissementCoche;
	// init des variables	
	recapErr = "";
	isOK = true;

	// --------------
/*	if ($('px1') && $F('px1') != '' && !Validation.get('validate-our-integer-positive').test($F('px1')) ) {
		display = '';
		if($('sh_rech_px1')) $('sh_rech_px1').style.border = '1px solid #D10019';
		isOK = false;
	} else {
		display = 'none';
		if($('sh_rech_px1')) $('sh_rech_px1').style.border = '1px solid #C0C6CC';
	}	
	$('erreur_prixIncorrect').style.display = display;
*/
	// --------------

	if ($('a0') && $('a1'))
	{
		anneeMinOK = anneeMaxOK = true;

		if ($F('a0') != '+10ans') {
			anneeMinOK = Validation.get('validate-our-annee').test($F('a0'));
		}
		if ($F('a1') != '+10ans') {
			anneeMaxOK = Validation.get('validate-our-annee').test($F('a1'));
		}
		if (!anneeMinOK)
		{
			display = '';
//			$('sh_rech_a0').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_a0').style.border = '1px solid #C0C6CC';
		}
		$('erreur_anneeMinIncorrecte').style.display = display;
		
		if (!anneeMaxOK)
		{
			display = '';
//			$('sh_rech_a1').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_a1').style.border = '1px solid #C0C6CC';
		}
		$('erreur_anneeMaxIncorrecte').style.display = display;

		if (anneeMaxOK && !$F('a1').empty())
		{
			if (parseInt($F('a1'), 10) > new Date().getFullYear())
			{
				display = '';
//				$('sh_rech_a1').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
//				$('sh_rech_a1').style.border = '1px solid #C0C6CC';
			}
			$('erreur_anneeMaxPlusGrandeAnneeCourante').style.display = display;
		}
		if (anneeMinOK && anneeMaxOK && !$F('a0').empty() && !$F('a1').empty())
		{
			if (parseInt($F('a1'), 10) < parseInt($F('a0'), 10))
			{
				display = '';
//				$('sh_rech_a0').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
//				$('sh_rech_a0').style.border = '1px solid #C0C6CC';
			}
			$('erreur_anneeMaxPlusPetiteAnneeMin').style.display = display;
		}
	}	
	// --------------
	if ($('km1'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('km1')))
		{
			display = '';
			$('sh_rech_km1').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_km1').style.border = '1px solid #C0C6CC';
		}
		$('erreur_kilometrageIncorrect').style.display = display;
	}
	// --------------

	// --------------
	if ($('heu'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('heu')))
		{
			display = '';
			$('sh_rech_heu').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_heu').style.border = '1px solid #C0C6CC';
		}
		$('erreur_nombreHeureIncorrect').style.display = display;
	}
	// --------------
	
	if ($('nc0'))
	{
		if (!Validation.get('validate-our-integer-positive').test($F('nc0')))
		{
			display = '';
//			$('sh_rech_nc').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
//			$('sh_rech_nc').style.border = '1px solid #C0C6CC';
		}
		$('erreur_nombreCouchagesIncorrect').style.display = display;
	}
	// --------------
	
	if ($('lg'))
	{
		if (!Validation.get('validate-our-float-positive').test($F('lg')))
		{
			display = '';
			$('sh_rech_lg').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_lg').style.border = '1px solid #C0C6CC';
		}
		$('erreur_longueurIncorrect').style.display = display;
	}	
	// --------------
//	if ($('lo') && $('sh_grisage2').style.display == 'none')
	if ($('lo'))
	{
		localisations = $F('lo').split(',');

		if (localisations.length > 8)
		{
			display = '';
			$('sh_rech_lo').style.border = '1px solid #D10019';
			isOK = false;
		} else {
			display = 'none';
			$('sh_rech_lo').style.border = '1px solid #C0C6CC';
		}
		$('erreur_pasPlus8Localisations2').style.display = display;
		$('erreur_localisationsSepareesVirgules').style.display = display;
	
		nbrLocalisationsIncorrectes = 0;
		nbrLocalisationsVilleOuCP = 0;
		localisationsIncorrectes = [];
		
		var flagBypassPrecision = true;

		localisations.each(function (localisation)
			{
				localisation = localisation.strip();
				if (/\d/.test(localisation))
				{
					if (! /^(_?\d{5})$/.test(localisation) &&
						! /^(\d{2})$/.test(localisation))
					{
						nbrLocalisationsIncorrectes++;
						localisationsIncorrectes.push(localisation);
					}
				}
				else
				{
					nbrLocalisationsVilleOuCP++;
					if(localisation.length != 0){
						flagBypassPrecision = false;
					}
				}
			});
	
		$('erreur_localisationIncorrecte').style.display = 'none';
		$('erreur_localisationsIncorrectes').style.display = 'none';
		$('erreur_localisationsSepareesVirgules').style.display = 'none';
		$('sh_rech_lo').style.border = '1px solid #C0C6CC';
		if (nbrLocalisationsIncorrectes)
		{
			if (nbrLocalisationsIncorrectes == 1)
			{
				$('erreur_localisationIncorrecte').style.display = '';
			}
			else
			{
				$('erreur_localisationsIncorrectes').style.display = '';
			}
			$('erreur_localisationsSepareesVirgules').style.display = '';
			$('sh_rech_lo').style.border = '1px solid #D10019';
			isOK = false;
			// fin modif messerr				
		} 

		if (localisations.length > 1 )
		{
			elargissementCoche = $F('distance1') || $F('distance2') || $F('distance3');
			if (elargissementCoche)
			{
				display = '';
				$('sh_rech_lo').style.border = '1px solid #D10019';
				isOK = false;
			} else {
				display = 'none';
				$('sh_rech_lo').style.border = '1px solid #C0C6CC';
			}
			$('erreur_elargissementSeulementPourUneLocalisation2').style.display = display;
		}
		
		//Si aucune localisation nécessitant la précision localisation n'a été saisie, on passe directement à la liste
		//Seulement pour la France
		//Mantis 450 : recherche.js est aussi utilisé lors de la création d'alerte, 
		// il faut donc faire ce test que si on fait un recherche d'annonces
/*
		if($('recherche')){
			if (isOK === true && flagBypassPrecision === true && $('pa').value == 'FR') {
				$('recherche').action = urlListeAnnonce;
			}
		}
*/		
	}
	if(!isOK){
		$('sh_ErrMess').style.display = '';
	}

	return isOK;

}



function sh_grisageFct(sh_gris){

	if(sh_gris == 2){
		$('sh_grisage1').style.display = '';
		$('sh_grisage2').style.display = 'none';
		$('sh_villeCHK').checked = true;
		$('uselo').value = 1;		
	}
	else{
		$('sh_grisage2').style.display = '';
		$('sh_grisage1').style.display = 'none';
		$('sh_villeCHK').checked = false;
		$('uselo').value = 0;		
	}

}


/*-----------------------------*/
/* GESTION DES BOX DE LOCALISATION  */
/*-----------------------------------------------------------------*/
function checkDistance(obj)
{
	if(obj.checked == true)
	{
		for(i=1;i<=4;i++)
		{
			document.getElementById('distance'+i).checked = false;
		}
		obj.checked = true;
	}
	else
	{
		obj.checked = false;
	}
}





