function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}


function addAnEvent( target, eventName, functionName){
        eval('target.on'+eventName+'=functionName');
}

function toggle(){
	var links=document.getElementsByTagName("a");
	var linkp;
	for(var i=0;i<links.length;i++){
		linkp = links[i];
		if(linkp.className == "toggle"){
			addAnEvent(linkp,'click',toggleopen);
		}
		if(linkp.className == "toggle-open"){
			addAnEvent(linkp,'click',toggleclosed);
		}
	}
	initSubNav(); initMaplinks(); initBack(); stripe(); hideButton();
	if (document.getElementById('commentform')) {createRequestObject(), initCat()};
}

function toggleopen(){
	this.className = "toggle-open";
	toggle();
}

function toggleclosed(){
	this.className = "toggle";
	toggle();
}

function hideButton(){
	if(document.getElementById('vol2')){
	var links=document.getElementsByTagName("div");
	var linkp;
	for(var i=0;i<links.length;i++){
		linkp = links[i];
		if(linkp.className == "chHead"){
			linkp.className = "hideLink";
		}
	}
							   
 }
}
							   

// Sub Nav highlight location

function initSubNav(){
	if (document.getElementById){
	//turns current subnav item on except on homepage
		if (document.getElementById('subNav')){
			var subnav = document.getElementById('subNav');  	//finds subnav element
			var subnavas = subnav.getElementsByTagName('a'); 	//finds all anchors within subnav
			for (var a=0; a<subnavas.length; a++){		//cycles through each link
				var currenthref=String(subnavas[a].href);	//assigns current link href to a string
				var currentloc=String(document.location);	//assigns current document url to a string
			
				//if the current link href matches the document url the anchor is given a class
				if (unescape(currenthref)==unescape(currentloc)){
					subnavas[a].className="on"
				}
			}
	  	}
	}
}

// These Are the Hidden Map divs

function initMaplinks(){
	if (document.getElementById('map') || document.getElementById('map2')){
	var links=document.getElementsByTagName("a");
	var linkp;
	for(var i=0;i<links.length;i++){
		linkp = links[i];
		if(linkp.className == "pit"){
			addAnEvent(linkp,'click',showPit);
		}
		if(linkp.className == "cow"){
			addAnEvent(linkp,'click',showCow);
		}
		if(linkp.className == "feather"){
			addAnEvent(linkp,'click',showFeather);
		}
		if(linkp.className == "potter"){
			addAnEvent(linkp,'click',showPotter);
		}
		if(linkp.className == "yuba"){
			addAnEvent(linkp,'click',showYuba);
		}
		if(linkp.className == "mokelumne"){
			addAnEvent(linkp,'click',showMokelumne);
		}
		if(linkp.className == "stanislaus"){
			addAnEvent(linkp,'click',showStanislaus);
		}
		if(linkp.className == "willow"){
			addAnEvent(linkp,'click',showWillow);
		}
		if(linkp.className == "kings"){
			addAnEvent(linkp,'click',showKings);
		}
		if(linkp.className == "kern"){
			addAnEvent(linkp,'click',showKern);
		}
		if(linkp.className == "carrizo"){
			addAnEvent(linkp,'click',showCarrizo);
		}
	}
	}
}

