function oninit(){
  if($("div_moteurMenu")) initSidebar();
  //if($("calendrierMenu")) setCalendrierGeneral("gites33","1","","","calendrierMenu",clicCalendJsMenu,"inpt_dateDeb","","","lst_nbj","1","");
  refreshCalDateArr();
  verifNavigateur();
}

/*bulle bleu menu*/
function afficheBulle(nomDiv){
    $(nomDiv).style.display="block";
}
function effaceBulle(nomDiv){
    $(nomDiv).style.display="none";
}
// fin bulle

// Calendrier JS
function afficheEffaceCalendJs(nomDiv){
  if($(nomDiv).showing==true){
    Effect.BlindUp(nomDiv);       
    $(nomDiv).showing=false;
  }
  else{
    Effect.BlindDown(nomDiv);       
    $(nomDiv).showing=true;
  }
}
function clicCalendJsMenu(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+mois+annee;
  afficheEffaceCalendJs("calendrierMenu")
}
// fin calend JS


/* IE6 hover sur les li */
metabarre_sfHover = function() {
 if ($("ul_menuHaut") != null) {
 var sfEls = $("ul_menuHaut").getElementsByTagName("LI");
 for (var i=0; i<sfEls.length; i++) {
  sfEls[i].onmouseover=function() {
  this.className+=" sfhover";
 }
   sfEls[i].onmouseout=function() {
   this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
 }
 }
 }
}
if (window.attachEvent) window.attachEvent("onload", metabarre_sfHover);


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


function setChmpPrixToReglette(reponse){
    
    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);
      
      if (!pxMini)pxMini=0;
      if ((!pxMaxi && !pxMini) || (!$("inpt_g").checked && !$("inpt_t").checked)){
      	$("div_moteurMenu_budget").hide();
      }else{
      
      		$("div_moteurMenu_budget").show();
	      $("infoPrix_prixMiniMontant").innerHTML=pxMini;
	      $("infoPrix_prixMaxiMontant").innerHTML=pxMaxi;
      
	      for (var i=0;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_prixMiniMontant").innerHTML=values[0];
	            $("infoPrix_prixMaxiMontant").innerHTML=values[1];
	          },
	          onChange: function(values) { 
	            if (!window.pxmin || window.pxmin!=values[0] || window.pxmax!=values[1]){
                        window.pxmin=values[0];
                        window.pxmax=values[1];
                        $("inpt_pxmini").value=values[0];
                        $("inpt_pxmaxi").value=values[1];
                        setListByForm($('frmMoteurGeneral'));
                    }        
	          }
	        });
	       }
	}
}
function setActionSurMenuHaut_avant(){
  
  for(var i=1;i<=6;i++){
    var objOnglet=document.getElementById("li_item-"+i);
    var objDiv=document.getElementById("elem_lst_lien_bouton_4_"+(i-1));
    objOnglet.objDiv=objDiv;
    
    objOnglet.onmouseover = function (evt){
      this.objDiv.style.visibility="visible";
    }
    objOnglet.onmouseout = function (evt){
      this.objDiv.style.visibility="hidden";
    }
    objDiv.onmouseover = function (evt){
      this.style.visibility="visible";
    }
    objDiv.onmouseout = function (evt){
      this.style.visibility="hidden";
    }
  }
}
  

  

function setActionSurMenuHaut(){
  

  $$("li.li_item").each(function(item){
    var idTime;
    var idMenu="elem_lst_lien_bouton_4_"+(parseInt(item.id.split("-")[1])-1);
    
    item.observe("mouseover",function(evt){
      $(idMenu).style.visibility="visible";
    });
    item.observe("mouseout",function(evt){
      idTime=setTimeout("$('"+idMenu+"').style.visibility='hidden'",1000);
    });
    $(idMenu).observe("mouseover",function(evt){
      clearTimeout(idTime);
    });
    $(idMenu).observe("mouseout",function(evt){
      idTime=setTimeout("$('"+idMenu+"').style.visibility='hidden'",1000);
    });
    
  
  });
}
 
 function initSidebar(){
      affichePrefChambre();
      appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE",setChmpCommuneAutoCompleter);
     

     /**** recherche avancee ****/
     $("div_rechercheAvanceeCrit").hide();
     $("sp_titreRechercheAvancee").onclick=function (evt){
          if (this.showing){
             Effect.BlindUp('div_rechercheAvanceeCrit'); 
             this.showing=false;
         }else{
             Effect.BlindDown('div_rechercheAvanceeCrit'); 
             appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",setChmpPrixToReglette);
             this.showing=true;
         }
         return false;
     }

}

function affichePrefChambre(){
  if(($("inpt_h"))&&($("inpt_h").checked)){
    $("div_prefChb").style.display="block";
  }
  else{
    $("div_prefChb").style.display="none";
    $("inpt_crit4").checked=false;
    $("inpt_crit5").checked=false;
  }
}

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'));
}
 
 
 /*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
/*                      Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}}); */
						Effect.toggle(tempc,'appear',{queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
/*          Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}}); */
            Effect.toggle('tabContent'+num,'appear',{queue:{scope:'menus', position:'end', limit: 3}});  
		}else{
            toggleDisp('tabContent'+num);
        }
    }
}

function changeNbj(obj){
    if($("inpt_dateDeb").value!=""){
        setParamCgiEtRefreshList("DEB="+$("inpt_dateDeb").value+'&amp;NBJ='+obj.value);
    }else{
        alertAMalibu('Vous devez d&#39;abord choisir une date');
    }
}

function initForColorisByTab(tabInfos){
    $A(tabInfos).each(function(elem){
        var html='<object width="100%" height="500" type="application/x-shockwave-flash" ';
        html+='data="http://apps.cooliris.com/embed/cooliris.swf" style="visibility: visible;">';
        html+='<param name="allowscriptaccess" value="always"/>';
        html+='<param name="flashvars" value="feed=api://www.flickr.com/?album='+elem.idAlbum+'&amp;numRows=3&amp;style=light"/></object>';

        $(elem.idObj).insert(html);
    });

    return true;
}

function lanceRechercheNumero(){
  $('inpt_refGite_NUM').value=$('inpt_refGite').value;
  document.location.href="/liste?"+getQueryStringByForm($('frm_numStruct'));
}
function refreshCalDateArr(){
	if ($("calendrierMenu")){
		if($("inpt_h").checked){
	//		$("lst_nbj").value="1";
			setCalendrierGeneral("gites33","1","","H","calendrierMenu",clicCalendJsMenu,"inpt_dateDeb","","","lst_nbj","1","");
		}
		else{
	//		$("lst_nbj").value="7";
			setCalendrierGeneral("gites33","1","","G","calendrierMenu",clicCalendJsMenu,"inpt_dateDeb","","","lst_nbj","1","");
		}
	}
}
function verifNavigateur(){//<== lancer cette fonction dans le Onload du body
        if (getVersionIE()<7){
                new Effect.BlindDown('div_avertissement', 1);
        }
}

function masquerAvertissement(){
        new Effect.BlindUp('div_avertissement', 1);
}
