gPrintFunctionsIncluded = false;

window.onload = function()
{
	LoadMenu();
	StyleLastLinks();
	IDcurrentPage();

	if ( gPrintFunctionsIncluded )
		LoadPrintOptions();
	else
		DisablePrintStyles();
};


function IDcurrentPage()
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Searches the nav                                     |
	   | until it finds the link to the currently loaded page |
	   | Assigns the list the ID "currPage"                   |
	   | and the link the ID "currLink."                      |
	   | If no link is found, no IDs are assigned.            |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+*/

	// First, get the URL of the currently loaded page, 
	// removing any anchors (shortcuts).
	var expURL = /^[^#]+/;	// a regular expression that captures everything before the first "#" in the URL
	var strURL = location.href.match(expURL);
	strURL = strURL.toString();	// save as a string of text

	if ( document.getElementById("nav") )
	{
		// Get all the <li>s in nav.
		var navLinks = document.getElementById("nav").getElementsByTagName("li");

		// For each <li> in nav...
		for ( var i=0; i < navLinks.length; i++ )
		{
			// ...get the path of the link nested inside that <li>.
			var strPath = navLinks[i].getElementsByTagName("a")[0].href;

			// I'm using all caps so that a comparison won't fail to match
			// simply because the letter casing is off.
			if ( strPath.toUpperCase()==strURL.toUpperCase() )
			{
				navLinks[i].id = "currPage";
				navLinks[i].getElementsByTagName("a")[0].id = "currLink";
				// If the currLink is in the subnav, then the nested list needs to be displayed.
				// (If it's not nested, then this just reinforces that the nav <div> is a block.)
				navLinks[i].parentNode.style.display = "block";
				return;	// no need to keep looping, you've found the match
			}
		}
	}
}

function StyleLastLinks()
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Assigns the lastLink class |
	   | to the last list element   |
	   | in the specificied list.   |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */
	if ( document.getElementById("content") )
	{
		var aBackNext = document.getElementById("content").getElementsByTagName("div");
		
		for ( var i=0; i < aBackNext.length; i++ )
		{
			if ( aBackNext[i].className=="backNext" )
			{
				var listElements = aBackNext[i].getElementsByTagName("li");
				
				listElements[listElements.length-1].className = "lastLink";
			}
		}
	}

	if ( document.getElementById("footer") )
	{
		var footerLinks = document.getElementById("footer").getElementsByTagName("li");

		footerLinks[footerLinks.length-1].className = "lastLink";
	}
}

function SetSrcFromRoot(strImg)
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Dynamically determines a path to the root /images/ directory. |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */

	// (It does this by stealing the src of the header graphic,
	// and replacing "AEP_head1" with the name of your <img>.)
	if ( document.getElementById("NPStitle") )
	{
		var objHeader = document.getElementById("NPStitle");
		
		var strFullPath = objHeader.src.replace("AEP_head1.gif", strImg);
		
		return ( strFullPath );
	}
}

function Toggle(targetID)
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Toggles the visibility of the object |
	   | that has the ID you feed in          |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */

	if ( document.getElementById )
	{
		var target = document.getElementById(targetID);

		if ( target.style.visibility=="hidden" )
			target.style.visibility = "visible";
		else if ( target.style.visibility=="visible" )
			target.style.visibility = "hidden";
		else if ( target.style.display=="none" )
			target.style.display = "block";
		else
			target.style.display = "none";
	}
}

function DisablePrintStyles()
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Disables all preferred style sheets             |
	   | with the word "print" in their title attribute. |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */

	var printStyles = new Array();
	var counter = 0;

	// Cycles through all the style sheets.
	var links = document.getElementsByTagName("link");

	for ( var i=0; i < links.length; i++ )
	{
		// If the rel attribute contains the word "s-t-y-l-e"
		// AND if there is a title attribute...
		if ( links[i].getAttribute("rel").indexOf("style") != -1
		  && links[i].getAttribute("title") )
		{
			// ...if that title attribute contains the word "p-r-i-n-t"...
			if ( links[i].getAttribute("title").indexOf("print") != -1 )
			{
				// ...save it.
				printStyles[counter] = links[i];
				counter++;
			}
		}
	}
	
	for ( var i=0; i < printStyles.length; i++ )
		printStyles[i].disabled = true;
}

function GetCookie(cookieName)
{
	/* +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
	   | Returns the value of the cookie         |
	   | whose name you pass as an argument,     |
	   | or returns null if it can't.            |
	   | [example: ...] |
	   +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */

	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");	// semicolons and spaces separate cookies in the cookie string

	if (cookieStartsAt==-1)		// then maybe the cookie you want is first in the object, in which case there would be no space
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");

	if (cookieStartsAt==-1)		// then your cookie doesn't exist and/or cookies have been disabled
		cookieValue = null;
	else				// otherwise...
	{				// ...capture the value
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;	// the start will be the first equal sign after the beginning of our cookie
		var cookieEndsAt = cookieValue.indexOf(";",cookieStartsAt);	// the end will be the first semicolon

		if (cookieEndsAt==-1)	// unless there were no more semicolons...
			cookieEndsAt = cookieValue.length;	// ...meaning that the cookie is at the end of the string
								// (string's length = index of last string character)

		cookieValue = cookieValue.substring(cookieStartsAt, cookieEndsAt);
	}

	return cookieValue;
}