xInclude('../support/x/x_core.js', '../support/x/x_event.js', '../support/x/x_drag.js', '../support/x/x_draw.js', '../support/x/x_dom.js', '../support/x/x_tip.js');
var ie=document.all
var ns6=document.getElementById && !document.all

var ArrDef = 0;
var StationSel = 0;
var StaionsView = 0;	// Number of stations in view
var shftMode = false; // if true the shift key is down

function initPage()
{
	initTrackMouse()
  	var ele = xGetElementById('click');
  	xEnableDrag(ele, dragStart, drag, dragEnd);

	if (document.mapserv.tool.value  == 'selecttl')
		setTool('selecttl');

	if (document.mapserv.etooltip.value == 'enabled') {
		if (document.mapserv.server.value == 'server.php') { 
			new xTooltipGroup(['p0','p1','p2','p4','p5','p6','p7','p8','p9','p10'],
				'tipGrp4s', 'left', 4, 0,
				["<p><b>Maximum Temperature</b></p><p>Daily maximum temperature. (Maximum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit. </p>",
				"<p><b>Minimum Temperature</b></p><p>Daily minimum temperature. (Minimum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit.</p>",
				"<p><b>Observation Temperature</b></p><p>Temperature at observation time. Unit Measurement, Whole Degrees Fahrenheit.</p>",
				"<p><b>Precipitation</b></p><p>Daily precipitation. Precipitation reading for 24 hours ending at time of observation. Trace is less than 0.005 inch. Unit Measurement, Inches to Hundredths.</p>",
				"<p><b>Snow Fall</b></p><p>Daily Snowfall (Snowfall includes sleet). Amount is for 24-hour period ending at observation time. Hail was included with snowfall from July 1948 through December 1955. Hail occurring alone was not included with either snowfall or snow depth before and after that period. Trace is less than 0.05 inch. Unit Measurement, Inches to Tenths.</p>",
				"<p><b>Snow Depth</b></p><p>Snow depth at observation time. (Snow depth is depth of snow on the ground at time of observation. Trace is depth less than 0.05 inch.) Unit Measurement, Whole Inches. </p>",
				"<p><b>GDD</b></p><p>Growing Degree Days (GDD) are used to estimate the growth and development of plants and insects during the growing season. The basic concept is that development will only occur if the temperature exceeds some minimum development threshold, or base temperature (TBASE). The base temperatures are determined experimentally and are different for each organism.</p>",
				"<p><b>HDD</b></p><p>Heating Degree Days (HDD) are used as an index to estimate the amount of energy required for heating during the cool season. When the daily mean temperature falls below 65 F, most buildings require heat to maintain a comfortable interior temperature. By monitoring heating fuel usage and heating degree day accumulation over a period of time, a building's energy consumption per HDD can be calculated and this value used, for example, in fuel consumption monitoring, energy efficiency evaluation or future fuel supply estimates. The daily mean temperature is found by adding together the high and low temperature for the day and dividing by two. When the mean temperature is above 65 F, the HDD total is zero. If the mean temperature is below 65 F, the HDD amount is the difference between 65 F and the mean temperature.</p>",
				"<p><b>CDD</b></p><p>Cooling Degree Days (CDD) are used as an index to estimate the amount of energy required for cooling. When the temperature rises above 65 F, many buildings use air conditioning to maintain a comfortable indoor temperature. By monitoring air conditioner energy usage and cooling degree day accumulation over a period of time, a building's energy consumption per CDD can be calculated and this value used, for example, in energy use monitoring, energy efficiency evaluation or future energy usage estimates. The daily mean temperature is found by adding together the high and low temperature for the day and dividing by two. When the mean temperature is below 65 F, the CDD total is zero. If the mean temperature is above 65 F, the CDD amount is the difference between the mean temperature and 65.</p>",
				"<p><b>ET0</b></p><p>The evapotranspiration computed is the so-called reference crop evapotranspiration or reference evapotranspiration, denoted as ETo. The reference surface is a hypothetical grass reference crop. The reference surface closely resembles an extensive surface of green, well-watered grass of uniform height, actively growing and completely shading the ground.</p>"]);
		}
		if (document.mapserv.server.value == 'server_gsod.php') { 
			new xTooltipGroup(['p0','p1','p2','p3', 'p4','p5','p6','p7','p8','p9','p10','p11','p12','p13','p14'],
				'tipGrp4s', 'left', 4, 0,
				["<p><b>Maximum Temperature</b></p><p>Daily maximum temperature. (Maximum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit. </p>",
				"<p><b>Minimum Temperature</b></p><p>Daily minimum temperature. (Minimum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit.</p>",
				"<p><b>Dew Point</b></p><p>Dew-Point temperature</p>",
				"<p><b>Mean Temperature</b></p><p>The daily mean temperature is found by adding together the high and low temperature for the day and dividing by two.</p>",
				"<p><b>Precipitation</b></p><p>Daily precipitation. Precipitation reading for 24 hours ending at time of observation. Trace is less than 0.005 inch. Unit Measurement, Inches to Hundredths.</p>",
				"<p><b>Snow Depth</b></p><p>Snow depth at observation time. (Snow depth is depth of snow on the ground at time of observation. Trace is depth less than 0.05 inch.) Unit Measurement, Whole Inches. </p>",
				"<p><b>GDD</b></p><p>Growing Degree Days (GDD) are used to estimate the growth and development of plants and insects during the growing season. The basic concept is that development will only occur if the temperature exceeds some minimum development threshold, or base temperature (TBASE). The base temperatures are determined experimentally and are different for each organism.</p>",
				"<p><b>HDD</b></p><p>Heating Degree Days (HDD) are used as an index to estimate the amount of energy required for heating during the cool season. When the daily mean temperature falls below 65 F, most buildings require heat to maintain a comfortable interior temperature. By monitoring heating fuel usage and heating degree day accumulation over a period of time, a building's energy consumption per HDD can be calculated and this value used, for example, in fuel consumption monitoring, energy efficiency evaluation or future fuel supply estimates. The daily mean temperature is found by adding together the high and low temperature for the day and dividing by two. When the mean temperature is above 65 F, the HDD total is zero. If the mean temperature is below 65 F, the HDD amount is the difference between 65 F and the mean temperature.</p>",
				"<p><b>CDD</b></p><p>Cooling Degree Days (CDD) are used as an index to estimate the amount of energy required for cooling. When the temperature rises above 65 F, many buildings use air conditioning to maintain a comfortable indoor temperature. By monitoring air conditioner energy usage and cooling degree day accumulation over a period of time, a building's energy consumption per CDD can be calculated and this value used, for example, in energy use monitoring, energy efficiency evaluation or future energy usage estimates. The daily mean temperature is found by adding together the high and low temperature for the day and dividing by two. When the mean temperature is below 65 F, the CDD total is zero. If the mean temperature is above 65 F, the CDD amount is the difference between the mean temperature and 65.</p>",
				"<p><b>Sea Level Pressure</b></p><p>Sea Level Pressure</p>",
				"<p><b>Station Pressure</b></p><p>Altimeter - Barometric Pressure is the amount of downward force exerted by the weight of the air above and is measured in inches of mercury (Hg). Meteorologists use millibars (mb) or hectopascals (hpa) rather than inches of mercury (Hg). </p>",
				"<p><b>Visibility</b></p><p>Visibility is the distance a person can see with normal vision, and is measured in statute miles.</p>",
				"<p><b>Wind Speed</b></p><p>Wind Speed is the average velocity at which the air travels over a one-minute period and is measured in nautical miles per hour (NM/H or knots). The measurement is given in miles per hour (mph) or knots.</p>",
				"<p><b>Wind Speed Max</b></p><p>Reported in Knots</p>",
				"<p><b>Wind Gust</b></p><p>Peak Wind Gusts are the highest wind speeds registered over the previous 10 minutes, measured in nautical miles per hour (NM/H or knots). If no gusts are detected more than 5 NM/H faster than the average wind speed, this field is zero. The measurement is given in miles per hour (mph) or knots.</p>",
				"<p><b>ET0</b></p><p>Reference Evapotranspiration </p>"]
				);
		}

		if (document.mapserv.server.value == 'server_awos.php') { 
			new xTooltipGroup(['p0','p1','p2','p3', 'p4','p5','p6','p7','p8','p9','p10'],
				'tipGrp4s', 'left', 4, 0,
				["<p><b>Temperature</b></p><p>Air Temperature is measured in degrees Celsius (international standard) by a sensor located six feet off the ground / also in degrees Fahrenheit</p>",
				"<p><b>Dew Point</b></p><p>Dew Point temperature is the temperature, measured in degrees Celsius (or Fahrenheit), at which the air is fully saturated with moisture. The dew point is a more useful measure of the moisture present, because it takes into consideration the air temperature. The amount of moisture that can co-exist in air decreases when it is cooled. As the air temperature drops there is a point at which the moisture in the air begins to condense and form fog, dew or frost; this point is referred to as the dew point.</p>",
				"<p><b>Altimeter</b></p><p>Altimeter - Barometric Pressure is the amount of downward force exerted by the weight of the air above and is measured in inches of mercury (Hg). Meteorologists use millibars (mb) or hectopascals (hpa) rather than inches of mercury (Hg). </p>",
				"<p><b>Wind Speed</b></p><p>Wind Speed is the average velocity at which the air travels over a one-minute period and is measured in nautical miles per hour (NM/H or knots). The measurement is given in miles per hour (mph) or knots.</p>",
				"<p><b>Wind Gust</b></p><p>Peak Wind Gusts are the highest wind speeds registered over the previous 10 minutes, measured in nautical miles per hour (NM/H or knots). If no gusts are detected more than 5 NM/H faster than the average wind speed, this field is zero. The measurement is given in miles per hour (mph) or knots.</p>",
				"<p><b>Wind Direction</b></p><p>Wind Direction is the average direction from which the wind is coming and is measured in degrees from north. </p>",
				"<p><b>Visibility</b></p><p>Visibility is the distance a person can see with normal vision, and is measured in statute miles.</p>",
				"<p><b>Precipitation</b></p><p>Precipitation reading since the last reported observation. Trace is less than 0.005 inch. Unit Measurement, Inches to Hundredths.</p>",
				"<p><b>Precipitation ID</b></p><p>Precipitation Identification (ID) identifies the type of precipitation.</p>",
				"<p><b>Maximum Temperature</b></p><p>Daily maximum temperature. (Maximum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit. </p>",
				"<p><b>Minimum Temperature</b></p><p>Daily minimum temperature. (Minimum temperature reading for 24 hours ending at time of observation.) Unit Measurement, Whole Degrees Fahrenheit.</p>",
				"<p><b>Dew Point</b></p><p>Dew-Point temperature</p>"]
				);
			var objh = document.getElementById('hourly');
			var objd = document.getElementById('daily');
				objh.style.display ="block"
				objd.style.display="none"
				if(document.query.Maximum_Temperature)
				  	document.query.Maximum_Temperature.checked = 0;
				if(document.query.Minimum_Temperature)
				  	document.query.Minimum_Temperature.checked = 0;
			  	if (document.query.All_Daily)
			  		document.query.All_Daily.checked = 0;
		}
	}
}
function radioSelectHourly()
{
	var objh = document.getElementById('hourly');
	var objd = document.getElementById('daily');
	objh.style.display ="block"
	objd.style.display="none"
	if(document.query.Maximum_Temperature)
	  	document.query.Maximum_Temperature.checked = 0;
	if(document.query.Minimum_Temperature)
	  	document.query.Minimum_Temperature.checked = 0;
  	if (document.query.All_Daily)
  		document.query.All_Daily.checked = 0;
}
function radioSelectDaily()
{
	var objh = document.getElementById('hourly');
	var objd = document.getElementById('daily');
	objd.style.display ="block"
	objh.style.display="none"
  	document.query.All_Hourly.checked = 0;
	document.query.Temperature.checked = 0;
	document.query.Dew_Point.checked = 0;
	document.query.Altimeter.checked = 0;
	document.query.Wind_Speed.checked = 0;
	document.query.Wind_Gust.checked = 0;
	document.query.Wind_Direction.checked = 0;
	document.query.Visibility.checked = 0;
	document.query.Precipitation.checked = 0;
	document.query.Precipitation_ID.checked = 0;
}
function initTrackMouse()
{
  var ele = xGetElementById('click');
  xAddEventListener(document, 'mousemove', TrackCoordinatesInImage, false);
  if (document.query.stat_id_num.value == '')
  	disableQForm();
}
function selectAllStationCheck()
{
  	if (document.query.Station_ID.disabled == true) {
		alert('A station must be choosen before selections can be made.');
		return;
	}
  	if (document.query.All_Station.checked == true) {
  		document.query.Station_ID.checked = 1;
  		document.query.Station_Name.checked = 1;
		if(document.query.State)
  			document.query.State.checked = 1;
		if(document.query.Country)
  			document.query.Country.checked = 1;
		if(document.query.Elevation)
  			document.query.Elevation.checked = 1;
  		document.query.Latitude.checked = 1;
  		document.query.Longitude.checked = 1;
	} else {
  		document.query.Station_ID.checked = 0;
  		document.query.Station_Name.checked = 0;
		if(document.query.State)
  			document.query.State.checked = 0;
		if(document.query.Country)
  			document.query.Country.checked = 0;
		if(document.query.Elevation)
  			document.query.Elevation.checked = 0;
  		document.query.Latitude.checked = 0;
  		document.query.Longitude.checked = 0;
	}
}
function selectAllAWOSDailyCheck()
{
  	if (document.query.All_Daily.checked == true) {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 1;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 1;
		if(document.query.Daily_Precip)
			document.query.Daily_Precip.checked = 1;
	} else {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 0;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 0;
		if(document.query.Daily_Precip)
			document.query.Daily_Precip.checked = 0;
	}
}
function selectAllAWOSCheck()
{
  	if (document.query.All_Hourly.checked == true) {
		document.query.Temperature.checked = 1;
		document.query.Dew_Point.checked = 1;
		document.query.Altimeter.checked = 1;
		document.query.Wind_Speed.checked = 1;
		document.query.Wind_Gust.checked = 1;
		document.query.Wind_Direction.checked = 1;
		document.query.Visibility.checked = 1;
		document.query.Precipitation.checked = 1;
		document.query.Precipitation_ID.checked = 1;
	} else {
		document.query.Temperature.checked = 0;
		document.query.Dew_Point.checked = 0;
		document.query.Altimeter.checked = 0;
		document.query.Wind_Speed.checked = 0;
		document.query.Wind_Gust.checked = 0;
		document.query.Wind_Direction.checked = 0;
		document.query.Visibility.checked = 0;
		document.query.Precipitation.checked = 0;
		document.query.Precipitation_ID.checked = 0;
	}
}

