// nowcoast.js


var obs_pt_wx_Text = new Array("Air Temp","Cloud Cover","Dewpoint","Precipitation","Pressure","Rel. Humidity","Snowfall","Solar Radiation","Visibility","Weather","Winds");
var obs_pt_wx_Value = new Array("AirTemp","CldCvr","DewPt","Precip","MSLP","RelHum","Snowfall","SolarRad","Vis","Weather","Winds");
var obs_pt_oc_Text = new Array("Currents","Salinity","Sea Surface Temp","Sea Sub-Sfc. Temp","Water Level/Height","Waves","Air Gap");
var obs_pt_oc_Value = new Array("Currents","Salinity","SSurTmp","SSubTmp","WLevel","Waves","AirGap");
var obs_pt_riv_Text = new Array("Discharge/Flow","Gage Height","Stream Velocity","Water Elevation (Lake)","Water Temp");
var obs_pt_riv_Value = new Array("Discharge","GageHeight","StreamVel","Elev_Water","WaterTemp");
var obs_pt_wq_Text = new Array("Chlorophyll","Conductivity","DO Concentration","DO Saturation","pH","Sediment","Turbidity");
var obs_pt_wq_Value = new Array("Chlor","Conduct","DOConc","DOSat","PH","Sediment","Turbidity");
var obs_pt_aq_Text = new Array("Ozone","Particles (PM2.5)","- All Variables -");
var obs_pt_aq_Value = new Array("OZONE","PM2_5","");

var obs_pt_wr_Text = new Array("Reflectivity");	
var obs_pt_wr_Value = new Array("");	
var obs_pt_blp_Text = new Array();
var obs_pt_blp_Value = new Array();	
var obs_pt_rs_Text = new Array();
var obs_pt_rs_Value = new Array();	
var obs_pg_hfr_Text = new Array("Surface Currents");
var obs_pg_hfr_Value = new Array("SfcCurr");
var obs_pt_wc_Text = new Array();
var obs_pt_wc_Value = new Array();	

var pred_pt_at_Text = new Array("Water Level/Height");
var pred_pt_at_Value = new Array("WLevel");
var fcst_pt_wo_Text = new Array("Air Temp","Cloud Cover","Currents","Dew Point","Precip","Sea Sfc. Temp","Snowfall","Salinity","Visibility","Water Level/Height","Waves","Weather","Winds");
var fcst_pt_wo_Value = new Array("AirTemp","CldCvr","Currents","DewPt","Precip","SSurTmp","Snowfall","Salinity","Vis","WLevel","Waves","Weather","Winds");
var fcst_pt_wx_Text = new Array("Air Temp","Cloud Cover","Dew Point","Precip","Snowfall","Visibility","Weather","Winds");
var fcst_pt_wx_Value = new Array("AirTemp","CldCvr","DewPt","Precip","Snowfall","Vis","Weather","Winds");
var fcst_pt_oc_Text = new Array("Currents","Salinity","Sea Sfc. Temp","Water Level/Height","Waves");
var fcst_pt_oc_Value = new Array("Currents","Salinity","SSurTmp","WLevel","Waves");
var fcst_pt_aq_Text = new Array("Ozone","Particles (PM2.5)","Particles (PM10)","Carbon Monoxide","Nitrogen Dioxide","- All Variables -");
var fcst_pt_aq_Value = new Array("OZONE","PM2_5","PM10","CO","NO2","");

var fcst_pt_riv_Text = new Array("Stage");
var fcst_pt_riv_Value = new Array("Stage");
var fcst_pg_cfz_Text = new Array("Air Temp","Cloud Cover","Precip","Weather","Winds");
var fcst_pg_cfz_Value = new Array("AirTemp","CldCvr","Precip","Weather","Winds");
var fcst_pt_taf_Text = new Array();
var fcst_pt_taf_Value = new Array();
var fcst_pg_sz_Text = new Array("Sea Sfc. Temp","Visibility","Waves","Weather","Winds");
var fcst_pg_sz_Value = new Array("SSurTmp","Vis","Waves","Weather","Winds");
var fcst_pg_coz_Text = new Array("Visibility","Waves","Weather","Winds");
var fcst_pg_coz_Value = new Array("Vis","Waves","Weather","Winds");
var fcst_pg_hsz_Text = new Array();
var fcst_pg_hsz_Value = new Array();
//var fcst_pg_hsz_Text = new Array("Visibility","Waves","Weather","Winds");
//var fcst_pg_hsz_Value = new Array("Vis","Waves","Weather","Winds");
var fcst_pg_hab_Text = new Array();
var fcst_pg_hab_Value = new Array();

var fcstdis_pg_wx_Text = new Array("General, Marine, Aviation");
var fcstdis_pg_wx_Value = new Array("");
var fcstdis_pg_riv_Text = new Array("Precip & River Stage");
var fcstdis_pg_riv_Value = new Array("");

