// oMap defined by map control

var gBusLocatorNetwork = new VENetwork();
var gBusLocatorTimerId = null;
var gRouteDetailsNetwork = new VENetwork();
var gStopDetailsNetwork = new VENetwork();

var gRouteManager = null;
var gVisibleVehicles = null;
var gRouteDetailWindow = null;
var gSearchEmptyText = 'Enter Stop # or Address';

function ctlMap_AfterMapLoad() {
	InitializePageVariables(); // defined in page
	gVisibleVehicles = new SmiTransitVehicleCollection();
	gRouteDetailWindow = new SmiRouteDetail(oMap);
	gRouteDetailWindow.Initialize();
	
	gRouteManager = new SmiTransitRouteManager(oMap);

	// stupid code to extra space in a bottom caused by window.ero default position
	var pin = new VEPushpin("Null", new VELatLong(0, 0));
	oMap.AddPushpin(pin);
	oMap.DeletePushpin(pin.ID);
	pin = null;
	window.ero.dockToElement(document.body);
	
	oMap.AttachEvent("oncontextmenu", MapPopupMenu);
	oMap.AttachEvent("onclick", HidePopupMenu);
	
	window.attachEvent("onunload", OnPageUnload);
	window.attachEvent("onresize", OnWindowResize);
	
	BusLocatorStart();

	helpBtn = new SmiHelpBtn(oMap);
	helpBtn.Initialize();
	
	legendBtn = new SmiLegendBtn(oMap);
	legendBtn.Initialize();
	
	var elmSearch = GetPageElementById('ctlSearch');
	if(elmSearch.value == "") {
		elmSearch.value = gSearchEmptyText;
	}
	if(elmSearch.value != gSearchEmptyText) {
		GetPageElementById("ctlMap").style.visibility = "hidden";
		GetPageElementById('ctlGo').click();
	}
	window.setTimeout('GetPageElementById("ctlMap").style.visibility = "visible";', 3000);

	OnWindowResize();
}

function BusLocatorStart() {
	if(gBusLocatorTimerId != null)
		window.clearTimeout(gBusLocatorTimerId);

	var params = gRouteManager.GetRoutesQueryString();
	if(params != "RouteIDs=") {
		gBusLocatorNetwork.ServiceUrl="BusLocator.axd?" + params;
		gBusLocatorNetwork.BeginInvoke(null, null, BusLocatorEnd);
	}
}


function BusLocatorEnd() {
	gBusLocatorTimerId = window.setTimeout(BusLocatorStart, 3000);
}

function OnPageUnload() {
	window.detachEvent("onunload", OnPageUnload);
	window.detachEvent("onresize", OnWindowResize);
	
	oMap.DetachEvent("oncontextmenu", MapPopupMenu);
	oMap.DetachEvent("onclick", HidePopupMenu);
	
	oMap = null;
}

var gResizeTimerID = null;
function OnWindowResize() {
	if(gResizeTimerID != null) {
		window.clearTimeout(gResizeTimerID);
		gResizeTimerID = null;
	}
	gResizeTimerID = window.setTimeout(DoResize, 100);
}

function DoResize() {
	var elm = window.document.getElementsByTagName("html")[0];
	var elmMap = GetPageElementById("ctlMap");
	var h = elm.clientHeight - 28 - elmMap.offsetTop;
	var w = elm.clientWidth - 28 - elmMap.offsetLeft;
	if(h < 200)
		h = 200;
	if(w < 200)
		w = 200;
	if(oMap != null) {
		oMap.VeMap.Resize(w, h);
	}
	else {
		elm = GetPageElementById("ctlMap");
		elm.style.width = w;
		elm.style.height = h;
	}
	elm = null;
	
	elm = GetPageElementById("ctlRoutesBody");
	h += elmMap.offsetTop - (elm.parentElement.offsetTop) - 10;
	//h -= 180;
	elm.style.height = h + "px";

	gResizeTimerID = null;
}

var _contextPushpin = null;
var _contextPushpinInterval = null;
function ShowContextPin(ll) {
	if(_contextPushpin != null) {
		oMap.DeletePushpin(_contextPushpin.ID);
		_contextPushpin = null;
	}
	
	_contextPushpin = new VEPushpin("ContextPushpin", ll, "images/context.gif", null, null, "ContextPin");
	oMap.AddPushpin(_contextPushpin);
}