function selectAllClimateCheck()
{
  	if (document.query.All_Climate.checked == true) {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 1;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 1;
		if(document.query.Observation_Temperature)
	  		document.query.Observation_Temperature.checked = 1;
		if(document.query.Mean_Temperature)
		  	document.query.Mean_Temperature.checked = 1;
		if(document.query.Dew_Point)
		  	document.query.Dew_Point.checked = 1;
		if(document.query.Precipitation)
		  	document.query.Precipitation.checked = 1;
		if(document.query.Snow_Fall)
	  		document.query.Snow_Fall.checked = 1;
		if(document.query.Snow_Depth)
		  	document.query.Snow_Depth.checked = 1;
		if(document.query.GDD)
		  	document.query.GDD.checked = 1;
		if(document.query.HDD)
		  	document.query.HDD.checked = 1;
		if(document.query.CDD)
		  	document.query.CDD.checked = 1;
		if(document.query.ET0)
			document.query.ET0.checked = 1;
		if(document.query.Sea_Level_Pressure)
		  	document.query.Sea_Level_Pressure.checked = 1;
		if(document.query.Station_Pressure)
		  	document.query.Station_Pressure.checked = 1;
		if(document.query.Visibility)
		  	document.query.Visibility.checked = 1;
		if(document.query.Wind_Speed)
		  	document.query.Wind_Speed.checked = 1;
		if(document.query.Wind_Speed_Max)
		  	document.query.Wind_Speed_Max.checked = 1;
		if(document.query.Wind_Gust)
		  	document.query.Wind_Gust.checked = 1;
	} else {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 0;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 0;
		if(document.query.Observation_Temperature)
	  		document.query.Observation_Temperature.checked = 0;
		if(document.query.Mean_Temperature)
		  	document.query.Mean_Temperature.checked = 0;
		if(document.query.Dew_Point)
		  	document.query.Dew_Point.checked = 0;
		if(document.query.Precipitation)
		  	document.query.Precipitation.checked = 0;
		if(document.query.Snow_Fall)
	  		document.query.Snow_Fall.checked = 0;
		if(document.query.Snow_Depth)
		  	document.query.Snow_Depth.checked = 0;
		if(document.query.GDD)
		  	document.query.GDD.checked = 0;
		if(document.query.HDD)
		  	document.query.HDD.checked = 0;
		if(document.query.CDD)
		  	document.query.CDD.checked = 0;
		if(document.query.ET0)
			document.query.ET0.checked = 0;
		if(document.query.Sea_Level_Pressure)
		  	document.query.Sea_Level_Pressure.checked = 0;
		if(document.query.Station_Pressure)
		  	document.query.Station_Pressure.checked = 0;
		if(document.query.Visibility)
		  	document.query.Visibility.checked = 0;
		if(document.query.Wind_Speed)
		  	document.query.Wind_Speed.checked = 0;
		if(document.query.Wind_Speed_Max)
		  	document.query.Wind_Speed_Max.checked = 0;
		if(document.query.Wind_Gust)
		  	document.query.Wind_Gust.checked = 0;
	}
}
function selectAllCRNCheck()
{
  	if (document.query.All_CRN.checked == true) {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 1;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 1;
		if(document.query.Observation_Temperature)
	  		document.query.Observation_Temperature.checked = 1;
		if(document.query.Mean_Temperature)
		  	document.query.Mean_Temperature.checked = 1;
		if(document.query.Dew_Point)
		  	document.query.Dew_Point.checked = 1;
		if(document.query.Precipitation)
		  	document.query.Precipitation.checked = 1;
		if(document.query.Snow_Fall)
	  		document.query.Snow_Fall.checked = 1;
		if(document.query.Snow_Depth)
		  	document.query.Snow_Depth.checked = 1;
		if(document.query.GDD)
		  	document.query.GDD.checked = 1;
		if(document.query.HDD)
		  	document.query.HDD.checked = 1;
		if(document.query.CDD)
		  	document.query.CDD.checked = 1;
		if(document.query.ET0)
			document.query.ET0.checked = 1;
		if(document.query.Sea_Level_Pressure)
		  	document.query.Sea_Level_Pressure.checked = 1;
		if(document.query.Station_Pressure)
		  	document.query.Station_Pressure.checked = 1;
		if(document.query.Visibility)
		  	document.query.Visibility.checked = 1;
		if(document.query.Wind_Speed)
		  	document.query.Wind_Speed.checked = 1;
		if(document.query.Wind_Speed_Max)
		  	document.query.Wind_Speed_Max.checked = 1;
		if(document.query.Wind_Gust)
		  	document.query.Wind_Gust.checked = 1;
		if(document.query.Evaporation)
		  	document.query.Evaporation.checked = 1;
		if(document.query.Min_Temp_Evaporation_Pan)
		  	document.query.Min_Temp_Evaporation_Pan.checked = 1;
		if(document.query.Max_Temp_Evaporation_Pan)
		  	document.query.Max_Temp_Evaporation_Pan.checked = 1;
		if(document.query.Wind_Movement)
		  	document.query.Wind_Movement.checked = 1;
		if(document.query.Water_Equiv_Of_Snow_Depth)
		  	document.query.Water_Equiv_Of_Snow_Depth.checked = 1;
		if(document.query.Avg_Wind_Direction)
		  	document.query.Avg_Wind_Direction.checked = 1;
		if(document.query.Avg_Rel_Humidity)
		  	document.query.Avg_Rel_Humidity.checked = 1;
		if(document.query.Max_Rel_Humidity)
		  	document.query.Max_Rel_Humidity.checked = 1;
		if(document.query.Min_Rel_Humidity)
		  	document.query.Min_Rel_Humidity.checked = 1;
		if(document.query.Peak_Wind_Gust)
		  	document.query.Peak_Wind_Gust.checked = 1;
		if(document.query.Peak_Wind_Dir)
		  	document.query.Peak_Wind_Dir.checked = 1;
		if(document.query.Avg_Daily_Station_Pressure)
		  	document.query.Avg_Daily_Station_Pressure.checked = 1;
		if(document.query.Avg_Daily_Sea_Level_Pressure)
		  	document.query.Avg_Daily_Sea_Level_Pressure.checked = 1;
		if(document.query.Avg_Daily_Dew_Point_Pressure)
		  	document.query.Avg_Daily_Dew_Point_Pressure.checked = 1;
		if(document.query.Avg_Daily_Wet_Bulb_Pressure)
		  	document.query.Avg_Daily_Wet_Bulb_Pressure.checked = 1;
		if(document.query.Avg_Daily_Temp)
		  	document.query.Avg_Daily_Temp.checked = 1;
		if(document.query.Solar_Radiation)
		  	document.query.Solar_Radiation.checked = 1;
		if(document.query.Avg_Wind_Speed)
		  	document.query.Avg_Wind_Speed.checked = 1;
	} else {
		if(document.query.Maximum_Temperature)
		  	document.query.Maximum_Temperature.checked = 0;
		if(document.query.Minimum_Temperature)
		  	document.query.Minimum_Temperature.checked = 0;
		if(document.query.Observation_Temperature)
	  		document.query.Observation_Temperature.checked = 0;
		if(document.query.Mean_Temperature)
		  	document.query.Mean_Temperature.checked = 0;
		if(document.query.Dew_Point)
		  	document.query.Dew_Point.checked = 0;
		if(document.query.Precipitation)
		  	document.query.Precipitation.checked = 0;
		if(document.query.Snow_Fall)
	  		document.query.Snow_Fall.checked = 0;
		if(document.query.Snow_Depth)
		  	document.query.Snow_Depth.checked = 0;
		if(document.query.GDD)
		  	document.query.GDD.checked = 0;
		if(document.query.HDD)
		  	document.query.HDD.checked = 0;
		if(document.query.CDD)
		  	document.query.CDD.checked = 0;
		if(document.query.ET0)
			document.query.ET0.checked = 0;
		if(document.query.Sea_Level_Pressure)
		  	document.query.Sea_Level_Pressure.checked = 0;
		if(document.query.Station_Pressure)
		  	document.query.Station_Pressure.checked = 0;
		if(document.query.Visibility)
		  	document.query.Visibility.checked = 0;
		if(document.query.Wind_Speed)
		  	document.query.Wind_Speed.checked = 0;
		if(document.query.Wind_Speed_Max)
		  	document.query.Wind_Speed_Max.checked = 0;
		if(document.query.Wind_Gust)
		  	document.query.Wind_Gust.checked = 0;
		if(document.query.Evaporation)
		  	document.query.Evaporation.checked = 0;
		if(document.query.Min_Temp_Evaporation_Pan)
		  	document.query.Min_Temp_Evaporation_Pan.checked = 0;
		if(document.query.Max_Temp_Evaporation_Pan)
		  	document.query.Max_Temp_Evaporation_Pan.checked = 0;
		if(document.query.Wind_Movement)
		  	document.query.Wind_Movement.checked = 0;
		if(document.query.Water_Equiv_Of_Snow_Depth)
		  	document.query.Water_Equiv_Of_Snow_Depth.checked = 0;
		if(document.query.Avg_Wind_Direction)
		  	document.query.Avg_Wind_Direction.checked = 0;
		if(document.query.Avg_Rel_Humidity)
		  	document.query.Avg_Rel_Humidity.checked = 0;
		if(document.query.Max_Rel_Humidity)
		  	document.query.Max_Rel_Humidity.checked = 0;
		if(document.query.Min_Rel_Humidity)
		  	document.query.Min_Rel_Humidity.checked = 0;
		if(document.query.Peak_Wind_Gust)
		  	document.query.Peak_Wind_Gust.checked = 0;
		if(document.query.Peak_Wind_Dir)
		  	document.query.Peak_Wind_Dir.checked = 0;
		if(document.query.Avg_Daily_Station_Pressure)
		  	document.query.Avg_Daily_Station_Pressure.checked = 0;
		if(document.query.Avg_Daily_Sea_Level_Pressure)
		  	document.query.Avg_Daily_Sea_Level_Pressure.checked = 0;
		if(document.query.Avg_Daily_Dew_Point_Pressure)
		  	document.query.Avg_Daily_Dew_Point_Pressure.checked = 0;
		if(document.query.Avg_Daily_Wet_Bulb_Pressure)
		  	document.query.Avg_Daily_Wet_Bulb_Pressure.checked = 0;
		if(document.query.Avg_Daily_Temp)
		  	document.query.Avg_Daily_Temp.checked = 0;
		if(document.query.Solar_Radiation)
		  	document.query.Solar_Radiation.checked = 0;
		if(document.query.Avg_Wind_Speed)
		  	document.query.Avg_Wind_Speed.checked = 0;
		
	}
}

