function oninit(){
  if($("div_moteurRechercheContenu")||$("div_moteurRechercheContenuAccueil")) refreshCalDateArr();
  if($("div_moteurRechercheContenu")||$("div_moteurRechercheContenuAccueil")) if($("inpt_g").selected) tarif_gite();
  if($("inpt_refGite")||$("inpt_refGite")) initRefLocation();       
}

function clicCalendJs(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJsMenu("calendrierMoteur");
}

function afficheEffaceCalendJsMenu(nomDiv){
  if($(nomDiv).showing==true){
    Effect.BlindUp(nomDiv);       
    $(nomDiv).showing=false;
  }
  else{
    Effect.BlindDown(nomDiv);       
    $(nomDiv).showing=true;
  }
}

function rechercheAjax(){
  setListByForm($('form_moteurRecherche'));
}
                       
function setChmpPrixToReglette(reponse){

    if (!reponse)return;
    eval("var infosPrix="+reponse);
 
    /**** reglette de prix *****/
      var reglette = $('slider_prix');
      if (reglette){
      var vals=new Array();   
      var pxMini=parseInt(infosPrix.prix_mini);
      var pxMaxi=parseInt(infosPrix.prix_maxi);
      
      $("infoPrix_prixMini").innerHTML=pxMini+"&nbsp;&euro;";
      $("infoPrix_prixMaxi").innerHTML=pxMaxi+"&nbsp;&euro;";
      
      for (var i=pxMini;i<=3500;i+=25)vals.push(i);
      new Control.Slider(reglette.select('.handle'), reglette, {
          range: $R(0, 3500),
          sliderValue: [pxMini, pxMaxi],
          restricted: true,
          values: vals,
          onSlide: function(values) {
            $("infoPrix_prixMini").innerHTML=values[0];
            $("infoPrix_prixMaxi").innerHTML=values[1];
          },
          onChange: function(values) { 
			if (!window.pxmin || window.pxmin!=values[0] || window.pxmax!=values[1]){
				window.pxmin=values[0];
				window.pxmax=values[1];
				$("inpt_pxmini").value=values[0];
				$("inpt_pxmaxi").value=values[1];
				setListByForm($('form_moteurRecherche'));
			}
          }
        });
       }
}

function refreshCalDateArr(){
	if ($("calendrierMoteur")){
		if( ($("inpt_g").selected) || ($("inpt_h").selected==false)){
			setCalendrierGeneral("sla85","6","","G","calendrierMoteur",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		}
		else{
			setCalendrierGeneral("sla85","6","","H","calendrierMoteur",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		}
	}
	if(($("inpt_g").selected==false)&&($("inpt_h").selected==false)) appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE",setChmpCommuneAutoCompleter);
	if(($("inpt_g").selected==true)&&($("inpt_h").selected==false)) appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&VAL=G",setChmpCommuneAutoCompleter);
	if(($("inpt_g").selected==false)&&($("inpt_h").selected==true)) appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&VAL=H",setChmpCommuneAutoCompleter);
}

function tarif_gite(){
  if($("inpt_g").selected){
    document.getElementById('div_moteurRechercheTarif').style.display = 'block';
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",setChmpPrixToReglette);
  }
  else{
    document.getElementById('div_moteurRechercheTarif').style.display = 'none';
  }
}

function valideInscNews(){
    envoiMailByAjaxByForm('frm_newsletter','mesg_replace',false);
}

function envoiFormDeContact(){
  envoiMailByAjaxByForm("frm_contact","div_contact_form",true);
}

function afficheCarteGrande(){
  setClassForObj($("divgmap2"),"divgmap2On");
}

/*---pour afficher les villes quand on les saisie dans le moteurs de re cherche-------*/
function setCGIForLstCommune(li){
    if ( navigator.appName == 'Microsoft Internet Explorer' ){
      //var infos=li.innerText.split("(");
     var commune = li.getElementsByTagName("span")[0].getAttribute("commune_reelle");
    }
    else{
      //var infos=li.textContent.split("(");
      var commune = li.getElementsByTagName("span")[0].getAttribute("commune_reelle");
    }
    document.getElementById("inpt_ville").value=commune;
    document.getElementById("inpt_ville").onfocus=function (evt){this.value='';document.getElementById("inpt_ville_libcommune").value='';}
    document.getElementById("inpt_ville").onblur=function (evt){document.getElementById("inpt_ville_libcommune").value=this.value;}
    
    document.getElementById("inpt_ville_libcommune").value=commune;
    setListByForm($('form_moteurRecherche'));
}

function setChmpCommuneAutoCompleter(reponse){
    var suffixe;
    var jsonarray=eval(reponse);
    var infos=[];
    for (var i=0;i<jsonarray.length;i++){
        (jsonarray[i].nb>1)?suffixe="s":suffixe="";
       infos.push(jsonarray[i].commune+" ("+Math.round(jsonarray[i].nb)+" réponse"+suffixe+")<span commune_reelle=\""+jsonarray[i].communeReelle+"\" />");   }
    
    /**** champ commune ****/
    var typeahead = new Autocompleter.Local('inpt_ville', 'divLstCommunes_inpt_ville', infos, {
        frequency: 0.5,
        updateElement: setCGIForLstCommune
    });
}

function validerMoteurRecherche(){
  if( ($("inpt_dateDeb").value != "")){ 
    if($("lst_nbj").value != "") 
      setListByForm($('form_moteurRecherche'));
    else
    alertAMalibu("Veuillez saisir une durée de séjour, s'il vous plait");  
  }else{
    setListByForm($('form_moteurRecherche'));
  }
}   

/*----------fonctions qui permet de lancer la recherche d'un hébergemt grâce à sa référence avec la touche "Entrée"---------*/ 
function valideInscRefLocation(){                       
   document.location.href='/liste?LNO='+$("inpt_refGite").value;
}

function viderChampRefLocation(obj){
  obj.value="";
}

function enterRefLocation(event){
  if(!event) var event = window.event;
  if(event && event.keyCode==13) valideInscRefLocation();
}

function initRefLocation(){
  $("inpt_refGite").value = "Référence de location";
  $("form_RechercheRefLocation").onsubmit = function(evt){return false;};
  $("a_valideNumero").observe("click",function(evt){valideInscRefLocation();});
  $("inpt_refGite").onfocus = function(evt){viderChp($("inpt_refGite"));viderChampRefLocation($("inpt_refGite"));}
  $("inpt_refGite").onkeypress = function(evt){enterRefLocation(evt);};
}   

