// initializes display by hiding popup windows and nav
if (document.getElementById) {
	document.write ("<style type='text/css'>");
	document.write ("@import url(/css/nav.css);");
	document.write ("</style>");
}


//show menu when link clicked
function ddb() {
	if (document.getElementById) {
		document.getElementById('ddBut').onclick = function() {
			return showhide('toc');
		}
	}
}


//shows/hides an id
function showhide(myId) {
	if (document.getElementById) {
		state = document.getElementById(myId).style.visibility
		if (state == 'visible') {
			hideId(myId)
			return false
		}
		else {
			showId(myId)
			return false
		}
	} else {
		return true
	}
}

//hides an id
function hideId(myId) {
	if (document.getElementById) {
		document.getElementById(myId).style.visibility = 'hidden'
	}
}

//shows an id
function showId(myId) {
	if (document.getElementById) {
		document.getElementById(myId).style.visibility = 'visible'
	}
}

months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

// Stylesheet switcher
function RARsetActiveStyleSheet(myStyle, myForm) {
	myForm.submit()
}

// switch styles

function setActiveStyleSheet(title, filename, myForm) {
	title = title.replace(/\+/g, " ");
	if (document.getElementsByTagName) {
		var i, a, main;
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel") &&
					a.getAttribute("rel").indexOf("style") != -1 &&
					a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	} else if (myForm) {
		myForm.submit()
	}
}

function getActiveStyleSheet() {
	if (document.getElementsByTagName) {
		var i, a;
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel") &&
					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") &&
				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 testCookies() {
	createCookie("test","ok",1);
	if (readCookie("test")) {
		return true;
	} else {
		return false;
	}
}

function getInnerHeight() {
	var y;
	if (self.innerHeight) // all except Explorer
	{
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		y = document.body.clientHeight;
	}
	return y;
}

function getInnerWidth() {
	var x;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
	}
	return x;
}

function getVertScroll() {
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	return y;
}

function getHorizScroll() {
	var x;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
	}
	return x;
}

window.onload = function(e) {
	var cookie = readCookie("styletitle");
	var title = (cookie != 'null') ? cookie : getPreferredStyleSheet();
	if(title) setActiveStyleSheet(title, '', false);
	ddb();
	initLinks();
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("styletitle", title, 365);
}

