﻿//preload loading image...for ie 6
if (document.images) {
	pic1 = new Image(142, 32);
	pic2 = new Image(1, 1);
	pic3 = new Image(1, 1);
	pic4 = new Image(1, 1);
	pic5 = new Image(1, 1);
	pic1.src = "/i/map/loading.gif";
	pic2.src = "/i/map/level_on.gif";
	pic3.src = "/i/map/street_on.gif";
	pic4.src = "/i/map/city_on.gif";
	pic5.src = "/i/map/region_on.gif";
};

var mapId;
var map = null;
var mapNavControl;
var mapPOIControl;
var mapPOIListControl;
var mapSelected;
var mapSize;
var selectedPOIArray = new Array();
var selectedCatArray = new Array();
var propArray = new Array();
var propLayer;
var poiLayer;
var poiListVisible = false;
var maxClusterItems = 15;
//used to show infobox of a POI
var selectedPOI = "";
var initCenter = null;
var initZoom = 8;
var lastCenter = null;
var s6avLink = "";
var avLink = "";
var detLink = "";
var dirLink = "";
var centerName = "";
var showAvailInfo = true;

function ShowFullMap(lat, lng, id, zoomLevel) {
	var mapDiv = document.getElementById(id);
	if (mapDiv) {
		ShowBasicMap(lat, lng, id, zoomLevel);
		AddMapNavControl();
		AddPOIControl();
		if (map) {
			map.AttachEvent("onchangeview", onChangeView);
			map.AttachEvent("onendzoom", EndZoomHandler);
			map.AttachEvent("onendpan", EndPanHandler);
			setSelectedMap(document.getElementById("roadLink"));
			map.ClearInfoBoxStyles();
			ResetUIControls();
			poiLayer = new VEShapeLayer();
			map.AddShapeLayer(poiLayer);
			UpdateZoomImages();
		}
	}
}
function ShowBasicMap(lat, lng, id, zoomLevel) {
	var mapDiv = document.getElementById(id);
	if (mapDiv) {
		mapId = id;
		map = new VEMap(mapId);
		if (lat != null && lng != null) {
			var latLng = new VELatLong(lat, lng);
			map.LoadMap(latLng, zoomLevel);
		} else
			map.LoadMap();
		map.HideDashboard();
		map.ClearInfoBoxStyles();
		poiLayer = new VEShapeLayer();
		map.AddShapeLayer(poiLayer);
	}
}

function HideMap() {
	var div = document.getElementById("mapDiv");
	if (div != undefined) {
		div.style.display = "none";
		if (mapNavControl != undefined) mapNavControl.style.display = "none";
		if (mapPOIControl != undefined) mapPOIControl.style.display = "none";
		if (mapPOIListControl != undefined) mapPOIListControl.style.display = "none";
	}
}
function DisplayMap() {
	var div = document.getElementById("mapDiv");
	if (div != undefined) {
		div.style.display = "";
		if (mapNavControl != undefined) mapNavControl.style.display = "";
		if (mapPOIControl != undefined) mapPOIControl.style.display = "";
		if (mapPOIListControl != undefined) mapPOIListControl.style.display = "";
		ResetUIControls();
	}
}

function AddProperties(showHover) {
	var Name; var Num; var Photo; var Address; var City, State, Zip; var Phone; var DirectionsToLink; var DirectionsFrLink; var Sizzle; var latitude; var longitude; var Brand; var Avail; var Video; var PropLink; if (showHover == undefined) showHover = true;
	var hwylocator = "";
	var isRemodeled = false; var isRefreshed = false;
	if (map) {
		var shapes = new Array();
		var pin = null;
		var cent = GetCenterLatLong();
		for (i = 0; i < propArray.length; i++) {
			Num = propArray[i][0];
			Name = propArray[i][1];
			Photo = propArray[i][2];
			Address = propArray[i][3];
			City = propArray[i][4];
			State = propArray[i][5];
			Zip = propArray[i][6];
			Phone = propArray[i][7];
			Latitude = propArray[i][8];
			Longitude = propArray[i][9];
			Sizzle = propArray[i][10];
			//DirectionsToLink = propArray[i][11];
			//DirectionsFrLink = propArray[i][12];

			Brand = propArray[i][11];
			Avail = propArray[i][12];

			Video = propArray[i][13];
			isRemodeled = propArray[i][14];
			isRefreshed = propArray[i][15];
			hwylocator = propArray[i][16];
			PropLink = detLink.replace("$propNum", Num); //propArray[i][17];
			var prefix = "Motel 6 - ";
			AvailLink = avLink.replace("$propNum", Num); //propArray[i][15];
			if (Brand == "STD") {
				prefix = "Studio 6 - ";
				AvailLink = s6avLink.replace("$propNum", Num); //propArray[i][15];
			}
			pin = new VEShape(VEShapeType.Pushpin, new VELatLong(Latitude, Longitude));
			pin.ID = "prop_" + Num;

			DirectionsToLink = dirLink.replace("$end", prefix + Name)
			DirectionsToLink = DirectionsToLink.replace("$endLoc", Latitude + "," + Longitude)
			DirectionsToLink = DirectionsToLink.replace("$start", centerName)
			DirectionsToLink = DirectionsToLink.replace("$startLoc", cent.Latitude + "," + cent.Longitude)

			DirectionsFrLink = dirLink.replace("$end", centerName)
			DirectionsFrLink = DirectionsFrLink.replace("$endLoc", cent.Latitude + "," + cent.Longitude)
			DirectionsFrLink = DirectionsFrLink.replace("$start", prefix + Name)
			DirectionsFrLink = DirectionsFrLink.replace("$startLoc", Latitude + "," + Longitude)

			//if (showHover == true) pin.SetTitle ("<span style='display:none;'>"+prefix + Name+"</span>");
			if (showHover == true) pin.SetTitle(prefix + Name + " #" + Num);
			pin.SetCustomIcon(GetPropertyIcon(Brand, Avail));
			if (showHover == true) pin.SetDescription(GetPropertyHoverInfo(Brand, Avail, Name, Num, Photo, Address, City, State, Zip, Phone, DirectionsToLink, DirectionsFrLink, Sizzle, AvailLink, Video, PropLink, isRemodeled, isRefreshed, hwylocator));
			shapes.push(pin);
		}
		//if there are shapes to add, then add to the property shape layer
		if (shapes.length > 0) {
			if (propLayer != null) { map.DeleteShapeLayer(propLayer); propLayer = null; }
			propLayer = new VEShapeLayer();
			map.AddShapeLayer(propLayer);
			propLayer.AddShapes(shapes);
		}
		UpdateCluster();
	}
}

