document.write("<script src=js/calendarview.js></script>");
document.write("<script src=js/menu_haut.js></script>");



// pour moteur de rechercher
function format_date(ma_date)
{
  if (ma_date == 'date d\'arrivée')
  {
    document.frm_moteur_recherche.DEB.value = "0";
  }
}


function format_nbj(nombre_jour,type_location)
{
  if (nombre_jour == '0' && type_location == "G")
  {
    document.frm_moteur_recherche.nbj.value = "7";
  }
  
  if (nombre_jour == '0' && type_location == "H")
  {
    document.frm_moteur_recherche.nbj.value = "1";
  }
}

function change_nbj(type_location)
{
  if (type_location == 'H')
  {
      document.getElementById('a_plus_criteres').href="/date?ACC=H";
      
      var val_nbj = new Array();
      val_nbj[0] = new Array("0")
      val_nbj[1] = new Array("1")
      val_nbj[2] = new Array("2")
      val_nbj[3] = new Array("3")
      val_nbj[4] = new Array("4")
      val_nbj[5] = new Array("5")
      
      var lbl_nbj = new Array();
      lbl_nbj[0] = new Array("indifférent")
      lbl_nbj[1] = new Array("1 nuit")
      lbl_nbj[2] = new Array("2 nuits")
      lbl_nbj[3] = new Array("3 nuits")
      lbl_nbj[4] = new Array("4 nuits")
      lbl_nbj[5] = new Array("5 nuits")
  
      document.frm_moteur_recherche.nbj.options.length = val_nbj.length;
      for (i=0;i<val_nbj.length;i++)
        {
        document.frm_moteur_recherche.nbj.options[i].value = val_nbj[i];
        document.frm_moteur_recherche.nbj.options[i].text = lbl_nbj[i];
        }
      document.frm_moteur_recherche.nbj.options.selectedIndex = 0;    
      
  }
  
  if (type_location == 'G')
  {
    document.getElementById('a_plus_criteres').href="/date?ACC=G";
    
    var val_nbj = new Array();
    val_nbj[0] = new Array("0")
    val_nbj[1] = new Array("7")
    val_nbj[2] = new Array("14")
    val_nbj[3] = new Array("21")
    val_nbj[4] = new Array("28")
    
    var lbl_nbj = new Array();
    lbl_nbj[0] = new Array("indifférent")
    lbl_nbj[1] = new Array("1 semaine")
    lbl_nbj[2] = new Array("2 semaines")
    lbl_nbj[3] = new Array("3 semaines")
    lbl_nbj[4] = new Array("4 semaines et +")

    document.frm_moteur_recherche.nbj.options.length = val_nbj.length;
    for (i=0;i<val_nbj.length;i++)
      {
      document.frm_moteur_recherche.nbj.options[i].value = val_nbj[i];
      document.frm_moteur_recherche.nbj.options[i].text = lbl_nbj[i];
      }
    document.frm_moteur_recherche.nbj.options.selectedIndex = 0;  
  }
}

function change_table(type_location)
{
  if (type_location == 'H')
  {

     document.getElementById('form_div_tab').style.display="block";
  }
  else
  {
     document.getElementById('form_div_tab').style.display="none";
  }
}


/*---------------------------Fonctions pour moteur de recherche en ajax-----------------------------------*/
var nbClick=0;

function oninit(){ 
  if ($("img_calendMoteur")) $("img_calendMoteur").onclick=function (evt){afficheEffaceCalendJsMenu('div_calendrierMoteur');}
  if($("lst_commune")) actualiseCommune(); 
  majMoteur();  
  initMoteurListe();      
  if ($("sp_moteur_titreRechercheCarteListe")) $("sp_moteur_titreRechercheCarteListe").onclick=function(evt){afficheOngletCarte();}
}

