//these are the user-initiated functions\\

var units = null;  // Since I don't see a units on VERoute
var AltitudeSet = false;  // User must call set altitude before get altitude
var blankMapLoaded = false; //Whether the current map shows no base tiles
function ChangeMap(e) //handles a click on a subnode in the Task Tree
{
    //unselect the current tree choice
    if (id!=-1) {document.getElementById(id).className="SDKtreesubnode";}
    if (id!=100) document.getElementById(100).className="SDKtreesubnode"; //clear first node selection from onload
    
    //get the new id of the selected tree node
    if (e.target) id = e.target.id; //moz
    else if (e.srcElement) id = e.srcElement.id; //ie
    
    //set the style of the selected node (highlights)
    document.getElementById(id).className="SDKtreeselected";
    
    //if there is currently an alert on the screen, clear it
    HideAlert();
    
    if(eventsAttached)
        RemoveEvents();

    if (blankMapLoaded)
    {
        blankMapLoaded = false;
        GetDefaultMap();
    }
    
    //Deleting any find shapes
    DeleteFindLayer();
    
    SwitchBackToHomeTabs();
    setTimeout('DoTreeClick()',100); //this delay is required to ensure the tree is updated correctly.
}
function SwitchBackToHomeTabs() {
    doClick(1); //sets us back on the map tab
}	
function DoTreeClick()
/*
for each node in the XML file, we read the id to see what it is, 
we then set the reference topic, and then call
the applicable code. All events are tracked by adCenter through the hierarchy object.
 */
{
    var hierarchy = ''; //Set up hierarchy for analytics view
    
    if      (id=="100") { refTopic="bb412546.aspx"; refsTable=null; GetDefaultMap(); hierarchy += 'Show/DefaultMap'; }
    else if (id=="101") { refTopic="bb412546.aspx"; refsTable=null; GetMap(18,47.6207,-122.349,'h',false); hierarchy += 'Show/SpecificMap'; }
    else if (id=="102") { refTopic="bb412504.aspx"; refsTable=null; GetMapWithCallback(); hierarchy += 'Show/Callback'; }
    else if (id=="103") { refTopic="bb412546.aspx"; refsTable=null; if (CheckBrowser()) {map.SetMapMode(VEMapMode.Mode3D);} hierarchy += 'Show/3DMap'; } 
    else if (id == "104") { // Get traffic
        refTopic="bb877877.aspx";
        refsTable=null;

        DoGetTrafficUI();
        hierarchy += 'Show/Traffic';
    }
    
    else if (id=="201") { refTopic="bb429640.aspx"; refsTable=new Object();refsTable['VEMap.SetZoomLevel']='bb429640.aspx';refsTable['VEMap.ZoomIn']='bb412525.aspx';refsTable['VEMap.ZoomOut']='bb429543.aspx'; DoZoomUI(); hierarchy += 'Control/Zoom';}
    else if (id=="202") { refTopic="bb412439.aspx"; refsTable=null; DoCenterUI(); hierarchy += 'Control/SetCenter';}
    else if (id=="203") { refTopic="bb412454.aspx"; refsTable=null; DoMapStyleUI(); hierarchy += 'Control/MapStyle';}
    else if (id=="204") { refTopic="bb412466.aspx"; refsTable=new Object();refsTable['VEMap.PanToLatLong']='bb412466.aspx';refsTable['VEMap.Pan']='bb412449.aspx';refsTable['VEMap.StartContinuousPan']='bb412531.aspx';refsTable['VEMap.EndContinuousPan']='bb429598.aspx';  DoPanUI(); hierarchy += 'Control/PanMap';}
    else if (id=="205") { refTopic="cc966724.aspx"; refsTable = null; GetBlankMap(); DoAlert("A blank Map has no base map tiles.<br>Use VEMap.AddTileLayer to add your own tiles to the map."); hierarchy += 'Control/LoadBlank'; }
    
    else if (id=="1101") { refTopic="bb412545.aspx"; refsTable=new Object();refsTable['VEMap.SetDashboardSize']='bb412545.aspx';refsTable['VEMap.ShowDashboard']='bb412416.aspx';refsTable['VEMap.HideDashboard']='bb412416.aspx'; DoNavControlsUI(); hierarchy += 'ShowHide/NavControls';}
    else if (id=="1102") { refTopic="bb412549.aspx"; refsTable=new Object();refsTable['VEMap.ShowMiniMap']='bb412549.aspx';refsTable['VEMap.HideMiniMap']='bb412432.aspx';refsTable['VEMap.Show3DNavigationControl']='bb412494.aspx';refsTable['VEMap.Hide3DNavigationControl']='bb412557.aspx';refsTable['VEMap.ShowScalebar']='cc966838.aspx';refsTable['VEMap.HideScalebar']='cc980906.aspx';  DoControlsUI(); hierarchy += 'ShowHide/Controls';}
    else if (id=="1103") { refTopic="bb412435.aspx"; refsTable=null; AddMyControl(); hierarchy += 'ShowHide/AddCustom';}
    else if (id=="1104") { refTopic="bb544963.aspx"; refsTable=null; RemoveMyControl(); hierarchy += 'ShowHide/RemoveCustom';}
    
    else if (id=="301") { refTopic="bb412436.aspx"; refsTable=null; DoAddDefaultShapeUI(); hierarchy += 'DefaultShapes/AddShapes';}
    else if (id=="302") { refTopic="bb544965.aspx"; refsTable=new Object();refsTable['VEShape.Show']='bb544965.aspx';refsTable['VEShape.Hide']='bb544960.aspx'; DoShowHideShapeUI(); hierarchy += 'DefaultShapes/ShowHide';}
    else if (id=="303") { refTopic="bb429572.aspx"; refsTable=null; DoDeleteShapeUI(); hierarchy += 'DefaultShapes/DeleteShape';}
    else if (id=="304") { refTopic="bb429616.aspx"; refsTable=null; DeleteAllShapes(); hierarchy += 'DefaultShapes/DeleteAll';}
    else if (id=="305") { refTopic="bb877869.aspx"; refsTable=null; ShowZIndexUI(); hierarchy += 'DefaultShapes/Zindex';}
    
    else if (id=="601") { refTopic="bb412436.aspx"; refsTable=new Object();refsTable['VEMap.AddShape']='bb412436.aspx';refsTable['VEShape.SetCustomIcon']='bb412425.aspx';refsTable['VEMap.ClearInfoBoxStyles']='bb412441.aspx';refsTable['VEShape.SetTitle']='bb429575.aspx';refsTable['VEShape.SetDescription']='bb412553.aspx';refsTable['VEShape.SetLineWidth']='bb412415.aspx';refsTable['VEShape.SetLineColor']='bb412522.aspx';refsTable['VEShape.SetFillColor']='bb412486.aspx'; DoAddCustomShapeUI(); hierarchy += 'CustomizeShapes/AddCustom';}
    //else if (id=="602") { refTopic=""; xmlNode=13; DoShapeMinMaxUI();}
    else if (id=="603") { refTopic="bb412501.aspx"; refsTable=new Object();refsTable['VEMap.ShowInfoBox']='bb412501.aspx';refsTable['VEMap.HideInfoBox']='bb412559.aspx'; DoShapeInfoUI(); hierarchy += 'CustomizeShapes/ShowHideInfo';}
    else if (id=="604") { refTopic="bb429563.aspx"; refsTable=new Object();refsTable['VEShape.SetIconAnchor']='bb429563.aspx';refsTable['VEShape.ShowIcon']='bb429571.aspx';refsTable['VEShape.HideIcon']='bb412468.aspx'; DoShapeIconUI(); hierarchy += 'CustomizeShapes/ShowHideIcon';}
    else if (id=="605") { refTopic="bb429572.aspx"; refsTable=null; DoDeleteShapeUI(); hierarchy += 'CustomizeShapes/DeleteShape';}
    else if (id == "606") { refTopic = "bb429616.aspx"; refsTable = null; DeleteAllShapes(); hierarchy += 'CustomizeShapes/DeleteAll'; }
    else if (id=="607") { refTopic="cc966930.aspx"; refsTable = null; ClusterShapesUI(); hierarchy += 'CustomizeShapes/ClusterShapes'; }
    
    else if (id=="701") { refTopic="bb412479.aspx"; refsTable=new Object();refsTable['VEShapeLayer Class']='bb412413.aspx';refsTable['VEMap.AddShapeLayer']='bb412479.aspx'; map.AddShapeLayer(new VEShapeLayer()); DoAlert("Layer number "+map.GetShapeLayerCount()+" has been created. Try adding shapes to the layer."); hierarchy += 'ShapeLayers/CreateLayer';}
    else if (id=="702") { refTopic="bb412548.aspx"; refsTable=null; DoAddLayerShapeUI(); hierarchy += 'ShapeLayers/AddShape';}
    //else if (id=="703") { refTopic=""; xmlNode=13; DoLayerMinMaxUI();}
    else if (id=="704") { refTopic="bb429601.aspx"; refsTable=null; DoLayerDeleteShapeUI(); hierarchy += 'ShapeLayers/DeleteShape';}
    else if (id=="705") { refTopic="bb412538.aspx"; refsTable=new Object();refsTable['VEShapeLayer.Show']='bb412538.aspx';refsTable['VEShapeLayer.Hide']='bb412443.aspx'; DoShowHideLayerUI();hierarchy += 'ShapeLayers/ShowHide';}
    else if (id=="706") { refTopic="bb412489.aspx"; refsTable=null; DoDeleteLayerUI(); hierarchy += 'ShapeLayers/DeleteLayer';}
    else if (id=="707") { refTopic="bb412514.aspx"; refsTable=null; map.DeleteAllShapeLayers(); hierarchy += 'ShapeLayers/DeleteAll';}
    
    else if (id=="801") { refTopic="bb429606.aspx"; refsTable=new Object();refsTable['VEMap.ImportShapeLayerData']='bb429606.aspx';refsTable['VEShapeSourceSpecification Class']='bb412471.aspx'; 
    
    AddMyLayer(VEDataType.GeoRSS,'GeoRSSTest.xml','./img/hiking_icon.gif'); hierarchy += 'ImportData/AddGeoRSS';}
    
    else if (id=="802") { refTopic="bb429606.aspx"; refsTable=new Object();refsTable['VEMap.ImportShapeLayerData']='bb429606.aspx';refsTable['VEShapeSourceSpecification Class']='bb412471.aspx'; 
    
    AddMyLayer(VEDataType.VECollection,'546E7E30AC2C5011!451',null); hierarchy += 'ImportData/AddCollection';}
    
    else if (id=="1001") { refTopic="bb429629.aspx"; refsTable=new Object();refsTable['VEMap.AddTileLayer']='bb429629.aspx';refsTable['VETileSourceSpecification Class']='bb429539.aspx'; LoadTiles(0.5); hierarchy += 'CustomTileLayers/AddTile';}
    else if (id=="1002") { refTopic="bb412405.aspx"; refsTable=null; DeleteTileLayer(); hierarchy += 'CustomTileLayers/DeleteTile';}
    
    else if (id=="401")
      {
	refTopic="bb429645.aspx";
	refsTable=null;
        DoBasicFindUI(null, 'area 51');
        hierarchy += 'FindBasicInfo/Location';
      }
    else if (id=="402")
      {
	refTopic="bb429645.aspx";
	refsTable=null;
        DoBasicFindUI('pizza', null);
        hierarchy += 'FindBasicInfo/Nearby';
      }
    else if (id=="403")
      {
	refTopic="bb429645.aspx";
	refsTable=null;
        DoBasicFindUI('elvis', 'Las Vegas, NV');
        hierarchy += 'FindBasicInfo/WhatWhere';
      }
      else if (id=="404")
      {
	refTopic="cc469978.aspx";
	refsTable=new Object();
	refsTable['VEMap.FindLocations']='cc469978.aspx';
	refsTable['VEMap.AttachEvent']='bb412496.aspx';
	eventsAttached = true;
	DoAlert("Click on the map to display location information.");
	map.AttachEvent("onclick",PixelToLatLongHandler);
	hierarchy += 'FindBasicInfo/ReverseFind';
	}
    
    else if (id=="1401") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); DoAdvanceFindUI(); hierarchy += 'FindAdvInfo/DifferentSettings';}
    else if (id=="1402") { refTopic="bb429645.aspx"; refsTable=null;  AddResultsToLayerUI(); hierarchy += 'FindAdvInfo/AddResults';}
    else if (id=="1403") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); GetMoreResultsUI(); hierarchy += 'FindAdvInfo/MoreResults';}
    else if (id=="1404") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); var cb = function(a,b,c,d,e) {if(b) {DoAlert(b.length + " results found, but not shown.<br>Click <a href='#' onclick='javascript:ShowShapesInFindLayer();'>here</a> to show results.");}}; DoFind('pizza', 'seattle, wa, usa', null, null, false, null, null, null, cb); hierarchy += 'FindAdvInfo/NotShowResults';}
    else if (id=="1405") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); NotCreatingResultUI(); hierarchy += 'FindAdvInfo/NotCreateResults';}	
    else if (id=="1406") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); var cb = DoFind(null, 'london'); hierarchy += 'FindAdvInfo/DefaultDisambiguation';}
    else if (id=="1407") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); var cb = DoFind(null, 'london', null, null, null, null, false, null, disambigCall); hierarchy += 'FindAdvInfo/CustomDisambiguation';}
    else if (id=="1408") { refTopic="bb429645.aspx"; refsTable=null;  InitFindLayer(); var cb = function(a,b,c,d,e) {if(b) {DoAlert("A find callback can be used to obtain search results and find out when the search ends.");}}; DoFind('pizza', 'seattle, wa, usa', null, null, null, null, null, null, cb); hierarchy += 'FindAdvInfo/Callback';}
    
    else if (id=="501") {
        refTopic="bb877838.aspx";
        refsTable=null;
        map.GetDirections(["Redmond, WA", "Everett WA", "Bellingham WA"]);
        hierarchy += 'RouteDirections/MultipointRoute';
    }
    else if (id=="502") {
        refTopic="bb877838.aspx";
        refsTable=null;
        var options = new VERouteOptions();
        options.RouteCallback = onGotRoute;
        units = options.DistanceUnit;
        map.GetDirections(["Redmond, WA", "Seattle WA", "Bellingham WA"], options);
        hierarchy += 'RouteDirections/ShowDirections';
    }
    else if (id=="503") {
        refTopic="bb877838.aspx";
        refsTable=null;
        var options = new VERouteOptions();
        options.RouteOptimize = VERouteOptimize.MinimizeDistance;
        options.RouteCallback = onGotRoute;
        units = options.DistanceUnit;
        map.GetDirections(["Redmond, WA", "Everett WA", "Bellingham WA"], options);
        hierarchy += 'RouteDirections/SwitchShortest';
    }
    else if (id=="504") {
        refTopic="bb877838.aspx";
        refsTable=null;
        var options = new VERouteOptions();
        options.DistanceUnit = VERouteDistanceUnit.Kilometer;
        options.RouteCallback = onGotRoute;
        units = options.DistanceUnit;
        map.GetDirections(["Redmond, WA", "Everett WA", "Bellingham WA"], options);
        hierarchy += 'RouteDirections/SwitchKM';
    }
    else if (id=="505") {
        refTopic="cc469975.aspx";
        refsTable=null;
        var options = new VERouteOptions();
        options.RouteMode = VERouteMode.Walking;
        options.RouteCallback = onGotRoute;
        units = options.DistanceUnit;
        map.GetDirections(["Space Needle", "Seattle Art Museum"], options);
        hierarchy += 'RouteDirections/ShowWalkingDirections';
    }
    else if (id=="506") {
        refTopic="cc469976.aspx";
        refsTable=null;
        var options = new VERouteOptions();
        options.UseTraffic = true;
        options.RouteCallback = onGotRoute;
        units = options.DistanceUnit;
        map.GetDirections(["Redmond, WA", "Everett WA", "Bellingham WA"], options);
        hierarchy += 'RouteDirections/ReturnTrafficBasedRoute';
    }
    else if (id=="507") {
        refTopic="bb412527.aspx";
        refsTable=null;
        
        try {
            map.DeleteRoute();
        }
        catch(err){}
        hierarchy += 'RouteDirections/DeleteRoute';
    }
    
    else if (id=="901")    // Show a specific image
    {
        refTopic="bb412464.aspx";
        refsTable=null;
        DoBirdsEye();
        hierarchy += 'BirdseyeImages/ShowSpecificImage';
    }
    else if (id=="902")    // Change the orientation
    {
        refTopic="bb412417.aspx";
        refsTable=null;
        m=map.GetMapMode();
        
        if (m==VEMapMode.Mode2D) {
            map.SetBirdseyeOrientation(VEOrientation.South);
        }
        else
        {
            DoAlert('You must be in 2D mode and viewing a birds eye image to change the orientation.');
        }
        hierarchy += 'BirdseyeImages/ChangeOrientation';
    }
    else if (id=="903")    // Get scene info
    {
        refTopic="bb412472.aspx";
        refsTable=new Object();
        refsTable['VEMap.GetBirdseyeScene']='bb412472.aspx';
        refsTable['VEBirdseyeScene Class']='bb412429.aspx';
        m=map.GetMapMode();
        if (m==VEMapMode.Mode2D) {
            GetBEInfo();
        }
        else {
            DoAlert('You must be in 2D mode and viewing a birds eye image to get the scene info.');
        }
        hierarchy += 'BirdseyeImages/GetSceneInfo';
    }
    else if (id=="904")    // Add a pushpin at altitude
    {
        refTopic="bb877811.aspx";  // VELatLong.SetAltitude
        refsTable=null;       
        AddPushpinAtAltitude();
        hierarchy += 'BirdseyeImages/AddPushpin';
    }
    
    else if (id=="1201") { refTopic="bb429545.aspx"; refsTable=null; if (CheckBrowser()) {SwitchModes();}hierarchy += '3DMaps/SwitchModes';}
    else if (id=="1202")
      {
	refTopic="bb429594.aspx";
	refsTable=new Object();
	refsTable['VEMap.SetMapView']='bb429594.aspx';
	refsTable['VEMapViewSpecification Class']='bb429574.aspx';

	if (CheckBrowser())
	  {
	    ShowCoolViews();
	  }
    hierarchy += '3DMaps/SetMapView';
      }
    else if (id=="1203") { refTopic="bb429540.aspx"; refsTable=null;  if (CheckBrowser()) {var view = map.GetMapView(); DoAlert('top left: ' + 
    view.TopLeftLatLong +'<br>top right: '+ 
    view.TopRightLatLong +'<br>bottom left: '+ 
    view.BottomLeftLatLong + '<br>bottom right: '+ 
    view.BottomRightLatLong);}    
    hierarchy += '3DMaps/GetMapView';}
    else if (id=="1204") { refTopic="bb412531.aspx"; refsTable=new Object();refsTable['VEMap.StartContinuousPan']='bb412531.aspx';refsTable['VEMap.EndContinuousPan']='bb429598.aspx'; if (CheckBrowser()) { var m=map.GetMapMode(); if (m==VEMapMode.Mode3D){ DoPan();}else{ DoAlert('You must be in 3D mode to use Continuous Pan.');} } hierarchy += '3DMaps/ContinuousPan'; }

    else if (id=="1205")
      {
	refTopic="bb412474.aspx";
	refsTable=new Object();
	refsTable['VEMap.SetAltitude']='bb412474.aspx';
	refsTable['VEMap.SetHeading']='bb412500.aspx';
	refsTable['VEMap.SetPitch']='bb412483.aspx';

	if (CheckBrowser())
	  {
	    var m=map.GetMapMode();

	    var alerttext = "";

	    if (m==VEMapMode.Mode3D)
	      {
		map.SetAltitude(8700);
		map.SetHeading(-90);
		map.SetPitch(-33);
                AltitudeSet = true;

		alerttext += '<b>Setting:</b><br>' +
		  'Altitude: 8700' +
		  '<br>' +
		  'Heading: -90' +
		  '<br>' +
		  'Pitch: -33';
	      }
	    else
	      {
		alerttext = 'You must be in 3D mode to set these properties.';
	      }

	    DoAlert(alerttext);
	  }
    hierarchy += '3DMaps/SetAltHeadingPitch';
      }

    else if (id=="1206")
      {
	refTopic="bb429624.aspx";
	refsTable=new Object();
	refsTable['VEMap.GetAltitude']='bb429624.aspx';
	refsTable['VEMap.GetHeading']='bb412459.aspx';
	refsTable['VEMap.GetPitch']='bb429577.aspx';

        if(!AltitudeSet)
	  {
	    DoAlert("You must set the altitude first!");
	    return;
	  }

	if (CheckBrowser())
	  {
	    var m=map.GetMapMode();

	    if (m==VEMapMode.Mode3D)
	      {
		var altitude = map.GetAltitude();

		if(altitude < 0)
		  {
		    altitude = 0;
		  }

		alerttext = 'Altitude: ' +
		  altitude +
		  '<br>Heading: ' +
		  map.GetHeading() +
		  '<br>Pitch: ' +
		  map.GetPitch();

		DoAlert(alerttext);
	      }
	    else
	      {
		DoAlert('You must be in 3D mode to get this information.');
	      }
	  }
    hierarchy += '3DMaps/GetAltHeadingPitch';
      }
    else if (id=="1207")    // Add a pushpin at altitude
      {
      refTopic="bb877810.aspx";    // VEShape.SetAltitude
      refsTable=null;

      if(CheckBrowser())
	{
	  // Clear any shapes on the map
          DeleteAllShapes();
	  Add3DPushpinAtAltitude();
	}
      hierarchy += '3DMaps/AddPushpin';
    }
    else if (id == "1208")    // Import 3D model
    {
        refTopic = "cc966728.aspx";
        refsTable = null;

        if (CheckBrowser()) {
            // Clear any shapes on the map
            DeleteAllShapes();
            Add3DModel();
        }
        hierarchy += '3DMaps/AddModel';
    }
    else if (id=="1301") { refTopic="bb412496.aspx"; refsTable=new Object();refsTable['VEMap.AttachEvent']='bb412496.aspx';refsTable['Bing Maps Events']='bb429568.aspx';  eventsAttached = true;DoAlert("Zoom in/out the see the map event thrown."); map.AttachEvent("onendzoom",EndZoomHandler); hierarchy += 'EventsCallbacks/AttachMapEvents';}
    else if (id=="1302") { refTopic="bb412496.aspx"; refsTable=new Object();refsTable['VEMap.AttachEvent']='bb412496.aspx';refsTable['Mouse Events']='bb412438.aspx'; eventsAttached = true;mouseEventList = new Array(); map.AttachEvent("onclick",MouseHandler);
    map.AttachEvent("ondoubleclick",MouseHandler);
    map.AttachEvent("onmousedown",MouseHandler);
    map.AttachEvent("onmouseup",MouseHandler);
    map.AttachEvent("onmousewheel",MouseHandler);
    hierarchy += 'EventsCallbacks/AttachMouseEvents';
    }   
    else if (id=="1303") { refTopic="bb412496.aspx"; refsTable=new Object();refsTable['VEMap.AttachEvent']='bb412496.aspx';refsTable['Mouse Events']='bb412438.aspx'; eventsAttached = true;if(map.GetMapStyle()==VEMapStyle.Birdseye)map.SetMapStyle(VEMapStyle.Road); AddDefaultShapeForEvent(); map.AttachEvent("onmouseover",ShapeHandler);map.AttachEvent("onmouseout",ShapeHandler); hierarchy += 'EventsCallbacks/AttachShapeEvents'; }
    else if (id=="1304") { refTopic="bb412496.aspx"; refsTable=new Object();refsTable['VEMap.AttachEvent']='bb412496.aspx';refsTable['Keyboard Events']='bb412426.aspx'; eventsAttached = true;if(map.GetMapStyle()==VEMapStyle.Birdseye)map.SetMapStyle(VEMapStyle.Road);if (map.GetShapeLayerByIndex(0).GetShapeCount() == 0) {AddDefaultShapeForEvent2();}; DoAlert("<table><tr><td>Up arrow key:</td><td>Zoom in</td></tr><tr><td>Down arrow key:</td><td>Zoom out</td></tr><tr><td>Left arrow key:</td><td>Previous shape</td></tr><tr><td>Right arrow key:</td><td>Next shape</td></tr><tr><td colspan='2'>(Keyboard events are not supported in 3D mode.)</td></tr></table>"); UpdateCount(); map.AttachEvent("onkeydown", KeyboardHandler);map.AttachEvent("onkeyup", KeyboardHandler2);try{document.getElementById('wl_ve_mapInput').focus();}catch(e){} hierarchy += 'EventsCallbacks/ChangeKeyboardEvents'; }
    
    else if (id=="1501") { refTopic="bb412550.aspx"; refsTable=null;  DoAlert('The top edge of the map on the Web page is at pixel: '+map.GetTop());hierarchy += 'MapInfo/GetTop'; }
    else if (id=="1502") { refTopic="bb412534.aspx"; refsTable=null;  DoAlert('The left edge of the map on the Web page is at pixel: '+map.GetLeft());hierarchy += 'MapInfo/GetLeft'; }
    else if (id=="1503") { refTopic="bb412539.aspx"; refsTable=null;  DoAlert('The latitude,longitude at the center of the map is: '+map.GetCenter()); hierarchy += 'MapInfo/GetCenter'; }
    else if (id=="1504") { refTopic="bb429564.aspx"; refsTable=null;  DoPixelToLL(); hierarchy += 'MapInfo/ConvertPixel'; }
    else if (id=="1505") { refTopic="bb429590.aspx"; refsTable=null;  DoLLToPixel(); hierarchy += 'MapInfo/ConvertLatLong'; }
    else if (id=="1506") { refTopic="bb412418.aspx"; refsTable=null;  DoAlert('The map control version is: '+VEMap.GetVersion()); hierarchy += 'MapInfo/GetVersion'; }

    if (xmldoc!=null) {
        ShowCode(); 
        GetRef();
    }
    TrackPage("vesdk/TOC/" + hierarchy, "iSDK TOC: " + hierarchy);
}
function CheckBrowser() //for 3d calls: are we dealing with IE or moz? 3d only works in IE
{  
    return true;
}

