function CPGeocoder(B,A){this.element=$(B);this.countryCode=A;this.coordinates=null;this.alternativesList=null;this.geocoder=new GClientGeocoder();this.isValid=false;this.geocoder.setBaseCountryCode(this.countryCode)}CPGeocoder.prototype.geocode=function(){this.coordinates=null;this.alternativesList=new Array();if(this.element.value!=""){this.geocoder.getLocations(this.element.value,function(A){if(A.Status.code==G_GEO_SUCCESS){if(A.Placemark.length>1){A.Placemark.each(function(C,B){this.alternativesList.push({element:this.element,index:B,address:C.address,coordinates:new GLatLng(C.Point.coordinates[1],C.Point.coordinates[0])})}.bind(this));GEvent.trigger(this,"gcMultipleAddresses",this);GEvent.trigger(this,"gcFailure",this);this.isValid=false}else{this.coordinates=new GLatLng(A.Placemark[0].Point.coordinates[1],A.Placemark[0].Point.coordinates[0]);this.element.value=A.Placemark[0].address;GEvent.trigger(this,"gcSuccess");this.isValid=true}}else{GEvent.trigger(this,"gcInvalidValue");this.isValid=false}}.bind(this))}else{GEvent.trigger(this,"gcInvalidValue");this.isValid=false}};CPGeocoder.prototype.reverse=function(A){this.alternativesList=new Array();this.geocoder.getLocations(A,function(B){if(B.Status.code==G_GEO_SUCCESS){this.coordinates=A;GEvent.trigger(this,"gcSuccess");this.isValid=true}else{GEvent.trigger(this,"gcInvalidValue");this.isValid=false}}.bind(this));if(this.isValid){GEvent.trigger(this,"gcSuccess")}else{GEvent.trigger(this,"gcFailure")}};CPGeocoder.prototype.getElement=function(){return this.element};CPGeocoder.prototype.getAlternativesList=function(){return this.alternativesList};CPGeocoder.prototype.getCoordinates=function(){return this.coordinates};CPGeocoder.prototype.getLatLng=function(){return(new GLatLng(this.coordinates.lat(),this.coordinates.lng()))};CPGeocoder.prototype.getAddress=function(){return this.element.value};CPGeocoder.prototype.chooseAddress=function(A){this.coordinates=A.coordinates;this.isValid=true;GEvent.trigger(this,"gcSuccess")};function CPRouteEnvironment(){this.map=null;this.startConnector=null;this.destinationConnector=null;this.countryCode=null;this.loadHomeMarkerUrl=APPLICATION_ROOT+"/geoSearch/getHomeAddress";this.homeIcon=null;this.homeMarker=null}CPRouteEnvironment.prototype.initialize=function(){};CPRouteEnvironment.prototype.validateConnector=function(B,A){A.status=1};CPRouteEnvironment.prototype.invalidateConnector=function(B,A){A.status=2};CPRouteEnvironment.prototype.showErrorMessage=function(D,A){A.status=2;var C=A.possibilityLayer.select(".content");var B=A.possibilityLayer.select(".errorMessage");C[0].update("");B[0].show();if(A.possibilityLayer.style.display=="none"){Effect.BlindDown(A.possibilityLayer,{duration:0.3})}};CPRouteEnvironment.prototype.showPossibilityLayer=function(F,A){var E=A.possibilityLayer.select(".content");E[0].update("");var B=A.geocoder.getAlternativesList();for(var C=0;C<B.length;C++){var D=new Element("a",{href:"#"});D.innerHTML=B[C].address;D.observe("click",this.chooseAddress.bindAsEventListener(this,A,B[C]));E[0].insert({bottom:D});E[0].insert({bottom:new Element("br")})}if(A.possibilityLayer.style.display=="none"){Effect.BlindDown(A.possibilityLayer,{duration:0.3})}};CPRouteEnvironment.prototype.chooseAddress=function(C,A,B){C.stop();this.hidePossibilityLayer(A);A.inputField.value=B.address;A.geocoder.chooseAddress(B)};CPRouteEnvironment.prototype.hidePossibilityLayer=function(A){if(A.possibilityLayer.style.display!="none"){Effect.BlindUp(A.possibilityLayer,{duration:0.3})}};CPRouteEnvironment.prototype.handleUnsupportedBrowser=function(){new Ajax.Updater("map",APPLICATION_ROOT+"/static/unsupportedBrowser")};CPRouteEnvironment.prototype.loadHomeMarker=function(){if(this.homeMarker){}new Ajax.Request(this.loadHomeMarkerUrl,{method:"get",onSuccess:this.showHomeMarker.bindAsEventListener(this)})};CPRouteEnvironment.prototype.showHomeMarker=function(A){if(!A.responseJSON){return }var B=A.responseJSON;if(B.latitude&&B.longitude){this.homeIcon=new GIcon(null,APPLICATION_ROOT+"/images/general/map/pin_home.png");this.homeIcon.size=new GSize(40,33);this.homeIcon.iconAnchor=new GPoint(8,30);var D;try{D=new GLatLng(B.latitude,B.longitude)}catch(C){return }this.homeMarker=new GHomeMarker(D,{draggable:false,icon:this.homeIcon});this.map.addOverlay(this.homeMarker);GEvent.trigger(this,"homeMarkerLoaded")}};function GHomeMarker(B,A){GMarker.apply(this,arguments)}GHomeMarker.prototype=new GMarker(new GLatLng(0,0));GHomeMarker.prototype.remove=function(){};function CPCarStopLoader(A){this.map=A;this.carstopMarkers={}}CPCarStopLoader.prototype.drawCarstops=function(A){this.removeCarstops();var D,B;if(typeof (console)!=="undefined"){console.log("[CPCarStopLoader.drawCarstops] Displaying carStops")}for(var C=0;C<A.length;C++){D=new GIcon();Object.extend(D,{shadow:"",image:A[C].icon,iconSize:new GSize(13,13),shadowSize:new GSize(0,0),iconAnchor:new GPoint(2,11),maxHeight:1});B=new GMarker((new GLatLng(A[C].latitude,A[C].longitude)),{draggable:false,icon:D});GEvent.addListener(B,"click",this.showCarstop.bindAsEventListener(this,A[C].url,B.getLatLng()));this.carstopMarkers[A[C].id]=B;this.map.addOverlay(B)}if(typeof (console)!=="undefined"){console.log("[CPCarStopLoader.drawCarstops] carStops loaded")}};CPCarStopLoader.prototype.removeCarstops=function(){for(var A in this.carstopMarkers){GEvent.clearNode(this.carstopMarkers[A]);this.map.removeOverlay(this.carstopMarkers[A])}this.carstopMarkers={}};CPCarStopLoader.prototype.showCarstop=function(B,A){new Ajax.Request(A,{method:"get",onSuccess:this.carstopLoadedCallback.bind(this,B)})};CPCarStopLoader.prototype.carstopLoadedCallback=function(B,A){if(!A.responseText){return }this.map.openInfoWindow(B,A.responseText)};function CPGeoSearchEnvironment(){}CPGeoSearchEnvironment.prototype=new CPRouteEnvironment();CPGeoSearchEnvironment.prototype.init=function(A){this.initData=A;this.routeColor="#15700B";this.visibleRoute=null;this.visibleRequest=null;this.startMarker=null;this.endMarker=null;this.polyline=null;if(GBrowserIsCompatible()){this.map=new GMap2($(A.mapCanvas));if(this.map.getSize().height<300){this.map.addControl(new GSmallMapControl())}else{this.map.addControl(new GLargeMapControl())}this.map.setCenter(A.initCoordinates,A.zoom);this.map.enableDoubleClickZoom();this.map.enableScrollWheelZoom();this.map.enableContinuousZoom();this.locale=A.locale;this.form=$(A.form);document.observe("click",this.hidePossibilityLayers.bindAsEventListener(this));if(A.clusterUrl){this.loadClusters(A.clusterUrl,A.clusterShowLinks)}if(A.startInput&&A.startPL){this.connectStart(A.startInput,A.startPL)}if(A.destinationInput&&A.destinationPL){this.connectDestination(A.destinationInput,A.destinationPL)}if(A.reload==true){this.loadRouteRequest()}this.boxTitle=null;this.boxTitles=null;if(A.titleId){this.boxTitle=$(A.titleId);this.boxTitles={step1:A.titleStep1,step2:A.titleStep2}}if($("showSearchResultsLink")){$("showSearchResultsLink").observe("click",this.hideRouteDetails.bindAsEventListener(this))}this.searchCallBack=A.searchCallBack;this.targetBounds=[]}else{this.handleUnsupportedBrowser()}};CPGeoSearchEnvironment.prototype.loadClusters=function(B,A){if(!this.mapCluster){this.mapCluster=new CPMapCluster(this.map,B,this,A)}this.mapCluster.loadClusters()};CPGeoSearchEnvironment.prototype.hidePossibilityLayers=function(A){if(this.startConnector&&this.startConnector.possibilityLayer.style.display!="none"||this.destinationConnector&&this.destinationConnector.possibilityLayer.style.display!="none"){A.stop();this.hidePossibilityLayer(this.startConnector);this.hidePossibilityLayer(this.destinationConnector)}};CPGeoSearchEnvironment.prototype.connectStart=function(A,B){var C=new CPGeocoder($(A),this.locale);this.startConnector={geocoder:C,possibilityLayer:$(B),inputField:$(A),status:0};this.addConnectorListeners(this.startConnector);$(A).observe("keypress",function(D){if(D.keyCode==Event.KEY_RETURN){D.stop();this.search()}}.bindAsEventListener(this))};CPGeoSearchEnvironment.prototype.connectDestination=function(A,B){var C=new CPGeocoder($(A),this.locale);this.destinationConnector={geocoder:C,possibilityLayer:$(B),inputField:$(A),status:0};this.addConnectorListeners(this.destinationConnector);$(A).observe("keypress",function(D){if(D.keyCode==Event.KEY_RETURN){D.stop();this.search()}}.bindAsEventListener(this))};CPGeoSearchEnvironment.prototype.validateConnector=function(B,A){A.status=1;this.checkAndSearch();this.hidePossibilityLayer(A);if(this.searchCallBack){this.searchCallBack()}};CPGeoSearchEnvironment.prototype.search=function(){this.startConnector.status=0;this.destinationConnector.status=0;this.startConnector.geocoder.geocode();this.destinationConnector.geocoder.geocode()};CPGeoSearchEnvironment.prototype.showRequestMarkers=function(){this.clearRequestMarkers();var B=new GIcon();B.image=APPLICATION_ROOT+"/images/general/map/pin_start.png";B.size=new GSize(40,33);B.iconAnchor=new GPoint(8,30);var A=new GIcon();A.image=APPLICATION_ROOT+"/images/general/map/pin_stop.png";A.size=new GSize(40,33);A.iconAnchor=new GPoint(8,30);this.startMarker=new GMarker(this.startConnector.geocoder.getCoordinates(),{draggable:false,icon:B});this.endMarker=new GMarker(this.destinationConnector.geocoder.getCoordinates(),{draggable:false,icon:A});this.map.addOverlay(this.startMarker);this.map.addOverlay(this.endMarker);var C=new GLatLngBounds();C.extend(this.startConnector.geocoder.getCoordinates());C.extend(this.destinationConnector.geocoder.getCoordinates());this.map.setCenter(C.getCenter());this.map.setZoom(this.map.getBoundsZoomLevel(C)-1)};CPGeoSearchEnvironment.prototype.clearRequestMarkers=function(){if(this.startMarker){GEvent.clearNode(this.startMarker);this.map.removeOverlay(this.startMarker)}if(this.endMarker){GEvent.clearNode(this.endMarker);this.map.removeOverlay(this.endMarker)}if(this.polyline){GEvent.clearNode(this.polyline);this.map.removeOverlay(this.polyline)}};CPGeoSearchEnvironment.prototype.checkAndSearch=function(A){if(this.startConnector.status==1&&this.destinationConnector.status==1){CPTools.lockWindow();this.showRequestMarkers();$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng();$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng();this.form.request({onSuccess:function(B){Effect.BlindUp("searchResultContainer",{duration:0.3,afterFinish:function(){$("searchResultContainer").update(B.responseText);Effect.BlindDown("searchResultContainer",{duration:0.6})}});GEvent.removeListener(this.zoomListener)}.bind(this),onError:function(){CPTools.handleHttpError("503")},onComplete:function(){CPTools.unlockWindow()}})}};CPGeoSearchEnvironment.prototype.loadRouteRequest=function(){if($("startLatitude").value!=""&&$("startLongitude").value!=""&&$("destinationLatitude").value!=""&&$("destinationLongitude").value!=""){this.map.clearOverlays();GEvent.clearInstanceListeners(this.startConnector.geocoder);GEvent.clearInstanceListeners(this.destinationConnector.geocoder);GEvent.addListener(this.startConnector.geocoder,"gcSuccess",this.validateReloadRouteRequest.bindAsEventListener(this,"start"));GEvent.addListener(this.destinationConnector.geocoder,"gcSuccess",this.validateReloadRouteRequest.bindAsEventListener(this,"destination"));this.startConnector.geocoder.reverse(new GLatLng($("startLatitude").value,$("startLongitude").value));this.destinationConnector.geocoder.reverse(new GLatLng($("destinationLatitude").value,$("destinationLongitude").value))}};CPGeoSearchEnvironment.prototype.addConnectorListeners=function(A){GEvent.addListener(A.geocoder,"gcMultipleAddresses",this.showPossibilityLayer.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcSuccess",this.validateConnector.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcInvalidValue",this.showErrorMessage.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcFailure",this.invalidateConnector.bindAsEventListener(this,A))};CPGeoSearchEnvironment.prototype.validateReloadRouteRequest=function(F,D){var B;var C=new GIcon();C.size=new GSize(40,33);C.iconAnchor=new GPoint(8,30);if(D=="start"){B=this.startConnector;C.image=APPLICATION_ROOT+"/images/general/map/pin_start.png"}else{B=this.destinationConnector;C.image=APPLICATION_ROOT+"/images/general/map/pin_stop.png"}B.status=1;GEvent.clearInstanceListeners(B.geocoder);this.addConnectorListeners(B);var A=new GMarker(B.geocoder.getCoordinates(),{draggable:false,icon:C});if(D=="start"){this.startMarker=A}else{this.endMarker=A}this.map.addOverlay(A);if(this.startConnector.status==1&&this.destinationConnector.status==1){this.polyline=new GPolyline([this.startConnector.geocoder.getCoordinates(),this.destinationConnector.geocoder.getCoordinates()],this.routeColor,5);this.map.addOverlay(this.polyline);var E=new GLatLngBounds();E.extend(this.startConnector.geocoder.getCoordinates());E.extend(this.destinationConnector.geocoder.getCoordinates());this.map.setCenter(E.getCenter());this.map.setZoom(this.map.getBoundsZoomLevel(E)-1)}};CPGeoSearchEnvironment.prototype.showRoute=function(B,A){if(this.visibleRoute&&this.visibleRoute.getRouteId()==B.id){this.visibleRoute.showInfoWindow();return }if(this.visibleRoute){this.visibleRoute.remove()}if(this.visibleRequest){this.visibleRequest.remove()}this.visibleRoute=new CPSearchRouteResult(B,this.map,this.routeColor,A,this.targetBounds);if(!A){Effect.BlindUp("searchResultContainer",{duration:0.6})}if(this.boxTitle){this.boxTitle.update(this.boxTitles.step2)}};CPGeoSearchEnvironment.prototype.showRouteRequest=function(B,A){if(this.visibleRequest&&this.visibleRequest.getId()==B.id){this.visibleRequest.showInfoWindow();return }if(this.visibleRoute){this.visibleRoute.remove()}if(this.visibleRequest){this.visibleRequest.remove()}this.visibleRequest=new CPSearchRouteRequestResult(B,this.map,this.routeColor,A);if(!A){Effect.BlindUp("searchResultContainer",{duration:0.6})}if(this.boxTitle){this.boxTitle.update(this.boxTitles.step2)}};CPGeoSearchEnvironment.prototype.clearRoutes=function(){if(this.visibleRoute){this.visibleRoute.remove();this.visibleRoute=null}};CPGeoSearchEnvironment.prototype.prepareRouteRequest=function(){this.form.action=this.initData.routeRequestUrl;var A=new Element("INPUT",{name:"prepare",value:"true",type:"hidden"});this.form.insert({bottom:A});if(this.startConnector.status==1){$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng()}if(this.destinationConnector.status==1){$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng()}this.form.submit()};CPGeoSearchEnvironment.prototype.prepareCreateRoute=function(){this.form.action=this.initData.createRouteUrl;if(this.startConnector.status==1){$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng()}if(this.destinationConnector.status==1){$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng()}this.form.submit()};CPGeoSearchEnvironment.prototype.saveRouteRequest=function(){if(this.startConnector.status==1&&this.destinationConnector.status==1){this.form.action=this.initData.routeRequestUrl;var A=new Element("INPUT",{name:"save",value:"true",type:"hidden"});this.form.insert({bottom:A});$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng();$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng();this.form.submit()}};CPGeoSearchEnvironment.prototype.enableSaveRouteRequestButton=function(A){if(this.startConnector.status==1&&this.destinationConnector.status==1&&A){A.disabled=false}};CPGeoSearchEnvironment.prototype.hideRouteDetails=function(A){A.stop();if(this.visibleRoute){this.visibleRoute.remove();this.visibleRoute=null}if(this.visibleRequest){this.visibleRequest.remove();this.visibleRequest=null}Effect.BlindUp("routeDetailsContainer",{duration:0.6});Effect.BlindDown("searchResultContainer",{duration:0.6})};CPGeoSearchEnvironment.prototype.extendTargetBounds=function(A){this.targetBounds.push(A)};var geoSearchEnvironment=new CPGeoSearchEnvironment();function CPSearchRouteRequestResult(C,D,B,A){this.requestData=C;this.map=D;this.color=B;this.id=C.id;this.useMap=A;this.startIcon=new GIcon();this.startIcon.image=APPLICATION_ROOT+"/images/general/map/pin_start.png";this.startIcon.size=new GSize(40,33);this.startIcon.iconAnchor=new GPoint(8,30);this.stopIcon=new GIcon();this.stopIcon.image=APPLICATION_ROOT+"/images/general/map/pin_stop.png";this.stopIcon.size=new GSize(40,33);this.stopIcon.iconAnchor=new GPoint(8,30);this.startCoordinates=new GLatLng(this.requestData.carstops[0][0],this.requestData.carstops[0][1]);this.destinationCoordinates=new GLatLng(this.requestData.carstops[1][0],this.requestData.carstops[1][1]);GEvent.addListener(this.map,"scroll",this.scrollListener.bind(this));this.drawRequest()}CPSearchRouteRequestResult.prototype.drawRequest=function(){this.startMarker=new GMarker(this.startCoordinates,{draggable:false,icon:this.startIcon});this.destinationMarker=new GMarker(this.destinationCoordinates,{draggable:false,icon:this.stopIcon});this.polyline=new GPolyline([this.startCoordinates,this.destinationCoordinates],this.color,5,0.6);this.map.addOverlay(this.startMarker);this.map.addOverlay(this.destinationMarker);this.map.addOverlay(this.polyline);var A=this.polyline.getBounds();this.map.setCenter(A.getCenter(),this.map.getBoundsZoomLevel(A));if(this.useMap){this.map.openInfoWindow(this.polyline.getBounds().getCenter(),$(this.requestData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})}else{$("routeDetailsContainerContent").update($(this.requestData.miniInfo).innerHTML);Effect.BlindDown("routeDetailsContainer",{duration:0.6})}};CPSearchRouteRequestResult.prototype.remove=function(){this.map.removeOverlay(this.startMarker);this.map.removeOverlay(this.destinationMarker);this.map.removeOverlay(this.polyline);this.map.closeInfoWindow()};CPSearchRouteRequestResult.prototype.scrollListener=function(){this.map.openInfoWindow(this.polyline.getBounds().getCenter(),$(this.requestData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})};CPSearchRouteRequestResult.prototype.getId=function(){return this.id};CPSearchRouteRequestResult.prototype.showInfoWindow=function(){if(this.useMap){this.map.openInfoWindow(this.polyline.getBounds().getCenter(),$(this.requestData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})}};function CPMapCluster(D,C,B,A){this.map=D;this.markers=[];this.parent=B;this.action=C;this.showLinks=A;this.zoomListener=GEvent.addListener(this.map,"zoomend",this.zoomHandler.bind(this));this.moveListener=GEvent.addListener(this.map,"moveend",this.moveHandler.bind(this));this.currentRequest=null}CPMapCluster.prototype.moveHandler=function(){this.loadClusters()};CPMapCluster.prototype.zoomHandler=function(){this.map.closeInfoWindow();this.removeClusters();this.loadClusters()};CPMapCluster.prototype.loadClusters=function(){if(this.currentRequest!==null){this.currentRequest.abort()}var A=this.map.getBounds();var B=this.map.getZoom();Ajax.blockNextOverlay=true;this.currentRequest=new Ajax.Request(this.action,{method:"get",evalJSON:true,parameters:{zoomLevel:B,sw_lat:A.getSouthWest().lat(),sw_lng:A.getSouthWest().lng(),ne_lat:A.getNorthEast().lat(),ne_lng:A.getNorthEast().lng()},onSuccess:this.clustersLoaded.bind(this)})};CPMapCluster.prototype.clustersLoaded=function(D){var H=D.responseJSON;if(!H){return }var B,G,C,A,E;for(var F=0;F<H.length;F++){G=new GIcon();B=H[F];if(this.markers[B.id]){continue}if(B.size<1){if(B.pois!==undefined&&B.pois.size>0){Object.extend(G,{shadow:"",image:B.pois[0].icon,iconSize:new GSize(20,20),shadowSize:new GSize(0,0),iconAnchor:new GPoint(10,10),maxHeight:1});C=new GMarker((new GLatLng(B.latitude,B.longitude)),{draggable:false,icon:G});if(this.showLinks){GEvent.addListener(C,"click",this.showSinglePoi.bindAsEventListener(this,C.getLatLng(),B.pois[0].link))}}else{Object.extend(G,{shadow:"",image:APPLICATION_ROOT+"/images/general/cluster/cluster0.png",iconSize:new GSize(15,15),shadowSize:new GSize(0,0),iconAnchor:new GPoint(5,5),maxHeight:1});C=new GMarker((new GLatLng(B.latitude,B.longitude)),{draggable:false,icon:G});if(this.showLinks){GEvent.addListener(C,"click",this.loadCarstopCluster.bindAsEventListener(this,B.link,false))}}}else{if(B.size>0&&B.size<3){A=[20,31];E="2plus.png"}else{if(B.size>2&&B.size<5){A=[30,46];E="10plus.png"}else{if(B.size>4&&B.size<7){A=[30,46];E="100plus.png"}else{if(B.size>6&&B.size<9){A=[40,61];E="500plus.png"}else{if(B.size>8){A=[48,71];E="1000plus.png"}}}}}Object.extend(G,{shadow:"",image:APPLICATION_ROOT+"/images/general/cluster/"+E,iconSize:new GSize(A[1],A[0]),shadowSize:new GSize(0,0),iconAnchor:new GPoint(Math.round(A[0]/2),Math.round(A[1]/2)),maxHeight:1});C=new GMarker((new GLatLng(B.latitude,B.longitude)),{draggable:false,icon:G});if(this.showLinks){GEvent.addListener(C,"click",this.showCluster.bindAsEventListener(this,B))}}this.map.addOverlay(C);this.markers[B.id]=C}};CPMapCluster.prototype.removeClusters=function(){for(var A in this.markers){GEvent.clearNode(this.markers[A]);this.map.removeOverlay(this.markers[A])}this.markers=[]};CPMapCluster.prototype.loadCarstopCluster=function(B,A,C){this.parent.clearRoutes();if(C!==undefined){this.map.closeInfoWindow()}new Ajax.Request(A,{method:"get",evalJSON:true,onSuccess:function(D){Effect.BlindUp("searchResultContainer",{duration:0.3,afterFinish:function(){$("searchResultContainer").update(D.responseText);Effect.BlindDown("searchResultContainer",{duration:0.6})}})}.bind(this)})};CPMapCluster.prototype.showSinglePoi=function(B,A){this.map.closeInfoWindow();new Ajax.Request(A,{method:"get",evalJSON:true,onSuccess:function(C,D){this.map.openInfoWindow(D,C.responseText)}.bindAsEventListener(this,B)})};CPMapCluster.prototype.showCluster=function(C,I){var B=this.map.getInfoWindow().getContentContainers();var J=new Template($("showClusterTemplateContainer").innerHTML);var H=new Element("DIV").update(J.evaluate({numberOfCarstops:I.numberOfCarStops,numberOfRoutes:I.numberOfRoutes}));this.map.openInfoWindow(C,H);var F=H.select(".carstopClusterText").first();var G=H.select(".poiList").first();if(I.numberOfCarStops>0){F.show();H.select(".withCarstops").first().show();F.observe("click",this.loadCarstopCluster.bindAsEventListener(this,I.link))}if(I.pois!=undefined&&I.pois.length>0){var D,A;for(var E=0;E<I.pois.length;E++){A=new Element("LI",{className:"poiShort"});G.insert({bottom:A});A.insert(new Element("IMG",{src:I.pois[E].icon,alt:I.pois[E].name,title:I.pois[E].name}));A.observe("click",this.showSinglePoi.bind(this,C,I.pois[E].link));A.show()}H.select(".poiClusterText").first().show()}};function CPSearchRouteResult(C,E,B,A,D){this.gdirections=new GDirections();this.routeData=C;this.map=E;this.overlay=null;this.color=B;this.useMap=A;if(D){this.targetBounds=D}GEvent.addListener(this.gdirections,"load",this.routeLoaded.bindAsEventListener(this));GEvent.addListener(this.map,"scroll",this.scrollListener.bind(this));this.gdirections.loadFromWaypoints(this.routeData.carstops,{getSteps:true,getPolyline:true});this.carstopLoader=new CPCarStopLoader(this.map)}CPSearchRouteResult.prototype=new CPCarStopLoader();CPSearchRouteResult.prototype.routeLoaded=function(C){this.gdirections.getPolyline().setStrokeStyle({color:this.color,weight:5,opacity:1});this.overlay=this.gdirections.getPolyline();this.map.addOverlay(this.overlay);GEvent.clearListeners(this.gdirections,"load");var B=this.overlay.getBounds();if(this.targetBounds){for(var A=0;A<this.targetBounds.length;A++){B.extend(this.targetBounds[A])}}this.map.setCenter(B.getCenter(),this.map.getBoundsZoomLevel(B));if(this.useMap){this.map.openInfoWindow(B.getCenter(),$(this.routeData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})}else{$("routeDetailsContainerContent").update($(this.routeData.miniInfo).innerHTML);Effect.BlindDown("routeDetailsContainer",{duration:0.6})}this.carstopLoader.drawCarstops(this.routeData.carstops)};CPSearchRouteResult.prototype.remove=function(){this.removeCarstops();this.map.removeOverlay(this.overlay);this.map.closeInfoWindow()};CPSearchRouteResult.prototype.scrollListener=function(){this.map.openInfoWindow(this.overlay.getBounds().getCenter(),$(this.routeData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})};CPSearchRouteResult.prototype.getRouteId=function(){return this.routeData.id};CPSearchRouteResult.prototype.showInfoWindow=function(){if(this.useMap){this.map.openInfoWindow(this.overlay.getBounds().getCenter(),$(this.routeData.miniInfo).innerHTML,{onCloseFn:this.remove.bind(this)})}};function CPSearchRouteEnvironment(){}CPSearchRouteEnvironment.prototype=new CPRouteEnvironment();CPSearchRouteEnvironment.prototype.initialize=function(D,E,C,A,B){this.visibleRoutes=[];this.routeColors=["#15700B","#dd0a0a","#ffa200","#2400ff","#fcff00"];this.nextRouteColor=0;if(GBrowserIsCompatible()){this.map=new GMap2($(D));this.map.addControl(new GLargeMapControl());this.map.setCenter(E,C);this.map.enableDoubleClickZoom();this.map.enableScrollWheelZoom();this.map.enableContinuousZoom();this.countryCode=A;this.form=$(B);this.route=null;document.observe("click",this.hidePossibilityLayers.bindAsEventListener(this))}else{this.handleUnsupportedBrowser()}};CPSearchRouteEnvironment.prototype.loadClusters=function(A){if(!this.mapCluster){this.mapCluster=new CPMapCluster(this.map,A,this)}this.mapCluster.loadClusters()};CPSearchRouteEnvironment.prototype.hidePossibilityLayers=function(A){if(this.startConnector.possibilityLayer.style.display!="none"||this.destinationConnector.possibilityLayer.style.display!="none"){A.stop();this.hidePossibilityLayer(this.startConnector);this.hidePossibilityLayer(this.destinationConnector)}};CPSearchRouteEnvironment.prototype.connectStart=function(A,B){var C=new CPGeocoder($(A),this.countryCode);this.startConnector={geocoder:C,possibilityLayer:$(B),inputField:$(A),status:0};this.addConnectorListeners(this.startConnector);$(A).observe("keypress",function(D){if(D.keyCode==Event.KEY_RETURN){D.stop();this.submitQuery()}}.bindAsEventListener(this))};CPSearchRouteEnvironment.prototype.connectDestination=function(A,B){var C=new CPGeocoder($(A),this.countryCode);this.destinationConnector={geocoder:C,possibilityLayer:$(B),inputField:$(A),status:0};this.addConnectorListeners(this.destinationConnector);$(A).observe("keypress",function(D){if(D.keyCode==Event.KEY_RETURN){D.stop();this.submitQuery()}}.bindAsEventListener(this))};CPRouteEnvironment.prototype.validateConnector=function(B,A){A.status=1;this.checkAndSubmit();this.hidePossibilityLayer(A)};CPSearchRouteEnvironment.prototype.submitQuery=function(){this.startConnector.status=0;this.destinationConnector.status=0;this.startConnector.geocoder.geocode();this.destinationConnector.geocoder.geocode()};CPSearchRouteEnvironment.prototype.showRequestMarkers=function(){var B=new GIcon();B.image=APPLICATION_ROOT+"/images/general/map/pin_start.png";B.size=new GSize(40,33);B.iconAnchor=new GPoint(8,30);var A=new GIcon();A.image=APPLICATION_ROOT+"/images/general/map/pin_stop.png";A.size=new GSize(40,33);A.iconAnchor=new GPoint(8,30);this.map.addOverlay(new GMarker(this.startConnector.geocoder.getCoordinates(),{draggable:false,icon:B}));this.map.addOverlay(new GMarker(this.destinationConnector.geocoder.getCoordinates(),{draggable:false,icon:A}));var C=new GLatLngBounds();C.extend(this.startConnector.geocoder.getCoordinates());C.extend(this.destinationConnector.geocoder.getCoordinates());this.map.setCenter(C.getCenter());this.map.setZoom(this.map.getBoundsZoomLevel(C)-1)};CPSearchRouteEnvironment.prototype.checkAndSubmit=function(A){if(this.startConnector.status==1&&this.destinationConnector.status==1){CPTools.lockWindow();this.map.clearOverlays();this.showRequestMarkers();$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng();$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng();this.form.request({onSuccess:function(B){Effect.BlindUp("searchResultContainer",{duration:0.3,afterFinish:function(){$("searchResultContainer").update(B.responseText);Effect.BlindDown("searchResultContainer",{duration:0.6})}});$("routeRequest").show();GEvent.removeListener(this.zoomListener);this.removePois()}.bind(this),onError:function(){CPTools.handleHttpError("503")},onComplete:function(){CPTools.unlockWindow()}})}};CPSearchRouteEnvironment.prototype.reload=function(){if($("startLatitude").value!=""&&$("startLongitude").value!=""&&$("destinationLatitude").value!=""&&$("destinationLongitude").value!=""){GEvent.clearInstanceListeners(this.startConnector.geocoder);GEvent.clearInstanceListeners(this.destinationConnector.geocoder);GEvent.addListener(this.startConnector.geocoder,"gcSuccess",this.validateReload.bindAsEventListener(this,"start"));GEvent.addListener(this.destinationConnector.geocoder,"gcSuccess",this.validateReload.bindAsEventListener(this,"destination"));this.startConnector.geocoder.reverse(new GLatLng($("startLatitude").value,$("startLongitude").value));this.destinationConnector.geocoder.reverse(new GLatLng($("destinationLatitude").value,$("destinationLongitude").value))}};CPSearchRouteEnvironment.prototype.addConnectorListeners=function(A){GEvent.addListener(A.geocoder,"gcMultipleAddresses",this.showPossibilityLayer.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcSuccess",this.validateConnector.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcInvalidValue",this.showErrorMessage.bindAsEventListener(this,A));GEvent.addListener(A.geocoder,"gcFailure",this.invalidateConnector.bindAsEventListener(this,A))};CPSearchRouteEnvironment.prototype.validateReload=function(E,C){var A;var B=new GIcon();B.size=new GSize(40,33);B.iconAnchor=new GPoint(8,30);if(C=="start"){A=this.startConnector;B.image=APPLICATION_ROOT+"/images/general/map/pin_start.png"}else{A=this.destinationConnector;B.image=APPLICATION_ROOT+"/images/general/map/pin_stop.png"}A.status=1;GEvent.clearInstanceListeners(A.geocoder);this.addConnectorListeners(A);this.map.addOverlay(new GMarker(A.geocoder.getCoordinates(),{draggable:false,icon:B}));if(this.startConnector.status==1&&this.destinationConnector.status==1){var D=new GLatLngBounds();D.extend(this.startConnector.geocoder.getCoordinates());D.extend(this.destinationConnector.geocoder.getCoordinates());this.map.setCenter(D.getCenter());this.map.setZoom(this.map.getBoundsZoomLevel(D)-1)}};CPSearchRouteEnvironment.prototype.showRoute=function(C,B){var A=new CPSearchRouteResult(C,B,this.map,this.routeColors[this.nextRouteColor]);this.nextRouteColor++;if(this.nextRouteColor>=this.routeColors.size()){this.nextRouteColor=0}this.visibleRoutes.push(A)};CPSearchRouteEnvironment.prototype.hideRoute=function(C){var A=[];for(var B=0;B<this.visibleRoutes.size();B++){if(this.visibleRoutes[B].getRouteId()!=C){A.push(this.visibleRoutes[B])}else{this.visibleRoutes[B].remove()}}this.visibleRoutes=A};CPSearchRouteEnvironment.prototype.clearRoutes=function(){for(var A=0;A<this.visibleRoutes.size();A++){this.visibleRoutes[A].remove()}this.visibleRoutes=[]};CPSearchRouteEnvironment.prototype.saveRouteRequest=function(){if(this.startConnector.status==1&&this.destinationConnector.status==1){$("startLatitude").value=this.startConnector.geocoder.getCoordinates().lat();$("startLongitude").value=this.startConnector.geocoder.getCoordinates().lng();$("destinationLatitude").value=this.destinationConnector.geocoder.getCoordinates().lat();$("destinationLongitude").value=this.destinationConnector.geocoder.getCoordinates().lng();this.form.submit()}};CPSearchRouteEnvironment.prototype.saveRequest=function(B){var A=$(B.form).serialize();if(B.emailField&&$(B.emailField)){A+="&email="+$(B.emailField).value}A+="&"+B.name+"=true";new Ajax.Request(B.url,{method:"post",parameters:A,onSuccess:function(C){if(!C.responseJSON){return }var D=C.responseJSON;if(D.success&&D.success==true){$(B.update).update(D.message);CPTools.hideLightbox()}else{if(B.lightbox){if($(B.lightbox)&&!$(B.lightbox).visible()){CPTools.displayLightbox(B.lightbox,0.2)}$(B.lightbox).select(".errorArea").first().update(D.message)}}}})};var searchRouteEnvironment=new CPSearchRouteEnvironment();var CPRide={lastRRUpdateLayer:null,lastRRForm:null,reactOnRate:function(e){var res=eval("("+e.responseText+")");if(res.success==true){$("rideRateBoxErrorArea").update("");$("rideRateBoxErrorArea").style.display="none";$(res.ratingLayer).innerHTML=res.code;CPTools.hideLightbox()}else{$("rideRateBoxErrorArea").update(res.code);$("rideRateBoxErrorArea").style.display="block"}},reactOnRideStatusChange:function(e){try{var res=eval("("+e.responseText+")");$(res.layerName).update(res.code)}catch(e){return false}},submitRideRequest:function(B,D,A){if(LOGGED_IN){$(B).request({method:"post",onSuccess:function(F){if(!F.responseJSON){return }var E=F.responseJSON;if(E.success){$(A).remove()}$(D).update(E.message)}})}else{this.lastRRForm=$(B);this.lastRRUpdateLayer=$(D);var C=$("authenticateBeforeRideRequestLightbox");CPTools.displayLightbox(C,0.2)}},submitAuthentication:function(A,B){$(A).request({method:"post",onSuccess:function(E){if(!E.responseJSON){return }var D=E.responseJSON;if(!D.success){$(B).update(D.dialog)}else{LOGGED_IN=true;if($("sidebarLogin")){var C=$("sidebarLogin");Effect.BlindUp(C,{duration:0.2,afterFinish:function(){C.replace(D.sidebar)}})}CPTools.hideLightbox();this.submitRideRequest(this.lastRRForm,this.lastRRUpdateLayer)}}.bind(this),on403:function(){CPTools.handleHttpError("403")}})},setRating:function(A){var B=$("ratingChooser");curValue=parseInt(B.value);if(curValue==A){A=0}B.value=A},displayRating:function(A){var B=$("ratingChooser");curValue=parseInt(B.value);for(i=1;i<=5;i++){if(i<=A){$("star-rating-"+i).className="selected"}else{$("star-rating-"+i).className=""}}},restoreRating:function(){var A=$("ratingChooser");curValue=parseInt(A.value);CPRide.displayRating(curValue)}}
