﻿/// <reference name="MicrosoftAjax.js" />
/* ----------------------------------------------------------------------------------- */
/* Copyright (C) Simplovation LLC (http://Simplovation.com) 2008. All rights reserved. */
/* ----------------------------------------------------------------------------------- */
/* Map.js - Simplovation.Web.Maps.VE */
Type.registerNamespace("Simplovation.Web.Maps.VE.Utils");
Simplovation.Web.Maps.VE.Utils.AppPathDomain=location.protocol + "//" + location.host;
Type.registerNamespace("Simplovation.Web.Maps.VE.Utils.UrlHelper");
Simplovation.Web.Maps.VE.Utils.UrlHelper.ToAbsolute=function(s,appPathRoot){var n=s;if(n.substring(0,2)=="~/"){n=appPathRoot+n.substring(2);}if(n.substring(0,1)=="/"){n=Simplovation.Web.Maps.VE.Utils.AppPathDomain+n;}return n;}

Type.registerNamespace("Simplovation.Web.Maps.VE");
Simplovation.Web.Maps.VE.Map=function(element){
    Simplovation.Web.Maps.VE.Map.initializeBase(this,[element]);
    this._Map=null;this._LatLong=null;this._Zoom="4";this._MapStyle="r";this._Fixed=false;this._MapMode=VEMapMode.Mode2D;this._ShowDashboard=true;
    this._ShowSwitch=true;this._DashboardSize=VEDashboardSize.Normal;this._TileBuffer=0;this._Shapes=null;this._hiddenFieldAlreadySet=false;
    this._ShowTraffic=false;this._ShowTrafficLegend=false;this._TrafficLegendText=null;
    this._AsyncPostbackPassShapes=true;this._AppPathRoot=null;this._AppPathDomain=null;this._CustomInfoBoxStylesEnabled=false;
    this._OnClientMapLoaded=null;
    function fcd(e,h){return Function.createDelegate(e,h);}
    /*Map Events*/
    this._OnMapLoaded_Handled=false;
    this._changeMapStyleHandler=fcd(this,this._onChangeMapStyle);
    this._OnChangeMapStyle_Handled=null;
    this._changeViewHandler=fcd(this,this._onChangeView);
    this._OnChangeView_Handled=null;
    this._endPanHandler=fcd(this,this._onEndPan);
    this._OnEndPan_Handled=null;
    this._endZoomHandler=fcd(this,this._onEndZoom);
    this._OnEndZoom_Handled=null;
    this._errorHandler=fcd(this,this._onError);
    this._OnError_Handled=null;
    this._initModeHandler=fcd(this,this._onInitMode);
    this._modeNotAvailableHandler=fcd(this,this._onModeNotAvailable);
    this._obliqueChangeHandler=fcd(this,this._onObliqueChange);
    this._obliqueEnterHandler=fcd(this,this._onObliqueEnter);
    this._OnObliqueEnter_Handled=null;    
    this._obliqueLeaveHandler=fcd(this,this._onObliqueLeave);
    this._OnObliqueLeave_Handled=null;
    this._resizeHandler=fcd(this,this._onResize);
    this._startPanHandler=fcd(this,this._onStartPan);
    this._startZoomHandler=fcd(this,this._onStartZoom);
    /*Mouse Events*/
    this._clickHandler=fcd(this,this._onClick);this._OnClick_Handled=null;
    this._onDoubleClickHandler=fcd(this,this._onDoubleClick);
    this._onMouseDownHandler=fcd(this,this._onMouseDown);
    this._onMouseMoveHandler=fcd(this,this._onMouseMove);
    this._onMouseOutHandler=fcd(this,this._onMouseOut);
    this._onMouseOverHandler=fcd(this,this._onMouseOver);
    this._onMouseUpHandler=fcd(this,this._onMouseUp);
    this._onMouseWheelHandler=fcd(this,this._onMouseWheel);
    /*Keyboard Events*/
    this._onKeyPressHandler=fcd(this,this._onKeyPress);
    this._onKeyDownHandler=fcd(this,this._onKeyDown);
    this._onKeyUpHandler=fcd(this,this._onKeyUp);
    
    this._apploaded=false;
    this._app_onload$delegate = Function.createDelegate(this, this._app_onload);
    this._pageLoadingHandler$delegate = Function.createDelegate(this, this._pageLoadingHandler);
    this._pageBeginRequestHandler$delegate = Function.createDelegate(this, this._pageBeginRequestHandler);
    this._map_OnLoad$delegate = fcd(this,this._map_OnLoad);
}
Simplovation.Web.Maps.VE.Map.prototype={
initialize:function()
{
    Simplovation.Web.Maps.VE.Map.callBaseMethod(this,"initialize");
    Sys.Application.add_load(this._app_onload$delegate);
    
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(this._pageLoadingHandler$delegate);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(this._pageBeginRequestHandler$delegate);
        
    /*All other Map stuff*/
    if(this._LatLong!=null){this._LatLong=Sys.Serialization.JavaScriptSerializer.deserialize(this._LatLong);}
    if(!isNaN(this._MapStyle)){if(this._MapStyle==2){this._MapStyle="a";}else if(this._MapStyle==3){this._MapStyle="h";}else if(this._MapStyle==4){this._MapStyle="o";}else if(this._MapStyle==5){this._MapStyle="s";}else{this._MapStyle="r";}}
    if(!isNaN(this._DashboardSize)){if(this._DashboardSize==2){this._DashboardSize=VEDashboardSize.Small;}else if(this._DashboardSize==3){this._DashboardSize=VEDashboardSize.Tiny;}else{this._DashboardSize=VEDashboardSize.Normal;}}
    
    this._Map=new VEMap(this.get_id()+"_Map");
    if(this._DashboardSize!=VEDashboardSize.Normal){this._Map.SetDashboardSize(this._DashboardSize);}
    if(this._TileBuffer!=0){this._Map.SetTileBuffer(this._TileBuffer);}
    this._Map.onLoadMap=this._map_OnLoad$delegate;
    this._Map.LoadMap(
        (this._LatLong.Latitude!=0?new VELatLong(this._LatLong.Latitude,this._LatLong.Longitude):null),
        this._Zoom,
        this._MapStyle,
        this._Fixed,
        this._MapMode,
        this._ShowSwitch
        );
    if(this._DistanceUnit!=null)
    {
        if(this._DistanceUnit==1){this._DistanceUnit=VEDistanceUnit.Kilometers;}else{this._DistanceUnit=VEDistanceUnit.Miles;}
        this._Map.SetScaleBarDistanceUnit(this._DistanceUnit);
    }
    if(this._CustomInfoBoxStylesEnabled){this._Map.ClearInfoBoxStyles();}
    if(this._ShowTraffic)
    {
        this._Map.LoadTraffic(true);
    }
    if(this._ShowTrafficLegend)
    {
        this._Map.ShowTrafficLegend();
        if(this._TrafficLegendText!=null)
        {
            this._Map.SetTrafficLegendText(this._TrafficLegendText);
        }
    }
    
    /*Attach Events*/
    function av(m,n,h){m._Map.AttachEvent(n,h);}
    /*Map*/
    av(this,"onchangemapstyle",this._changeMapStyleHandler);
    av(this,"onchangeview",this._changeViewHandler);
    av(this,"onendpan",this._endPanHandler);
    av(this,"onendzoom",this._endZoomHandler);
    av(this,"onerror",this._errorHandler);
    av(this,"oninitmode",this._initModeHandler);
    av(this,"onmodenotavailable",this._modeNotAvailableHandler);
    av(this,"onobliquechange",this._obliqueChangeHandler);
    av(this,"onobliqueenter",this._obliqueEnterHandler);
    av(this,"onobliqueleave",this._obliqueLeaveHandler);
    av(this,"onresize",this._resizeHandler);
    av(this,"onstartpan",this._startPanHandler);
    av(this,"onstartzoom",this._startZoomHandler);
    /*Mouse*/
    av(this,"onclick",this._clickHandler);
    av(this,"ondoubleclick",this._onDoubleClickHandler);
    av(this,"onmousedown",this._onMouseDownHandler);
    av(this,"onmousemove",this._onMouseMoveHandler);
    av(this,"onmouseout",this._onMouseOutHandler);
    av(this,"onmouseover",this._onMouseOverHandler);
    av(this,"onmouseup",this._onMouseUpHandler);
    av(this,"onmousewheel",this._onMouseWheelHandler);
    /*Keyboard*/
    av(this,"onkeypress",this._onKeyPressHandler);
    av(this,"onkeydown",this._onKeyDownHandler);
    av(this,"onkeyup",this._onKeyUpHandler);
    
    if(this._ShowDashboard==false){this._Map.HideDashboard();}
    if(this._Shapes!=null){this._loadShapesFromJSON(this._Shapes);}
},
dispose:function(){
    Sys.Application.remove_load(this._app_onload$delegate);
    if (this._Map != null)
    {
        this._Map.Dispose();
    }
    if (typeof(Sys.WebForms)!=="undefined" && typeof(Sys.WebForms.PageRequestManager)!=="undefined")
    {
        Sys.WebForms.PageRequestManager.getInstance().remove_pageLoading(this._pageLoadingHandler$delegate);
        Sys.WebForms.PageRequestManager.getInstance().remove_beginRequest(this._pageBeginRequestHandler$delegate);
    }
    Simplovation.Web.Maps.VE.Map.callBaseMethod(this,"dispose");
},
_app_onload:function(sender, e){
    if (!this._apploaded)
    {
        this._apploaded = true;
        // Put all Application Load stuff here
    }
},
_map_OnLoad:function(e){
    if (this.get_OnMapLoaded_Handled()) { this._triggerPostback("maploaded",null,null); }
    if(this._OnClientMapLoaded)
    {
        var maploaded$delegate = Function.createDelegate(this, eval(this._OnClientMapLoaded));
        maploaded$delegate(this, e);
    }
},
_loadShapesFromJSON:function(json){this._Shapes=Sys.Serialization.JavaScriptSerializer.deserialize(json);this._loadShapesFromCollection(this._Shapes);},
_loadShapesFromCollection:function(col)
{
    for(var i=0;i<col.length;i++)
    {
        this.AddShape(col[i]);
    }
},
_getVEShape:function(s)
{
    if(s.Type==1){s.Type=VEShapeType.Polyline;}else if(s.Type==2){s.Type=VEShapeType.Polygon;}else{s.Type=VEShapeType.Pushpin;}
    var points=new Array();
    for(var p=0;p<s.Points.length;p++)
    {
        points[points.length]=new VELatLong(s.Points[p].Latitude,s.Points[p].Longitude);
    }
    var shape=new VEShape(s.Type, points);
    
    this._setVEShapeProperties(s, shape);
    
    return shape;
},
_updateVEShape:function(s)
{
    var shape = this.get_Map().GetShapeByID(s.ClientID);
    if (shape == null)
    {
        alert("Shape (" + s.ClientID + ") not found.");
    }
    else
    {
        if(s.Type==1){s.Type=VEShapeType.Polyline;}else if(s.Type==2){s.Type=VEShapeType.Polygon;}else{s.Type=VEShapeType.Pushpin;}
        this._setVEShapeProperties(s, shape);
    }    
},
_setVEShapeProperties:function(s, shape)
{
    if(s.CustomIcon!=null)
    {
        shape.SetCustomIcon(s.CustomIcon);
    }
    if(s.Description!=null)
    {
        shape.SetDescription(s.Description);
    }
    if(s.FillColor!=null)
    {
        shape.SetFillColor(new VEColor(s.FillColor.R,s.FillColor.G,s.FillColor.B,s.FillColor.A));
    }
    if(s.IconAnchor!=null)
    {
        shape.SetIconAnchor(new VELatLong(s.IconAnchor.Latitude,s.IconAnchor.Longitude));
    }
    if(s.LineColor!=null)
    {
        shape.SetLineColor(new VEColor(s.LineColor.R,s.LineColor.G,s.LineColor.B,s.LineColor.A));
    }
    if(s.Type!=VEShapeType.Pushpin)
    {
        if(s.LineWidth>0)
        {
            shape.SetLineWidth(s.LineWidth);
        }
    }
    if(s.MoreInfoURL!=null)
    {
        shape.SetMoreInfoURL(Simplovation.Web.Maps.VE.Utils.UrlHelper.ToAbsolute(s.MoreInfoURL,this.get_AppPathRoot()));
    }
    if(s.PhotoURL!=null)
    {
        shape.SetPhotoURL(Simplovation.Web.Maps.VE.Utils.UrlHelper.ToAbsolute(s.PhotoURL,this.get_AppPathRoot()));
    }
    shape.SetTitle(s.Title);
    if(s.ShowIcon){shape.ShowIcon();}else{shape.HideIcon();}
},

AddShape:function(s)
{
    if (s.ClientID==null)
    {
        /*plot new shape*/
        var shape = this._getVEShape(s);
        this._Map.AddShape(shape);
    }
    else
    {
        /*modify existing shape*/
        this._updateVEShape(s);
    }
},
DeleteShapeById:function(id){var s=this.GetShapeByID(id);this.DeleteShape(s);},


AddControl:function(e, z){this.get_Map().AddControl(e, z);},
AddShapeLayer:function(l){this.get_Map().AddShapeLayer(l);},
AddTileLayer:function(l,v){this.get_Map().AddTileLayer(l,v);},
Clear:function(){this.get_Map().Clear();},
ClearInfoBoxStyles:function(){this.get_Map().ClearInfoBoxStyles();},
ClearTraffic:function(){this.set_ShowTraffic(false);this.get_Map().ClearTraffic();},
DeleteAllShapeLayers:function(){this.get_Map().DeleteAllShapeLayers();},
DeleteAllShapes:function(){this.get_Map().DeleteAllShapes();},
DeleteControl:function(e){this.get_Map().DeleteControl(e);},
DeleteRoute:function(){this.get_Map().DeleteRoute();},
DeleteShape:function(s){if(s!=null){this.get_Map().DeleteShape(s);s=null;}},
DeleteShapeLayer:function(l){this.get_Map().DeleteShapeLayer(l);},
DeleteTileLayer:function(id){this.get_Map().DeleteTileLayer(id)},
EnableShapeDisplayThreshold:function(v){this.get_Map().EnableShapeDisplayThreshold(v);},
EndContinuousPan:function(){this.get_Map().EndContinuousPan();},
Find:function(what,where,findType,shapeLayer,startIndex,numberOfResults,showResults,createResults,useDefaultDisambiguation,setBestMapView,callback){this.get_Map.Find(what,where,findType,shapeLayer,startIndex,numberOfResults,showResults,createResults,useDefaultDisambiguation,setBestMapView,callback);},
GetAltitude:function(){return this.get_Map().GetAltitude();},
GetBirdseyeScene:function(){return this.get_Map().GetBirdseyeScene();},
GetCenter:function(){return this.get_Map().GetCenter();},
GetDirections:function(l,o){this.get_Map().GetDirections(l,o);},
GetHeading:function(){return this.get_Map().GetHeading();},
GetLeft:function(){return this.get_Map().GetLeft();},
GetMapMode:function(){return this.get_Map().GetMapMode();},
GetMapStyle:function(){return this.get_Map().GetMapStyle();},
GetMapView:function(){return this.get_Map().GetMapView();},
GetPitch:function(){return this.get_Map().GetPitch();},
GetShapeByID:function(id){return this.get_Map().GetShapeByID(id);},
GetShapeLayerByIndex:function(i){return this.get_Map().GetShapeLayerByIndex(i);},
GetShapeLayerCount:function(i){return this.get_Map().GetShapeLayerCount(i);},
GetTileLayerByID:function(id){return this.get_Map().GetTileLayerByID(id);},
GetTileLayerByIndex:function(i){return this.get_Map().GetTileLayerByIndex(i);},
GetTileLayerCount:function(){return this.get_Map().GetTileLayerCount();},
GetTop:function(){return this.get_Map().GetTop();},
GetVersion:function(){return VEMap.GetVersion();},
GetZoomLevel:function(){return this.get_Map().GetZoomLevel();},
Hide3DNavigationControl:function(){this.get_Map().Hide3DNavigationControl();},
HideAllShapeLayers:function(){this.get_Map().HideAllShapeLayers();},
HideControl:function(e){this.get_Map().HideControl(e);},
HideDashboard:function(){this._ShowDashboard=false;this.get_Map().HideDashboard();},
HideFindControl:function(){this.get_Map().HideFindControl();},
HideInfoBox:function(){this.get_Map().HideInfoBox();},
HideMiniMap:function(){this.get_Map().HideMiniMap();},
HideTileLayer:function(l){this.get_Map().HideTileLayer(l);},
HideTrafficLegend:function(){this._ShowTrafficLegend=false;this.get_Map().HideTrafficLegend();},
ImportShapeLayerData:function(s,c,v){this.get_Map().ImportShapeLayerData(s,c,v);},
IncludePointInView:function(l){this.get_Map().IncludePointInView(l);},
IsBirdseyeAvailable:function(){return this.get_Map().IsBirdseyeAvailable();},
LatLongToPixel:function(l){return this.get_Map().LatLongToPixel(l);},
LoadTraffic:function(v){this.set_ShowTraffic(true);this.get_Map().LoadTraffic(v);},
Pan:function(x,y){this.get_Map().Pan(x,y);},
PanToLatLong:function(l){this.get_Map().PanToLatLong(l);},
PixelToLatLong:function(p){return this.get_Map().PixelToLatLong(p);},
Resize:function(w,h){this.get_Map().Resize(w,h);},
SetAltitude:function(a){this.get_Map().SetAltitude(a);},
SetBirdseyeOrientation:function(o){this.get_Map().SetBirdseyeOrientation(o);},
SetBirdseyeScene:function(a,b,c,d){this.get_Map().SetBirdseyeScene(a,b,c,d);},
SetCenter:function(l){this.get_Map().SetCenter(l);},
SetCenterAndZoom:function(l,z){this.get_Map().SetCenterAndZoom(l,z);},
SetDashboardSize:function(d){this.get_Map().SetDashboardSize(d);},
SetDefaultInfoBoxStyles:function(){this.get_Map().SetDefaultInfoBoxStyles();},
SetFailedShapeRequest:function(p){this.get_Map().SetFailedShapeRequest(p);},
SetHeading:function(h){this.get_Map().SetHeading(h);},
SetMapMode:function(v){this.get_Map().SetMapMode(v);},
SetMapStyle:function(v){if(!isNaN(v)){if(v==2){v="a";}else if(v==3){v="h";}else if(v==4){v="o";}else if(v==5){v="s";}else{v="r";}}this.get_Map().SetMapStyle(v);},
SetMapView:function(v){this.get_Map().SetMapView(v);},
SetMouseWheelZoomToCenter:function(v){this.get_Map().SetMouseWheelZoomToCenter(v);},
SetPitch:function(p){this.get_Map().SetPitch(p);},
SetShapesAccuracy:function(p){this.get_Map().SetShapesAccuracy(p);},
SetShapesAccuracyRequestLimit:function(v){this.get_Map().SetShapesAccuracyRequestLimit(v);},
SetTileBuffer:function(v){this.get_Map().SetTileBuffer(v);},
SetTrafficLegendText:function(v){this._TrafficLegendText=v;this.get_Map().SetTrafficLegendText(v);},
SetZoomLevel:function(v){this.get_Map().SetZoomLevel(v);},
Show3DNavigationControl:function(){this.get_Map().Show3DNavigationControl();},
ShowAllShapeLayers:function(){this.get_Map().ShowAllShapeLayers();},
ShowControl:function(e){this.get_Map().ShowControl();},
ShowDashboard:function(){this._ShowDashboard=true;this.get_Map().ShowDashboard();},
ShowDisambiguationDialog:function(v){this.get_Map().ShowDisambiguationDialog(v);},
ShowFindControl:function(){this.get_Map().ShowFindControl();},
ShowInfoBox:function(s,a,o){this.get_Map().ShowInfoBox(s,a,o);},
ShowMessage:function(m){this.get_Map().ShowMessage(m);},
ShowMiniMap:function(x,y,s){this.get_Map().ShowMiniMap(x,y,s);},
ShowTileLayer:function(id){this.get_Map().ShowTileLayer(id);},
ShowTrafficLegend:function(x,y){this._ShowTrafficLegend=true;this.get_Map().ShowTrafficLegend(x,y);},
StartContinuousPan:function(x,y){this.get_Map().StartContinuousPan(x,y);},
ZoomIn:function(){this.get_Map().ZoomIn();},
ZoomOut:function(){this.get_Map().ZoomOut();},

        
/*Property Accessors*/
get_Map:function(){return this._Map;},
get_LatLong:function(){return this._LatLong;},set_LatLong:function(v){this._LatLong=v;},
get_Zoom:function(){return this._Zoom;},set_Zoom:function(v){this._Zoom=v;},
get_MapStyle:function(){return this._MapStyle;},set_MapStyle:function(v){this._MapStyle=v;},
get_AsyncPostbackPassShapes:function(){return this._AsyncPostbackPassShapes;},set_AsyncPostbackPassShapes:function(v){this._AsyncPostbackPassShapes=v;},
get_Fixed:function(){return this._Fixed;},set_Fixed:function(v){this._Fixed=v;},
get_CustomInfoBoxStylesEnabled:function(){return this._CustomInfoBoxStylesEnabled;},set_CustomInfoBoxStylesEnabled:function(v){this._CustomInfoBoxStylesEnabled=v;},
get_DistanceUnit:function(){return this._DistanceUnit;},set_DistanceUnit:function(v){this._DistanceUnit=v;},
get_MapMode:function(){return this._MapMode;},set_MapMode:function(v){this._MapMode=v;},
get_ShowDashboard:function(){return this._ShowDashboard;},set_ShowDashboard:function(v){this._ShowDashboard=v;},
get_ShowSwitch:function(){return this._ShowSwitch;},set_ShowSwitch:function(v){this._ShowSwitch=v;},
get_DashboardSize:function(){return this._DashboardSize;},set_DashboardSize:function(v){this._DashboardSize=v;},
get_TileBuffer:function(){return this._TileBuffer;},set_TileBuffer:function(v){this._TileBuffer=v;},
get_Shapes:function(){return this._Shapes;},set_Shapes:function(v){this._Shapes=v;},
get_ShowTraffic:function(){return this._ShowTraffic;},set_ShowTraffic:function(v){this._ShowTraffic=v;},
get_ShowTrafficLegend:function(){return this._ShowTrafficLegend;},set_ShowTrafficLegend:function(v){this._ShowTrafficLegend=v;},
get_TrafficLegendText:function(){return this._TrafficLegendText;},set_TrafficLegendText:function(v){this._TrafficLegendText=v;},
get_AppPathRoot:function(){return this._AppPathRoot;},set_AppPathRoot:function(v){this._AppPathRoot = v;},
/* Map Events Handled */
get_OnMapLoaded_Handled:function(){return this._OnMapLoaded_Handled;},set_OnMapLoaded_Handled:function(v){this._OnMapLoaded_Handled=v;},
get_OnClientMapLoaded:function(){return this._OnClientMapLoaded;},set_OnClientMapLoaded:function(v){this._OnClientMapLoaded=v;},
get_OnChangeMapStyle_Handled:function(){return this._OnChangeMapStyle_Handled;},set_OnChangeMapStyle_Handled:function(v){this._OnChangeMapStyle_Handled=v;},
get_OnChangeView_Handled:function(){return this._OnChangeView_Handled;},set_OnChangeView_Handled:function(v){this._OnChangeView_Handled=v;},get_OnEndPan_Handled:function(){return this._OnEndPan_Handled;},set_OnEndPan_Handled:function(v){this._OnEndPan_Handled=v;},get_OnEndZoom_Handled:function(){return this._OnEndZoom_Handled;},set_OnEndZoom_Handled:function(v){this._OnEndZoom_Handled=v;},get_OnObliqueEnter_Handled:function(){return this._OnObliqueEnter_Handled;},set_OnObliqueEnter_Handled:function(v){this._OnObliqueEnter_Handled=v;},get_OnObliqueLeave_Handled:function(){return this._OnObliqueLeave_Handled;},set_OnObliqueLeave_Handled:function(v){this._OnObliqueLeave_Handled=v;},/* Mouse Events Handled */get_OnClick_Handled:function(){return this._OnClick_Handled;},set_OnClick_Handled:function(v){this._OnClick_Handled=v;},
_triggerPostback:function(evtName,evtArgs,directionEventArgs){
    var mapData = this._setHiddenFieldMapData(evtName,evtArgs,directionEventArgs);
    this._hiddenFieldAlreadySet=true;
    if (mapData.Latitude!=null&&mapData.Longitude!=null)
    {
        /*Trigger Postback*/
        var lb=document.getElementById(this.get_id()+'_UpdatePanel_LinkButton');
        var s=lb.href.substring(lb.href.indexOf(":")+1);
        eval(s);
    }
},
_pageLoadingHandler:function(sender, args){
    SimplovationWebMapsVEMap_HandlePageLoadingDataItems(this.get_id(), args.get_dataItems());
},
_pageBeginRequestHandler:function(sender, args){
    if(!this._hiddenFieldAlreadySet)
    {
        this._setHiddenFieldMapData("");
        /*Add AsyncMapData to async request*/
        var hiddenField=document.getElementById(this.get_id()+'_UpdatePanel_HiddenField');
        var hiddenFieldPostbackName=hiddenField.name;
        var newHiddenFieldPostbackValue=hiddenFieldPostbackName+'='+hiddenField.value;
        var items=args.get_request().get_body().split("&");
        var newBody="";
        var hiddenFieldAlreadyIncluded=false;
        
        while(hiddenFieldPostbackName.indexOf("$")!=-1){/*fixes bug introduced in ASP.NET 3.5*/hiddenFieldPostbackName=hiddenFieldPostbackName.replace("$","%24");}
        
        for(var i=0;i<items.length;i++)
        {
            if(newBody.length!=0){newBody+="&";}
            if(items[i].substring(0,hiddenFieldPostbackName.length)==hiddenFieldPostbackName&&!hiddenFieldAlreadyIncluded)
            {
                newBody+=newHiddenFieldPostbackValue;
                hiddenFieldAlreadyIncluded=true;
            }
            else
            {
                newBody+=items[i];
            }
        }
        args.get_request().set_body(newBody);
    }
    this._hiddenFieldAlreadySet=false;
},
_setHiddenFieldMapData:function(evtName,evtArgs,directionEventArgs){
    var hf=document.getElementById(this.get_id()+'_UpdatePanel_HiddenField');
    var mapData=new Simplovation.Web.Maps.VE.AsyncMapData();
    mapData.EventName=evtName;
    mapData.EventArgs=evtArgs;
    mapData.ZoomLevel=this._Map.GetZoomLevel();
    var mapStyle=this._Map.GetMapStyle();
    if(mapStyle=="a"){mapData.MapStyle=2;}else if(mapStyle=="h"){mapData.MapStyle=3;}else if(mapStyle=="o"){mapData.MapStyle=4;}else if(mapStyle=="s"){mapData.MapStyle=5;}else{/*r*/mapData.MapStyle=1;}
    if(mapData.MapStyle!=4){mapData.MapView=this._Map.GetMapView();}
    mapData.Latitude=this._Map.GetCenter().Latitude;
    mapData.Longitude=this._Map.GetCenter().Longitude;
    mapData.ShowDashboard=this._ShowDashboard;
    mapData.CustomInfoBoxStyles=this._CustomInfoBoxStyles;
    mapData.ShowTraffic=this._ShowTraffic;
    mapData.ShowTrafficLegend=this._ShowTrafficLegend;
    if(evtName=="maploaded")
    {
        mapData.MapLoadedEventArgs=new Object();
        mapData.MapLoadedEventArgs.MapView=this._Map.GetMapView();
    }
    if(this._DistanceUnit==VEDistanceUnit.Miles)
    {
        mapData.DistanceUnit=0
    }
    else if(this._DistanceUnit==VEDistanceUnit.Kilometers)
    {
        mapData.DistanceUnit=1;
    }
    else
    {
        mapData.DistanceUnit=this._DistanceUnit;
    }
    if(evtName=="onclick")
    {
        if(this._Map.GetMapMode()==VEMapMode.Mode2D)
        {
            /*2D Mode*/
            var clickedLatLong=this._Map.PixelToLatLong(new VEPixel(evtArgs.mapX,evtArgs.mapY));
            if(clickedLatLong.Latitude != null)
            {
                mapData.ClickedLatitude=clickedLatLong.Latitude;
                mapData.ClickedLongitude=clickedLatLong.Longitude;
            }
            else
            {
                /* this occurs in Birdseye/Oblique map style */
            }
        }
        else
        {
            /*3D Mode*/
            if(mapData.EventArgs.latLong!=undefined)
            {
                mapData.ClickedLatitude=mapData.EventArgs.latLong.Latitude;
                mapData.ClickedLongitude=mapData.EventArgs.latLong.Longitude;
            }
            else
            {
                mapData.ClickedLatitude=mapData.EventArgs.latlong.Latitude;
                mapData.ClickedLongitude=mapData.EventArgs.latlong.Longitude;
            }
        }
    }
    /*Get map Shapes to pass back to server*/
    var myShapes=new Array();
    if(this._AsyncPostbackPassShapes)
    {
        /*Get all shapes to postback*/
        var sl = this.get_Map().GetShapeLayerByIndex(0);
        for(var i = 0; i < sl.GetShapeCount(); i++)
        {
            Array.add(myShapes,this._convertShapeToPostback(sl.GetShapeByIndex(i)));
        }
    }
    else
    {
        if(evtArgs!=null)
        {
            if(evtArgs.elementID!=null)
            {
                Array.add(myShapes,this._convertShapeToPostback(evtArgs.elementID));
            }
        }
    }
    mapData.Shapes=myShapes;
    hf.value=Sys.Serialization.JavaScriptSerializer.serialize(mapData);
    if(directionEventArgs!=null)
    {
        /*serialize routelegs*/
        var route = directionEventArgs;
        var sbRoute = new Sys.StringBuilder();
        var itinerary;sbRoute.append("{\"Distance\":");
        sbRoute.append(route.Distance);
        sbRoute.append(",\"RouteLegs\":[");
        for(var rl=0;rl<route.RouteLegs.length;rl++)
        {
            if(rl>0){sbRoute.append(",");}
            sbRoute.append("{\"Distance\":");
            sbRoute.append(route.RouteLegs[rl].Distance);
            sbRoute.append(",\"Itinerary\":{\"Items\":[");
            for(var i=0;i<route.RouteLegs[rl].Itinerary.Items.length;i++)
            {
                itinerary=route.RouteLegs[rl].Itinerary.Items[i];
                if(i>0){sbRoute.append(",");}
                sbRoute.append("{");
                sbRoute.append("\"Distance\":");
                sbRoute.append(itinerary.Distance);
                sbRoute.append(",\"LatLong\":{\"Latitude\":");
                sbRoute.append(itinerary.LatLong.Latitude);
                sbRoute.append(",\"Longitude\":");
                sbRoute.append(itinerary.LatLong.Longitude);
                sbRoute.append("}");
                sbRoute.append(",\"Text\":");
                sbRoute.append(Sys.Serialization.JavaScriptSerializer.serialize(itinerary.Text));
                sbRoute.append("}");
            }
            sbRoute.append("]}}");
        }
        sbRoute.append("]}");
        var hfd=document.getElementById(this.get_id()+'_UpdatePanel_HiddenField_Directions');
        hfd.value=sbRoute.toString();
    }
    return mapData;
},
_raiseClientSideEvent:function(evtName, e)
{
    var h = this.get_events().getHandler(evtName);
    if (h){h(this, e);}
},
addHandler:function(eventName, method){this.get_events().addHandler(eventName, method);},
removeHandler:function(eventName, method){this.get_events().removeHandler(eventName, method);},

_convertShapeToPostback:function(shape){var myShape=new Simplovation.Web.Maps.VE.Shape();var mapShape;if(typeof(shape)!="string"){mapShape=shape;myShape.ClientID=mapShape.GetID();}else{myShape.ClientID=shape;mapShape=this._Map.GetShapeByID(myShape.ClientID);}myShape.Title=Simplovation$Web$Maps$JSONEncodeString(mapShape.GetTitle());myShape.Description=Simplovation$Web$Maps$JSONEncodeString(mapShape.GetDescription());if(mapShape.GetCustomIcon()!=null){myShape.CustomIcon=Simplovation$Web$Maps$JSONEncodeString(mapShape.GetCustomIcon());}myShape.FillColor=mapShape.GetFillColor();myShape.IconAnchor=mapShape.GetIconAnchor();myShape.LineColor=mapShape.GetLineColor();var lineWidth=mapShape.GetLineWidth();if(lineWidth!=null){myShape.LineWidth=lineWidth;}var strMoreInfoUrl=mapShape.GetMoreInfoURL();if(strMoreInfoUrl.substring(0,Simplovation.Web.Maps.VE.Utils.AppPathDomain.length)==Simplovation.Web.Maps.VE.Utils.AppPathDomain){strMoreInfoUrl=strMoreInfoUrl.substring(Simplovation.Web.Maps.VE.Utils.AppPathDomain.length);}if(strMoreInfoUrl.substring(0,this.get_AppPathRoot().length)==this.get_AppPathRoot()){strMoreInfoUrl="~/"+strMoreInfoUrl.substring(this.get_AppPathRoot().length);}myShape.MoreInfoURL=strMoreInfoUrl;var strPhotoUrl=mapShape.GetPhotoURL();if(strPhotoUrl.substring(0,Simplovation.Web.Maps.VE.Utils.AppPathDomain.length)==Simplovation.Web.Maps.VE.Utils.AppPathDomain){strPhotoUrl=strPhotoUrl.substring(Simplovation.Web.Maps.VE.Utils.AppPathDomain.length);}if(strPhotoUrl.substring(0,this.get_AppPathRoot().length)==this.get_AppPathRoot()){strPhotoUrl="~/"+strPhotoUrl.substring(this.get_AppPathRoot().length);}myShape.PhotoURL=strPhotoUrl;myShape.Points=mapShape.GetPoints();if (mapShape.GetType()==VEShapeType.Pushpin){myShape.Type=0;}else if(mapShape.GetType()==VEShapeType.Polygon){myShape.Type=2;}else{/*if(mapShape.GetType()==VEShapeType.Polyline)*/myShape.Type=1;}return myShape},
/*Map Events*/
_onChangeMapStyle:function(e)
{
    if(this.get_OnChangeMapStyle_Handled()){this._triggerPostback("onchangemapstyle",e);}
    this._raiseClientSideEvent("onchangemapstyle",e);
},
_onChangeView:function(e)
{
    if(this.get_OnChangeView_Handled()){this._triggerPostback("onchangeview",e);}
    this._raiseClientSideEvent("onchangeview",e);
},
_onEndPan:function(e)
{
    if(this.get_OnEndPan_Handled()){this._triggerPostback("onendpan",e);}
    this._raiseClientSideEvent("onendpan",e);
},
_onEndZoom:function(e)
{
    if(this.get_OnEndZoom_Handled()){this._triggerPostback("onendzoom",e);}
    this._raiseClientSideEvent("onendzoom",e);
},
_onError:function(e)
{
    this._triggerPostback("onerror",e);
    this._raiseClientSideEvent("onerror",e);
},
_onObliqueEnter:function(e)
{
    if(this.get_OnObliqueEnter_Handled()){this._triggerPostback("onobliqueenter",e);}
    this._raiseClientSideEvent("onobliqueenter",e);
},
_onObliqueLeave:function(e)
{
    if(this.get_OnObliqueLeave_Handled()){this._triggerPostback("onobliqueleave",e);}
    this._raiseClientSideEvent("onobliqueleave",e);
},
_onInitMode:function(e){this._raiseClientSideEvent("oninitmode",e);},
_onModeNotAvailable:function(e){this._raiseClientSideEvent("onmodenotavailable",e);},
_onObliqueChange:function(e){this._raiseClientSideEvent("onobliquechange",e);},
_onResize:function(e){this._raiseClientSideEvent("onresize",e);},
_onStartPan:function(e){this._raiseClientSideEvent("onstartpan",e);},
_onStartZoom:function(e){this._raiseClientSideEvent("onstartzoom",e);},
/*Mouse Events*/
_onClick:function(e)
{
    if(this.get_OnClick_Handled()){this._triggerPostback("onclick", e);}
    this._raiseClientSideEvent("onclick",e);
},
_onDoubleClick:function(e){this._raiseClientSideEvent("ondoubleclick",e);},
_onMouseDown:function(e){this._raiseClientSideEvent("onmousedown",e);},
_onMouseMove:function(e){this._raiseClientSideEvent("onmousemove",e);},
_onMouseOut:function(e){this._raiseClientSideEvent("onmouseout",e);},
_onMouseOver:function(e){this._raiseClientSideEvent("onmouseover",e);},
_onMouseUp:function(e){this._raiseClientSideEvent("onmouseup",e);},
_onMouseWheel:function(e){this._raiseClientSideEvent("onmousewheel",e);},
/*Keyboard Events*/
_onKeyPress:function(e){this._raiseClientSideEvent("onkeypress",e);},
_onKeyDown:function(e){this._raiseClientSideEvent("onkeydown",e);},
_onKeyUp:function(e){this._raiseClientSideEvent("onkeyup",e);}
}