function AddCenterPushpin(lat, lng, name, desc) {
	if (map) {
		var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lng));
		pin.SetCustomIcon(GetCenterPointIcon());
		pin.SetDescription(GetGenericHoverInfo(name, desc, -39 + 8, -48 + 8));
		map.AddShape(pin);
	}
}
function AddIconToMap(lat, lng, name, desc, icon, leftOffset, topOffset) {
	if (map) {
		var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lng));
		pin.SetCustomIcon(icon);
		pin.SetDescription(GetGenericHoverInfo(name, desc, leftOffset, topOffset));
		map.AddShape(pin);
	}
}
//Since we have one orientation button we rotate the orientation everytime we click on it
function SetBirdseyeOrientation() {
	if (map) {
		var beoScene = map.GetBirdseyeScene();
		switch (beoScene.GetOrientation()) {
			case VEOrientation.East: map.SetBirdseyeOrientation(VEOrientation.North);
				break;
			case VEOrientation.North: map.SetBirdseyeOrientation(VEOrientation.West);
				break;
			case VEOrientation.West: map.SetBirdseyeOrientation(VEOrientation.South);
				break;
			case VEOrientation.South: map.SetBirdseyeOrientation(VEOrientation.East);
				break;
			default:
				//alert("nothing");
		}
	}
}

function GetPropertyIcon(brand, avail) {
	var icon = null;
	var img;

	if (brand == "STD") {
		if (avail == false && showAvailInfo == true) {
			img = "s6_icon_na.gif";
		} else {
			img = "s6_icon.gif";
		}
	} else {
		if (avail == false && showAvailInfo == true) {
			img = "m6_icon_na.gif";
		} else {
			img = "m6_icon.gif";
		}
	}

	icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div><img src='/i/map/" + img + "' style='position:relative;left:0px;top:-17px'/></div>";
	icon.TextContent = " ";
	return icon;
}

function GetPOIIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:0px;top:-14px;'><img src='/i/map/poi_icon.gif'/></div>";
	icon.TextContent = " ";
	return icon;
}

function GetStartingPointIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:-3px;top:-16px;'><img src='/i/map/sign_start.gif'/></div>";
	icon.TextContent = " ";
	return icon;
}
function GetEndingPointIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:-3px;top:-16px;'><img src='/i/map/sign_end.gif'/></div>";
	icon.TextContent = " ";
	return icon;
}
function GetCenterPointIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:-2px;top:-2px'><img class='png' src='/i/map/target_icon.png'/></div>";
	icon.TextContent = " ";
	return icon
}
function GetM6ClusterIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:-14px;top:-19px'><img class='png' src='/i/map/m6_icon_cluster.png'/></div>";
	icon.TextContent = " ";
	return icon;
}
function GetS6ClusterIcon() {
	var icon = new VECustomIconSpecification();
	icon.CustomHTML = "<div style='position:relative;left:-14px;top:-19px'><img class='png' src='/i/map/s6_icon_cluster.png'/></div>";
	icon.TextContent = " ";
	return icon;
}
function GetPropertyHoverInfo(brand, avail, Name, Num, Photo, Address, City, State, Zip, Phone, DirectionsToLink, DirectionsFrLink, Sizzle, availLink, Video, PropLink, isRemodeled, isRefreshed, hwylocator) {
	var top = -89 + GetTopBrowserOffset();
	var left = -31 + GetLeftBrowserOffset();
	var availContent = "";
	var videoContent = "";
	var imgContent = "";
	var dirContent = "";
	var divClass = "mapInfoM6";
	var browserOffset = "top:" + top + "px;left:" + left + "px;";
	var prefix = "Motel 6 - ";
	var remodeledString = ""; var refreshedString = "";
	//avail Content

	if (avail == false && showAvailInfo == true)
		availContent = "<div class='na'>Not Available</div>";
	else if (availLink != "")
		availContent = "<a href='" + availLink + "'><img class='rates' src='/i/btn_rates_avail.gif' height='26' width='179' border='0'/></a>";
	else {
		if (brand == "STD")
			availContent = "<a href='/reservations/studio6_travel_web.asp?property=" + Num + "'><img class='rates' src='/i/btn_rates_avail.gif' height='26' width='179' border='0'/></a>";
		else
			availContent = "<a href='/ms/check-availability.do?property=" + Num + "'><img class='rates' src='/i/btn_rates_avail.gif' height='26' width='179' border='0'/></a>";
	}

	if (brand == "STD") {
		divClass = "mapInfoS6";
		prefix = "Studio 6 - ";
	}

	//video Content
	if (Video != "" && Video != undefined) videoContent = "<div class='video'><a href='" + PropLink + "'><img class='png' src='/i/map/video.png' /></a></div>";
	//photo Content
	if (Photo != "" && Photo != undefined) imgContent = "<div class='photo'><img src='/i/photos/" + Photo + ".jpg' /></div>"

	if (isRemodeled)
		remodeledString = "<div style='float:left;position:relative;'><img src='/i/remodeled_sm.gif' border='0' />&nbsp;</div>"
	if (isRefreshed)
		refreshedString = "<div style='float:left;position:relative;'><img src='/i/refreshed_sm.gif' border='0' />&nbsp;</div>"


	//directions
	if (DirectionsToLink != "")
		dirContent = "<div class='directions'>Directions <a href='" + DirectionsToLink + "'>To</a> | <a href='" + DirectionsFrLink + "'>From</a></div>"

	var info = "<div class='" + divClass + "' style='" + browserOffset + "'>" +
						"<div class=\"content\">" +
						"<div class='name' title='" + prefix + Name + " #" + Num + "'><a href='" + PropLink + "'>" + prefix + Name + " #" + Num + "</a></div>" +
            "<div class='media'>" + imgContent + videoContent + "</div>" +
            "<div class='address'>" +
							hwylocator + Address + "<br />" + City + ", " + State + " " + Zip + "<br />Phone: " + Phone +
							dirContent +
            "</div>" +
            "<div class='promo'>" + remodeledString + refreshedString + Sizzle + "</div>" +
            availContent +
            "</div>" +
            "<div class='bottom'></div>" +
            "</div>";

	return info;
}
function GetPOIHoverInfo(poiName, poiCategory) {
	var hoverPOIInfo;
	var left = -25 + GetLeftBrowserOffset();
	var top = -55 + GetTopBrowserOffset();
	var browserOffset = "top:" + top + "px;left:" + left + "px;";

	hoverPOIInfo = "<div class='mapInfoPOI' style='" + browserOffset + "'><div class=\"content\"><div class='name'>" + poiName + "</div><div class='category'>" + poiCategory + "</div></div><div class=\"bottom\"></div></div>";
	return hoverPOIInfo;
}

