function oninit1(){
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE",window.setChmpCommuneAutoCompleter);
}

function lanceRecherche(){
  if(document.getElementById('inpt_deb').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
        });
    }
}
