function oninit1(){
  appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCOMMUNE&val=G",window.setChmpCommuneAutoCompleter);
  //appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=PRIXMINIMAXI",window.setChmpPrixToReglette);
  defActionOngletsFiche();
  masqueOnglet();
  ongletAfficheDepart();
  loadItineraire();
}

function ongletAfficheDepart(){
  if($("div_fiche_detailPromo"))afficheOngletPromos();
  else afficheOngletTarifs();
}

/****************** Masque les onglets inutiles dans la fiche ***************************/
function masqueOnglet(){
  if(!$("div_fiche_rubriques"))$("li_ongletThematique").style.display="none";
  if(!$("div_fiche_infosTouri"))$("li_ongletSitesTouri").style.display="none";
  if(!$("div_fiche_tarif"))$("li_ongletTarifs").style.display="none";
  if(!$("div_fiche_detailPromo"))$("li_ongletPromo").style.display="none";
  if(!$("div_fiche_distance_lbl"))$("li_ongletLoisirs").style.display="none";
  if(!$("div_fiche_planInterieur"))$("li_ongletPlan").style.display="none";
  //if(!$("div_fiche_btnDispo_v2"))$("li_ongletDispos").style.display="none";
  if(!$("div_fiche_acces"))$("li_ongletAcces").style.display="none";
  if(!$("div_fiche_youtube"))$("li_ongletVideo").style.display="none";  
  if(!$("div_fiche_youtube"))$("div_fiche_btvideo").style.display="none";
  if(!$("div_fiche_planInterieur"))$("div_fiche_pictoPlan").style.display="none";
}

/****************** Definissions des actions de clic sur les onglets ***************************/
function afficheOngletRubriques(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="block";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFicheOn");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletSitesTouri(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="block";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFicheOn");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletLoisirs(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="block";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFicheOn");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletTarifs(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="block";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFicheOn");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletPromos(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="block";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFicheOn");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletDispos(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="block";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFicheOn");  
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletPlan(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="block";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
    if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
    if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFicheOn");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");  
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
}

function afficheOngletAcces(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="block";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="none";
  
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFicheOn");  
  setClassForObj($("li_ongletVideo"),"li_ongletFiche");
  
  if (window.map){
       setDirections("Paris", $("toAddress").value, "fr_FR");
  }
}

function afficheOngletVideo(){
  if($("div_fiche_rubriques"))$("div_fiche_rubriques").style.display="none";
  if($("div_fiche_infosTouri"))$("div_fiche_infosTouri").style.display="none";
  if($("div_fiche_tarif"))$("div_fiche_tarif").style.display="none";
  if($("div_fiche_detailPromo"))$("div_fiche_detailPromo").style.display="none";
  if($("div_fiche_distance_lbl"))$("div_fiche_distance_lbl").style.display="none";
  if($("div_fiche_planInterieur"))$("div_fiche_planInterieur").style.display="none";
  if($("div_fiche_calendrierDispo"))$("div_fiche_calendrierDispo").style.display="none";
  if($("div_fiche_acces"))$("div_fiche_acces").style.display="none";
  if($("div_fiche_youtube"))$("div_fiche_youtube").style.display="block";  
  
  
  setClassForObj($("li_ongletThematique"),"li_ongletFiche");
  setClassForObj($("li_ongletSitesTouri"),"li_ongletFiche");
  setClassForObj($("li_ongletTarifs"),"li_ongletFiche");
  setClassForObj($("li_ongletPromo"),"li_ongletFiche");
  setClassForObj($("li_ongletLoisirs"),"li_ongletFiche");
  setClassForObj($("li_ongletPlan"),"li_ongletFiche");
  //setClassForObj($("li_ongletDispos"),"li_ongletFiche");
  setClassForObj($("li_ongletAcces"),"li_ongletFiche");  
  setClassForObj($("li_ongletVideo"),"li_ongletFicheOn");  
}



function defActionOngletsFiche(){
 if($("li_ongletThematique"))$("li_ongletThematique").onclick=function (evt){afficheOngletRubriques();}  
 if($("li_ongletSitesTouri"))$("li_ongletSitesTouri").onclick=function (evt){afficheOngletSitesTouri();}  
 if($("li_ongletTarifs"))$("li_ongletTarifs").onclick=function (evt){afficheOngletTarifs();}  
 if($("li_ongletPromo"))$("li_ongletPromo").onclick=function (evt){afficheOngletPromos();}  
 if($("li_ongletLoisirs"))$("li_ongletLoisirs").onclick=function (evt){afficheOngletLoisirs();}  
 if($("li_ongletPlan"))$("li_ongletPlan").onclick=function (evt){afficheOngletPlan();}    
 //if($("li_ongletDispos"))$("li_ongletDispos").onclick=function (evt){afficheOngletDispos();}
 if($("li_ongletAcces"))$("li_ongletAcces").onclick=function (evt){afficheOngletAcces();}
 if($("li_ongletVideo"))$("li_ongletVideo").onclick=function (evt){afficheOngletVideo();}        
}

function setCGIForLstCommune(li){
    if ( navigator.appName == 'Microsoft Internet Explorer' ){
      var infos=li.innerText.split("(");
    }
    else{
      var infos=li.textContent.split("(");
    }
    document.getElementById("inpt_ville").value=infos[0];
    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=infos[0];
    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+")");
    }
    
    /**** 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);
      
      $("infoPrix_prixMini").innerHTML=pxMini+"&nbsp;&euro;";
      $("infoPrix_prixMaxi").innerHTML=pxMaxi+"&nbsp;&euro;";
      
      for (var i=pxMini;i<=3000;i+=25)vals.push(i);
      new Control.Slider(reglette.select('.handle'), reglette, {
          range: $R(0, 3000),
          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($('frmMoteurGeneral'));         
          }
        });
       }
}
*/
/************** Plan d'acces googlemap **************/
 function loadItineraire() {
     if (GBrowserIsCompatible()) {      
         window.map = new GMap2($("div_map_directions"));
         window.gdir = new GDirections(map,$("div_fiche_directions"));
         GEvent.addListener(window.gdir, "error", handleErrors);
         setDirections("Paris", $("toAddress").value, "fr_FR");
     }
}
    
function setDirections(fromAddress, toAddress, locale) {
    window.gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale,"preserveViewport":false });
    window.map.setZoom(9);
    window.map.checkResize();
}

function handleErrors(){
    if (window.gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS ||  window.gdir.getStatus().code == G_GEO_BAD_REQUEST)$("div_fiche_directions").update("Aucune correspondance g&eacute;ographique trouv&eacute;e");
	else if (window.gdir.getStatus().code == G_GEO_SERVER_ERROR)$("div_fiche_directions").update("Serveur de g&eacute;olocalisation non disponible");
	     else $("div_fiche_directions").update("Une erreur est survenue");
}
