//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 saveValue(text) {
    alert("saveValue text = " + text);
}

function initButton(id){
        //alert(id);
		//Highlight the initial state of the serving ohio buttons/links
		resetButtons();
		//document.getElementById(id).style.backgroundColor="#3A5DBF";
		document.getElementById(id).src = "/img/tab_default.gif";
		
		//if (cur_lyr) {cur_lyr = "option1"}
		cur_lyr = "option1"
		
		//var theLink = document.getElementById("option2link");
		//var theControl = document.getElementById("ctl00_HomeContent_litOption");
		//var theText = theControl.value;
		//alert("theText=" + theText);
		var theText = document.getElementById("body1$txtOption").value;
		if (!theText == ""){
		    //alert(document.getElementById("ctl00_HomeContent_txtOption").value);
		var theLink = document.getElementById(theText);
		//alert("theLink=" + theLink);
		//theLink.click();
		}
		
}

/*function initButton(id){
        //alert(id);
		//Highlight the initial state of the serving ohio buttons/links
		resetButtons();
		//document.getElementById(id).style.backgroundColor="#3A5DBF";
		document.getElementById(id).src = "tab_default.gif";
		
		//if (cur_lyr) {cur_lyr = "option1"}
		cur_lyr = "option1"
		
		//var theLink = document.getElementById("option2link");
		//var theControl = document.getElementById("ctl00_HomeContent_litOption");
		//var theText = theControl.value;
		//alert("theText=" + theText);
		var theText = document.getElementById("ctl00_HomeContent_txtOption").value;
		if (!theText == ""){
		    //alert(document.getElementById("ctl00_HomeContent_txtOption").value);
		var theLink = document.getElementById(theText);
		//alert("theLink=" + theLink);
		theLink.click();
		}
		
}*/

