// This script creates the menu's for the weather data section of the site
// Created by Martin Warning, mwarning@hotmail.com


	// !! Be very careful when modifying !!

	// This code is used on all pages in the weatherdata folder



	// Features:
	// * Entrance menu with only last months data
	// 	* Graphs and total.txt open in a new window
	//	* Summary data will open the city page itself

	// * City based menus with more information by city
	// 	* All months available for the specific city
	//	* Different amounts of information available for cities
	//	* Graphics open in page itself
	//		* If the month of the graph selected is other then the month 
	//		  of the page displayed, the page is changed to the month  
	//		  of the graph and the selected graph is displayed

	//	* Summary will open the selected months page
	//	* The total.txt file will open in a new window

	// * Menu shown changes based on which city is viewed



	// ! Code only works for the -http://www.tamiu.edu/cost/drought/weatherdata- folder
	// ! All option fields with no data are set to value -a- which will not return anything
	// ! Certain cities have less months available, seperate code exists for these
	// ! Certain cities have additional data available, separate code exists for these
	// ! Rainfall graphics are blocked for months earlier the July
	// ! Code needs to be adjusted in 2002 to have a year option box
	// ! All months have to have 3 characters
	// ! All Years have to have for characters	
		
		
		
		
		
		
		

// Check current month and year displayed
// Answer looks like '/2001/aug/'
// Is used to change month page when a graph from another month is selected, see the chgImg function
	var dirs = location.href.substring(location.href.lastIndexOf('/')-4,location.href.lastIndexOf('/')+1);
	var curlocation = "/2001" + dirs;


// Loads the default image or loads the image selected by the user
// Used in chgImg function
var table_of_contents = "total.gif";  // loads default image
var content = (location.search) ? location.search.substring(1, location.search.length) : table_of_contents;


// To have the images change within a page, used in the drop-down menu's
// !! This function is not for the links at the bottom of the page, there is seperate funcrion called chgImg

	// Function to change the image and the page if month of page and image are not the same
	function chgImgDrop(link,fromurl,city,site) {
	
		var dirs = location.href.substring(location.href.lastIndexOf('/')-4,location.href.lastIndexOf('/')+1);
		var curlocation = "/2001" + dirs;

		// If the page month and graph month are the same then just the image is changed
		if (fromurl == curlocation)
		{
			document.weatherdata.src = link;
		}
		else
		{
			// Create the link to open the new month page with the selected graph	
			var toopenpage = site + "/" + city + fromurl + "index.htm?" + link;

			// The actual opening of the page
			eval("parent.main.location='" + toopenpage + "'");
		}

	}

	// Display the image on the page
	var displayimage = "<IMG SRC='" + content + "' name='weatherdata' ALT='Weatherdata graphics'>";



// Function to change images on a page from the links at the bottom of the page
	function chgImg(link) {
		document.weatherdata.src = link;
	}





// Menu 1 with cities
	var linecity1 ="<select name=menu1 ID=style1>";
	var linecity2 = "";