function doAbout3D() //references the About 3D maps in the SDK.
{
    
    doClick(3);
    if (codetab==3) document.getElementById('refbox').className = 'ref';
    document.getElementById('refframe').src = './Ref/HTML/3DMaps.htm';
    
    reloadRef = true;
}
function doNewMap() //sometimes we need to just reset everything and start over
{
    if (map!=null) {
        map.Dispose();
    }
    map = new VEMap('SDKmap');
}
function SwitchModes() {
    var mapmode=map.GetMapMode();
    if (mapmode==VEMapMode.Mode3D){map.SetMapMode(VEMapMode.Mode2D);}
    else{map.SetMapMode(VEMapMode.Mode3D);} 
}

function DoBirdsEye() {
    var SpaceNeedle = new VELatLong(47.6218, -122.3492);
    
    map.LoadMap(SpaceNeedle, 17);
    
    // Let me know if a birdseye scene is available
    map.AttachEvent("onobliqueenter", OnObliqueEnterHandler);
}
function OnObliqueEnterHandler() {
    if(map.IsBirdseyeAvailable()) {
      //        var TopOfNeedle = new VELatLong(47.622, -122.3491); 
      //        map.SetBirdseyeScene(TopOfNeedle);
      map.SetMapStyle(VEMapStyle.Birdseye);
    }
    else {
        DoAlert("Birdseye is not available");
    }
}
function AddPushpinAtAltitude() {
    var SpaceNeedle = new VELatLong(47.6218, -122.3492);
    
    map.LoadMap(SpaceNeedle, 17);
    
    // Let me know if a birdseye scene is available
    map.AttachEvent("onobliqueenter", ReadyForBirdseye);
}
function ReadyForBirdseye()
{
  if(map.IsBirdseyeAvailable()) {
    map.SetMapStyle(VEMapStyle.Birdseye);
    var pinLocation = new VELatLong(47.6222, -122.34865);
    pinLocation.SetAltitude(604, VEAltitudeMode.RelativeToGround);
    var pushpin = new VEShape(VEShapeType.Pushpin, pinLocation);
    map.AddShape(pushpin);
  }
  else {
    DoAlert("Birdseye must be available to set the pushpin");
  }
}