function initMoteurListe(){
  refreshCalDateArr();
  $$(".select_moteur").each(function(obj){
    obj.observe("change",rechercheAjaxListe);
  });
  $("sp_valideDate").onclick=function(evt){
    if(!$("inpt_dateDeb").value || !$("lst_nbj").value) alertAMalibu("Vous devez saisir la date de début de votre séjour ainsi que la durée !");
    else rechercheAjaxListe();
  };
  if($("select_commune").value) $("inpt_distcomm").disabled=false;
  actualiseCommune();
  $("lst_commune").observe("change",function(evt){
    $("inpt_distcomm").disabled=false;
    $("select_commune").value=$("lst_commune").value;
  });
  $('inpt_sousType').value="";
  if(($("inpt_g")) && ($("inpt_g").checked==true)){
    $("div_moteurRubriqueQuelPrix").style.display="block";
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",setChmpPrixToReglette);
  }
  else{
    $("div_moteurRubriqueQuelPrix").style.display="none";
  }
  $("div_valideLno").onclick=function(evt){lanceRechercheReferenceListe();};
  $("a_btPlusCrit").onclick=function(evt){
    afficheEfface("div_plusCritContent");
    if($("div_plusCritContent").style.display=="none") $("a_btPlusCrit").innerHTML = "Moins de critères";
    else  $("a_btPlusCrit").innerHTML = "Plus de critères";
  } 
}

function majMoteur(){
  refreshCalDateArr();
  if(($("inpt_g")) && ($("inpt_g").checked==true)) { 
    $("div_moteurDate").style.display="block"; 
    setCalendrierGeneral("gites66","1","","G","div_calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurSejour").style.display="block";        
    $("div_moteurRubriqueQuelPrix").style.display="block";
    appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",setChmpPrixToReglette);      
    actualiseCommune();
    $("div_moteurTable").style.display="none";
  }  else if((($("inpt_h")) && ($("inpt_h").checked==true)) || ($("inpt_tous").checked==true)){
    $("div_moteurRubriqueQuand").style.display="block";
    setCalendrierGeneral("gites66","1","","H","div_calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
    $("div_moteurRubriqueQuelPrix").style.display="none";      
    $("inpt_pxmini").value="";
    $("inpt_pxmaxi").value="";  
    actualiseCommune();
    $("div_moteurTable").style.display="block";
  }
  else{ 
    $("div_moteurRubriqueQuand").style.display="none";
    $("div_moteurRubriqueQuelPrix").style.display="none";
    $("inpt_pxmini").value="";
    $("inpt_pxmaxi").value="";
    actualiseCommune(); 
    $("div_moteurTable").style.display="none";
  }
}

function lanceRechercheReferenceListe(){
  if($("inpt_refGite").value && $("inpt_refGite").value!="Référence") document.location.href="/listeheb?LNO="+$("inpt_refGite").value;
  else alertAMalibu("Vous devez saisir une référence pour lancer la recherche");
}

function rechercheAjaxListe(){
  setListByForm($('form_moteurRechercheListe'));
}

function select_paysTouristique(){
  $('lst_commune').value='';
}

function select_commune(){
  $('select_paysTouristique').value='';
}

/*-------------------------actualise  la commune-------------------------------*/    
function actualiseCommune(){
  var acc = "";
  $$(".chk_acc").each(function(obj){
    if(obj.checked==true){
      if(acc=="") acc = obj.value;
      else acc += ","+obj.value;
    } 
  });
  appelAjaxToFunc("/config_v3/66/P.v3/STANDARD_GLGP.FRANCAIS/librairie/bloc_html/communes.php","REG="+$("select_paysTouristique").value+"&ACC="+acc+"&SOUSTYPE="+$("inpt_sousType").value,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("Sélectionnez une 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[0]);
	   $("lst_commune").options[$("lst_commune").options.length-1].value=obj[1];
      indice++;
      if(obj[1]==$("select_commune").value) selected=indice;
    });
    $("lst_commune").selectedIndex = selected;             
  });                                        
}  

/*---------calendrier-------------------*/                      
function clicCalendJs(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJsMenu("div_calendrierMoteur");
}

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

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