// Create the city in the menu if on that city page, city will also be auto selected
// Other cities will not show up in the menu
	// Aguilares
		if (document.title == "Aguilares Weather Data"){var linecity3 ="<option selected value=aguilares>Aguilares</option>";}
		else{var linecity3 = "";}

	// Asherton
		if (document.title == "Asherton Weather Data"){var linecity4 ="<option selected value=asherton>Asherton</option>";}
		else{var linecity4 = "";}

	// Benavides
		if (document.title == "Benavides Weather Data"){var linecity5 ="<option selected value=benavides>Benavides</option>";}
		else{var linecity5 = "";}

	// Brundage
		if (document.title == "Brundage Weather Data"){var linecity6 ="<option selected value=brundage>Brundage</option>";}
		else{var linecity6 = "";}
		
	// Bruni
		if (document.title == "Bruni Weather Data"){var linecity7 ="<option selected value=bruni>Bruni</option>";}
		else{var linecity7 = "";}

	// Bruni 2
		if (document.title == "Bruni2 Weather Data"){var linecity8 ="<option selected value=bruni2>Bruni 2</option>";}
		else{var linecity8 = "";}

	// Bruni 2050
		if (document.title == "Bruni 2050 Weather Data"){var linecity9 ="<option selected value=bruni2050>Bruni (2050)</option>";}
		else{var linecity9 = "";}

	// Carrizo Springs
		if (document.title == "Carrizo Springs Weather Data"){var linecity10 ="<option selected value=carrizosprings>Carrizo Springs</option>";}
		else{var linecity10 = "";}

	// Chaparral Wildlife Area
		if (document.title == "Chaparral Wildlife Area Weather Data"){var linecity11 ="<option selected value=chaparral>Chaparral Wildlife Area</option>";}
		else{var linecity11 = "";}

	// Dimmit County 1
		if (document.title == "Dimmit County 1 Weather Data"){var linecity12 ="<option selected value=dimmit1>Dimmit County 1</option>";}
		else{var linecity12 = "";}

	// Dimmit County 2
		if (document.title == "Dimmit County 2 Weather Data"){var linecity12 ="<option selected value=dimmit2>Dimmit County 2</option>";}
		else{var linecity13 = "";}

	// Dimmit County 3
		if (document.title == "Dimmit County 3 Weather Data"){var linecity14 ="<option selected value=dimmit3>Dimmit County 3</option>";}
		else{var linecity14 = "";}

	// Encinal
		if (document.title == "Encinal Weather Data"){var linecity15 ="<option selected value=encinal>Encinal</option>";}
		else{var linecity15 = "";}

	// Falfurrias
		if (document.title == "Falfurrias Weather Data"){var linecity16 ="<option selected value=falfurrias>Falfurrias</option>";}
		else{var linecity16 = "";}

	// Hebbronville
		if (document.title == "Hebbronville Weather Data"){var linecity17 ="<option selected value=hebbronville>Hebbronville</option>";}
		else{var linecity17 = "";}

	// Laredo Pueblo Nuevo
		if (document.title == "Laredo Pueblo Nuevo Weather Data"){var linecity19 ="<option selected value=laredopueblonuevo>Laredo (Pueblo Nuevo)</option>";}
		else{var linecity19 = "";}

	// Laredo Tamiu
		if (document.title == "Laredo Tamiu Weather Data"){var linecity20 ="<option selected value=laredotamiu>Laredo (Tamiu)</option>";}
		else{var linecity20 = "";}

	// Mirando City
		if (document.title == "Mirando City Weather Data"){var linecity21 ="<option selected value=mirandocity>Mirando City</option>";}
		else{var linecity21 = "";}

	// US-59
		if (document.title == "US 59 Weather Data"){var linecity22 ="<option selected value=us59>US 59</option>";}
		else{var linecity22 = "";}

	// Winter Garden
		if (document.title == "Winter Garden Weather Data"){var linecity23 ="<option selected value=wintergarden>Winter Garden</option>";}
		else{var linecity23 = "";}

	// All Weather Data, shows all cities in the main page
		if (document.title == "All Weather Data")
		{
			var linecity2 ="<option selected value=a>City</option>";
			var linecity3 ="<option value=aguilares>Aguilares</option>";
			var linecity4 ="<option value=asherton>Asherton</option>";
			var linecity5 ="<option value=benavides>Benavides</option>";
			var linecity6 ="<option value=brundage>Brundage</option>";
			var linecity7 ="<option value=bruni>Bruni</option>";
			var linecity8 ="<option value=bruni2>Bruni 2</option>";
			var linecity9 ="<option value=bruni2050>Bruni (2050)</option>";
			var linecity10 ="<option value=carrizosprings>Carrizo Springs</option>";
			var linecity11 ="<option value=chaparral>Chaparral Wildlife Area</option>";
			var linecity12 ="<option value=dimmit1>Dimmit County 1</option>";
			var linecity13 ="<option value=dimmit2>Dimmit County 2</option>";
			var linecity14 ="<option value=dimmit3>Dimmit County 3</option>";
			var linecity15 ="<option value=encinal>Encinal</option>";
			var linecity16 ="<option value=falfurrias>Falfurrias</option>";
			var linecity17 ="<option value=hebbronville>Hebbronville</option>";
			var linecity19 ="<option value=laredopueblonuevo>Laredo (Pueblo Nuevo)</option>";
			var linecity20 ="<option value=laredotamiu>Laredo (Tamiu)</option>";
			var linecity21 ="<option value=mirandocity>Mirando City</option>";
			var linecity22 ="<option value=us59>US 59</option>";
			var linecity23 ="<option value=wintergarden>Winter Garden</option>";
		}
		
	// Show other option, shows other option when in the city pages
		if (document.title != "All Weather Data")
		{var linecity24 ="<option value=a>--------</option><option value=other>Other</option>";}
		else{var linecity24 = "";}

	var linecity25 ="</select>";
	
	var linecity = linecity1 + linecity2 + linecity3 + linecity4 + linecity5 + linecity6 + linecity7 + linecity8 + linecity9 + linecity10 + linecity11 + linecity12 + linecity13 + linecity14 + linecity15 + linecity16 + linecity17 + linecity19 + linecity20 + linecity21 + linecity22 + linecity23 + linecity24 + linecity25;
