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));
});


function verif_immoneuf_carte(){
	var bln = true; 
	var formu =  document.getElementById('rechercheautre');
	if (formu['lo'].value != '')
		{
			bln = localisation(formu);
		}
	if (formu['px1'].value != ''){
		if (!Validation.get('validate-our-integer-positive').test(formu['px1'].value)){
			$('erreur_entier_px1').show();
			bln =false;
		}else{
			$('erreur_entier_px1').hide();
		}
	}
	return bln;
}

function verif_immoneuf_investir(){
	var bln = true; 
	var formu =  document.getElementById('rechercheinvestir');
	if (formu['lo'].value != '')
		{
			bln = localisation(formu);
		}
	if (formu['px1'].value != ''){
		if (!Validation.get('validate-our-integer-positive').test(formu['px1'].value)){
			$('erreur_entier_px1').show();
			bln =false;
		}else{
			$('erreur_entier_px1').hide();
		}
	}
	return bln;
}

function verif_immoneuf(detpar){
	//alert('test');
	if(detpar == "enter"){
		//alert('touche enter');
	}
	var bln = true; 
	var form = document.getElementById('recherche');
	var pays = form['pa'].value;
	//alert('localisation : '+form['lo'].value);
	if (form['lo'].value != '')
	{
		//alert('localisation OK');
		$('erreur_localisationObligatoire').hide();
		bln = localisation(form);
		localisations = form['lo'].value.split(',');
		if ((localisations.length > 1) && (pays == 'FR') )
		{	
			elargissementCoche = form['distance1'].checked || form['distance2'].checked || form['distance3'].checked;
			if (elargissementCoche != false)
			{
				$('erreur_elargissementSeulementPourUneLocalisation').show();
				bln = false;
			}else $('erreur_elargissementSeulementPourUneLocalisation').hide();
		}else
		{
			$('erreur_elargissementSeulementPourUneLocalisation').hide();
		}
		//pas de recherche ?largie si aucune localisation renseign?e ou si c'est un d?partement qui est renseign?
		elargissementCoche = form['distance1'].checked || form['distance2'].checked || form['distance3'].checked;
		if(form['lo'].value == null || form['lo'].value == '' || ((/^(\d{2})$/.test(form['lo'].value.strip())) && elargissementCoche != false && pays == 'FR') ){
			$('erreur_elargissementSeulementSiLocalisation').show();
			bln = false;
		}
		else
		{ 
			$('erreur_elargissementSeulementSiLocalisation').hide();
		}
	}
	else
	{
		//alert('localisation PAS OK');
		if (pays == 'FR'){
			$('erreur_localisationObligatoire').show();
			bln = false;
			//alert('localisation PAS OK2');
			
		}else
		{
			//alert('localisation PAS OK3');
			$('erreur_localisationObligatoire').hide();
		}
	}
	
	if (form['px1'].value != ''){
		if (!Validation.get('validate-our-integer-positive').test(form['px1'].value)){
			$('erreur_entier_px1').show();
			bln =false;
		}else{
			$('erreur_entier_px1').hide();
		}
	}
	
	//alert('bln : '+bln);
	if(bln == true){
			//alert('valdation');
			//document.forms.recherche.action='{literal}{copixurl dest="defaultimmoneuffo|localisation|precisionLocalisation" idChaine=9}?{/literal}';
			//sur la home, on a besoin de valider rechercheautre
			if(document.forms.rechercheautre){
				return document.forms.rechercheautre.submit();
			}
			else{ //mais sur la liste on a besoin de valider recherche
				return document.forms.recherche.submit();
			}
			
	}
	else{
		//alert('PAS valdition');
		return false;
	}
	

}

function localisation(form){

var bln = true; 
localisations = form['lo'].value.split(',');
			if (localisations.length > 8)
			{
				$('erreur_pasPlus8Localisations').show();
				$('erreur_localisationsSepareesVirgules').show();
				bln = false;
			}else {
				$('erreur_pasPlus8Localisations').hide();
				$('erreur_localisationsSepareesVirgules').hide();
			}
			var localisations, nbrLocalisationsIncorrectes, localisationsIncorrectes;
			var nbrLocalisationsVilleOuCP;
			var elargissementCoche;
			var pays = form['pa'].value;
			
			nbrLocalisationsIncorrectes = 0;
			nbrLocalisationsVilleOuCP = 0;
			localisationsIncorrectes = [];
			localisations.each(function (localisation)
				{
					localisation = localisation.strip();
					if (/\d/.test(localisation))
					{
						if (! /^(_?\d{5})$/.test(localisation) &&
							! /^(\d{2})$/.test(localisation))
						{
							nbrLocalisationsIncorrectes++;
							localisationsIncorrectes.push(localisation);
							bln = false;
						}
					}
					else
					{
						nbrLocalisationsVilleOuCP++;
					}
				});
			
			if (nbrLocalisationsIncorrectes)
			{
				if (nbrLocalisationsIncorrectes == 1)
				{
					$('erreur_localisationIncorrecte').show();
					$('strLocalisationIncorrecte').innerHTML = localisationsIncorrectes.join(', ');
					bln = false;
				}
				else
				{
					$('erreur_localisationsIncorrectes').show();
					$('strLocalisationsIncorrectes').innerHTML = localisationsIncorrectes.join(', ');
					bln = false;
				}
				$('erreur_localisationsSepareesVirgules').show();
				bln = false;
			}else {
				$('erreur_localisationsSepareesVirgules').hide();
				$('erreur_localisationIncorrecte').hide();
				$('erreur_localisationsIncorrectes').hide();
			}
return	bln;		
}

/*Permet de verifier que seul une distance est checké sur la recherche animmos*/
	function checkDistance(obj)
{
	//alert(obj.checked);
	if(obj.checked == true)
	{
		for(i=1;i<=3;i++)
		{
			document.getElementById('distance'+i).checked = false;
		}
		obj.checked = true;
	}
	else
	{
		obj.checked = false;
	}
}	

//Fonction modifie l'affichage lors d'un changement de pays
function choixPays2() {
	var pays = document.forms.recherche.pa.value;  
	if (pays != 'FR'){

		var element = document.getElementById('minicarte');

		element.style.display= "none";


		element = document.getElementById('minicarte');

		document.forms.recherche.lo.disabled=true;
		element.style.display= "none";

	}else{
		var element = document.getElementById('minicarte');
		element.style.display= "";
		document.forms.recherche.lo.disabled=false;
	}
}
//choixPays2