//var RAS_RADAR_Text = new Array("Reflectivity");
//var RAS_RADAR_Value = new Array("");
var RAS_RIDGE_NEXRAD_Text = new Array("Reflectivity");
var RAS_RIDGE_NEXRAD_Value = new Array("");
var RAS_GOES_Text = new Array("Visible Image");
var RAS_GOES_Value = new Array("");
var RAS_GOES_I4_Text = new Array("IR Image");
var RAS_GOES_I4_Value = new Array("");
var OBS_MET_Text = new Array("Air Temp","Dew Point","Wind","Pressure","Visibility","Sea Surface Temp","Sign. Wave Height","-All Variables-");
var OBS_MET_Value = new Array("OBS_MET_TEMP","OBS_MET_DP","OBS_MET_WIND","OBS_MET_PRES","OBS_MET_VIS","OBS_MAR_SSTF","OBS_MAR_SWHFT","");
var OBS_MAR_Text = new Array("","-All Variables-");
var OBS_MAR_Value = new Array("OBS_MAR_","");
var NCEP_ANAL_RTG_SST_Text = new Array("Sea Surface Temp");
var NCEP_ANAL_RTG_SST_Value = new Array("RTG_SST");
var NCEP_ANAL_RTG_SST_HR_Text = new Array("Sea Surface Temp");
var NCEP_ANAL_RTG_SST_HR_Value = new Array("RTG_SST");
var RTOFS_RAS_ATL_Text = new Array("Velocity");
var RTOFS_RAS_ATL_Value = new Array("RTOFS_ATL");
var WARN_SHORT_Text = new Array("Special Marine","Flash Flood","Flood","Severe Thunderstorm","Extreme Wind","Tornado","- All Warnings -");
var WARN_SHORT_Value = new Array("WARN_SHORT_SMW","WARN_SHORT_FFW","WARN_SHORT_FLW","WARN_SHORT_SVR","WARN_SHORT_EWW","WARN_SHORT_TOR","");
var NHC_TRACK_Text = new Array("- All Variables -");
var NHC_TRACK_Value = new Array("");
var NDFD_Text = new Array("Max Temp","Min Temp","Relative Humidity","Wind Speed","Wind Vel (Barb)","Wind Vel (Vector)","Sig Wave Height","Precip Amount");
var NDFD_Value = new Array("MAXT","MINT","RHM","WSPD","WIND","WINDVECT","WAVEH","QPF");

var NCOM_Text = new Array("Speed", "Sea Surface Temp");
var NCOM_Value = new Array("NCOM_SPD","NCOM_SST");

var SFC_CURRENTS_Text = new Array("w/Flow Speed","w/Sea Surface Temp","w/Total Water Levels");
var SFC_CURRENTS_Value = new Array("NCOM_RAS_SPD_DETAIL","NCOM_RAS_SST_DETAIL","NCOM_RAS_WL_DETAIL");

var RTMA_Text = new Array("Air Temp","Wind Speed","Wind Vel (Barb)","Wind Vel (Vector)");
var RTMA_Value = new Array("RTMA_AIRTEMP","RTMA_WSPD","RTMA_WIND","RTMA_WINDVECT");

var RTMA_QPE_Text = new Array("1-hr Accumulation");
var RTMA_QPE_Value = new Array("RTMA_RAS_QPE_1HR");

var NSSL_QPE_Text = new Array("1-hr Accumulation","3-hr Accumulation","6-hr Accumulation","12-hr Accumulation","24-hr Accumulation");
var NSSL_QPE_Value = new Array("NSSL_RAS_QPE_1HR","NSSL_RAS_QPE_3HR","NSSL_RAS_QPE_6HR","NSSL_RAS_QPE_12HR","NSSL_RAS_QPE_24HR");

var obsDisclaimer = "Observations from non-NOAA, DOD, or FAA stations should be\nconsidered experimental.  The reliability, quality, and representitiveness\nof these experimental observations can vary by station or observing \nnetwork. \n\n\nThe links to these experimental observations are provided as a \nconvenience to the user and does not represent an endorsement by \nNOS of the station or its observations.   The user assumes the entire risk \nrelated to use or misuse of the data (please see full disclaimer under Help).";
var webcamDisclaimer = "The reliability, quality, and representitiveness of these\nweb cameras can vary by location. Any commercial product\nassociated with the webcams are not endorsed by NOS/NOAA. \n\nThe links to these web cameras are provided as a convenience\nto the user and does not represent an endorsement by NOS.\nThe user assumes the entire risk related to use or misuse of the data.";
var obsDisclaimerDisplayed = false;
var webcamDisclaimerDisplayed = false;


var m = parent.MapFrame;


//****************GLOBAL VARIABLES BELOW*********************
//allows functions.js to check if jumpbar has been used
var jumpbarRefreshUsed = false;
var ncLayerID;
var ncLayerVariable;
var ncLayerVarName;
var ncLayerDisplay;

// boolean for jumpbarRefreshMap to test if the location pulldown has been changed, toggled to true in top.htm with onchange handler
var locationPulldownUsed = false; 

var selectLayerID;
var queryLayerID;

var infoText;					//infoText: text that is displayed in the 'info' window
var lyrNamePrefix = "";			//lyrNamePrefix and layerFeature type are text strings with information about the active layer
var layerFeatureType = "features";			//	such as name prefix and type of feature for alert popup msgs. set in setLayerInfo()

