/////////////////////////////////// Multiple Onload Events

var onloadEvents = new Array();

function setOnload(f)
{
	var i = onloadEvents.length;
	onloadEvents[i] = f;
}

function doOnload()
{
	if(onloadEvents.length == 0) return;

	for(var i=0; i<onloadEvents.length; i++)
	{
		eval(onloadEvents[i] + "()");
	}
}

onload=doOnload;

/////////////////////////////////// Get Levels (URL)

function getLevels()
{
	var levels = window.location.pathname.substring(1,window.location.pathname.length).split("/");

	for(var i=0; i<levels.length; i++)
	{
		if(levels[i]=="" && i==levels.length-1) levels[i] = "index";
	}

	return levels;
}

////////////////////////////////// Highlight Menu

function setMenu()
{
	var levels = getLevels(); // Get the URL array

	var ul = document.getElementById("p-menu"); // Get the list with the top anchors

	if(ul)
	{
		var li,a,href; // The li, the anchor, the anchor's pathname
	
		var page = new Array; // The file/folder, used to match up the levels array
	
		for(var i=0; i<ul.childNodes.length; i++)
		{
			if(ul.childNodes[i].nodeType == 1) // if it's a HTML tag (LI)
			{
				li = ul.childNodes[i];
	
				if(li.childNodes[0] && li.childNodes[0].nodeName == "A") // If it has an anchor in the LI
				{
					a = li.childNodes[0];
	
					href = (a.pathname.indexOf("/")==0) ? a.pathname.substring(1,a.pathname.length) : a.pathname; // Get rid of the leading "/"
	
					if(href.indexOf("/") > -1) // It's in a folder
					{
						page = href.split("/");
						if(page[1] == "") page[1] = "index"; // If it's a page, and it's blank, make it the index
					}
					else
					{
						if(href == "") page[0] = "index"; // If it's a page, and it's blank, make it the index
						else page[0] = href; // Ok, it's just a file
					}
	
					if(page[0] == levels[0]) // If the current location and the link match, turn it on
					{
						li.className = "on"; // On
						break;
					}
				}
			}
		}
	}
}

//setOnload("setMenu");

////////////////////////////////// Highlight Submenu

function setSub()
{
	var levels = getLevels(); // Get the URL array

	var ul = document.getElementById("menu-sub"); // Get the list with the top anchors

	if(ul)
	{
		var li,a,href; // The li, the anchor, the anchor's pathname
	
		var page = new Array; // The file/folder, used to match up the levels array
	
		for(var i=0; i<ul.childNodes.length; i++)
		{
			if(ul.childNodes[i].nodeType == 1) // if it's a HTML tag (LI)
			{
				li = ul.childNodes[i];
	
				if(li.childNodes[0] && li.childNodes[0].nodeName == "A") // If it has an anchor in the LI
				{
					a = li.childNodes[0];
	
					href = (a.pathname.indexOf("/")==0) ? a.pathname.substring(1,a.pathname.length) : a.pathname; // Get rid of the leading "/"
	
					if(href.indexOf("/") > -1) // It's in a folder
					{
						page = href.split("/");
						if(page[1] == "") page[1] = "index"; // If it's a page, and it's blank, make it the index
					}
					else
					{
						if(href == "") page[0] = "index"; // If it's a page, and it's blank, make it the index
						else page[0] = href; // Ok, it's just a file
					}
	
					if(page[1] == levels[1] && page[0] == levels[0]) // If the current location and the link match, turn it on
					{
						li.className = "on"; // On
						break;
					}
				}
			}
		}
	}
}

//setOnload("setSub");

////////////////////////////////// Global, First Input Field Focus

function formFocus()
{
	var f = document.forms[0];
	
	if(f == null)
		return;

	for(var i=0; i<f.elements.length; i++)
	{
		if(f.elements[i].type.indexOf("text") > -1)
		{
			f.elements[i].focus();
			break;
		}
	}
}

setOnload("formFocus");