function refreshCalDateArr(){
	if(($("inpt_g")) && ($("inpt_g").checked==true)){
		setCalendrierGeneral("gites66","1","","G","div_calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		$("img_calendMoteur").onclick=function (evt){afficheEffaceCalendJsMenu('div_calendrierMoteur');}
		$("div_fermeCalend").onclick=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
    $("inpt_dateDeb").onfocus=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
	} else if (($("inpt_h")) && ($("inpt_h").checked==true)){
		setCalendrierGeneral("gites66","1","","H","div_calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		$("img_calendMoteur").onclick=function (evt){afficheEffaceCalendJsMenu('div_calendrierMoteur');}
		$("div_fermeCalend").onclick=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
    $("inpt_dateDeb").onfocus=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
	}// else {
   // setCalendrierGeneral("gites66","1","","H","div_calendrierMoteurContent",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
   // $("img_calendMoteur").onclick=function (evt){afficheEffaceCalendJsMenu('div_calendrierMoteur');}
	//	$("div_fermeCalend").onclick=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
  //  $("inpt_dateDeb").onfocus=function(evt){afficheEffaceCalendJsMenu("div_calendrierMoteur");};
 // }   
}
/*--------------définition de la durée------------------------*/
function definitionDuree(obj){ 
  $("lst_nbj").value=obj.getAttribute("valeur");
  $("sp_libDuree").innerHTML=obj.innerHTML;
  afficheEffaceListe("ul_dureeSejour");
}

function enterRef(event){
  if(!event) var event = window.event;
  if(event && event.keyCode==13) document.location.href = "/liste-hebergement.html?CRITINIT=O&LNO="+$("inpt_refGite").value;
}

/*-----------prix réglette-----------*/
function setChmpPrixToReglette(reponse){

  if (!reponse)return;
  eval("var infosPrix="+reponse);
  
  /**** reglette de prix *****/
  var reglette = $('slider_prix');
  if (reglette){
    var vals=new Array();   
    var pxMini=parseInt(infosPrix.prix_mini);
    var pxMaxi=parseInt(infosPrix.prix_maxi);
    
    $("infoPrix_prixMini").innerHTML=pxMini+"&nbsp;&euro;";
    $("infoPrix_prixMaxi").innerHTML=pxMaxi+"&nbsp;&euro;";
    
    for (var i=pxMini;i<=2500;i+=25)vals.push(i);
    new Control.Slider(reglette.select('.handle'), reglette, {
      range: $R(0, 2500),
      sliderValue: [pxMini, pxMaxi],
      restricted: true,
      values: vals,
      onSlide: function(values) {
        $("infoPrix_prixMini").innerHTML=values[0];
        $("infoPrix_prixMaxi").innerHTML=values[1];          
      },
      onChange: function(values) { 
        $("inpt_pxmini").value=values[0];
        $("inpt_pxmaxi").value=values[1];
        setListByForm($('form_moteurRechercheListe'));         
      }
    });
  }
}

/*-------------------------------------------Carto----------------------------------------------*/
function afficheEffaceListe(nomDiv){
  if($(nomDiv).style.display == "none"){
    $(nomDiv).style.display = "block";
  }else{
    $(nomDiv).style.display = "none";
  }
}

//Affichage de la carto
function afficheOngletCarte(){
  afficheEffaceListe("div_liste_carto");
  if(window.gmap)window.gmap.checkResize();    
  if(window.gmap)window.gmap.resetCentre();
  gmap.reload();
  iteaGMap_reload();
  afficheEffaceListe("div_liste1");
  if($("div_liste1").style.display=="none") {
    $("sp_moteur_titreRechercheCarteListe").innerHTML = "Rechercher dans la liste";
    $("div_entete_infos").style.display="none";
    $("div_liste_navigPageBas").style.display="none";
  }
  else{ 
    $("sp_moteur_titreRechercheCarteListe").innerHTML = "Rechercher sur la carte !";
    $("div_entete_infos").style.display="block";
    $("div_liste_navigPageBas").style.display="block";
  }
}

//Fonction pour définir le clic sur le bouton localiser dans la liste 
function setLinkVisuCarto(){
    if (window.iteaGMAP_setElemDeListeClickToVisuCarte)
    iteaGMAP_setElemDeListeClickToVisuCarte({
        callback:function(){
            afficheOngletCarto();
            $("div_listesHeb").scrollTo();
        },
        imgPicto:"/img/punaise.png",
        zoom:10} 
    );
}

function traiteGMap(){  
  if(window.gmap)window.gmap.checkResize();    
  if(window.gmap)window.gmap.resetCentre();
  if(gmap)gmap.reload();
  iteaGMAP_withLstCurr();
  setLinkVisuCarto();
} 