// new code here......


function jumpbarRefreshMap() {
	var locPulldown = parent.TopFrame.document.Jumpbar.elements[0];
	var dataPulldown = parent.TopFrame.document.Jumpbar.elements[1];
	var varPulldown = parent.TopFrame.document.Jumpbar.elements[2];
	var timePulldown = parent.TopFrame.document.Jumpbar.elements[3];
	var area = locationPulldownUsed ? locPulldown.options[locPulldown.selectedIndex].value : "";		//only if the pulldown has been moved
	var data = dataPulldown.options[dataPulldown.selectedIndex].value;
	var variable = varPulldown.options[varPulldown.selectedIndex].value;
	var time = timePulldown.options[timePulldown.selectedIndex].value;
	var selectArea = false;
	var selectData = false;
	var selectVariable = false;
	var selectTime = false;

	
	jumpbarRefreshUsed = true;
	
	if (area != "") {selectArea = true;}
	if (data != "") {selectData = true;}
	if ((variable != "") && (variable != "def")) {selectVariable = true;}
	if ((time != "") && (time != "def")) {selectTime = true;}
	
	if ((data == "NDFD") && (variable == "def" || time == "def")) {alert('Please select a Forecast Type and Time to display NDFD data');}
        if ((data == "RTMA" || data == "RTMA_QPE") && !selectVariable) {alert('Please select the desired RTMA Field from the Variable pulldown menu');}
        if ((data == "NCOM") && !selectVariable) {alert('Please select the desired NCOM Field from the Variable pulldown menu');}
        if ((data == "SFC_CURRENTS") && !selectVariable) {alert('Please select the desired Surface Currents background type from the Variable pulldown menu');}
	if (!selectArea && !selectData) {alert('Please enter a Location and Product and try again');}
	

	// change jspform values depending on input from jumpbar
	if (selectArea) {parseCoords(area)}	
	
	// if layer information was included in Jumpbar request, perform various actions to update map
	if (selectData) {
		var index = -1;
		
		// set background layer visibility
		if (!layerListAssociate) {			//layerListAssociate: conditional for associating jumpbar with layerlist: found in parameters.js
			setBackgroundLayersVisible(data);
		}

		switch (data) {
			
			case 'NDFD' :
				if (selectVariable && selectTime) {
					index = getLayerIndex(time);
                                        m.toc.closeNdfdGroups();
                                        m.toc.ndfdItemVisClick(index,1);
                                        
                                        //if (m && index != -1) m.toc.setParentVisibility(index,1);
                                        
                                        /*if ( time.indexOf("WIND") != -1 )  {
					    // if a wind layer, must turn on the group containing the merged layers
                                            // JRG Apr 2008:  Commented out WSPD--should be like other NDFD layers.
					    index = getLayerIndex(time);
					    if (m && index != -1) m.toc.setParentVisibility(index,1);
					    setActive(index); commented out--wind layers cannot be set active
					} else {
					    //index = getLayerIndex(time);
					    if (index != -1) {setVisible(index); setActive(index); }
					}*/
					parent.PostFrame.document.forms[0].ForecastLayer.value = time;
				}
				break;
                        case 'RTMA' :
                                if (selectVariable) {
                                    index = getLayerIndex(time);
                                    m.toc.groupItemVisClick(index,1);
                                }
                                break;
                        case 'RTMA_QPE' :
                                // Currently there's only one RTMA QPE layer, so
                                //  turn it on even if they don't select the time period
                                index = getLayerIndex(variable);
                                m.toc.itemVisClick(index,1);
                                break;
                        case 'NSSL_QPE' :
                                if (selectVariable) {
                                    if (selectTime)
                                      index = getLayerIndex(time);
                                    else
                                      index = getLayerIndex(variable);
                                    m.toc.itemVisClick(index,1);
                                }
                                break;
                        case 'NCOM' :
                                if (selectVariable) {
                                    index = getLayerIndex(time);
                                    m.toc.groupItemVisClick(index,1);
                                }
                                break;
                        case 'SFC_CURRENTS' :
                                if ( selectVariable ) {
                                    index = getLayerIndex(variable);
                                    m.toc.groupItemVisClick(index,1);
                                }
                                break;
                        case 'NCEP_ANAL_RTG_SST' :
                                index = getLayerIndex("NCEP_RAS_ANAL_RTG_SST");
                                if ( index != -1 ) {
                                    m.toc.sstVisClick(index,1);
                                }
                                break;
			// case for OBS_MET layers 
			case 'OBS_MET' :
				if (selectVariable) {
					index = getLayerIndex(variable);
					if (index != -1) {setVisible(index); setActive(index); }
				} else {
					for (i = OBS_MET_Value.length-1; i >= 0; i--) {
						index = getLayerIndex(OBS_MET_Value[i]);
						if (index != -1) {setVisible(index); setActive(index); }
					}
				}
				break;
			// case for OBS_MAR layers 
			case 'OBS_MAR' :
				if (selectVariable) {
					index = getLayerIndex(variable);
					if (index != -1) {setVisible(index); setActive(index); }
				} else {
					for (i = OBS_MAR_Value.length-1; i >= 0; i--) {
						index = getLayerIndex(OBS_MAR_Value[i]);
						if (index != -1) {setVisible(index); setActive(index); }
					}
				}
				break;
                        case 'WARN_SHORT' :
                                if ( selectVariable ) {
                                    index = getLayerIndex(variable);
                                    if (index != -1) {setVisible(index); setActive(index);}
                                } else {
                                    for (i = WARN_SHORT_Value.length-1; i>= 0; i--) {
                                        index = getLayerIndex(WARN_SHORT_Value[i]);
                                        if (index != -1) {setVisible(index); setActive(index);}
                                    }
                                }
                                break;
                        case 'NHC_TRACK' :
                                // Locate the NHC Cone of Uncertainty layer and set its 
                                //  parent group to visible (the cone of uncertainty layer
                                //  is a standalone LAYER whose parent is the Trop Cyclone Track
                                //  group...unlike some of the other NHC layers which are
                                //  grouped together into sub-groups to appear as a single layer)
                                index = getLayerIndex("NHC_TRACK_POLY");
                                m.toc.setParentVisibility(index,1);
                                break;
			// case for all other 'data' selections:
			//	for RTG_SST layers (NCEP_ANAL_RTG_SST and NCEP_ANAL_RTG_SST_HR), 
			//	do not execute doDynamicLayerStuff
			default :
				index = getLayerIndex(data);
				if (index != -1) {
					setVisible(index);
					if (m.LayerType[index].toUpperCase()=="FEATURE")
					    setActive(index); 
					if (data.indexOf("NCEP_ANAL_RTG_SST") == -1) {
						doDynamicLayerStuff(index,data);
					}
				}
				break;
		}
	}
	
	// reset the locationPulldownUsed boolean variable to false
	locationPulldownUsed = false;

	// display disclaimers if they haven't already been shown
	if ((obsDisclaimerDisplayed == false) && ((data == "obs_pt_wx") || (data == "obs_pt_oc"))) {
		obsDisclaimerDisplayed = true;
		alert(obsDisclaimer);
	} else if ((webcamDisclaimerDisplayed == false) && (data == "obs_pt_wc")) {
		webcamDisclaimerDisplayed = true;
		alert(webcamDisclaimer);
	}
	
	
	if (selectArea || selectData) {
		getMapImage();
	}

	//Refresh LayerList and LayerListTop
	parent.ListInfoFrame.location = "layerListTop.htm";
}


