/* {/agences/js/markermanager.js,/agences/js/Z_map.js,/agences/js/map.directions.js} */
function MarkerManager(d,e){var b=this;b.map_=d;b.mapZoom_=d.getZoom();b.projection_=d.getCurrentMapType().getProjection();e=e||{};b.tileSize_=MarkerManager.DEFAULT_TILE_SIZE_;var a=MarkerManager.DEFAULT_MAX_ZOOM_;if(e.maxZoom!=undefined){a=e.maxZoom}b.maxZoom_=a;b.trackMarkers_=e.trackMarkers;var c;if(typeof e.borderPadding=="number"){c=e.borderPadding}else{c=MarkerManager.DEFAULT_BORDER_PADDING_}b.swPadding_=new GSize(-c,c);b.nePadding_=new GSize(c,-c);b.borderPadding_=c;b.gridWidth_=[];b.grid_=[];b.grid_[a]=[];b.numMarkers_=[];b.numMarkers_[a]=0;GEvent.bind(d,"moveend",b,b.onMapMoveEnd_);b.removeOverlay_=function(f){d.removeOverlay(f);b.shownMarkers_--};b.addOverlay_=function(f){d.addOverlay(f);b.shownMarkers_++};b.resetManager_();b.shownMarkers_=0;b.shownBounds_=b.getMapGridBounds_()}MarkerManager.DEFAULT_TILE_SIZE_=1024;MarkerManager.DEFAULT_MAX_ZOOM_=17;MarkerManager.DEFAULT_BORDER_PADDING_=100;MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE=256;MarkerManager.prototype.resetManager_=function(){var c=this;var a=MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE;for(var b=0;b<=c.maxZoom_;++b){c.grid_[b]=[];c.numMarkers_[b]=0;c.gridWidth_[b]=Math.ceil(a/c.tileSize_);a<<=1}};MarkerManager.prototype.clearMarkers=function(){var a=this;a.processAll_(a.shownBounds_,a.removeOverlay_);a.resetManager_()};MarkerManager.prototype.getTilePoint_=function(d,b,c){var a=this.projection_.fromLatLngToPixel(d,b);return new GPoint(Math.floor((a.x+c.width)/this.tileSize_),Math.floor((a.y+c.height)/this.tileSize_))};MarkerManager.prototype.addMarkerBatch_=function(c,g,b){var f=c.getPoint();if(this.trackMarkers_){GEvent.bind(c,"changed",this,this.onMarkerMoved_)}var d=this.getTilePoint_(f,b,GSize.ZERO);for(var e=b;e>=g;e--){var a=this.getGridCellCreate_(d.x,d.y,e);a.push(c);d.x=d.x>>1;d.y=d.y>>1}};MarkerManager.prototype.isGridPointVisible_=function(b){var f=this;var d=f.shownBounds_.minY<=b.y&&b.y<=f.shownBounds_.maxY;var a=f.shownBounds_.minX;var c=a<=b.x&&b.x<=f.shownBounds_.maxX;if(!c&&a<0){var e=f.gridWidth_[f.shownBounds_.z];c=a+e<=b.x&&b.x<=e-1}return d&&c};MarkerManager.prototype.onMarkerMoved_=function(e,a,c){var g=this;var i=g.maxZoom_;var d=false;var b=g.getTilePoint_(a,i,GSize.ZERO);var f=g.getTilePoint_(c,i,GSize.ZERO);while(i>=0&&(b.x!=f.x||b.y!=f.y)){var h=g.getGridCellNoCreate_(b.x,b.y,i);if(h){if(g.removeFromArray(h,e)){g.getGridCellCreate_(f.x,f.y,i).push(e)}}if(i==g.mapZoom_){if(g.isGridPointVisible_(b)){if(!g.isGridPointVisible_(f)){g.removeOverlay_(e);d=true}}else{if(g.isGridPointVisible_(f)){g.addOverlay_(e);d=true}}}b.x=b.x>>1;b.y=b.y>>1;f.x=f.x>>1;f.y=f.y>>1;--i}if(d){g.notifyListeners_()}};MarkerManager.prototype.removeMarker=function(c){var f=this;var e=f.maxZoom_;var g=false;var b=c.getPoint();var d=f.getTilePoint_(b,e,GSize.ZERO);while(e>=0){var a=f.getGridCellNoCreate_(d.x,d.y,e);if(a){f.removeFromArray(a,c)}if(e==f.mapZoom_){if(f.isGridPointVisible_(d)){f.removeOverlay_(c);g=true}}d.x=d.x>>1;d.y=d.y>>1;--e}if(g){f.notifyListeners_()}};MarkerManager.prototype.addMarkers=function(d,e,c){var a=this.getOptMaxZoom_(c);for(var b=d.length-1;b>=0;b--){this.addMarkerBatch_(d[b],e,a)}this.numMarkers_[e]+=d.length};MarkerManager.prototype.getOptMaxZoom_=function(a){return a!=undefined?a:this.maxZoom_};MarkerManager.prototype.getMarkerCount=function(b){var a=0;for(var c=0;c<=b;c++){a+=this.numMarkers_[c]}return a};MarkerManager.prototype.addMarker=function(b,f,d){var e=this;var a=this.getOptMaxZoom_(d);e.addMarkerBatch_(b,f,a);var c=e.getTilePoint_(b.getPoint(),e.mapZoom_,GSize.ZERO);if(e.isGridPointVisible_(c)&&f<=e.shownBounds_.z&&e.shownBounds_.z<=a){e.addOverlay_(b);e.notifyListeners_()}this.numMarkers_[f]++};GBounds.prototype.containsPoint=function(a){var b=this;return(b.minX<=a.x&&b.maxX>=a.x&&b.minY<=a.y&&b.maxY>=a.y)};MarkerManager.prototype.getGridCellCreate_=function(a,f,e){var c=this.grid_[e];if(a<0){a+=this.gridWidth_[e]}var b=c[a];if(!b){b=c[a]=[];return b[f]=[]}var d=b[f];if(!d){return b[f]=[]}return d};MarkerManager.prototype.getGridCellNoCreate_=function(a,e,d){var c=this.grid_[d];if(a<0){a+=this.gridWidth_[d]}var b=c[a];return b?b[e]:undefined};MarkerManager.prototype.getGridBounds_=function(a,i,h,f){i=Math.min(i,this.maxZoom_);var b=a.getSouthWest();var e=a.getNorthEast();var g=this.getTilePoint_(b,i,h);var d=this.getTilePoint_(e,i,f);var j=this.gridWidth_[i];if(e.lng()<b.lng()||d.x<g.x){g.x-=j}if(d.x-g.x+1>=j){g.x=0;d.x=j-1}var c=new GBounds([g,d]);c.z=i;return c};MarkerManager.prototype.getMapGridBounds_=function(){var a=this;return a.getGridBounds_(a.map_.getBounds(),a.mapZoom_,a.swPadding_,a.nePadding_)};MarkerManager.prototype.onMapMoveEnd_=function(){var a=this;a.objectSetTimeout_(this,this.updateMarkers_,0)};MarkerManager.prototype.objectSetTimeout_=function(b,c,a){return window.setTimeout(function(){c.call(b)},a)};MarkerManager.prototype.refresh=function(){var a=this;if(a.shownMarkers_>0){a.processAll_(a.shownBounds_,a.removeOverlay_)}a.processAll_(a.shownBounds_,a.addOverlay_);a.notifyListeners_()};MarkerManager.prototype.updateMarkers_=function(){var a=this;a.mapZoom_=this.map_.getZoom();var b=a.getMapGridBounds_();if(b.equals(a.shownBounds_)&&b.z==a.shownBounds_.z){return}if(b.z!=a.shownBounds_.z){a.processAll_(a.shownBounds_,a.removeOverlay_);a.processAll_(b,a.addOverlay_)}else{a.rectangleDiff_(a.shownBounds_,b,a.removeCellMarkers_);a.rectangleDiff_(b,a.shownBounds_,a.addCellMarkers_)}a.shownBounds_=b;a.notifyListeners_()};MarkerManager.prototype.notifyListeners_=function(){GEvent.trigger(this,"changed",this.shownBounds_,this.shownMarkers_)};MarkerManager.prototype.processAll_=function(b,d){for(var a=b.minX;a<=b.maxX;a++){for(var c=b.minY;c<=b.maxY;c++){this.processCellMarkers_(a,c,b.z,d)}}};MarkerManager.prototype.processCellMarkers_=function(b,f,d,e){var a=this.getGridCellNoCreate_(b,f,d);if(a){for(var c=a.length-1;c>=0;c--){e(a[c])}}};MarkerManager.prototype.removeCellMarkers_=function(a,c,b){this.processCellMarkers_(a,c,b,this.removeOverlay_)};MarkerManager.prototype.addCellMarkers_=function(a,c,b){this.processCellMarkers_(a,c,b,this.addOverlay_)};MarkerManager.prototype.rectangleDiff_=function(b,a,d){var c=this;c.rectangleDiffCoords(b,a,function(e,f){d.apply(c,[e,f,b.z])})};MarkerManager.prototype.rectangleDiffCoords=function(b,a,l){var f=b.minX;var m=b.minY;var h=b.maxX;var d=b.maxY;var e=a.minX;var k=a.minY;var g=a.maxX;var c=a.maxY;for(var j=f;j<=h;j++){for(var i=m;i<=d&&i<k;i++){l(j,i)}for(var i=Math.max(c+1,m);i<=d;i++){l(j,i)}}for(var i=Math.max(m,k);i<=Math.min(d,c);i++){for(var j=Math.min(h+1,e)-1;j>=f;j--){l(j,i)}for(var j=Math.max(f,g+1);j<=h;j++){l(j,i)}}};MarkerManager.prototype.removeFromArray=function(e,c,d){var a=0;for(var b=0;b<e.length;++b){if(e[b]===c||(d&&e[b]==c)){e.splice(b--,1);a++}}return a};
function ClusterMarker(a,b,c){this.point_=a;this.title_=c;this.bounds_=b}ClusterMarker.prototype=new GOverlay();ClusterMarker.prototype.initialize=function(a){var b=document.createElement("div");$(b).addClass("clustermarker").attr("title",this.title_).css("cursor","pointer").tooltip({extraClass:"gmaps_tooltip",track:false,delay:0,showURL:false,showBody:" - "});a.getPane(G_MAP_MAP_PANE).appendChild(b);this.map_=a;this.div_=b;GEvent.bindDom(this.div_,"mouseover",this,this.onMouseOver);GEvent.bindDom(this.div_,"mouseout",this,this.onMouseOut)};ClusterMarker.prototype.onMouseOver=function(){this.map_.last_cluster=this};ClusterMarker.prototype.onMouseOut=function(){this.map_.last_cluster=null};ClusterMarker.prototype.getPoint=function(){return this.point_};ClusterMarker.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_);if(this.map_.last_cluster==this){this.map_.last_cluster=null;$("#tooltip").hide()}};ClusterMarker.prototype.copy=function(){return new ClusterMarker(this.point_,this.bounds_,this.title_)};ClusterMarker.prototype.redraw=function(c){if(!c){return}var b=this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());var a=this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());this.div_.style.width=Math.max(0,Math.abs(a.x-b.x)-2)+"px";this.div_.style.height=Math.max(0,Math.abs(a.y-b.y)-2)+"px";this.div_.style.left=Math.min(a.x,b.x)+"px";this.div_.style.top=Math.min(a.y,b.y)+"px"};GPolygon.prototype.Contains=function(b){if(!this.getBounds().containsLatLng(b)){return false}var c=0;var e=false;var a=b.lng();var f=b.lat();for(var d=0;d<this.getVertexCount();d++){c++;if(c==this.getVertexCount()){c=0}if(((this.getVertex(d).lat()<f)&&(this.getVertex(c).lat()>=f))||((this.getVertex(c).lat()<f)&&(this.getVertex(d).lat()>=f))){if(this.getVertex(d).lng()+(f-this.getVertex(d).lat())/(this.getVertex(c).lat()-this.getVertex(d).lat())*(this.getVertex(c).lng()-this.getVertex(d).lng())<a){e=!e}}}return e};GPolygon.prototype.getPoint=function(){return this.getBounds().getCenter()};function HtmlControl(b,a){this._html=b;this._opts={isPrintable:false,isSelectable:false,isVisible:true};$.extend(this._opts,a);this.show=function(){if(!this._opts.isVisible){$(this._div).show();this._opts.isVisible=true}};this.hide=function(){if(this._opts.isVisible){$(this._div).hide();this._opts.isVisible=false}}}HtmlControl.prototype=new GControl();HtmlControl.prototype.initialize=function(a){this.selectable=function(){return this._opts.isSelectable};this.printable=function(){return this._opts.isPrintable};this._div=document.createElement("div");$(this._div).append(this._html);a.getContainer().appendChild(this._div);return this._div};HtmlControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,7))};function createZoomControl(){var a=$('<img class="fixpng" src="/imgs/maps/zoomcontrol.png"/>');var b=$("<div></div>").append(a);b.append('<div id="zoomfrance" title="'+libelles.zoomfrance+'"></div>');b.append('<div id="zoomagences" title="'+libelles.recentrercarte+'"></div>');b.append('<div id="resetmap" title="'+libelles.reinitcarte+'"></div>');$("div",b).css({position:"absolute",cursor:"pointer",left:"9px",width:"18px",height:"18px",backgroundColor:"white",opacity:0});$("#zoomfrance",b).css("top","2px");$("#zoomagences",b).css("top","20px");$("#resetmap",b).css("top","38px");return new HtmlControl(b)}GMap2.prototype.boundTo=function(b,c){if(typeof(c)!="number"){c=0}var a=this.getBoundsZoomLevel(b)+c;if(a!=this.getZoom()){this.setCenter(b.getCenter(),a)}else{this.panTo(b.getCenter())}};var max_zoom_regions=-1;var max_zoom_clustering=-1;var map;var mgr;var geocoder;var timeout;var regions=[];var gicons=[];var icon;var recherche_markers=[];var directions=null;var loader_control=null;var loader_status={ajax:false,geocoder:false,directions:false};var zoom_control=null;var libelles={};var agencesBounds=new GLatLngBounds();$(function(){$.ifixpng("/imgs/maps/pixel.gif");if(GBrowserIsCompatible()){$(window).unload(GUnload);$("#panel").tabs({disabled:[1]});if($("#options select").length<1){$("#options").hide()}$("#options form").hide();$("#options h2").click(function(){$("#options form").slideToggle();$(this).toggleClass("opened")});$("#mapsplitter").click(function(){var c=parseInt($("#map").css("margin-left"));if($("#panel").is(":visible")){$("#panel").addClass("gmnoscreen");$("#map").css("margin-left",c+$(this).width()-$("#panel").width());$(this).addClass("collapsed")}else{$("#panel").removeClass("gmnoscreen");$("#map").css("margin-left",c-$(this).width()+$("#panel").width());$(this).removeClass("collapsed")}map.checkResize()}).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});$("#masthead > * ").not("#logo_print").addClass("gmnoprint");$("#bloc_central > * ").not("#contenu").addClass("gmnoprint");$("#google_maps > *").not("#description_itineraire").addClass("gmnoprint");map=new GMap2(document.getElementById("map"));map.last_region=null;map.last_cluster=null;var a=new GLatLngBounds();a.extend(new GLatLng(42.3,-5));a.extend(new GLatLng(51.2,8.3));var b=agencesBounds;map.boundTo(b);map.last_bounds=new GLatLngBounds(b.getSouthWest(),b.getNorthEast());map.enableDragging();map.enableDoubleClickZoom();map.enableScrollWheelZoom();map.addControl(new GSmallMapControl());map.addControl(new GHierarchicalMapTypeControl());loader_control=new HtmlControl('<img class="fixpng" src="/imgs/maps/ajax-loader.gif"/>');map.addControl(loader_control,new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(75,5)));zoom_control=createZoomControl();map.addControl(zoom_control,new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,110)));$("img.fixpng").load(function(){$(this).ifixpng()});mgr=new MarkerManager(map);geocoder=new GClientGeocoder();directions=new Directions(map,$("#directions .resultat").get(0),function(){updateDescriptionItineraire();$("#panel").tabs("enable",1).tabs("select",1);map.closeInfoWindow()});directions.fromMarker=null;gicons.agence=new GIcon();gicons.agence.image="/imgs/maps/logo_agence.png";gicons.agence.shadow="/imgs/maps/logo_agence_shadow.png";gicons.agence.iconSize=new GSize(24,24);gicons.agence.shadowSize=new GSize(37,24);gicons.agence.iconAnchor=new GPoint(12,12);gicons.agence.infoWindowAnchor=new GPoint(12,1);gicons.agence_goutte=new GIcon();gicons.agence_goutte.image="/imgs/maps/logo_agence_goutte.png";gicons.agence_goutte.shadow="/imgs/maps/logo_agence_goutte_shadow.png";gicons.agence_goutte.iconSize=new GSize(20,34);gicons.agence_goutte.shadowSize=new GSize(37,34);gicons.agence_goutte.iconAnchor=new GPoint(9,34);gicons.agence_goutte.infoWindowAnchor=new GPoint(9,2);gicons.agence_goutte.infoShadowAnchor=new GPoint(18,25);gicons.recherche=new GIcon(G_DEFAULT_ICON);GEvent.addListener(map,"zoomend",function(c,d){$("#tooltip").hide();map.last_cluster=null});GEvent.addListener(map,"dragend",function(){var c=map.getZoom();if(c<=max_zoom_regions){$("#map shape,svg").css("cursor","pointer")}else{if(c<=max_zoom_clustering){$("#map div.clustermarker").css("cursor","pointer")}}});GEvent.addListener(map,"dragstart",function(){$("#tooltip").hide();var c=map.getZoom();if(c<=max_zoom_regions){$("#map shape,svg").css("cursor","")}else{if(c<=max_zoom_clustering){$("#map div.clustermarker").css("cursor","")}}});GEvent.addListener(map,"click",function(d,c){if(c&&map.getZoom()<=max_zoom_regions){if(timeout){clearTimeout(timeout)}var e=findRegion(c);if(e!=null){zoomRegion(e)}}else{if(c&&map.getZoom()>max_zoom_regions&&map.getZoom()<=max_zoom_clustering&&map.last_cluster){map.boundTo(map.last_cluster.bounds_)}else{if(d&&d.is_agence){showAgence(d)}}}});GEvent.addListener(map,"mousemove",function(c){if(map.getZoom()>max_zoom_regions){return}if(timeout){clearTimeout(timeout)}var e=c.lat();var d=c.lng();timeout=setTimeout("hoverRegions("+e+","+d+")",20)});$("#map").ajaxStart(function(){check_loader({ajax:true})}).ajaxStop(function(){check_loader({ajax:false})});$("#rechercheadresse form").get(0).reset();$("#gmap_rechercher").get(0).disabled=false;$("#options select").change(function(){if(null!=directions.fromMarker){rechercheAgenceDepuis(directions.fromMarker,true)}else{unloadMarkers();loadMarkers()}});$("#effaceritineraire").click(function(){directions.clear();$("#panel").tabs("select",0).tabs("disable",1)});$("#zoomfrance").click(function(){map.boundTo(a)});$("#zoomagences").click(function(){if(map.last_bounds){map.boundTo(map.last_bounds)}else{map.boundTo(b)}});$("#resetmap").click(function(){var c=false;$("#effaceritineraire").click();map.boundTo(b);if(!$("#rechercheadresse .resultat").is(":empty")){effacerRechercheAgence();c=true}$("#rechercheadresse input[name=adresse]").focus();var d=0==$.grep($("#options select").get(),function(e){return(0!==e.selectedIndex)}).length;if(!d){$("#options form").get(0).reset();c=true}if(c){unloadMarkers();loadMarkers()}});loadMarkers()}});function check_loader(a){$.extend(loader_status,a);var b=false;$.each(loader_status,function(){if(this==true){b=true}});if(b){loader_control.show()}else{loader_control.hide()}}function showAgence(b){var a=b.getPoint();var c=setTimeout("map.openInfoWindowHtml(new GLatLng("+a.lat()+","+a.lng()+'),"Chargement...")',500);var d=/^.*-X\d+(\w+)$/.exec(location.pathname)||[];$.get("/agences/jsp/map_info_agence.jsp?id_agence="+b.id_agence+"&xtp=0"+(d[1]||""),function(f){var h=$(f);$("div.description",h).append(directions.getForm(b,h,libelles));if(directions.fromMarker){$("form input[name=address]",h).val(directions.markerToDirectionQuery(directions.fromMarker))}var g=function(j){b.openInfoWindow(j[0]);map.last_infos_agence=j.clone();map.last_id_agence=b.id_agence};var i=$("img",h).attr("src");if(i){var e=new Image();$(e).load(function(){$("img",h).parent().css("height",this.height);$("div.description",h).css("margin-left",(this.width+10)+"px");if(c){clearTimeout(c)}g(h)}).error(function(){$("div.description",h).css("margin-left","10px");if(c){clearTimeout(c)}g(h)});e.src=i}else{if(c){clearTimeout(c)}g(h)}})}function hoverRegions(c,a){var b=findRegion(new GLatLng(c,a));if(b==map.last_region){return}map.last_region=b;if(b==null){$("#map shape,svg").attr("title","").css("cursor","")}else{$("#map shape,svg").attr("title",b.label_).css("cursor","pointer")}}function findRegion(a){for(var b=0;b<regions.length;b++){if(regions[b].Contains(a)){return regions[b];break}}return null}function zoomRegion(a){map.closeInfoWindow();map.boundTo(a.getBounds(),1)}function blockOptions(){$("#options select").each(function(){this.disabled=true});$("#nbagences").hide();$("#agencesloading").show()}function unblockOptions(){$("#options select").each(function(){this.disabled=false});$("#agencesloading").hide();$("#nbagences").show()}function loadMarkers(){blockOptions();loadAgences()}function unloadMarkers(){regions=[];mgr.clearMarkers();map.closeInfoWindow();$("#nbagences").empty();max_zoom_regions=-1;max_zoom_clustering=-1}function loadRegions(){if(max_zoom_regions<0){mgr.refresh();unblockOptions();return}regions=[];$.get("/agences/jsp/regions.xml",function(a){$("poly",a).each(function(){var c=$(this).attr("name");var b=$(this).attr("color");var e=[];$("point",this).each(function(){e.push(new GLatLng(parseFloat($(this).attr("lat")),parseFloat($(this).attr("lng"))))});var d=new GPolygon(e,"#000000",1,1,b,0.5,{clickable:false});d.label_=c;regions.push(d)});mgr.addMarkers(regions,0,max_zoom_regions);mgr.refresh();unblockOptions()})}function loadAgences(){var c=$("#options select[name=specialite]").val();if(c==null){c=""}var b=$("#options select[name=marque]").val();if(b==null){b=""}var a=$("#options select[name=service]").val();if(a==null){a=""}$.post("/servlet/Geo.srvl",{action:"agences",specialite:c,marque:b,service:a},function(l){var h=$("markers",l);var o=0;if(o=h.attr("nb")){var g=$("#nbagences");if(o==0){g.html(libelles.zeroagencestrouvees)}else{if(o==1){g.html(libelles.uneagencestrouvees)}else{g.html("<strong>"+o+"</strong> "+libelles.xagencestrouvees)}}}max_zoom_regions=parseInt(h.attr("mzr"));max_zoom_clustering=parseInt(h.attr("mzc"));icon=h.attr("icon");var m=parseFloat(h.attr("minlat"));var i=parseFloat(h.attr("maxlat"));var n=parseFloat(h.attr("minlng"));var k=parseFloat(h.attr("maxlng"));var f=h.attr("enseignes").split(/,/);$.each(f,function(r,s){if(!gicons[s]){gicons[s]=new GIcon(gicons.agence);gicons[s].image="/imgs/maps/logo_agence_"+s+".png"}});if(isNaN(m)||isNaN(n)||isNaN(i)||isNaN(k)){map.last_bounds=null}else{map.last_bounds=new GLatLngBounds();map.last_bounds.extend(new GLatLng(m,n));map.last_bounds.extend(new GLatLng(i,k))}var q=max_zoom_regions+1;var d=[];var j=[];var p;if(max_zoom_clustering<0){$("agc",l).each(function(t,u){var r=new GLatLng(parseFloat(u.getAttribute("lat")),parseFloat(u.getAttribute("lng")));var v=u.getAttribute("id");var s=createAgenceMarker(r,v,u.getAttribute("nom"),u.getAttribute("ens"));d.push(s)});mgr.addMarkers(d,q);mgr.refresh();unblockOptions()}else{for(var e=q;e<=max_zoom_clustering+1;e++){d[e]=[];j[e]=[]}$("agc",l).each(function(t,u){var r=new GLatLng(parseFloat(u.getAttribute("lat")),parseFloat(u.getAttribute("lng")));var w=u.getAttribute("id");var v=u.getAttribute("level");var s=createAgenceMarker(r,w,u.getAttribute("nom"),u.getAttribute("ens"));d[v].push(s)});$("clust",l).each(function(u,A){var v=parseFloat(A.getAttribute("sw_lat"));var y=parseFloat(A.getAttribute("sw_lng"));var x=parseFloat(A.getAttribute("ne_lat"));var z=parseFloat(A.getAttribute("ne_lng"));var r=new GLatLngBounds();r.extend(new GLatLng(v,y));r.extend(new GLatLng(x,z));var w=new GLatLng(parseFloat(A.getAttribute("lat")),parseFloat(A.getAttribute("lng")));var s=A.getAttribute("level");var t=createClusterMarker(w,$("agc",A),r);j[s].push(t)});for(var e=q;e<=max_zoom_clustering+1;e++){mgr.addMarkers(d[e],e);mgr.addMarkers(j[e],e,e)}loadRegions()}})}function createAgenceMarker(a,e,c,d){var b=new GMarker(a,{title:c,icon:(d?gicons[d]:gicons[icon])});$.extend(b,{is_agence:true,id_agence:e});return b}function createClusterMarker(a,d,c){var f=d.length;var g=f+" "+libelles.agencesdanszone+" - <p>";if(f>10){f=10}for(var b=0;b<f;b++){g+=d[b].getAttribute("nom").replace(/ /ig,"&nbsp;")+"<br/>"}if(f!=d.length){var e=d.length-f;g+="... et "+e+" ";if(e==1){g+=libelles.autreagence+"."}else{g+=libelles.autresagences+"."}}g+="</p>";return new ClusterMarker(a,c,g,1,"#000000","rgb(225,59,0)")}function simplifyPlacemark(b){var a={};$.each(b,function(d,c){if(typeof(c)=="object"){$.extend(a,simplifyPlacemark(c))}else{if(typeof(c)=="string"){a[d]=c}}});return a}function placemark2address(e){var a=simplifyPlacemark(e);var f=a.ThoroughfareName;var i=a.LocalityName;var c=a.DependentLocalityName;var g=a.PostalCodeNumber;var h=a.SubAdministrativeAreaName;var b=a.AdministrativeAreaName;var d=[];if(f){d.push(f)}if(c){d.push(c)}if(i||g){d.push($.trim((g?g:"")+" "+(i?i:"")))}if(h||b){if(h){d.push(h)}else{d.push(b)}}return d.join(", ")}function rechercheAgence(b){check_loader({geocoder:true});var a="";if(typeof(b)=="string"){a=b}else{a=b.adresse.value}a=$.trim(a);if(null==a.match(/[\W,-]+fr(?:ance)?$/i)){a+=", France"}geocoder.getLocations(a,function(e){switch(e.Status.code){case G_GEO_SUCCESS:unloadMarkers();check_loader({geocoder:false});var d=$(e.Placemark);var g=new GLatLngBounds();if(d.length>1){effacerRechercheAgence();var i=$("#rechercheadresse .resultat").empty();i.html('<div class="fieldset"><p class="titre">Sélectionnez la bonne adresse</p><br /></div>');i=$("div.fieldset",i);d.each(function(){var m=placemark2address(this);var l=$('<a href="javascript:void(0);">'+m+"</a>");var n=this.Point.coordinates;var j=new GLatLng(n[1],n[0]);g.extend(j);var k=new GMarker(j,{title:m,icon:gicons.recherche});map.addOverlay(k);recherche_markers.push(k);GEvent.addListener(k,"click",function(){l.click()});l.click(function(){var o=$("<div><b>Adresse :</b><br/>"+m+"<br/><br/></div>");$('<a class="suite">Utiliser cette adresse</a>').attr("href","javascript:void(0)").appendTo(o).click(function(){var p=new GMarker(k.getPoint(),{title:"Déplacez-moi",icon:gicons.recherche,draggable:true});p.nom=m;rechercheAgenceDepuis(p)});k.openInfoWindow(o[0])}).css("cursor","pointer");i.append(l).append("<br />")});$('<a class="gmap_effacer_recherche" href="javascript:void(0);">'+libelles.effacerrecherche+"</a>").click(function(){effacerRechercheAgence();loadMarkers()}).appendTo(i);map.boundTo(g);map.last_bounds=g}else{var h=d.get(0).Point.coordinates;var f=d.get(0).address;var c=new GMarker(new GLatLng(h[1],h[0]),{title:"Déplacez-moi",icon:gicons.recherche,draggable:true});c.nom=f;rechercheAgenceDepuis(c)}break;default:check_loader({geocoder:false});alert("Adresse inconnue.");break}})}function effacerRechercheAgence(){map.closeInfoWindow();$("#rechercheadresse .resultat a").unbind();$("#rechercheadresse .resultat").empty();$(recherche_markers).each(function(){map.removeOverlay(this)});recherche_markers=[];if(directions.fromMarker){map.removeOverlay(directions.fromMarker)}}function rechercheAgenceDepuis(c,e){if(!e){effacerRechercheAgence();directions.fromMarker=c;GEvent.addListener(c,"dragend",function(){c.nom="Point sur la carte";$("#gmap_rechercher").get(0).disabled=true;$("#rechercheadresse input[name=adresse]").val(c.nom).unbind("focus").one("focus",function(){$(this).val("");$("#gmap_rechercher").get(0).disabled=false}).blur();rechercheAgenceDepuis(c,true)});GEvent.addListener(c,"remove",function(){c=null;directions.fromMarker=null;recherche_markers=[]})}var d=$("#options select[name=specialite]").val();if(d==null){d=""}var b=$("#options select[name=marque]").val();if(b==null){b=""}var a=$("#options select[name=service]").val();if(a==null){a=""}$.post("/servlet/Geo.srvl",{action:"recherche",nb:10,lat:c.getPoint().lat(),lng:c.getPoint().lng(),specialite:d,marque:b,service:a},function(f){$("#rechercheadresse .resultat a").unbind();$("#rechercheadresse .resultat").empty();if(!e){map.addOverlay(c)}else{$(recherche_markers).each(function(){map.removeOverlay(this)});recherche_markers=[]}var g=new GLatLngBounds();g.extend(c.getPoint());var h=[];$("agc",f).each(function(){var j=new GLatLng(parseFloat($(this).attr("lat")),parseFloat($(this).attr("lng")));var k=createAgenceMarker(j,$(this).attr("id"),$(this).attr("nom"),$(this).attr("ens"));map.addOverlay(k);recherche_markers.push(k);g.extend(j);h.push([k,$(this).attr("nom"),$(this).attr("distance")])});map.last_bounds=g;var i=$("#rechercheadresse .resultat").empty();i.html('<div class="fieldset"><p class="titre">Résultat de votre recherche</p><br /></div>');i=$("div.fieldset",i);if(h.length>0){if(!e){map.boundTo(g)}$(h).each(function(l){var m=this[0];var k=this[1];var n=this[2];if(n<1000){n=n+" m"}else{n=(Math.round(n/100)/10)+" km"}var j=$('<a href="javascript:void(0);">'+n+", "+k+"</a>").click(function(){showAgence(m)});i.append(j).append("<br />")})}else{i.append("Aucun résultat.<br/>")}$('<a class="gmap_effacer_recherche" href="javascript:void(0);">'+libelles.effacerrecherche+"</a>").click(function(){effacerRechercheAgence();loadMarkers()}).appendTo(i);$.get("/includes/xiti_ajax.jsp",{jsp:"xiti_ajax",xtrecherche:"agence:"+cleanString($("#rechercheadresse input[name=adresse]").val())})})}function updateDescriptionItineraire(){var a=(typeof(directions.from)=="object")?directions.from:directions.to;if(a&&a.is_agence){if(a.id_agence==map.last_id_agence){$("#description_itineraire .description").html($("div.description",map.last_infos_agence).html());$("#description_itineraire .itineraire").html($("#directions .resultat").html())}}};
function Directions(c,a,d){this.directions=new GDirections(c,a);this.callback=d;var b=this;GEvent.addListener(this.directions,"addoverlay",function(){if(typeof b.callback=="function"){b.callback.call()}if(typeof check_loader=="function"){check_loader({directions:false})}});GEvent.addListener(this.directions,"error",this.onError)}Directions.prototype.onError=function(a){if(typeof check_loader=="function"){check_loader({directions:false})}var b=a.getStatus().code;if(b==G_GEO_UNKNOWN_ADDRESS){alert("Erreur : Addresse inconnue ou incomplête")}else{if(b==G_GEO_SERVER_ERROR){alert("Erreur : Calcul d'itinéraire indisponible.")}else{if(b==G_GEO_MISSING_QUERY){alert("Erreur : Addresse incomplête.")}else{if(b==G_GEO_BAD_KEY){alert("Erreur : clé google incorrecte")}else{if(b==G_GEO_BAD_REQUEST){alert("Erreur : Addresse mal formulée.")}else{if(b==G_GEO_TOO_MANY_QUERIES){alert("Erreur : Nombre maximal de requêtes atteint pour la journée.")}else{alert("Erreur")}}}}}}};Directions.prototype.markerToDirectionQuery=function(a){var c=a.getPoint().lat()+","+a.getPoint().lng();var b="";if(a.nom){b=a.nom}else{b=a.getTitle()}if(b.length==0){return c}else{return b+"@"+c}};Directions.prototype.load=function(c,b){if(typeof check_loader=="function"){check_loader({directions:true})}this.from=c;this.to=b;var a="from: ";if(typeof(c)=="object"){a+=this.markerToDirectionQuery(c)}else{a+=c}a+=" to: ";if(typeof(b)=="object"){a+=this.markerToDirectionQuery(b)}else{a+=b}this.directions.clear();this.directions.load(a,{locale:"fr"})};Directions.prototype.retour=function(){this.load(this.to,this.from)};Directions.prototype.clear=function(){this.directions.clear()};Directions.prototype.getForm=function(b,c,f){var e=this;var a={itineraire:"Itinéraire",apartirde:"A partir de cette agence",vers:"Vers cette agence",arrivee:"Lieu d'arrivée",depart:"Lieu de départ",submit:"Envoyer",cancel:"« Retour"};$.extend(a,f);var d=$('<div class="gmnoprint">	'+a.itineraire+' :	<a class="dfm" href="javascript:void(0);">'+a.vers+'</a><span class="dtm">'+a.vers+'</span>	-	<a class="dtm" href="javascript:void(0);">'+a.apartirde+'</a><span class="dfm">'+a.apartirde+'</span>	<div class="dform">		<span class="dfm">'+a.arrivee+'</span>		<span class="dtm">'+a.depart+'</span>		<br/>		<form>			<input type="text" value="" name="address" /><input type="submit" value="'+a.submit+'">		</form>		<br/>		<a class="retour" style="cursor: pointer;">'+a.cancel+"</a>	</div></div>");$("span, div.dform",d).hide();$("a.dfm, a.dtm",d).click(function(){if(e.fromMarker){e.versAgence=$(this).is(".dfm")}if($(this).is(".dfm")){e.versAgence=true;$(".dfm",d).hide();$(".dtm",d).show()}else{e.versAgence=false;$(".dtm",d).hide();$(".dfm",d).show()}if(!$("div.dform",d).is(":visible")){$("div.dform",d).show();var g=GEvent.addListener(b,"infowindowopen",function(){$("form",d)[0].address.focus();GEvent.removeListener(g)});b.openInfoWindow(c[0])}else{$("form",d)[0].address.focus()}});$("a.retour",d).click(function(){$("span",d).hide();$("a",d).show();$("div.dform",d).hide();b.openInfoWindow(c[0])});$("form",d).submit(function(){var g=this.address.value;if(null==g.match(/[\W,-]+fr(?:ance)?$|@/i)){g+=", France"}if(e.versAgence){e.load(g,b)}else{e.load(b,g)}return false});return d};