function Add3DPushpinAtAltitude()
{
  var SpaceNeedle = new VELatLong(47.622582, -122.347622);

  map.AttachEvent("onendpan", onEndPan3DHandler);

  map.SetMapMode(VEMapMode.Mode3D);
  map.SetMapStyle(VEMapStyle.Aerial);

  var TheMapView = new VEMapViewSpecification(SpaceNeedle, null, 1520, -38.752, 27.77318);
  map.SetMapView(TheMapView);
}

function onEndPan3DHandler()
{
  // Remove handler
  map.DetachEvent("onendpan", onEndPan3DHandler);

  var SpaceNeedleTop = new VELatLong(47.622582, -122.347622);

  var pushpin = new VEShape(VEShapeType.Pushpin, SpaceNeedleTop);
  pushpin.SetAltitude(0.0, VEAltitudeMode.RelativeToGround);
  pushpin.SetZIndex(2000);
  map.AddShape(pushpin);
}

function doNo3D() //when 3D is not available
{
    DoAlert('Before viewing the maps in 3D mode, you must install the Bing Maps 3D software on your computer.' +
    '<br>To install the software, click <a href="http://go.microsoft.com/fwlink/?LinkId=72623">here</a>.');
}
function GetDefaultMap() //this is used when we've messed with events, etc. 
{
    doNewMap();
    map.LoadMap();
    map.AttachEvent('onmodenotavailable',doNo3D);
    map.AttachEvent('onendpan',doneLoading);
    map.AttachEvent('onstartpan',startLoading);
    map.AttachEvent('onstartpan',function() {shapeAdded = false;});
}
function GetMap(z,la,lo,s,f) {
    doNewMap();
    map.LoadMap(new VELatLong(la,lo),z,s,f);
    map.AttachEvent('onmodenotavailable',doNo3D);
    map.AttachEvent('onendpan',doneLoading);
    map.AttachEvent('onstartpan',startLoading);
    map.AttachEvent('onstartpan',function() {shapeAdded = false;});
}
function GetMapWithCallback() {
    doNewMap();
    map.onLoadMap = function(){ DoAlert('The map has loaded'); };
    map.LoadMap(new VELatLong(47.22, -122.44), 12, 'r', false);
    map.AttachEvent('onmodenotavailable',doNo3D);
    map.AttachEvent('onendpan',doneLoading);
    map.AttachEvent('onstartpan',startLoading);
    map.AttachEvent('onstartpan',function() {shapeAdded = false;});
}
function GetMapWithDashboard(size) {
    doNewMap();
    map.SetDashboardSize(size);
    map.LoadMap();
    map.AttachEvent('onmodenotavailable',doNo3D);
    map.AttachEvent('onendpan',doneLoading);
    map.AttachEvent('onstartpan',startLoading);
    map.AttachEvent('onstartpan',function() {shapeAdded = false;});
}
function GetBlankMap()
{
    blankMapLoaded = true;
    doNewMap();
    var options = new VEMapOptions();
    options.LoadBaseTiles = false;
    map.LoadMap(null, null, null, null, null, null, null, options);
    map.AttachEvent('onmodenotavailable', doNo3D);
    map.AttachEvent('onendpan', doneLoading);
    map.AttachEvent('onstartpan', startLoading);
    map.AttachEvent('onstartpan', function() { shapeAdded = false; });
}
function AddPin(latlong,icon,mytitle,text,titlestyle,iconstyle,detailsstyle,custom) {
    var pin = new VEPushpin(pinid, latlong, icon, mytitle, text,titlestyle,iconstyle,detailsstyle);
    if (custom) {
        VEPushpin.ShowDetailOnMouseOver = false;
        VEPushpin.OnMouseOverCallback = function(x, y, title, details) {
            DoAlert('Your mouse is at : ' + x + ', ' + y + '.<br>' + 
            ' You can display the details from title: <b>' + unescape(title) + '</b><br>'+
            ' and details: <b>' + unescape(details)+ '</b>');
        }
    }
    else {
        VEPushpin.ShowDetailOnMouseOver = true;
        VEPushpin.OnMouseOverCallback = null;
    }
    
    map.AddPushpin(pin);
    map.SetCenter(latlong);
    pinid +=1;
}
function DoBestMap() {
    var locs = new Array;
    var loc = new VELatLong(40, -123);
    locs.push(loc);
    var loc = new VELatLong(42, -122);
    locs.push(loc);
    var loc = new VELatLong(44, -118);
    locs.push(loc);
    var loc = new VELatLong(46, -118);
    locs.push(loc);
    
    for (i=0;i<locs.length;i++) {
        var pin = new VEPushpin(pinid, locs[i], null, 'A point', 'location number '+i);
        map.AddPushpin(pin);
        pinid++;
    }
    map.SetMapView(locs);
}

