function oninit(){
  if($("div_moteurAccContent")) initMoteurAccueil();
  initNewsletter();
}

function valideInscNews(){
    envoiMailByAjaxByForm('frm_newsletter','mesg_replace',false);
}


function afficheEffaceCalendJs(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 afficheEffaceFaq(nomDiv){
  if(($(nomDiv).showing==true)||($(nomDiv).style.display=="block")){
    Effect.BlindUp(nomDiv,{"duration":0.6});       
    $(nomDiv).showing=false;
  }
  else{
    Effect.BlindDown(nomDiv,{"duration":0.6});       
    $(nomDiv).showing=true;
  }
}

function clicCalendJs(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("calendrierMoteur");
  recapRecherche();
}

function lanceRecherche(){
  setListByForm($('frm_moteurAcc'));
}

function lanceRechercheAffine(){
  setListByForm($('frm_moteurAffine'));
}

function lanceRechercheNum(){
  var adr = "/liste?CRITINIT=O&LNO="+$("inpt_numAcc").value;
  document.location.href=adr;
}
function lanceRechercheNumAffine(){
  document.location.href='/liste?'+getQueryStringByForm($("frm_moteurAffineNum"));
}

function lanceRechercheCarte(){
  document.location.href='/liste?'+getQueryStringByForm($("frm_moteurAcc"))+"#js:afficheOngletCarte()";
}

function envoiFormDeContact(){
  envoiMailByAjaxByForm("frm_contact","div_form",true);
}


function initMoteurAccueil(){
  setCalendrierGeneral("","1","","","calendrierMoteur",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
  $("a_moteurAfficheOu").onclick=function(evt){clicAscenceur("a_moteurAfficheOu","div_moteurOu")};
  $("a_moteurAfficheQuoi").onclick=function(evt){clicAscenceur("a_moteurAfficheQuoi","div_moteurQuoi")};
  $("a_moteurAfficheQuand").onclick=function(evt){clicAscenceur("a_moteurAfficheQuand","div_moteurQuand")};
  
  $$(".chmpFormAcc").each(function(obj){if(obj.tagName.toLowerCase()=="select") obj.onchange=function(evt){recapRecherche();}; else obj.onclick=function(evt){recapRecherche();};});
  $$(".lstDuree").each(function(obj){obj.onclick=function(evt){definitionDuree(obj);}});
  $("sp_libDuree").onclick=function(evt){afficheEffaceCalendJs("ul_dureeSejour");}
  $("sp_inptDpt").onclick=function(evt){afficheEffaceCalendJs("div_lstDpt");}
  $("a_fermeListeDpt").onclick=function(evt){afficheEffaceCalendJs("div_lstDpt");}
  
  $("checkGite").observe("click",initDuree);
  $("checkCh").observe("click",initDuree);
  $("checkGegs").observe("click",initDuree);  
  initDuree();
  recapRecherche();
  
  $$(".checkType").each(function(obj){obj.observe("click",affMessageDureeGite);})
}

function clicAscenceur(ascenceur,div){
  if($(ascenceur).hasClassName("ascenceurFerme")){
    $$(".div_contentAscenceur").each(function(obj){if(obj.style.display!="none")Effect.BlindUp(obj,{"duration":0.8});});
    Effect.BlindDown(div,{"duration":0.8});
    $$(".ascenceur").each(function(obj){obj.removeClassName("ascenceurOuvert");obj.addClassName("ascenceurFerme")});
    $(ascenceur).removeClassName("ascenceurFerme");
    $(ascenceur).addClassName("ascenceurOuvert");
  }  
}

function recapRecherche(){
  $$(".sp_recapRech").each(function(obj){obj.innerHTML=""});
  $$(".chmpFormAcc").each(function(obj){
    if(obj.value){
      if(obj.getAttribute("recap"))sp_recap=obj.getAttribute("recap");else sp_recap="";
      if(obj.getAttribute("lblAvant"))lbl_avant=obj.getAttribute("lblAvant");else lbl_avant="";
      if(obj.getAttribute("lblApres"))lbl_apres=obj.getAttribute("lblApres");else lbl_apres="";
      if(obj.getAttribute("info"))info=obj.getAttribute("info");else info="";
      
      if((obj.getAttribute("type")=="checkbox")){
        if(obj.checked) $(sp_recap).innerHTML+=lbl_avant+" "+info+""+lbl_apres+" ";
      }
      else{
        if(obj.getAttribute("name")=="NBJ"){
          if($("inpt_dateDeb").value){
            if(info) $(sp_recap).innerHTML+=lbl_avant+" "+info+" "+lbl_apres+" ";
            else $(sp_recap).innerHTML+=lbl_avant+" "+obj.value+" "+lbl_apres+" ";
          }
        }
        else{
          if(info) $(sp_recap).innerHTML+=lbl_avant+" "+info+" "+lbl_apres+" ";
          else $(sp_recap).innerHTML+=lbl_avant+" "+obj.value+" "+lbl_apres+" ";
        }
      }
    }    
  });
}

function definitionDuree(obj){
  $("lst_nbj").value=obj.getAttribute("valeur");
  $("sp_libDuree").innerHTML=obj.innerHTML;
  afficheEffaceCalendJs("ul_dureeSejour");  
  recapRecherche();
}

function initDuree(){
  $$(".lstDuree").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbj").value=obj.getAttribute("valeur");$("sp_libDuree").innerHTML=obj.innerHTML;}});
  if($("checkGite").checked==true && $("checkCh").checked==false){
    $$(".dureeH").each(function(obj){obj.style.display="none";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
  }
  else if($("checkGite").checked==false && $("checkCh").checked==true){
    $$(".dureeG").each(function(obj){obj.style.display="none";});
    $$(".dureeH").each(function(obj){obj.style.display="block";});   
  }
  else{
    $$(".dureeH").each(function(obj){obj.style.display="block";});
    $$(".dureeG").each(function(obj){obj.style.display="block";});
  }
}

function affMessageDureeGite(){
  if(($("inpt_dateDeb").value)&&($("checkCh").checked==false)&&($("checkGegs").checked==false)){
    $("p_messGiteSelect").style.display="block";
  }
  else{
    $("p_messGiteSelect").style.display="none";
  }
}

function viderChampNews(obj){
  obj.value="";
}

function enterNews(event){
  if(!event) var event = window.event;
  if(event && event.keyCode==13) checkForm($("frm_newsletter"),valideInscNews);
}

function initNewsletter(){
  $("inpt_inscNews").value = "Entrez votre email";
  $("frm_newsletter").onsubmit = function(evt){return false;};
  $("a_validNews").observe("click",function(evt){checkForm($('frm_newsletter'),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);};
}