function MapPopupMenu(e) {
	ShowContextPin(e.LatLong);
	
	var msg = "";
	msg += "<h2>Nearest Routes</h2>";
	msg += "<div id='StopPopupContent' class='StopPopupContent' width='100%'><div class='StopPopupLoading'>Loading...</div></div>";

	oMap.CalloutWindow.ShowByPin(msg, _contextPushpin.ID);
	

	var sUrl = "RouteArrivals.axd?ll=" + e.LatLong;
	sUrl += "&RouteIDs=";
	var routes = gRouteManager.GetRoutes();
	for(r in routes) {
			sUrl +=  "," + r;
	}
	routes = null;

	gStopDetailsNetwork.ServiceUrl = sUrl;
	gStopDetailsNetwork.BeginInvoke(null, null, null);	
	
	if(_contextPushpinInterval != null) {
		window.clearInterval(_contextPushpinInterval);
		_contextPushpinInterval = null;
	}
	_contextPushpinInterval = window.setInterval(CheckCalloutWindowStatus, 200);

	function CheckCalloutWindowStatus() {
		if(oMap.CalloutWindow == null || !oMap.CalloutWindow.IsVisible()) {
			if(_contextPushpin != null) {
				oMap.DeletePushpin(_contextPushpin.ID);
				_contextPushpin = null;
			}
			if(_contextPushpinInterval != null) {
				window.clearInterval(_contextPushpinInterval);
				_contextPushpinInterval = null;
			}
		}
	}
}

function HidePopupMenu(e) {
	oMap.CalloutWindow.Hide();
}

var gPreviousVehicles = new Object();
function PlotBusLocations(locations) {
	var currentVehicles = new Object();
	for(var i = 0; i < locations.length; i++) {
		var l = locations[i];
		if(!gVisibleVehicles.Contains(l.ID)) {
			gVisibleVehicles.Add(new SmiTransitVehicle(l, oMap));
		} else {
			var vehicle = gVisibleVehicles.Get(l.ID);
			gVisibleVehicles.Get(l.ID).Update(l);
		}
		gPreviousVehicles[l.ID] = true;
		currentVehicles[l.ID] = true;
	}
	
	// delete old buses from map	
	for(var vID in gPreviousVehicles) {
		if(currentVehicles[vID] == "undefined" || currentVehicles[vID] == null) {
			delete gPreviousVehicles[vID];
			gVisibleVehicles.Delete(vID);
		}
	}
	
	currentVehicles = null;
}

function UpdateStopInfo(text) {
	var elm = GetPageElementById("StopPopupContent");
	if(elm != null) {
		elm.innerHTML = text;
	}
}

var route2Element = null;
function EnsureRouteIndex() {
	if(route2Element == null) {
		route2Element = new Object();
		var arrayOfCheckBoxes = GetPageElementById("ctlRoutes").getElementsByTagName("input");
		for(var i=0;i<arrayOfCheckBoxes.length;i++) {
			route2Element[arrayOfCheckBoxes[i].parentNode.attributes["route"].value] = arrayOfCheckBoxes[i];
		}
	}
}
function RouteChecked(routeID, fromPopup){
	if(fromPopup == null || fromPopup == "undefined")
		fromPopup = false;
		
	EnsureRouteIndex();
	//Add code to handle your event here.
	if(route2Element[routeID].checked) {
		gRouteManager.AllowZoom = !fromPopup;
		gRouteDetailsNetwork.ServiceUrl = "RouteDetails.axd?RouteID=" + routeID;
		gRouteDetailsNetwork.BeginInvoke(null, null, null);
	} else {
		gRouteManager.Delete(routeID);
	}
	
	n = null;
	BusLocatorStart();
}

function ToggleRoute(routeID, fromPopup) {
	if(fromPopup == null || fromPopup == "undefined")
		fromPopup = true;

	EnsureRouteIndex();
	route2Element[routeID].checked = !route2Element[routeID].checked;
	RouteChecked(routeID, fromPopup);
}

SmiTransitRoute = function(id, name, color, points) {
	this.ID = id;
	this.Name = name;
	this.Color = color;
	this.Waypoints = points;
	
	this.GetVEColor = function() {
		return new VEColor(
				parseInt(this.Color.substring(0,2), 16), 
				parseInt(this.Color.substring(2,4), 16), 
				parseInt(this.Color.substring(4,6), 16), 
				0.80);
	}
	
	
	this.GetLatLngPointArray = function() {
		var ary = new Array();
		for(var i = 0; i < this.Waypoints.length; i++) {
			ary.push(this.Waypoints[i].LatLng);
		}
		return ary;
	}
}