function onFindResults(findResults) {
    var results="Find Results:<ol>";
    for (r=0; r<findResults.length; r++) {
        results+="<li>"+findResults[r].Name + ", " + findResults[r].Description+": "+ findResults[r].Phone +"</li>";
    }
    DoAlert(results);
}

function onGotRoute(route) {
    // Unroll route
    var legs          = route.RouteLegs;
    var turns         = "Total distance: " + route.Distance.toFixed(1) + " " + units + "<br/><ol>";
    var leg           = null;
    
    // Get intermediate legs
    for(var i = 0; i < legs.length; i++) {
        // Get this leg so we don't have to dereference multiple times
        leg = legs[i];  // Leg is a VERouteLeg object
        
        // Unroll each intermediate leg
        var turn = null;  // The itinerary leg
        
        for(var j = 0; j < leg.Itinerary.Items.length; j ++) {
            turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
        
            turns += "<li>" + turn.Text + " (" + turn.Distance.toFixed(1) + " " + units + ")";
            
            //Display any traffic warnings
            if (turn.Warnings != null) {
                
                turns += "<ul>";
                
                for (var k = 0; k < turn.Warnings.length; k++) {
                    
                    turns += "<li style='color:red;'>" + turn.Warnings[k].Text + "</li>";
                }
                
                turns += "</ul>";
            }

            //Display any hints
            if (turn.Hints != null)
            {
                turns += "<ul>";

                for (var k = 0; k < turn.Hints.length; k++)
                {
                    turns += "<li style='color:green;'>" + turn.Hints[k].Text + "</li>";
                }

                turns += "</ul>";
            }
            
            turns += "</li>";
        }
    }
    
    turns += "</ol>";
    
    DoAlert(turns);
}