function doDynamicLayerStuff (index,data) {
	// only do the following if the the layer specified is a "Feature" layer (avoid Java Connector exceptions)
	if (LayerType[index] == "Feature") {
		addVariableLayer();
		//Activate hyperlink tool
		clickFunction('hyperlink');
		parent.ToolFrame.setToolPic('Hyperlink');
	}

}

function getLayerIndex (layerId) {
	for (var i=0;i<layerCount;i++) {
		if(LayerID[i] == layerId) {return i;}
	}
	return -1;
}



function setVisible(i) {
	LayerVisible[i] = 1;	
}

function setActive(i) {
	var f = parent.PostFrame.document.forms[0];
	ActiveLayerId = LayerID[i];
	activeLayerIndex = i;
	f.ActiveLayer.value = ActiveLayerId;
	f.SelectMinX.value = "";
	f.SelectMinY.value = "";
	f.SelectMaxX.value = "";
	f.SelectMaxY.value = "";
	f.SelectLayer.value = "";
	f.QueryExpression.value = "";
	f.QueryLayer.value = "";
}

//reset all layers visibility to 0, and set the default set of 'background' layers visibility to 1
function setBackgroundLayersVisible(data) {
	// get the starting visibility values for Watersheds and ARTCC layers
	var wshedsVis = LayerVisible[gridPolyLow-2];
	var artccVis = LayerVisible[gridPolyLow-5];
	var goesIRVis = LayerVisible[rasterLow];

	for(i=0;i<layerCount;i++) {LayerVisible[i]=0}
        //for(i=sstAnalHigh+1;i<gridPolyLow;i++) {LayerVisible[i] = 1;}
        // Changed the line below from sstAnalHigh+1 to +2 (since RTOFS layer was 
        //   added right above SST analysis layers but under the background layers)
	//for(i=sstAnalHigh+2;i<gridPolyLow;i++) {LayerVisible[i] = 1;}
        //Commented out for current release.  Will be included when NCOM layers are published
        for(i=currentsHigh+1;i<gridPolyLow;i++) {LayerVisible[i] = 1;}
        //for(i=sstAnalHigh+1;i<gridPolyLow;i++) {LayerVisible[i] = 1;}
        
	for(i=gridPointHigh+1;i<=gridPointHigh+numBackgroundLayers;i++) {LayerVisible[i] = 1;}

	// if selecting SST or an NDFD layer, don't display GOES or Weather Radar Layers
	if ( data != "NCEP_ANAL_RTG_SST" && data != "NDFD" && data != "RTMA" && data != "RTMA_QPE" && data != "NSSL_QPE" && data != "NCOM" && data != "SFC_CURRENTS") {
	    //set GOES Visible Satellite layer to visible, unless user has selected data = GOES IR (or GOES IR already turned ON)
	    if (data != "RAS_GOES" && (data == "RAS_GOES_I4" || goesIRVis == 1)) {
		LayerVisible[rasterLow] = 1;
		LayerVisible[rasterLow+1] = 0;
	    } else {
		LayerVisible[rasterLow] = 0;
		LayerVisible[rasterLow+1] = 1;
	    }

	    //set Weather Radar Mosaic to visible
	    LayerVisible[rasterHigh] = 1;

	    //set the Urban Areas fill color to OFF
	    LayerVisible[gridPointHigh+1] = 0;
	} else if ( data == "NDFD" || data == "RTMA" || data == "RTMA_QPE" || data == "NSSL_QPE" ) {
	    LayerVisible[gridPointHigh+1] = 0;
	}

	// set watersheds layer to its previous value
	LayerVisible[gridPolyLow-2] = wshedsVis;

	// set ARTCC Boundaries layer to its previous value
	LayerVisible[gridPolyLow-5] = artccVis;
         
        // Turn ON Short Duration Warning Polygons, unless WARN_SHORT
        //   was selected from 'data' pulldown (in which case we only
        //   display the warning selected from 'variable' pulldown):
        if ( data != "WARN_SHORT" ) {
            LayerVisible[rasterHigh+1] = 1;
            LayerVisible[rasterHigh+2] = 1;
            LayerVisible[rasterHigh+3] = 1;
            LayerVisible[rasterHigh+4] = 1;
            LayerVisible[rasterHigh+5] = 1;
            LayerVisible[rasterHigh+6] = 1;
        }
        
        // Turn on Tropical Cyclone Layers
        LayerVisible[rasterHigh+7] = 1;
        LayerVisible[rasterHigh+8] = 1;
        LayerVisible[rasterHigh+9] = 1;
        LayerVisible[rasterHigh+10] = 1;
        LayerVisible[rasterHigh+11] = 1;
        LayerVisible[rasterHigh+12] = 1;
        LayerVisible[rasterHigh+13] = 1;
        LayerVisible[rasterHigh+14] = 1;
        LayerVisible[rasterHigh+15] = 1;
        LayerVisible[rasterHigh+16] = 1;

	// if selecting Surface Forecasts layer, turn county borders off
	if ( data == "fcst_pg_cfz" ) LayerVisible[gridPolyLow-6] = 0;
}


