var itemOver;

function initAfterLoad()
	{
	alternateTableRowColors();
	}
	
function getTarget()
	{
	var target = document.getElementById(sitePath);
	if (target == null)
		{
		re = /:index$/gi;
		target = document.getElementById(sitePath.replace(re, ''));
		}
	return target;
	}
	
function setMenu(expand) 
	{
	menuExpanded = expand;
	if (document.getElementById)
		{
		var menuRoot = getMenuRoot();
		if (menuRoot)
			openMenu(menuRoot);
		/*
		 * Flag menu reference with 'urhere' class
		 */
		var target =  getTarget();
		if (target)
			{
			pageTitle = target.getAttribute("title");
			target.className = target.className + " urhere";
			}
			
		var sitePathArray = sitePath.split(':');
		var topItem = sitePathArray[0];
		var topTarget = document.getElementById("top:" + topItem);
		if (topTarget)
			topTarget.className = "urhere";
		/*
		 * Change menu image
		 */
		if (topItem && topItem.length)
			{
			var menuTitle = document.getElementById("mmtitle");
			if (menuTitle && menuTitle.nodeName.toLowerCase() == "img")
				{
				menuTitle.src = "/ccs/wwwresources/images/nav/" + topItem + ".gif";
				}
			var container = document.getElementById("container");
			var depth = sitePathArray.length;
			if (container && depth == 2)
				{
				container.style.background = "White url(images/watermark.gif) no-repeat top right";
				}
			}
			
		/*
		 * Change Expand/Collapse text based on context
		 */
		var menuToggle = document.getElementById('menuToggle');
		if (!menuToggle) return;
		var nodeAnchorList = menuToggle.getElementsByTagName("a");
		if (nodeAnchorList && nodeAnchorList.length)
			toggleLink = nodeAnchorList[0];
		if (menuExpanded)
			toggleLink.innerHTML = "Collapse Menu";
		else
			toggleLink.innerHTML = "Expand Menu";
		}
	}
	
function getMenuRoot()
	{
	var menuRoot = document.getElementById("sideMenu");
	if (menuRoot && menuRoot.nodeName.toLowerCase() == "ul")
		return menuRoot;
	return null;
	}
	
function openMenu(node)
	{
	if (node == null) return;
	if (node.nodeName.toLowerCase() == "ul")
		{
		var listItems = node.getElementsByTagName("li");
		for (var i = 0; i < listItems.length; i++)
			{
			var submenu = getSubmenu(listItems[i]);
			if (submenu != null && submenu.length)
				openMenu(submenu);
			}
		}
	}

function getNodeAnchor(listItem)
	{
	var nodeAnchorList = listItem.getElementsByTagName("a");
	if (nodeAnchorList && nodeAnchorList.length)
		return nodeAnchorList[0];
	return null;
	}
	
function getNodeMenu(listItem)
	{
	var nodeMenuList = listItem.getElementsByTagName("ul");
	if (nodeMenuList && nodeMenuList.length)
		return nodeMenuList[0];
	return null;
	}
	
function getListParent(listItem)
	{
	var menuParent = listItem.parentNode;
	if (menuParent.nodeName.toLowerCase() == "ul")
		{
		var listParent = menuParent.parentNode;
		if (listParent.nodeName.toLowerCase() == "li")
			return listParent;
		}
	return null;
	}
	
function getSubmenu(listItem)
	{
	if (listItem.nodeName.toLowerCase() != "li") return null;
	var nodeAnchor = getNodeAnchor(listItem);
	var id = (nodeAnchor) ? nodeAnchor.id : "";
	var depth = id.split(":").length;
	
	var subMenu = getNodeMenu(listItem);	// returns UL object
	if (subMenu)
		{
		if (depth == 3)
			{
			setFloatMenu(listItem);
			nodeAnchor.className = "open";
			}
		else if (sitePath.indexOf(id) != -1 || menuExpanded)
			{
			nodeAnchor.className = "open";
			subMenu.style.display = "block";
			return subMenu;
			}
		else
			{
			nodeAnchor.className = "closed";
			subMenu.style.display = "none";
			}
		}
	return null;
	}
	
