// get element id in dom d.
function d_e(d, id) { return d.getElementById(id) }

// get element id in document
function e(id) { return d_e(document, id) }

// get elements with ids enumerated (id0, id1, id2) in dom d.
function d_e_enum(d, id)
{
	var i = 0;
	var elements = Array();
	while(element = d_e(d, id + i)) elements[i++] = element;
	return elements;
}

// get elements with ids enumerated in document.
function e_enum(id) { return d_e_enum(document, id) }

// get tags of name n in document d.
function d_tags(d,n) { return d.getElementsByTagName(n) }

// get tags of name n in document.
function tags(n) { return d_tags(document, n) }

// get attribute a from element e
function att(e, a) { return e.getAttribute(a) }

// call do_f when on_f is called.
function listen(on_f, do_f)
{
	if(on_f)
	{
		var old_f = on_f;
		on_f = function() { old_f(); do_f(); }
	}
	else on_f = do_f;
}

// add style class c to element el.
function add(el,c){ el.className += el.className ? " "+c : ((el.className.indexOf(c)==-1) ? c : "");}

// remove style class c from element el.
function rem(el,c){
	var all = el.className.split(" ");
	var newc = Array();
	for(i in all) if(all[i] != c) newc[newc.length] = all[i];
	el.className = newc.join(" ");
}

// make a javascript cookie with name n, value v, expiring in d days.
function setCookie(n, v, d)
{
    var dt = new Date();
    dt.setTime(dt.getTime() + (d * 86400000));
  	document.cookie = n +"="+ v + "; expires="+ dt.toGMTString() +"; path=/";
}

// read a javascript cookie with name n.
function readCookie(n)
{
	var vars = document.cookie.split(";");
	for(var v = 0; v < vars.length; v++)
	{
		c = vars[v]
		while (c.charAt(0)==' ') c = c.substring(1, c.length);
		if(c.indexOf(n + "=") == 0) { return c.substr(c.indexOf("=") + 1); }
	}
	return false;
}

// set up swappable stylesheets.
var swap = Array("stylesheet 1", "stylesheet 2", "stylesheet 3");
var sheets = Array();
var links = tags("link");
for(var i = 0; i < links.length; i++)
{
	var t = att(links[i], "title");
	if(t) for(j in swap) if(t == swap[j]) sheets[swap[j]] = links[i];
}

// load saved stylesheet, validate and set it.
var saved = readCookie("stylepref");
if(saved && sheets[saved] && (saved != swap[0])) setActiveStyleSheet(saved);

/// enable style with title.
function setActiveStyleSheet(title)
{
	for(i in sheets) sheets[i].disabled = true;
	sheets[title].disabled = false;
	setCookie("stylepref", title, 365);
}

// JavaScript Document

function mailpage()
{
mail_str = "mailto:?subject=Interesting MonroeCounty.gov Web Page";
mail_str += "&body=Hi,\n\nI thought you might be interested in this:\n" + document.title;
mail_str += ". \n\nYou can view it at " + location.href + "."; 
location.href = mail_str;
return false;
}


function toggle(control, toggledID)
{
	var toggled = document.getElementById(toggledID);
	if(toggledID != "deptlinks") var txt = control.previousSibling;
	if(control.className == "minus")
	{
		control.className = "plus";
		toggled.style.display = "none";
		if(txt) txt.nodeValue = "Open ";
	}
	else
	{
		control.className = "minus";
		toggled.style.display = "block";
		if(txt) txt.nodeValue = "Close ";
	}
	return false;
}

