//IE4 throws javascript errors when java disabled. This method catches 
//those errors and suppresses them.
onerror=handleErr
function handleErr(msg,url,l){
	return true;
}

//Hides all toggle sub-menus. If javascript is disabled on the client browser, the toggles won't collapse.
function hide_all() {
	var arr = document.getElementsByTagName("dt");
    for (var i = 1; i<=arr.length; i++) {
        document.getElementById('smenu'+i).style.display='none';
		document.getElementById('toggle'+i).innerHTML = " [ + ]";
    }
}

function show(id, toggle) {
	
	var d = document.getElementById(id);
	var tog = document.getElementById(toggle);
	/*var arr = document.getElementsByTagName("dt");
		for (var i = 1; i<=arr.length; i++) {
			if (document.getElementById('smenu'+i)) {
				document.getElementById('smenu'+i).style.display='none';
				document.getElementById('toggle' + i).innerHTML = " [ + ]";
			}
		}*/
	if (d) {
		if (d.style.display == 'none') {
			d.style.display='block';
			tog.innerHTML = " [ - ]";
		}
		else {
			d.style.display = 'none';
			tog.innerHTML = " [ + ]";
		}
	}
}

var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css){
    lyr.css.visibility = "visible";
  }
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function initButton(id){
		//Highlight the initial state of the serving ohio buttons/links
		resetButtons();
		//document.getElementById(id).style.backgroundColor="#3A5DBF";
		document.getElementById(id).src = "img/tabs_governor_winter08_on.gif";
}

/*function resetButtons(){
	//grab all the buttons and drop the style off the links
	var panel = document.getElementById("serving_buttons");
	var mainlinks = panel.getElementsByTagName("a");
	var mainMenuA;

	//reset the buttons to show no background on the link/button elements
	for (k=0; k < mainlinks.length; k++) {
		if (mainlinks[k].id.toString() != ""){
				mainMenuA = document.getElementById(mainlinks[k].id);
				mainMenuA.style.background = "none";
				mainMenuA.style.backgroundColor = "#b6b9cb";
				mainMenuA.style.color = "#FFFFFF";
		}
	}
	
}*/

//IE4 and Netscape4 should not use any of the CSS styles or Javascript.  They are too old for most of the functionality to work properly.
//This function detects for IE4 and Netscape4, IE5+, Netscape 5+, and any other browser (Mozilla, Firefox, Safari, etc).  It sets no styles
//or Javascript for IE4 or less, Netscape4 or less. It sets a special style for IE5, and the default styles for IE6+ and the other browsers.
function detectBrowser() {
    var IE5detected = false;
    var Net5detected = false;
	var stylesheet1; 
	var stylesheet2;
	var jScript;
	
	//for modern browsers
	if (document.getElementById) {
		stylesheet1 = document.getElementById("default_css");
		stylesheet2 = document.getElementById("ie5_css");
		jScript = document.getElementById("standard_js");
	}
	//for older browsers (IE4)
	else if (document.all) {
		stylesheet1 = document.all["default_css"];
		stylesheet2 = document.all["ie5_css"];
		jScript = document.all["standard_js"];
	}
	
	stylesheet1.disabled = true;
	stylesheet2.disabled = true;
	jScript.disabled = true;
    
    //detect IE 5.x+
    var version=0
    if (navigator.appVersion.indexOf("MSIE")!=-1){
        temp=navigator.appVersion.split("MSIE");
        version=parseFloat(temp[1]);
        
        if (version >= 5) {
            IE5detected = true;
        }
    }
    
    //detect Netscape 5.x+
    if (navigator.appName=="Netscape" && parseFloat(navigator.appVersion) >= 5.0) {
        Net5detected = true;
    }
    
    //if either browser detected, enable CSS and Javascript
    if (IE5detected || Net5detected) {
		
		if (IE5detected && version < 6) {
			stylesheet1.disabled = true;
			stylesheet2.disabled = false;
		}
		else {
			stylesheet1.disabled = false;
			stylesheet2.disabled = true;
		}
		
		jScript.disabled = false;
    }
	//IE5 or Netscape5 not detected - could be older browser or different browser
	else {
		//detect IE version 4.x -        
        if (version < 5 && version != 0) {
			stylesheet1.disabled = true;
			stylesheet2.disabled = true;
			jScript.disabled = true;
		}
		//detect Netscape 4.x -
		else if(navigator.appName=="Netscape" && parseFloat(navigator.appVersion) < 5.0) {
			stylesheet1.disabled = true;
			stylesheet2.disabled = true;
			jScript.disabled = true;
		}
		//some other browser - Mozilla, Firefox, etc
		else {
			stylesheet1.disabled = false;
			stylesheet2.disabled = true;
			jScript.disabled = false;
		}
	}
}

//remove the word "search" from the search bar when the user selects the textbox
function clearSearch() {
	var box = document.getElementById("text_search");
	if (box.value == "search" || box.value == undefined) {
		box.value = "";
	}
}