function TrackCoordinatesInImage(e)
{
  var evt = new xEvent(e);

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}

  //this is where you position the click so you don't get dots off map
  if ( (posx < 245) || (posx > 675) || (posy < 225) || (posy > 725) ) {
	hidedtip();
	return;	
  }

  var ele = evt.target;
  if (ele) {
  	document.mapserv.map_x_val.value = evt.offsetX;
  	document.mapserv.map_y_val.value = evt.offsetY;
  }

  //var ttext = evt.offsetX + ' -- ' + evt.offsetY;
  //window.status= ttext;


	if (ArrDef == 10) {
		var xypos = evt.offsetX + "-" + evt.offsetY;

		if (xyPosArr[xypos]) {
			var station = xyPosArr[xypos];
			var sinfo=station.split(",");
			var wtext = '<table class=sm><tr><td><b>Station Name: </b></td><td>' + sinfo[0] + '</td></tr>';
			wtext += '<tr><td><b>Period of Record: </b></td><td>' + sinfo[2] + '</td></tr></table>';

			if (station.length > 3) {
				dtip(wtext, 250)
				positiontip(e)
			}
		} else {
			hidedtip();
		}
	}
}
function callToServerSearch(theServerName)
{
	document.mapserv.tool.value = 'search';
	document.mapserv.city_name.value = document.mapsearch.city_name.value;
	document.mapserv.state_name.value = document.mapsearch.state_name.value;
	return(callToServer(theServerName));
}
function callToLayerServer(theServerName)
{
	document.mapserv.tool.value = 'layer_refresh';
	return(callToServer(theServerName));
}
function buildQueryString() {
  theForm = document.forms.mapserv;
  var qs = ''

  for (e=0;e<theForm.elements.length;e++) {
    if (theForm.elements[e].name!='') {
      qs+=(qs=='')?'?':'&'
      qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
      }
    }
  theForm = document.forms.layserv;
  for (e=0;e<theForm.elements.length;e++) {
    if (theForm.elements[e].name!='') {
		if (theForm.elements[e].type != 'checkbox') {
	      qs+=(qs=='')?'?':'&'
	      qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
		} else {
			if (theForm.elements[e].checked) {
	      		qs+=(qs=='')?'?':'&'
	      		qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
			}
		}
      }
    }
  return qs
}

