function oninit(){
  generePagesPromos();
  generePagesCoeur();
  generePagesActus();
  generePagesThemes();
  if($("div_newsContent")) initNewsletter();
  if($("div_moteurCentral")) initMoteurCentral();
  if($("sp_btPlusCrit")) $("sp_btPlusCrit").onclick=function(evt){plusDeCriteres();};
  if($("a_aubergeCampagne")) $("a_aubergeCampagne").onclick=function(evt){aubergeCampagne();};
}

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

function plusDeCriteres(){
  afficheEffaceCalendJs("div_plusDeCriteresContent");
  if($("acc_h").checked){
    if($("div_typeChambre").style.display=="none") $("div_typeChambre").style.display="block";
    else $("div_typeChambre").style.display="none";
  }
}

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);};
}

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

function valideInscNews(){
    if($("inpt_inscNews").value) document.location.href="/newsletter.php?mail="+$("inpt_inscNews").value;
    else alertAMalibu("Vous devez saisir votre email");
}
function viderChampNews(inpt){
  inpt.value="";
}

function generePagesPromos(){
  if($("div_miseAvantPromotionsContent")) setScrollHorizontalOnLstGenerePage("div_miseAvantPromotionsContent","ul_miseAvantPromotions",{idDivPastePage:"div_miseAvantPromotions",position:"bottom"});
}

function generePagesCoeur(){
  if($("div_miseAvantCoeurContent")){
		setScrollHorizontalOnLstGenerePage("div_miseAvantCoeurContent","ul_miseAvantCoeur",{idDivPastePage:"div_miseAvantCoeur",position:"bottom"});
		//ajout car sans cela le menu n'apparaissait pas sur IE7
		$("menu").style.position="absolute";
	}
}

function generePagesActus(){
  if($("div_miseAvantActusContent")) setScrollHorizontalOnDiv('div_miseAvantActusContent','ul_miseAvantActus',{nextButton:"bt_actuSuiv",prevButton:"bt_actuPrec"});
}

function generePagesThemes(){
  if($("div_miseAvantThemesContent")) setScrollHorizontalOnDiv('div_miseAvantThemesContent','ul_miseAvantThemes',{nextButton:"bt_theSuiv",prevButton:"bt_thePrec"});
}