function AddMyControl() {
    var el = document.createElement("div"); 
    el.style.top ="300px"; 
    el.style.left = "50px"; 
    el.style.border = "2px solid black";
    el.style.padding = "2px";
    el.style.background = "#D1FDCD";
    el.innerHTML = "Click here to <br><a href='#' onclick='javascript:parent.map.ZoomIn();'>Zoom In</a>";  
    el.id = "myControl";
    map.AddControl(el);
    
    AddMyShim(el,"myShim");
}
function AddMyShim(el,id) { 
    var shim = document.getElementById(id);
    if (!shim)
        shim = document.createElement("iframe");
    //Hack to make this work in safari.
    //Safari does not have removeNode in an iframe.
    if(typeof shim.removeNode != "function")
        shim.removeNode = function() {};
    shim.id = id;         
    shim.frameBorder = "0";      
    shim.style.position = "absolute";
    shim.style.zIndex = "1";
    shim.style.top  = el.offsetTop;
    shim.style.left = el.offsetLeft;
    shim.width  = el.offsetWidth;
    shim.height = el.offsetHeight;
    el.shimElement = shim; 
    el.parentNode.insertBefore(shim, el);
}
function RemoveMyControl() {
    var mycontrol = document.getElementById("myControl");
    if (mycontrol!=null) map.DeleteControl(mycontrol);          
    var myShim = document.getElementById("myShim");            
    if (myShim!=null) myShim.parentNode.removeChild(myShim);            
    myShim = null;
}
function DrawPolygon(id,points,width,outlinecolor, fillcolor) {
    poly = new VEPolygon(id,points);
    poly.SetOutlineWidth(width);
    poly.SetOutlineColor(outlinecolor);
    poly.SetFillColor(fillcolor);
    map.AddPolygon(poly);
    map.SetMapView(points);
    polyid++;
}
function DrawPolyline(id,points,width,color) {
    poly = new VEPolyline(id,points);
    poly.SetWidth(width);
    poly.SetColor(color);
    map.AddPolyline(poly);
    map.SetMapView(points);
    polyid++;
}

