/***********************************************************************************
 * Frontline Logic, Inc. Confidential and Proprietary
 *
 * This file and its related files contain valuable, confidential, and proprietary
 * information.  Disclosure, use, or reproduction without the written 
 * authorization of Frontline Logic, Inc. is prohibited.  This work by Frontline
 * Logic, Inc. is protected by laws of the United States and other
 * countries.  If publication of this file and its related files should occur, the
 * following notice shall apply:
 *
 * Copyright (c) 2007 Frontline Logic, Inc.  All rights reserved.
 ***********************************************************************************/

/**
* Object for drawing footer menu
* @param separator text string to add between menu entries.  Default is " | " (space, pipe, space)
* @return object
*/
function cgFooter(separator)
{
	this.m_separator  = " | ";
	
	if (separator != null && separator.length > 0)
	{
		if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter", "Setting separator to: " + separator);
		this.m_separator = separator;
	}
	
	cgFooter.prototype.drawMenu = cgFooter_drawMenu;
	cgFooter.prototype.createSubnodeMenu = cgFooter_createSubnodeMenu;

	/**
	* Writes menu to browser document
	* @param node root node for site
	* @return void
	*/
	function cgFooter_drawMenu (node)
	{
		var menu = this.createSubnodeMenu(node);
		if (g_debugLevel == 4) addDebugMessage("cgFooter.js", "cgFooter_drawMenu", "Created menu: " + menu);
		document.writeln(menu);
		//document.write('<table cellspacing="0" cellpadding="0" border="0" style="margin: 0 auto;">');
		//this.displaySubLevel(node);
		//document.write('</table>');
	}

	/**
	* Builds menu for site excluding items marked with custom section property to not show in menu
	* @param node root node for site
	* @return string
	*/
	function cgFooter_createSubnodeMenu(node)
	{
		var out = new Array(); // to build output string
		var o = 0; // counter for out array
		try
		{
			// put Home link in menu
			out[o++] = cgFooter_buildUrl(node.m_label, node.m_href);
			subNodes = node.m_subNodes;
			for (var i = 0; i < subNodes.length; i++)
			{
				subNode = subNodes[i];
				if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter_createSubnodeMenu", "Processing node: " + subNode.m_id + ", " + subNode.m_label);
				// skip any nodes not marked to "showInNavigation"
				if (subNode.cp_showInNavigation != 'TRUE' || subNode.cp_ShowinFooter != 'TRUE')
				{
					if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter_createSubnodeMenu", "Skipping node because custom property showInNavigation != TRUE");
					continue;
				}
				if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter_createSubnodeMenu", "Adding node to menu string");
				out[o++] = this.m_separator;
				out[o++] = cgFooter_buildUrl(subNode.m_label, subNode.m_href);
			}
		}
		catch (e)
		{
			showErrorMessage("cgFooter.js", "cgFooter_createSubnodeMenu", e);
		}
		if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter_createSubnodeMenu", "Returning completed menu string");
		return out.join("");
	}
	
	/**
	* Creates an anchor tag
	* @param label text to display in anchor
	* @param href URL for anchor
	* @return string
	*/
	function cgFooter_buildUrl(label, href)
	{

		while(label.indexOf("&lt;") > -1) {
			
			last = " " + label.substring(label.indexOf("&gt;") + 4,label.length)
			first = label.substring(0,label.indexOf("&lt;"))
			label = first + last;
		}


		if (g_debugLevel == 5) addDebugMessage("cgFooter.js", "cgFooter_buildUrl", "Creating anchor tag for: " + label + " (" + href + ")");
		return "<a href=\"" + href + "\">" + label + "</a>";
	}
}

