function oninit1(){
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE",window.setChmpCommuneAutoCompleter);
    setCalendrierGeneral("gites80","1","","H","div_calendrierDateArrivee",clicCalendJsDeb,"inpt_dateDeb","","","duree","1","");
  $("img_fermeCalendArrivee").onclick=function(evt){
    afficheEffaceCalendJs("div_calendrierMoteurArrivee");
  };
  $("img_calendAcc").onclick=function(evt){
    afficheEffaceCalendJs("div_calendrierMoteurArrivee");
  };
}

function clicCalendJsDeb(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("div_calendrierMoteurArrivee");
}

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

function lanceRecherche(){
  if(document.getElementById('inpt_dateDeb').value!=''){
    if(document.getElementById('lst_nbj').value==''){
      alertAMalibu('Vous avez sélectionné une date, vous devez donc indiquer la durée de votre séjour');
    }
    else{
      document.getElementById('frm_moteur_acc').submit();
    }
  }
  else{
    document.getElementById('frm_moteur_acc').submit();
  }
}

function setCGIForLstCommune(li){
    if ( navigator.appName == 'Microsoft Internet Explorer' ){
      var infos=li.innerText.split(" (");
    }
    else{
      var infos=li.textContent.split(" (");
    }
    document.getElementById("inpt_commune").value=infos[0];
    document.getElementById("inpt_commune").onfocus=function (evt){this.value='';document.getElementById("inpt_ville_libcommune").value='';}
    document.getElementById("inpt_commune").onblur=function (evt){document.getElementById("inpt_ville_libcommune").value=this.value;}
    
    document.getElementById("inpt_ville_libcommune").value=new String(infos[0]).replace(new RegExp(" ","g"),'_');
}

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);
    }
    
    /**** champ commune ****/
    if ($("divLstCommunes_inpt_ville") && $("inpt_commune")){
        var typeahead = new Autocompleter.Local('inpt_commune', 'divLstCommunes_inpt_ville', infos, {
            frequency: 0.5,
            updateElement: setCGIForLstCommune
        });
    }
}
