﻿

	// Begin...
	function loadMap()
	{
		try
		{
			// Reset...
			document.getElementById('errorMessage').innerHTML = "";
			
			
			var mapOptions = 
			{
				zoom: minZoomLevel_DEFAULT,
				
				mapTypeId: mapType_DEFAULT,
				
				mapTypeControl: true,
				mapTypeControlOptions: 
				{
					position: google.maps.ControlPosition.LEFT_BOTTOM,
					style: google.maps.MapTypeControlStyle.DEFAULT 
				},
				
				panControl: true,
				panControlOptions: 
				{
					position: google.maps.ControlPosition.LEFT_BOTTOM 
				},

                streetViewControl: false,

				navigationControl: true,
				navigationControlOptions: 
				{
					position: google.maps.ControlPosition.LEFT_BOTTOM,
					style: google.maps.NavigationControlStyle.SMALL
				},

				scaleControl: true,
				scaleControlOptions: 
				{
					position: google.maps.ControlPosition.BOTTOM_LEFT
				}

			}
			
			mapCanvas = new google.maps.Map(document.getElementById("mapCanvas"), mapOptions);


			// Add several standard Google Maps API event handlers...
			google.maps.event.addListener(mapCanvas, 'click', function() 
			{ 
				// Hide any INFO WINDOW and MARKER CIRCLE that happens to be displaying...
				document.getElementById('overlayInfoWindowBlock').style.visibility = 'hidden';
			    circleSelectedMarker.setMap(null); 
			
			    ddmenuitem.style.visibility = 'hidden'; 
		    }); 
			
            google.maps.event.addListener(mapCanvas, 'zoom_changed', function() 
            {
                // MARKER CIRCLE: if a marker was previously clicked and the information window for that marker is displayed, resize and redisplay the marker circle...
                if (document.getElementById('overlayInfoWindowBlock').style.visibility == 'visible')
                {
                    var radiusCircle = radiusCircleBasedOnMapZoomLevel();
				    
                    circleSelectedMarker.setOptions({radius: radiusCircle, center: circleCenterPosition, strokeColor: 'white', fillColor: 'white'});				    
					circleSelectedMarker.setMap(mapCanvas);                
                }
                
                if (this.getZoom() > 15) this.setZoom(15);
                if (this.getZoom() < 2) this.setZoom(2);
            });			



			// ****
			// Try to auto geo-locate the map canvas based on the user's location
			// ****
			// Try W3C Geolocation (Preferred)
			  if(navigator.geolocation) {
				browserSupportFlag = true;
				navigator.geolocation.getCurrentPosition(function(position) {
				  initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
				  mapCanvas.setCenter(initialLocation);
				}, function() {
				  handleNoGeolocation(browserSupportFlag);
				});
			  // Try Google Gears Geolocation
			  } else if (google.gears) {
				browserSupportFlag = true;
				var geo = google.gears.factory.create('beta.geolocation');
				geo.getCurrentPosition(function(position) {
				  initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
				  mapCanvas.setCenter(initialLocation);
				}, function() {
				  handleNoGeoLocation(browserSupportFlag);
				});
			  // Browser doesn't support Geolocation
			  } else {
				browserSupportFlag = false;
				handleNoGeolocation(browserSupportFlag);
			  }
			  
			  function handleNoGeolocation(errorFlag) 
			  {
				if (errorFlag == true) 
				{
				} 
				else 
				{
				}
				
				mapCanvas.setCenter(new google.maps.LatLng(mapLatitude_DEFAULT, mapLongitude_DEFAULT));
			  }
			
			

			// Using nulls, create a holding place for each of the overlay objects in the Overlays array */
			for (iX = 0; iX < overlaysSpecial.length; iX++)
			{
				mapCanvas.overlayMapTypes.push(null);
			}



			// Special for NASA JPL OnEarth - BLUE MARBLE "NEXT GENERATION" layer set current month name dropdownlist control...
			var currentMonthNumber = (currentDate.getMonth() + 1).toString();
			if (currentMonthNumber.length == 1) {currentMonthNumber = "0" + currentMonthNumber};

			document.getElementById("dropdownOtherLayers_Thematic_BlueMarble").value = currentMonthNumber;


			//
			// Set defaults on various checkbox controls....
			//
			
			
			//
			// *** EARTHQUAKE / TSUNAMI / VOLCANO / TROPICAL CYCLONE ***
			//
			//
			
			
			// EARTHQUAKE - USGS EHP
			document.myForm.checkboxEarthquake.checked = true;
			document.myForm.radioEarthquake_Age[0].checked = true;


			// EARTHQUAKE - USGS EHP - PLATE BOUNDARIES
			document.myForm.checkboxEarthquake_PlateBoundaries.checked = false;



			// TSUNAMI
			document.myForm.checkboxTsunami.checked = true;
			document.myForm.radioTsunami_Age[0].checked = true;						            // Past 24 hours...
			document.myForm.checkboxTsunami_MostRecentReportsOnly.checked = true; 	            // Most recently issued reports only...



			// VOLCANO - USGS VHP
			document.myForm.checkboxVolcano_USGS_VHP_Red.checked = true;
			document.myForm.checkboxVolcano_USGS_VHP_Orange.checked = true;
			document.myForm.checkboxVolcano_USGS_VHP_Yellow.checked = true;
			document.myForm.checkboxVolcano_USGS_VHP_GreenUnassigned_SpecialMonitored.checked = true;
			document.myForm.checkboxVolcano_USGS_VHP_Green.checked = false;					    // Don't display unmonitored GREEN status volcanoes initially...
			document.myForm.checkboxVolcano_USGS_VHP_Unassigned.checked = false;			    // Don't display unmonitored UNASSIGNED status volcanoes initially...
			

			// VOLCANO - VAAC
			document.myForm.checkboxVolcano_VAAC_Reports.checked = true;
			document.myForm.checkboxVolcano_VAAC_Areas.checked = false;
			document.myForm.radioVolcano_VAAC_Areas[0].checked = true;
			


			// VOLCANO - SMITHSONIAN GLOBAL VOLCANISM PROGRAM...
			document.myForm.checkboxVolcano_Smithsonian_GVP_New.checked = true;
			document.myForm.checkboxVolcano_Smithsonian_GVP_Ongoing.checked = false;	        // Don't display ONGOING status volcanoes markers initially...



			// TROPICAL CYCLONE
			document.myForm.checkboxTropicalCyclone.checked = true;
			document.myForm.checkboxTropicalCyclone_StormTrackHistory.checked = false;	        // Don't display TROPICAL CYCLONE STORM TRACKS initially...
			document.myForm.checkboxTropicalCyclone_Invests.checked = true;	        			



            // WEATHER
            document.myForm.checkboxWeather_NWS_Alerts.checked = false;
            document.myForm.checkboxWeather_NWS_Alerts.disabled = false;



			// FIRE / HOT SPOTS
			document.myForm.checkboxFire_GEOMAC_ActivePerimeters.checked = false;

			document.myForm.checkboxFire_USFS_RSAC_Incidents.checked = false;

			document.myForm.checkboxFire_USFS_RSAC_HotSpots.checked = false;
			document.myForm.checkboxFire_USFS_RSAC_HotSpots_12Hours.checked = true;
			document.myForm.checkboxFire_USFS_RSAC_HotSpots_12to24Hours.checked = false;

			document.myForm.checkboxFire_FIRMS_Hotspots.checked = false;



			//
			// *** SATELLITE ***
			//
			document.myForm.checkboxSatellite.checked = false;
			document.myForm.radioSatellite[0].checked = true;



			//
			// *** OTHER LAYERS ***
			//

			// DAY/NIGHT TERMINATOR Layer
			document.myForm.checkboxOtherLayers_DayNightTerminator_CityLights.checked = false;

			// THEMATIC Layers
			document.myForm.checkboxOtherLayers_Thematic.checked = false;
			document.myForm.radioOtherLayers_Thematic[0].checked = true;
			document.myForm.checkboxOtherLayers_Thematic_BlueMarble.checked = true;


			// WEBCAMS - VOLCANO
			document.myForm.checkboxOtherLayers_Webcams_Volcano.checked = false;
		

			// NEWS - VOLCANO LIVE (JOHN SEACH)
			document.myForm.checkboxOtherLayers_News_VolcanoLive.checked = false;




			//
			// *** HISTORY ***
			//

			markerclusterHistory = new MarkerClusterer(mapCanvas, [], {maxZoom: 6});
			
			document.myForm.checkboxHistory_NGDC_SignificantEvents_Earthquake.checked = false;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_Tsunami.checked = false;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_Volcano.checked = false;
			
			document.myForm.checkboxHistory_NGDC_SignificantEvents_1950ADtoPresent.checked = true;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_1900to1949AD.checked = true;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_1800to1899AD.checked = true;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_1500to1799AD.checked = true;
			document.myForm.checkboxHistory_NGDC_SignificantEvents_5000BCto1499AD.checked = true;




			//
			// *** VOLCANO CATALOG ***
			//
			markerclusterVolcanoCatalog = new MarkerClusterer(mapCanvas, [], {maxZoom: 9});
			
			this.resetVolcanoCatalog(true);

			


			// Set the map to the default position (zoomed over the PACIFIC RING OF FIRE) and the default zoom level...
			isWorldView = true;

			this.positionMap(mapLatitude_DEFAULT, mapLongitude_DEFAULT, minZoomLevel_DEFAULT);




			// Adjust the map canvas and application functionality based on the size and type of mobile device...
			this.detectMobileDevice();
			


			// Load all current Earthquake, Tsunami, Volcano and Tropical Cyclone activity markers onto the map...
			this.updateMap(true);
			
		}


		catch (ex_loadMap)
		{
			document.getElementById('errorMessage').innerHTML = "function 'loadMap' -- Error: " + ex_loadMap.description;
		}
	}
	
	
	
	function updateMap(doSetUpdateInterval)
	{
		try
		{

			document.getElementById('errorMessage').innerHTML = "";

			document.getElementById('menuUpdateMap').innerHTML = "Updating Map...";
			document.getElementById('menuUpdateMap').style.backgroundColor = "Gold";

			document.getElementById('loadingMessage').style.visibility = 'visible';
			document.getElementById('loadingMessageText').innerHTML = "Updating map...";
			window.setTimeout("clearMessages()", 2500)	// Display this message for 2.5 seconds max...


			isUpdatingMapAllHazards = true;



			// Set some common use variables used below for Date-Time processing...
			dtNow = new Date();
			localOffset_Hours = -(dtNow.getTimezoneOffset()/60); 
			milliseconds_dtNow = dtNow.getTime();



			// USGS EHP - Earthquake
			this.fetchData("Earthquake");
			
			
			
			// NOAA WCATWC/PTWC - Tsunami
			this.fetchData("Tsunami");
			
			
			
			// USGS VHP - Volcanoes
			this.fetchData("Volcano_USGS_VHP");
			
			
			
			// VAAC - VOLCANIC ASH ADVISORIES
			this.fetchData("Volcano_VAAC_Reports");
			
			if (document.myForm.checkboxVolcano_VAAC_Areas.checked)
			{
				this.fetchData("Volcano_VAAC_Areas");
			}
			
			
			
			// SMITHSONIAN GVP - WEEKLY REPORTS
			this.fetchData("Volcano_Smithsonian_GVP_New");
			this.fetchData("Volcano_Smithsonian_GVP_Ongoing");
			
			
			
			// WEATHER UNDRGROUND - TROPICAL CYCLONE
			this.fetchData("TropicalCyclone");



			
			// NATIONAL WEATHER SERVICE - Active NWS Alerts (Warnings, Watches, etc.) for CONUS, Alaska, Hawaii & U.S. Territories
			if (document.myForm.checkboxWeather_NWS_Alerts.checked)
			{
			    this.toggleLayer("Weather_NWS_Alerts");
    	    }

			// NATIONAL WEATHER SERVICE - RIDGE Radar image overlay for CONUS, Alaska, Hawaii & Guam 
			if (document.myForm.checkboxWeather_NWS_Radar.checked)
			{
			    this.toggleLayer("Weather_NWS_Radar");
    	    }



			// USFS / RSAC - Active Fire Locations
			if (document.myForm.checkboxFire_USFS_RSAC_Incidents.checked)
			{
    	        this.fetchData("Fire_USFS_RSAC_Incidents");
    	    }


			// USFS / RSAC - Hot Spots
			if (document.myForm.checkboxFire_USFS_RSAC_HotSpots.checked &
			   (document.myForm.checkboxFire_USFS_RSAC_HotSpots_12Hours.checked | document.myForm.checkboxFire_USFS_RSAC_HotSpots_12to24Hours.checked))
			{
    	        this.fetchData("Fire_USFS_RSAC_HotSpots");
    	    }


			// GEOMAC - Active Fire Perimeters
			if (document.myForm.checkboxFire_GEOMAC_ActivePerimeters.checked)
			{
    	        this.fetchData("Fire_GEOMAC_ActivePerimeters");
    	    }
			

			// FIRMS - Hot Spots
			if (document.myForm.checkboxFire_FIRMS_Hotspots.checked)
			{
    	        this.fetchData("Fire_FIRMS_HotSpots");
			}
			
			
			
			// Since the Satellite data are time-sensitive, automatically reload the currently selected layer if currently enabled...
            if (document.myForm.checkboxSatellite.checked)
            {
			    this.toggleLayer("Satellite_Checkbox");
            }
			
			
			
			isUpdatingMapAllHazards = false;


			document.getElementById('updatedDateTimeMessage').innerHTML = "Last updated: " + this.formatLocalDateTimeString(new Date(), false);



			// Automatically update the map with "Current Activity" every 10 minutes...
			if (doSetUpdateInterval)
			{
				var updateMapMinutes = 10;
				
				window.setTimeout("this.updateMap(true)", 60000 * updateMapMinutes);
			}
		}
		
		
		catch (ex_updateMap)
		{
			document.getElementById('errorMessage').innerHTML = "function 'updateMap' -- Error: " + ex_updateMap.description;
		}
	}
	
	
	
	function toggleLayer(layerName)
	{
		try
		{

			// Hide any INFO WINDOW and MARKER CIRCLE that happens to be displaying...
			document.getElementById('overlayInfoWindowBlock').style.visibility = 'hidden';
		    circleSelectedMarker.setMap(null);
			
			
			switch (layerName)
			{
				case "Earthquake":
					isEnabled_Earthquake = (document.myForm.checkboxEarthquake.checked);
					
					for (var iX = 0; iX < markersEarthquake.length; iX++) 
					{
						markersEarthquake[iX].setVisible(isEnabled_Earthquake);
					}
					
                    document.getElementById('textEarthquake_MostRecent').innerHTML = (isEnabled_Earthquake) ? listEarthquake_MostRecent : "";
					break;
					
					
					
				case "Earthquake_PlateBoundaries":
					if (!isLoaded_Earthquake_PlateBoundaries)
					{
						this.fetchData(layerName);	// Only load this layer if user manually selects it...
					}
					else
					{
						if (polylinesEarthquake_PlateBoundaries.getMap()) 
						{ 
							polylinesEarthquake_PlateBoundaries.setMap(null); 
						} 
						else 
						{ 
							polylinesEarthquake_PlateBoundaries.setMap(mapCanvas); 
						} 					
					}
					break;



				case "Tsunami":
					isEnabled_Tsunami = (document.myForm.checkboxTsunami.checked);
					
					for (var iX = 0; iX < markersTsunami.length; iX++) 
					{
						markersTsunami[iX].setVisible(isEnabled_Tsunami);
					}
					
                    document.getElementById('textTsunami_MostRecent').innerHTML = (isEnabled_Tsunami) ? listTsunami_MostRecent : "";
					break;


					
				case "Volcano_USGS_VHP_Red":
					isEnabled_Volcano_USGS_VHP_Red = (document.myForm.checkboxVolcano_USGS_VHP_Red.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_Red.length; iX++) 
					{
						markersVolcano_USGS_VHP_Red[iX].setVisible(isEnabled_Volcano_USGS_VHP_Red);
					}
					break;
					


				case "Volcano_USGS_VHP_Orange":
					isEnabled_Volcano_USGS_VHP_Orange = (document.myForm.checkboxVolcano_USGS_VHP_Orange.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_Orange.length; iX++) 
					{
						markersVolcano_USGS_VHP_Orange[iX].setVisible(isEnabled_Volcano_USGS_VHP_Orange);
					}
					break;


					
				case "Volcano_USGS_VHP_Yellow":
					isEnabled_Volcano_USGS_VHP_Yellow = (document.myForm.checkboxVolcano_USGS_VHP_Yellow.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_Yellow.length; iX++) 
					{
						markersVolcano_USGS_VHP_Yellow[iX].setVisible(isEnabled_Volcano_USGS_VHP_Yellow);
					}
					break;
					


				case "Volcano_USGS_VHP_GreenUnassigned_SpecialMonitored":
					isEnabled_Volcano_USGS_VHP_GreenUnassigned_SpecialMonitored = (document.myForm.checkboxVolcano_USGS_VHP_GreenUnassigned_SpecialMonitored.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_GreenUnassigned_SpecialMonitored.length; iX++) 
					{
						markersVolcano_USGS_VHP_GreenUnassigned_SpecialMonitored[iX].setVisible(isEnabled_Volcano_USGS_VHP_GreenUnassigned_SpecialMonitored);
					}
					break;


					
				case "Volcano_USGS_VHP_Green":
					isEnabled_Volcano_USGS_VHP_Green = (document.myForm.checkboxVolcano_USGS_VHP_Green.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_Green.length; iX++) 
					{
						markersVolcano_USGS_VHP_Green[iX].setVisible(isEnabled_Volcano_USGS_VHP_Green);
					}
					break;


					
				case "Volcano_USGS_VHP_Unassigned":
					isEnabled_Volcano_USGS_VHP_Unassigned = (document.myForm.checkboxVolcano_USGS_VHP_Unassigned.checked);
					
					for (var iX = 0; iX < markersVolcano_USGS_VHP_Unassigned.length; iX++) 
					{
						markersVolcano_USGS_VHP_Unassigned[iX].setVisible(isEnabled_Volcano_USGS_VHP_Unassigned);
					}
					break;



				case "Volcano_VAAC_Reports":
					isEnabled_Volcano_VAAC_Reports = (document.myForm.checkboxVolcano_VAAC_Reports.checked);
					
					for (var iX = 0; iX < markersVolcano_VAAC_Reports.length; iX++) 
					{
						markersVolcano_VAAC_Reports[iX].setVisible(isEnabled_Volcano_VAAC_Reports);
					}
					break;


					
				case "Volcano_VAAC_Areas":
					isEnabled_Volcano_VAAC_Areas = (document.myForm.checkboxVolcano_VAAC_Areas.checked);

					if (isEnabled_Volcano_VAAC_Areas)
					{
						this.fetchData(layerName);	// Only load this layer if user manually selects it...
					}
					else
					{
						polygonsVolcano_VAAC_Areas.setMap(null); 
					}
					break;


					
				case "Volcano_Smithsonian_GVP_New":
					isEnabled_Volcano_Smithsonian_GVP_New = (document.myForm.checkboxVolcano_Smithsonian_GVP_New.checked);
					
					for (var iX = 0; iX < markersVolcano_Smithsonian_GVP_New.length; iX++) 
					{
						markersVolcano_Smithsonian_GVP_New[iX].setVisible(isEnabled_Volcano_Smithsonian_GVP_New);
					}
					break;


					
				case "Volcano_Smithsonian_GVP_Ongoing":
					isEnabled_Volcano_Smithsonian_GVP_Ongoing = (document.myForm.checkboxVolcano_Smithsonian_GVP_Ongoing.checked);
					
					for (var iX = 0; iX < markersVolcano_Smithsonian_GVP_Ongoing.length; iX++) 
					{
						markersVolcano_Smithsonian_GVP_Ongoing[iX].setVisible(isEnabled_Volcano_Smithsonian_GVP_Ongoing);
					}
					break;


					
				case "TropicalCyclone":
				case "TropicalDisturbance":
				case "TropicalCyclone_StormTrackHistory":
					isEnabled_TropicalCyclone = (document.myForm.checkboxTropicalCyclone.checked);
					isEnabled_TropicalDisturbance = (document.myForm.checkboxTropicalCyclone_Invests.checked);

					if (layerName == "TropicalCyclone")
					{
						for (var iX = 0; iX < markersTropicalCyclone.length; iX++) 
						{
							markersTropicalCyclone[iX].setVisible(isEnabled_TropicalCyclone);
						}
						
						document.getElementById('textTropicalCyclone_Active').innerHTML = (isEnabled_TropicalCyclone) ? listTropicalCyclone_Active : "";
					}
					

					if (layerName == "TropicalDisturbance")
					{
						for (var iX = 0; iX < markersTropicalDisturbance.length; iX++) 
						{
							markersTropicalDisturbance[iX].setVisible(isEnabled_TropicalDisturbance);
						}
					}

					
					// TROPICAL CYCLONE storm tracks...
					var isEnabled_Tropical_StormTrackHistory = (document.myForm.checkboxTropicalCyclone_StormTrackHistory.checked);
					if (!isEnabled_TropicalCyclone) {isEnabled_Tropical_StormTrackHistory = false;}

					for (var iX = 0; iX < markersTropicalCyclone_StormTrackHistory.length; iX++) 
					{
						try
						{
							markersTropicalCyclone_StormTrackHistory[iX].setVisible(isEnabled_Tropical_StormTrackHistory);
						}
						catch (ex_TropicalCyclone_StormTrackHistory1)
						{
						}
					}
					
					for (var iX = 0; iX < polylinesTropicalCyclone_StormTrackHistory.length; iX++) 
					{
						try
						{
							var polylineStormTrack = polylinesTropicalCyclone_StormTrackHistory[iX];
	
							if (isEnabled_Tropical_StormTrackHistory)
							{
								polylineStormTrack.setMap(mapCanvas);
							}
							else
							{
								polylineStormTrack.setMap(null);
							}
						}
						catch (ex_TropicalCyclone_StormTrackHistory1)
						{
						}
					}


					// TROPICAL DISTURBANCE (INVEST) storm tracks...
					isEnabled_Tropical_StormTrackHistory = (document.myForm.checkboxTropicalCyclone_StormTrackHistory.checked);
					if (!isEnabled_TropicalDisturbance) {isEnabled_Tropical_StormTrackHistory = false;}

					for (var iX = 0; iX < markersTropicalDisturbance_StormTrackHistory.length; iX++) 
					{
						try
						{
							markersTropicalDisturbance_StormTrackHistory[iX].setVisible(isEnabled_Tropical_StormTrackHistory);
						}
						catch (ex_TropicalCyclone_Invests_StormTrackHistory1)
						{
						}
					}
					
					for (var iX = 0; iX < polylinesTropicalDisturbance_StormTrackHistory.length; iX++) 
					{
						try
						{
							var polylineStormTrack2 = polylinesTropicalDisturbance_StormTrackHistory[iX];
	
							if (isEnabled_Tropical_StormTrackHistory)
							{
								polylineStormTrack2.setMap(mapCanvas);
							}
							else
							{
								polylineStormTrack2.setMap(null);
							}
						}
						catch (ex_TropicalCyclone_Invests_StormTrackHistory2)
						{
						}
					}
					
					break;
					
					
					
                case "Weather_NWS_Alerts":
                case "Weather_NWS_Radar":

					var layerID;

					switch (layerName)
					{
						case "Weather_NWS_Alerts":
							layerID = 4;
							break;
							
						case "Weather_NWS_Radar":
							layerID = 3;
							break;
					}


					// Use the unique Layer ID to tell the map where to set to null...switch the layer out with a null. This effectively removes the layer from the map canvas...
					try
					{
						if (mapCanvas.overlayMapTypes.getLength() > 0)
						{
							mapCanvas.overlayMapTypes.setAt(layerID, null);
						}
					}
					catch (ex_Weather_NWS)
					{
					}
					


					var urlWMS = "";
					
					switch (layerName)
					{
						case "Weather_NWS_Alerts":
							//this.setLegendOverlay_Weather_NWS_Alerts();
							
							if (document.myForm.checkboxWeather_NWS_Alerts.checked)
							{
								//	urlWMS = urlWMS_Weather_NWS_Alerts;
								urlWMS = urlWMS_Weather_NWS_Warnings_ShortDuration;
							}
							break;
							
						case "Weather_NWS_Radar":
							
							if (document.myForm.checkboxWeather_NWS_Radar.checked)
							{
								urlWMS = urlWMS_Weather_NWS_Radar;
							}
							break;
					}


					if (urlWMS != "")
					{
						var overlayOptions = 
						{
							getTileUrl: 
								function WMS_GetTileUrl(coord, zoom) 
								{
									var projection = mapCanvas.getProjection();
									
									var zpow = Math.pow(2, zoom);
									
									var lULP = new google.maps.Point(coord.x * 256.0 / zpow, (coord.y + 1) * 256.0 / zpow);
									var lLRP = new google.maps.Point((coord.x + 1) * 256.0 / zpow, coord.y * 256.0 / zpow);
									
									var lULg = projection.fromPointToLatLng(lULP);
									var lLRg = projection.fromPointToLatLng(lLRP);
									
									var lULg_Longitude = lULg.lng();  
									var lULg_Latitude = lULg.lat();
									var lLRg_Longitude = lLRg.lng();
									var lLRg_Latitude = lLRg.lat();
									
									// There seems to be a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it...
									if (lLRg_Longitude < lULg_Longitude)
									{
									    lLRg_Longitude = Math.abs(lLRg_Longitude);
									}
							
									// Create the Bounding Box string
									var bbox = "&bbox=" + lULg_Longitude + "," + lULg_Latitude + "," + lLRg_Longitude + "," + lLRg_Latitude;

									var urlResult = urlWMS + bbox;
							
									return urlResult;
								},
								
							tileSize: new google.maps.Size(256, 256),
							
							minZoom: minZoomLevel_DEFAULT,
							maxZoom: 15,
							
							opacity: 0.70,
							
							isPng: true
						};	
						
						var overlayWMS = new google.maps.ImageMapType(overlayOptions);
		
						mapCanvas.overlayMapTypes.setAt(layerID, overlayWMS);
					}


					// Build the NWS legend block...
					mapLegendElements = mapLegendElements.replace(overlayLegend_Weather_NWS_Top, "");
					mapLegendElements = mapLegendElements.replace(overlayLegend_Weather_NWS_Warnings_ShortDuration, "");
					mapLegendElements = mapLegendElements.replace(overlayLegend_Weather_NWS_Radar, "");
					mapLegendElements = mapLegendElements.replace(overlayLegend_Weather_NWS_Bottom, "");


					if (document.myForm.checkboxWeather_NWS_Alerts.checked | document.myForm.checkboxWeather_NWS_Radar.checked)
					{
						mapLegendElements = mapLegendElements + 
											overlayLegend_Weather_NWS_Top;
	
						if (document.myForm.checkboxWeather_NWS_Alerts.checked)
						{
							mapLegendElements += overlayLegend_Weather_NWS_Warnings_ShortDuration;
						}
						
						if (document.myForm.checkboxWeather_NWS_Radar.checked)
						{
							mapLegendElements += overlayLegend_Weather_NWS_Radar;
						}
	
						mapLegendElements += overlayLegend_Weather_NWS_Bottom;
					}
					
                    document.getElementById('overlayLegendBlock').innerHTML = mapLegendElements;
					break;
					
					
				
				case "Fire_USFS_RSAC_Incidents":
                    isEnabled_Fire_USFS_RSAC_Incidents = (document.myForm.checkboxFire_USFS_RSAC_Incidents.checked);

					for (var iX = 0; iX < markersFire_USFS_RSAC_Incidents.length; iX++) 
					{
						markersFire_USFS_RSAC_Incidents[iX].setVisible(isEnabled_Fire_USFS_RSAC_Incidents);
					}

                    if (isEnabled_Fire_USFS_RSAC_Incidents & markersFire_USFS_RSAC_Incidents.length == 0)
					{   
					    this.fetchData(layerName);			
					}
					break;
					
					
					
				case "Fire_USFS_RSAC_HotSpots":
				case "Fire_USFS_RSAC_HotSpots_12Hours":
				case "Fire_USFS_RSAC_HotSpots_12to24Hours":
                    isEnabled_Fire_USFS_RSAC_HotSpots = (document.myForm.checkboxFire_USFS_RSAC_HotSpots.checked);


					var isEnabled_Fire_USFS_RSAC_HotSpots_12Hours =
						(isEnabled_Fire_USFS_RSAC_HotSpots & document.myForm.checkboxFire_USFS_RSAC_HotSpots_12Hours.checked) ? true : false;

					for (var iX = 0; iX < markersFire_USFS_RSAC_HotSpots_12Hours.length; iX++) 
					{
						markersFire_USFS_RSAC_HotSpots_12Hours[iX].setVisible(isEnabled_Fire_USFS_RSAC_HotSpots_12Hours);
					}
					
					
					var isEnabled_Fire_USFS_RSAC_HotSpots_12to24Hours =
						(isEnabled_Fire_USFS_RSAC_HotSpots & document.myForm.checkboxFire_USFS_RSAC_HotSpots_12to24Hours.checked) ? true : false;

					for (var iX = 0; iX < markersFire_USFS_RSAC_HotSpots_12to24Hours.length; iX++) 
					{
						markersFire_USFS_RSAC_HotSpots_12to24Hours[iX].setVisible(isEnabled_Fire_USFS_RSAC_HotSpots_12to24Hours);
					}


					if (layerName == "Fire_USFS_RSAC_HotSpots" & isEnabled_Fire_USFS_RSAC_HotSpots &
						markersFire_USFS_RSAC_HotSpots_12Hours.length == 0 & markersFire_USFS_RSAC_HotSpots_12to24Hours.length == 0)
					{
					    this.fetchData(layerName);			
					}
					break;
					
					
					
				case "Fire_GEOMAC_ActivePerimeters":
                    isEnabled_Fire_GEOMAC_ActivePerimeters = (document.myForm.checkboxFire_GEOMAC_ActivePerimeters.checked);
				
					if (isEnabled_Fire_GEOMAC_ActivePerimeters)
					{
						this.fetchData(layerName);	// Only load this layer if user manually selects it...
					}
					else
					{
						polygonsFire_GEOMAC_Incidents.setMap(null); 
					}
				    break;
				    
				    
				    
				case "Fire_FIRMS_HotSpots":
				
					var layerID = 5;


					// Use the unique Layer ID to tell the map where to set to null...switch the layer out with a null. This effectively removes the layer from the map canvas...
					try
					{
						if (mapCanvas.overlayMapTypes.getLength() > 0)
						{
							mapCanvas.overlayMapTypes.setAt(layerID, null);
						}
					}
					catch (ex_Fire_FIRMS_HotSpots)
					{
					}


					if (document.myForm.checkboxFire_FIRMS_Hotspots.checked)
					{

						var tileWidth = 400;
						var tileHeight = 400;
						var minZoomLevel = minZoomLevel_DEFAULT;
						var maxZoomLevel = 15;
						var opacityLevel = 1.0;
						var isPng = false;
						
						var urlWMS = urlWMS_Fire_FIRMS_Hotspots + "&width=" + tileWidth + "&height=" + tileHeight;

						var overlayOptions = 
						{
							getTileUrl: 
								function WMS_GetTileUrl(coord, zoom) 
								{
									var projection = mapCanvas.getProjection();
									
									var zpow = Math.pow(2, zoom);
									
									var lULP = new google.maps.Point(coord.x * 256.0 / zpow, (coord.y + 1) * 256.0 / zpow);
									var lLRP = new google.maps.Point((coord.x + 1) * 256.0 / zpow, coord.y * 256.0 / zpow);
									
									var lULg = projection.fromPointToLatLng(lULP);
									var lLRg = projection.fromPointToLatLng(lLRP);
									
									var lULg_Longitude = lULg.lng();  
									var lULg_Latitude = lULg.lat();
									var lLRg_Longitude = lLRg.lng();
									var lLRg_Latitude = lLRg.lat();
									
									// There seems to be a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it...
									if (lLRg_Longitude < lULg_Longitude)
									{
									    lLRg_Longitude = Math.abs(lLRg_Longitude);
									}
							
									// Create the Bounding Box string
									var bbox = "&bbox=" + lULg_Longitude + "," + lULg_Latitude + "," + lLRg_Longitude + "," + lLRg_Latitude;

									var urlResult = urlWMS + bbox;
							
									return urlResult;
								},
							
							tileSize: new google.maps.Size(256, 256),
							
							minZoom: minZoomLevel,
							maxZoom: maxZoomLevel,
							
							opacity: opacityLevel,
							
							isPng: isPng
						};			


						var overlayWMS = new google.maps.ImageMapType(overlayOptions);
    		
						mapCanvas.overlayMapTypes.setAt(layerID, overlayWMS);
					}
					break;
					
					
				
				case "Satellite_Checkbox":
				case "Satellite_Radio":

					var layerID = 1;


					// Use the unique Layer ID to tell the map where to set to null...switch the layer out with a null. This effectively removes the layer from the map canvas...
					try
					{
						if (mapCanvas.overlayMapTypes.getLength() > 0)
						{
							mapCanvas.overlayMapTypes.setAt(layerID, null);
						}
					}
					catch (ex_Satellite)
					{
					}
					

					// Update the map legend to remove any existing custom layer legend element...
					mapLegendElements = mapLegendElements.replace(overlayLegend_Satellite, "");



					if (document.myForm.checkboxSatellite.checked)
					{
						
    				    // Reset for new custom layer legend element...
					    overlayLegend_Satellite = "";
					
						
						var tileWidth = 256;
						var tileHeight = 256;
						var minZoomLevel = minZoomLevel_DEFAULT;
						var maxZoomLevel = 7;
						var opacityLevel;
						var isPng;
						
						var urlWMS = "";
						

						// NASA LANCE MODIS Terra
						if (document.myForm.radioSatellite[0].checked)
						{
							maxZoomLevel = 10;
							opacityLevel = 1.0;
							isPng = false;
							
							urlWMS = urlWMS_NASA_GSFC_MODIS_Terra;
							
							// Set "Today Date" parameters...
							var dateToday = new Date();
							
							var currentYearNumber = (dateToday.getFullYear()).toString();
							
							var currentMonthNumber = (dateToday.getMonth() + 1).toString();
							if (currentMonthNumber.length == 1) {currentMonthNumber = "0" + currentMonthNumber};

							var currentDayNumber = (dateToday.getDate()).toString();
							if (currentDayNumber.length == 1) {currentDayNumber = "0" + currentDayNumber};

							//urlWMS = urlWMS.replace("<TODAY_DATE>", currentYearNumber + currentMonthNumber + currentDayNumber);
							urlWMS = urlWMS.replace(",Terra_<TODAY_DATE>", "");
							
							
							// Set "Yesterday Date" parameters...
							var dateYesterday = new Date();
							
							dateYesterday.setDate(dateToday.getDate() - 1);
							
							currentYearNumber = (dateYesterday.getFullYear()).toString();
							
							currentMonthNumber = (dateYesterday.getMonth() + 1).toString();
							if (currentMonthNumber.length == 1) {currentMonthNumber = "0" + currentMonthNumber};

							currentDayNumber = (dateYesterday.getDate()).toString();
							if (currentDayNumber.length == 1) {currentDayNumber = "0" + currentDayNumber};
							
							urlWMS = urlWMS.replace("<YESTERDAY_DATE>", currentYearNumber + currentMonthNumber + currentDayNumber);
						}
						
			
						// NASA GOES / METEOSTAT / GMS Composite (Infrared)
						else if (document.myForm.radioSatellite[1].checked)
						{
							maxZoomLevel = 10;
							opacityLevel = 1.0;
							isPng = true;
							
							urlWMS = urlWMS_NASA_CPC_Infrared_CloudCover;
						}
						
						// NASA LANCE GES-DISC AIRS RGB
						else if (document.myForm.radioSatellite[2].checked)
						{
							opacityLevel = 0.70;
							isPng = true;
							
							urlWMS = urlWMS_NASA_LANCE_GESDISC_AIRS_RGB;
						}
						
						// NASA LANCE GES-DISC AIRS SO2
						else if (document.myForm.radioSatellite[3].checked)
						{
							opacityLevel = 0.70;
							isPng = true;
							
							urlWMS = urlWMS_NASA_LANCE_GESDISC_AIRS_S02;
							
							overlayLegend_Satellite = legendImage_NASA_GESDISC_AIRS_S02;
						}
			
						// NASA OMI AURA SO2
						else if (document.myForm.radioSatellite[4].checked)
						{
							opacityLevel = 0.70;
							isPng = true;
							
							urlWMS = urlWMS_NASA_OMI_AURA_S02;
							
							overlayLegend_Satellite = legendImage_NASA_OMI_AURA_S02;
						}
			
						// NOAA GOES (Visible)
						else if (document.myForm.radioSatellite[5].checked)
						{
							maxZoomLevel = 10;
							opacityLevel = 1.0;
							isPng = true;
							
							urlWMS = urlWMS_NOAA_GOES_CloudCover.replace("<TYPE>", "RAS_GOES");
						}
			
						// NOAA GOES (Infared)
						else if (document.myForm.radioSatellite[6].checked)
						{
							maxZoomLevel = 10;
							opacityLevel = 1.0;
							isPng = true;
							
							urlWMS = urlWMS_NOAA_GOES_CloudCover.replace("<TYPE>", "RAS_GOES_I4");
						}
						

						urlWMS += "&width=" + tileWidth + "&height=" + tileHeight;

						var overlayOptions = 
						{
							getTileUrl: 
								function WMS_GetTileUrl(coord, zoom) 
								{
									var projection = mapCanvas.getProjection();
									
									var zpow = Math.pow(2, zoom);
									
									var lULP = new google.maps.Point(coord.x * 256.0 / zpow, (coord.y + 1) * 256.0 / zpow);
									var lLRP = new google.maps.Point((coord.x + 1) * 256.0 / zpow, coord.y * 256.0 / zpow);
									
									var lULg = projection.fromPointToLatLng(lULP);
									var lLRg = projection.fromPointToLatLng(lLRP);
									
									var lULg_Longitude = lULg.lng();  
									var lULg_Latitude = lULg.lat();
									var lLRg_Longitude = lLRg.lng();
									var lLRg_Latitude = lLRg.lat();
									
									// There seems to be a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it...
									if (lLRg_Longitude < lULg_Longitude)
									{
									    lLRg_Longitude = Math.abs(lLRg_Longitude);
									}
							
									// Create the Bounding Box string
									var bbox = "&bbox=" + lULg_Longitude + "," + lULg_Latitude + "," + lLRg_Longitude + "," + lLRg_Latitude;

									var urlResult = urlWMS + bbox;
							
									return urlResult;
								},
							
							tileSize: new google.maps.Size(256, 256),
							
							minZoom: minZoomLevel,
							maxZoom: maxZoomLevel,
							
							opacity: opacityLevel,
							
							isPng: isPng
						};			


						var overlayWMS = new google.maps.ImageMapType(overlayOptions);
    		
						mapCanvas.overlayMapTypes.setAt(layerID, overlayWMS);



                        // Update the map legend block...                    
                        if (overlayLegend_Satellite != "")
                        {
                            mapLegendElements = overlayLegend_Satellite + mapLegendElements;
                        }                 
					}


                    document.getElementById('overlayLegendBlock').innerHTML = mapLegendElements;
					break;



				case "OtherLayers_DayNightTerminator_Checkbox":

					var layerID = 2;


					// Use the unique Layer ID to tell the map where to set to null...switch the layer out with a null. This effectively removes the layer from the map canvas...
					try
					{
						if (mapCanvas.overlayMapTypes.getLength() > 0)
						{
							mapCanvas.overlayMapTypes.setAt(layerID, null);
						}
					}
					catch (ex_OtherLayers_DayNightTerminator)
					{
					}
					
					
					try
					{
						// Day/night terminator custom map layer...
						if (document.myForm.checkboxOtherLayers_DayNightTerminator.checked)
						{
							//mapCanvas.overlayMapTypes.setAt(layerID, overlayDayNightTerminator);
						    mapCanvas.overlayMapTypes.insertAt(layerID, overlayDayNightTerminator);
						    overlayDayNightTerminator.setMap(mapCanvas);

						    overlayDayNightTerminator.setAutoRefresh(60);		// Update every 60 seconds...
							overlayDayNightTerminator.setShowLights(document.myForm.checkboxOtherLayers_DayNightTerminator_CityLights.checked);		// Optional - show city lights in night areas...
						}
					}
					catch (ex_OtherLayers_DayNightTerminator2)
					{
					}
					break;
					


				case "OtherLayers_Thematic_Checkbox":
				case "OtherLayers_Thematic_Radio":

					var layerID = 0;  // (bottom level overlay)


					// Use the unique Layer ID to tell the map where to set to null...switch the layer out with a null. This effectively removes the layer from the map canvas...
					try
					{
						if (mapCanvas.overlayMapTypes.getLength() > 0)
						{
							mapCanvas.overlayMapTypes.setAt(layerID, null);
						}
					}
					catch (ex_OtherLayers_Thematic)
					{
					}
					

					// Update the map legend to remove any existing custom layer legend element...
					mapLegendElements = mapLegendElements.replace(overlayLegend_Thematic, "");



					if (document.myForm.checkboxOtherLayers_Thematic.checked)
					{
    				    // Reset for new custom layer legend element...
					    overlayLegend_Thematic = "";
						
						
						var tileWidth;
						var tileHeight;
						var minZoomLevel = minZoomLevel_DEFAULT;
						var maxZoomLevel = 7;
						var opacityLevel;
						var isPng;
						
						var urlWMS = "";
						

						// NASA JPL - BLUE MARBLE "NEXT GENERATION"
						if (document.myForm.radioOtherLayers_Thematic[0].checked)
						{
							tileWidth = 256;
							tileHeight = 256;
							opacityLevel = 1.0;
							isPng = false;
							
							var bmng_selectedIndex = document.myForm.dropdownOtherLayers_Thematic_BlueMarble.selectedIndex;
							
							var bmng_SeasonalView = "2004" + document.myForm.dropdownOtherLayers_Thematic_BlueMarble.options[bmng_selectedIndex].value + "01";

							urlWMS = urlWMS_NASA_BlueMarble.replace("<DATE>", bmng_SeasonalView);
							
							if(!document.myForm.checkboxOtherLayers_Thematic_BlueMarble.checked)
							{
								urlWMS = urlWMS.replace("TOPO_BATHY_", "");
							}
						}
			
						// CIESIN SEDAC - POPULATION DENSITY
						else if (document.myForm.radioOtherLayers_Thematic[1].checked)
						{
							tileWidth = 256;
							tileHeight = 256;
							opacityLevel = 0.60;
							isPng = true;
							
							urlWMS = urlWMS_CIESIN_SEDAC_PopulationDensity;
							
							overlayLegend_Thematic = legendImage_CIESIN_SEDAC_PopulationDensity;
						}
						
						// CIESIN SEDAC - EARTHQUAKE FREQUENCY & DISTRIBUTION
						else if (document.myForm.radioOtherLayers_Thematic[2].checked)
						{
							tileWidth = 256;
							tileHeight = 256;
							opacityLevel = 0.60;
							isPng = true;

							urlWMS = urlWMS_CIESIN_SEDAC_Hazard_Frequency_Distribution.replace("<HAZARD_TYPE>", "earthquake")
							
							overlayLegend_Thematic = legendImage_CIESIN_SEDAC_NaturalDisasterHotspots;
						}

			            // CIESIN SEDAC - VOLCANO FREQUENCY & DISTRIBUTION
			            else if (document.myForm.radioOtherLayers_Thematic[3].checked) 
                        {
			                tileWidth = 256;
			                tileHeight = 256;
			                opacityLevel = 0.60;
			                isPng = true;

			                urlWMS = urlWMS_CIESIN_SEDAC_Hazard_Frequency_Distribution.replace("<HAZARD_TYPE>", "volcano-hazard")

			                overlayLegend_Thematic = legendImage_CIESIN_SEDAC_NaturalDisasterHotspots;
			            }

			            // CIESIN SEDAC - FLOOD FREQUENCY & DISTRIBUTION
			            else if (document.myForm.radioOtherLayers_Thematic[4].checked) 
                        {
			                tileWidth = 256;
			                tileHeight = 256;
			                opacityLevel = 0.60;
			                isPng = true;

			                urlWMS = urlWMS_CIESIN_SEDAC_Hazard_Frequency_Distribution.replace("<HAZARD_TYPE>", "flood-hazard")

			                overlayLegend_Thematic = legendImage_CIESIN_SEDAC_NaturalDisasterHotspots;
			            }
						
						
						urlWMS += "&width=" + tileWidth + "&height=" + tileHeight;


						var overlayOptions = 
						{
							getTileUrl: 
								function WMS_GetTileUrl(coord, zoom) 
								{
									var projection = mapCanvas.getProjection();
									
									var zpow = Math.pow(2, zoom);
									
									var lULP = new google.maps.Point(coord.x * 256.0 / zpow, (coord.y + 1) * 256.0 / zpow);
									var lLRP = new google.maps.Point((coord.x + 1) * 256.0 / zpow, coord.y * 256.0 / zpow);
									
									var lULg = projection.fromPointToLatLng(lULP);
									var lLRg = projection.fromPointToLatLng(lLRP);
									
									var lULg_Longitude = lULg.lng();  
									var lULg_Latitude = lULg.lat();
									var lLRg_Longitude = lLRg.lng();
									var lLRg_Latitude = lLRg.lat();
									
									// There seems to be a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it...
									if (lLRg_Longitude < lULg_Longitude)
									{
									    lLRg_Longitude = Math.abs(lLRg_Longitude);
									}
							
									// Create the Bounding Box string
									var bbox = "&bbox=" + lULg_Longitude + "," + lULg_Latitude + "," + lLRg_Longitude + "," + lLRg_Latitude;

									var urlResult = urlWMS + bbox;
							
									return urlResult;
								},
							
							tileSize: new google.maps.Size(256, 256),
							
							minZoom: minZoomLevel,
							maxZoom: maxZoomLevel,
							
							opacity: opacityLevel,
							
							isPng: isPng
						};			
						

						var overlayWMS = new google.maps.ImageMapType(overlayOptions);
    		
						mapCanvas.overlayMapTypes.setAt(layerID, overlayWMS);



						// Update the map legend block...                    
                        if (overlayLegend_Thematic != "")
                        {
                            mapLegendElements = overlayLegend_Thematic + mapLegendElements;
                        }                 
					}


					else if (layerName == "OtherLayers_Thematic_Checkbox")
					{
                        mapLegendElements = mapLegendElements.replace(overlayLegend_Thematic, "");
					}


                    document.getElementById('overlayLegendBlock').innerHTML = mapLegendElements;
					break;
					
				

				case "OtherLayers_Webcams_Volcano":
                    isEnabled_OtherLayers_Webcams_Volcano = (!isEnabled_OtherLayers_Webcams_Volcano)

                    switch (isEnabled_OtherLayers_Webcams_Volcano)
					{
					    case true:
					        if (markersOtherLayers_Webcams_Volcano.length == 0)
					        {
						        // Fetch the data for this layer one time only...
						        this.fetchData(layerName);			
					        }
					        else
					        {
						        for (var iX = 0; iX < markersOtherLayers_Webcams_Volcano.length; iX++) 
						        {
							        markersOtherLayers_Webcams_Volcano[iX].setVisible(true);
						        }
					        }
					        break;
					        
					    case false:
						    for (var iX = 0; iX < markersOtherLayers_Webcams_Volcano.length; iX++) 
						    {
							    markersOtherLayers_Webcams_Volcano[iX].setVisible(false);
						    }
					        break;
					}
					break;

					
					
				case "OtherLayers_News_VolcanoLive":
                    isEnabled_OtherLayers_News_VolcanoLive = (!isEnabled_OtherLayers_News_VolcanoLive)

                    switch (isEnabled_OtherLayers_News_VolcanoLive)
					{   
					    case true:
				            // Fetch the the latest data for this layer every time the user turns it on...
						    this.fetchData(layerName);			
					        break;
					        
					    case false:
						    for (var iX = 0; iX < markersOtherLayers_News_VolcanoLive.length; iX++) 
						    {
							    markersOtherLayers_News_VolcanoLive[iX].setVisible(false);
						    }
					        break;
					}
					break;
				    
					
					
				case "History_NGDC_SignificantEvents_Earthquake":
				case "History_NGDC_SignificantEvents_Tsunami":
				case "History_NGDC_SignificantEvents_Volcano":
				case "History_NGDC_SignificantEvents_DateRange":
				
					// Reset...
                    markerclusterHistory.clearMarkers();
                    
                    
					// * EARTHQUAKE *
                    var isChecked_History_SignificantEvents_Earthquake = (document.myForm.checkboxHistory_NGDC_SignificantEvents_Earthquake.checked);
                    
					if (layerName == "History_NGDC_SignificantEvents_Earthquake" & isChecked_History_SignificantEvents_Earthquake & markersHistory_Earthquake_1950ADtoPresent.length == 0)
					{
                        this.fetchData(layerName);
					}
					
					else
					{
					    isEnabled_History_Earthquake_1950ADtoPresent =
						    (isChecked_History_SignificantEvents_Earthquake & document.myForm.checkboxHistory_NGDC_SignificantEvents_1950ADtoPresent.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Earthquake_1950ADtoPresent.length; iX++) 
					    {
					        if (isEnabled_History_Earthquake_1950ADtoPresent)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Earthquake_1950ADtoPresent[iX]);
					        }
					    }
    						
    					
					    isEnabled_History_Earthquake_1900to1949AD = 
						    (isChecked_History_SignificantEvents_Earthquake & document.myForm.checkboxHistory_NGDC_SignificantEvents_1900to1949AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Earthquake_1900to1949AD.length; iX++) 
					    {
					        if (isEnabled_History_Earthquake_1900to1949AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Earthquake_1900to1949AD[iX]);
					        }
					    }


					    isEnabled_History_Earthquake_1800to1899AD = 
						    (isChecked_History_SignificantEvents_Earthquake & document.myForm.checkboxHistory_NGDC_SignificantEvents_1800to1899AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Earthquake_1800to1899AD.length; iX++) 
					    {
					        if (isEnabled_History_Earthquake_1800to1899AD)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Earthquake_1800to1899AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Earthquake_1500to1799AD = 
						    (isChecked_History_SignificantEvents_Earthquake & document.myForm.checkboxHistory_NGDC_SignificantEvents_1500to1799AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Earthquake_1500to1799AD.length; iX++) 
					    {
					        if (isEnabled_History_Earthquake_1500to1799AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Earthquake_1500to1799AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Earthquake_5000BCto1499AD = 
						    (isChecked_History_SignificantEvents_Earthquake & document.myForm.checkboxHistory_NGDC_SignificantEvents_5000BCto1499AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Earthquake_5000BCto1499AD.length; iX++) 
					    {
					        if (isEnabled_History_Earthquake_5000BCto1499AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Earthquake_5000BCto1499AD[iX]);
					        }
					    }
					}
							
							
					// * TSUNAMI *	
                    var isChecked_History_SignificantEvents_Tsunami = (document.myForm.checkboxHistory_NGDC_SignificantEvents_Tsunami.checked);
                    
					if (layerName == "History_NGDC_SignificantEvents_Tsunami" & isChecked_History_SignificantEvents_Tsunami & markersHistory_Tsunami_1950ADtoPresent.length == 0)
					{
                        this.fetchData(layerName);
					}
					
					else
					{
					    isEnabled_History_Tsunami_1950ADtoPresent =
						    (isChecked_History_SignificantEvents_Tsunami & document.myForm.checkboxHistory_NGDC_SignificantEvents_1950ADtoPresent.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Tsunami_1950ADtoPresent.length; iX++) 
					    {
					        if (isEnabled_History_Tsunami_1950ADtoPresent)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Tsunami_1950ADtoPresent[iX]);
					        }
					    }
    						
    					
					    isEnabled_History_Tsunami_1900to1949AD = 
						    (isChecked_History_SignificantEvents_Tsunami & document.myForm.checkboxHistory_NGDC_SignificantEvents_1900to1949AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Tsunami_1900to1949AD.length; iX++) 
					    {
					        if (isEnabled_History_Tsunami_1900to1949AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Tsunami_1900to1949AD[iX]);
					        }
					    }


					    isEnabled_History_Tsunami_1800to1899AD = 
						    (isChecked_History_SignificantEvents_Tsunami & document.myForm.checkboxHistory_NGDC_SignificantEvents_1800to1899AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Tsunami_1800to1899AD.length; iX++) 
					    {
					        if (isEnabled_History_Tsunami_1800to1899AD)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Tsunami_1800to1899AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Tsunami_1500to1799AD = 
						    (isChecked_History_SignificantEvents_Tsunami & document.myForm.checkboxHistory_NGDC_SignificantEvents_1500to1799AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Tsunami_1500to1799AD.length; iX++) 
					    {
					        if (isEnabled_History_Tsunami_1500to1799AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Tsunami_1500to1799AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Tsunami_5000BCto1499AD = 
						    (isChecked_History_SignificantEvents_Tsunami & document.myForm.checkboxHistory_NGDC_SignificantEvents_5000BCto1499AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Tsunami_5000BCto1499AD.length; iX++) 
					    {
					        if (isEnabled_History_Tsunami_5000BCto1499AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Tsunami_5000BCto1499AD[iX]);
					        }
					    }
					}
					
					
					
					// * VOLCANO *	
                    var isChecked_History_SignificantEvents_Volcano = (document.myForm.checkboxHistory_NGDC_SignificantEvents_Volcano.checked);
                    
					if (layerName == "History_NGDC_SignificantEvents_Volcano" & isChecked_History_SignificantEvents_Volcano & markersHistory_Volcano_1950ADtoPresent.length == 0)
					{
                        this.fetchData(layerName);
					}
					
					else
					{
					    isEnabled_History_Volcano_1950ADtoPresent =
						    (isChecked_History_SignificantEvents_Volcano & document.myForm.checkboxHistory_NGDC_SignificantEvents_1950ADtoPresent.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Volcano_1950ADtoPresent.length; iX++) 
					    {
					        if (isEnabled_History_Volcano_1950ADtoPresent)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Volcano_1950ADtoPresent[iX]);
					        }
					    }
    						
    					
					    isEnabled_History_Volcano_1900to1949AD = 
						    (isChecked_History_SignificantEvents_Volcano & document.myForm.checkboxHistory_NGDC_SignificantEvents_1900to1949AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Volcano_1900to1949AD.length; iX++) 
					    {
					        if (isEnabled_History_Volcano_1900to1949AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Volcano_1900to1949AD[iX]);
					        }
					    }


					    isEnabled_History_Volcano_1800to1899AD = 
						    (isChecked_History_SignificantEvents_Volcano & document.myForm.checkboxHistory_NGDC_SignificantEvents_1800to1899AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Volcano_1800to1899AD.length; iX++) 
					    {
					        if (isEnabled_History_Volcano_1800to1899AD)
					        {
    						    markerclusterHistory.addMarker(markersHistory_Volcano_1800to1899AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Volcano_1500to1799AD = 
						    (isChecked_History_SignificantEvents_Volcano & document.myForm.checkboxHistory_NGDC_SignificantEvents_1500to1799AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Volcano_1500to1799AD.length; iX++) 
					    {
					        if (isEnabled_History_Volcano_1500to1799AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Volcano_1500to1799AD[iX]);
					        }
					    }
    					
    					
					    isEnabled_History_Volcano_5000BCto1499AD = 
						    (isChecked_History_SignificantEvents_Volcano & document.myForm.checkboxHistory_NGDC_SignificantEvents_5000BCto1499AD.checked) ? true : false;
    					
					    for (var iX = 0; iX < markersHistory_Volcano_5000BCto1499AD.length; iX++) 
					    {
					        if (isEnabled_History_Volcano_5000BCto1499AD)
					        {
						        markerclusterHistory.addMarker(markersHistory_Volcano_5000BCto1499AD[iX]);
					        }
					    }
                    }
                    
					break;

			}
			
		}

		catch (ex1)
		{
			document.getElementById('errorMessage').innerHTML = "function 'toggleLayer' -- Error: " + ex1.description;
		}
	}



	//
	// *** TO DO! ***
	//

	//
	// Map event handlers...
	//

	function onLinkClicked_DisplayMarkerInfoWindow(hazardType, iX)
	{
		switch (hazardType)
		{
			case "Earthquake":
				google.maps.event.trigger(markersEarthquake[iX], "click");
				break;
				
			case "Tsunami":
				google.maps.event.trigger(markersTsunami[iX], "click");
				break;
				
			case "TropicalCyclone":
				google.maps.event.trigger(markersTropicalCyclone[iX], "click");
				break;
		}
	}