SmiTransitWaypoint = function(id, name, lat, lng, type) {
	this.ID = id;
	this.Name = name;
	this.LatLng = new VELatLong(lat, lng);
	this.Type = type;
}

SmiTransitVehicleLocation = function(id, lat, lng, routeID, bearing) {
	this.ID = id;
	this.LatLng = new VELatLong(lat, lng);
	this.RouteID = routeID;
	this.Bearing = bearing;
        var bearing = Math.round(bearing / 10) * 10; // convert to a number between 0-360 in 10 degree increments
	if (360 == bearing) {
	  bearing = 0;
	}
        var tmp = "00" + bearing.toString(); // 000,0010,0020,...,00350
	this.Imgsrc = "Images/bus" + tmp.substr(tmp.length - 3,3) + ".gif"; // image names in form bus000.gif, bus010.gif, ..., bus350.gif 
}


SmiTransitRouteManager = function(map) {
	var _map = map
	var _routes = new Object();
	var _stops = new Object();
	//var _colorHelper = new SmiTransitRouteColorHelper();
	
	this.AllowZoom = true;

	this.Add = function(route) {
		if(_routes[route.ID] != "undefined" && _routes[route.ID] != null)
			return;
			
		//_colorHelper.Add(route);
		
		var llAry = route.GetLatLngPointArray();
		if(llAry.length > 0) {
			var poly = new VEPolyline(route.ID, llAry);
			poly.SetWidth(3);
			poly.SetColor(route.GetVEColor());
			oMap.VeMap.AddPolyline(poly);
			
			if(this.AllowZoom)
				oMap.SetMapView(llAry)

			for(var i = 0; i < route.Waypoints.length; i++) {
				var w = route.Waypoints[i];
				if(w.Type == 1) {
					var stop = null;
					if(_stops[w.ID] == null || _stops[w.ID] == "undefined") {
						stop = new SmiTransitStop(w, _map);
						_stops[w.ID] = stop;
						stop.Display();
					} else {
						stop = _stops[w.ID];
					}
					stop.AddRoute(route);
				}
			}

			_routes[route.ID] = route;
		}
	}

	this.Delete = function(routeId) {
		var route = _routes[routeId];
		if(route == null || route == "undefined")
			return;
			
		oMap.VeMap.DeletePolyline(routeId);
		//_colorHelper.Delete(routeId);
		
		for(var i = 0; i < route.Waypoints.length; i++) {
			var w = route.Waypoints[i];
			if(w.Type == 1) {
				if(_stops[w.ID] != null && _stops[w.ID] != "undefined") {
					var stop = _stops[w.ID];
					stop.DeleteRoute(routeId);
					if(stop.GetRouteCount() == 0) {
						stop.Dispose();
						delete _stops[w.ID];
					}
				}
			}
		}
		
		delete _routes[routeId];
	}
	
	this.GetRouteByID = function(id) {
		return _routes[id];
	}

	this.GetRoutes = function() {
		return _routes;
	}
	
	this.GetRoutesQueryString = function() {
		var qs = "&RouteIDs=";
		for(r in _routes) {
			qs +=  "," + r;
		}
		return qs;
	}

}
var stopPopupTimeout = null;
SmiTransitStop = function(waypoint, map) {
	var _waypoint = waypoint;
	var _map = map
	var _pinID = "Stop_" + _waypoint.ID;
	var _pin = null;
	var _routes = new Object();
	var _routeCount = 0;
	
	this.ID = _waypoint.ID;
	
	this.Display = function() {
		_pin = new VEPushpin(_pinID, _waypoint.LatLng,  "Images/Stop.gif", null, null, "BusStopPin");
		_pin.onmouseover = MouseOver;
		_pin.onmouseout = MouseOut;
		_map.AddPushpin(_pin);
	}
	
	this.AddRoute = function(r) {
		if(_routes[r.ID] == null || _routes[r.ID] == "undefined") {
			_routes[r.ID] = r;
			_routeCount++;
		}
	}

	this.DeleteRoute = function(rId) {
		if(_routes[rId] != null && _routes[rId] != "undefined") {
			delete _routes[rId];
			_routeCount--;
		}
	}
	
	this.GetRouteCount = function() {
		return _routeCount;
	}
	
	this.Dispose = function() {
		_map.DeletePushpin(_pinID);
		for(var id in _routes) {
			delete _routes[id];
		}
		_routes = null;
		_waypoint = null;
		_map = null;
		_pinID = null;
		_pin = null;
	}
	
	MouseOver = function() {
		var sUrl = "RouteArrivals.axd?WaypointID=" + _waypoint.ID;
		sUrl += gRouteManager.GetRoutesQueryString();
		var msg = "";
		msg += "<h2>" + _waypoint.Name + "</h2>";
		//msg += "<div class='StopPopupLoading'>Loading...</div>";
		//msg += "<iframe  class='StopContent' frameBorder='0' marginHeight='5' marginWidth='5' allowTransparency='true' width='245px' height='" + (cnt*100 - 10) + "px' src='" + sUrl + "'></iframe>";
		msg += "<div id='StopPopupContent' class='StopPopupContent' width='100%'><div class='StopPopupLoading'>Loading...</div></div>";

		MouseOut();
		
		//GetRouteArrivals(sUrl);
		stopPopupTimeout = window.setTimeout("GetRouteArrivals('" + sUrl + "', \"" + msg + "\", '" + _pinID + "')", 200);
	}
	
	GetRouteArrivals = function(sUrl, msg, _pinID) {
		oMap.CalloutWindow.ShowByPin(msg, _pinID);

		gStopDetailsNetwork.ServiceUrl = sUrl;
		gStopDetailsNetwork.BeginInvoke(null, null, null);
	}

	MouseOut = function() {
		oMap.CalloutWindow.Hide();
			
		if(stopPopupTimeout != null) {
			window.clearTimeout(stopPopupTimeout);
			stopPopupTimeout = null;
		}
	}
}