// End menu1 with cities







// Menu 2 with date
  // The month option should have the latest month as value
	var linedate1 ="<select name=menu2 ID=style1>";
	var linedate2 ="<option value=a>Month</option>";
	var linedate3 ="<option value=/2001/feb/>2001 February</option>";
	var linedate4 ="<option value=/2001/mar/>2001 March</option>";
	var linedate5 ="<option value=/2001/apr/>2001 April</option>";
	var linedate6 ="<option value=/2001/may/>2001 May</option>";
	var linedate7 ="<option value=/2001/jun/>2001 June</option>";
	var linedate8 ="<option value=/2001/jul/>2001 July</option>";
	var linedate9 ="<option value=/2001/aug/>2001 August</option>";
	var linedate10 ="<option value=/2001/sep/>2001 September</option>";
	var linedate11 ="<option value=/2001/oct/>2001 October</option>";
	var linedate12 ="<option value=/2001/nov/>2001 November</option>";
	var linedate13 ="<option value=/2001/dec/>2001 December</option>";

	var linedate20 ="<option value=/2002/jan/>2002 January</option>";
	var linedate21 ="<option value=/2002/feb/>2002 February</option>";
	var linedate22 ="<option value=/2002/mar/>2002 March</option>";
	var linedate23 ="<option value=a>--------------</option>";
	var linedate24 ="<option value=a></option>";

	var linedate99 ="</select>";


// Limitations
     // Dimmit County 2 not done yet	
	if (document.title == "Dimmit County 2 Weather Data")
	{
		var linedate12 = "";
		var linedate13 = "";
		var linedate20 = "";
		var linedate21 = "";
	}


     // Dimmit County 3 not done yet	
	if (document.title == "Dimmit County 3 Weather Data")
	{
		var linedate20 = "";
		var linedate21 = "";
	}

     // Bruni2 misses November & December	
	if (document.title == "Bruni2 Weather Data")
	{
		var linedate12 = "";
		var linedate13 = "";
	}

     // Laredo Tamiu misses first couple of months	
	if (document.title == "Laredo Tamiu Weather Data")
	{
		var linedate3 = "";
		var linedate4 = "";
		var linedate5 = "";
		var linedate6 = "";
	}
	
     // For cities where data measurement started June 2001
	if (document.title == "Bruni 2050 Weather Data" || document.title == "Laredo Larga Vista Weather Data" || document.title == "Laredo Pinieas Weather Data" || document.title == "Laredo Pueblo Nuevo Weather Data" || document.title == "US 59 Weather Data"  || document.title == "Encinal Weather Data")
	{
		var linedate3 = "";
		var linedate4 = "";
		var linedate5 = "";
		var linedate6 = "";
	}

     // Mirando City and Laredo Pueblo Nuevo miss data for September
	if (document.title == "Mirando City Weather Data" || document.title == "Laredo Pueblo Nuevo Weather Data")
	{

		var linedate10 = "";
	}	

     // For cities where data measurement started September 2001
	if (document.title == "Dimmit County 1 Weather Data" || document.title == "Dimmit County 2 Weather Data" || document.title == "Dimmit County 3 Weather Data" || document.title == "Brundage Weather Data" || document.title == "Carrizo Springs Weather Data" || document.title == "Asherton Weather Data" || document.title == "Chaparral Wildlife Area Weather Data" || document.title == "Winter Garden Weather Data")
	{
		var linedate3 = "";
		var linedate4 = "";
		var linedate5 = "";
		var linedate6 = "";
		var linedate7 = "";
		var linedate8 = "";
		var linedate9 = "";
	}

	var linedate = linedate1 + linedate2 + linedate20 + linedate21 + linedate22 + linedate23 + linedate3 + linedate4 + linedate5 + linedate6 + linedate7 + linedate8 + linedate9 + linedate10 + linedate11 + linedate12 + linedate13 + linedate99;

     // Main page just has latest data/graphs
     
 // !!!!!! the last 2 linedate need to be updated each month, untill we have all 12 months.
	if (document.title == "All Weather Data")
	{
		var linedate = linedate1 + linedate22 + linedate99;
	}

