function oninit(){
  if($("div_moteurRecherche")) initMoteur();
}

function afficheEfface(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 bonsPlans(){
  setScrollHorizontalOnLstGenerePage("div_bonsPlanContent","ul_bonsPlans",{idDivPastePage:"div_bonplans",position:"bottom"});
  var test;
}


function initMoteur(){
  setCalendrierGeneral("","1","","","div_calendrierMoteurContent",clicCalendJs,"inpt_deb","","","lst_nbj","1","");
  $("img_pictoCalend").onclick=function(evt){afficheEfface("div_calendrierMoteur");};
  $("img_fermeCalend").onclick=function(evt){afficheEfface("div_calendrierMoteur");};
  
  $("lst_type").onchange=function(evt){rechercheAjax();actualiseCommune();};  
  $("lst_chefLieu").onchange=function(evt){rechercheAjax();actualiseCommune();};    
  $$(".list_moteur").each(function(obj){obj.onchange=function(evt){rechercheAjax();};});  
  $$(".inpt_check").each(function(obj){obj.onclick=function(evt){rechercheAjax();};});  
  $("sp_plusCriteres").onclick=function(evt){
    afficheEfface("div_plusCriteres"); 
    if($("div_plusCriteres").showing==true) $("sp_plusCriteres").innerHTML = "- de critères";
    else $("sp_plusCriteres").innerHTML = "+ de critères";
  };
  $("sp_libDuree").onclick=function(evt){afficheEfface("ul_dureeSejour");};
  $$(".lstDuree").each(function(obj){obj.onclick=function(evt){definitionDuree(obj);};});
  $("sp_defDate").onclick=function(evt){lanceRechercheDate();};
  actualiseCommune();
}

/*
function actualiseCommune(){
  var acc = $("lst_type").value;
  appelAjaxToFunc("/config_v3/BOURGOGNE/G.v3/BOURGOGNEv4.FRANCAIS/librairie/bloc_html/villeProxEtCommunes.php","DEPARTEMENT="+$("lst_dpt").value+"&LIBCHEFLIEU="+$("select_villeProx").value+"&ACC="+acc,function(reponseAjx){
    var tab;
    eval("tab="+reponseAjx);
    var indice = 0;
    var selected = 0;
    $("lst_commune").options.length=0;
    $("lst_commune").options[$("lst_commune").options.length] = new Option("Commune");
    $("lst_commune").options[$("lst_commune").options.length-1].value="";
    $A(tab.communes).each(function(obj){
      $("lst_commune").options[$("lst_commune").options.length] = new Option(obj);
      $("lst_commune").options[$("lst_commune").options.length-1].value=obj;
      indice++;
      if(obj==$("select_commune").value) selected=indice;
    });
    $("lst_commune").selectedIndex = selected;
  });
}        */

function actualiseCommune(){
  var acc = $("lst_type").value;
  appelAjaxToFunc("/config_v3/58/G.v3/GDFV4.FRANCAIS/librairie/bloc_html/villeProxEtCommunes.php","LIBCHEFLIEU="+$("lst_chefLieu").value+"&ACC="+acc+"&COMSELECT="+$("select_commune").value,function(reponseAjx){
    $("div_lstCommune").innerHTML = reponseAjx;
    $("lst_commune").onchange=function(evt){$("select_commune").value=$("lst_commune").value;rechercheAjax();};
  });
}                               

function defCommune(){
  $("select_commune").value = $("lst_commune").value;
}

function rechercheAjax(){
  setListByForm($("frm_moteur"));
}

function clicCalendJs(evt,jour,mois,annee,etat){
  $("inpt_deb").value=jour+"/"+mois+"/"+annee;
  afficheEfface("div_calendrierMoteur");
}

function reinitCalend(){
  if($("lst_type").value) type = $("lst_type").value;
  else type="";
  if(type=="T") type="H";
  setCalendrierGeneral("gites89","1","",type,"div_calendrierMoteurContent",clicCalendJs,"inpt_deb","","","lst_nbj","1","");
}

function definitionDuree(obj){
  $("lst_nbj").value=obj.getAttribute("valeur");
  $("sp_libDuree").innerHTML=obj.innerHTML;
  afficheEfface("ul_dureeSejour");  
}

function lanceRechercheDate(){
  if(($("inpt_deb").value!="" && $("lst_nbj").value=="")||($("inpt_deb").value=="" && $("lst_nbj").value!="")||($("inpt_deb").value=="" && $("lst_nbj").value=="")){
    alertAMalibu("Merci de saisir à la fois, la date de votre arrivée, ainsi que la durée de votre séjour");
  }
  else{
    rechercheAjax();
  }
}

function envoiContact(){
  checkForm($("frm_contact"),envoiMailContact);
  $("page").scrollTo();
}
function envoiMailContact(){
  envoiMailByAjaxByForm('frm_contact','frm_contact',true);
}

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

function enterNews(event){
  if(!event) var event = window.event;
  if(event && event.keyCode==13) checkForm($("frm_news"),valideInscNews);
}

function initNewsletter(){
  $("inpt_inscNews").value = "Entrez votre email";
  $("frm_news").onsubmit = function(evt){return false;};
  $("sp_validNews").observe("click",function(evt){checkForm($('frm_news'),valideInscNews);});
  $("inpt_inscNews").onfocus = function(evt){viderChp($("inpt_inscNews"));viderChampNews($("inpt_inscNews"));}
  $("inpt_inscNews").onblur = function(evt){checkByInput(this,'checkMailObligatoire');};
  $("inpt_inscNews").onkeypress = function(evt){enterNews(evt);};
}

function valideInscNews(){
  $("inpt_expediteur").value=$("inpt_inscNews").value;
    envoiMailByAjaxByForm('frm_news','div_formNews',false);
}

