
Prado.WebUI.Response={redirect:function(element,url){window.location.href=url;}}
CustomEvent={};CustomEvent.Events={};CustomEvent.Events.Base=Class.create();CustomEvent.Events.Base.prototype={initialize:function(){this.type="CustomEvent.Events.Base";}}
CustomEvent.EventController=Class.create();CustomEvent.EventController.prototype={initialize:function(){this.listeners=$A([]);},addEventListener:function(n,f){this.listeners.push({name:n,callback:f});},removeListener:function(n,f){this.listeners=this.listeners.without({name:n,callback:f});},dispatchEvent:function(n,e){for(var x=0;x<this.listeners.length;x++){if(this.listeners[x].name==n){this.listeners[x].callback(e);}}}}
var EventController=new CustomEvent.EventController();var B=B||{};var B=B||{};B.Marker=Class.create();B.Marker.prototype={initialize:function(options){this.id=options[0];this.siteName=options[1];this.latitude=options[2][0];this.longitude=options[2][1];this.clientId=options[3];this.title=options[4];this.dragging=options[5];this.options=options;this.eventDragging=null;},getGLatLng:function(){if(!this.point){this.point=new GLatLng(this.latitude,this.longitude);}
return this.point;},getGMarker:function(icon){if(!this.marker){icon=icon||G_DEFAULT_ICON;this.marker=new GMarker(this.getGLatLng(),{icon:icon,title:this.title,draggable:this.dragging});GEvent.bind(this.marker,'click',this,this.openInfoWindow.bind(this,'Loading...'));}
return this.marker;},openInfoWindow:function(content){this.marker.openInfoWindowHtml(content);},distanceFrom:function(marker){distance=0;if(marker){distance=this.getGLatLng().distanceFrom(marker.getGLatLng());distance=distance/1609.344;}
return distance;}};B.ActiveGoogleMaps={register:function(key,value){this._maps=this._maps||new Array;this._maps[key]=value;},unregister:function(key){this._maps[key]=null;},get:function(key){return this._maps[key];},setMarkerVisible:function(id,marker,value){B.ActiveGoogleMaps.get(id).setMarkerVisible(marker,value);},setCenter:function(id,value){B.ActiveGoogleMaps.get(id).setCenter(value);},setScrollWheelZoom:function(id,value){B.ActiveGoogleMaps.get(id).setScrollWheelZoom(value);},setBounds:function(id,value){B.ActiveGoogleMaps.get(id).setBounds(value);},setZoom:function(id,value){B.ActiveGoogleMaps.get(id).setZoom(value);},setControls:function(id,value){B.ActiveGoogleMaps.get(id).setControls(value);},openInfoWindow:function(id,value){B.ActiveGoogleMaps.get(id).openInfoWindow(value);},closeInfoWindow:function(id){B.ActiveGoogleMaps.get(id).closeInfoWindow();},setMarkerID:function(id,value){B.ActiveGoogleMaps.get(id).setMarkerID(value);},addMarker:function(id,options){B.ActiveGoogleMaps.get(id).addMarker(options);},setMarkerDragging:function(id,markerID,value){B.ActiveGoogleMaps.get(id).setMarkerDragging(markerID,value);}}
B.ActiveGoogleMap=Class.extend(Prado.WebUI.CallbackControl,{onInit:function(options){this.options=options;B.ActiveGoogleMaps.register(this.options.ID,this);Event.OnLoad(this.onLoad.bind(this));Event.observe(window,"unload",this.onUnload.bind(this));},onUnload:function(){GUnload();this.markers=null;this.lines=null;B.ActiveGoogleMaps.unregister(this.options.ID);},onLoad:function(){this.element=$(this.options.ID);this.markers=new Array();this._markerID;this.lines=new Array();this.mapInit();},mapInit:function(){this.map=new GMap2(this.element);this.map.setCenter(new GLatLng(this.options.Center[0],this.options.Center[1]),Number(this.options.ZoomLevel));this.setControls(this.options.Controls);this.setScrollWheelZoom(this.options.ScrollWheelZoom);GEvent.bind(this.map,'click',this,this.mapClick);GEvent.bind(this.map,'moveend',this,this.moveEnd);this.moveEnd();},openInfoWindow:function(content){this.getMarker().openInfoWindow(content,this);},closeInfoWindow:function(){this.map.closeInfoWindow();},getMarker:function(id){id=id||this.getMarkerID()
return this.markers[id];},setMarkerID:function(value){this._markerID=value;},getMarkerID:function(){return this._markerID;},panToMarker:function(marker){this.map.panTo(marker.getGLatLng());},setCenter:function(value){this.map.panTo(new GLatLng(value[0],value[1]));},getCenter:function(){center=this.map.getCenter();return Array(center.lat(),center.lng());},setScrollWheelZoom:function(value){if(value)
this.map.enableScrollWheelZoom();else
this.map.disableScrollWheelZoom();},setBounds:function(value){sw=new GLatLng(value[0],value[2]);ne=new GLatLng(value[1],value[3]);bounds=new GLatLngBounds(sw,ne);this.map.setCenter(bounds.getCenter(),this.map.getBoundsZoomLevel(bounds));},getBounds:function(){bounds=this.map.getBounds();sw=bounds.getSouthWest();ne=bounds.getNorthEast();return Array(sw.lat(),ne.lat(),sw.lng(),ne.lng());},setZoom:function(value){this.map.setZoom(value);},getZoom:function(){return this.map.getZoom();},setControls:function(value){this.controls=this.controls||new Array;for(ID in this.controls){this.map.removeControl(this.controls[ID]);this.controls[ID]=null;}
for(ID in value){if(ID>=0){this.addControlFactory(value[ID]);}}},addControlFactory:function(controlName){switch(controlName){case'GLargeMapControl':if(!this.controls.GLargeMapControl){this.map.addControl(this.controls.GLargeMapControl=new GLargeMapControl());}
return this.controls.GLargeMapControl;break;case'GMapTypeControl':if(!this.controls.GMapTypeControl){this.map.addControl(this.controls.GMapTypeControl=new GMapTypeControl());}
return this.controls.GMapTypeControl;break;case'GOverviewMapControl':if(!this.controls.GOverviewMapControl){this.map.addControl(this.controls.GOverviewMapControl=new GOverviewMapControl());}
return this.controls.GOverviewMapControl;break;case'GScaleControl':if(!this.controls.GScaleControl){this.map.addControl(this.controls.GScaleControl=new GScaleControl());}
return this.controls.GScaleControl;break;case'GSmallMapControl':if(!this.controls.GSmallMapControl){this.map.addControl(this.controls.GSmallMapControl=new GSmallMapControl());}
return this.controls.GSmallMapControl;break;case'GSmallZoomControl':if(!this.controls.GSmallZoomControl){this.map.addControl(this.controls.GSmallZoomControl=new GSmallZoomControl());}
return this.controls.GSmallZoomControl;break;}},moveEnd:function(){param=new Object;param.eventType="__BActiveGoogleMap_OnMoveEnd__";param.clientSide=this.getClientSide();param=Prado.JSON.stringify(param);Prado.Callback(this.options.EventTarget,param,null,this.options);},getClientSide:function(){ret=new Object();ret.bounds=this.getBounds();ret.zoomLevel=this.getZoom();ret.center=this.getCenter();return ret;},addMarker:function(markerData,icon){id=markerData[0];if(!this.markers[id]){this.markers[id]=new B.Marker(markerData);this.map.addOverlay(this.markers[id].getGMarker(icon));dragging=markerData[5];this.setMarkerDragging(id,dragging);GEvent.bind(this.markers[id].getGMarker(),'click',this,this.markerClick.bind(this,this.markers[id]));}},markerClick:function(marker){if(marker=marker||this.getMarker()){param=new Object;param.eventType="__BActiveGoogleMap_OnMarkerChanged__";param.markerID=marker.id;param=Prado.JSON.stringify(param);Prado.Callback(this.options.EventTarget,param,null,this.options);}},markerDrag:function(marker){if(marker=marker||this.getMarker()){param=new Object;param.eventType="__BActiveGoogleMap_OnMarkerDrag__";param.markerID=marker.id;param.clientSide=this.getClientSide();param.lat=marker.getGMarker().getPoint().lat();param.lng=marker.getGMarker().getPoint().lng();param=Prado.JSON.stringify(param);Prado.Callback(this.options.EventTarget,param,null,this.options);}},setMarkerVisible:function(id,value){if(this.markers[id]){if(value)
this.markers[id].getGMarker().show();else
this.markers[id].getGMarker().hide();}},setMarkerDragging:function(id,value){if(this.markers[id]){marker=this.markers[id];if(marker.eventDragging)
GEvent.removeListener(marker.eventDragging);if(value){marker.getGMarker().enableDragging();marker.eventDragging=GEvent.bind(marker.getGMarker(),'dragend',this,this.markerDrag.bind(this,marker));}else{marker.getGMarker().disableDragging();}}},mapClick:function(overlay,point){if(!overlay&&point){param=new Object;param.eventType="__BActiveGoogleMap_OnClick__";param.clientSide=this.getClientSide();param.lat=point.lat();param.lng=point.lng();param=Prado.JSON.stringify(param);Prado.Callback(this.options.EventTarget,param,null,this.options);}}});