function oninit1(){
  defBtsOnglets();
  recupVille();
}

function defBtsOnglets(){  
  if($("a_btn_dispoCalendJS")) $("a_btn_dispoCalendJS").observe("click",affTarifsDispos);
  else $("a_tarifsDispo").onclick=function (evt){affOnglet("div_ongletTarifsDispoContent","a_tarifsDispo");};  
  //if($("div_fiche_photoSuppl")) $("a_visuPhotos").onclick=function (evt){affOnglet("div_fiche_photoSuppl","a_visuPhotos");}
  //else $("div_ongletPhotos").style.display="none";
  $("a_locate").onclick=function (evt){affOnglet("div_ongletLocateContent","a_locate");};
  $("a_promo").onclick=function (evt){affOnglet("div_ongletPromoContent","a_promo");};
  if($("ulPromo_details_fiche").innerHTML!="") $("div_ongletPromo").style.display="block";
}

function affOnglet(div,bt){
  if($(div).showing==true){
    Effect.BlindUp(div,{"duration":0.4});      
    $(div).showing=false;
    setClassForObj($(bt),"a_onglet");
  }
  else{
    Effect.BlindDown(div,{"duration":0.6});     
    $(div).showing=true;
    setClassForObj($(bt),"a_ongletOn");
  }
}

function affTarifsDispos(){
  affOnglet("div_ongletTarifsDispoContent","a_btn_dispoCalendJS");
}

/************** **************/
var map;
var gdir;
 function loadItineraire() {
     if (GBrowserIsCompatible()) {      
         map = new GMap2($("div_map_directions"));
         gdir = new GDirections(map,$("div_fiche_directions"));
         GEvent.addListener(gdir, "error", handleErrors);
     }
}
    
function setDirections(fromAddress, toAddress, locale) {
    if (!gdir)loadItineraire();
    gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale,"preserveViewport":false });
    map.setZoom(9);
    map.checkResize();
}

function handleErrors(){
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS ||  gdir.getStatus().code == G_GEO_BAD_REQUEST)$("div_fiche_directions").update("Aucune correspondance g&eacute;ographique trouv&eacute;e");
	else if (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");
}

function affDetailItineraire(){
  if(($("fromAddress").value)||($("fromAddress").value!="Saisir une adresse")){
    $("div_fiche_directions").style.display="block";
    $("div_map_directions").style.display="block";   
    setDirections($('fromAddress').value, $('toAddress').value); 
  }
  else alertAMalibu("Vous devez saisir une adresse de départ pour calculer votre itinéraire !");
}

function recupVille(){
  //spanVille = $("div_fiche_commune").descendants(".sp_lbl_commune").first();  
  if($("div_fiche_commune")) $$(".sp_lbl_commune").each(function(obj){$("toAddress").value = obj.innerHTML;});  
  //if($("div_fiche_commune")) $("toAddress").value = $("div_fiche_commune").lastElementChild.innerHTML;
  else if($("div_fiche_desc19")) $("toAddress").value = $("div_fiche_desc19").lastElementChild.innerHTML;
}