SmiTransitVehicle = function(vehicleLocation, map) {
	var _location = vehicleLocation;
	var _pinID = "Vehicle_" + _location.ID;
	var _pin = null;
	var _map = map
	this.ID = _location.ID;

	var _mouseOver = function() {
		var msg = "";
		msg += "<h2>" + gRouteManager.GetRouteByID(_location.RouteID).Name + "</h2>";
		msg += "<br/>";
		//msg += "<div>Driver: " + _location.Driver + "</div>";
		//msg += "<div>Heading: " + _location.Heading + "</div>";
		//msg += "<a href='javascript: gRouteDetailWindow.ShowByVehicleID(\"" + _location.RouteName + "\", " + _location.RouteID + ", " + _location.ID + "); '>View All Details</div>";
		_map.CalloutWindow.ShowByPin(msg, _pinID);
		gRouteDetailWindow.Hide();
	}

	var _mouseOut = function() {
		_map.CalloutWindow.Hide();
	}
	
	this.Display = function() {
		_pin = new VEPushpin(_pinID, _location.LatLng,  _location.Imgsrc, null, null, "BusPin");
		_pin.onmouseover = _mouseOver;
		_pin.onmouseout = _mouseOut;
		_map.AddPushpin(_pin);
		
		document.getElementById(_pinID).style.zIndex = 10000;
	}
	
	this.Update = function(newLocation) {
		_location = newLocation;
		_map.DeletePushpin(_pinID);
		_pin = null;
		_pin = new VEPushpin(_pinID, _location.LatLng,  _location.Imgsrc, null, null, "BusPin");
		_pin.onmouseover = _mouseOver;
		_pin.onmouseout = _mouseOut;
		_map.AddPushpin(_pin);
		document.getElementById(_pinID).style.zIndex = 10000;
	}
	
	this.Dispose = function() {
		_map.DeletePushpin(_pinID);
		_location = null;
		_pinID = null;
		_pin = null;
	}

}

SmiTransitVehicleCollection = function() {
	var _vehicles = new Object();
	
	this.Add = function(transitVehicle) {
		if(this.Contains(transitVehicle.ID))
			throw "Vehicle already displayed, use update method to change its location";
		
		_vehicles[transitVehicle.ID] = transitVehicle;
		transitVehicle.Display();
	}

	this.Get = function(vehicleID) {
		return _vehicles[vehicleID];
	}

	this.Contains = function(vehicleID) {
		return (_vehicles[vehicleID] != "undefined" && _vehicles[vehicleID] != null)
	}
	
	this.Delete = function(vehicleID) {
		_vehicles[vehicleID].Dispose();
		delete _vehicles[vehicleID];
	}
}

