// Used to create all stock selection lists for Inseason Forecast forms
// modify crisprt.js for query year as season progresses and forecasts are 
//	started for various species and stocks
// add or remove stocks as needed for the current season
// values for Stock, FishType, Location, etc. are defined in 
//	/usr/local/cbr/perl/lib/CBR/CRISPRT/Lexicon.pm under SVN control

// argument from html
var x;
function formSnakePit() {
	// form objects
	var predElement = document.snakePit.predType;
	var locElement = document.snakePit.location;
	var stkElement = document.snakePit.stock;
	var locSel;
	var stkSel;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'survival' && x != 'daily' && x != 'passage' && x != 'pbg' && x != 'survtoday' && x != 'transtoday' && x != 'trans') {
		x = 'passage';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
	} else {
		// if an option is selected in location select, capture it
		if ( x == 'passage' || x == 'survival' || x == 'daily' || x == 'pbg' || x == 'survtoday' || x == 'transtoday' || x == 'trans') {
  			for ( var i = 0; i < locElement.options.length; i++ ) {
				if ( locElement.options[i].selected ) {
					locSel = i;
				}
			}
  			for ( var i = 0; i < stkElement.options.length; i++ ) {
				if ( stkElement.options[i].selected ) {
					stkSel = i;
				}
			}
		}
	}

	// set length of location ans stock select list to 0
  	locElement.options.length = 0;
 	 var loc1,loc2,loc3,loc4,loc5,loc6;
  	stkElement.options.length = 0;
  	var stk1,stk2,stk3,stk4,stk5,stk6,stk7,stk8,stk9,stk10,
		stk11,stk12,stk13,stk14,stk15,stk16,stk17,stk18,
		stk19,stk20,stk21,stk22,stk23,stk24,stk25,stk26,
		stk27,stk28,stk29,stk30,stk31,stk32,stk33,stk34;


	// if daily or pbg, initialize options of location and stock
	if ( x == 'daily' || x == 'pbg') {
	  // locx = new Option("Label","Location",Selected?,Default?);

	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Lower Granite Dam","Lower_Granite_Dam",true,true);

	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook Select Composite Wild","chin1:real:",true,true);
		stk2 = new Option("Yearling Chinook All Wild","chin1:chin1pit:",false,false);
		stk3 = new Option("Yearling Chinook Big Creek Wild","chin1:BIG2C:",false,false);
		stk4 = new Option("Yearling Chinook Catherine Creek Wild","chin1:CATHEC:",false,false);
		stk5 = new Option("Yearling Chinook Grande Ronde River Wild","chin1:GRAND2:",false,false);
		stk6 = new Option("Yearling Chinook Imnaha River Wild","chin1:IMNAHR:",false,false);
		stk7 = new Option("Yearling Chinook Imnaha River Trap Wild","chin1:IMNTRP:",false,false);
		stk8 = new Option("Yearling Chinook Johnson Creek Trap Wild","chin1:JOHTRP:",false,false);
		stk9 = new Option("Yearling Chinook Lemhi River Wild","chin1:LEMHIR:",false,false);
		stk10 = new Option("Yearling Chinook Lemhi River Weir Wild","chin1:LEMHIW:",false,false);
		stk11 = new Option("Yearling Chinook Lookingglass Creek Wild","chin1:LOOKGC:",false,false);
		stk12 = new Option("Yearling Chinook Lostine River Wild","chin1:LOSTIR:",false,false);
		stk13 = new Option("Yearling Chinook Meadow Creek Wild","chin1:MEADOC:",false,false);
		stk14 = new Option("Yearling Chinook Minam River Wild","chin1:MINAMR:",false,false);
		stk15 = new Option("Yearling Chinook Valley Creek Wild","chin1:VALEYC:",false,false);
		stk16 = new Option("Steelhead, Wild","stlhd:lgrStlhd:",false,false);
		stk17 = new Option("Subyearling Chinook, Wild, Snake River","chin0:SNAKER:",false,false);
		stk18 = new Option("Subyearling Chinook, Wild, Clearwater River","chin0:clearww:",false,false);
		stk19 = new Option("Sockeye, Hatchery, Redfish Lake","sock:REDFL:",false,false);

	// if passage, initialize options of location and stock
	} else if ( x == 'passage' ) {
	  // locx = new Option("Label","Config Suffix:Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Config Suffix is either "one.rt" for RT location or
	  //	"one.crisp" for CRiSP location
	  //  Location is either not specified for all sites web page or individual location
		loc1 = new Option("All Sites","all:",true,true);
		loc2 = new Option("Lower Granite Dam","one.rt:Lower_Granite_Dam",false,false);
		loc3 = new Option("Little Goose Dam","one.crisp:Little_Goose_Dam",false,false);
		loc4 = new Option("Lower Monumental Dam","one.crisp:Lower_Monumental_Dam",false,false);
		loc5 = new Option("Ice Harbor Dam","one.crisp:Ice_Harbor_Dam",false,false);
		loc6 = new Option("McNary Dam","one.crisp:McNary_Dam",false,false);

	  // stkx = new Option("Label","Config Prefix:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  Config Prefix is the beginning of the Config file name which 
	  //	will be joined with Config Suffix
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook","passage.snake.pit.chin1:real:",true,true);
		stk2 = new Option("Steelhead","passage.snake.pit.stlhd:lgrStlhd:",false,false);
		stk3 = new Option("Subyearling Chinook *","passage.snake.pit.chin0:SNAKER:",false,false);
		stk4 = new Option("Sockeye, Hatchery, Redfish Lake *","passage.snake.pit.sock:REDFL:",false,false);


	// if survival or transtoday or trans, initialize options of location and stock
	} else if ( x == 'survival' || x == 'transtoday' || x == 'trans' ) {
	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is empty because there is only one possible location
		loc1 = new Option("All Sites","",true,true);
		loc2 = new Option("Lower Granite Dam","",true,true);

	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook Select Composite Wild","chin1:real:",true,true);
		stk2 = new Option("Yearling Chinook All Wild","chin1:chin1pit:",false,false);
		stk3 = new Option("Steelhead, Wild","stlhd:lgrStlhd:",false,false);
	} else if ( x == 'survtoday' ) {
	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is empty because there is only one possible location
		loc1 = new Option("Lower Granite Dam-Bonneville Dam","Lower_Granite_Dam:Bonneville_Dam:4/1:7/5",true,true);
		loc2 = new Option("Lower Granite Dam-McNary Dam","Lower_Granite_Dam:McNary_Dam:4/1:7/5",false,false);
		loc3 = new Option("McNary Dam-Bonneville Dam","McNary_Dam:Bonneville_Dam:4/15:9/9",false,false);

	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook, Wild","chin1:2009",true,true);
		stk2 = new Option("Steelhead, Wild","stlhd:2009",false,false);
	}
		
	// populate options depending on predType
	if ( x == 'passage' ) {
		// add options to select objects
		for ( var i = 1; i < 7; i++ ) {
			locElement.options[locElement.options.length] = eval("loc" + i);
		}
		for ( var i = 1; i < 5; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	} else if ( x == 'survival' || x == 'transtoday' || x == 'trans' || x == 'survtoday' ) {
		// add options to select objects
		if ( x == 'survival' || x == 'trans' ) {
			locElement.options[locElement.options.length] = loc1;
		} else if ( x == 'transtoday' ) {
			locElement.options[locElement.options.length] = loc2;
		} else if ( x == 'survtoday' ) {
			for ( var i = 1; i < 4; i++ ) {
				locElement.options[locElement.options.length] = eval("loc" + i);
			}
		}
		for ( var i = 1; i < 5; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	} else if ( x == 'daily' || x == 'pbg' ) {
		// add options to select objects
		locElement.options[locElement.options.length] = loc1;
		for ( var i = 1; i <= 20; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	}
	// set defaults
	locElement.options[0].selected = true;
	locElement.options[0].defaultSelected = true;
	stkElement.options[0].selected = true;
	stkElement.options[0].defaultSelected = true;

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function formMidColPI() {
	// form objects
	var predElement = document.midColPI.predType;
	var locElement = document.midColPI.location;
	var stkElement = document.midColPI.stock;
	var locSel;
	var stkSel;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'daily' && x != 'passage' && x != 'pbg' ) {
		x = 'passage';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
   	} else {
		// if an option is selected in location select, capture it
		if ( x == 'passage' || x == 'daily' || x == 'pbg' ) {
  			for ( var i = 0; i < locElement.options.length; i++ ) {
				if ( locElement.options[i].selected ) {
					locSel = i;
				}
			}
  			for ( var i = 0; i < stkElement.options.length; i++ ) {
				if ( stkElement.options[i].selected ) {
					stkSel = i;
				}
			}
		}
	}

	// set length of location and stock select list to 0
	locElement.options.length = 0;
	var loc1,loc2,loc3,loc4,loc5;
	stkElement.options.length = 0;
	var stk1,stk2,stk3,stk4,stk5;

	// locx = new Option("Label","Location",Selected?,Default?);
	//  Label is form label for selection object on web page
	//  Location is individual location
	loc1 = new Option("Rock Island Dam","Rock_Island_Dam",true,true);
	loc2 = new Option("Lower Granite Dam","Lower_Granite_Dam",false,false);
	loc3 = new Option("McNary Dam","McNary_Dam",false,false);
	loc4 = new Option("John Day Dam","John_Day_Dam",false,false);
	loc5 = new Option("Bonneville Dam","Bonneville_Dam",false,false);

	// if daily or pbg, initialize options of location and stock
	if ( x == 'daily' || x == 'pbg') {
	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Combined Yearling Chinook","chin1:Chin1:",true,true);
		stk2 = new Option("Combined Steelhead","stlhd:Stlhd:",false,false);
		stk3 = new Option("Combined Subyearling Chinook","chin0:Chin0:",false,false);
		stk4 = new Option("Combined Sockeye","sock:Sock:",false,false);
		stk5 = new Option("Combined Coho","coho:Coho:",false,false);
	// if passage, initialize options of location and stock
	} else if ( x == 'passage' ) {
	  // stkx = new Option("Label","Config:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  Config the Config file name which is used for query
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Combined Yearling Chinook","passage.midcol2.pi.chin1.one.rt:Chin1:",true,true);
		stk2 = new Option("Combined Steelhead","passage.midcol2.pi.stlhd.one.rt:Stlhd:",false,false);
		stk3 = new Option("Combined Subyearling Chinook","passage.midcol2.pi.chin0.one.rt:Chin0:",false,false);
		stk4 = new Option("Combined Sockeye","passage.midcol2.pi.sock.one.rt:Sock:",false,false);
		stk5 = new Option("Combined Coho","passage.midcol2.pi.coho.one.rt:Coho:",false,false);
	}
		
	// add options to select objects
	for ( var i = 1; i < 6; i++ ) {
		locElement.options[locElement.options.length] = eval("loc" + i);
	}
	for ( var i = 1; i < 6; i++ ) {
		stkElement.options[stkElement.options.length] = eval("stk" + i);
	}

	// test to see if "locSel" exists, if so 
	// then set selected attribute to this option
	if ( locSel != null && locSel != 'undefined' ) {
		locElement.options[0].selected = false;
		locElement.options[0].defaultSelected = false;
		locElement.options[locSel].selected = true;
		locElement.options[locSel].defaultSelected = true;
	} else {
		locElement.options[0].selected = true;
		locElement.options[0].defaultSelected = true;
	}
	// test to see if "stkSel" exists, if so 
	// then set selected attribute to this option
	if ( stkSel != null && stkSel != 'undefined' ) {
		stkElement.options[0].selected = false;
		stkElement.options[0].defaultSelected = false;
		stkElement.options[stkSel].selected = true;
		stkElement.options[stkSel].defaultSelected = true;
	} else {
		stkElement.options[0].selected = true;
		stkElement.options[0].defaultSelected = true;
	}

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function formMidColCHE() {
	// form objects
	var predElement = document.midColCHE.predType;
	var locElement = document.midColCHE.location;
	var stkElement = document.midColCHE.stock;
	var locSel;
	var stkSel;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'daily' && x != 'passage' && x != 'pbg' ) {
		x = 'passage';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
   	} else {
		// if an option is selected in location select, capture it
		if ( x == 'passage' || x == 'daily' || x == 'pbg' ) {
  			for ( var i = 0; i < locElement.options.length; i++ ) {
				if ( locElement.options[i].selected ) {
					locSel = i;
				}
			}
  			for ( var i = 0; i < stkElement.options.length; i++ ) {
				if ( stkElement.options[i].selected ) {
					stkSel = i;
				}
			}
		}
	}

	// set length of location and stock select list to 0
	locElement.options.length = 0;
	var loc1;
	stkElement.options.length = 0;
	var stk1,stk2,stk3,stk4,stk5;

	// locx = new Option("Label","Location",Selected?,Default?);
	//  Label is form label for selection object on web page
	//  Location is individual location
	loc1 = new Option("Rocky Reach Dam","Rocky_Reach_Dam",true,true);

	// if daily or pbg, initialize options of location and stock
	if ( x == 'daily' || x == 'pbg') {
	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook","chin1:chechin1:",true,true);
		stk2 = new Option("Steelhead","stlhd:chestlhd:",false,false);
		stk3 = new Option("Subyearling Chinook","chin0:chechin0:",false,false);
		stk4 = new Option("Sockeye","sock:chesock:",false,false);
	// if passage, initialize options of location and stock
	} else if ( x == 'passage' ) {
	  // stkx = new Option("Label","Config:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  Config the Config file name which is used for query
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Yearling Chinook","passage.midcol2.che.chin1.one.rt:chechin1:",true,true);
		stk2 = new Option("Steelhead","passage.midcol2.che.stlhd.one.rt:chestlhd:",false,false);
		stk3 = new Option("Subyearling Chinook","passage.midcol2.che.chin0.one.rt:chechin0:",false,false);
		stk4 = new Option("Sockeye","passage.midcol2.che.sock.one.rt:chesock:",false,false);
	}
		
	// add options to select objects
	locElement.options[0] = loc1;
	for ( var i = 1; i < 5; i++ ) {
		stkElement.options[stkElement.options.length] = eval("stk" + i);
	}

	locElement.options[0].selected = true;
	locElement.options[0].defaultSelected = true;
	// test to see if "stkSel" exists, if so 
	// then set selected attribute to this option
	if ( stkSel != null && stkSel != 'undefined' ) {
		stkElement.options[0].selected = false;
		stkElement.options[0].defaultSelected = false;
		stkElement.options[stkSel].selected = true;
		stkElement.options[stkSel].defaultSelected = true;
	} else {
		stkElement.options[0].selected = true;
		stkElement.options[0].defaultSelected = true;
	}

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function formESUPit() {
	// form objects
	var predElement = document.esuPit.predType;
	var locElement = document.esuPit.location;
	var stkElement = document.esuPit.stock;
	var stkSel;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'daily' && x != 'passage' && x != 'pbg' && x != 'survival' ) {
		x = 'passage';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
	} else {
		// if an option is selected in location select, capture it
		if ( x == 'passage' || x == 'daily' || x == 'pbg' || x == 'survival' ) {
  			for ( var i = 0; i < stkElement.options.length; i++ ) {
				if ( stkElement.options[i].selected ) {
					stkSel = i;
				}
			}
		}
	}

	// set length of location ans stock select list to 0
  	locElement.options.length = 0;
 	var loc1,loc2,loc3,loc4,loc5;
  	stkElement.options.length = 0;
  	var stk1,stk2,stk3,stk4,stk5,stk6,stk7;


	// if daily or pbg, initialize options of location and stock
	if ( x == 'daily' || x == 'pbg') {
	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("McNary Dam","McNary_Dam",true,true);

	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Chinook Spring/Summer ESU, Snake River","chin1:mcnChin1S:",true,true);
		stk2 = new Option("Chinook Fall ESU, Snake River","chin0:mcnChin0S:",false,false);
		stk3 = new Option("Chinook Fall, Upper Col. River","chin0:mcnChin0C:",false,false);
		stk4 = new Option("Steelhead ESU, Snake River","stlhd:mcnStlhdS:",false,false);
		stk5 = new Option("Steelhead ESU, Upper Col. River","stlhd:mcnStlhdC:",false,false);
		stk6 = new Option("Steelhead ESU, Combined Upper Col. & Snake River","stlhd:mcnStlhdCS:",false,false);
		stk7 = new Option("Sockeye ESU, Snake River","sock:mcnSockS:",false,false);

		// set options for location
		locElement.options[locElement.options.length] = loc1;

		// set options for stock
		for ( var i = 1; i < 8; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	// if passage, initialize options of location and stock
	} else if ( x == 'passage' ) {

	  // locx = new Option("Label","Config Suffix:Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Config Suffix is either "one.rt" for RT location or
	  //	"one.crisp" for CRiSP location
	  //  Location is either not specified for all sites web page or individual location
		loc1 = new Option("All Sites","all:",true,true);
		loc2 = new Option("McNary Dam","one.rt:McNary_Dam",false,false);
		loc3 = new Option("John Day Dam","one.crisp:John_Day_Dam",false,false);
		loc4 = new Option("The Dalles Dam","one.crisp:The_Dalles_Dam",false,false);
		loc5 = new Option("Bonneville Dam","one.crisp:Bonneville_Dam",false,false);

	  // stkx = new Option("Label","Config Prefix:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  Config Prefix is the beginning of the Config file name which 
	  //	will be joined with Config Suffix
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Chinook Spring/Summer ESU, Snake River","passage.col.pit.chin1:mcnChin1S:",true,true);
		stk2 = new Option("Chinook Fall ESU, Snake River *","passage.col.pit.chin0:mcnChin0S:",false,false);
		stk3 = new Option("Chinook Fall, Upper Col. River *","passage.col.pit.chin0:mcnChin0C:",false,false);
		stk4 = new Option("Steelhead ESU, Snake River","passage.col.pit.stlhd:mcnStlhdS:",false,false);
		stk5 = new Option("Steelhead ESU, Upper Col. River","passage.col.pit.stlhd:mcnStlhdC:",false,false);
		stk6 = new Option("Steelhead ESU, Combined Upper Col. & Snake River *","passage.col.pit.stlhd:mcnStlhdCS:",false,false);
		stk7 = new Option("Sockeye ESU, Snake River *","passage.col.pit.sock:mcnSockS:",false,false);

		// set options for location
		for ( var i = 1; i < 6; i++ ) {
			locElement.options[locElement.options.length] = eval("loc" + i);
		}
		// set options for stock
		for ( var i = 1; i < 8; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	// if survival, initialize options of location and stock
	} else if ( x == 'survival' ) {
	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is empty because there is only one possible location
		loc1 = new Option("All Sites","",true,true);

	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Chinook Spring/Summer ESU, Snake River","chin1:mcnChin1S:",true,true);
		//stk2 = new Option("Chinook Fall ESU, Snake River","chin0:mcnChin0S:",false,false);
		//stk3 = new Option("Chinook Fall, Upper Col. River","chin0:mcnChin0C:",false,false);
		stk4 = new Option("Steelhead ESU, Snake River","stlhd:mcnStlhdS:",false,false);
		stk5 = new Option("Steelhead ESU, Upper Col. River","stlhd:mcnStlhdC:",false,false);
		// set options for location
		locElement.options[locElement.options.length] = loc1;
		// set options for stock
		for ( var i = 1; i < 6; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
	}
		
	// set defaults
	// test to see if "stkSel" exists, if so 
	// then set selected attribute to this option
	if ( stkSel != null && stkSel != 'undefined' && stkSel < 6 ) {
		stkElement.options[0].selected = false;
		stkElement.options[0].defaultSelected = false;
		stkElement.options[stkSel].selected = true;
		stkElement.options[stkSel].defaultSelected = true;
	} else {
		stkElement.options[0].selected = true;
		stkElement.options[0].defaultSelected = true;
	}
	locElement.options[0].selected = true;
	locElement.options[0].defaultSelected = true;

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function formAdult() {
	// form objects
	var predElement = document.adult.predType;
	var locElement = document.adult.location;
	var stkElement = document.adult.stock;
	var locSel;
	var stkSel;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'adultRun' && x != 'passage' && x != 'adultRunSize' && x != 'adultPeak') {
		x = 'adultRun';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
   	} else {
		// if an option is selected in location select, capture it
		if ( x == 'passage' || x == 'adultRun' || x == 'adultRunSize' || x == 'adultPeak') {
  			for ( var i = 0; i < locElement.options.length; i++ ) {
				if ( locElement.options[i].selected ) {
					locSel = i;
				}
			}
  			for ( var i = 0; i < stkElement.options.length; i++ ) {
				if ( stkElement.options[i].selected ) {
					stkSel = i;
				}
			}
		}
	}

	// set length of location and stock select list to 0
	locElement.options.length = 0;
	var loc1,loc2,loc3,loc4;
	stkElement.options.length = 0;
	var stk1,stk2,stk3,stk4,stk5,stk6,stk7,stk8;

	// if passage, initialize options of location and stock
	if ( x == 'passage' ) {

	  // stkx = new Option("Label","Config Prefix:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  Config Prefix is the beginning of the Config file name which 
	  //	will be joined with Config Suffix
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Adult Spring Chinook, Snake R","passage.snake.apc.fc1:SnakeSpringAdult_4b:",false,false);
		stk2 = new Option("Adult Spring Chinook, Upper Col R","passage.ucol.apc.fc1:UColSpringAdult_4b:",false,false);
		stk3 = new Option("Adult Spring Chinook, Lower Col R","passage.lcol.apc.fc1:LColSpringAdult_4b:",false,false);
		stk4 = new Option("Adult Spring Chinook, Hanford/Yakima","passage.yakima.apc.fc1:YakimaSpringAdult_4b:",false,false);
		stk5 = new Option("Adult Fall Chinook, Snake R","passage.snake.apc.fc3:SnakeFallAdult_4b:",true,true);
		stk6 = new Option("Adult Fall Chinook, Upper Col R","passage.ucol.apc.fc3:UColFallAdult_4b:",false,false);
		stk7 = new Option("Adult Fall Chinook, Lower Col R","passage.lcol.apc.fc3:LColFallAdult_4b:",false,false);
		stk8 = new Option("Adult Fall Chinook, Hanford/Yakima","passage.yakima.apc.fc3:YakimaFallAdult_4b:",false,false);

	  // locx = new Option("Label","Config Suffix:Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Config Suffix is either "one.rt" for RT location or
	  //	"one.crisp" for CRiSP location
	  //  Location is either not specified for all sites web page or individual location
		loc1 = new Option("All Sites","all:",true,true);
		loc2 = new Option("Bonneville Dam","one.crisp:Bonneville_Dam",false,false);
		loc3 = new Option("The Dalles Dam","one.crisp:The_Dalles_Dam",false,false);
		loc4 = new Option("John Day Dam","one.crisp:John_Day_Dam",false,false);

		// add options to select objects
		for ( var i = 1; i < 5; i++ ) {
			locElement.options[locElement.options.length] = eval("loc" + i);
		}
		for ( var i = 1; i < 9; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}

		// test to see if "stkSel" exists, if so 
		// then set selected attribute to this option
		// if ( stkSel != null && stkSel != 'undefined' ) {
		// 	stkElement.options[0].selected = false;
		// 	stkElement.options[0].defaultSelected = false;
		// 	stkElement.options[stkSel].selected = true;
		// 	stkElement.options[stkSel].defaultSelected = true;
		// } else {
		// set default selected to Fall Chinook Snake River
			stkElement.options[4].selected = true;
			stkElement.options[4].defaultSelected = true;
		// }


	// if adultRun, initialize options of location and stock
	} else if ( x == 'adultRun' ) {
	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Adult Spring Chinook","fc1:SnakeSpringAdult_4b:",false,false);
		stk2 = new Option("Adult Fall Chinook","fc3:SnakeFallAdult_4b:",true,true);

	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Bonneville Dam","Bonneville_Dam",true,true);

		// add options to select objects
		locElement.options[locElement.options.length] = loc1;
		for ( var i = 1; i < 3; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
		// test to see if "stkSel" exists, if so 
		// then set selected attribute to this option
		// if ( stkSel != null && stkSel != 'undefined' ) {
		// 	stkElement.options[0].selected = false;
		// 	stkElement.options[0].defaultSelected = false;
		// 	stkElement.options[stkSel].selected = true;
		// 	stkElement.options[stkSel].defaultSelected = true;
		// } else {
		// set default selected to Fall Chinook
			stkElement.options[1].selected = true;
			stkElement.options[1].defaultSelected = true;
		// }
	// if adultPeak, initialize options of location and stock
	} else if ( x == 'adultPeak' ) {
	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Adult Spring Chinook","fc1:SpringAdult:",true,true);

	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Bonneville Dam","Bonneville_Dam",true,true);

		// add options to select objects
		locElement.options[locElement.options.length] = loc1;
		stkElement.options[stkElement.options.length] = stk1;

		stkElement.options[0].selected = true;
		stkElement.options[0].defaultSelected = true;
	// if adultRunSize, initialize options of location and stock
	} else if ( x == 'adultRunSize' ) {
	  // stkx = new Option("Label","FishType:Stock:Year",Selected?,Default?); 
	  //  Label is form label for selection object on web page
	  //  FishType as defined in lexicon.pl
	  //  Stock as defined in lexicon.pl
	  //  Year is either hard-coded or if not specified will default
	  //	to CurrentYear value in /usr/local/cbr/perl/lib/CBR/CRISPRT/Constants.pm under SVN control
		stk1 = new Option("Adult Fall Chinook","fc3:SnakeFallAdult_4b:2005",true,true);

	  // locx = new Option("Label","Location",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Bonneville Dam","Bonneville_Dam",true,true);

		// add options to select objects
		locElement.options[locElement.options.length] = loc1;
		for ( var i = 1; i < 2; i++ ) {
			stkElement.options[stkElement.options.length] = eval("stk" + i);
		}
		// test to see if "stkSel" exists, if so 
		// then set selected attribute to this option
		// if ( stkSel != null && stkSel != 'undefined' ) {
		// 	stkElement.options[0].selected = false;
		// 	stkElement.options[0].defaultSelected = false;
		// 	stkElement.options[stkSel].selected = true;
		// 	stkElement.options[stkSel].defaultSelected = true;
		// } else {
		// set default selected to Fall Chinook
			stkElement.options[0].selected = true;
			stkElement.options[0].defaultSelected = true;
		// }
	}
		
	// set selected attribute for loc
	locElement.options[0].selected = true;
	locElement.options[0].defaultSelected = true;

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function formMcpud() {
	 var plotTypeElement  = document.mcpud.PlotType;
	 var riverDataElement = document.mcpud.RiverData;
	 var yearRangeElement = document.mcpud.YearRange;

	 var flowLabel, flowVar;
	 if ( document.mcpud.Config.value == 'mcpud.trap') {
	    flowLabel = "Flow";
	    flowVar   = "flow_cfs";
	 } else {
	   flowLabel = "Outflow";
	   flowVar   = "outflow";
	 }

	 var selectedYearRange  = yearRangeElement.selectedIndex;
	 var selectedRiverRange = riverDataElement.selectedIndex;

	 yearRangeElement.options.length = 0;
	 riverDataElement.options.length = 0;

	 // current histograms
	 if (plotTypeElement.selectedIndex == 3 || plotTypeElement.selectedIndex == 4 ) {
	    // add options to select objects
	    yearRangeElement.options[0] = new Option("Current Year", "last1Years", true, true);
	    
	    if ( selectedRiverRange == 0 ) {
	    	    riverDataElement.options[0] = new Option("None", "none", true, true);
	    	    riverDataElement.options[1] = new Option(flowLabel, flowVar, false, false);
	    } else {
	    	    riverDataElement.options[0] = new Option("None", "none", false, false);
	    	    riverDataElement.options[1] = new Option(flowLabel, flowVar, true, true);
	    }
	} 
	else {
	    var yearNames  = ['All Years', 'Current Year', 'Last 5 Years', 'Last 10 Years'];
	    var yearValues = ['allYears', 'last1Years', 'last5Years', 'last10Years'];
            var defaultSelected;
	    var selected;
	    for (i = 0; i < 4; i++ ) {
	         if ( i == selectedYearRange ) {
		    defaultSelected = true;
		    selected = true;
		 }  else {
		    defaultSelected = false;
		    selected = false;
		 }

		 yearRangeElement.options[i] =  new Option(yearNames[i], yearValues[i], defaultSelected, selected);
	    }		 

	    riverDataElement.options[0] = new Option("None", "none", true, true);
       } 
}


function formWater() {
	// form objects
	var predElement = document.water.predType;
	var locElement = document.water.location;

	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].checked ) {
			x = predElement[i].value;
		}
	}

	// check x, if not defined then set it to passage
	if ( x != 'gas' && x != 'temperature' ) {
		x = 'gas';
		for ( var i = 0; i < predElement.length; i++ ) {
			predElement[i].checked = false;
			predElement[i].defaultChecked = false;
		}
	}

	// set length of location ans stock select list to 0
  	locElement.options.length = 0;
  	var loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8,loc9,loc10,
		loc11,loc12,loc13,loc14,loc15;

	// if gas, initialize options of location
	if ( x == 'gas' ) {

	  // locx = new Option("Label","Location:Year",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Dworshak Dam","Dworshak_Dam:",true,true);
		loc2 = new Option("Lower Granite Dam","Lower_Granite_Dam:",false,false);
		loc3 = new Option("Little Goose Dam","Little_Goose_Dam:",false,false);
		loc4 = new Option("Lower Monumental Dam","Lower_Monumental_Dam:",false,false);
		loc5 = new Option("Ice Harbor Dam","Ice_Harbor_Dam:",false,false);
		loc6 = new Option("Chief Joseph Dam","Chief_Joseph_Dam:",false,false);
		loc7 = new Option("Wells Dam","Wells_Dam:",false,false);
		loc8 = new Option("Rocky Reach Dam","Rocky_Reach_Dam:",false,false);
		loc9 = new Option("Rock Island Dam","Rock_Island_Dam:",false,false);
		loc10 = new Option("Wanapum Dam","Wanapum_Dam:",false,false);
		loc11 = new Option("Priest Rapids Dam","Priest_Rapids_Dam:",false,false);
		loc12 = new Option("McNary Dam","McNary_Dam:",false,false);
		loc13 = new Option("John Day Dam","John_Day_Dam:",false,false);
		loc14 = new Option("The Dalles Dam","The_Dalles_Dam:",false,false);
		loc15 = new Option("Bonneville Dam","Bonneville_Dam:",false,false);

		for ( var i = 1; i < 16; i++ ) {
			locElement.options[locElement.options.length] = eval("loc" + i);
		}
	} else if ( x == 'temperature' ) {

	  // locx = new Option("Label","Location:Year",Selected?,Default?);
	  //  Label is form label for selection object on web page
	  //  Location is individual location
		loc1 = new Option("Lower Granite Pool","Lower_Granite_Pool:",true,true);
		loc2 = new Option("Little Goose Pool","Little_Goose_Pool:",false,false);
		loc3 = new Option("Lower Monumental Pool","Lower_Monumental_Pool:",false,false);
		loc4 = new Option("Ice Harbor Pool","Ice_Harbor_Pool:",false,false);
		loc5 = new Option("Wells Pool","Wells_Pool:",false,false);
		loc6 = new Option("Rocky Reach Pool","Rocky_Reach_Pool:",false,false);
		loc7 = new Option("Rock Island Pool","Rock_Island_Pool:",false,false);
		loc8 = new Option("Wanapum Pool","Wanapum_Pool:",false,false);
		loc9 = new Option("Priest Rapids Pool","Priest_Rapids_Pool:",false,false);
		loc10 = new Option("McNary Pool","McNary_Pool:",false,false);
		loc11 = new Option("John Day Pool","John_Day_Pool:",false,false);
		loc12 = new Option("The Dalles Pool","The_Dalles_Pool:",false,false);
		loc13 = new Option("Bonneville Pool","Bonneville_Pool:",false,false);

		for ( var i = 1; i < 14; i++ ) {
			locElement.options[locElement.options.length] = eval("loc" + i);
		}
	}
		
	// set defaults
	locElement.options[0].selected = true;
	locElement.options[0].defaultSelected = true;

	// set checked attribute for predType radio button
	for ( var i = 0; i < predElement.length; i++ ) {
		if ( predElement[i].value == x ) {
			predElement[i].checked = true;
			predElement[i].defaultChecked = true;
		}
	}
}

function getQuery() {
	// get values from form 
	var s, l, pt, ds, r;
	var f = document.forms[1].name;

	if ( f == 'snakePit' ) {
		ds = "pit";
		r = "snake";
	} else if ( f == 'midColPI' ) {
		ds = "pi";
		r = "midcol2";
	} else if ( f == 'midColCHE' ) {
		ds = "che";
		r = "midcol2";
	} else if ( f == 'adult' ) {
		ds = "apc";
		r = "snake";
	} else if ( f == 'esuPit' ) {
		ds = "pit";
		r = "col";
	}

	for ( var i = 0; i < document.forms[1].location.length; i++ ) {
		if ( document.forms[1].location[i].selected ) {
			l = document.forms[1].location[i].value;
		}
	}
	for ( var i = 0; i < document.forms[1].predType.length; i++ ) {
		if ( document.forms[1].predType[i].checked ) {
			pt = document.forms[1].predType[i].value;
		}
	}
	if ( document.forms[1].stock ) {
		for ( var i = 0; i < document.forms[1].stock.length; i++ ) {
			if ( document.forms[1].stock[i].selected ) {
				s = document.forms[1].stock[i].value;
			}
		}
	}

	var pageToGet = "";
	if ( pt == 'passage' ) {
		if ( f == 'snakePit' || f == 'adult' || f == 'esuPit' ) {
			pageToGet += "/crt/get?ConfigID:Segment=" + l;
		} else if ( f == 'midColPI' || f == 'midColCHE' ) {
			pageToGet += "/crt/get?Segment=" + l;
		}
		pageToGet += "&Config:Stock:Year=" + s;
		pageToGet += "&HistYear=all";
		pageToGet += "&Forecast=1";
		pageToGet += "&Curr=1";
		pageToGet += "&River=" + r;
	} else if ( pt == 'daily' ) {
		pageToGet += "/crt/get?Segment=" + l;
		pageToGet += "&FishType:Stock:Year=" + s;
		pageToGet += "&HistYear=all";
		pageToGet += "&Forecast=1";
		pageToGet += "&Config=daily";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&River=" + r;
	} else if ( pt == 'survival' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Forecast=1";
		pageToGet += "&Config=survival";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&River=" + r;
		pageToGet += "&Input=crisp";
	} else if ( pt == 'pbg' ) {
		pageToGet += "/crt/get?Segment=" + l;
		pageToGet += "&FishType:Stock:Year=" + s;
		pageToGet += "&HistYear=all";
		pageToGet += "&Forecast=1";
		pageToGet += "&Config=pbg";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&River=" + r;
	} else if ( pt == 'survtoday' ) {
		pageToGet += "/crt/get?FishType:Year=" + s;
		pageToGet += "&Segment:SegmentDn:StartDate:EndDate=" + l;
//		pageToGet += "&Input=crisp"; DO NOT USE, causes program to search for Keys/dates
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&Config=survtoday";
		pageToGet += "&River=" + r;
	} else if ( pt == 'transtoday' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Forecast=1";
		pageToGet += "&Input=crisp";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&Config=transtoday";
		pageToGet += "&River=" + r;
	} else if ( pt == 'trans' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Forecast=1";
		pageToGet += "&Input=crisp";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&Config=trans";
		pageToGet += "&Plot=trans";
		pageToGet += "&River=" + r;
	} else if ( pt == 'adultRun' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Config=adultRun";
		pageToGet += "&Segment=" + l;
		pageToGet += "&Plot=adultRun";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&AutoScale=on";
		pageToGet += "&DateInput=crispAdultRun";
	} else if ( pt == 'adultPeak' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Config=adultPeak";
		pageToGet += "&Segment=" + l;
		pageToGet += "&Plot=adultPeak";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&AutoScale=on";
		pageToGet += "&DateInput=crispAdultPeak";
	} else if ( pt == 'adultRunSize' ) {
		pageToGet += "/crt/get?FishType:Stock:Year=" + s;
		pageToGet += "&Config=adultRunSize";
		pageToGet += "&Segment=" + l;
		pageToGet += "&Plot=adultRunSize";
		pageToGet += "&DataSource=" + ds;
		pageToGet += "&AutoScale=on";
		pageToGet += "&DateInput=crispAdultRun";
	} else if ( pt == 'gas' || pt == 'temperature' ) {
		pageToGet += "/crt/get?Segment:Year=" + l;
		pageToGet += "&Config=" + pt;
		pageToGet += "&EndDate=10/31";
	}
		
	window.open(pageToGet,'_self');
	//alert(pageToGet);
	return true;
}


function getPage() {
	// get value from form html
	var pageElement = document.html.htmlPage;
	var p;
	for ( var i = 0; i < pageElement.length; i++ ) {
		if ( pageElement[i].checked ) {
			p = pageElement[i].value;
		}
	}
	window.open(p,'_self');
	return true;
}

function getToolPage(href) {
	 var width=800;
	 var height=700;

	 if ( screen.availWidth < width ) {
	    width = screen.availWidth;
	 }
	 if ( screen.availHeight < height ) {
	    height = screen.availHeight;
	 }
	 //var xpos = ( screen.availWidth - width)/2; // center
	 //var ypos = (screen.availHeight - height)/2; // center
	 var pad = 20;
	 var xpos = screen.availWidth - width - pad;
	 var ypos = pad;

	window.open(href,'tool',
		"width="+width+",height="+height+",screenX="+xpos+",screenY="+ypos+",resizable,scrollbars,statusbar,toolbar" );

	return true;
}
