           
       function getFlashMovieObject(movieName)
       {
       if (navigator.appName.indexOf("Microsoft Internet")!=-1) 
       {
        return window.document[movieName];
        }
        else
        {
        if (document.embeds && document.embeds[movieName])
        return document.embeds[movieName]; 
        }
        }

        function StoreBounds() {
            if (main = getFlashMovieObject('FC_Main')) {
                if (subgurim_GMap1.getZoom() > 2) {
                    main.SetVariable("_root.lat1", subgurim_GMap1.getBounds().getNorthEast().lat());
                    main.SetVariable("_root.lng1", subgurim_GMap1.getBounds().getNorthEast().lng());
                    main.SetVariable("_root.lat2", subgurim_GMap1.getBounds().getSouthWest().lat());
                    main.SetVariable("_root.lng2", subgurim_GMap1.getBounds().getSouthWest().lng());
                } else {
                    main.SetVariable("_root.lat1", 90);
                    main.SetVariable("_root.lng1", 180);
                    main.SetVariable("_root.lat2", -90);
                    main.SetVariable("_root.lng2", -180);
                }
            }
        }
        
       function onFlash(ObjFlash,value) {
                    if(obj=getFlashMovieObject(ObjFlash))
	 {
    	obj.SetVariable("_level0.isOutsideFlash", value);
     }
     }

     function SearchFor(str) {
         var ev = new serverEvent("Search", subgurim_GMap1);
         ev.addArg(str);
         ev.send();     

     }

function ResultGeoCodeD(pt){
    var main=getFlashMovieObject('FC_Main');
    if (pt.Status.code == 200) {
       place = pt.Placemark[0];  
       iti_d = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 
       //subgurim_GMap1.setCenter(point,SelectZoom(place.AddressDetails.Accuracy));
        // StoreBounds();
       if (main) {    
         main.SetVariable("/aide_mc:dlat",place.Point.coordinates[1]);
         main.SetVariable("/aide_mc:dlng",place.Point.coordinates[0]);
       }}
       if (main) {  
        main.TCallLabel("/aide_mc","retourGeoCode");
       }
       }
     
 function ResultGeoCodeA(pt){
    var main=getFlashMovieObject('FC_Main');
    if (pt.Status.code == 200) {
       place = pt.Placemark[0];  
       iti_a = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 
       //subgurim_GMap1.setCenter(point,SelectZoom(place.AddressDetails.Accuracy));
        // StoreBounds();
       if (main) {    
         main.SetVariable("/aide_mc:alat",place.Point.coordinates[1]);
         main.SetVariable("/aide_mc:alng",place.Point.coordinates[0]);
       }}
       if (main) {  
        main.TCallLabel("/aide_mc","retourGeoCode");
       }
       }

function SetItiD(lat,lng) {
 iti_a=new GLatLng(lng,lat);
}

function ViewItineraire() {
    subgurim_GMap1.addOverlay(iti_mkd);
    subgurim_GMap1.addOverlay(iti_mka);
    subgurim_GMap1.addOverlay(iti_pl);
    ShowMk=false;  
    subgurim_GMap1.setCenter(iti_bd.getCenter(),subgurim_GMap1.getBoundsZoomLevel(iti_bd));
          
}
 function CreateItineraire(lg){
        var directions = new GDirections(); 
        var baseIcon = new GIcon();
        baseIcon.iconSize=new GSize(25,25);
        baseIcon.iconAnchor=new GPoint(12,25);
        baseIcon.infoWindowAnchor=new GPoint(10,0);

        var startIcon = (new GIcon(baseIcon, "icones/ico_depart.png", null,""));
        var endIcon = (new GIcon(baseIcon, "icones/ico_arrivee.png", null, ""));

        var arrLocation = new Array(2); 
        arrLocation[0] = iti_d;
        arrLocation[1] = iti_a; 
        var Opts = {"getSteps":true,"getPolyline":true,"locale":lg};//"preserveViewport":true ,
        GEvent.addListener(directions, 'load', function(){
         var main=getFlashMovieObject('FC_Main');
        if (this.getStatus().code==200) {
            ClearItineraire();
            var startPt=this.getRoute(0).getStep(0).getLatLng();
            var endPt=this.getRoute(0).getEndLatLng();
            iti_bd=this.getBounds();
            iti_mka=new GMarker(endPt,endIcon)
            iti_mkd=new GMarker(startPt,startIcon)
            iti_pl =copyPolyline(this.getPolyline());
            var iti_route=new Array(directions.getRoute(0).getNumSteps())
            //iti_route=directions.getRoute(0).getSummaryHtml();
            var txt=new RegExp("<wbr/>","g");
            var txtB=new RegExp("<b>","g");
            iti_route[0]=directions.getRoute(0).getSummaryHtml();
            for (var i=0;i<directions.getRoute(0).getNumSteps();i++) {
              var txt=  directions.getRoute(0).getStep(i).getDescriptionHtml().replace(txt," ").replace(txtB," <b>") + ' - ' + directions.getRoute(0).getStep(i).getDistance().html ;
              iti_route[i+1]=txt+'<br/>';
              }
            if (main) {
                main.SetVariable("/aide_mc:itiOk","OK");
                main.SetVariable("/aide_mc:iti_route_nb",iti_route.length );  
              for (var i=0;i<iti_route.length;i++){  
                main.SetVariable("/aide_mc:iti_route" + i ,iti_route[i]);  
              }  
                main.TCallLabel("/aide_mc","retourIti");  }
             }});
            GEvent.addListener(directions, 'error', function(){
            var main=getFlashMovieObject('FC_Main');
            if (main) {
                main.SetVariable("/aide_mc:itiOk",this.getStatus().code);
                main.TCallLabel("/aide_mc","retourIti");  }
             }); 
        directions.loadFromWaypoints(arrLocation,Opts); 
  
} 