var IFrameObj; // our IFrame object
function callToServer(theServerName) {

  if (!document.createElement) {
  	return true;
  };
  var IFrameDoc;


  var URL = theServerName + buildQueryString() + '&shftMode=' + shftMode;

  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      /* This is for IE5 PC, which does not allow dynamic creation
       and manipulation of an iframe object. Instead, we'll fake
       it up by creating our own objects.
	  */
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }

  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
  
    return true;
  }

  IFrameDoc.location.replace(URL);
  return false;
}
function createArray(n, init)
{
     this.size = n  //This initialization is absolutely necessary
     for (i = 1 ; i <= n ; i++)
          {
               this[i] = init      //Initialize all of the left hand elements
          }
     return this         //Return the  array object to the caller
}
function getAllFormFields(node, bool)
{
	var x = node.getElementsByTagName('input');
	for (var i=0;i<x.length;i++)
		x[i].disabled = bool;
	//var y = node.getElementsByTagName('option');
	var y = node.getElementsByTagName('select');
	for (var i=0;i<y.length;i++)
		y[i].disabled = bool;
}
function enabledQForm()
{
	var form = document.query;
    getAllFormFields(form,false);
}
function disableQForm()
{
    var allFields = getAllFormFields(document.query,true);
}
function removeAllOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
	} 
} 
// Handle Iframe callback to receive stations selections
function handleResponse3(msg) {

	if (msg.length < 1) return;

	var entries=msg.split(";");

	if (entries.length > 11) {
		alert('Only 10 stations may be selected at anyone time.  You have exceeded this limit and only 10 stations have been selected.');
		entries.length = 11;
	}

	var elements=entries[0].split(",");
	// elements should now have -- Name, Num, Elev, start date, end date, state;
	var stat_num = "";
	var sdates=elements[3].split("-")
	var edates=elements[4].split("-")

	if (elements[2] == 'COUNTRY') {
		var html = '<table width=400 cellpadding=1 cellspacing=1 class=dk><tr><td><b>Station Name</b></td><td><b>&nbsp;&nbsp;&nbsp;Country&nbsp;&nbsp;&nbsp;</b></td><td><b>Period of Record</b></td></tr>';
	} else {
		var html = '<table width=400 cellpadding=1 cellspacing=1 class=dk><tr><td><b>Station Name</b></td><td><b>&nbsp;&nbsp;&nbsp;State&nbsp;&nbsp;&nbsp;</b></td><td><b>Period of Record</b></td></tr>';
	}
	for (var j=0; j<(entries.length-1); j++) {
		elements=entries[j].split(",");
		if (j==0)
			stat_num = elements[1];
		else
			stat_num += ',' + elements[1];
		html += '<tr><td valign=top>' + elements[0] + '</td><td align=center valign=top>' + elements[5] + '</td><td>' + elements[3] + ' to ' + elements[4] + '</td></tr>'
		var stest=elements[3].split("-")
		var etest=elements[4].split("-")

		if (sdates[0] > stest[0]) sdates[0] = stest[0]
		if (edates[0] < etest[0]) edates[0] = etest[0]
	}
	html += '</table><br>';

	var stDiv = document.getElementById('stat_info');
	stDiv.innerHTML = html
	document.query.stat_id_num.value = stat_num 

	enabledQForm();
	removeAllOptions(document.query.Syear)
	removeAllOptions(document.query.Eyear)

	var i=0
	for (var year=sdates[0]; year<=edates[0]; year++) {
		document.query.Eyear.options[i] = new Option(year, year);
		document.query.Syear.options[i] = new Option(year, year);
		i++;
	}
	document.query.Syear.selectedIndex = 0;
	document.query.Smonth.selectedIndex = stest[1]-1;
	document.query.Sday.selectedIndex = stest[2];
	document.query.Sday.selectedIndex++;
	document.query.Emonth.selectedIndex = stest[1]-1;
	document.query.Eday.selectedIndex = stest[2];
	document.query.Eday.selectedIndex++;
	if (i > 1) {
		document.query.Eyear.selectedIndex = 1;
	} else {
		document.query.Eyear.selectedIndex = 0;
	}

}
// Handle Iframe callback to receive station information for mouseovers
function handleResponse2(msg) {
	var entries=msg.split(";");
	StaionsView = entries.length - 1;

	if (StaionsView <= 0) {
		xyPosArr = new createArray(1,';');
		return;
	}
    ArrDef = 10;

	xyPosArr = new createArray((entries.length*20),';');

	var cnt = 0;
	for (ind=0; ind < (entries.length - 1); ind++) {
		var elements=entries[ind].split(",");

		var ival = parseInt(elements[3]);

		for (i=(ival-3); i <= (ival+3); i++) {
			var xypos = i + "-" + elements[4];
			xyPosArr[cnt] = xypos;
			xyPosArr[xyPosArr[cnt]] = elements[0]+"," +elements[1]+"," +elements[2];
			cnt+=1;
		}

		ival = parseInt(elements[4]);
		for (i=(ival-3); i <= (ival+7); i++) {
			var xypos = elements[3] + "-" + i;
			xyPosArr[cnt] = xypos;
			xyPosArr[xyPosArr[cnt]] = elements[0]+"," +elements[1]+"," +elements[2];
			cnt+=1;
		}
  	}
}
// Handle Iframe callback to receive error looking for a city
function handleResponse5(msg) {
	if (msg.length > 1 ) {
		newMsg = msg + ' was not found, zooming to the selected state.';
		alert(newMsg);
	}
}
// Handle Iframe callback to receive new extents
function handleResponse6(msg,city) {
	if (msg.length > 1 ) {
		newMsg = msg + ' was not found, zooming to the selected Country.';
		newMsg += city;
		alert(newMsg);
	}
}
// Handle Iframe callback to receive new extents
function handleResponse4(msg) {
	//alert(msg);
	//window.status=msg;
}
// Handle Iframe callback to receive new image
function handleResponse1(msg) {
	var extentsDiv = document.getElementById('extents');
	message = '<INPUT TYPE=HIDDEN NAME="extent" VALUE="';
	message += msg;
	message += '">';
	extentsDiv.innerHTML = message;
}
// Handle Iframe callback to receive new image
function handleResponse(msg) {
	var clickDiv = document.getElementById('click');
	message = '<img SRC="';
	message += msg;
	message += '"><div id=box> <\/div>';

	clickDiv.innerHTML = message;

    var ele = xGetElementById('click');
    xMoveTo(ele, 0, 0);
}
// Handle Iframe callback to determine if layer legend should appear
function handleResponse7(msg)
{
	if(msg == 1)
	{
		var obj = document.getElementById('precip');
		obj.style.visibility='visible';
	}
	else
	{
		var obj = document.getElementById('precip');
		obj.style.visibility='hidden';
	}
}
function openHelp() {
	var help_win = window.open("/help.php?page=menudata", "", "width=850,height=700,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=,status=no");
}
function showOptions() {
	var help_win = window.open("coop_options.php", "", "width=600,height=600,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=,status=no");

    return false;
}
function setTool(tool,server) {
	if (tool == "zoom_in") {
		document.mapserv.tool.value = tool;
  		document.mapserv.map_x_val.value = 215;
  		document.mapserv.map_y_val.value = 250;//use to be 225 and the map would move down
		callToServer(server);
	} 
	if (tool == "zoom_out") {
		document.mapserv.tool.value = tool;
  		document.mapserv.map_x_val.value = 215;
  		document.mapserv.map_y_val.value = 250;//use to be 225 and the map would move down
		callToServer(server);
	} 
	if (tool == "reset") {
		document.mapserv.tool.value = tool;
  		document.layserv.AStations.checked = 1
  		document.layserv.IStations.checked = 1
  		document.layserv.Cities.checked = 1
		if (server != "server_gsod.php") {
  			document.layserv.Interstates.checked = 1
  			document.layserv.States.checked = 1
		} else {
  			document.layserv.Country.checked = 1
		}
  		document.layserv.Raster.checked = 1

		callToServer(server);
	} 
	if (tool == "selecttl") {
		if (StaionsView < 1) {
			alert('There are no stations in the current view.\nZoom in on the map until stations are visiable, then click this button to enable station selection.\nFor details about map navigation click on the help book icon.');
		} else {
			if (StationSel == 1) {
				document.mapserv.selecttl.src = "../img/data/but_sel_0.gif";
				StationSel = 0;
			} else {
				document.mapserv.selecttl.src = "../img/data/but_sel_1.gif";
				StationSel = 1;
				document.mapserv.select_state.value = "select";
			}
		}
	}
}