var pushpinIcon;
function AddMyLayer(type,source,icon) {
    //	veLayerSpec.IconUrl = icon;
    var l = new VEShapeLayer();
    pushpinIcon = icon;
    var veLayerSpec = new VEShapeSourceSpecification(type, source, l);
    map.ImportShapeLayerData(veLayerSpec, onFeedLoad);
    
    layerid++;
}

function onFeedLoad(feed) {
    if(pushpinIcon) {
        for(var i =0;i<feed.GetShapeCount();i++) {
            var s = feed.GetShapeByIndex(i);
            // WAS: s.SetCustomIcon("<img src='"+pushpinIcon+"'/>");
            s.SetCustomIcon(pushpinIcon);
        }
    }
    
    DoAlert('RSS or Collection loaded. There are '+feed.GetShapeCount()+' items in this list.');
}

function DoPixelToLL() {
    if (map.GetMapStyle()!=VEMapStyle.Birdseye) {
        var ll = map.PixelToLatLong(new VEPixel(20,55)).toString();
        DoAlert("The latitude,longitude of the pixel at (20,55) is: "+ll);
    }
    else {
        var be = map.GetBirdseyeScene();
        var ll = be.PixelToLatLong(new VEPixel(20,55)).toString();
        DoAlert("The latitude,longitude of the pixel at (20,55) is: "+ll);
    }
}
function DoLLToPixel() {
    var center = map.LatLongToPixel(map.GetCenter());
    DoAlert("The center of the map is at pixel: x="+center.x+", y="+center.y);
}
function GetNeighbor() {
    if (map.IsBirdseyeAvailable()) {
        var be = map.GetBirdseyeScene();
        var b = be.GetNeighbor(0);
        map.SetBirdseyeScene(b);
    }
    else {
        DoAlert("You must be viewing a bird's eye image to do this.");
    }
}
function GetBEInfo() {
    if (map.IsBirdseyeAvailable()) {
        var be = map.GetBirdseyeScene();
        var info = "<b>ID:</b> " + be.GetID() + "<br>";
        info += "<b>thumbnail:</b> " + be.GetThumbnailFilename()+ "<br>";
        info += "<b>orientation:</b> " + be.GetOrientation()+ "<br>";
        info += "<b>height:</b> " + be.GetHeight() + "<br>";
        info += "<b>width:</b> " + be.GetWidth() + "<br>";
        DoAlert(info);
    }
    else {
        DoAlert("You must be viewing a bird's eye image to get this info.");
    }
}
function LoadTiles(opacity) {
    DeleteTileLayer();
    try {
        var bounds = [new VELatLongRectangle(new VELatLong(49,-123),new VELatLong(47,-121))];

        var tileSourceSpec = new VETileSourceSpecification("lidar", "http://www.microsoft.com/virtualearth/isdk/ajax/layers/lidar/%4.png");
        tileSourceSpec.NumServers = 1;
        tileSourceSpec.Bounds = bounds;
        tileSourceSpec.MinZoomLevel = 10;
        tileSourceSpec.MaxZoomLevel = 16;
        tileSourceSpec.Opacity = opacity;
        tileSourceSpec.ZIndex = 100;
        
        map.AddTileLayer(tileSourceSpec, true);
        map.SetCenterAndZoom(new VELatLong(48.03,-122.4),12);
    }
    catch (e) {
        //alert(e.message);
    }
}
function DeleteTileLayer() {
    try {
        map.DeleteTileLayer("lidar");
        //map.DeleteTileSource("lidar");
    }
    catch (e) {
    }
    
}
function DoPan() {
    map.StartContinuousPan(100,0);
    setTimeout('map.EndContinuousPan();',5000);
}
function ShowCoolViews() {
    map.SetMapMode(VEMapMode.Mode3D); 
    map.SetMapStyle('a');
    
    DoAlert("Choose a 3D View you want to see:<br>"+
    "<div><a href='#' onclick='doView(46.223, -122.17975, 8400, -31.35, 205.54);'>Mount St. Helens</div>"+
    "<div><a href='#' onclick='doView(36.378, -111.861658, 6074, -23, 144.5);'>Grand Canyon</div>"+
    "<div><a href='#' onclick='doView(28, 86.9, 8500, -3.6, 80);'>Mount Everest</div>" +
    "<div><a href='#' onclick='doView(36.139497, -5.34595, 5348, -25.986, 0);'>Gibraltar</div>"+
    "<div><a href='#' onclick='doView(47.623484, -122.349307, 1520, -38.752, -332.22682);'>Space Needle</div>"+
    "<div><a href='#' onclick='doView(37.7916, -122.3940, 530, -8.8, 288);'>San Francisco, CA</div>" 
    //                                47.620484, -122.349307
    );
}
function doView(lat,lon,alt,pitch,heading) {
    var viewspec = new VEMapViewSpecification(new VELatLong(lat,lon), null, alt, pitch, heading);
    map.SetMapView(viewspec);
}