/*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() {
    if (document.getElementById('optionlink1') != null) {
        document.getElementById('optionlink1').src = "../img/tabs_justin2.gif";
    }
    if (document.getElementById('optionlink2') != null) {
        document.getElementById('optionlink2').src = "../img/tabs_families2.gif";
    }
    if (document.getElementById('optionlink3') != null) {
        document.getElementById('optionlink3').src = "../img/tabs_providers2.gif";
    }
    if (document.getElementById('optionlink4') != null) {
        document.getElementById('optionlink4').src = "../img/tabs_advocacy2.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(img_name, img_src) {
//alert("img_name=" + img_name);
//alert("img_src=" + img_src);
//document.getElementById("hiddenOption").value = img_name;
//alert("hiddenOptionValue=" + document.getElementById("hiddenOption").value);
    resetButtons();
    //Highlight the clicked tab
    document.getElementById(img_name).src = img_src;
}

//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";
}
        
/// from existing GB site ---------------------------------------------------------------------


// This script based on Paul Snowden's work described on A List Apart
//  <http://www.alistapart.com/stories/alternate/>
// Certain modifications (setFontSize and related) by Eric Meyer
//  <http://www.meyerweb.com/eric/>

function setActiveStyleSheet(title) {
  var i, a, main;
  if (title) {
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) {
        a.disabled = true;
        if(a.getAttribute('title') == title) a.disabled = false;
      }
    }
  }
}

function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled) return a.getAttribute('title');
    }
    return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
    if(a.getAttribute('rel').indexOf('style') != -1
       && a.getAttribute('rel').indexOf('alt') == -1
       && a.getAttribute('title')
       )
       return a.getAttribute('title');
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else expires = '';
  document.cookie = name+'='+value+expires+'; path=/';
}

function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
	createCookie(name,'',-1);
}

function setFontSize(fontVal) {
	var fontSet = document.getElementById('fontSet');
	var docBase = new Array(); docBase = document.getElementsByTagName('body');
	if (!fontVal) {fontVal = document.getElementById('fontSet').value;}
	var docSize = fontVal+'px';
	createCookie('mw-baseTextSize', fontVal, 365);
	docBase[0].style.fontSize = docSize;
	if (fontSet) {fontSet.value = fontVal;}
}

window.onload = function(e) {
  var cookie = readCookie('mw-themeName');
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  var cookie2 = readCookie('mw-baseTextSize');
  if (cookie2) {setFontSize(cookie2);}
}

loaded = function(e) {
  var cookie = readCookie('mw-themeName');
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  var cookie2 = readCookie('mw-baseTextSize');
  if (cookie2) {setFontSize(cookie2);}
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie('mw-themeName', title, 365);
}

//    var cookie = readCookie('mw-themeName');
//    var title = cookie ? cookie : getPreferredStyleSheet();
//    setActiveStyleSheet(title);
//    var cookie2 = readCookie('mw-baseTextSize');
//    if (cookie2) {setFontSize(cookie2);}


// DPS UPDATE THIS PORTION == START 
//for dropdown menu

//===========================================================================
// dropdown menu

//Contents for menu 1
var menu1 = [
'<a href="/information/oda/history.aspx">History</a>',
'<a href="/information/oda/director.aspx">Director</a>',
'<a href="/information/oda/structure.aspx">Structure</a>',
'<a href="/information/oda/stateplanonaging.aspx">State Plan on Aging</a>',
'<a href="/information/oda/commonsensebusinessregulationpolicy.aspx">Common Sense Business Regulation Policy</a>',
'<a href="/information/oda/employment.aspx">Work for the Department</a>'
]
							
//Contents for menu 2
var menu2 = [
'<a href="/services/assistedliving/">Assisted Living</a>',
'<a href="/services/choices/">Choices Home Care Waiver</a>',
'<a href="/goldenbuckeye/">Golden Buckeye Program</a>',
'<a href="/services/ombudsman/">Long-term Care Ombudsman Programs</a>',
'<a href="/services/pace/">PACE (Program of All-inclusive Care for the Elderly)</a>',
'<a href="/services/passport/">PASSPORT Program</a>',
'<a href="/services/residentialstatesupplement/">Residential State Supplement</a>',
'<a href="/services/seniorcivicengagementinitiative/">Senior Civic Engagement Initiative</a>',
'<a href="/services/seniorcommunityserviceemploymentprogram/">Senior Community Service Employment Program</a>',
'<a href="/services/seniorfarmersmarketnutritionprogram/">Senior Farmers Market Nutrition Program</a>'
]

//Contents for menu 3
var menu3 = [
'<a href="/resources/advocacy/">Advocacy</a>',
'<a href="/resources/aginganddisabilityresourcenetwork/">Aging and Disability Resource Network</a>',
'<a href="/resources/alzheimersdiseaseeducationresources/">Alzheimers Disease Education Resources</a>',
'<a href="/resources/americanrecoveryandreinvestmentact/">American Recovery and Reinvestment Act</a>',
'<a href="/resources/areaagenciesonaging/">Area Agencies on Aging</a>',
'<a href="/resources/assessments/">Long-term Care Assessments</a>',
'<a href="/resources/grants/">Grants</a>',
'<a href="/resources/nationalfamilycaregiversupport/">National Family Caregiver Support</a>',
'<a href="/resources/nursinghomes/">Nursing Homes</a>',
'<a href="/resources/otherstateunitsonaging/">Other State Units on Aging</a>',
'<a href="/resources/publications/">Publications</a>',
'<a href="/resources/seniorcenters/">Senior Centers</a>',
'<a href="/resources/webinars/">Webinars</a>'
]

//Contents for menu 4
var menu4 = [
'<a href="/information/rules/">Administrative Rules</a>',
'<a href="/information/advisorycouncil/">Advisory Council on Aging</a>',
'<a href="/information/doublejeopardy/">Caregivers of Adults with Disabilities</a>',
'<a href="/information/emergencypreparedness/">Emergency Preparedness</a>',
'<a href="/information/employmentforseniors/">Employment for Seniors</a>',
'<a href="/information/energyassistance/">Energy Assistance</a>',
'<a href="/information/homesteadexemption/">Homestead Exemption</a>',
'<a href="/information/housing/">Housing and Home Repair</a>',
'<a href="/information/legalassistance/">Legal Assistance</a>',
'<a href="/information/learning/">Lifelong Learning</a>',
'<a href="/information/medicare/">Medicare</a>',
'<a href="/information/nutrition/">Nutrition</a>',
'<a href="/information/seniorserviceslevies/">Senior Services Levies</a>',
'<a href="/information/transportation/">Transportation</a>',
'<a href="/information/ultcb/">Unified Long-term Care Systems</a>',
'<a href="/information/volunteeropportunities/">Volunteer Opportunities</a>'
]

//Contents for menu 5
var menu5 = [
'<a href="/news/activeaging/">Active Aging</a>',
'<a href="/news/agingconnection/">Aging Connection</a>',
'<a href="/news/agingissues/">Aging Issues</a>',
'<a href="/news/birthday/">Birthday Certificates</a>',
'<a href="/news/boomerang/">Boomerang</a>',
'<a href="/news/eldercaregiveraward/">Elder Caregiver Award</a>',
'<a href="/news/finerwithage/">Finer With Age</a>',
'<a href="/news/greatdepressionstoryproject/">Great Depression Story Project</a>',
'<a href="/news/halloffame/">Hall of Fame</a>',
'<a href="/news/joinedheartsingiving/">Joined Hearts in Giving</a>',
'<a href="/news/olderamericansmonth/">Older Americans Month</a>',
'<a href="/news/pressreleases/">Press Releases</a>'
]

//Contents for menu 6
var menu6 = [
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>',
'<a href=""></a>'
]

var menuwidth = '300px' //default menu width
var menubgcolor = '#ebf6ff'  //menu bgcolor
var disappeardelay = 250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick = "yes" //hide menu when user clicks within menu?

/////No further editing needed

var ie4 = document.all
var ns6 = document.getElementById&&!document.all

if (ie4||ns6)
	document.write('<div id="dropmenudiv" class="noprint" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>');

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px"
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
		if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
			edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
	}
	}
	return edgeoffset
}

function populatemenu(what){
	if (ie4||ns6)
		dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
	if (window.event) 
		event.cancelBubble=true
	else if (e.stopPropagation) 
		e.stopPropagation()
	clearhidemenu()
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents)
	
	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
		
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+5+"px"
	}
	
	return clickreturnvalue()
}

function clickreturnvalue(){
	if (ie4||ns6) 
		return true
	else 
		return false
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide = setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide != "undefined")
	 	clearTimeout(delayhide)
}

if (hidemenu_onclick == "yes")
	document.onclick = hidemenu



// DPS UPDATE THIS PORTION == STOP

/*
"Whats new?" image script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/

//set the below to the image you wish to use as the "new" image
var imagetag='<img src="/img/new.jpg">'
var today=new Date()
function expireat(expiredate){
var expire=new Date(expiredate)
if (today.getTime()<=expire.getTime())
document.write(imagetag)
}

function exlink() {
window.open('/misc/exlink.html','','toolbar=no,menubar=no,location=no,status=no,height=200,width=300');
}


//validation in forms to be submitted
function validateMoreInfo(src, arg){
    arg.IsValid = arg.Value.length > 0;
    if (!arg.IsValid) return false;
}