// JavaScript Document

function stripHTML(string) { 
	return string.replace(/<(.|\n)*?>/g, ''); 
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
   
function initSubPageLeftNav()
{
	var pageTitle = trim(stripHTML($("#subpageHeaderDiv").html().toUpperCase()));
	var found = false;

	$('.leftNavNormalItemInactiveDiv').each( function() {
		var element = $(this);
		var thisLeftNavTitle = trim(stripHTML($(element.children("a")[0]).html()));
		if (thisLeftNavTitle == pageTitle)
		{
			//found a match
			element.removeClass("leftNavNormalItemInactiveDiv");
			element.addClass("leftNavNormalItemActiveDiv");
			
			//now light up the parent One...
			var parentDivElement = $(element.parent().get(0));				
			var headerDivElement = $(parentDivElement.children("div")[0]);
			headerDivElement.removeClass("leftNavHeaderItemInactiveDiv");
			headerDivElement.addClass("leftNavHeaderItemActiveDiv");	
			
			found = true;
		}
	});	
	
	if (found ==false)
	{
		//havent found the left nav link yet, could it be a section header?
		$('.leftNavHeaderItemInactiveDiv').each( function() {
			var element = $(this);
			var thisLeftNavTitle = trim(stripHTML($(element.children("a")[0]).html()));
			
			if (thisLeftNavTitle == pageTitle)
			{	
				element.removeClass("leftNavHeaderItemInactiveDiv");
				element.addClass("leftNavHeaderItemActiveDiv");				
			}		
		});	
	}
	
	
}