function GetDefaultPushpin() {
    var shape = new VEShape(VEShapeType.Pushpin, GetShapeCenter());
    shape.SetTitle('My pushpin');
    shape.SetDescription('This is shape number '+pinid);
    return shape;
}

function GetDefaultPolyline() {
    var ll = GetShapeCenter();
    var lat = ll.Latitude;
    var lon = ll.Longitude;
    
    var shape = new VEShape(VEShapeType.Polyline, [new VELatLong(lat-0.1,lon-0.1),
    new VELatLong(lat+0.1,lon-0.1),
    new VELatLong(lat+0.1,lon),
    new VELatLong(lat-0.1,lon),
    new VELatLong(lat-0.1,lon+0.1),
    new VELatLong(lat+0.1,lon+0.1)]);
    shape.SetTitle('My polyline');
    shape.SetDescription('This is shape number '+pinid);
    return shape;
}

function GetDefaultPolygon() {
    var ll = GetShapeCenter();
    var lat = ll.Latitude;
    var lon = ll.Longitude;
    
    var shape = new VEShape(VEShapeType.Polygon, [new VELatLong(lat,lon-0.15),
    new VELatLong(lat+0.1,lon-0.05),
    new VELatLong(lat+0.1,lon+0.05),
    new VELatLong(lat,lon+0.15),
    new VELatLong(lat-0.1,lon+0.05),
    new VELatLong(lat-0.1,lon-0.05)]);
    shape.SetTitle('My polygon');
    shape.SetDescription('This is shape number '+pinid);
    return shape;
}

var shapeAdded = false;
function GetShapeCenter() {
    var ll = map.GetCenter();
    
    if (shapeAdded) {
        if (ll.Longitude < 179)
            ll.Longitude += 0.2;
        else
            ll.Longitude -= 0.2;
        map.SetCenter(ll);
    }
    
    shapeAdded = true;
    return ll;
}

function SetCustomLine(s) {
    var a = Math.random();
    if (a < 0.1)
        a += 0.1;
    s.SetLineColor(new VEColor(Math.round(254*Math.random()),Math.round(254*Math.random()),Math.round(254*Math.random()),a));
    s.SetLineWidth(Math.round(5*Math.random())+1);
}

function SetCustomFill(s) {
    s.SetFillColor(new VEColor(Math.round(254*Math.random()),Math.round(254*Math.random()),Math.round(254*Math.random()),Math.random()));
}

function SetCustomIcon(s) {
    var icon = "<div style='font-size:12px;font-weight:bold;border:solid 2px Black;background-color:Aqua;width:90px;'><img src='img/new.gif' style='vertical-align:middle;'/>Shape "+pinid+"</div>";
    s.SetCustomIcon(icon);
}

function SetCustomInfo(s) {
    map.ClearInfoBoxStyles();
    var box = "<div style='width:309px;'><img src='img/new.gif'/>You can add html codes into the info box or change the style of the info box. You can design and show any info box you want!<br>"+
    "<a href='http://msdn2.microsoft.com/en-us/library/bb412553.aspx' target='_blank'>Click here to find out more.</a><br></div>";
    box += "<embed src='http://images.soapbox.msn.com/flash/soapbox1_1.swf' quality='high' width='309px' height='272px' wmode='transparent' type='application/x-shockwave-flash' pluginspage='http://macromedia.com/go/getflashplayer' flashvars='c=v&v=a4b53303-d58c-450e-a01d-069c9bcb5fe9' ></embed><br /><a href='http://soapbox.msn.com/video.aspx?vid=a4b53303-d58c-450e-a01d-069c9bcb5fe9' target='_blank' title='Bing Maps - Bird&#39;s eye view and 3D'>Video: Bing Maps - Bird&#39;s eye view and 3D</a>";
    function cb() {return true;}
    map.AttachEvent("onmouseout", cb);
    s.SetTitle("<h2>Custom Pin</h2>");
    s.SetDescription(box);
}

function EndZoomHandler(e) {
    var z = map.GetZoomLevel();
    DoAlert("Map stopped zooming.<br>Current zoom level = "+z);
}