function SmiRouteDetail(map)
{
	var _panel = null;
	var _oMap = map;
	
	var _elmClose = null;
	var _elmHeader = null;
	var _elmBody = null;
	
	this.Initialize=function()
	{
		_panel = document.createElement("div");
		_panel.id =  _oMap.VeMap.ID + "_SmiRouteDetail";
		_panel.className = "SmiRouteDetail";
		_panel.unselectable="on";

		_elmClose = document.createElement("a");
		_elmClose.href="javascript://";
		_elmClose.className = "Close";
		_elmClose.innerHTML = "X";
		_elmClose.attachEvent("onclick", _closeClick)
		
		_elmHeader = document.createElement("h2");
		_elmHeader.innerHTML = "Title";
		
		_elmBody = document.createElement("iframe");
		_elmBody.frameBorder="0";
		_elmBody.marginHeight="5"; 
		_elmBody.marginWidth="5";
		_elmBody.allowTransparency="true";
		_elmBody.src="about:blank";
		
		_panel.appendChild(_elmClose);
		_panel.appendChild(_elmHeader);
		_panel.appendChild(_elmBody);
		
		document.body.appendChild(_panel)
		
		_oMap.VeMap.AttachEvent("onresize", _onMapResize);
		_elmBody.CloseDialog = function() {
			_Hide();
		}
		
		_onMapResize();
		_Hide();
	}
	
	function _closeClick() {
		_Hide();
	}
	
	function _Hide() {
		_panel.style.display = "none";
		//_elmBody.src="about:blank";
		_elmBody.contentWindow.document.open("about:blank");
		_elmBody.contentWindow.document.write("<style type='text/css'>html, body { background-color:transparent; }</style>");
		_elmBody.contentWindow.document.close();
	}

	function _ShowByVehicleID(title, routeID, vehicleID) {
		_panel.style.display = "block";
		_elmHeader.innerHTML = title;
		_elmBody.src="VehicleDetail.aspx?RouteID=" + routeID + "&VehicleID=" + vehicleID;
		_onMapResize();
	}
	
	this.IsVisible = function() {
		return (_panel.style.display != "none");
	}
	
	function _onMapResize() {
		_panel.style.left = Math.ceil(_oMap.VeMap.GetLeft() + _oMap.VeMap.GetWidth() / 2 - _panel.offsetWidth / 2) + "px";
		_panel.style.top = Math.ceil(_oMap.VeMap.GetTop() + _oMap.VeMap.GetHeight() / 2 - _panel.offsetHeight / 2) + "px";
	}
	
	this.Dispose=function(){
		try {
			_elmBody.CloseDialog = null;
			_elmClose.detachEvent("onclick", _closeClick)
			_oMap.VeMap.DetachEvent("onresize", _onMapResize);
			document.body.removeChild(_panel);
			_panel = null;
			_oMap = null;

			_elmClose = null;
			_elmHeader = null;
			_elmBody = null;
		} catch(g){}
	}	
	
	this.Hide = _Hide;
	this.ShowByVehicleID = _ShowByVehicleID;
	
}

/* ************************* SEARCH FUNCTIONS ************************************** */

function SearchResultSelectChange() {
	var oList = GetPageElementById("ctlSearchResultList");
	if(oList.value != "") {
		var ary = oList.value.split("_");
		var type = ary[0];
		switch(type) {
			case "W":
				var ll = new VELatLong(ary[2], ary[3]);
				ShowSearchPin(ll, oList.options[oList.selectedIndex].innerText, ary[1]);
				oMap.SetCenterAndZoom(ll, 15);
				break;
			case "R":
				ToggleRoute(ary[1], false);
				break;
			case "S":
				var ll = new VELatLong(ary[1], ary[2]);
				ShowSearchPin(ll, oList.options[oList.selectedIndex].innerText, null);
				oMap.SetCenterAndZoom(ll, 15);
				break;
		}
	}
}

