﻿/// <reference path="../VEJS/VeJavaScriptIntellisenseHelper.js" />

// NOTE:    The above reference is used only at design time.
//          It provides a skeleton of the VE API to enable 
//          intellisense.  Notice that the Default.aspx 
//          page DOES NOT reference VeJavaScriptIntellisenseHelper.js.
//          At run time, we use the real VE API.


var map
var oPRShapeL = new VEShapeLayer();  // park-n-ride layer
var oStationShapeL = new VEShapeLayer();
var findLayer = new VEShapeLayer();
var findArray = new Array();
var bTrafficLoaded;


var index = 0;
var results = null;

if (typeof (DESIGN_TIME) == 'undefined') {
    map = null;
}
else {
    map = new VEMap();
}

function pageLoad() {
    try {
        map = new VEMap("myMap");
        bTrafficLoaded = false;
        map.onLoadMap = map_Loaded;
        map.LoadMap(new VELatLong(44.962500, -93.247000), 12, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
        oStationShapeL.SetTitle = "Stations";
        oPRShapeL.SetTitle = "ParkRideLoc";
        document.getElementById('MSVE_obliqueNotification').innerHTML = "";
    }
    catch (e) {

    }
}

function GetSmallMap() {
    map = new VEMap("myMap");
    bTrafficLoaded = false;
    map.onLoadMap = map_Loaded;
    map.LoadMap(new VELatLong(44.962500, -93.247000), 12, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
    oStationShapeL.SetTitle = "Stations";
    oPRShapeL.SetTitle = "ParkRideLoc";
}

function pageUnload() {
    if (map != null) {
        map.Dispose();
    }
}

function PrintMap() {
    var pOptions = new VEPrintOptions(true);
    map.SetPrintOptions(pOptions);
    window.print();
    pOptions = new VEPrintOptions(false);
    map.SetPrintOptions(pOptions);
}

function map_Loaded() {
    AddRail(map);
    AddStations(map, 1);
    LoadParkRideLoc();
    ToggleTraffic();
    AddEvent(map);
}

function AddEvent(map) {
    //    var points1 = new VELatLong(33.431521, -111.940700, 0, VEAltitudeMode.RelativeToGround)
    //    var shape1 = new VEShape( VEShapeType.Pushpin, points1)
    //    shape1.SetDescription("<div style='z-index:5000;background-color: #FF0000;text-align:center'><h2><a href='http://tempemusicfestival.com/'><u>Tempe Music Festival</u></a></h2><br/>April 3 & 4 <br /><img src='http://tempemusicfestival.com/images/photoGallery/thumbs08/fergietv4_thumb.jpg' alt='Tempe Music Festival'/><br/> <img src='http://tempemusicfestival.com/images/photoGallery/thumbs08/fergie2_thumb.jpg' alt='Tempe Music Festival'/><img src='http://tempemusicfestival.com/images/photoGallery/thumbs08/Puddle%20of%20Mud%203_thumb.jpg' alt='Tempe Music Festival'/><img src='http://tempemusicfestival.com/images/photoGallery/thumbs08/Peachcake_thumb.jpg' alt='Tempe Music Festival'/></div>"); 
    //    shape1.SetCustomIcon("http://www.downtownlightrail.com/light-rail-maps/Images/camera39_big.gif");
    //    map.AddShape(shape1);

}

//loads the light rail map
function AddRail(map) {
    var points = new Array(
            new VELatLong(44.8542, -93.2388, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8526, -93.2387, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8525, -93.2387, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8524, -93.2386, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8522, -93.2373, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8522, -93.2371, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8519, -93.2359, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8519, -93.2357, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8519, -93.2341, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8519, -93.2339, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8519, -93.2336, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8521, -93.2333, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8523, -93.2331, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8524, -93.2330, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8526, -93.2329, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8548, -93.2329, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8549, -93.2328, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8550, -93.2327, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8551, -93.2326, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8553, -93.2323, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8562, -93.2310, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8563, -93.2308, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2306, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2303, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2300, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8564, -93.2278, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2268, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2240, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2238, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8564, -93.2237, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8565, -93.2235, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8566, -93.2234, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8567, -93.2232, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8568, -93.2232, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8570, -93.2232, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8601, -93.2231, 0, VEAltitudeMode.RelativeToGround),
            
            new VELatLong(44.8608, -93.2231, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8614, -93.2230, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8634, -93.2231, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8637, -93.2231, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8650, -93.2233, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8655, -93.2233, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8679, -93.2232, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8727, -93.2233, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8731, -93.2233, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8734, -93.2235, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8738, -93.2238, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8748, -93.2247, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8750, -93.2247, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8752, -93.2248, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8754, -93.2248, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8757, -93.2248, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8759, -93.2247, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8759, -93.2247, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8762, -93.2243, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8774, -93.2214, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8776, -93.2193, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8776, -93.2156, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8773, -93.2099, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8778, -93.2073, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8799, -93.2043, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8813, -93.2031, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8858, -93.1997, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8865, -93.1994, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8883, -93.1987, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8888, -93.1987, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8897, -93.1986, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8913, -93.1987, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8917, -93.1987, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8922, -93.1985, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8947, -93.1976, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8951, -93.1975, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8956, -93.1976, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8976, -93.1979, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8979, -93.1980, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8982, -93.1982, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8987, -93.1987, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8988, -93.1989, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8992, -93.1997, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8995, -93.2002, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.8996, -93.2005, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.8998, -93.2008, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9002, -93.2011, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9004, -93.2013, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9007, -93.2014, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9032, -93.2024, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9037, -93.2027, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9041, -93.2028, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9049, -93.2031, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.9054, -93.2033, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9056, -93.2035, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9057, -93.2036, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9084, -93.2058, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9089, -93.2061, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9093, -93.2063, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9094, -93.2065, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9095, -93.2066, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9100, -93.2072, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.9117, -93.2093, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9128, -93.2105, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9145, -93.2127, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9152, -93.2136, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9164, -93.2157, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9169, -93.2162, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9188, -93.2182, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9192, -93.2186, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9200, -93.2193, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9211, -93.2201, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.9347, -93.2294, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9446, -93.2363, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9472, -93.2382, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9484, -93.2389, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9496, -93.2398, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9502, -93.2403, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9512, -93.2411, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9513, -93.2412, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9515, -93.2413, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9517, -93.2413, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9519, -93.2413, 0, VEAltitudeMode.RelativeToGround),

            new VELatLong(44.9529, -93.2412, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9531, -93.2412, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9534, -93.2413, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9536, -93.2414, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9544, -93.2418, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9561, -93.2427, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9573, -93.2435, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9591, -93.2447, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9625, -93.2471, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9633, -93.2476, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9638, -93.2478, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9651, -93.2485, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9656, -93.2489, 0, VEAltitudeMode.RelativeToGround),
            
            new VELatLong(44.9661, -93.2494, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9667, -93.2498, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9672, -93.2502, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9681, -93.2508, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9687, -93.2512, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9701, -93.2522, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9717, -93.2533, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9734, -93.2545, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9740, -93.2550, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9741, -93.2551, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9741, -93.2551, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9741, -93.2552, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9743, -93.2553, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9743, -93.2555, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9744, -93.2556, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9745, -93.2558, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9750, -93.2570, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9754, -93.2580, 0, VEAltitudeMode.RelativeToGround),
            
            new VELatLong(44.9754, -93.2581, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9754, -93.2582, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9754, -93.2584, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9753, -93.2587, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9753, -93.2588, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9748, -93.2607, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9748, -93.2608, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9748, -93.2609, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9748, -93.2610, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9749, -93.2611, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9749, -93.2612, 0, VEAltitudeMode.RelativeToGround),
            
            new VELatLong(44.9768, -93.2657, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9773, -93.2670, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9782, -93.2691, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9783, -93.2693, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9785, -93.2696, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9792, -93.2715, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9795, -93.2724, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9796, -93.2726, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9797, -93.2727, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9801, -93.2732, 0, VEAltitudeMode.RelativeToGround),
            new VELatLong(44.9804, -93.2736, 0, VEAltitudeMode.RelativeToGround)           
          )
    myPolygon = new VEShape(VEShapeType.Polyline, points);
    myPolygon.SetLineWidth(6);
    myPolygon.HideIcon();
    myPolygon.SetMinZoomLevel(8);
    map.AddShape(myPolygon);
}

//formats the station pushpins
function onStationsFeedLoad(feed) {
    if (feed != null) {
        var numShapes = feed.GetShapeCount();
        for (var i = 0; i < numShapes; ++i) {
            try {
                var shape1 = feed.GetShapeByIndex(i);
                var shapeHTML = shape1.GetDescription();
                var latlong = shape1.GetPoints()[0];
                var lat = latlong.Latitude;
                var lon = latlong.Longitude;

                shapeHTML = shapeHTML + "<br /><hr /><a onclick='JavaScript:DoZoom(" + lat + "," + lon + ") ;' style='background-color:#BBC423; cursor:pointer; color:black; padding:3px;border: solid 1px black;'>Zoom to this station</a>";
                var sImage = "";

                sImage = sImage + "<br />";
                shape1.SetDescription("<div style='z-index:5000;'>" + sImage + shapeHTML + "</div>");
            }
            catch (e) {

            }
        }
    }
}

//imports Stations from the data feed.
function AddStations(map, bestlocation) {
    var shapeSource = new VEShapeSourceSpecification(VEDataType.ImportXML, 'http://www.downtownlightrail.com/light-rail-maps/StationFeed.ashx?lineId=15', oStationShapeL);
    map.ImportShapeLayerData(shapeSource, onStationsFeedLoad, bestlocation);
}

function DoZoom(lat, lon) {
    map.SetCenterAndZoom(new VELatLong(lat, lon), 19);
    map.SetMapStyle(VEMapStyle.Hybrid);
}

//formats the pushpins for the park-n-rides
function onParkRideLocFeedLoad(feed) {
    if (feed != null) {
        var numShapes = feed.GetShapeCount();
        for (var i = 0; i < numShapes; ++i) {
            try {
                var shape = feed.GetShapeByIndex(i);
                shape.SetCustomIcon("http://www.downtownlightrail.com/light-rail-maps/images/car.gif");
            }
            catch (e) {

            }
        }
    }
}

//gets the park and ride locations and loads them in the shapelayer. 
function LoadParkRideLoc() {
    //    var shapeSource = new VEShapeSourceSpecification (VEDataType.ImportXML, 'http://www.downtownlightrail.com/light-rail-maps/Parking.ashx?lineId=15', oPRShapeL);
    //    map.ImportShapeLayerData(shapeSource, onParkRideLocFeedLoad, 0);
}

//function Resize()
//{
//    var mapDiv = document.getElementById("myMap");
//    var sqlTXT = document.getElementById("txtSQL");
//    var accordion = document.getElementById("Accordion1");
//    var windowWidth = document.body.clientWidth;
//    var windowHeight = document.body.clientHeight;
//    mapWidth = windowWidth - 305;
//    mapHeight = windowHeight  - 155;
//    mapDiv.style.width = mapWidth + "px";
//    mapDiv.style.height = mapHeight + "px";
//    sqlTXT.style.width = mapWidth - 175 + "px";
//    accordion.style.height = (windowHeight - 45) + "px";
//    map.Resize(mapWidth, mapHeight);
//    map.ShowMiniMap(mapWidth-205, 13, VEMiniMapSize.Large);
//}

//This function is used to hide and show the station shape layer after it is loaded.
function ToggleStationLayer() {
    if (oStationShapeL.GetVisibility()) {
        oStationShapeL.Hide();
    }
    else {
        oStationShapeL.Show();
    }
}

//This function is used to hide and show the park-n-ride shape layer after it is loaded.
function ToggleParknRideLayer() {
    if (oPRShapeL.GetVisibility()) {
        oPRShapeL.Hide();
    }
    else {
        oPRShapeL.Show();
    }
}

//Toggles traffic off and on.
function ToggleTraffic() {
    if (bTrafficLoaded) {
        bTrafficLoaded = false;
        map.HideTrafficLegend();
        map.ClearTraffic();
    }
    else {
        bTrafficLoaded = true;
        map.ShowTrafficLegend(20, 470);
        map.SetTrafficLegendText("Traffic");
        map.LoadTraffic(bTrafficLoaded);
    }
}

//Does the find functionality - yellow book find. bNext = -1 means a new search.
function DoFind(numResults, bNext) {
    try {
        var what = document.getElementById('txtWhat').value;
        findLayer.DeleteAllShapes();
        findLayer = new VEShapeLayer();

        map.AddShapeLayer(findLayer);

        if (bNext == -1) {
            index = 0;
        }
        else if (bNext != 1) {
            index = parseInt(index) - (numResults * 2)
        }

        if (index < 0) index = 0;
        if (numResults > 20) numResults = 20;
        results = map.Find(what,
                          null,
                          null,
                          findLayer,
                          index,
                          numResults,
                          true,
                          true,
                          true,
                          true,
                          MoreResults);
        index = parseInt(index) + numResults;
    }
    catch (e) {
        alert(e.message);
    }
}

function MoreResults(layer, resultsArray, places, hasMore, veErrorMessage) {
    var r = "";
    if (hasMore) {
        if (index > 10) {
            r = "<a href='#' onclick='javascript:DoFind(10,0);'>&lt;Prev</a>&nbsp;&nbsp;";
        }
        r = r + "<a href='#' onclick='javascript:DoFind(10,1);'>Next></a><hr />";
    }
    else if (index < 10) {
        r = "<a href='#' onclick='javascript:DoFind(10,1);'>Next></a><hr />";
    }
    else {
        if (index > 9) {
            r = "<a href='#' onclick='javascript:DoFind(10,0);'>&lt;Prev</a>";
        }
    }

    document.getElementById('results').innerHTML = r;
    var resList = "";

    if (layer != null) {
        var numShapes = layer.GetShapeCount();
        for (var i = 0; i < numShapes; ++i) {
            var x = i + 1
            var shape = layer.GetShapeByIndex(i);
            shape.SetCustomIcon("http://www.downtownlightrail.com/light-rail-maps/images/Black" + x + ".gif");

            try {
                var fName = resultsArray[i].Name;
                var fDescrip = resultsArray[i].Description;
                var fPhone = resultsArray[i].Phone;
            }
            catch (e) {

            }
            resList = resList + "<img src='http://www.downtownlightrail.com/light-rail-maps/images/Black" + x + ".gif'</img>" + fName + "<br />" + fDescrip + "<br />" + fPhone + "<br /><hr />";
        }
    }
    document.getElementById('resultslist').innerHTML = resList;
}

function hideFindDiv() {
    //hide the find part of the control
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('findControl').style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.findControl.visibility = 'hidden';
        }
        else { // IE 4 
            document.all.findControl.style.visibility = 'hidden';
        }
    }

    //hide the results part of the control
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('results').style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.results.visibility = 'hidden';
        }
        else { // IE 4 
            document.all.results.style.visibility = 'hidden';
        }
    }
}

function showFindDiv() {
    //show the find part of the control
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('findControl').style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.findControl.visibility = 'visible';
        }
        else { // IE 4 
            document.all.findControl.style.visibility = 'visible';
        }
    }

    //show the results part of the control
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('results').style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4 
            document.results.visibility = 'visible';
        }
        else { // IE 4 
            document.all.results.style.visibility = 'visible';
        }
    }
} 


