//  World Atlas Section
	function Legend()
	{
		var LegendURL = "/encnet/features/MapCenter/MapLegend.aspx?mapstyleindex=" + document.mapSearchFrm.MapStyleSelectedIndex.value;
		legendWindow = window.open(LegendURL,"MapLegend","width=230,height=490,scrollbars=yes,left=480,top=120,screenX=480,screenY=120" );
		legendWindow.focus();
	}
	
	function PrintPreview()
	{
		var PrintPreviewURL = "/encnet/features/MapCenter/MapPrintPreview.aspx"+GetMapImageUrlParams()+"&entityname=";
		if(UnicodingBrowser.toLowerCase() == "true")
			PrintPreviewURL += encodeURI(entityname);
		else
			PrintPreviewURL += UTF8UrlEncode(entityname);
		var previewWindow = window.open(PrintPreviewURL);
		previewWindow.focus();
	}
	
	function SelectSearchResult()
	{
		if (document.mapSearchFrm.ResultsListbox.selectedIndex != -1)
		{
			var selectedValue = document.mapSearchFrm.ResultsListbox.options[document.mapSearchFrm.ResultsListbox.selectedIndex].value;
			var semis = new Array(4);
			semis[0] = selectedValue.indexOf(";");
			semis[1] = selectedValue.indexOf(";", semis[0]+1);
			semis[2] = selectedValue.indexOf(";", semis[1]+1);
			semis[3] = selectedValue.indexOf(";", semis[2]+1);
			var latitude = selectedValue.substring(0, semis[0]);
			var longitude = selectedValue.substring(semis[0] + 1, semis[1]);
			if(SiteCultureNonUS == 1)
			{			
				if (-1 < latitude.indexOf(","))
				{
					var i = latitude.indexOf(",");
					latitude = latitude.substring(0,i) + "." + latitude.substring(i+1,latitude.length);
				}
				if (-1 < longitude.indexOf(","))
				{
					var i = longitude.indexOf(",");
					longitude = longitude.substring(0,i) + "." + longitude.substring(i+1,longitude.length);
				}
			}
			var altitude = selectedValue.substring(semis[1] + 1, semis[2]);
			var selectedEntity = selectedValue.substring(semis[2] + 1, semis[3]);
			entityname = selectedValue.substr(semis[3] + 1);
			var iAdditionalNameText = entityname.indexOf(";");
			if(iAdditionalNameText >=0 )
				entityname = entityname.substring(0,iAdditionalNameText);
			document.title = MapOfText+" "+entityname+" - "+mapWindowTitle;
			writeToLayer('MapTitle', "<H1>"+MapOfText+" "+entityname+"</H1>");
			document.mapSearchFrm.TextLatitude.value = latitude;
			document.mapSearchFrm.TextLongitude.value = longitude;
			document.mapSearchFrm.TextSelectedEntity.value = selectedEntity;
			ZoomTo(altitude, false);
			UpdateMap();
			var Mac= (navigator.userAgent != null)?navigator.userAgent.search(/Mac/):-1;
			if(Mac != -1)
			{
				if(!(navigator.userAgent.toUpperCase().indexOf("SAFARI")>-1))
					window.location.hash = "map_frame";
			}
			else
				window.location.hash = "#map_frame";
		}
	}
	function writeToLayer(layerID, layerText)
	{
		if (document.getElementById)// NS6 & IE5+
		{
			document.getElementById(layerID).innerHTML = layerText;
		}
		else if (document.all)// IE4+
		{
			document.all[layerID].innerHTML = layerText;
		}
	}
	function MapClick(e)
	{
		var x;
		var y;
		if (navigator.userAgent.indexOf("MSIE") > 0)
		{
			x = window.event.offsetX;
			y = window.event.offsetY;
		}
		else
		{
			x = e.pageX-23;
			y = e.pageY-311;
		}
		HandleMapClick(x, y, 1, false);
	}
	function HandleMapClick(x, y, zDelta, bSuppNS)
	{
		var longLatDiffArray = GetLatLong(Math.floor(x - (mapWidthPX / 2) ), Math.floor(y - (mapHeightPX / 2) ), bSuppNS );
		if (longLatDiffArray != null && !isNaN(longLatDiffArray[0]) && !isNaN(longLatDiffArray[1]))
		{
			document.mapSearchFrm.TextLatitude.value = TestAgainstHiLo(longLatDiffArray[0],-90,90);
			document.mapSearchFrm.TextLongitude.value = WrapLongitude(longLatDiffArray[1]);
			if (document.mapSearchFrm.ZoomOnMapClickCheck.checked && zDelta != 0)
			{
				ZoomTo(parseInt(document.mapSearchFrm.TextAltitude.value, 10) + zDelta, false);
			}
			document.title = PageTitle;
			entityname = "";
			UpdateMap();
		}
	}
	function TestAgainstHiLo(toTest, low, high)
	{
		if (toTest > high)
			return high;
		else if (toTest < low)
			return low;
		return toTest;
	}
	function WrapLongitude(toTest)
	{
		if (toTest > 180)
			return toTest - 360;
		else if (toTest <= -180)
			return toTest + 360;
		return toTest;
	}
	
	function GetMapImageUrlParams()
	{
		return "?lat=" + escape(document.mapSearchFrm.TextLatitude.value.toString())
			+ "&long=" + escape(document.mapSearchFrm.TextLongitude.value.toString())
			+ "&alt=" + escape(document.mapSearchFrm.TextAltitude.value.toString())
			+ "&mapsize=" + escape(document.mapSearchFrm.MapSize.value)
			+ "&mapstyle=" + escape(document.mapSearchFrm.MapStyle.value)
			+ "&mapstyleselectedindex=" + escape(document.mapSearchFrm.MapStyleSelectedIndex.value)
			+ "&selectedent=" + escape(document.mapSearchFrm.TextSelectedEntity.value.toString());
	}
	
	function UpdateMap()
	{
		var mapIFrame = document.getElementById('MapIFrame');
		var mapImage = document.getElementById('MapImage');
		var newMapImageUrl = "/encnet/features/MapCenter/MapImg.aspx" + GetMapImageUrlParams();
		if (mapIFrame.src != newMapImageUrl)
		{
			
			mapIFrame.src = newMapImageUrl;
			if(mapImage.style.display == "none")
				mapImage.style.display = "block";
			var loadingImage = document.getElementById('LoadingImage');
			if (loadingImage != null)
				loadingImage.style.display = "none";
		}
		UpdateScaleImageSrc();
		var zoomLevel = parseInt(document.mapSearchFrm.TextAltitude.value, 10);
		if (mapImage != null)
		{
			if (!document.mapSearchFrm.ZoomOnMapClickCheck.checked || zoomLevel == 10)
			{
				mapImage.alt = mapHintCenter;
				mapImage.title = mapHintCenter;
			}
			else
			{
				mapImage.alt = mapHintZoom;
				mapImage.title = mapHintZoom;
			}
		}
 	} 
 	
 	function ChangeMapImageAltText()
 	{
		var mapImage = document.getElementById("MapImage");
 		if (mapImage != null)
 		{
			if (!document.mapSearchFrm.ZoomOnMapClickCheck.checked)
			{
				mapImage.alt = mapHintCenter;
				mapImage.title = mapHintCenter;
				setCookie("ZoomOnMapClickCheck","off");
			}
			else
			{
				mapImage.alt = mapHintZoom;	
				mapImage.title = mapHintZoom;	
				setCookie("ZoomOnMapClickCheck","on");
			}
		}
 	}
	
	function ZoomTo(zoomlevel, boolUpdateMap)
	{
		zoomlevel = TestAgainstHiLo(zoomlevel, 0, permissibleZoomLevels[document.mapSearchFrm.MapStyleSelectedIndex.value]-1);
		if (zoomlevel != document.mapSearchFrm.TextAltitude.value)
		{
			var ScaleImageSelected = document["Z"+document.mapSearchFrm.TextAltitude.value].src.substring(document["Z"+document.mapSearchFrm.TextAltitude.value].src.lastIndexOf("/")+1,document["Z"+document.mapSearchFrm.TextAltitude.value].src.length);
			if(ScaleImageSelected != "active.gif")
			{
				var i=0;
				var ScaleImage = document["Z"+i].src.substring(document["Z"+i].src.lastIndexOf("/")+1,document["Z"+i].src.length);
				while(i<10 && ScaleImage != "active.gif")
				{
					i++;
					ScaleImage = document["Z"+i].src.substring(document["Z"+i].src.lastIndexOf("/")+1,document["Z"+i].src.length);
				}
				if(i<10)
					document.mapSearchFrm.TextAltitude.value =i;
			}	
			UpdateZoomIndicator(document.mapSearchFrm.TextAltitude.value,zoomlevel);
			document.mapSearchFrm.TextAltitude.value = zoomlevel;
			if (boolUpdateMap)
			{
				UpdateMap();
			}
		}
	}
	function UpdateZoomIndicator(oldLevel,newLevel)
	{
		if (oldLevel != newLevel)
		{
			var oldImgName = "Z" + oldLevel;
			var newImgName = "Z" + newLevel;
			document[oldImgName].src = "/xImages/maps/passive.gif";
			document[newImgName].src = "/xImages/maps/active.gif";
		}
	}
	function Navigate(x,y,z)
	{
		document.title = PageTitle;
		entityname = "";
		var panningFraction = 0.3;// adjustable
		
		if ('0' == document.mapSearchFrm.TextAltitude.value)
		{
			panningFraction = 0.1;
		}
		else if ('1' == document.mapSearchFrm.TextAltitude.value)
		{
			panningFraction = 0.2;
		}
		if ('' + x == '0' && '' + y == '0')
		{
			ZoomTo(parseInt(document.mapSearchFrm.TextAltitude.value, 10) + z, true);
		}
		else
		{
			var xClick = mapWidthPX/2 + (x*mapWidthPX*panningFraction);
			var yClick = mapHeightPX/2 + (y*mapHeightPX*panningFraction);
			
			if ('' + y == '0' && '' + z == '0')
			{
				HandleMapClick(xClick, yClick, z, true);
			}
			else
			{
				HandleMapClick(xClick, yClick, z, false);
			}
		}
	}
	
	function UpdateScaleImageSrc()
	{
		var newScaleImageSrc;
		if(document.mapSearchFrm.MapStyle.value.toLowerCase() == "moon")
			newScaleImageSrc = "/xImages/maps/moon-scale-"+document.mapSearchFrm.MapSize.value.toLowerCase()+"-"+document.mapSearchFrm.TextAltitude.value+".gif";
		else
			newScaleImageSrc = "/xImages/maps/scale-"+document.mapSearchFrm.MapSize.value.toLowerCase()+"-"+document.mapSearchFrm.TextAltitude.value+".gif";
		if (document.getElementById("ScaleImage").src != newScaleImageSrc)
		{
			document.getElementById("ScaleImage").src = newScaleImageSrc;
		}
	}
	
	function GetLatLong(pxX, pxY, bNoNS)
	{
		var latLong = new Array(2);
		var dSphereRadiusKM = 6378.2;
		var dRadiansToDegrees = 180.0 / Math.PI;
		var R;
		switch(document.mapSearchFrm.MapSize.value)
		{
			case "small":
				R = (dSphereRadiusKM * mapHeightPX) / mapWidthsKm[document.mapSearchFrm.TextAltitude.value];
				break;
			case "medium":
				R = (dSphereRadiusKM * mapHeightPX)*SmallMapHeight / MediumMapHeight * mapWidthsKm[document.mapSearchFrm.TextAltitude.value];
				break;
			case "large":
				R = (dSphereRadiusKM * mapHeightPX)*SmallMapHeight / LargeMapHeight * mapWidthsKm[document.mapSearchFrm.TextAltitude.value];
				break;
			default:
				R = (dSphereRadiusKM * mapHeightPX) / mapWidthsKm[document.mapSearchFrm.TextAltitude.value];
				break;
		}
		
		var vC = new Array(0.0, 0.0, 0.0);
		vC[0] = pxX / R;
		vC[1] = - pxY / R;
		if( (vC[0]*vC[0] + vC[1]*vC[1]) > 1.0 )
			return null; // return if click is off the world
		vC[2] = Math.sqrt( 1 - (vC[0]*vC[0] + vC[1]*vC[1]) );
		var CurLat = -(parseFloat(document.mapSearchFrm.TextLatitude.value) / dRadiansToDegrees);
		var CurLon = (parseFloat(document.mapSearchFrm.TextLongitude.value) / dRadiansToDegrees);
		var m1 = new Array( Math.cos(CurLon), Math.sin(CurLat)*Math.sin(CurLon), Math.cos(CurLat)*Math.sin(CurLon) );
		var m2 = new Array( 0.0, Math.cos(CurLat), -Math.sin(CurLat) );
		var m3 = new Array( -Math.sin(CurLon), Math.sin(CurLat)*Math.cos(CurLon), Math.cos(CurLat)*Math.cos(CurLon) );
		var vF = new Array(0.0, 0.0, 0.0);
		for(i=0;i<3;i++)
		{
			vF[0] = vF[0] + vC[i]*m1[i];
		}
		for(i=0;i<3;i++)
		{
			vF[1] = vF[1] + vC[i]*m2[i];
		}
		for(i=0;i<3;i++)
		{
			vF[2] = vF[2] + vC[i]*m3[i];
		}
		var FinalLat = Math.asin( vF[1] );
		var FinalLon = Math.atan2( vF[2], vF[0] );
		
		if (true == bNoNS)
		{
			latLong[0] = document.mapSearchFrm.TextLatitude.value;
		}
		else
		{
			latLong[0] = FinalLat * dRadiansToDegrees;
		}
		latLong[1] = WrapLongitude(90 - (FinalLon * dRadiansToDegrees) );
		return latLong;
	}
	
	function MapSearch()
	{
		if(document.getElementById("searchTextMap").value != null && document.getElementById("searchTextMap").value != "")
		{
			if(document.mapSearchFrm.MapStyle.value.toLowerCase() == "moon")
			{
				if( confirm(FindErrorMessage) == true)
				{
					document.mapSearchFrm.MapStylesList.selectedIndex = 0;
					ChangeMapStyle();
				}	
				else
					return;
			}
			document.mapSearchFrm.action= "/encnet/features/mapcenter/map.aspx";
			document.mapSearchFrm.submit();
		}	
	}
		
	function MapBodyOnLoad()
	{
		document.mapSearchFrm.MapStylesList.selectedIndex = document.mapSearchFrm.MapStyleSelectedIndex.value;
		document.mapSearchFrm.MapStyle.value = mapStyleStrings[parseInt(document.mapSearchFrm.MapStyleSelectedIndex.value)];
		if(document.mapSearchFrm.ZoomOnMapClickCheck.value == "on")
			document.mapSearchFrm.ZoomOnMapClickCheck.checked = true;
		else
			document.mapSearchFrm.ZoomOnMapClickCheck.checked = false;
		if (document.mapSearchFrm.MapSize.value == "")
		{
			if(document.body.clientWidth >= 1126)
				document.mapSearchFrm.MapSize.value = "Large";
			else if (document.body.clientWidth >= 903)
				document.mapSearchFrm.MapSize.value = "Medium";
			else
				document.mapSearchFrm.MapSize.value = "Small";
		}
		AutoChangeMapSize(document.mapSearchFrm.MapSize.value);
		RenderZoomControl();
		SetKeyboardInputFocus();
	}
	
	function ChangeHoverState(Image)
	{
		var ImageSource = Image.src.substring(Image.src.lastIndexOf("/")+1,Image.src.length);
		if(ImageSource == "passive.gif")
			Image.src = "/xImages/maps/hover.gif";
		else if(ImageSource == "hover.gif")
			Image.src ="/xImages/maps/passive.gif";
	}
	
	function SelectMapSizeIcon(MapSize)
	{
		document.getElementById("SmallMapSizeIcon").src = "/xImages/maps/passive.gif";
		document.getElementById("MediumMapSizeIcon").src = "/xImages/maps/passive.gif";
		document.getElementById("LargeMapSizeIcon").src = "/xImages/maps/passive.gif";
		document.getElementById(MapSize+"MapSizeIcon").src= "/xImages/maps/active.gif";
	}
	
	function AutoChangeMapSize(NewMapSize)
	{
		ChangeMapSize(NewMapSize,false);
	}
	
	function ChangeMapSize(NewMapSize,saveSize)
	{
		if (saveSize)
			document.mapSearchFrm.MapSize.value = NewMapSize;
		SelectMapSizeIcon(NewMapSize);
		switch(NewMapSize.toLowerCase())
		{
			case "small":
				document.getElementById('HeaderTable').style.width = document.getElementById('MapTable').style.width = mapFrameWidths[0] + 300;
				document.getElementById('MapFrameTable').style.width = document.getElementById('MapCenterTitleCell').style.width= document.getElementById('MapToolsTable').style.width = document.getElementById('MapLinksTable').style.width = mapFrameWidths[0];	
				mapWidthPX = document.getElementById('MapImage').style.width = document.getElementById('NorthImageCell').style.width = document.getElementById('MapImageCell').style.width = document.getElementById('SouthImageCell').style.width = mapWidths[0]; 
				mapHeightPX = mapHeights[0];
				document.getElementById('MapImageCell').style.height = document.getElementById('MapImage').style.height = mapHeights[0];
				document.getElementById('MapStylesList').style.width = mapStylesWidths[0];
				document.getElementById('MapSizePaddingLeft').style.width = mapSizeLeftPaddings[0];
				document.getElementById('MapSizePaddingRight').style.width = mapSizeRightPaddings[0];
				document.getElementById('ToolsRightPadding').style.width = mapToolsRightPaddings[0];
				document.getElementById('LegendCell').style.width = mapLegendWidths[0];
				document.getElementById('PrintCell').style.width = mapPrintWidths[0];
				document.getElementById('GetDirectionsCell').style.width = mapGetDirectionsWidths[0];
				if(NonZeroSearchResults == 1)
				{
					document.getElementById('ResultsTable').style.width = mapFrameWidths[0];	
				}
				document.getElementById('MoreAtlasResourcesCell').style.width = mapFrameWidths[0];
				if(UseNavMap == "true")
				{
					GenerateImageMap('MapImageMapDiv');
					mapImageCellWidthPX = smallMapImageCellWidthPX;
					mapImageCellHeightPX = smallMapImageCellHeightPX;
					document.MapImage.useMap = "#MapImageMap"+document.getElementById('MapSize').value;
				}
				break;
			case "medium":
				document.getElementById('HeaderTable').style.width = document.getElementById('MapTable').style.width = mapFrameWidths[1] + 300;
				document.getElementById('MapFrameTable').style.width = document.getElementById('MapCenterTitleCell').style.width = document.getElementById('MapToolsTable').style.width = document.getElementById('MapLinksTable').style.width  = mapFrameWidths[1];
				mapWidthPX = document.getElementById('MapImage').style.width  = document.getElementById('NorthImageCell').style.width = document.getElementById('MapImageCell').style.width = document.getElementById('SouthImageCell').style.width = mapWidths[1];
				mapHeightPX = mapHeights[1];
				document.getElementById('MapImageCell').style.height = document.getElementById('MapImage').style.height  = mapHeights[1];
				document.getElementById('MapStylesList').style.width = mapStylesWidths[1];
				document.getElementById('MapSizePaddingLeft').style.width = mapSizeLeftPaddings[1];
				document.getElementById('MapSizePaddingRight').style.width = mapSizeRightPaddings[1];
				document.getElementById('ToolsRightPadding').style.width = mapToolsRightPaddings[1];
				document.getElementById('LegendCell').style.width = mapLegendWidths[1];
				document.getElementById('PrintCell').style.width = mapPrintWidths[1];
				document.getElementById('GetDirectionsCell').style.width = mapGetDirectionsWidths[1];
				if(NonZeroSearchResults == 1)
				{
					document.getElementById('ResultsTable').style.width = mapFrameWidths[1] -7;		
					document.getElementById('ResultsPaddingCell').style.width = 20;					
				}
				document.getElementById('MoreAtlasResourcesCell').style.width = mapFrameWidths[1];
				if(UseNavMap == "true")
				{
					GenerateImageMap('MapImageMapDiv');
					mapImageCellWidthPX = mediumMapImageCellWidthPX;
					mapImageCellHeightPX = mediumMapImageCellHeightPX;
					document.MapImage.useMap = "#MapImageMap"+document.getElementById('MapSize').value;
				}
				break;
			case "large":
				document.getElementById('HeaderTable').style.width = document.getElementById('MapTable').style.width = mapFrameWidths[2] + 300;
				document.getElementById('MapFrameTable').style.width = document.getElementById('MapCenterTitleCell').style.width = document.getElementById('MapToolsTable').style.width = document.getElementById('MapLinksTable').style.width =  mapFrameWidths[2];
				mapWidthPX = document.getElementById('MapImage').style.width  =  document.getElementById('NorthImageCell').style.width = document.getElementById('MapImageCell').style.width = document.getElementById('SouthImageCell').style.width = mapWidths[2];
				mapHeightPX = mapHeights[2];
				document.getElementById('MapImageCell').style.height = document.getElementById('MapImage').style.height  =  mapHeights[2];
				document.getElementById('MapStylesList').style.width = mapStylesWidths[2];
				document.getElementById('MapSizePaddingLeft').style.width = mapSizeLeftPaddings[2];
				document.getElementById('MapSizePaddingRight').style.width = mapSizeRightPaddings[2];
				document.getElementById('ToolsRightPadding').style.width = mapToolsRightPaddings[2];
				document.getElementById('LegendCell').style.width = mapLegendWidths[2];
				document.getElementById('PrintCell').style.width = mapPrintWidths[2];
				document.getElementById('GetDirectionsCell').style.width = mapGetDirectionsWidths[2];
				if(NonZeroSearchResults == 1)
				{
					document.getElementById('ResultsTable').style.width = mapFrameWidths[1] -7;	
					document.getElementById('ResultsPaddingCell').style.width = 20;												
				}
				document.getElementById('MoreAtlasResourcesCell').style.width = mapFrameWidths[1];
				if(UseNavMap == "true")
				{
					GenerateImageMap('MapImageMapDiv');
					mapImageCellWidthPX = largeMapImageCellWidthPX;
					mapImageCellHeightPX = largeMapImageCellHeightPX;
					document.MapImage.useMap = "#MapImageMap"+document.getElementById('MapSize').value;
				}
				break;
			default:
				break;
		}
		UpdateMap();
		if (saveSize)
			setCookie("MapSize",NewMapSize);
	}
	
	function RenderZoomControl()
	{
		var ZoomToolTable = document.getElementById('ZoomToolTable');
		var iMaxZoomLevel =  permissibleZoomLevels[document.mapSearchFrm.MapStyleSelectedIndex.value];
		var TableHTML="";
		var padding = 5 * iMaxZoomLevel+3;
		ZoomToolTable.innerHTML = "";
		//document.getElementById('ZoomTextPaddingCell').style.width = padding;
		//document.getElementById('ZoomTextCell').style.width = 150 - padding;
		if(document.getElementById('ZoomTextCell').innerHTML == "")
			document.getElementById('ZoomTextCell').innerHTML = ZoomText;
		TableHTML += "<table align='left' border='0' cellpadding='0' cellspacing='0' ><tr>";
		TableHTML += "<td><a href='javascript:Navigate(0,0,-1);'><img width='16' height='16' border='0' src = '/xImages/maps/zoomout.gif' alt='"+ ZoomOutText + "' ID='ZoomOut' name='ZoomOut'/></a></td>";
		TableHTML += "<td width='5'><IMG width='5' alt='' border='0' SRC='/xImages/trans.gif'></td>";
		for(i=0; i <iMaxZoomLevel; i++)
		{
			var ImageHTML="";
			ImageHTML  += "<td align='left' valign='center' width='5' width='5' height='18' height='18'><a href='javascript:ZoomTo(" + i + ",true);'> <img border='0' vspace='0' name='Z" + i + "' id='Z" + i + "' src='/xImages/maps/";
			if(document.mapSearchFrm.TextAltitude.value == i)
				ImageHTML += "active.gif'";
			else
				ImageHTML += "passive.gif'";
			ImageHTML += " width='5' height='18' onmouseover='ChangeHoverState(this);'  onmouseout='ChangeHoverState(this);'/></a>";
			ImageHTML += "</td>";
			if( i < iMaxZoomLevel)
				ImageHTML += " <td width='5' valign='center'><IMG width='5' height='18' alt='' border='0' SRC='/xImages/trans.gif' /></td>";
			TableHTML += ImageHTML;
		} 
		if(iMaxZoomLevel == 10)
			TableHTML += " <td align='left' width='5'><IMG width='5' height='18' alt='' border='0' SRC='/xImages/trans.gif' /></td>";
		TableHTML += "<td align='left' width='16'><a href='javascript:Navigate(0,0,1);' ><IMG width='16' height='16'  border='0' src='/xImages/maps/zoomin.gif' alt='"+ ZoomInText + "' ID='ZoomIn' name='ZoomIn'/></a></td>";
		TableHTML += "</tr></table>";
		ZoomToolTable.innerHTML = TableHTML;
	}
	function ChangeMapStyle()
	{

		var SelectedStyleNumber = document.mapSearchFrm.MapStylesList.selectedIndex;
		var SelectedStyleText = document.mapSearchFrm.MapStylesList.options[SelectedStyleNumber].text;
		var SelectedStyleValue = document.mapSearchFrm.MapStylesList.options[SelectedStyleNumber].value.toLowerCase();
		if (SelectedStyleValue != "")
		{
			if(SelectedStyleValue.toLowerCase() != "n/a")
			{
				if(SelectedStyleValue == "moon")
				{
					var MoonMapURL = "/encnet/features/mapcenter/map.aspx?mapstyle=moon&mapsize="+document.mapSearchFrm.MapSize.value;
					MoonMapURL += "&TextAltitude=0&TextLatitude="+WorldLatitude+"&TextLongitude="+WorldLongitude+ "&MapStyleSelectedIndex="+ MoonStyleIndex;
					window.open(MoonMapURL,"_self");
				}
				else
				{
					if(document.mapSearchFrm.MapStylesList.options[document.mapSearchFrm.MapStyleSelectedIndex.value].value.toLowerCase() == "moon")
					{
						document.mapSearchFrm.TextAltitude.value = 0;
						document.mapSearchFrm.TextLatitude.value = WorldLatitude;
						document.mapSearchFrm.TextLongitude.value = WorldLongitude;
						document.title = mapWindowTitle+ " - "+MapOfText+" "+ WorldEntityName;
						writeToLayer('MapTitle',WorldEntityName);
					}					
					document.mapSearchFrm.MapStyleSelectedIndex.value = SelectedStyleNumber;
					document.mapSearchFrm.MapStyle.value = SelectedStyleValue ;
					if(permissibleZoomLevels[SelectedStyleNumber] <= document.mapSearchFrm.TextAltitude.value)
						ZoomTo(permissibleZoomLevels[SelectedStyleNumber]-1, true);
					else
						UpdateMap();
					RenderZoomControl();
					if(legendWindow != null && legendWindow.closed != true){
					
						legendWindow.open("/encnet/features/mapcenter/MapLegend.aspx?mapstyleindex="+SelectedStyleNumber, "_self");
					}
				}
				setCookie("MapStyle", SelectedStyleValue);
				setCookie("MapStyleSelectedIndex", SelectedStyleNumber);
			}	
		}
		else 
		{
			var SelectedMapStyleIndex = document.mapSearchFrm.MapStyleSelectedIndex.value;
			var SelectedMapStyle = document.mapSearchFrm.MapStyle.value;
			if(parseInt(SelectedStyleNumber,10) < 18)
			{
				SelectedMapStyleIndex = SelectedStyleNumber;
				SelectedMapStyle = (SelectedStyleText.indexOf("*") > -1)? SelectedStyleText.substring(3,SelectedStyleText.length):SelectedStyleText;
			}
			var MapURL = "?textlatitude=" + document.mapSearchFrm.TextLatitude.value.toString()
			+ "&textlongitude=" + document.mapSearchFrm.TextLongitude.value.toString()
			+ "&textaltitude=" + document.mapSearchFrm.TextAltitude.value.toString()
			+ "&mapsize=" + document.mapSearchFrm.MapSize.value
			+ "&mapstyle=" + SelectedMapStyle
			+ "&mapstyleselectedindex=" + SelectedMapStyleIndex
			+ "&selectedent=" + document.mapSearchFrm.TextSelectedEntity.value.toString()
			+ "&search=" + document.mapSearchFrm.searchTextMap.value.toString();
			
			var SignInURL = "/encnet/signin/SignInMain.aspx?cred=1|3|4|5&tgt=/encnet/features/mapcenter/map.aspx"+escape(MapURL);
			window.open(SignInURL, '_self');
		}
	}
	
	function GenerateImageMap(ImageMap)
	{
		var ImageMapName = "MapImageMap"+document.getElementById('MapSize').value;			
		var ImageMapHTML = "<map name='"+ImageMapName+"' id='"+ImageMapName+"'>";
		var i,j;
		for(j=0;j<Math.ceil(mapHeightPX/mapImageCellHeightPX);j++)
		{
			for(i=0;i<Math.ceil(mapWidthPX/mapImageCellWidthPX);i++)
			{
			
				ImageMapHTML += "\n<!-- "+i+" -->";
				ImageMapHTML += "<area tabindex='-1' shape=rect coords='"+(i*mapImageCellWidthPX)+","+(j*mapImageCellHeightPX)+","+((i+1)*mapImageCellWidthPX)+","+((j+1)*mapImageCellHeightPX)+"'";
				var midWidth = i*mapImageCellWidthPX + Math.ceil(mapImageCellWidthPX/2);
				var midHeight = j*mapImageCellHeightPX + Math.ceil(mapImageCellHeightPX/2);
				ImageMapHTML  += " href='javascript:HandleMapClick("+midWidth+","+midHeight+",1,false)'>\n";
			}
		}
		ImageMapHTML += "</map>";
		document.getElementById(ImageMap).innerHTML = ImageMapHTML;
	}
	
	function getCookieVal()
	{
		var cookieVal = document.cookie;
		var retCookieVal = "";
		var start;
		if (cookieVal != null && cookieVal != "" && (start = cookieVal.indexOf(CookieName + "=")) != -1 )
		{
			start += CookieName.length + 1;
			var end = cookieVal.indexOf(";",start);
			if (end == -1)
				end = cookieVal.length;
			retCookieVal = cookieVal.substring(start,end);
		}
		return retCookieVal;
	}
	
	function setCookie(name,val)
	{
		var cookieVal = "";
		var retCookieVal = getCookieVal();
		if(retCookieVal != "")
		{
			var a = retCookieVal.split("&");
			for (var i = 0; i < a.length; i++)
			{
				a[i] = a[i].split("=");
			}
			var found = false;
			for (var i = 0; i < a.length; i++)
			{
				var newval;
				if (a[i][0] == name)
				{
					found = true;
					newval = name + "=" + val;
				}
				else
					newval = a[i][0] + "=" + a[i][1];
				cookieVal += newval;
				if (i != a.length - 1)
					cookieVal += "&";
			}
			if (!found)
			{
				var v = "&" + name + "=" + val;
				cookieVal += v;
			}
		}
		else
			cookieVal = name + "=" + val;
			
		var now = new Date();
		now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365);
		var setval = CookieName + "=" + cookieVal + "; expires=" + now.toGMTString();
		document.cookie = setval;
	}
	