function GetGenericHoverInfo(hoverTitle, hoverDesc, leftOffset, topOffset) {
	var hoverGenericInfo;
	var left = leftOffset + GetLeftBrowserOffset();
	var top = topOffset + GetTopBrowserOffset();
	var browserOffset = "top:" + top + "px;left:" + left + "px;";
	hoverGenericInfo = "<div class='mapInfoGeneric' style='" + browserOffset + "'><div class='content'><div class='title'>" + hoverTitle + "</div><div class='desc'>" + hoverDesc + "</div></div><div class='bottom'></div></div>";
	return hoverGenericInfo;
}
function GetClusterHoverInfo(hoverTitle, hoverDesc, leftOffset, topOffset) {
	var left = leftOffset + GetLeftBrowserOffset();
	var top = topOffset + GetTopBrowserOffset();
	var browserOffset = "top:" + top + "px;left:" + left + "px;";
	var hover = "<div class='mapInfoGeneric' style='" + browserOffset + "'><div class='content'><div class='desc'>" + hoverTitle + "</div>" + hoverDesc + "</div><div class=\"bottom\"></div></div>";
	return hover;
}

function AddMapNavControl() {
	if (map) {
		mapNavControl = document.createElement("div");
		mapNavControl.id = "mapNav";
		mapNavControl.style.position = "relative";
		var left = 0;
		var top = 0;
		//Gecko engine is a couple pixels off when rendering controls on the map
		if (Web.Browser.isMozilla || (Gimme.Browser.isIE && GetIEVersion() >= 8) || Gimme.Browser.isKHTML) {
			top += 2;
			left += 2;
		}
		mapNavControl.style.top = top + "px";
		mapNavControl.style.left = left + "px";

		mapNavControl.innerHTML = "<div id='road'><a name='mapLinkType' id='roadLink' onclick='map.SetMapStyle(VEMapStyle.Road);setSelectedMap(this);'></a></div>" +
            "<div id='aerial'><a name='mapLinkType' onclick='map.SetMapStyle(VEMapStyle.Aerial);setSelectedMap(this);'></a></div>" +
            "<div id='hybrid'><a name='mapLinkType' onclick='map.SetMapStyle(VEMapStyle.Hybrid);setSelectedMap(this);'></a></div>" +
            "<div id='birdseye'><a id='birdseyeLink' name='mapLinkType' onclick='map.SetMapStyle(VEMapStyle.Birdseye);setSelectedMap(this);' style='display:none'></a></div>" +
            "<div id='zoomIn'><a href='javascript:void(0);' onclick='map.ZoomIn();'><img src='/i/map/zoom_in.gif' width='20' height='18' title='Zoom In' /></a></div>" +
            "<a id='rotateLink' style='display:none' onclick='SetBirdseyeOrientation();' title='Rotate the camera angle'></a>" +
            "<div id='levelControls' style='display:block'>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(17);'><img src='/i/map/level.gif' id='zoomlev17'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(16);'><img src='/i/map/level.gif' id='zoomlev16'/></a></div>" +
                "<div class='levelStreet'><a href='javascript:void(0);' onclick='map.SetZoomLevel(15);'><img src='/i/map/street.gif'  id='zoomlev15'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(14);'><img src='/i/map/level.gif' id='zoomlev14'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(13);'><img src='/i/map/level.gif' id='zoomlev13' /></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(12);'><img src='/i/map/level.gif' id='zoomlev12' /></a></div>" +
                "<div class='levelCity'><a href='javascript:void(0);' onclick='map.SetZoomLevel(11);'><img src='/i/map/city.gif' id='zoomlev11'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(10);'><img src='/i/map/level.gif' id='zoomlev10' /></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(9);'><img src='/i/map/level.gif' id='zoomlev9' /></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(8);'><img src='/i/map/level.gif' id='zoomlev8' /></a></div>" +
                "<div class='levelRegion'><a href='javascript:void(0);' onclick='map.SetZoomLevel(7);'><img src='/i/map/region.gif' id='zoomlev7'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(6);'><img src='/i/map/level.gif' id='zoomlev6'/></a></div>" +
                "<div class='level' style='block'><a href='javascript:void(0);' onclick='map.SetZoomLevel(5);'><img src='/i/map/level.gif' id='zoomlev5' /></a></div>" +
            "</div>" +
            "<div id='zoomOut'><a href='javascript:void(0);' onclick='map.ZoomOut();'><img src='/i/map/zoom_out.gif' width='20' height='18' title='Zoom Out' /></a></div>";
		map.AddControl(mapNavControl);
		addShim(mapNavControl);
	}
}

function UpdateZoomImages() {
	if (map) {
		var zoomLevel = map.GetZoomLevel();
		if (zoomLevel > 17) zoomLevel = 17; //our highest zoom level on the nav control is 17,

		var OnSet = false;
		try {
			for (i = 0; i < 20; i++) {
				var img = document.getElementById("zoomlev" + i);
				if (img) {
					var imgSrc = img.src;
					imgSrc = imgSrc.replace("_on.", ".");
					if (zoomLevel <= i && OnSet == false) {
						imgSrc = imgSrc.replace(".gif", "_on.gif");
						OnSet = true;
					}
					img.src = imgSrc;
				}
			}
		} catch (e) { }
	}
}
//EVENT HANDLERS-------------------------------------------------
function EndPanHandler(e) {
	if (map) {
		if (poiListVisible) {//&& map.GetMapStyle() != VEMapStyle.Birdseye && map.GetMapStyle() != VEMapStyle.BirdseyeHybrid) {
			UpdatePOIList();
		}
	}
}
function ShowInfoBoxOfLastSelected() {
	if (map) {
		if (selectedPOI != "") {
			ShowShapeInfobox(selectedPOI, poiLayer);
			selectedPOI = "";
		}
	}
}