var _searchPushpin = null;
function ShowSearchPin(ll, title, waypointID) {
	if(_searchPushpin != null) {
		oMap.DeletePushpin(_searchPushpin.ID);
		_searchPushpin = null;
	}
		
	SearchPinMouseOver = function() {
		var sUrl = "RouteArrivals.axd?";
		if(waypointID == null) {
			sUrl += "ll=" + ll
		} else {
			sUrl += "WaypointID=" + waypointID;
		}
		var routes = gRouteManager.GetRoutes();
		sUrl += gRouteManager.GetRoutesQueryString();
		
		var msg = "";
		msg += "<h2>" + title + "</h2>";
		msg += "<div id='StopPopupContent' class='StopPopupContent' width='100%'><div class='StopPopupLoading'>Loading...</div></div>";
		SearchPinMouseOut();

		ShowSearchPinPopup = function(sUrl, msg, pinID) {
			oMap.CalloutWindow.ShowByPin(msg, pinID);

			gStopDetailsNetwork.ServiceUrl = sUrl;
			gStopDetailsNetwork.BeginInvoke(null, null, null);
		}
		
		stopPopupTimeout = window.setTimeout("ShowSearchPinPopup('" + sUrl + "', \"" + msg + "\", '" + _searchPushpin.ID + "')", 200);
	}

	SearchPinMouseOut = function() {
		oMap.CalloutWindow.Hide();
			
		if(stopPopupTimeout != null) {
			window.clearTimeout(stopPopupTimeout);
			stopPopupTimeout = null;
		}
	}	
	
	SearchPinMouseOut();
	
	_searchPushpin = new VEPushpin("SearchPushpin", ll, "images/target.gif", null, null, "SearchPin");
	_searchPushpin.onmouseover = SearchPinMouseOver;
	_searchPushpin.onmouseout = SearchPinMouseOut;
	oMap.AddPushpin(_searchPushpin);
}

function SearchOnBloor() {
	var elm = GetPageElementById("ctlSearch");
	if(elm.value == '') { 
		elm.value = gSearchEmptyText; 
	}
}
function SearchOnFocus() {
	var elm = GetPageElementById("ctlSearch");
	if(elm.value == gSearchEmptyText)  
	{
		elm.value = ''; 
	} 
}

function DoSearch() {
	if(_searchPushpin != null) {
		oMap.DeletePushpin(_searchPushpin.ID);
		_searchPushpin = null;
	}

	var oList = GetPageElementById("ctlSearchResultList");
	DeleteAllOptions(oList);
	var newOpt = new Option("Searching...", "");
	oList.options[oList.length] = newOpt;
	
	var prm = Sys.WebForms.PageRequestManager.getInstance();	
	prm.add_endRequest(EndSearchHandler)
	prm = null;
}

function EndSearchHandler() {
	var prm = Sys.WebForms.PageRequestManager.getInstance();	
	prm.remove_endRequest(EndSearchHandler);
	prm = null;

	var oList = GetPageElementById("ctlSearchResultList");
	if(oList.options.length == 1 && oList.options[0].value != "") {
		oList.options[0].selected = true;
		SearchResultSelectChange();
		var mapElm = GetPageElementById("ctlMap");
		if(mapElm.style.visibility != "visible") {
			mapElm.style.visibility = "visible";
		}
		mapElm = null;
	} else if(oList.value == "") {
		var sText = GetPageElementById('ctlSearch').value;
		if(sText == gSearchEmptyText) {
			sText = "";
		}
		sText += ", Toronto, Ontario, Canada";
		sText = sText.replace("#", "");
		
		oMap.VeMap.Find(null, sText, null, null, 0, 1, false, false, false, false, OnFindLocationResults);
	}
}
function OnFindLocationResults(a,b,e) {
	var oList = GetPageElementById("ctlSearchResultList");
	DeleteAllOptions(oList);
	for (var i = 0; i < e.length; i++)
	{
		var newOpt = new Option(e[i].Name, "S_" + e[i].LatLong.Latitude + "_" + e[i].LatLong.Longitude);
		oList.options[oList.length] = newOpt;
	}
	if(e.length == 0) {
		var newOpt = new Option("No Records Found", "");
		oList.options[oList.length] = newOpt;
	}
	if(oList.options.length > 0) {
		oList.options[0].selected = true;
		SearchResultSelectChange();
	}
	var mapElm = GetPageElementById("ctlMap");
	if(mapElm.style.visibility != "visible") {
		mapElm.style.visibility = "visible";
	}
	mapElm = null;
}
function DeleteAllOptions(oList) {
	for(i=oList.length-1; i>=0; i--)
	{
		oList.options[i] = null;
	}
}
