//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);
  var vid;
  //if(lyr && id..indexOf("video_tour")!=-1) // start video
 // {
//  	vid = lyr.getElemRefs("videotour");
//  	if(vid)
//  		vid.Play();
//  }  
  if (lyr && lyr.css){
    lyr.css.visibility = "visible";
  }
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  var vid;
  
  //if(lyr && id..indexOf("video_tour")!=-1) // stop video
 // {
//  	vid = lyr.getElemRefs("videotour");
//  	if(vid)
//  		vid.Stop();
//  }

  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_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 = "#a0c3df";
				mainMenuA.style.color = "#FFFFFF";
		}
	}
	
}*/

//Used in conjunction with the Government Tabs on the homepage. Resets all buttons to the "off" image.
function resetButtons() {
  var container = document.getElementById("tab_buttons");
  var divs;
  if(container)
  {
  		divs = container.getElementsByTagName("div");
  		for (i=0; i<divs .length; i++) 
      		divs[i].className = "normal_button";

  }
/*    if (document.getElementById('linkServing_Ohio') != null) {
        document.getElementById('linkServing_Ohio').src = "img/tabs_governor.gif";
    }
    if (document.getElementById('linkExecutive') != null) {
        document.getElementById('linkExecutive').src = "img/tabs_executive.gif";
    }
    if (document.getElementById('linkJudicial') != null) {
        document.getElementById('linkJudicial').src = "img/tabs_judicial.gif";
    }
    if (document.getElementById('linkLegislative') != null) {
        document.getElementById('linkLegislative').src = "img/tabs_legislative.gif";
    }
    */
}
    


/*function setButton(obj){
	//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 = "#999999";
	//			mainMenuA.style.color = "#4581d0";
	//	}
	//}
	
	resetButtons();
	
	//Highlight the clicked link/button	
	document.getElementById(obj.id).style.backgroundColor="#3A5DBF";
	document.getElementById(obj.id).style.color="#FFFFFF";
}*/

//Used in conjunction with the Government Tabs on the homepage. Sets the passed button to the new "on" image
function setButton(button_name) {
    resetButtons();
    //Highlight the clicked tab
    document.getElementById(button_name).className = "active_button";
}

//This function works with the home page. It equalizes the height of the news and Government Tabs sections
	//function equalize() {
	//    var elem = document.getElementById('News_Content');
    //alert("heightToMatch = " + elem.offsetHeight.toString());
    //alert(navigator.userAgent.toString());
    
	//    if (elem.offsetHeight > 135) {
	//		var heightChange = elem.offsetHeight - 135;
	//        document.getElementById('Column_top').style.height = (document.getElementById('Column_top').offsetHeight + heightChange) + "px";
	//        document.getElementById('News_container').style.height = (document.getElementById('News_container').offsetHeight + heightChange) + "px"; 
	//        document.getElementById('News').style.height = (document.getElementById('News').offsetHeight + heightChange - 1) + "px";        
	//        document.getElementById('options_container').style.height = (document.getElementById('options_container').offsetHeight + heightChange) + "px";
 	//       document.getElementById('serving_ohio').style.height = (document.getElementById('serving_ohio').offsetHeight + heightChange) + "px";
	//        document.getElementById('serving_ohio').style.paddingTop = (document.getElementById('serving_ohio').style.paddingTop + heightChange) + "px";
	//        document.getElementById('Executive').style.height = (document.getElementById('Executive').offsetHeight + heightChange) + "px";
	//        document.getElementById('Judicial').style.height = (document.getElementById('Judicial').offsetHeight + heightChange) + "px";
	//        document.getElementById('Legislative').style.height = (document.getElementById('Legislative').offsetHeight + heightChange) + "px";
	//    }
	//}

//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 = "";
	}
}

//populate the search box with "search" for IE
function setSearch() {
	var box = document.getElementById("text_search");
	box.value = "search";
}
        