function ClearItineraire() {
    if (iti_mka!=null) { subgurim_GMap1.removeOverlay(iti_mka);iti_mka=null } 
    if (iti_mkd!=null) { subgurim_GMap1.removeOverlay(iti_mkd);iti_mkd=null } 
    if (iti_pl!=null) {subgurim_GMap1.removeOverlay(iti_pl); iti_pl=null}

}
function ResultLocateFL(pt){
    var main=getFlashMovieObject('FC_Main');
    if (pt.Status.code == 200) {
       place = pt.Placemark[0];  
       point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 
       ShowMk=false;
        subgurim_GMap1.setCenter(point,SelectZoom(place.AddressDetails.Accuracy));
         StoreBounds();
       if (main) {    
         main.SetVariable("/rech_mc:localisationOK","true");
       }}
       if (main) {  
        main.TCallLabel("/rech_mc","retourLocalisation");
       //ShowMk=true;  
       }
       }
       
 var mk;
function ResultLocate(pt){
        $get('lbl_rechercherErr').style.visibility='hidden';
        if (pt.Status.code == 200) {

        place = pt.Placemark[0];  
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 
        subgurim_GMap1.setCenter(point,SelectZoom(place.AddressDetails.Accuracy));
        if(place.AddressDetails.Accuracy>=6){
       var baseIcon = new GIcon();
        baseIcon.image = "icones/mark.png";
        baseIcon.iconSize = new GSize(16, 16);
        baseIcon.iconAnchor = new GPoint(8, 8)
          
        markerOptions = { icon:baseIcon }; 
       if (mk != null) {
       subgurim_GMap1.removeOverlay(mk);
       }
       mk=new GMarker(point,markerOptions)
       subgurim_GMap1.addOverlay(mk);
   }
   Wait(false);
        }
        else {
            //SearchFor($get('txt_rechercher').value);
       $get('lbl_rechercherErr').style.visibility='visible';
       }  
        }
 
       
       function SelectZoom(acc){
       switch (acc) {
       case 1 :
       return 6
       break;
       case 2 :
       return 8
       break;
       case 3 :
       return 10
       break;
       case 4 :
       return 13
       break;
       case 5 :
       return 13
       break;
       case 6 :
       return 14
       break;
       case 7 :
       return 14
       break;
       case 8 :
       return 15
       break;
       }
       }

       var src_Map = '';

       function MoveMap(dx, dy) {
           src_Map = 'Bouton'
       subgurim_GMap1.panDirection(dx,dy);
       }

       function ZoomIn() {
           src_Map = 'Bouton'
        subgurim_GMap1.zoomIn(null,false,true);
       }
       function ZoomOut() {
           src_Map = 'Bouton'
        subgurim_GMap1.zoomOut(null,true);
        }

        function MapType(value) {
        
       subgurim_GMap1.setMapType(value);
       }
       
   
function CenterMap(lat,lng,fiche_id) {
    ShowMk=false;
    if (subgurim_GMap1.getZoom()>=12) {
        subgurim_GMap1.panTo(new GLatLng(lat,lng)); }
     else {
        subgurim_GMap1.setCenter(new GLatLng(lat,lng),12);
    }    
    var ev = new serverEvent('AddCenterMk',subgurim_GMap1);
     ev.addArg(lat);
     ev.addArg(lng);
     ev.addArg(fiche_id); 
     ev.send();
}

function FilterMap(cat) {
    Wait(true);
    ShowMk = false;
    var ev = new serverEvent('Filter', subgurim_GMap1);
    ev.addArg(cat);
    ev.send();
}  