// End menu 2






// Menu 3 with data
  // Be careful with naming the variables as date and data are quite similar
	var linedata1 ="<select name=menu3 ID=style1>";
	var linedata2 ="<option value=a>Graphs:</option>";
	var linedata3 ="<option value=a>--------------</option>";
	var linedata4 ="<option value=dewpoint.gif>Dewpoint</option>";
	var linedata5 ="<option value=humidity.gif>Humidity</option>";
	var linedata6 ="<option value=rainfall.gif>Rainfall</option>";
	var linedata7 ="<option value=temperature.gif>Temperature</option>";
	var linedata8 ="<option value=total.gif>All</option>";
	var linedata9 ="<option value=a>         </option>";
	var linedata10 ="<option value=index.htm>Summary data</option>";
	var linedata11 ="<option value=a>         </option>";
	var linedata12 ="<option value=a>Downloads:</option>";
	var linedata13 ="<option value=a>--------------</option>";
	var linedata14 ="<option value=total.txt>Complete data</option>";
	var linedata15 ="</select>";

	var linedata = linedata1 + linedata2 + linedata3 + linedata4 + linedata5 + linedata6 + linedata7 + linedata9 + linedata10 + linedata11 + linedata12 + linedata13 + linedata14 + linedata15;
// End menu 3







// This variable creates the complete menu
var complete = linecity + linedate + linedata



// Display warning message for Netscape users
	var bName=navigator.appName;
	var bVer=parseInt(navigator.appVersion);
	if (bName=="Netscape" && bVer<4)
	{
		var netback = "<CENTER><FONT COLOR=red>Please use BACK button after viewing data</FONT>";
	}
	else {
		var netback = "";
	}


// The following code executes the menu's correctly
site = "http://www.tamiu.edu/cost/drought/weatherdata";
function combineMenus(frm, menu1, menu2, menu3) {
  with (frm) {
    str = menu1.options[menu1.selectedIndex].value;
    str += menu2.options[menu2.selectedIndex].value;
    str += menu3.options[menu3.selectedIndex].value;
    url = site + "/" + str;
  

// Declare some variables we will use
        URLS1 = menu1.options[menu1.selectedIndex].value;
	URLS2 = menu2.options[menu2.selectedIndex].value;
	URLS3 = menu3.options[menu3.selectedIndex].value;
	
        // To move from the city menu's back to the main menu
        if (URLS1 == "other")
	{
	  url = site + "/index.htm";
	  window.location.href = url;
	}
	else
	{
    // To make the Script work in Netscape versions lower than 4 and in Opera
	  var bName=navigator.appName;
	  var bVer=parseInt(navigator.appVersion);
	  if (bName=="Netscape" && bVer<4)
	  {
	    window.location.href = url;
	  }
	  else
	  {

	// Some warnings if user doesn't select something in the pulldown menu's 
		if (URLS1 == "a")
		{
		  alert ("Please select a city!");
		}
		else if (URLS2 == "a")
		{
		  alert ("Please select a month!");
		}
		else if (URLS3 == "a")
		{
		  alert ("Please select a graph or download!");
		}

	// The total.txt files are displayed in a different formatted window as they can be downloaded
		else if (URLS3 == "total.txt")
		{		
		  window.open(url, 'popup', 'menubar=1,scrollbars=1,resizable=1,width=550,height=500');
		}
		
	// Open the selected month page	
		else if (URLS3 == "index.htm")
		{
		  eval("parent.main.location='"+url+"'");
		}
		
	// Only the main page, this will open pop-ups for the graphs too.	
		else if (document.title == "All Weather Data")
		{		
		  window.open(url, title, 'menubar=0,scrollbars=0,resizable=0,width=600,height=300');
		}
		
	// Displaying the graphs
	// No data previous to July available
		else if (URLS3 == "rainfall.gif")
		{
		  if (URLS2 == "/2001/jul/" || URLS2 == "/2001/aug/" || URLS2 == "/2001/sep/")
		  {
		    chgImgDrop(url,URLS2,URLS1,site)
		  }
		  else
		  {
		    alert ("Sorry, no rainfall graphs previous to July are available!");
		  }
		}
				
	// Displaying the remaining graphs
		else
		{
		  chgImgDrop(url,URLS2,URLS1,site)
		}
	  }
	}
  }
}