function actualiseCommune(){
  var acc = "";
  $$(".chk_type").each(function(obj){
    if(obj.checked==true){
      if(acc=="") acc = obj.value;
      else acc += ","+obj.value;
    } 
  });
  appelAjaxToFunc("/config_v3/74/G.v3/GDFv4.FRANCAIS/librairie/bloc_html/Communes.php","REG="+$("lst_region").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("Indifférent");
    $("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 defCommune(){
  $("select_commune").value = $("lst_commune").value;
}

function initMoteurCentral(){
  $$(".div_lignePrefCheck").each(function(obj){obj.style.display="none";});
  defAffListeSelect("sp_nbp","ul_nbp","lst_nbp",".lstNbp");
  $$(".lstNbp").each(function(obj){if(obj.getAttribute("selected")=="selected"){$("lst_nbp").value=obj.getAttribute("valeur");$("sp_nbp").innerHTML=obj.innerHTML;}});

  $("lst_commune").observe("change",defCommune);
  $("lst_region").observe("change",actualiseCommune);
  actualiseCommune();
  $$(".chk_Moteur").each(function(obj){obj.observe("click",function(evt){setListByForm($("frm_central"));});});
  $$(".selectMoteur").each(function(obj){obj.observe("change",function(evt){setListByForm($("frm_central"));});});
  
  if($("acc_g").checked==true) moteurTypeGite();
  if($("acc_h").checked==true) moteurTypeChambre();
  if($("acc_gegs").checked==true) moteurTypeGroupe();
  if($("acc_c").checked==true) moteurTypeCamping();
  
  $("acc_g").observe("click",function(evt){
    defFondMoteurGite();
    actualiseCommune();
    $("div_typeChambre").style.display="none";
    $$(".reinit").each(function(obj){
      obj.checked=false;
    });
    moteurTypeGite();
    setListByForm($("frm_central"));
  });
  
  $("acc_h").observe("click",function(evt){
    defFondMoteurChambre();
    actualiseCommune();
    $$(".reinit").each(function(obj){
      obj.checked=false;
    });
    moteurTypeChambre();
    setListByForm($("frm_central"));
  });
  
  $("acc_gegs").observe("click",function(evt){
    defFondMoteurGegs();
    actualiseCommune();
    $("div_typeChambre").style.display="none";
    $$(".reinit").each(function(obj){
      obj.checked=false;
    });
    moteurTypeGroupe();
    setListByForm($("frm_central"));
  });
  
  $("acc_c").observe("click",function(evt){
    defFondMoteurCamping();
    actualiseCommune();
    $("div_typeChambre").style.display="none";
    $$(".reinit").each(function(obj){
      obj.checked=false;
    });
    moteurTypeCamping();
    setListByForm($("frm_central"));
  });
  
  $("a_rechExpressMoteur").onclick = function(evt){$("frm_rechNum").submit()};
  $("inpt_refMoteur").onkeypress = function(evt){rechercheExpressMoteur(evt);};
  $("inpt_refMoteur").onfocus=function(evt){this.value='';};
}

function rechercheExpressMoteur(event){
  if(!event) var event = window.event;
  if(event && event.keyCode==13) $("frm_rechNum").submit();
}

function moteurTypeGite(){
  defFondMoteurGite();
  $$(".div_equipType").each(function(obj){obj.style.display="none"});
  $("div_equipGite").style.display="block";
  $$(".div_lignePrefCheck").each(function(obj){obj.style.display="none";});
  $("div_handicap").style.display="block";
  $("div_animaux").style.display="block";
  $("div_chVac").style.display="block";
  affDates();
  $$(".nbpH").each(function(obj){obj.style.display="none";});
  $$(".nbpT").each(function(obj){obj.style.display="none";});
  $$(".nbpG").each(function(obj){obj.style.display="block";});
  afficheDomaines();
}

function moteurTypeChambre(){
  defFondMoteurChambre();
  $$(".div_equipType").each(function(obj){obj.style.display="none"});
  $("div_equipChambre").style.display="block";
  $$(".div_lignePrefCheck").each(function(obj){obj.style.display="none";});
  $("div_handicap").style.display="block";
  $("div_table").style.display="block";  
  $("div_animaux").style.display="block";
  $("div_chVac").style.display="block";
  effaceDates();
  $$(".nbpG").each(function(obj){obj.style.display="none";});
  $$(".nbpT").each(function(obj){obj.style.display="none";});
  $$(".nbpH").each(function(obj){obj.style.display="block";});
  afficheDomaines();
}

function moteurTypeGroupe(){
  defFondMoteurGegs();
  $$(".div_equipType").each(function(obj){obj.style.display="none"});
  $("div_equipGroupe").style.display="block";
  $$(".div_lignePrefCheck").each(function(obj){obj.style.display="none";});
  $("div_handicap").style.display="block";
  $("div_table").style.display="block";  
  $("div_auberge").style.display="block";
  $("div_salle").style.display="block";
  $("div_chVac").style.display="block";
  effaceDates();
  $$(".nbpG").each(function(obj){obj.style.display="none";});
  $$(".nbpH").each(function(obj){obj.style.display="none";});
  $$(".nbpT").each(function(obj){obj.style.display="block";});
  afficheDomaines();
}

function moteurTypeCamping(){
  defFondMoteurCamping();
  $$(".div_equipType").each(function(obj){obj.style.display="none"});
  $$(".div_lignePrefCheck").each(function(obj){obj.style.display="none";});
  $("div_ferme").style.display="block";
  effaceDates();
  effaceDomaines();
}

function defFondMoteurGite(){
  if($("div_moteurCentral").hasClassName("div_moteurCentralCamping")) $("div_moteurCentral").removeClassName("div_moteurCentralCamping");
  if($("div_moteurCentral").hasClassName("div_moteurCentralChambre")) $("div_moteurCentral").removeClassName("div_moteurCentralChambre");
  if($("div_moteurCentral").hasClassName("div_moteurCentralGegs")) $("div_moteurCentral").removeClassName("div_moteurCentralGegs");
  if(!$("div_moteurCentral").hasClassName("div_moteurCentralGite")) $("div_moteurCentral").addClassName("div_moteurCentralGite");
}
function defFondMoteurChambre(){
  if($("div_moteurCentral").hasClassName("div_moteurCentralCamping")) $("div_moteurCentral").removeClassName("div_moteurCentralCamping");
  if($("div_moteurCentral").hasClassName("div_moteurCentralGite")) $("div_moteurCentral").removeClassName("div_moteurCentralGite");
  if($("div_moteurCentral").hasClassName("div_moteurCentralGegs")) $("div_moteurCentral").removeClassName("div_moteurCentralGegs");
  if(!$("div_moteurCentral").hasClassName("div_moteurCentralChambre")) $("div_moteurCentral").addClassName("div_moteurCentralChambre");
}
function defFondMoteurGegs(){
  if($("div_moteurCentral").hasClassName("div_moteurCentralCamping")) $("div_moteurCentral").removeClassName("div_moteurCentralCamping");
  if($("div_moteurCentral").hasClassName("div_moteurCentralGite")) $("div_moteurCentral").removeClassName("div_moteurCentralGite");
  if($("div_moteurCentral").hasClassName("div_moteurCentralChambre")) $("div_moteurCentral").removeClassName("div_moteurCentralChambre");
  if(!$("div_moteurCentral").hasClassName("div_moteurCentralGegs")) $("div_moteurCentral").addClassName("div_moteurCentralGegs");
}
function defFondMoteurCamping(){
  if($("div_moteurCentral").hasClassName("div_moteurCentralGegs")) $("div_moteurCentral").removeClassName("div_moteurCentralGegs");
  if($("div_moteurCentral").hasClassName("div_moteurCentralGite")) $("div_moteurCentral").removeClassName("div_moteurCentralGite");
  if($("div_moteurCentral").hasClassName("div_moteurCentralChambre")) $("div_moteurCentral").removeClassName("div_moteurCentralChambre");
  if(!$("div_moteurCentral").hasClassName("div_moteurCentralCamping")) $("div_moteurCentral").addClassName("div_moteurCentralCamping");
}

function affDates(){
  $("div_dates").style.display="block";
  setCalendrierGeneral("gites74","1","","G","div_calendrierMoteurCentralContent",clicCalendJsCentral,"inpt_dateDebCentral","","","lst_nbjCentral","1",""); 
  $("img_fermeCalendCentral").onclick=function(evt){afficheEffaceCalendJs("div_calendrierMoteurCentral");};
  $("inpt_dateDebCentral").onfocus=function(evt){afficheEffaceCalendJs("div_calendrierMoteurCentral");};
}
function effaceDates(){
  $("div_dates").style.display="none";
  $("inpt_dateDebCentral").value="";
  $("lst_nbjCentral").value="";
}

function effaceDomaines(){
  $("div_domainesMoteur").style.display="none";
  $("lst_domaines").value="";
  $("sp_ouLac").style.display="none";
}
function afficheDomaines(){
  $("div_domainesMoteur").style.display="block";
  $("sp_ouLac").style.display="inline";
}

function defAffListeSelect(span,ul,input,li){
  $(span).onclick = function(evt){afficheEffaceCalendJs(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;
  afficheEffaceCalendJs(ul2);
  if(span2!="sp_libDuree") setListByForm($('frm_central'));
}

function clicCalendJsCentral(evt,jour,mois,annee,etat){
  $("inpt_dateDebCentral").value=jour+mois+annee;
  afficheEffaceCalendJs("div_calendrierMoteurCentral");
}

function aubergeCampagne(){
  var html = "<div class='div_fermePopIn'><a href='#ferme' class='fermePopIn' onclick='effaceDivAvecTransparence();'>Fermer</a><div class='clear'></div></div>";
  html += "<iframe name=\"ifrm_auberge\" id=\"ifrm_auberge\" src=\"/auberges-de-campagne.html\" border=\"0\" frameborder=\"0\"></iframe>";
  afficheDivAvecTransparence(html,760,600);
}

function desactiveListeRubMoteur(lst1,lst2){
  if($(lst1).value!=""){
    $(lst2).disabled=true;
    var yes;
  }
  else {
    $(lst2).disabled=false;
  }
}

function desactiveDomaines(){
  desactiveListeRubMoteur("lst_lacsMassifs","lst_domaines");
  
}
function desactiveLacs(){
  desactiveListeRubMoteur("lst_domaines","lst_lacsMassifs");
}