function SetDates(date_vals) {
	//window.status=date_vals;

	var elements=date_vals.split("-");
	// elements should now have --  start year, start month, start date, end year, end month, and end day ;

	for (var j=0; j<(document.query.Syear.length); j++) {
		yearString = document.query.Syear.options[j].text;
		if (yearString == elements[0])
			document.query.Syear.selectedIndex = j;
	}
	for (var j=0; j<(document.query.Smonth.length); j++) {
		yearString = document.query.Smonth.options[j].value;
		if (yearString == elements[1])
			document.query.Smonth.selectedIndex = j;
	}
	for (var j=0; j<(document.query.Sday.length); j++) {
		yearString = document.query.Sday.options[j].text;
		if (yearString == elements[2])
			document.query.Sday.selectedIndex = j;
	}
	for (var j=0; j<(document.query.Eyear.length); j++) {
		yearString = document.query.Eyear.options[j].text;
		if (yearString == elements[3])
			document.query.Eyear.selectedIndex = j;
	}
	for (var j=0; j<(document.query.Emonth.length); j++) {
		yearString = document.query.Emonth.options[j].value;
		if (yearString == elements[4])
			document.query.Emonth.selectedIndex = j;
	}
	for (var j=0; j<(document.query.Eday.length); j++) {
		yearString = document.query.Eday.options[j].text;
		if (yearString == elements[5])
			document.query.Eday.selectedIndex = j;
	}
}

