function oninit(){
  refreshCalDateArr();
  if($('div_moteurRechercheTarif')) appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",setChmpPrixToReglette);
  if($("inpt_g")) tarif_chambre();     
  if($("div_contenu_menuMoteurRecherche")) actualiseVilleProxCommune();
  if($("div_contenu_menuMoteurRecherche")){
    if($("select_villeProx").value!="") actualiseCommune();
  }
}

function clicCalendJs(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+mois+annee;
  afficheEffaceCalendJsMenu("calendrierMoteur");
}

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

function lanceRechercheCarto(form){
  document.location.href='/liste?'+getQueryStringByForm($(form))+'#js:afficheOngletCarte()';
}

function rechercheAjax(){
  if($("inpt_g").checked==true || $("inpt_t").checked==true || $("inpt_c").checked==true) pasChambre();
  if($("inpt_ANI").checked==true){
	var deb = $("inpt_dateDeb").value;
	if(deb != '' ){
		var year = deb.substring((deb.length-4));
		if(year>2011){
			$("inpt_ANI").value="G";
		} else {
			$("inpt_ANI").value="O";
		}
	} else {
		$("inpt_ANI").value="O";
	}
  }
  setListByForm($('form_moteurRecherche'));  
}

function pasChambre(){
  $("inpt_table").checked=false;
  $("inpt_chF").checked=false;
  $("div_critsChambre").style.display="none";
}
                       
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_moteurRecherche'));         
          }
        });
       }
}

function refreshCalDateArr(){
	if ($("calendrierMoteur")){
		if($("inpt_h").checked){
			setCalendrierGeneral("gites21","1","","H","calendrierMoteur",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		}
		else{
			setCalendrierGeneral("gites21","1","","G","calendrierMoteur",clicCalendJs,"inpt_dateDeb","","","lst_nbj","1","");
		}
	}
}

function tarif_chambre(){
  if($("div_moteurRechercheTarif")){
    if(($("inpt_g").checked)){
      $("div_moteurRechercheTarif").style.visibility="visible";
    }else{
      $("div_moteurRechercheTarif").style.visibility="hidden";
    }
  }
}

function valideInscNews(){
    envoiMailByAjaxByForm('frm_newsletter','mesg_replace',false);
}

function envoiFormDeContact(){
  envoiMailByAjaxByForm("frm_contact","div_contact_form",true);
}

function bourgogneEnImage(){
  var html = "<a href='#ferme' id='a_fermeBgImage' class=\"fermePopIn\" onclick='effaceDivAvecTransparence();'>Fermer</a>";
  html += "<iframe name=\"ifrm_bgImage\" id=\"ifrm_bgImage\" src=\"http://www.cotedor-tourisme.com/balade.php\" border=\"0\" frameborder=\"0\"></iframe>";
  if(document.documentElement.clientHeight>=680) afficheDivAvecTransparence(html,750,670);
  else document.location.href="/bourgogne-en-image.html";
}

function defBtBgImage(){
  $$(".a_btBgImage").each(function(obj){obj.onclick=function(evt){bourgogneEnImage();}});
}

function actualiseVilleProxCommune(){
  var acc = "";
  $$(".chk_acc").each(function(obj){
    if(obj.checked==true){
      if(acc=="") acc = obj.value;
      else acc += ","+obj.value;
    } 
  });
  appelAjaxToFunc("/config_v3/21/G.v3/GDFv4.FRANCAIS/librairie/bloc_html/villeProxEtCommunes.php","REG="+$("lst_region").value+"&INFOTOUR="+$("lst_infotour").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;
    
    var indiceProx = 0;
    var selectedProx = 0;
    $("lst_chefLieu").options.length=0;
    $("lst_chefLieu").options[$("lst_chefLieu").options.length] = new Option("Indifférent");
    $("lst_chefLieu").options[$("lst_chefLieu").options.length-1].value="";
    $A(tab.villeprox).each(function(obj){
      $("lst_chefLieu").options[$("lst_chefLieu").options.length] = new Option(obj);
      $("lst_chefLieu").options[$("lst_chefLieu").options.length-1].value=obj;
      indiceProx++;
      if(obj==$("select_villeProx").value) selectedProx=indiceProx;
    });
    $("lst_chefLieu").selectedIndex = selectedProx;
  });
}

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/21/G.v3/GDFv4.FRANCAIS/librairie/bloc_html/villeProxEtCommunes.php","REG="+$("lst_region").value+"&INFOTOUR="+$("lst_infotour").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("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 defVilleProx(){
  $("select_villeProx").value = $("lst_chefLieu").value;
}
function defCommune(){
  $("select_commune").value = $("lst_commune").value;
}

function valideContact(){
  $("inpt_expediteur").value=$("inpt_mail").value;
  checkForm($('frm_contact'),envoiFormDeContact);
}