function EndZoomHandler(e) {
	UpdateCluster();
	UpdateZoomImages();
	//ShowInfoBoxOfLastSelected();
	//temporary fix to show infobox in cases when zoomlevel changes by one level out,
	//for example, from 14 to 13, infobox doesn't pop up...have to figure out why
	setTimeout(ShowInfoBoxOfLastSelected, 0);
}

//If there is a bird's eye view show the rotate button and hide zoom levels
function onChangeView(e) {
	if (map) {
		var beLink = document.getElementById('birdseyeLink');
		var beRotate = document.getElementById('rotateLink');
		var levelControls = document.getElementById('levelControls');
		var mapstyle = map.GetMapStyle();
		if (mapstyle == VEMapStyle.Birdseye) {
			beRotate.style.display = "block";
			levelControls.style.display = "none";
			map.SetShapesAccuracy(VEShapeAccuracy.Pushpin);
			HidePOI();
		}
		else {
			beRotate.style.display = "none";
			levelControls.style.display = "block";
			map.SetShapesAccuracy(VEShapeAccuracy.None);
			ShowPOI();
		}

		if (map.IsBirdseyeAvailable()) {
			if (!(mapstyle == VEMapStyle.Birdseye)) {
				//Only show the Birdseye UI button if we get down to street level
				if (map.GetZoomLevel() > 15) {
					beLink.style.display = "block";
					document.getElementById('birdseye').style.marginBottom = "-17px";
				}
				else {
					beLink.style.display = "none";
					document.getElementById('birdseye').style.marginBottom = "";
				}
			}
			else {
				beLink.style.display = "block";
			}
		}
		else {
			beLink.style.display = "none";
		}
		ResetUIControls();
	}
}

//CLUSTER--------------------------------------------------------
function UpdateCluster() {
	if (map) {
		if (map.GetZoomLevel() < 15) {
			if (propLayer) SetUpCluster(propLayer, GetM6ClusterIcon(), "Multiple locations in this area");
		} else {
			if (propLayer) propLayer.SetClusteringConfiguration(VEClusteringType.None);
		}
	}
}
function SetUpCluster(layer, clusterIcon, clusterTitle) {
	if (layer) {
		var options = new VEClusteringOptions();
		options.Icon = clusterIcon;

		layer.SetClusteringConfiguration(VEClusteringType.Grid, options);
		var clusterShapes = new Array();
		var s = "";
		var c;
		var desc = "";
		var cluster = null;
		var brandClass;
		var title;
		var tempArray;
		var left = -45;
		var top = -56;

		clusterIcons = layer._clusterLayer.Annotations;
		clusterShapes = layer.GetClusteredShapes(VEClusteringType.Grid);
		var icon;
		for (var i = 0; i < clusterIcons.length; i++) {
			cluster = clusterShapes[i].Shapes;
			icon = clusterIcons[i];
			icon.Description = "";
			icon.Notes = "";
			icon.Title = "";

			desc = "";
			if (cluster.length > maxClusterItems) {
				icon.SetDescription(GetGenericHoverInfo("Too many locations to display", "<a href='javascript:void(0);' onclick='map.ZoomIn();'>Please zoom in</a>", left, top));
			}
			else {
				for (var j = 0; j < cluster.length; j++) {
					//remove span tags
					//cluster[j].Title.match("^<span style='display:none;'>(.*)<\/span>");
					//tempArray = RegExp.$1.split("-");
					tempArray = cluster[j].Title.split("-");
					brandClass = "m6";

					if (tempArray.length > 1) {
						if (tempArray[0] == "Studio 6 ") brandClass = "s6";
						title = tempArray[1];
						for (b = 2; b < tempArray.length; b++) {
							title += "-" + tempArray[b];
						}
					}
					desc += "<div class=\"multi\"><a href=\"javascript:GoToShape('" + cluster[j].GetID() + "')\" class=\"" + brandClass + "\" title=\"" + cluster[j].Title + "\"><span>" + title + "</span></a></div>"
				}
				icon.SetDescription(GetClusterHoverInfo(clusterTitle.replace("@length", cluster.length), desc, left, top));
			}
		}
	}
}

//POI------------------------------------------------------------
function AddPOIControl() {
	if (map) {
		mapPOIControl = document.createElement("div");
		mapPOIControl.id = "mapPOIControl";
		mapPOIControl.style.position = "relative";
		var left = 335; //map.GetLeft() + 335;
		var top = 3;
		//Gecko engine is a couple pixels off when rendering controls on the map
		if (Web.Browser.isMozilla || (Gimme.Browser.isIE && GetIEVersion() >= 8) || Gimme.Browser.isKHTML) {
			top += 2;
			left += 2;
		}
		mapPOIControl.style.top = top + "px";
		mapPOIControl.style.left = left + "px";
		mapPOIControl.innerHTML = "<div class='mapPOI'><a id='poiImg' style='background-position:0px 0px' onclick='togglePOI();' href='javascript:void(0);' title='Show Points of Interest'></a></div>";
		map.AddControl(mapPOIControl);
		addShim(mapPOIControl);
	}
}

//Show and hide points of interest list
function togglePOI() {
	if (!poiListVisible)
		ShowPOIList();
	else
		HidePOIList();
}

function HidePOI() {
	if (map) {
		if (mapPOIControl) map.HideControl(mapPOIControl);
		if (mapPOIListControl) map.HideControl(mapPOIListControl);

	}
}
function ShowPOI() {
	if (map) {
		if (mapPOIControl) map.ShowControl(mapPOIControl);
		if (mapPOIListControl) {
			if (poiListVisible) map.ShowControl(mapPOIListControl);
		}
	}
}