function parseCoords(coords) {
	//var coordsArray = new Array(coords.split(:));
	var coordsArray = new Array(4);
	coordsArray = coords.split(":");
	
	//set global variables here
	minX = coordsArray[0];
	maxX = coordsArray[1];
	minY = coordsArray[2];
	maxY = coordsArray[3];	
}




// populateVariables():  determines list of variable values to diplay in variable pulldown field in top.htm
// 	Takes value from 'product' pulldown field in top.htm and populates an array of text/value pairs for variable pulldown	
function populateVariables() {
	var dataPulldown = parent.TopFrame.document.Jumpbar.elements[1];
	var varPulldown = parent.TopFrame.document.Jumpbar.elements[2];
	var timePulldown = parent.TopFrame.document.Jumpbar.elements[3];
	var data = dataPulldown.options[dataPulldown.selectedIndex].value;
	
	if (data != "") {
		var temptext = eval(data + "_Text");
		var tempvalue =  eval(data + "_Value");
		var variableLabel, timeLabel;

		// if there are no variables to select: ; else populate var pulldown
		if (temptext.length == 0) {
			varPulldown.length  = 1;
			variableLabel = "-No Var Selection-->";
			timeLabel = "-Click 'GO'-->";

		} else {
			varPulldown.length  = temptext.length+1;
			variableLabel = "-Select Variable-";
			if (data == "NDFD") timeLabel = "-Select Forecast-";
			else timeLabel = "-Real Time-";
		}

		varPulldown.options[0].text = variableLabel;
		varPulldown.options[0].value = "def";
		varPulldown.options[0].selected = "true";

		//populate variables dropdown
		for(var i=0;i < temptext.length;i++) {
			varPulldown.options[i+1].text = temptext[i];
			varPulldown.options[i+1].value = tempvalue[i];
		}

		//populate time pulldown with default values
		timePulldown.length = 1;
		timePulldown.options[0].text = timeLabel;
		timePulldown.options[0].value = "def";
		timePulldown.options[0].selected = "true";

	// If no Obs/Forecast selected, set variable and time pulldowns to default values
	} else {
		varPulldown.length =1;
		varPulldown.options[0].text = "<--Select Obs/Forecast";
		varPulldown.options[0].value = "def";
		varPulldown.options[0].selected = "true";

		timePulldown.length = 1;
		timePulldown.options[0].text = "-Real Time-";
		timePulldown.options[0].value = "def";
		timePulldown.options[0].selected = "true";

	}
}	