function copyPolyline(p) {
	pLinePoints = Array();
	for (var n = 0 ; n < p.getVertexCount() ; n++ ) {
		pLinePoints.push(p.getVertex(n));
	}
	var pLine = new GPolyline(pLinePoints,'#0000AA');
	return pLine;
}
   
  function Wait(value){
    var video=getFlashMovieObject('FC_Video');
  if (video) {    
    if (value) {
            video.TCallLabel("/","Loading");         
    } else {
            video.TCallLabel("/","Loaded");
    } }}
  
        
       var videos=new Array();
       var textes=new Array();
       var liens=new Array();
       var photos=new Array();
       var idxphoto=0;
       var idxvideo=0;
       var isvideo=0;
       function ShowVideo(){
            if (idxvideo>=videos.length) { idxvideo=0}
            $get('img_video').src=videos[idxvideo];
            $get('btn_play').title=textes[idxvideo];
            $get('lbl_video').innerHTML=textes[idxvideo];
            $get('btn_play').href=liens[idxvideo];
            idxvideo++;
         }
       
       function NextPhoto(idx) {
       idxphoto+=idx;
       if (idxphoto>=photos.length) { idxphoto=0 }
       if (idxphoto<0) {idxphoto=photos.length-1}
       
       $get('img_Photo').src=photos[idxphoto];
       $get('txt_PhotoC').innerHTML=idxphoto+1;
       }
       
        function AfficheVideo(){
        var video=getFlashMovieObject('FC_Video');
       var cnt= subgurim_GMap1.getCenter();
       if (cnt && video) {
        video.SetVariable("/:vLat",cnt.lat());
        video.SetVariable("/:vLon",cnt.lng()); 
       video.TCallLabel("/","majVideo");          
       var news=getFlashMovieObject('FC_News');
       news.SetVariable("/:vLat",cnt.lat());
       news.SetVariable("/:vLon",cnt.lng()); 
       news.TCallLabel("/","majNews");          
       }}
       
       
        //Evenement Serveur pour l'affichage des Markers
        var ShowMk=true;
        function AfficheMarker(){
        if (ShowMk){
        Wait(true);
        var ev = new serverEvent('GetMk',subgurim_GMap1);
        ev.send();
        var video=getFlashMovieObject('FC_Video');
       var cnt= subgurim_GMap1.getCenter();
       if (cnt && video) {
        video.SetVariable("/:vLat",cnt.lat());
        video.SetVariable("/:vLon",cnt.lng()); 
       video.TCallLabel("/","majVideo");          
       var news=getFlashMovieObject('FC_News');
       news.SetVariable("/:vLat",cnt.lat());
       news.SetVariable("/:vLon",cnt.lng()); 
       news.TCallLabel("/","majNews");          
       }}
       }
       
       
       function ShowFiche(idfiche){
        if(main=getFlashMovieObject('FC_Main')) {
            main.SetVariable("aouvrir","fiche");
            main.SetVariable("ficheaouvrir",idfiche);
            main.TCallLabel("/","ouvrir");        
       } else {
         var ev = new serverEvent("ShowFiche",subgurim_GMap1);
        ev.addArg(idfiche);
        ev.send();     
       }}
       
       function DragMarker(fiche,point)  {
       var ev = new serverEvent(fiche,subgurim_GMap1);
       ev.addArg(point.lat());
       ev.addArg(point.lng());
       ev.send();
       } 
       
       function ResizePanel(pn,w,h) {
            var obj=$get(pn);
            obj.style.height=h;
            obj.style.width=w;
        }
       function ResizePanelNews(w,h) {
            var obj=$get('PN_News');
            obj.style.height=h;
            obj.style.width=w;
        }
       
    function ResizeControl(pn) {
    var obj=$get(pn);
  if (obj.style.left=="") {obj.style.left="0px;"}  
    if (obj.style.left=="0px") {
      obj.style.left="-60px";  }
     else {  
     obj.style.left="0px"; }
}

function GetCodeVille(source, eventArgs) {
    $get("ctl00_ContentPlaceHolder1_HF_Ville_ID").value = eventArgs.get_value();
}

function TrackResa(pays, fiche) {
    pageTracker._trackEvent('Reservation', pays, fiche);
   }

//var directions; 
//function init_ini() {
//directions = new GDirections(subgurim_GMap1);
//directions.load("from: Chavanod to: Rumilly");
//}

 

       /*
pour l'ouverture du login :
main.SetVariable("aouvrir","login");
main.TCallLabel("/","ouvrir");

pour l'ouverture d'une fiche :
main.SetVariable("aouvrir","fiche");
main.SetVariable("ficheaouvrir","36f59d4e-5fe2-11d5-950c-004005676e64");
main.TCallLabel("/","ouvrir");


pour l'ouverture du login au chargement :
eexpand = "login"

pour l'ouverture d'une fiche au chargement :
eexpand = "fiche"
ficheaouvrir = "36f59d4e-5fe2-11d5-950c-004005676e64"
*/