Simplovation.Web.Maps.VE.Map.registerClass("Simplovation.Web.Maps.VE.Map", Sys.UI.Control);


var SimplovationWebMapsVEMap_LastDataItems=null;
function SimplovationWebMapsVEMap_HandlePageLoadingDataItems(s,dataItems)
{
    var m=$find(s);
    var map=m.get_Map();
    document.getElementById(m.get_id()+"_UpdatePanel_HiddenField").value="";
    if(SimplovationWebMapsVEMap_LastDataItems != dataItems[s])
    {
        var mapData=Sys.Serialization.JavaScriptSerializer.deserialize(dataItems[s]);
        SimplovationWebMapsVEMap_LastDataItems=dataItems[s];
        if(mapData.MapStyle!=null)
        {
            m.SetMapStyle(mapData.MapStyle);
        }
        if(mapData.MapMode!=null)
        {
            m.SetMapMode(mapData.MapMode);
        }
        if(mapData.ShowDashboard!=null&&!m._Fixed)
        {
            m._ShowDashboard=mapData.ShowDashboard;
            if(mapData.ShowDashboard)
            {
                map.ShowDashboard();
            }
            else
            {
                map.HideDashboard();
            }
        }
        if(mapData.ShowTraffic!=null)
        {
            if(mapData.ShowTraffic)
            {
                m.LoadTraffic(true);
            }
            else
            {
                m.ClearTraffic();
            }
        }
        if(mapData.ShowTrafficLegend!=null)
        {
            if(mapData.ShowTrafficLegend)
            {
                m.ShowTrafficLegend();
            }
            else
            {
                m.HideTrafficLegend();
            }
        }
        if(mapData.TrafficLegendText!=null)
        {
            m.SetTrafficLegendText(mapData.TrafficLegendText);
        }       
        if(mapData.DeleteShapesFirst!=null)
        {
            if(mapData.DeleteShapesFirst){m.DeleteAllShapes();}
        }
        if(mapData.ShapesToRemove!=null)
        {
            var ids=mapData.ShapesToRemove.split("|");
            for(var i=0;i<ids.length;i++)
            {
                m.DeleteShape(map.GetShapeByID(ids[i]));
            }
        }
        if(mapData.Shapes!=null)
        {
            m._loadShapesFromCollection(mapData.Shapes);
        }
        if(mapData.CustomInfoBoxStylesEnabled!=null)
        {
            this._CustomInfoBoxStylesEnabled=mapData.CustomInfoBoxStylesEnabled;
            if(this._CustomInfoBoxStylesEnabled)
            {
                map.ClearInfoBoxStyles();
            }
            else
            {
                map.SetDefaultInfoBoxStyles();
            }
        }
        if(mapData.ZoomLevel!=null&&mapData.Latitude!=null&&mapData.Longitude!=null)
        {
            map.SetCenterAndZoom(new VELatLong(mapData.Latitude,mapData.Longitude),mapData.ZoomLevel);
        }
        else
        {
            if(mapData.ZoomLevel!=null)
            {
                map.SetZoomLevel(mapData.ZoomLevel);
            }
            if(mapData.Latitude!=null&&mapData.Longitude!=null)
            {
                map.SetCenter(new VELatLong(mapData.Latitude,mapData.Longitude));
            }
        }
        
        if(mapData.Direction_Locations!=null)
        {
            var locations=new Array();
            for(var i=0;i<mapData.Direction_Locations.length;i++)
            {
                var loc=mapData.Direction_Locations[i];
                if(typeof(loc)=="string"){locations[i]=loc;
            }
            else
            {
                locations[i]=new VELatLong(loc.Latitude,loc.Longitude);
            }
        }
        var routeOptions=new VERouteOptions();
        routeOptions.RouteCallback = function(route)
        {
            if(route!=null)
                {
                    /*Wait 1/10th second then trigger event*/
                    m._lastDirectionsLoaded=route;window.setTimeout("var m=$find('"+s+"');m._triggerPostback('directionsloaded',null,m._lastDirectionsLoaded);",100);
                }
            };
            var ro=mapData.Direction_RouteOptions;
            if (ro!=null)
            {
                if(ro.DistanceUnit!=null)
                {
                    routeOptions.DistanceUnit=((ro.DistanceUnit==1)?VERouteDistanceUnit.Kilometer:VERouteDistanceUnit.Mile);
                }
                if(ro.DrawRoute!=null)
                {
                    routeOptions.DrawRoute=ro.DrawRoute;
                }
                if(ro.RouteColor!=null)
                {
                    var c=ro.RouteColor;
                    routeOptions.RouteColor=new VEColor(c.R,c.G,c.B,c.A);
                }
                if(ro.RouteOptimize!=null)
                {
                    routeOptions.RouteOptimize=((ro.RouteOptimize==1)?VERouteOptimize.MinimizeTime:((ro.RouteOptimize==2)?VERouteOptimize.MinimizeDistance:VERouteOptimize.Default));
                }
                if(ro.RouteWeight!=null)
                {
                    routeOptions.RouteWeight=ro.RouteWeight;
                }
                if(ro.RouteZIndex!=null)
                {
                    routeOptions.RouteZIndex=ro.RouteZIndex;
                }
                if(ro.SetBestMapView!=null)
                {
                    routeOptions.SetBestMapView=ro.SetBestMapView;
                }
                if(ro.ShowDisambiguation!=null)
                {
                    routeOptions.ShowDisambiguation=ro.ShowDisambiguation;
                }
                if(ro.ShowErrorMessages!=null)
                {
                    routeOptions.ShowErrorMessages=ro.ShowErrorMessages;
                }
            }
            map.GetDirections(locations,routeOptions);
        }

        m._setHiddenFieldMapData("");
    }
}
Simplovation.Web.Maps.VE.AsyncMapData=function(){this.EventName=null;this.EventArgs=null;this.ZoomLevel=null;this.Latitude=null;this.Longitude=null;this.MapStyle=null;this.ShowDashboard=null;this.MapView=null;this.ClickedLatitude=null;this.ClickedLongitude=null;this.Direction_Locations=null;this.Direction_RouteOptions=null;this.MapLoadedEventArgs=null;this.CustomInfoBoxStylesEnabled=null;this.ShowTraffic=null;this.ShowTrafficLegend=null;this.TrafficLegendText=null;}
Simplovation.Web.Maps.VE.Shape=function(){this.ClientID=null;this.CustomIcon=null;this.Description=null;this.FillColor=null;this.IconAnchor=null;this.LineColor=null;this.LineWidth=2;this.MoreInfoURL=null;this.PhotoURL=null;this.Points=null;this.Title=null;this.Type=0;}
function Simplovation$Web$Maps$JSONEncodeString(str){var newstr=str;if(typeof(str)!="string"){/*VECustomIconSpecification*/newstr=str.CustomHTML;}while(newstr.indexOf("<")!=-1){newstr=newstr.replace("<","\\u003c");}while(newstr.indexOf(">")!=-1){newstr=newstr.replace(">","\\u003e");}while(newstr.indexOf("&")!=-1){newstr=newstr.replace("&","\\u0026");}return newstr;}
Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();