function oninit(){
  if($("divMeteoMenu")) affUrlInDiv("divMeteoMenu","/config_v3/73/G.v3/STANDARDAJX2.FRANCAIS/librairie/bloc_html/meteo.php");  
  if($("div_moteurMenu")){
    $$(".inpt_type").each(function(obj){obj.observe("click",initMoteur);});
    $$(".chk_prefEnfant").each(function(obj){
      obj.observe("click",function(evt){
        setListByForm($('frmMoteurGeneral'));
      });
    });
    $$(".select_dist").each(function(obj){
      obj.observe("change",function(evt){
        setListByForm($('frmMoteurGeneral'));
      });
    });
    initMoteur();
    clickType();
    $("bt_secteurs").onclick=function(evt){affCarteSecteurs();};
    $("bt_domaines").onclick=function(evt){affCarteDomaines();};
    $("img_supprCommune").onclick=function(evt){supprCommune();};
    $$(".span_simuleListPref").each(function(obj){obj.style.display="block";});
    $("inpt_ville").onmouseover=function(evt){$("div_messageCommune").style.display="block";};
    $("inpt_ville").onmouseout=function(evt){$("div_messageCommune").style.display="none";};
  }
}

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

function afficheEffaceCalendJsMenu(nomDiv){
  if($(nomDiv).showing==true){
    Effect.BlindUp(nomDiv,{"duration":0.6});       
    $(nomDiv).showing=false;
  }
  else{
    Effect.BlindDown(nomDiv,{"duration":0.6});       
    $(nomDiv).showing=true;
  }
}

function affichePlusCrit(nomDiv,span){
  if($(nomDiv).showing==true){
    Effect.BlindUp(nomDiv);       
    $(nomDiv).showing=false;
    $(span).innerHTML="+";
  }
  else{
    Effect.BlindDown(nomDiv);       
    $(nomDiv).showing=true;
    $(span).innerHTML="-"; 
  }
}

function setCGIForLstCommune(li){
    if ( navigator.appName == 'Microsoft Internet Explorer' ){
      var commune = li.getElementsByTagName("span")[0].getAttribute("commune_reelle");
    }
    else{
      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($('frmMoteurGeneral'));
}

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
    });
    $("inpt_ville").disabled=false;
}

function changeRegion(){
  $("lst_rubriques").value="";
  $("inpt_ville_libcommune").value="";
  $("inpt_ville").value="Commune";
  setListByForm($('frmMoteurGeneral'));  
}

function changeDomaine(){
  $("micro_reg").value="";
  $("inpt_ville_libcommune").value="";
  $("inpt_ville").value="Commune";
  setListByForm($('frmMoteurGeneral'));  
}

function changeCommune(){
  $("micro_reg").value="";
  $("lst_rubriques").value="";  
}

function valideDate(){
  if((!$("inpt_dateDeb").value) || ($("lst_nbj").value=="")) alertAMalibu("Vous devez saisir la date d'arriv&eacute;e et la dur&eacute;e de votre s&eacute;jour !");
  else setListByForm($('frmMoteurGeneral'));
}

function clickType(){
  $$(".inpt_type").each(function(obj){
    obj.onclick=function(evt){
      initMoteur();
      setListByForm($('frmMoteurGeneral'));
    };
  })
}