function showPit(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Pit McCloud River</h2><ul id="pitmccloud"><li><a href="pitmccloud/fall-river.htm">Fall River Valley</a></li><li><a href="pitmccloud/mcarthur-swamp.htm">McArthur Swamp</a></li><li><a href="pitmccloud/fall-river-mills.htm">Fall River Mills</a></li><li><a href="pitmccloud/hat-creek.htm">Hat Creek</a></li><li><a href="pitmccloud/lake-britton.htm">Lake Britton</a></li><li><a href="pitmccloud/tunnel-resevoir.htm">Tunnel Reservoir</a></li><li><a href="pitmccloud/pit-river.htm">Pit River</a></li><li><a href="pitmccloud/iron-canyon.htm">Iron Canyon Reservoir</a></li><li><a href="pitmccloud/lake-mccloud.htm">Lake McCloud</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showCow(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Cow-Battle Creek</h2><ul id="cow-battle"><li><a href="cow-battle/burney-gardens.htm">Burney Gardens</a></li><li><a href="cow-battle/kilarc-reservoir.htm">Kilarc Reservoir</a></li><li><a href="cow-battle/cow-creek.htm">Cow Creek</a></li><li><a href="cow-battle/battle-creek.htm">Battle Creek</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showFeather(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Feather River</h2><ul id="feather-river"><li><a href="feather-river/lake-almanor.htm">Lake Almanor</a></li><li><a href="feather-river/mountain-meadows.htm">Mountain Meadows Reservoir</a></li><li><a href="feather-river/butt-valley.htm">Butt Valley Reservoir</a></li><li><a href="feather-river/humbug-valley.htm">Humbug Valley</a></li><li><a href="feather-river/philbrook-reservoir.htm">Philbrook Reservoir</a></li><li><a href="feather-river/deer-creek.htm">Deer Creek</a></li><li><a href="feather-river/butte-creek.htm">Butte Creek</a></li><li><a href="feather-river/bucks-lake.htm">Bucks Lake</a></li><li><a href="feather-river/north-fork.htm">North Fork Feather River</a></li><li><a href="feather-river/oroville.htm">Oroville</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showPotter(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Eel River</h2><br /><ul id="potter-valley"><li><a href="potter-valley/potter-valley.htm">Eel River</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showYuba(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Yuba Bear River</h2><ul id="yuba-bear"><li><a href="yuba-bear/fordyce-lake.htm">Fordyce Lake</a></li><li><a href="yuba-bear/lake-spaulding.htm">Lake Spaulding</a></li><li><a href="yuba-bear/bear-river.htm">Bear River</a></li><li><a href="yuba-bear/narrows.htm">Narrows</a></li><li><a href="yuba-bear/lower-drum.htm">Lower Drum</a></li><li><a href="yuba-bear/chili-bar.htm">Chili Bar</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showMokelumne(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Upper Mokelumne</h2><ul id="mokelumne"><li><a href="mokelumne/blue-lakes.htm">Blue Lakes</a></li><li><a href="mokelumne/lower-bear.htm">Lower Bear Area</a></li><li><a href="mokelumne/north-fork.htm">North Fork Mokelumne River</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showStanislaus(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Stanislaus River</h2><ul id="stanislaus"><li><a href="stanislaus/kennedy-meadows.htm">Kennedy Meadows</a></li><li><a href="stanislaus/middle-fork.htm">Middle Fork Stanislaus River</a></li><li><a href="stanislaus/lyons-reservoir.htm">Lyons Reservoir</a></li><li><a href="stanislaus/merced-river.htm">Merced River</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showWillow(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Willow Creek</h2><ul id="willow-creek"><li><a href="willow-creek/bass-lake.htm">Bass Lake</a></li><li><a href="willow-creek/manzanita-lake.htm">Manzanita Lake</a></li><li><a href="willow-creek/willow-creek.htm">Willow Creek</a></li><li><a href="willow-creek/kerckhoff-lake.htm">Kerckhoff Lake</a></li><li><a href="willow-creek/auberry-service.htm">Auberry Service Center</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showKings(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Kings<br />River</h2><ul id="kings-river"><li><a href="kings-river/wishon-reservoir.htm">Wishon Reservoir</a></li><li><a href="kings-river/kings-river.htm">Kings River</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showKern(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Kern-Tule River</h2><ul id="kern-tule"><li><a href="kern-tule/doyle-springs.htm">Doyle Springs</a></li><li><a href="kern-tule/kern-river.htm">Kern River</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function showCarrizo(){
	var div = document.getElementById('planning-units');
	onSwitch();
	this.parentNode.className = "on";
	div.className = "block";
	div.innerHTML = '<a class=\"close\" title=\"close\" href=\"#\" onClick=\"closeDiv();\">close</a><h2>Carrizo<br />&nbsp;</h2><ul id="carrizo"><li><a href="carrizo/carrizo-plain.htm">Carrizo Plain</a></li></ul><div class="bottom"></div>';
	scroll();
	return false;
}

function closeDiv(){
	var div = document.getElementById('planning-units');
	div.className = "";
	onSwitch();
	return false;
}

function scroll(){
	window.scrollTo(0,600);
}

// This finds Client on links and turns them off
function onSwitch(){
	var findon=document.getElementsByTagName("span");
	var linkon;
	for(var i=0;i<findon.length;i++){
		linkon = findon[i];
		if(linkon.className == "on"){
			linkon.className = "";
		}
	}
}

function initBack(){
	if (document.getElementById('back')){
		var back = document.getElementById('back');
		back.href = "javascript:history.go(-2)";
	
		}
	}
	
	//===========================================

function createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}
FORM_DATA = createRequestObject();
  // This is the array/object containing the GET data.
  // Retrieve information with 'FORM_DATA [ key ] = value'.


//===========================================



// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}   

function stripe(id) {
	// obtain a reference to the desired table
	// if no such table exists, abort
	var inc = 0;
	var tables = new Array();
	var alltags = document.getElementsByTagName("table")
	for (i=0; i<alltags.length; i++){
		var classname = alltags[i].className
		var classname = classname.split(" ");
		for (var j=0; j < classname.length; j++)
		if (classname[j]=="stripe")
			tables[inc++]=alltags[i];
	}
	

    for (var g = 0; g < tables.length; g++){
	    // by definition, tables can have more than one tbody
		// element, so we'll have to get the list of child
		// &lt;tbody&gt;s 
	    var tbodies = tables[g].getElementsByTagName("tbody");

		// and iterate through them...
	    for (var h = 0; h < tbodies.length; h++) {
    		// find all the tr elements... 
			var trs = tbodies[h].getElementsByTagName("tr");
			// ... and iterate through them
			for (var i = 0; i < trs.length; i++) {
				// avoid rows that have a class attribute
				// or backgroundColor style
				if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
					var isEven = (i % 2) ? "even" : "odd"
					trs[i].className = isEven;
				}
			}
		}
	}
}


function changeOptions(){
  var plist = document.getElementById('plist');
  var ws1 = document.getElementById('ws1');
  var ws2 = document.getElementById('ws2');
  var ws3 = document.getElementById('ws3');
  var ws4 = document.getElementById('ws4');
  var ws5 = document.getElementById('ws5');
  var ws6 = document.getElementById('ws6');
  var ws7 = document.getElementById('ws7');
  var ws8 = document.getElementById('ws8');
  var ws9 = document.getElementById('ws9');
  var ws10 = document.getElementById('ws10');
  var ws11 = document.getElementById('ws11');
  
  if (ws1.selected = true){
	  plist.className = "showws1";
  }
  if (ws2.selected = true){
	  plist.className = "showws2";
  }
}

window.onload = toggle;
