/*
	Variables:
*/
var currentState = "open"; // stores the current state of the Left Nav 
var browserName=navigator.appName; // stores the name of the web browser the person is using
/*
	pageLoaded -- calls the appropriate functions to load the page.
*/
function pageLoaded(Page_Name, Nav_State) {
	processNavList(Page_Name);
	navOpener(Nav_State);
}
/*
	processNavList -- starting point for collapsing the bulleted list for the navigation
*/
function processNavList(Current_Page) {
	collapseAllBullets();
	if (Start_Node = document.getElementById("leftnav")) {
		child = Start_Node.getElementsByTagName("a");
		for ( var j = 0; j<child.length; j++ ) {
			if ( child.item(j).id == Current_Page ) {
				childULs = child.item(j).parentNode.childNodes;
				for (var i = 0; i<childULs.length; i++ ) {
					if (childULs.item(i).tagName == "UL") {
						childULs.item(i).className = childULs.item(i).className.replace("notshown", " shown");
					}
					recurseNav(childULs.item(i));
				}
			}
		}
	}
}
/*
	recurseNav -- recurses through the bulleted list and displays the items below the start
*/
function recurseNav(Given_Node) {
	Parent_Node = Given_Node.parentNode.parentNode;
	if (Parent_Node.tagName == "UL") {
		Parent_Node.className = Parent_Node.className.replace("notshown", " shown");
		recurseNav(Parent_Node);
	}
}
/*
	collapseAllBullets -- goes through all of the bullets in the list and hides them
*/
function collapseAllBullets() {
	uls = document.getElementById("leftnav").getElementsByTagName("UL");
	i=0;
	while (i<uls.length) {
		uls.item(i).className += " notshown";
		i++;
	}
	leftNavChildren = document.getElementById("leftnav").childNodes;
	i=0;
	while (i<leftNavChildren.length) {
		if (leftNavChildren.item(i).tagName == "UL") {
			leftNavChildren.item(i).className = leftNavChildren.item(i).className.replace("notshown", " shown");
		}
		i++;
	}
}

/*
	navOpener -- performs the actual opening or closing of the left nav bar
*/
function navOpener(State) {
	if ( ! document.getElementById("Home_Index") ) {
		leftNav = document.getElementById("leftnav");
		collapseImage = document.getElementById("collapsor");

		if ( State == "close" ) {
			leftNav.style.display = "none";
			currentState = "close";
			document.images["collapsor"].src="/skins/2007/gfx/collapse_right.gif";
		} else {
			if ( browserName == "Microsoft Internet Explorer" ) {
				leftNav.style.display = "block";
			} else {
				leftNav.style.display = "table-cell";
			}
			currentState = "open";
			document.images["collapsor"].src="/skins/2007/gfx/collapse_left.gif";
		}
	}
}

/*
	toggleNavBar -- opens or closes the left nav depending on it's state.
*/
function toggleNavBar() {
	if ( currentState == "close" ) {
		navOpener("open");
	} else {
		navOpener("close");
	}
}

/*
	clearField -- clears the input field when a user clicks into it, if a default isn't there
*/
function clearField(myField, defaultText) {
	if ( myField.value == defaultText ) {
		myField.value = "";
	}
}

/*
	restoreField -- restores the default text on a field if the user clicked out of it and the field is empty
*/
function restoreField(myField, defaultText) {
	if ( myField.value == "" ) {
		myField.value = defaultText;
	}
}