function ShowPOIList() {
	if (map) {
		map.HideInfoBox();
		poiImage = document.getElementById("poiImg");
		if (poiImage) {
			poiImage.style.backgroundPosition = "0px -22px";
			poiImage.setAttribute("title", "Hide Points of Interest");
		}
		map.ShowControl(mapPOIListControl);
		var center = GetCenterLatLong();
		if (HasCenterChanged(center)) {
			ShowPOILoadingImage();
			UpdatePOIList();
		}
		poiListVisible = true;
	}
}
function HasCenterChanged(currentCenter) {
	if (currentCenter != null && lastCenter != null)
		return (currentCenter.Latitude != lastCenter.Latitude && currentCenter.Longitude != lastCenter.Longitude)
	else
		return true;
}

function ShowPOILoadingImage() {
	SetPOIMessage("<div class='loading'><img src='/i/map/loading.gif' /></div>");
}
function SetPOIMessage(msg) {
	SetPOIListHTML(GetPOIHTMLTable(GetPOIHTMLRow(msg)));
}

function HidePOIList() {
	if (map) {
		poiImage = document.getElementById("poiImg");
		if (poiImage) {
			poiImage.style.backgroundPosition = "0px 0px";
			poiImage.setAttribute("title", "Show Points of Interest");
		}
		map.HideControl(mapPOIListControl);
		poiListVisible = false;
		lastCenter = GetCenterLatLong();
	}
}

function UpdatePOIIcon(id, name, entitytype, lat, lng) {
	if (map) {
		var ckbox = document.getElementById("ck_" + id);
		if (ckbox) {
			if (ckbox.checked == true) {
				AddPOIToMap(id, name, entitytype, lat, lng, true, true);
			} else {
				selectedPOIArray = RemoveFromArray(id, selectedPOIArray, 0);
				DeleteShape("poi_" + id);
			}
		}
	}
}
function AddPOICenter(id, name, entitytype, lat, lng) {
	if (map) {
		AddPOIToMap(id, name, entitytype, lat, lng, false, false);
	}
}
function AddPOIToMap(id, name, entitytype, lat, lng, zoom, showInfo) {
	if (map) {
		var shape = GetShapeByID("poi_" + id, poiLayer);
		if (shape) {
			map.ShowInfoBox(shape, new VELatLong(lat, lng), new VEPixel(10, 0));
		} else {
			try {
				map.HideInfoBox();
				var latlng = new VELatLong(lat, lng);
				var pin = new VEShape(VEShapeType.Pushpin, latlng);
				pin.SetCustomIcon(GetPOIIcon());
				pin.SetDescription(GetPOIHoverInfo(name, entitytype));
				pin.ID = "poi_" + id;
				poiLayer.AddShape(pin);
				AddToArray([id, unescape(name), unescape(entitytype), lat, lng], selectedPOIArray);
				var zoomLevelChanged = false;
				selectedPOI = pin.ID;
				if (zoom) {
					if (zoom == true) zoomLevelChanged = ZoomWithoutPanning(latlng);
				}
				if (showInfo == true) map.ShowInfoBox(pin, latlng, new VEPixel(10, 0));
				if (!zoomLevelChanged) selectedPOI = ""; //clear when the zoom level didn't change...this variable is used to show the infobox on end of zoom
			} catch (e) {

			}
		}
	}
}

function ZoomWithoutPanning(latlng) {
	if (map) {
		var center = GetCenterLatLong();
		if (!IsPointInView(latlng)) {
			var latDifference = Math.abs(center.Latitude - latlng.Latitude);
			var lngDifference = Math.abs(center.Longitude - latlng.Longitude);
			var tlLatLng = new VELatLong(center.Latitude - latDifference, center.Longitude - lngDifference);
			var blLatLng = new VELatLong(center.Latitude + latDifference, center.Longitude - lngDifference);
			var trLatLng = new VELatLong(center.Latitude - latDifference, center.Longitude + lngDifference);
			var brLatLng = new VELatLong(center.Latitude + latDifference, center.Longitude + lngDifference);
			map.SetMapView([tlLatLng, blLatLng, trLatLng, brLatLng]);
			return true;
		} else return false;
	}
}
function IsPointInView(latlng) {
	if (map) {
		var view = map.GetMapView();
		if (latlng.Latitude < view.TopLeftLatLong.Latitude && latlng.Latitude > view.BottomRightLatLong.Latitude && latlng.Longitude > view.TopLeftLatLong.Longitude && latlng.Longitude < view.BottomRightLatLong.Longitude)
			return true;
		else
			return false;
	}
	else
		return true;
}

function UpdatePOIList() {
	if (map) {
		var center = GetCenterLatLong();
		//var radius = GetMapRadius();
		//if (radius > 25) radius = 25;
		radius = 25;
		Motel6.SearchSvc.GetNearbyPOI_SQL(center.Latitude, center.Longitude, radius, UpdatePOI_Success, UpdatePOI_Fail, "XmlDocument")
		//Motel6.SearchSvc.GetNearbyPOI_SQL_Arr(center.Latitude, center.Longitude, radius, UpdatePOI_Success, UpdatePOI_Fail, "String")
	}
}

function GetSelectedPOIArrayForEntityType(entitytype) {
	var st = new Date();
	var newArray = new Array();
	for (var i = 0; i < selectedPOIArray.length; i++) {
		if (selectedPOIArray[i][2] == entitytype) {
			newArray.push(selectedPOIArray[i]);
		}
	}
	newArray.sort();
	return newArray;
}

