


var select_dept = new Request.JSON({
	  url : "../outils/js/t_departement_public.php",
	  method : "post",
	  onSuccess: function(reponseJSON) {
		$('recherche_departement').empty();
		$('recherche_ville').removeClass("recherche_ville_on");
		$('recherche_ville').addClass("recherche_ville_off");
		var option1 = new Element('option',{
			"html": "Selectionner un département",
			"selected" : "selected",
			"value" : ""
		});
		$('recherche_departement').adopt(option1);
		var html = "";
		reponseJSON.each(function(elem){
	  		html = new Element('option',{
				'html':elem['code']+" - "+elem['nom'],
				'value':elem['id']
			});
	  		$('recherche_departement').adopt(html);
	  	});
	  }
});


var select_ville_recherche = new Request.JSON({
	  url : "../outils/js/t_ville_public.php",
	  method : "post",
	  onSuccess: function(reponseJSON) {
		$('recherche_ville').empty();
		$('recherche_ville').removeClass("recherche_ville_off");
		$('recherche_ville').addClass("recherche_ville_on");
		var option1 = new Element('option',{
			"html": "Selectionner une ville",
			"selected" : "selected",
			"value" : ""
		});
		$('recherche_ville').adopt(option1);
		var html = "";
		reponseJSON.each(function(elem){
	  		html = new Element('option',{
				'html':elem['nom']+" ("+elem['cp']+")",
				'value':elem['id']
			});
	  		$('recherche_ville').adopt(html);
	  	});
	  }
});


function maxlength(text,length) {
	if(text.value.length>length) 
		text.value=text.value.substr(0,length); 
} 

window.addEvent('domready', function() {
	$('rechercheRegion').addEvent('change', function(){
		nb_camping.send($('recherche_avancee'));
		select_dept.send("id="+this.value);
	});
	$('recherche_departement').addEvent('change', function(){
		nb_camping.send($('recherche_avancee'));
		select_ville_recherche.send("id="+this.value);
	});
	$('recherche_ville').addEvent('change', function(){
		nb_camping.send($('recherche_avancee'));
	});
});

var nb_camping = new Request({
	  url : "http://campons.eu/outils/js/t_nb_camping.php",
	  method : "post",
	  onSuccess: function(reponse) {
		$('nb_camping_trouve').innerHTML = reponse+" campings trouvés";
	  }
});



window.addEvent('domready', function() {
	$$('.liensExterieur').addEvent('click',function() {
		window.open(this.href);
		return false;
	});
});