///////////////////////////
///////////////////////////
// Add Stuff for Tool Tip!!
///////////////////////////
///////////////////////////
var offsetfromcursorX=12
var offsetfromcursorY=10

var offsetdivfrompointerX=10
var offsetdivfrompointerY=14

var hide_count=0;

var enabletip=false

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function dtip(thetext, thewidth, thecolor){
	var tipobj = document.getElementById('tooltp');
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
	if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
	tipobj.innerHTML=thetext
	enabletip=true
	hide_count=0
	return false
}

function positiontip(e){
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
	if (enabletip){
		var pointerobj = document.getElementById('toolptr');
		var pointerobjr = document.getElementById('toolptrr');
		var tipobj = document.getElementById('tooltp');
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;


		var winwidth=710
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			pointerobjr.style.left=curX - 20;
			pointerobjr.style.top=curY+offsetfromcursorY+"px"
			pointerobjr.style.visibility="visible"
			pointerobj.style.visibility="hidden"
		} else{
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
			pointerobj.style.visibility="visible"
			pointerobjr.style.visibility="hidden"
		}

		tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
		tipobj.style.visibility="visible"
	}
}

function hidedtip(){
	hide_count++

	if (hide_count > 3) {
		var tipobj = document.getElementById('tooltp');
		var pointerobj = document.getElementById('toolptr');
		var pointerobjr = document.getElementById('toolptrr');
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		pointerobjr.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip

function clickIE() {if (document.all) {return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu=new Function("return false") 