function UpdatePOI_Success(result) {
	SetPOIListHTML(GetPOIListHTML(result));
}
function SetPOIListHTML(html) {
	if (map) {
		if (mapPOIListControl == undefined) AddPoiListControl();
		mapPOIListControl.innerHTML = html;
	}
}
function AddPoiListControl() {
	if (map) {
		mapPOIListControl = document.createElement("div");
		mapPOIListControl.id = "mapPOIListControl";
		mapPOIListControl.style.position = "relative";
		mapPOIListControl.style.zIndex = "500";

		//Match the POI List height to the map height
		if (document.getElementById(mapId).style.height == "370px") {
			mapPOIListControl.style.height = "340px";
		} else {
			mapPOIListControl.style.height = "240px";
		}

		//Gecko engine is a couple pixels off when rendering controls on the map
		if (Web.Browser.isMozilla || (Gimme.Browser.isIE && GetIEVersion() >= 8) || Gimme.Browser.isKHTML) {
			mapPOIListControl.style.top = "28px";
			mapPOIListControl.style.left = "337px";
		}
		else {
			mapPOIListControl.style.top = "26px";
			mapPOIListControl.style.left = "335px";
		}
		map.AddControl(mapPOIListControl);
		addShim(mapPOIListControl);

	}
}
function GetTimeSpan(startTime, endTime) {
	return Math.floor((endTime.getTime() - startTime.getTime()) / 100);
}
function GetPOIListHTML(result) {
	//var startTime = new Date();
	var xmldoc = result;
	var entitygroup = xmldoc.getElementsByTagName("EG")
	var pois;
	var display;
	var htmlString = "";
	var htmlArray = new Array();

	var id; var name; var entitytype; var lat; var lng; var catName;
	var numPOICat = 0;

	for (var i = 0; i < entitygroup.length; i++) {
		pois = entitygroup[i].getElementsByTagName("p");
		catName = entitygroup[i].getAttribute("n");
		display = "";

		if (!IsInArray(catName, selectedCatArray)) display = "none";
		//combine selectedPOI with current poi category list
		var selPOIArr = GetSelectedPOIArrayForEntityType(catName);
		var catPOIArr = new Array();
		catPOIArr = CombinePOIArrays(selPOIArr, pois, catName);

		if (catPOIArr.length > 0) {
			numPOICat++;
			htmlArray.push("<tr><th colspan='2'><a href='javascript:void(0);' onclick='switchPOICat(\"cat" + catName + "\");'>" + catName + "</a> <span class='catCount'>(" + catPOIArr.length + ")</span></th></tr>");

			for (j = 0; j < catPOIArr.length; j++) {
				id = catPOIArr[j][0];
				name = catPOIArr[j][1];
				entitytype = catPOIArr[j][2];
				lat = catPOIArr[j][3];
				lng = catPOIArr[j][4];
				isChecked = catPOIArr[j][5];
				htmlArray.push("<tr class='cat" + catName + "' style='display:" + display + "'>" +
   				"<td class='cb'><input type='checkbox' id='ck_" + id + "' name='ck_" + id + "' value='checkbox' " + isChecked + " onclick='UpdatePOIIcon(\"" + id + "\", \"" + escape(name) + "\", \"" + escape(entitytype) + "\", " + lat + ", " + lng + ");' /></td>" +
   				"<td>" + name + "</td></tr>");

			}
		}
	}

	if (numPOICat == 0)
		htmlString = GetPOIHTMLRow("No points of interest.");
	else
		htmlString = htmlArray.join("");

	htmlString = GetPOIHTMLTable(htmlString);

	return htmlString;
}

function GetPOIHTMLRow(msg) {
	var htmlString = "<tr><td colspan='2'>" + msg + "</td></tr>";
	return htmlString;
}
function GetPOIHTMLTable(rows) {
	var htmlString = "<b class='cPnl'><b class='cPnl1'><b></b></b><b class='cPnl2'><b></b></b><b class='cPnl3'></b><b class='cPnl4'></b><b class='cPnl5'></b></b>" +
     	"<div class='cPnlfg'>" +
     	  "<table border='0' cellspacing='0' cellpadding='0' class='mapPOITbl' id='poiDiv'>";
	htmlString += rows;
	htmlString += "</table></div><b class='cPnl'><b class='cPnl5'></b><b class='cPnl4'></b><b class='cPnl3'></b><b class='cPnl2'> <b></b></b><b class='cPnl1'><b></b></b></b>";
	return htmlString;
}

function CombinePOIArrays(selectedArray, currentXMLNodeArray, catName) {
	var combinedArray = new Array();
	var catArray = new Array();
	var isChecked = "";
	var selIndex = 0;

	if (selectedArray == undefined) selectedArray = new Array();
	if (currentXMLNodeArray == undefined) currentXMLNodeArray = new Array();
	//create new array from nodelist
	for (var c = 0; c < currentXMLNodeArray.length; c++) {
		catArray.push([currentXMLNodeArray[c].getAttribute("id"), currentXMLNodeArray[c].getAttribute("n"), catName, currentXMLNodeArray[c].getAttribute("lat"), currentXMLNodeArray[c].getAttribute("lng")]);
	}

	selectedArray.sort(SortByID);
	//catArray.sort(SortByID);

	for (var c = 0; c < catArray.length; c++) {
		isChecked = "";
		id = parseInt(catArray[c][0]);

		for (var s = selIndex; s < selectedArray.length; s++) {
			if (parseInt(selectedArray[s][0]) < id) {
				selectedArray[s].push("checked");
				combinedArray.push(selectedArray[s]);
				selIndex++;
			}
			else if (parseInt(selectedArray[s][0]) == id) {
				isChecked = "checked";
				catArray[c][1] = selectedArray[s][1]
				selIndex++;
			}
			else
				break;
		}
		catArray[c].push(isChecked);
		combinedArray.push(catArray[c]);
	}
	//add remaining selected
	for (var s = selIndex; s < selectedArray.length; s++) {
		selectedArray[s].push("checked");
		combinedArray.push(selectedArray[s]);
	}

	combinedArray.sort(SortByName);
	return combinedArray;
}