// populateTime():  populates pulldown options of 'Time' pulldown according to:
//		value of 'OBS/Forecast' pulldown : dataPulldown.options[dataPulldown.selectedIndex].value,
//		value of 'Variable' pulldown : varPulldown.options[varPulldown.selectedIndex].value
function populateTime() {
	var dataPulldown = parent.TopFrame.document.Jumpbar.elements[1];
	var varPulldown = parent.TopFrame.document.Jumpbar.elements[2];
	var timePulldown = parent.TopFrame.document.Jumpbar.elements[3];
	var data = dataPulldown.options[dataPulldown.selectedIndex].value;
	var variable = varPulldown.options[varPulldown.selectedIndex].value;
	

	if (data != "") {
		// case for datasets which do not have time label values set by NCTimeLabelController:
		if (data != "NDFD" && data != "NCEP_ANAL_RTG_SST" && data != "NCEP_ANAL_RTG_SST_HR" && data != "RTOFS_RAS_ATL" && data != "RTMA" && data != "RTMA_QPE" && data != "NSSL_QPE" && data != "NCOM" ) {
			var theLabel;
			
			switch (data) {
				case 'fcst_pt_riv' :
					switch (variable) {
						case 'Stage' :
						default:
							theLabel = "0 - 4 Days";
							break;
					}
					break;
				case 'fcst_pt_wx' :
					switch (variable) {
						case 'Winds' :
						case 'AirTemp' :
						case 'DewPt' :
						case 'Precip' :
						case 'Weather' :
						case 'Snowfall' :
						case 'CldCvr' :
						case 'Vis' :
							theLabel = "6 Hrs - 8 Days";
							break;
						default:
							theLabel = "-Real Time-";
							break;
					}
					break;
				case 'fcst_pt_oc' :
					switch (variable) {
						case 'Waves' :
							theLabel = "0 - 7 Days";
							break;
						case 'WLevel' :
						case 'Currents' :
						case 'SSurTmp' :
							theLabel = "0 - 48 Hrs";
							break;
						case 'Salinity' :
							theLabel = "0 - 36 Hrs";
							break;
						default:
							theLabel = "-Real Time-";
							break;
					}
					break;
				case 'fcst_pg_cfz' :
					switch (variable) {
						case 'AirTemp' :
						case 'CldCvr' :
						case 'Precip' :
						case 'Weather' :
						case 'Winds' :
						default:
							theLabel = "3 Hrs - 7 Days";
							break;
					}
					break;
				case 'fcst_pg_coz' :
					switch (variable) {
						case 'Vis' :
						case 'Waves' :
						case 'Weather' :
						case 'Winds' :
						default:
							theLabel = "3 Hrs - 5 Days";
							break;
					}
					break;

				case 'fcst_pg_hsz' :
					switch (variable) {
						default:
							theLabel = "3 Hrs - 7 Days";
							break;
					}
					break;

				case 'fcst_pg_sz' :
					switch (variable) {
						case 'Vis' :
						case 'Waves' :
						case 'Winds' :
						default:
							theLabel = "0 - 48 Hrs";
							break;
					}
					break;

				case 'pred_pt_at' :
					switch (variable) {
						case 'WLevel' :
						default:
							theLabel = "Present - 1 Month";
							break;
					}
					break;
				
				case 'OBS_MET' :
					theLabel = "Within 1 Hour";
					break;
                                case 'SFC_CURRENTS' :
                                        theLabel = "- Latest -";
                                        break;
				default :
					theLabel = "-Real Time-";
					break;			
			}

			timePulldown.length = 1;
			timePulldown.options[0].text = theLabel;
			timePulldown.options[0].value = "def";
			timePulldown.options[0].selected = "true";

		// case for datasets with time labels stored in NCTimeLabelController class (NDFD, NCEP_ANAL_RTG_SST):
		} else {	
			var temptext = eval(variable + "_Time_Label");
			var tempvalue =  eval(variable + "_Time_Value");
			
			
			timePulldown.length  = temptext.length+1;

			//put default entry in options[0]
			timePulldown.options[0].text = "-Select Time-";
			timePulldown.options[0].value = "def";
			timePulldown.options[0].selected = "true";

			//populate variables dropdown
			for(var i=0;i < temptext.length;i++) {
				timePulldown.options[i+1].value = tempvalue[i];
				timePulldown.options[i+1].text = temptext[i];
			}
			
			
		}
	} 
}



// NOT USED: ------------------------------------------
// forecastHourPopulate(): populates time pulldown menu with each NDFD forecast (Day/Hour)
function forecastHourPopulate (interval,numForecasts,timePulldown) {
		//populate time array
		timePulldown.length = numForecasts+1;
		timePulldown.options[0].text = "-Select Forecast Time-";
		timePulldown.options[0].value = "def";
		timePulldown.options[0].selected = "true";

		var theDate = new Date();
		var j = 1;
		var numDays = 0;
		
		for (var i = 0; i < numForecasts; i++) {
			var forecastDate = new Date();
			if (theDate.getUTCHours()+(j*interval)>(24*(numDays+1))) {
				numDays++;
			}
			forecastDate.setDate(theDate.getDate()+numDays);
			//alert(forecastDate);
			//alert(theDate.getUTCHours());
			
			//Compose Date String to display in pulldown
			dateString = writeDateString(forecastDate);
			dateString += '   ' + (j*interval) + ' HRS'; 
			timePulldown.options[j].text = dateString;
			timePulldown.options[j].value = "Hour" + (j*interval);
			
			j++;
		}
}