function initMoteur(){
  $("inptPasDate").onclick = function(evt){
    effaceDate();
    setListByForm($('frmMoteurGeneral'));
  };
  defAffListeSelect("sp_libDuree","ul_dureeSejour","lst_nbj",".lstDuree");
  defAffListeSelect("sp_nbp","ul_nbp","lst_nbp",".lstNbp");
  defAffListeSelect("sp_epi","ul_epi","lst_epi",".lstEpi");
  defAffListeSelect("sp_chb","ul_chb","lst_chb",".lstChb");
  $$(".lstDuree").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbj").value=obj.getAttribute("valeur");$("sp_libDuree").innerHTML=obj.innerHTML;}});
  $$(".lstNbp").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbp").value=obj.getAttribute("valeur");$("sp_nbp").innerHTML=obj.innerHTML;}});
  $$(".lstEpi").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_epi").value=obj.getAttribute("valeur");$("sp_epi").innerHTML=obj.innerHTML;}});
  $$(".lstChb").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_chb").value=obj.getAttribute("valeur");$("sp_chb").innerHTML=obj.innerHTML;}});
  if($("inpt_g").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpH").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="none";});
    $$(".nbpG").each(function(obj){obj.style.display="block";});
    $$(".dureeH").each(function(obj){obj.style.display="none";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
    
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="block";});    
    $$(".chbG").each(function(obj){obj.style.display="block";});
    
    setCalendrierGeneral("gites73","1","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurMenu_date").show();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=G",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  }
  else if($("inpt_maxi").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpH").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="none";});
    $$(".nbpG").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="block";});
    $$(".dureeH").each(function(obj){obj.style.display="none";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
    
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="block";});    
    $$(".chbG").each(function(obj){obj.style.display="block";});
    
    setCalendrierGeneral("gites73","1","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurMenu_date").show();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    $("lst_nbp").value="12";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=G",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  }
  else if($("inpt_chalet").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpH").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="none";});
    $$(".nbpG").each(function(obj){obj.style.display="block";});
    $$(".dureeH").each(function(obj){obj.style.display="none";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
    
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="block";});    
    $$(".chbG").each(function(obj){obj.style.display="block";});
    
    setCalendrierGeneral("gites73","6","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurMenu_date").show();
    $("inpt_gestheb").value="H";
    $("inpt_label").value="ALPAG";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=G",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  }
  else if($("inpt_t").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpH").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="none";});
    $$(".nbpG").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="block";});
    $$(".dureeG").each(function(obj){obj.style.display="none";});
    $$(".dureeH").each(function(obj){obj.style.display="block";});
    
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="block";});    
    $$(".chbG").each(function(obj){obj.style.display="none";});
    $$(".chbT").each(function(obj){obj.style.display="block";});
    
    setCalendrierGeneral("gites73","1","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurMenu_date").show();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=T",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  }
  else if($("inpt_e").checked==true){
    $("div_moteurMenu_date").hide();
    $("p_crit3").style.display="none";
    effaceDate();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    $("div_prefEnfant").style.display="block";
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=E",setChmpCommuneAutoCompleter);
    effacePreferencesEtInit();
    $("lst_rubriques").value="";
    $("lst_nbp").value="";
    $("lst_epi").value="";
    $("lst_chb").value="";
    effaceEmplacements();
  }
  else if($("inpt_c").checked==true){
    $("p_crit3").style.display="block";
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="none";});    
    $$(".chbG").each(function(obj){obj.style.display="none";});
    $$(".chbC").each(function(obj){obj.style.display="block";});
    $("div_moteurMenu_date").hide();
    effaceDate();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=C",setChmpCommuneAutoCompleter);
    $("lst_nbp").value="";
    $("lst_epi").value="";
    $("lst_chb").value="";
    effacePreferencesEtInit();    
    if(!$("lst_chb").hasClassName("lst_chbCamping")) $("lst_chb").addClassName("lst_chbCamping");
  }
  else if($("inpt_ch").checked==true || $("inpt_chville").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpG").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="none";});
    $$(".nbpH").each(function(obj){obj.style.display="block";});
    $$(".dureeG").each(function(obj){obj.style.display="none";});
    $$(".dureeH").each(function(obj){obj.style.display="block";});  
    
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="none";});    
    $$(".chbG").each(function(obj){obj.style.display="none";});
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".epiH").each(function(obj){obj.style.display="block";});    
    $$(".chbH").each(function(obj){obj.style.display="block";});
    
    $("div_moteurMenu_date").show();
    setCalendrierGeneral("gites73","1","","H","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");    
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    if($("int_infotour").value=="CHALETSLOISIRS") $("int_infotour").value="";
    if($("inpt_chville").checked==true) $("rubVille").value="HVILL";
    else if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=H",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  }
  else if($("inpt_loisir").checked==true){
    $("p_crit3").style.display="block";
    $$(".nbpH").each(function(obj){obj.style.display="none";});
    $$(".nbpMaxi").each(function(obj){obj.style.display="none";});
    $$(".nbpT").each(function(obj){obj.style.display="none";});
    $$(".nbpG").each(function(obj){obj.style.display="block";});
    $$(".dureeH").each(function(obj){obj.style.display="none";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
    
    $$(".chbC").each(function(obj){obj.style.display="none";});
    $$(".chbT").each(function(obj){obj.style.display="none";});
    $$(".epiH").each(function(obj){obj.style.display="none";});    
    $$(".chbH").each(function(obj){obj.style.display="none";});
    $$(".epiG").each(function(obj){obj.style.display="block";});    
    $$(".chbG").each(function(obj){obj.style.display="block";});
    
    setCalendrierGeneral("gites73","1","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurMenu_date").show();
    if($("inpt_gestheb").value) $("inpt_gestheb").value="";
    if($("inpt_label").value) $("inpt_label").value="";
    if($("lst_nbp").value=="12") $("lst_nbp").value="";
    $("int_infotour").value="CHALETSLOISIRS";
    if($("rubVille").value=="HVILL") $("rubVille").value="";
    effacePrefEnfant();
    $("div_prefs").show();
    $("div_Nbp").show();
    $("div_Epi").show();
    $("lbl_nbChb").style.display="block";
    $("lbl_nbEmpl").style.display="none";
    $("div_btPlusCrit").show();
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=H",setChmpCommuneAutoCompleter);
    effaceEmplacements();
    $("p_lieuStation").show();
  } 
  else{
    setCalendrierGeneral("gites73","1","","G","calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE",setChmpCommuneAutoCompleter);
  } 
}

function defAffListeSelect(span,ul,input,li){
  $(span).onclick = function(evt){afficheEffaceCalendJsMenu(ul);};
  $$(li).each(function(obj){obj.onclick=function(evt){definitionListe(span,ul,input,obj);};});
}

function definitionListe(span2,ul2,input2,li2){
  $(input2).value=li2.getAttribute("valeur");
  $(span2).innerHTML=li2.innerHTML;
  afficheEffaceCalendJsMenu(ul2);
  if(span2!="sp_libDuree") setListByForm($('frmMoteurGeneral'));
}

function effacePrefEnfant(){
  $("div_prefEnfant").style.display="none";
  $$(".chk_prefEnfant").each(function(obj){obj.checked=false;});
}

function effacePreferencesEtInit(){
  $("lst_nbp").value="";
  $("lst_epi").value="";
  $("lst_chb").value="";
  $$(".lstNbp").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbp").value=obj.getAttribute("valeur");$("sp_nbp").innerHTML=obj.innerHTML;}});
  $$(".lstEpi").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_epi").value=obj.getAttribute("valeur");$("sp_epi").innerHTML=obj.innerHTML;}});
  $$(".lstChb").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_chb").value=obj.getAttribute("valeur");$("sp_chb").innerHTML=obj.innerHTML;}});
  $$(".chk_pref").each(function(obj){obj.checked=false;});
  $$(".select_dist").each(function(obj){obj.value="";});
  if($("inpt_c").checked==false) $("div_prefs").hide();
  else{
    $("div_Nbp").hide();
    $("div_Epi").hide();
    $("lbl_nbChb").style.display="none";
    $("lbl_nbEmpl").style.display="block";
  }
  $("div_btPlusCrit").hide();
  $("div_rechercheAvancee").hide();
  $("p_lieuStation").hide();
  $("lst_rubriques").value="";  
}

function effaceEmplacements(){
  if($("lst_chb").hasClassName("lst_chbCamping")){
    $("lst_chb").removeClassName("lst_chbCamping");
    $("lst_chb").value="";
    $$(".lstChb").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_chb").value=obj.getAttribute("valeur");$("sp_chb").innerHTML=obj.innerHTML;}});
  }
}

function effaceDate(){
  $("inptPasDate").checked=true;
  $("inpt_dateDeb").value="";
  $("lst_nbj").value="";
  $$(".chbC").each(function(obj){obj.setAttribute("selected","");});
  $$(".lstDuree").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbj").value=obj.getAttribute("valeur");$("sp_libDuree").innerHTML=obj.innerHTML;}});
}

function affCarteSecteurs(){
  var html = "<a href='#ferme' class=\"fermePopIn\" onclick='effaceDivAvecTransparence();'>Fermer</a>";
  html += "<div class='clear'></div>";
  html += "<img src='/img/moteur/carte-secteurs-touristiques.jpg' />";
  if(document.documentElement.clientHeight>=520) afficheDivAvecTransparence(html,805,520);
  else document.location.href="/cartes-secteurs-touristiques.html";
}

function affCarteDomaines(){
  var html = "<a href='#ferme' class=\"fermePopIn\" onclick='effaceDivAvecTransparence();'>Fermer</a>";
  html += "<div class='clear'></div>";
  html += "<img src='/img/moteur/carte-domaines-skiables.jpg' />";
  if(document.documentElement.clientHeight>=603) afficheDivAvecTransparence(html,732,603);
  else document.location.href="/cartes-domaines-skiables.html";
}

function supprCommune(){
  $("inpt_ville_libcommune").value="";
  $("inpt_ville").value="Commune";
  setListByForm($('frmMoteurGeneral'));
}

function lanceRechercheDate(){
  if(($("inpt_dateDeb").value!="" && $("lst_nbj").value=="") || ($("inpt_dateDeb").value=="" && $("lst_nbj").value!="")){
    alertAMalibu("Vous devez définir la date de votre séjour ainsi que la durée");
  }
  else{
    setListByForm($('frmMoteurGeneral'));
  }
}

