var Maps_lang={address_not_found:"Nie znaleziono adresu: "};var Maps=Class.create();Object.extend(Maps.prototype,AppCore.prototype);Object.extend(Maps.prototype,{mapContainer:null,map:null,geocoder:null,markerManager:null,zoom:13,mapId:"map",searchId:"search",latField:"latitude",lngField:"longitude",lat:null,lng:null,lastpos:null,load:function(){if(GBrowserIsCompatible()){this.mapContainer=document.getElementById(this.mapId);if(this.mapContainer==null){return false}this.map=new GMap2(this.mapContainer);this.map.setCenter(new GLatLng(this.lat,this.lng),this.zoom);this.map.enableScrollWheelZoom();this.map.addControl(new GLargeMapControl());this.markerManager=new GMarkerManager(this.map);this.geocoder=new GClientGeocoder()}},setCenter:function(B,A){this.lat=B;this.lng=A;this.map.setCenter(new GLatLng(this.lat,this.lng),this.zoom)},setZoom:function(A){this.zoom=A;this.map.setCenter(new GLatLng(this.lat,this.lng),this.zoom)},moveMarker:function(B,A){this.map.clearOverlays();point=new GLatLng(B,A);marker=new GMarker(point,{draggable:true});GEvent.addListener(marker,"dragend",function(){maps.lastpos=marker.getPoint();document.getElementById(maps.latField).value=maps.lastpos.y;document.getElementById(maps.lngField).value=maps.lastpos.x});this.map.addOverlay(marker);this.setCenter(B,A);document.getElementById(this.latField).value=B;document.getElementById(this.lngField).value=A},addMarker:function(E,D,F,B){var A=new GLatLng(E,D);var C={draggable:false,title:F,clickable:!!B};marker=new GMarker(A,C);if(!!B){GEvent.addListener(marker,"click",function(){window.location.href=B})}this.map.addOverlay(marker)},getLastPos:function(){return this.latpos},search:function(){var A=document.getElementById(this.searchId).value;if(this.geocoder){this.geocoder.getLatLng(A,function(B){if(!B){alert(A+" not found")}else{maps.moveMarker(B.y,B.x)}})}},show:function(){lat=document.getElementById(this.latField).value;lng=document.getElementById(this.lngField).value;this.moveMarker(lat,lng)}});function GaduAirMapUtils(){this.newLocation.type=globalCurrentType;this.newLocation.province=globalCurrentProvince;this.newLocation.cityId=globalCurrentCityId;this.newLocation.page=globalCurrentPage}GaduAirMapUtils.prototype={PARAMS_SEPARATOR:"/",USED_HREF:"/starter/w-sklepie",POINT_TYPE_STARTER:globalTypeStarter,POINT_TYPE_TOPUP:globalTypeTopUp,POINT_TYPE_BOTH:globalTypeBoth,MAP_ANCHOR_NAME:"#map",newLocation:{type:null,province:null,cityId:null,page:null},setUsedHref:function(A){this.USED_HREF=A},redirect:function(A){var B=this.USED_HREF+this.PARAMS_SEPARATOR;if(A.type){B+=A.type}B+=this.PARAMS_SEPARATOR;if(A.province){B+=A.province}B+=this.PARAMS_SEPARATOR;if(A.cityId){B+=A.cityId}B+=this.PARAMS_SEPARATOR;if((A.page)&&(A.page>1)){B+=1}B+=this.MAP_ANCHOR_NAME;window.location.replace(B)},checkAndManageUserCitySelection:function(A){if((!isNaN(A))&&(A>0)){this.newLocation.cityId=A;this.newLocation.page=null;this.redirect(this.newLocation)}},checkAndManageUserProvinceSelection:function(A){if((A)&&(A!=="")){this.newLocation.province=A;this.newLocation.cityId=null;this.newLocation.page=null;this.redirect(this.newLocation)}},getCheckBoxStatuses:function(){if((document.getElementById("select_starters").checked)&&(document.getElementById("select_topups").checked)){return this.POINT_TYPE_BOTH}if(document.getElementById("select_starters").checked){return this.POINT_TYPE_STARTER}if(document.getElementById("select_topups").checked){return this.POINT_TYPE_TOPUP}return this.POINT_TYPE_BOTH}};var Locations=Class.create();Object.extend(Locations.prototype,AppCore.prototype);Object.extend(Locations.prototype,{mapsManager:null,searchCity:"searchCity",searchStreet:"searchStreet",locationStarter:true,locationTopup:true,geocoder:null,addressSeparator:", ",addressSuffix:"Poland",locationFoundZoom:15,ajaxUrl:"/locations/search",searchPoint:null,init:function(A){this.mapsManager=A;elem=document.getElementById(this.searchCity);var B=this;Event.observe(elem,"keypress",function(C){if(C){if(C.keyCode==13){B.search()}}})},search:function(){if(this.geocoder==null){this.geocoder=new GClientGeocoder()}var city=document.getElementById(this.searchCity).value;var address=Array();if(city.length>0){address.push(city)}var url=this.ajaxUrl;var loc=this;var amount=0;advAJAX.get({url:url+"/"+city,parameters:{},onSuccess:function(obj){var data=obj.responseText;var list=eval("("+data+")");amount=list["amount"];loc.doSearch(amount,address)}.bind(this),onError:function(obj){}.bind(this)})},doSearch:function(C,B){if(C>1){alert("Podaj kod pocztowy")}else{var A=B.join(this.addressSeparator);B.push(this.addressSuffix);var E=this;var D=this;this.geocoder.getLatLng(B.join(this.addressSeparator),function(F){if(!F){alert(Maps_lang.address_not_found+A)}else{D.mapsManager.map.setCenter(F,10);D.searchPoint=F}})}},updateFilter:function(){starter=this.locationStarter;topup=this.locationTopup;if(topup&&!starter){this.mapsManager.setLocationType("t")}else{if(!topup&&starter){this.mapsManager.setLocationType("s")}else{if(!topup&&!starter){topup=true;starter=true;this.mapsManager.setLocationType(null)}else{this.mapsManager.setLocationType(null)}}}this.mapsManager.closeOverlay()},updateFilterReload:function(B,A){if(B==1){this.locationStarter=!this.locationStarter}if(A==1){this.locationTopup=!this.locationTopup}this.updateFilter();this.mapsManager.updateMarkers()}});var MapsControl=Class.create();Object.extend(MapsControl.prototype,{map:null,mapContainer:null,mapLoader:null,zoom:6,minZoom:null,maxZoom:null,maxSatelliteZoom:null,gridElementsLat:7,gridElementsLng:15,moveFactorUpdate:2,requests:0,mapId:"map",lat:null,lng:null,geocode_url:null,ADDRESS_NOT_FOUND:10,ADDRESS_NEED_CONFIRMATION:20,ADDRESS_FOUND:30,marker_type:{cluster:"c",single:"m"},info_window_url:null,topupIcon:"marker_orange.png",topupGroupIcon:"",starterIcon:"marker_green.png",starterGroupIcon:"",ADDRESS_SEPARATOR:",",PARAMS_SEPARATOR:"/",imagePath:null,latMin:null,latMax:null,lngMin:null,lngMax:null,currentMarker:null,locationType:null,ajaxURL:null,descriptionURL:null,setImagePath:function(A){this.imagePath=A},initialize:function(C,B,A){this.ajaxURL=C;this.descriptionURL=B;this.descriptionURL=B;this.imagePath=A;this.topupIcon=this.imagePath+this.topupIcon;this.starterIcon=this.imagePath+this.starterIcon;this.topupGroupIcon=this.imagePath+this.topupGroupIcon;this.starterGroupIcon=this.imagePath+this.starterGroupIcon},setLocationType:function(A){this.locationType=A},load:function(){if(GBrowserIsCompatible()){this.mapContainer=document.getElementById(this.mapId);if(this.mapContainer===null){return }this.map=new GMap2(this.mapContainer);this.map.setCenter(new GLatLng(this.lat,this.lng),this.zoom);this.map.enableScrollWheelZoom();this.map.addControl(new GLargeMapControl());this.map.addControl(new GMapTypeControl());this.attachEventListeners();this.updateMapBounds()}},attachEventListeners:function(){var A=this;GEvent.addListener(A.map,"zoomend",function(C,B){if(B>A.maxZoom){A.map.setZoom(A.maxZoom)}if(B<A.minZoom){A.map.setZoom(A.minZoom)}if(A.map.getCurrentMapType().PL=="Satelita"&&B>A.maxSatelliteZoom){A.map.setZoom(A.maxSatelliteZoom)}A.updateMarkers();t=A;setTimeout(function(){t.updateSearchPoint()},2000);A.updateMapBounds()});GEvent.addListener(A.map,"dragend",function(){var B=A.map.getBounds();var D=B.getSouthWest();var C=B.getNorthEast();if((Math.abs(D.x-A.lngMin)>((A.lngMax-A.lngMin)/A.moveFactorUpdate))||(Math.abs(D.y-A.latMin)>((A.latMax-A.latMin)/A.moveFactorUpdate))){A.updateMarkers();t=A;setTimeout(function(){t.updateSearchPoint()},2000);A.updateMapBounds()}})},updateMapBounds:function(){var C=this.map.getBounds();var B=C.getSouthWest();var A=C.getNorthEast();this.latMin=B.y;this.latMax=A.y;this.lngMin=B.x;this.lngMax=A.x},updateSearchPoint:function(){if(locObj){if(locObj.searchPoint!=null){options=new Array();options.type="s";str=""+locObj.searchPoint;data=str.replace(" ","").split(",");customIcon=new GIcon();customIcon.iconSize=new GSize(20,27);customIcon.iconAnchor=new GPoint(10,26);customIcon.image=this.starterIcon;locationId="";this.addContentMarker(data[0].replace("(",""),data[1].replace(")",""),customIcon,locationId)}}},addContentMarker:function(F,G,B,J,D,I){var E=this;var H=new GLatLng(F,G);var C;if(B instanceof GIcon){B=new GIcon();B.iconSize=new GSize(20,27);B.iconAnchor=new GPoint(10,26);B.image=this.starterIcon;var A={icon:B.icon,clickable:true,draggable:B.draggable||false,labelClass:B.labelClass||"markerLabel",labelOffset:B.labelOffset||new GSize(0,0)};C=new GMarker(H,A);GEvent.addListener(C,"click",function(){this.openInfoWindow(I)})}else{var A={icon:B.icon,clickable:B.clickable||false,draggable:B.draggable||false,labelClass:B.labelClass||"markerLabel",labelOffset:B.labelOffset||new GSize(0,0)};C=new LabeledMarker(H,A);C.div=B.label;if(B.clickable){map=E.map;GEvent.addListener(C,"click",function(){zoom=map.getZoom();if(D==1){zoom=17}else{zoom=zoom+2}map.setCenter(new GLatLng(F,G),zoom)})}}E.map.addOverlay(C);return C},closeOverlay:function(){if(this.currentMarker){this.map.removeOverlay(this.currentMarker.overlay);this.currentMarker.show()}},randomString:function(){var A=new Date();return A.getTime().toString(20)},hideLoader:function(){if(this.mapLoader!==null){this.removeLoader()}},updateMarkers:function(){var A=this;this.requests+=1;setTimeout(function(){A.loadMarkers()},400)},loadMarkers:function(){this.requests-=1;if(this.requests>0){return }var E=this;this.info_window_url=this.descriptionURL;if(this.ajaxURL.search(/\/$/)<0){this.ajaxURL+="/"}this.map.clearOverlays();var D=this.map.getBounds();var C=D.getSouthWest();var B=D.getNorthEast();var A=C.toUrlValue().replace(",","/")+"/"+B.toUrlValue().replace(",","/")+"/"+this.map.getZoom();if(this.ajaxURL!==null){advAJAX.useJSON=true;advAJAX.get({url:this.ajaxURL+A+(this.locationType===null?"":("/"+this.locationType)),parameters:null,onSuccess:function(I){var F=I.responseJSON;E.map.clearOverlays();if(F.result!==0){if(F.errorMsg){alert(F.errorMsg)}return }var H=F.data;var G,J=0;for(G=0;G<H.length;G++){if(E.inViewport(H[G])){J+=1}E.addLocationMarker(H[G])}}.bind(this),onError:function(F){}.bind(this)})}},inViewport:function(H){var A=this.map.getBounds();var C=A.getSouthWest();var D=A.getNorthEast();var E=C.y;var F=C.x;var G=D.y;var I=D.x;var B=Boolean(H.lat>=E&&H.lat<=G&&H.lng>=F&&H.lng<=I);return B},addLocationMarker:function(B){var E;var A=document.createElement("div");var D=document.createElement("span");var C=null;if(B.cluster===true){D.innerHTML=B.count;A.appendChild(D);E={icon:null,label:A,clickable:true,labelClass:"clusterLabel-"+B.type,labelOffset:new GSize(-18,5)};if(B.type=="t"){E.icon=new topupClusterIcon(this.imagePath)}else{E.icon=new starterClusterIcon(this.imagePath)}return this.addContentMarker(B.lat,B.lng,E,C,B.count)}else{E=new GIcon();E.iconSize=new GSize(20,27);E.iconAnchor=new GPoint(10,26);if(B.type=="s"){E.image=this.starterIcon}else{E.image=this.topupIcon}C=B.id;return this.addContentMarker(B.lat,B.lng,E,C,B.count,B.description)}}});function starterClusterIcon(A){var B=new GIcon();B.image=A+"marker_group_starter.gif";B.iconSize=new GSize(50,50);B.iconAnchor=new GPoint(25,25);B.infoWindowAnchor=new GPoint(25,1);B.infoShadowAnchor=new GPoint(25,25);return B}function topupClusterIcon(A){var B=new GIcon();B.image=A+"marker_group_topup.gif";B.iconSize=new GSize(50,50);B.iconAnchor=new GPoint(25,25);B.infoWindowAnchor=new GPoint(25,1);B.infoShadowAnchor=new GPoint(25,25);return B}function LabeledMarker(B,A){this.clickable=A.clickable||false;this.latlng=B;this.labelClass=A.labelClass||"markerLabel";this.labelOffset=A.labelOffset||new GSize(0,0);GMarker.apply(this,arguments)}LabeledMarker.prototype=new GMarker(new GLatLng(0,0));LabeledMarker.prototype.initialize=function(A){GMarker.prototype.initialize.call(this,A);var B=this.div;if(this.clickable){GEvent.addDomListener(B,"click",newEventPassthru(this,"click"));B.style.cursor="pointer"}GMarker.prototype.initialize.call(this,A);B.className=this.labelClass;B.style.position="absolute";A.getPane(G_MAP_MARKER_PANE).appendChild(B);this.map=A;this.div=B};function newEventPassthru(B,A){return function(){GEvent.trigger(B,A)}}LabeledMarker.prototype.redraw=function(A){GMarker.prototype.redraw.call(this,map);if(!A){return }var B=this.map.fromLatLngToDivPixel(this.latlng);var C=GOverlay.getZIndex(this.latlng.lat());this.div.style.left=(B.x+this.labelOffset.width)+"px";this.div.style.top=(B.y+this.labelOffset.height)+"px";this.div.style.zIndex=C+1};LabeledMarker.prototype.remove=function(){this.div.parentNode.removeChild(this.div);this.div=null;GMarker.prototype.remove.call(this)}