function getHourOffset (type,interval,zeroHour) {
	var hourOffset = zeroHour%interval;	 //hourOffset is remainder of modulo operation of zeroHour against interval
	
	
	// check if hourOffset is positive or negative, set accordingly (will be negative for cases where zeroHour is negative) 
	//	special case for MINT, which is compared against when it is valid (12 hours UTC)
	if (type == "MINT") {
		if (hourOffset > 12) {hourOffset =  36 - hourOffset;}
		else {hourOffset = 12 - hourOffset;}
	} else {
		if (hourOffset > 0) {hourOffset =  interval - hourOffset;}
		else {hourOffset = 0 - hourOffset;}
	}
	return hourOffset;
}


function getLayerLabel (theHour) {
	var theDate = new Date();
	
	// numHours and numDays are the hours/days forecast is valid from present time
	var numHours = theHour%24;
	var numDays = parseInt(theHour/24);
	
	theDate.setMinutes(0);
	theDate.setSeconds(0);
	theDate.setDate(theDate.getDate()+numDays);
	theDate.setHours(theDate.getHours()+numHours);
	
	var dayOfWeek = theDate.getDay();
	var theDay;
	switch (dayOfWeek) {
		case 0: theDay = "Sunday";
			break;
		case 1: theDay = "Monday";
			break;
		case 2: theDay = "Tuesday";
			break;
		case 3: theDay = "Wednesday";
			break;
		case 4: theDay = "Thursday";
			break;
		case 5: theDay = "Friday";
			break;
		case 6: theDay = "Saturday";
			break;
	}

	var hours = theDate.getHours().toString();
	
	var dateString = writeDateString(theDate);
	dateString += ' ' + theDay + ' ' + hours + ':00';
	if (theHour >= 0) {
		dateString += ' +' + theHour + ' HRS';
	} else {
		dateString += '  ' + theHour + ' HRS';
	}
	 
	
	var test = theDate.toUTCString();

	return dateString;
}

function createForecastTimes () {
	var forecastTimes = new Array();
	var forecastHour = 0;
	var forecastDay = 0;

	var forecastInterval = 3;
	var maxNumForecasts = 56;

	var validHour;
	var key;
	for (var i = 0; i < maxNumForecasts; i++) {
		validHour = i * forecastInterval;
		
		if (forecastHour == 24) {
			forecastHour = 0;
			forecastDay ++;
		}
		if (forecastHour < 10) {
			key = forecastDay + '_0' + forecastHour;
		} else {
			key = forecastDay + '_' + forecastHour;
		}
		forecastTimes[key] = validHour;
		forecastHour += forecastInterval;
	}
	return forecastTimes;

}


//writeDateString(theDate):  takes a date object as input and returns a string of format MM/DD/YYYY
function writeDateString(theDate) {
	year = theDate.getFullYear().toString(); 
	year = year.substring(2,4);
	month = (theDate.getMonth() + 1).toString();
	day = theDate.getDate().toString();
	
	theString = month + '/' + day + '/' + year;
	return theString;
	
}


function addVariableLayer() {
	var dataPulldown = parent.TopFrame.document.Jumpbar.elements[1];
	var varPulldown = parent.TopFrame.document.Jumpbar.elements[2];
	var data = dataPulldown.options[dataPulldown.selectedIndex].value;
	var variable = varPulldown.options[varPulldown.selectedIndex].value;
	var f = parent.PostFrame.document.forms[0];
	
	if ((variable != "def") && (variable != "")) {
	    f.NCLayerID.value = data;
	    f.NCLayerVariable.value = variable;
		f.NCLayerVarName.value = varPulldown.options[varPulldown.selectedIndex].text;
	    f.NCLayerDisplay.value = "true"; 
	} else {
		f.NCLayerID.value = data;
	    f.NCLayerVariable.value = "";
		f.NCLayerVarName.value = "";
	    f.NCLayerDisplay.value = "false";
		
	}
}


//resetVariableLayer:  removes information about NCLayer from jspForm and resets Pulldown menu to default values
function resetVariableLayer() {
	var f = parent.PostFrame.document.forms[0];
	var t = parent.TopFrame.document.forms[0];
	
	f.NCLayerID.value = "";
	f.NCLayerVariable.value = "";
	f.NCLayerVarName.value = "";
	f.NCLayerDisplay.value = "false";
	
	t.elements[1].options[0].selected = "true";

	t.elements[2].length =1;
	t.elements[2].options[0].text = "<--Select Obs/Forecast";
	t.elements[2].options[0].value = "def";
	t.elements[2].options[0].selected = "true";

	t.elements[3].length = 1;
	t.elements[3].options[0].text = "-Real Time-";
	t.elements[3].options[0].value = "def";
	t.elements[3].options[0].selected = "true";
}