var mouseEventList;
function MouseHandler(e) {
    var name;
    if (e.eventName == "onclick") {
        if (e.leftMouseButton)
            name = "onclick (left mouse button)  event";
        else if (e.rightMouseButton)
            name = "onclick (right mouse button)  event";
        else if (e.leftMouseButton)
            name = "onclick (middle mouse button)  event";
    }else {
        name = e.eventName + " event.";
    }
    
    if (mouseEventList.length > 3) {
        mouseEventList[0] = mouseEventList[1];
        mouseEventList[1] = mouseEventList[2];
        mouseEventList[2] = name;
    }
    else 
        mouseEventList.push(name);
    
    DoAlert(mouseEventList[0] + "<br>" + mouseEventList[1] + "<br>" + mouseEventList[2]);
}

function PixelToLatLongHandler(e) {

            var x = e.mapX;
      	    var y = e.mapY;
      	    var pixel = new VEPixel(x, y);
      	    var latlong = map.PixelToLatLong(pixel);

            map.FindLocations(latlong, GetFindLocationsResults);

}


function GetFindLocationsResults(locations) {
      	    
      	    var s = "Click on the map to display location information.<br>";
      	    
            if(locations != null)
            {
                  s += "Address match: <b>" + locations[0].Name + "</b>";

               
            }
            else
            {
               s+="No location matched the latlong entered.";
            } 

            DoAlert(s);
 }

function ShapeHandler(e) {
    if (e.elementID) {
        DoAlert(e.eventName + " event occurred on shape (id=" + e.elementID + ").");
    }
}

var shapeArray;
function KeyboardHandler(e) {
    if (e.keyCode == 37)      //left arrow
    {
        DoPrevShape();
        var s = map.GetShapeLayerByIndex(0).GetShapeByIndex(currentShapeIndex);
        if (s) {
            map.SetCenter(GetCenter(s.GetPoints()));
        }
        return true;
    }else if (e.keyCode == 39)//right arrow
    {
        DoNextShape();
        var s = map.GetShapeLayerByIndex(0).GetShapeByIndex(currentShapeIndex);
        if (s) {
            map.SetCenter(GetCenter(s.GetPoints()));
        }
        return true;
    }else if (e.keyCode == 38)//up arrow
    {
        map.ZoomIn();
        return true;
    }else if (e.keyCode == 40)//down arrow
    {
        map.ZoomOut();
        return true;
    } 
}

function KeyboardHandler2(e) {
    if(e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40)
        return true;
}

function AddDefaultShapeForEvent() {
    var c = map.GetCenter();
    var s = GetDefaultPolygon();
    s.SetTitle('My polygon');
    s.SetDescription('Move the mouse over polygon to see the event.');
    map.AddShape(s);
    
    map.SetZoomLevel(9);
}

function AddDefaultShapeForEvent2() {
    var c = map.GetCenter();
    var s = new VEShape(VEShapeType.Pushpin, new VELatLong(c.Latitude,c.Longitude-1));
    s.SetTitle('My pushpins');
    s.SetDescription('This is shape number 1');
    map.AddShape(s);
    
    s = new VEShape(VEShapeType.Pushpin, new VELatLong(c.Latitude,c.Longitude));
    s.SetTitle('My pushpins');
    s.SetDescription('This is shape number 2');
    map.AddShape(s);
    
    s = new VEShape(VEShapeType.Pushpin, new VELatLong(c.Latitude,c.Longitude+1));
    s.SetTitle('My pushpins');
    s.SetDescription('This is shape number 3');
    map.AddShape(s);
    
    map.SetZoomLevel(7);
}

function DoFind(what, where, start, number, showResult, createResult, disam, bestmap, callback) {
    InitFindLayer();
    
    map.Find(what, where, null, findLayer, start, number, showResult, createResult, disam, bestmap, callback);
}

function ShowShapesInFindLayer() {
    for(var i =0; i < findLayer.GetShapeCount(); i++) {
        findLayer.GetShapeByIndex(i).Show();
    }
}

var moreIndex;
function DoMoreFind(n) {
    moreIndex = n;
    var cb = function(a,b,c,d,e) {
        var r = "Results ("+moreIndex+" to "+(moreIndex+9)+") found.<br>";
        
        if (moreIndex)
            r += "<a href='#' onclick='javascript:DoMoreFind(moreIndex-10);'>(Previous 10 results)</a>";
        else
            r += "(Previous 10 results) ";
        
        if (d)
            r += "<a href='#' onclick='javascript:DoMoreFind(moreIndex+10);'>(Next 10 results)</a>";
        else
            r += "(Next 10 results) ";
        
        DoAlert(r);
    };
    DoFind('pizza', 'seattle, wa, usa', n, null, null, null, null, null, cb);
}

var eventsAttached = false;
function RemoveEvents() {
    eventsAttached = false;
    
    map.DetachEvent("onendzoom",EndZoomHandler);
    map.DetachEvent("onclick",MouseHandler);
    map.DetachEvent("onclick",PixelToLatLongHandler);
    map.DetachEvent("ondoubleclick",MouseHandler);
    map.DetachEvent("onmousedown",MouseHandler);
    map.DetachEvent("onmouseup",MouseHandler);
    map.DetachEvent("onmousewheel",MouseHandler);
    map.DetachEvent("onmouseover",ShapeHandler);
    map.DetachEvent("onmouseout",ShapeHandler);
    map.DetachEvent("onkeydown", KeyboardHandler);
    map.DetachEvent("onkeyup", KeyboardHandler2);    
}


function DeleteAllShapes() {
    var lc = map.GetShapeLayerCount();
    for(var i=0;i<lc;i++)
        map.GetShapeLayerByIndex(i).DeleteAllShapes();
}

function Add3DModel()
{
    map.SetMapMode(VEMapMode.Mode3D);

    var center = map.GetCenter();

    var layer = new VEShapeLayer();
    var modelSpec = new VEModelSourceSpecification(VEModelFormat.OBJ, "http://www.microsoft.com/virtualearth/isdk/ajax/model/house.obj", layer);
    map.Import3DModel(modelSpec, onModelLoad, center, null, null);

    // Zoom in so you can see the model
    map.SetZoomLevel(17);
    // map.SetPitch(-30); //
}

function onModelLoad(model, status)
{
    if (status == VEModelStatusCode.Success)
    {
        DoAlert("The 3D model has been loaded.");
    }

    if (status == VEModelStatusCode.InvalidURL)
    {
        DoAlert("The URL given for the model data is invalid.");
    }

    if (status == VEModelStatusCode.Failed)
    {
        DoAlert("There was a problem loading the 3D model.");
    }
}