function setFloatMenu(listItem)
	{
	if (enabled)
		{
		listItem.onmouseover = function()
			{
			this.className = "over";
			}
		listItem.onmouseout = function()
			{
			this.className = "";
			}
		}
	}

function getLink(listItem)
	{
	if (listItem.nodeName.toLowerCase() != "li") return null;
	if (listItem.firstChild != null && listItem.firstChild.nodeName.toLowerCase() == "a")
		return listItem.firstChild;
	}

/*
 * Build breadcrumb string
 */
function buildBreadCrumbs() 
	{
	if (!document.getElementById)
		return '';
    
	var trail = '';
	var path = '';
	/* getElementById(sitePath) will return the A element which links to
	 * current page.  Split the path on '/' and build breadcrumbs forward.
	 */
	var sitePathArray = sitePath.split(':');
	for (var i = 0; i < sitePathArray.length; i++)
		{
		path = concatPath(path, sitePathArray[i]);
		/* If explicitly viewing an index page (last token in sitePath),
		 * it is not reflected in the breadcrumbs trail.
		 */
		if (sitePathArray[i] == 'index')
			return trail;
      	
		trail += getLink(path);
    	}
	return trail;
	}

function concatPath(str1, str2)
	{
	if (str1.length > 0)
		return str1 + ':' + str2;
	else
		return str2;
	}

function getLink(id)
	{
	/*
	 * Returns formatted link if element with associated id is an <a> element.
	 * otherwise, returns empty string.  Filename in path is optional for index
	 * pages.
	 */
	var linkElement = document.getElementById(id) ? document.getElementById(id) : document.getElementById(concatPath(id, 'index'));
	if (linkElement && linkElement.nodeName.toLowerCase() == "a")
		{
		hrefAttribute = linkElement.getAttribute('href');
		if (hrefAttribute)
			return ' > <a href="' + linkElement.getAttribute('href') + '">' + linkElement.innerHTML + '</a>';
		return ' > ' + linkElement.innerHTML;
		}
	return '';
	}

function alternateTableRowColors()
	{
	if (!document.getElementById) return;
	var className = "alternateRowColors";
	var rowColor0 = "white";
	var rowColor1 = "#eee";
	var colColor0 = "#eee";
	var colColor1 = "#ddd";
	
	var tables = document.getElementsByTagName("table");
	for(var i=0; i < tables.length; i++)
		{
		if (tables[i].className != className) continue;
		var table = tables[i];
		var rows = table.getElementsByTagName("tr");
		var rowCount = 0;
		for(var j=0; j < rows.length; j++)
			{
			var row = rows[j];
			var cols = row.getElementsByTagName("td");
			if (cols.length) // excluded if no TD found (table header)
				{
				row.style.background = eval("rowColor" + (rowCount%2));
				cols[0].style.background = eval("colColor" + (rowCount%2));
				rowCount++;
				}
			}
		}
	}

/* Used for simple validation of login forms */
function  checkLogin(form)
    {
    if  (form.userid && !form.userid.value.length) 
        {
		alert("Please provide your Central Login account userID");
		return false;
		}
	else if  (form.username && !form.username.value.length) 
        {
		alert("Please provide your Central Login account userID");
		return false;
		}
	else if  (form.login && !form.login.value.length) 
        {
		alert("Please provide your Central Login account userID");
		return false;
		}
	else if (form.password && !form.password.value.length)
		{
		alert("Please provide your Central Login account password");
		return false;
		}
	return true;
    }
	
/* pop window - biggest size */
function popUpSizedWindow1(url, offset) 
	{
		childWindow = window.open(url,'info','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=950,height=550,left='+offset+',top='+offset);
		childWindow.focus();
		return false;
	}
/* pop window - medium size */
function popUpSizedWindow2(url, offset) 
	{
		childWindow = window.open(url,'info','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=550,left='+offset+',top='+offset);
		childWindow.focus();
		return false;
	}

/* pop window - small size */
function popUpSizedWindow3(url, offset) 
	{
		childWindow = window.open(url,'info','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=450,left='+offset+',top='+offset);
		childWindow.focus();
		return false;
	}