function showHelp () {
	var f = parent.PostFrame.document.forms[0];
	if (f.Action.value == "showHelpCompleted") {
            f.Action.value = "";
            rollImage("toggleInstructions","instructions_off.gif");
        } else {
            rollImage("toggleInstructions","instructions_on.gif");
            f.Action.value = "showHelp";
        }
	getMapImage();
}

function toggleLegend() {
    var f = parent.PostFrame.document.forms[0];
    if ( f.ShowLegend.value == "off" || f.ShowLegend.value == "0" || f.ShowLegend.value == "no" ) {
        // Legend is currently off.  Set ShowLegend to empty string and turn legend on.
        f.ShowLegend.value = "";
		//rollImage("toggleLegend","map-hideLegend.png");
                rollImage("toggleLegend","legend_on.gif");
    } else {
        // Legend is currently on.  Set ShowLegend to "0" and turn legend off
        f.ShowLegend.value = "0";
		//rollImage("toggleLegend","map-showLegend.png");
                rollImage("toggleLegend","legend_off.gif");
    }
    getMapImage();
}

function about() {
	var aboutWindow = open("help/intro.shtml","InfoDepot","width=800,height=600,left=0,top=0,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,resizable=yes,status=yes");
	aboutWindow.focus();
}

function mapservices() {
	var aboutWindow = open("help/mapservices.shtml?name=mapservices","InfoDepot","width=800,height=600,left=0,top=0,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,resizable=yes,status=yes");
	aboutWindow.focus();
}

function newVersionInfo() {
        var versionInfoWindow = open("newVersionInfo.htm","NewVersionInfo","width=870,height=600,left=0,top=0,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,resizable=yes,status=yes");
        versionInfoWindow.focus();
}

function openLayerInfo(index) {
	//var layerInfoURL = "layerInfo.htm?layerid=" + LayerID[index] + "&layername=" + LayerName[index];
	var layerInfoURL = "layerInfo.htm?layerindex=" + index;
	var layerInfoWindow = open(layerInfoURL,"LayerInfo","width=750,height=600,left=0,top=0,menubar=no,scrollbars=yes,toolbar=no,location=no,resizable=yes");
	layerInfoWindow.focus();
	
}

function openToolInfo(toolmode) {
	var toolInfoWindow = open("toolHelp.htm","ToolHelp","width=500,height=350,left=0,top=0,menubar=no,scrollbars=yes,toolbar=no,location=no,resizable=yes");
	toolInfoWindow.focus();
}


//  rollimage_old():  original image rollover function that changes image source depending on document.images Array
function rollImage_old(imgNum,imgSrc) {
		document.images[imgNum].src = "images/" + imgSrc;
}

//  rollimage():  image rollover function that changes image source depending on name of <img> tag: newer browsers
function rollImage(imgName,imgSrc) {
		document[imgName].src = "images/" + imgSrc;
}

//rollImage_highlight: image rollover function used in nowCOAST info depot that keeps record of highlighted image
var highlightImageName;
function rollImage_highlight(imgName,imgSrc) {
	if (!(imgName == highlightImageName)) {
		document[imgName].src = "images/" + imgSrc;
	}
}


function setLayerInfo() {
	var prefix = ActiveLayerId.substring(0,7);
	switch(prefix) {
		case 'obs_pt_' :
			lyrNamePrefix = "Observations: ";
			layerFeatureType = "observation stations";
			break;
		case 'obs_pg_' :
			lyrNamePrefix = "Observations: ";
			layerFeatureType = "observation locations";
			break;
		case 'pred_pt' :
			lyrNamePrefix = "Predictions: ";
			layerFeatureType = "prediction locations";
			break;
		case 'fcst_pt' :
			lyrNamePrefix = "Forecast Model Guidance: ";
			layerFeatureType = "forecast points";
			break;
		case 'fcst_pg' :
			lyrNamePrefix = "Surface Forecasts: ";
			layerFeatureType = "forecast zones";
			break;
		default:
			lyrNamePrefix = "";
			layerFeatureType = "features"
			break;

	}
}


// Retrieve values for web parameter from URL string, pass 
//	the parameter string (params) and the variable, returns theValue
function getWebParams(params,variable) {
	var startpos = 0;
	var endpos = 0;
	var theValue;
	var pos = params.indexOf(variable);
	if (pos!=-1) {
		startpos = pos + variable.length;
		endpos = params.indexOf("&",startpos);
		if (endpos==-1) endpos = params.length;
		theValue = params.substring(startpos,endpos);
	}
	return theValue;
}

// process the parameter string for Info Depot pages, set a button
//	to be highlighted according to the name of the button in DOM
function setHelpParams(params) {
	var theName = getWebParams(params,"name=");
	highlightImageName = theName;
	document[theName].src = "images/" + theName + "On.gif";
} 

// getPath:  function returns string value of the full directory path of a file ('theFullPath')
//	which is passed as a parameter
function getPath(theFullPath) {
		var theSlash = theFullPath.lastIndexOf("/");
		var theDir = theFullPath.substring(0,theSlash);
		if (theDir==null) theDir="";
		theDir = theDir + "/";
		return theDir;
}