            var map = null;
	        var resultsarray=new Array();	
	        var layer = new VEShapeLayer();
	        var traillayer = new VEShapeLayer();
	        var preservelayer = new VEShapeLayer();
		    var servicearealayer = new VEShapeLayer();
            var ParkingCount;
	        var TrailCount;
	        var PreserveCount;
	        var preserve= new Array();
	        var turnlegs = new Array();
	        var findpreservestring;
	        var latlong;
	        var ZoomLatLong;
	        var LeavingLatLong;
	        var ZoomShape;
	        var turns;
	        var directions;
	        var searchShapeLayer = new VEShapeLayer();
	        var ashape2;
	        var atitle2;
	        var InfoBoxLatLong;
	        var HasBeenAerial = false;
	        var tileSource;
	        var veLayerSpec2;
	        var veLayerSpec3;
                
            function GetMap()
            {
                if(typeof(PreserveLatLong) != "undefined" && typeof(ZoomLevel) != "undefined" && typeof(DashboardSize) != "undefined")
                {
                    map = new VEMap("mapControl");
                    map.SetDashboardSize(DashboardSize);
                    var MapOptions = new VEMapOptions();
                    MapOptions.EnableBirdseye = false;
                    if (typeof(MapKey) != "undefined") {
                        //alert(MapKey);
                        map.SetCredentials(MapKey);                    
                    }
                    
                    map.LoadMap(PreserveLatLong, ZoomLevel, MapStyle, false, VEMapMode.Mode2D, true, 0, MapOptions);
	                map.AttachEvent("onchangemapstyle", StyleChangeHandler);
                    map.EnableShapeDisplayThreshold(false);
                    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, "http://www.acreslandtrust.org/clientimages/44551/parking.xml", layer);
	                var veLayerSpec4 = new VEShapeSourceSpecification(VEDataType.ImportXML, 
"http://www.acreslandtrust.org/clientimages/44551/servicearea.xml", servicearealayer);
   	                map.ImportShapeLayerData(veLayerSpec4, onServiceAreaLoad,0);
                    map.ImportShapeLayerData(veLayerSpec, onParkingLoad,0);
                    veLayerSpec2 = new VEShapeSourceSpecification(VEDataType.ImportXML, "http://www.acreslandtrust.org/clientimages/44551/preserve.xml", preservelayer);
                    veLayerSpec3 = new VEShapeSourceSpecification(VEDataType.ImportXML, "http://www.acreslandtrust.org/clientimages/44551/trails.xml", traillayer);
                    veLayerSpec3.MaxImportedShapes=5000;
                    //map.ImportShapeLayerData(veLayerSpec2,onPreserveLoad,0);
	                //map.ImportShapeLayerData(veLayerSpec3,onTrailLoad,0);
	                map.AddShapeLayer(searchShapeLayer);
	                //@@ This is for future development to incorporate topo map tiles
	                tileSource = new VETileSourceSpecification("Layer_NewLayer", "http://www.acreslandtrust.org/clientimages/44551/maps/%4.png");
	                tileSource.NumServers = 1;
	                //tileSource.Bounds = [new VELatLongRectangle(new VELatLong(49,-123),new VELatLong(47,-121))];
	                tileSource.MinZoomLevel = 12;
	                tileSource.MaxZoomLevel = 18;
	                tileSource.Opacity = 1.0;
	                tileSource.ZIndex = 2;
 	                map.AddTileLayer(tileSource, true);
                }
            }
            
            function Resize()
            {
                var mapDiv = document.getElementById("mapControl");
                 var OutputPanel = document.getElementById("mapOutputPanel");
	             var windowWidth = document.documentElement.clientWidth;
	             var windowHeight = document.documentElement.clientHeight;
                 var mapWidth;
                 var mapHeight;
	             if (windowWidth > 253)
                 {
	                mapWidth = windowWidth - 253;
	             }
	             else
	             {
	                mapWidth = 0;
	             }
	             if (windowHeight > 475)
                 {
	                mapHeight = windowHeight - 102;
	             }
	             else
	             {
	                mapHeight = 373;
	             }
        	          
	             var dirHeight = mapHeight - 245;
	             OutputPanel.style.height = dirHeight + "px";
	             mapDiv.style.width = mapWidth + "px";
	             mapDiv.style.height = mapHeight + "px";
	             window.setTimeout(function() 
	                    {
	                    map.Resize(mapWidth, mapHeight);
	                    }, 300);
	        }
                
            function Print()
            {
                window.print();
            }

            function DisposeMap()
            {
                if(map != null)
                {
                    map.Dispose();
                }
            }                                            

            function addOption(selectbox,text,value)
	        {
		        var optn = document.createElement("OPTION");
		        optn.text = text;
		        optn.value = value;
		        selectbox.options.add(optn);
	        }

	        function onParkingLoad(ParkingFeed)
	        {
                ParkingCount = layer.GetShapeCount();
	            for (var i=0; i < ParkingCount;++i)
	            {
		            var indshape =layer.GetShapeByIndex(i);
		            indshape.SetCustomIcon("http://www.acreslandtrust.org/clientimages/44551/oakleaf.gif");
			    indshape.SetMoreInfoURL(null);
		            var indtitle = indshape.GetTitle();
		            preserve.push(indtitle);
		        }
		        preserve.sort();
	            StyleChangeHandler();
	            WriteOutput("");
	            document.getElementById("mapOutputPanel").style.zIndex="0";
                //if(document.getElementById("mapPreserve_list") != null && document.getElementById("mapZoomPreserveList") != null && document.getElementById("mapLeavingPreserveList") != null)
                //{
		            for (i=0; i < ParkingCount;++i)
	                {
		                addOption(document.mapdrop_list.mapPreserve_list, preserve[i], preserve[i]);
		                addOption(document.mapZoomDropList.mapZoomPreserveList, preserve[i], preserve[i]);
		                addOption(document.mapLeavingDropList.mapLeavingPreserveList, preserve[i], preserve[i]);
	                }
	            //}
            } 

            function onPreserveLoad(PreserveFeed)
	        {
	            PreserveCount = preservelayer.GetShapeCount();
	            if (map.GetMapStyle() == "b" || map.GetMapStyle() == "o") {
	                map.HideTileLayer("Layer_NewLayer");
	                for (var j = 0; j < PreserveCount; ++j) {
	                    var PreserveShape = preservelayer.GetShapeByIndex(j);
	                    PreserveShape.HideIcon();
	                    PreserveShape.SetMinZoomLevel(1);
	                    PreserveShape.SetLineColor(new VEColor(255, 0, 0, 0.5));
	                    PreserveShape.SetLineWidth(4);
	                    PreserveShape.SetFillColor(new VEColor(255, 255, 255, 0.0));
	                }
	            }
	            else if (map.GetMapStyle() == "a" || map.GetMapStyle() == "h") {
	                map.HideTileLayer("Layer_NewLayer");
	                for (var j = 0; j < PreserveCount; ++j) {
	                    var PreserveShape = preservelayer.GetShapeByIndex(j);
	                    PreserveShape.HideIcon();
	                    PreserveShape.SetMinZoomLevel(12);
	                    PreserveShape.SetLineColor(new VEColor(255, 0, 0, 0.5));
	                    PreserveShape.SetLineWidth(3);
	                    PreserveShape.SetFillColor(new VEColor(255, 255, 255, 0.0));
	                }
	            }
	            else {
	                map.ShowTileLayer("Layer_NewLayer");
	                PreserveShape.HideIcon();
	                PreserveShape.Hide();
	            }
		        		
		        
	        }

	        function onTrailLoad(TrailFeed)
	        {
		        TrailCount = traillayer.GetShapeCount();
		        if (map.GetMapStyle() == "b" || map.GetMapStyle() == "o") {
		            map.HideTileLayer("Layer_NewLayer");
		            for (var i = 0; i < TrailCount; ++i) {
		                var TrailShape = traillayer.GetShapeByIndex(i);
		                TrailShape.HideIcon();
		                TrailShape.SetMinZoomLevel(1);
		                TrailShape.SetLineColor(new VEColor(255, 255, 255, 0.75));
		            }
		        }
		        else if (map.GetMapStyle() == "a" || map.GetMapStyle() == "h") {
		            map.HideTileLayer("Layer_NewLayer");
		            for (var i = 0; i < TrailCount; ++i) {
		                var TrailShape = traillayer.GetShapeByIndex(i);
		                TrailShape.HideIcon();
		                TrailShape.SetMinZoomLevel(15);
		                TrailShape.SetLineColor(new VEColor(255, 255, 255, 0.75));
		            }
		        }
		        else {
		            map.ShowTileLayer("Layer_NewLayer");
		            TrailShape.HideIcon();
		            TrailShape.Hide();
		        }

		        for (var i=0; i < TrailCount;++i)
		        {
			        var TrailShape =traillayer.GetShapeByIndex(i);
			        TrailShape.HideIcon();
			        TrailShape.SetMinZoomLevel(15);		
		        }
	            //StyleChangeHandler();
	            WriteOutput("");
	            document.getElementById("mapOutputPanel").style.zIndex="0";
            }

	        function onServiceAreaLoad(ServiceAreaFeed)
	        {
		        var ServiceAreaShape =servicearealayer.GetShapeByIndex(0);
			    ServiceAreaShape.HideIcon();
			    ServiceAreaShape.SetLineColor(new VEColor(115,0,0,0.8));
			    ServiceAreaShape.SetFillColor(new VEColor(255,255,255,0.0));  
           	}

            function OpenFullScreen()
            {                                                    	
		//window.open ("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm");
                var PrintLatLong = map.GetCenter();
                var ZL = map.GetZoomLevel();
                var Lat = PrintLatLong.Latitude;
                var Long = PrintLatLong.Longitude;
                var MS = map.GetMapStyle();
                if (MS == "b" || MS == "o")
                {
                    var origMapStyle = MS;
                    map.SetMapStyle(VEMapStyle.Hybrid);
                    PrintLatLong = map.GetCenter();
                    Lat = PrintLatLong.Latitude;
                    Long = PrintLatLong.Longitude;
                    map.SetMapStyle(origMapStyle);
                    window.open("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm?Lat=" + Lat + "&Long=" + Long + "&ZL=" + ZL + "&MS=" + MS);		                    
                }
                else
                {
                    window.open("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm?Lat=" + Lat + "&Long=" + Long + "&ZL=" + ZL + "&MS=" + MS);		
                }
            }            
            function SendMapLink()
		    {
		    //window.open ("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm");
                var PrintLatLong = map.GetCenter();
                var ZL = map.GetZoomLevel();
                var Lat = PrintLatLong.Latitude;
                var Long = PrintLatLong.Longitude;
                var MS = map.GetMapStyle();
                if (MS == "b" || MS == "o")
                {
                    var origMapStyle = MS;
                    map.SetMapStyle(VEMapStyle.Hybrid);
                    PrintLatLong = map.GetCenter();
                    Lat = PrintLatLong.Latitude;
                    Long = PrintLatLong.Longitude;
                    map.SetMapStyle(origMapStyle);
                    //window.open("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm?Lat=" + Lat + "&Long=" + Long + "&ZL=" + ZL + "&MS=" + MS);		                    
                }
                else
                {
                    //window.open("http://www.acreslandtrust.org/clientimages/44551/FullScreenMap.htm?Lat=" + Lat + "&Long=" + Long + "&ZL=" + ZL + "&MS=" + MS);		
                }
            }
	        function StyleChangeHandler(e)
	        {
	            if (HasBeenAerial == false && map.GetMapStyle() != "s" && map.GetMapStyle() != "r")
	            {
	                WriteOutput("Loading Map...");
	                //alert(HasBeenAerial + map.GetMapStyle());
	                map.ImportShapeLayerData(veLayerSpec2, onPreserveLoad, 0);
	                map.ImportShapeLayerData(veLayerSpec3, onTrailLoad, 0);
	                HasBeenAerial = true;
	            }
	            else 
	            {
	                if (map.GetMapStyle() == "b" || map.GetMapStyle() == "o") {
	                    map.HideTileLayer("Layer_NewLayer");
	                    for (var i = 0; i < TrailCount; ++i) {
	                        var TrailShape = traillayer.GetShapeByIndex(i);
	                        TrailShape.Show();
	                        TrailShape.SetMinZoomLevel(1);
	                        TrailShape.SetLineColor(new VEColor(255, 255, 255, 0.75));
	                    }
	                    for (var j = 0; j < PreserveCount; ++j) {
	                        var PreserveShape = preservelayer.GetShapeByIndex(j);
	                        PreserveShape.Show();
	                        PreserveShape.SetMinZoomLevel(1);
	                        PreserveShape.SetLineColor(new VEColor(255, 0, 0, 0.5));
	                        PreserveShape.SetLineWidth(4);
	                        PreserveShape.SetFillColor(new VEColor(255, 255, 255, 0.0));
	                    }
	                }
	                else if (map.GetMapStyle() == "a" || map.GetMapStyle() == "h") {
	                    map.HideTileLayer("Layer_NewLayer");
	                    for (var i = 0; i < TrailCount; ++i) {
	                        var TrailShape = traillayer.GetShapeByIndex(i);
	                        TrailShape.Show();
	                        TrailShape.SetMinZoomLevel(15);
	                        TrailShape.SetLineColor(new VEColor(255, 255, 255, 0.75));
	                    }
	                    for (var j = 0; j < PreserveCount; ++j) {
	                        var PreserveShape = preservelayer.GetShapeByIndex(j);
	                        PreserveShape.Show();
	                        PreserveShape.SetMinZoomLevel(12);
	                        PreserveShape.SetLineColor(new VEColor(255, 0, 0, 0.5));
	                        PreserveShape.SetLineWidth(3);
	                        PreserveShape.SetFillColor(new VEColor(255, 255, 255, 0.0));
	                    }
	                }
	                else {
	                    map.ShowTileLayer("Layer_NewLayer");
	                    for (var i = 0; i < TrailCount; ++i) {
	                        var TrailShape = traillayer.GetShapeByIndex(i);
	                        TrailShape.Hide();
	                        //TrailShape.SetMinZoomLevel(15);
	                        //TrailShape.SetLineColor(new VEColor(0, 0, 0, 0.5));
	                    }
	                    for (var j = 0; j < PreserveCount; ++j) {
	                        var PreserveShape = preservelayer.GetShapeByIndex(j);
	                        PreserveShape.Hide();
	                        //PreserveShape.SetMinZoomLevel(12);
	                        //PreserveShape.SetLineColor(new VEColor(128, 128, 128, 0.5));
	                        //PreserveShape.SetLineWidth(1);
	                        //PreserveShape.SetFillColor(new VEColor(38, 115, 0, 0.3));
	                    }
	                }
	            }
            }
        	 
	        function disp_text()
            {
                var selected_text = document.mapdrop_list.mapPreserve_list.value;	 
	            for (var i=0; i < ParkingCount;++i)
	            {
		            var indshape =layer.GetShapeByIndex(i);
		            var indtitle = indshape.GetTitle();
			        if (selected_text == indtitle)
			        {
			            latlong = indshape.GetIconAnchor();
			        }
	            }
            }

	        function ZoomDispText()
            {
                var selected_text = document.mapZoomDropList.mapZoomPreserveList.value;	 
	            for (var i=0; i < ParkingCount;++i)
	            {
		            var indshape =layer.GetShapeByIndex(i);
		            var indtitle = indshape.GetTitle();
			        if (selected_text == indtitle)
			        {
				        ZoomLatLong = indshape.GetIconAnchor();
				        ZoomShape = indshape;
			        }
	            }
            }
        	    
	        function LeavingDispText()
            {
                var selected_text = document.mapLeavingDropList.mapLeavingPreserveList.value;	 
	            for (var i=0; i < ParkingCount;++i)
	            {
		            var indshape =layer.GetShapeByIndex(i);
		            var indtitle = indshape.GetTitle();
			        if (selected_text == indtitle)
			        {
				        LeavingLatLong = indshape.GetIconAnchor();
			        }
	            }
            }
        	    
            function ZoomTo()
            {
                var ZoomList = document.getElementById("mapZoomPreserveList");
	            var OutputPanel = document.getElementById("mapOutputPanel").innerHTML;

                if (ZoomList.value == "")
                {
                    WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Preserve Name</span> </em>");
                }
                else
                {
                    if (map.GetZoomLevel() < 15) {
                        map.SetCenterAndZoom(ZoomLatLong, 15);
                    }
                    else {
                        map.SetCenter(ZoomLatLong);
                    }	                
	                map.ShowInfoBox(ZoomShape, ZoomLatLong);
	                if (OutputPanel = "*Required:  Preserve Name")
	                {
	                    WriteOutput("");
	                }
	            }
            }	    
    	    
	        function sortNumber(a, b)
	        {
	            var numA = parseFloat(a);
	            var numB = parseFloat(b);
	            return numA - numB;
	        }

	        function GetRoute()
	        {
	            var options = new VERouteOptions();
                options.RouteCallback = onGotRoute;      
                var mapRadioAddress = document.getElementById("mapRadioAddress");
                var mapRadioShortestDistance = document.getElementById("mapRadioShortestDistance");
                var mapRadioPreserve = document.getElementById("mapRadioPreserve");
                var LeavingFrom = document.getElementById("mapLeavingPreserveList");
                var TravelingTo = document.getElementById("mapTravelingToPreserveList"); 
                if (mapRadioAddress.checked)
                {
                    var mapDirectionsLeavingFromtxt = document.getElementById("mapDirectionsLeavingFromtxt");
                    var WhereTextInput = mapDirectionsLeavingFromtxt.value;
                }    
                else
                {
                    WhereTextInput = LeavingLatLong;
                }
                if (mapRadioShortestDistance.checked)
                {
                    options.RouteOptimize = VERouteOptimize.MinimizeDistance;
                }
                if (mapRadioPreserve.checked && LeavingFrom.value == "")
                {
                    WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Leaving From</span> </em>");
	                turns = "";
	                directions = "";           
                }
                else if (mapRadioAddress.checked && mapDirectionsLeavingFromtxt.value == "")
                {
                    WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Leaving From</span> </em>");
	                turns = "";
	                directions = "";           
                }
                else
                {
                    if (TravelingTo.value == "")
                    {
                        WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Traveling To</span> </em>");
                        turns = "";
	                    directions = "";
                    }
                    else
                    {
                        map.GetDirections([WhereTextInput, latlong], options);       
	                    WriteOutput("Retrieving Directions...");
	                    turns = "";
	                    directions = "";
	                }
	            }
            }
            function onGotRoute(route)
            {
                try
                {  
                    var legs = route.RouteLegs;
                    turnlegs = [];
                    var routetime;
                    var LeavingFrom = document.getElementById("mapLeavingPreserveList");
                    var TravelingTo = document.getElementById("mapTravelingToPreserveList"); 
                    var mapRadioAddress = document.getElementById("mapRadioAddress");
                    var mapDirectionsLeavingFromtxt = document.getElementById("mapDirectionsLeavingFromtxt");


                    var seconds = route.Time;
		            if (seconds <3570)
		            {
			            routetime = Math.round (seconds / 60) + " min";	
		            }
		            else
		            {
			            var hours = Math.floor(seconds /3600);
			            var minutes = Math.round(seconds/60) - hours * 60;
			            routetime = hours + " hr " + minutes + " min";
		            }
	                var theleg = legs[0];
	                var starttext = theleg.Itinerary.Items[0];
                    turns = "<a href=" + '"' + "javascript:PrintPreviewDirections();" + '"' + ">Print Directions </a> <br/> Trip: " + route.Distance.toFixed(1) + " mi, " + routetime + "<ol> Start: "  + starttext.Text;
                    var mapRadioShortestDistance = document.getElementById("mapRadioShortestDistance");
                    if (mapRadioAddress.checked)
                    {
                        directions = "<h2> ACRES Directions </h2> From: " + mapDirectionsLeavingFromtxt.value + " <br/> To: " + TravelingTo.value + " <br/> <br/>";
                    }    
                    else
                    {
                        directions = "<h2> ACRES Directions </h2> From: " + LeavingFrom.value + " <br/> To: " + TravelingTo.value + " <br/> <br/>";
                    }
                    directions += "Trip: " + route.Distance.toFixed(1) + " mi, " + routetime + "<ol> Start: "  + starttext.Text;
                    var numTurns = 0;
                    var leg = null;
                    for(var i = 0; i < legs.length; i++)
                    {
                        leg = legs[i];  
                        var turn = null;  
                        for(var j = 1; j < leg.Itinerary.Items.length-1; j++)
                        {
                            turn = leg.Itinerary.Items[j];
                            turnlegs.push(new VELatLong(turn.LatLong.Latitude, turn.LatLong.Longitude));
                            turns += "<hr style=" + '"' + "height:0; border-right: #dcdcdc 0px solid; border-top: #dcdcdc 1px solid; border-left: #dcdcdc 0px solid; border-bottom: #dcdcdc 0px solid;" + '"' + ">" + "<li>" + "<a " + "style=" + '"' + "text-decoration: none;" + '"' + "href=" + '"' + "javascript:PanToDirections(" + (j-1) + ");" +'"' + ">" + turn.Text + "<a/>" + " (" + turn.Distance.toFixed(1) + " mi) </li>";
                            directions += "<hr style=" + '"' + "height:0; border-right: #dcdcdc 0px solid; border-top: #dcdcdc 1px solid; border-left: #dcdcdc 0px solid; border-bottom: #dcdcdc 0px solid;" + '"' + ">" + "<li>" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi) </li>";
                        } 
                    }
	                var endtext = theleg.Itinerary.Items[theleg.Itinerary.Items.length-1];
	                turns += "<hr style=" + '"' + "height:0; border-right: #dcdcdc 0px solid; border-top: #dcdcdc 1px solid; border-left: #dcdcdc 0px solid; border-bottom: #dcdcdc 0px solid;" + '"' + ">" + "End: " + endtext.Text + "<ol/>";
	                directions += "<hr style=" + '"' + "height:0; border-right: #dcdcdc 0px solid; border-top: #dcdcdc 1px solid; border-left: #dcdcdc 0px solid; border-bottom: #dcdcdc 0px solid;" + '"' + ">" + "End: " + endtext.Text + "<ol/>"; 
	                WriteOutput(turns);
	            }
                catch(e)
                {
                    WriteOutput("");
                }	    
            }

            function ClearDirections()
            {
                map.DeleteRoute();
 	            turns = "";
 	            directions ="";
	            WriteOutput("");	
            }

	        function WriteOutput(text)
	        {
	            document.getElementById("mapOutputPanel").innerHTML = text;
	        }

	        function ChangeToDirections()
	        {
	            var mapDirectionsControl = document.getElementById("mapDirectionsControl");
                var mapFindControl = document.getElementById("mapFindControl");
                var mapFindTab = document.getElementById("mapFindTab");
	            var mapDirectionsTab = document.getElementById("mapDirectionsTab");     
	            mapDirectionsControl.style.visibility = "visible";
	            mapFindControl.style.visibility= "hidden";
	            mapFindTab.style.border = "solid 1px Gray";
	            mapFindTab.style.height = "20px";
	            mapFindTab.style.backgroundColor = "#D2D2D2";
	            mapDirectionsTab.style.borderBottom ="none";
                mapDirectionsTab.style.height = "21px";
	            mapDirectionsTab.style.backgroundColor = "#F0F0F0"
	            if (turns != undefined)
	            {
		            WriteOutput(turns);
	            }	  
	            else
	            {
		            WriteOutput("");
	            }
            }

	        function ChangeToFind()
	        {
	            var mapDirectionsControl = document.getElementById("mapDirectionsControl");
                var mapFindControl = document.getElementById("mapFindControl");
                var mapFindTab = document.getElementById("mapFindTab");
	            var mapDirectionsTab = document.getElementById("mapDirectionsTab");
	            mapDirectionsControl.style.visibility = "hidden";	 
	            mapFindControl.style.visibility= "visible";   
	            mapDirectionsTab.style.border = "solid 1px Gray";
	            mapDirectionsTab.style.backgroundColor = "#D2D2D2";
	            mapDirectionsTab.style.height = "20px";
	            mapFindTab.style.backgroundColor = "#F0F0F0";
	            mapFindTab.style.borderBottom ="none";
	            mapFindTab.style.height = "21px";
	            if (findpreservestring != undefined)
	            {
	                WriteOutput(resultsarray.join("<br/>"));
	            }	  
	            else
	            {
		            WriteOutput("");
	            }
            }

            function Find()
            {
	            WriteOutput("Searching for preserves...");
	            var mapFindSearchRadius = document.getElementById("mapFindSearchRadius"); 
	            var mapFindSearchFromtxt = document.getElementById("mapFindSearchFromtxt");
                try
                {
                    if (mapFindSearchFromtxt.value == "" || mapFindSearchFromtxt.value =="Address, city, or location")
                    {
			            WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Search From</span> </em>");
                    }
                    else if (mapFindSearchRadius.value == "")
                    {
			            WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Search Radius</span> </em>");
                    }    
	                else if (isNaN(mapFindSearchRadius.value))
		            {
			            WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">Search Radius must be a number</span> </em>");
		            }
                    else
                    {
                    
                    map.Find(null, mapFindSearchFromtxt.value, null, null, null, null, true, true, null, true, GetCoordinates);
                    }
                }
                catch(e)
                {
                    WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">*Required:  Search From</span> </em>");
                }
            }

	        function ShowHyperlink(text)
	        {
	            for (var i=0; i < ParkingCount;++i)
	            {
		            var ashape =layer.GetShapeByIndex(i);
		            var atitle = ashape.GetTitle();
		            if (text == atitle)
			        {
			            var LatLong = ashape.GetIconAnchor();
			            var ourshape = ashape;
			            if (map.GetZoomLevel() < 15) {
			                map.SetCenterAndZoom(LatLong, 15);
			            }
			            else {
			                map.SetCenter(LatLong);
			            }
			        }
		            window.setTimeout(function() 
		            {
		                map.ShowInfoBox(ourshape, LatLong);
		            }, 1000);		  
	            }
	        }

	        function ShowInfoBox(text)
	        {
	            map.HideInfoBox(ashape2, InfoBoxLatLong);
	            for (var i=0; i < ParkingCount;++i)
	            {
		            ashape2 =layer.GetShapeByIndex(i);
		            atitle2 = ashape2.GetTitle();
		            if (text == atitle2)
		            {
			            InfoBoxLatLong = ashape2.GetIconAnchor(); 
			            var ExtentCoords = map.GetMapView();
                        if (InfoBoxLatLong.Latitude < ExtentCoords.TopLeftLatLong.Latitude && InfoBoxLatLong.Latitude > ExtentCoords.BottomRightLatLong.Latitude && InfoBoxLatLong.Longitude > ExtentCoords.TopLeftLatLong.Longitude && InfoBoxLatLong.Longitude < ExtentCoords.BottomRightLatLong.Longitude)
                        {
			                map.ShowInfoBox(ashape2, InfoBoxLatLong);
			            }
		            }
	            }
            }
        	 
	        function PanToDirections(text)
	        {
	            if (map.GetZoomLevel() > 13)
	            {
	                map.SetCenter(turnlegs[text]);
	            }
	            else
	            {
	                map.SetCenterAndZoom(turnlegs[text], 14);
	            }
	        }
             
            function PrintPreviewDirections()
            { 
                var inf = directions;   
                var win = window.open('', '', 'toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=400, height=400'); 

                win.document.write(inf);
                win.document.close();
            }
            
            function PrintMap()
            {
                var PrintLatLong = map.GetCenter();
                var ZL = map.GetZoomLevel();
                var Lat = PrintLatLong.Latitude;
                var Long = PrintLatLong.Longitude;
                var MS = map.GetMapStyle();
                window.open("http://www.acreslandtrust.org/clientimages/44551/PrintPreviewMap.htm?Lat=" + Lat + "&Long=" + Long + "&ZL=" + ZL + "&MS=" + MS);
            }
              
            function TermsOfUse()
            {
                window.open("http://www.microsoft.com/maps/assets/docs/terms.aspx"); 
            }        
	        function GetCoordinates(resultlayer, resultsArray, places, hasMore, veErrorMessage)
            {
                try
                {
                    var mapFindSearchRadius = document.getElementById("mapFindSearchRadius"); 
	                searchShapeLayer.DeleteAllShapes();
	                findpreservestring = "";
	                resultsarray.length= null;
   	                findPlaceResults = places[0].LatLong;	 
    	            var myShape = new VEShape(VEShapeType.Pushpin, findPlaceResults);
    	            var origin = findPlaceResults;
	                var radius = mapFindSearchRadius.value * 1.609344;
	                for(var i=0; i < layer.GetShapeCount(); i++)
	                {
	                    var shape = layer.GetShapeByIndex(i);
	                    var findlatlong = shape.GetPoints()[0];
	                    var d = distance(origin,findlatlong);
	                    if(Math.abs(d)<= Math.abs(mapFindSearchRadius.value))
	                    {
            		        var thestring = shape.Title;
		                    findpreservestring = (d.toFixed(1)) + " mi " + "- " + "<a " + "style=" + '"' + "text-decoration: none;" + '"' + "href=" + '"' + "javascript:ShowHyperlink(" + "'" + thestring + "'" + ");" +'"' + "OnMouseOver=" + '"' + "javascript:ShowInfoBox(" + "'" + thestring + "'" + ");" + '"' + ">" + shape.Title  + "<a/>";
		                    resultsarray.push(findpreservestring);    
	                    }
	                }
 	                drawCircle(origin,radius);
	                resultsarray.sort(sortNumber);
	                WriteOutput(resultsarray.join("<br/>"));
	            }
                catch(e)
                {
                    WriteOutput("<em> <span style=" + '"' + "color: red; " + '"' + ">Search From:  Location not found</span> </em>");
                }
            } 

	        function distance(latlong,latlong2)
	        {
	            var lat1 = latlong.Latitude;
	            var lon1 = latlong.Longitude;
	            var lat2 = latlong2.Latitude;
	            var lon2 = latlong2.Longitude;
	            var earthRadius = 6371; 
	            var factor = Math.PI/180;
	            var dLat = (lat2-lat1)*factor;
	            var dLon = (lon2-lon1)*factor; 
	            var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1*factor) 
	             * Math.cos(lat2*factor) * Math.sin(dLon/2) * Math.sin(dLon/2); 
	            var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	            var d = earthRadius * c * 0.62137119;
	            return d;
            }

	        function drawCircle(origin,radius)
	        {  
	            var earthRadius = 6371;
	            var lat = (origin.Latitude*Math.PI)/180; 
	            var lon = (origin.Longitude*Math.PI)/180; 
	            var d = parseFloat(radius)/earthRadius;  
	            var points = new Array();
	            for (i = 0; i <= 360; i++) 
	            { 
	                var point = new VELatLong(0,0);            
	                var bearing = i * Math.PI / 180; //rad
	                point.Latitude = Math.asin(Math.sin(lat)*Math.cos(d) + 
	                Math.cos(lat)*Math.sin(d)*Math.cos(bearing));
	                point.Longitude = ((lon + Math.atan2(Math.sin(bearing)*Math.sin(d)*Math.cos(lat),
	                Math.cos(d)-Math.sin(lat)*Math.sin(point.Latitude))) * 180) / Math.PI;
	                point.Latitude = (point.Latitude * 180) / Math.PI;
	                points.push(point);
	            }
	            var circle = new VEShape(VEShapeType.Polyline, points); 
	            circle.HideIcon();
	            searchShapeLayer.AddShape(circle);
	            map.SetMapView(points);
            }  

	        function ClearFindResults()
	        {
	            searchShapeLayer.DeleteAllShapes();
	            resultsarray.length= null;
	            WriteOutput("");
	        }

            function clearText(thefield)
            {
                if (thefield.defaultValue==thefield.value)
                thefield.value = "";
            } 
        				
            function RadioPreserve_onclick() 
            {
                var mapDirectionsLeavingFromtxt = document.getElementById("mapLeavingPreserveList");
                var LeavingFrom = document.getElementById("mapLeavingPreserveList");       
                mapDirectionsLeavingFromtxt.style.visibility= "hidden";
                LeavingFrom.style.visibility= "visible";
            }
            
            function RadioAddress_onclick() 
            {
                var mapDirectionsLeavingFromtxt = document.getElementById("mapLeavingPreserveList");
                var LeavingFrom = document.getElementById("mapLeavingPreserveList");
                mapDirectionsLeavingFromtxt.style.visibility= "visible";
                LeavingFrom.style.visibility= "hidden";
            }
            
            window.onload=GetMap;
            window.onunload=DisposeMap;