function switchPOICat(classRow) {
	if (mapPOIListControl) {
		el = mapPOIListControl.getElementsByTagName("tr");
		var cat;

		for (var i = 0; i < el.length; i++) {
			if (el[i].className == classRow) {
				cat = classRow.substr(3); //catname always start with "cat"...remove this prefix to get the cat name
				if (el[i].style.display != 'none') {
					el[i].style.display = 'none';
					selectedCatArray = RemoveFromArray(cat, selectedCatArray)
				}
				else {
					el[i].style.display = '';
					AddToArray(cat, selectedCatArray)
				}
			}
		}
	}
}
//MISC MAP-------------------------------------------
function addShim(el) {
	var shim = document.createElement("iframe");
	shim.className = "shim";
	shim.frameBorder = "0";
	shim.style.position = "relative";
	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 setSelectedMap(obj) {
	mapSelected = obj;
	var mapLinks = new Array();
	mapLinks = document.getElementsByName("mapLinkType");
	for (i = 0; i < mapLinks.length; i++) {
		mapLinks[i].style.backgroundPosition = '0px -17px';
	}
	obj.style.backgroundPosition = '0px 0px';
}

function GetTopBrowserOffset() {
	var offset = 0;
	if (navigator.vendor == "Camino")
		offset = -9;
	else if (Gimme.Browser.isGecko)
		offset = -6;
	else if (Gimme.Browser.isOpera)
		offset = 2;
	else if (Gimme.Browser.isKHTML)
		offset = -6;
	else if (Web.Browser.isMozilla)
		offset = 2;
	else if (Gimme.Browser.isIE) {
		if (GetIEVersion() >= 8)
			offset = -6;
		else
			offset = 0;
	}
	else
		offset = 0;
	return offset;
	//-6;
}

function GetLeftBrowserOffset() {
	var offset = 0;
	if (navigator.vendor == "Camino")
		offset = 0;
	else if (Gimme.Browser.isGecko)
		offset = 2;
	else if (Gimme.Browser.isOpera)
		offset = 0;
	else if (Gimme.Browser.isKHTML)
		offset = 2;
	else if (Web.Browser.isMozilla)
		offset = 2;
	else if (Gimme.Browser.isIE) {
		if (GetIEVersion() >= 8)
			offset = 2;
		else
			offset = 0;
	}
	else
		offset = 0;
	return offset;
}

function MakeMapBigger() {
	if (map) {
		var mapBiggerLink = document.getElementById("mapBiggerLink");
		var mapSmallerLink = document.getElementById("mapSmallerLink");
		lastCenter = GetCenterLatLong();
		var m6Map = document.getElementById("m6Map");
		mapSmallerLink.style.display = "inline";
		mapBiggerLink.style.display = "none";
		map.Resize(523, 370);
		if (mapPOIListControl) {
			mapPOIListControl.style.height = "340px";
		}
	}

}
function MakeMapSmaller() {
	if (map) {
		var mapBiggerLink = document.getElementById("mapBiggerLink");
		var mapSmallerLink = document.getElementById("mapSmallerLink");
		var m6Map = document.getElementById("m6Map");
		lastCenter = GetCenterLatLong();
		mapSmallerLink.style.display = "none";
		mapBiggerLink.style.display = "inline";
		map.Resize(523, 270);
		m6Map.style.height = "270px";
		if (mapPOIListControl) {
			mapPOIListControl.style.height = "240px";
		}
		map.PanToLatLong(lastCenter);

	}
}

//realigns controls when window is resized
function ResetUIControls() {
	if (map) {
		var left = map.GetLeft(); //+ GetLeftBrowserOffset();
		var top = map.GetTop();

		if (Web.Browser.isMozilla || (Gimme.Browser.isIE && GetIEVersion() >= 8) || Gimme.Browser.isKHTML) {
			left += 2;
			top += 2;
		}
		if (mapPOIListControl) {
			mapPOIListControl.style.left = left + 335 + "px";
			mapPOIListControl.style.top = top + 26 + "px";
		}
		if (mapPOIControl) {
			mapPOIControl.style.left = left + 335 + "px";
			mapPOIControl.style.top = top + 3 + "px";
		}
		if (mapNavControl) {
			mapNavControl.style.left = left + "px";
			mapNavControl.style.top = top + "px";
		}

		
		
	}
}

function GoToShape(shapeID) {
	if (map) {
		var shape = map.GetShapeByID(shapeID);
		if (shape) {
			var pts = shape.GetPoints();
			var zoomLevel = map.GetZoomLevel();
			if (zoomLevel < 15) zoomLevel = 15;
			var latlng = new VELatLong(pts[0].Latitude, pts[0].Longitude);
			map.SetCenterAndZoom(latlng, zoomLevel);
			map.ShowInfoBox(shape, latlng, new VEPixel(17, 4));
		}
	}
}

function ShowShapeInfobox(shapeID, layer) {
	if (map) {
		try {
			if (shapeID != "") {
				var shape = GetShapeByID(shapeID, layer);
				if (shape != undefined) {
					var pts = shape.GetPoints();
					if (pts != undefined) {
						var latlng = new VELatLong(pts[0].Latitude, pts[0].Longitude);
						map.ShowInfoBox(shape, latlng, new VEPixel(10, 0));
					}
				}
			}
		} catch (e) {

		}
	}
}

function GetShapeByID(id, layer) {
	var shape;
	if (layer) {
		var tmpshape;
		var count = layer.GetShapeCount();
		for (i = 0; i < count; i++) {
			tmpshape = layer.GetShapeByIndex(i);
			if (tmpshape.ID == id) {
				shape = tmpshape;
				break;
			}
		}
	}
	return shape;
}

function OnFail(error) {
	//alert("Service Error: " + error.get_message());
}
function UpdatePOI_Fail(error) {
	SetPOIMessage("Unable to load points of interest.  Please <a href='javascript:void();' onclick='ShowPOILoadingImage();UpdatePOIList();'>try again</a>.");
}

function AddToArray(values, arr) {
	if (arr) {
		if (!IsInArray(values, arr)) {
			arr.push(values);
			arr.sort();
		}
	}
}
function IsInArray(value, arr) {
	if (arr) {
		for (var a = 0; a < arr.length; a++) {
			if (value == arr[a]) {
				return true;
			}
		}
	}
	return false;
}
function RemoveFromArray(id, arr, keyIndex) {
	//alert(id + ":" + keyIndex);
	var newArray = new Array();
	if (arr) {
		for (var i = 0; i < arr.length; i++) {
			if (keyIndex != undefined) {
				if (arr[i][keyIndex] != id) newArray.push(arr[i]);
			}
			else {
				if (arr[i] != id) newArray.push(arr[i]);
			}
		}
	}
	return newArray;
}

function DeleteShape(id) {
	if (poiLayer) {
		var shape = GetShapeByID(id, poiLayer);
		if (shape) {
			map.HideInfoBox();
			poiLayer.DeleteShape(shape);
		}
	}
}

//DIRECTIONS
function ShowRoute(startLat, startLng, endLat, endLng, startLocation, endLocation) {
	if (startLat != undefined && startLng != undefined && endLat != undefined && endLng != undefined) {
		ShowFullMap(null, null, 'm6Map', 8);
		GetDirections(new Array(new VELatLong(startLat, startLng), new VELatLong(endLat, endLng)));
		AddIconToMap(startLat, startLng, "START", startLocation, GetStartingPointIcon(), -45, -40);
		AddIconToMap(endLat, endLng, "END", endLocation, GetEndingPointIcon(), -45, -40);
		map.ClearInfoBoxStyles();
		showAvailInfo = false;
	}
}

function GetDirections(locations) {
	if (map != undefined && locations != undefined) {
		var options = new VERouteOptions;

		// Otherwise what's the point?
		options.DrawRoute = true;

		// So the map doesn't change:
		//options.SetBestMapView = false;
		options.SetBestMapView = false;

		// Call this function when map route is determined:
		options.RouteCallback = ShowTurns;

		// Show as miles
		options.DistanceUnit = VERouteDistanceUnit.Mile;

		// Show the disambiguation dialog
		options.ShowDisambiguation = true;
		//use Mappoint Web Service as routing engine.  virtual earth and mappoint uses different routing engines.
		//nearby properties are based on mappoint routes.  to guarantee that the properties are along the correct
		//route, we have to set this property to true.
		options.UseMWS = true;
		map.GetDirections(locations, options);
	}
}

function ShowTurns(route) {
	if (map != undefined && route != undefined) {
		initCenter = GetCenterLatLong();
		initZoom = map.GetZoomLevel();

		var turns = "<table class=\"mapDirections\" cellspacing=\"0\" cellpadding=\"6\" border=\"0\" id=\"textDirectionsDG\" style=\"border-collapse:collapse;\">" +
	"<tr class=\"mapDirectionsH\">" +
		"<td>Step</td><td>Instruction</td><td>Distance</td>" +
	"</tr>"

		var legs = route.RouteLegs;
		var leg = null;
		var turnNum = 0;

		for (var i = 0; i < legs.length; i++) {
			leg = legs[i];  // Leg is a VERouteLeg object

			var legNum = i + 1;
			var turn = null;  // The itinerary leg
			var legDistance = null;  // The distance for this leg

			for (var j = 0; j < leg.Itinerary.Items.length; j++) {
				//if (j>0)turnNum++;
				turnNum++;
				turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object

				turns += "<tr><td class=\"mapDirectionsStep\">"

				turns += turnNum;
				map.DeleteShape(turn.Shape);
				turns += "</td>";
				turns += "<td class=\"mapDirectionsItem\">" + turn.Text + "</td>";

				legDistance = turn.Distance;

				// So we don't show 0.0 for the arrival
				if (legDistance > 0)
					turns += "<td class=\"mapDirectionsDistance\">" + legDistance.toFixed(1) + " miles</td>";
				else
					turns += "<td class=\"mapDirectionsDistance\">&nbsp;</td>";

				//if (turn.Time != null)
				//	turns += "<td class=\"mapDirectionsItem\">" + GetTime(turn.Time) + "</td>";
				//else
				//	turns += "<td class=\"mapDirectionsItem\">&nbsp;</td>"; 
				turns += "</tr>";
			}
			turns += "<tr><td colspan='3' align='right'><b>Total Distance:</b> " + leg.Distance.toFixed(1) + " miles" +
                           "<br/><b>Total Time:</b> " + GetTime(leg.Time) + "</td></tr>";


			turns += "</table>";
		}
	}
	var d = document.getElementById("directions");
	if (d) d.innerHTML = turns;
}

// time is an integer representing seconds
// returns a formatted string
function GetTime(time) {
	if (time == null) {
		return ("");
	}

	if (time > 60) {                                 // if time == 100
		var seconds = time % 60;       // seconds == 40
		var minutes = time - seconds;  // minutes == 60
		minutes = minutes / 60;    // minutes == 1


		if (minutes > 60) {                                     // if minutes == 100
			var minLeft = minutes % 60;        // minLeft    == 40
			var hours = minutes - minLeft;   // hours      == 60
			hours = hours / 60;          // hours      == 1

			return (hours + " hr(s), " + minLeft + " min(s), " + seconds + " sec(s)");
		}
		else {
			return (minutes + " min(s), " + seconds + " sec(s)");
		}
	}
	else {
		return (time + " secs");
	}
}

//Sorting functions for selected poi array
function SortByName(a, b) {
	return (a[1] == b[1] ? 0 : (a[1] < b[1]) ? -1 : 1);
}

function SortByID(a, b) {
	return (parseInt(a[0]) - parseInt(b[0]));
}


function GetCenterLatLong() {
	if (map.GetMapStyle() == VEMapStyle.Birdseye || map.GetMapStyle() == VEMapStyle.BirdseyeHybrid) {
		var birdseyeScene = map.GetBirdseyeScene();

		//Get approximate center coordinate of the map
		var x = birdseyeScene.GetWidth() / 2;
		var y = birdseyeScene.GetHeight() / 2;
		var center = birdseyeScene.PixelToLatLong(new VEPixel(x, y), map.GetZoomLevel());

		return (new _xy1).Decode(center);
	}
	else {
		return map.GetCenter();
	}
}

function GetTopLeftLatLong() {
	if (map.GetMapStyle() == VEMapStyle.Birdseye || map.GetMapStyle() == VEMapStyle.BirdseyeHybrid) {
		var birdseyeScene = map.GetBirdseyeScene();

		// Get the Lat/Long 
		var tl = birdseyeScene.PixelToLatLong(new VEPixel(0, 0), map.GetZoomLevel());

		// Convert the BirdseyeScene LatLong to a normal LatLong we can use
		return (new _xy1).Decode(tl);
	}
	else {
		var v = map.GetMapView();
		var tl = v.TopLeftLatLong;
		return tl;
	}
}

function ResetMap() {
	if (map) {
		var link = document.getElementById("resetLink")
		if (link) {
			lastCenter = GetCenterLatLong();
			map.SetCenterAndZoom(initCenter, initZoom);
			if (HasCenterChanged(initCenter) && poiListVisible == true) UpdatePOIList();
		}
	}
}

function PrintPageAfterMapHasLoaded() {
	setTimeout(function() { window.print(); }, 1000);
}