/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007, 2008, Oracle. All rights reserved.
// Function : TS_GE_HNAV
// Comments : 
/////////////////////////////////////////////////////////////////////////////

var uRoles ="";

function TS_GE_HNAV(strTextColor, strHoverColor, strFocusColor, strSeparator, strClassName, 
							strShowHome, strStartLevel, strNumLevels, strUserProducts, strUserRoles, strPageProducts, strPageRoles, strNode)
{
	this.NodeName = strNode;
	this.uRoles = strUserRoles;

	this.m_TextColor  = '';
	this.m_HoverColor = '';
	this.m_FocusColor = '';
	this.m_Separator  = '|';
	this.m_ClassName  = 'nav-first ';
	
	this.m_ShowHome   = false;
	
	this.m_StartLevel = 1;
	this.m_NumLevels  = 1;
	this.m_EndLevel   = 1;
	
	this.m_NavPath    = g_navNode_Path;
			
	TS_GE_HNAV.prototype.Display = TS_GE_HNAV_Display;
	TS_GE_HNAV.prototype.DisplaySubLevel = TS_GE_HNAV_DisplaySubLevel;
		
	if (strTextColor != '')
		this.m_TextColor = strTextColor;
		
	if (strHoverColor != '')
		this.m_HoverColor = strHoverColor;

	if (strFocusColor != '')
		this.m_FocusColor = strFocusColor;

	if (strSeparator != '')
		this.m_Separator = strSeparator;

	if (strClassName != '')
		this.m_ClassName = strClassName;

	if (strShowHome == 'true')
		this.m_ShowHome = true;
		
	if (strStartLevel != '')
	{
		var value = parseInt(strStartLevel);
		if (value != NaN)
			this.m_StartLevel = value;
	}
	
	if (strNumLevels != '')
	{
		var value = parseInt(strNumLevels);
		if (value != NaN)
			this.m_NumLevels = value;
	}

	this.m_EndLevel = this.m_StartLevel + this.m_NumLevels - 1 ;
}

function TS_GE_HNAV_Display (node)
{
	//document.write('<table width="100%" cellspacing="0" cellpadding="0" border="0">');
	this.DisplaySubLevel(node);	
	//document.write('</table>');
}

function TS_GE_HNAV_DisplaySubLevel (node)	
{
	var bSelected = false;
	var bDisplay  = false;

	var nodeColor = this.m_TextColor;
	var nodeClass = this.m_ClassName
	var nodeLevel = node.m_level+1;
	
	if (nodeLevel > 6)
		nodeLevel = 6;
		
	var ds = new Array();
	var di = 0;
	var count = 0;

	var selectedNode = null;

	if (this.m_ShowHome && (node.m_level == 0))
		count = -1;

	var href = '';
	var label = '';
	
	if(node.m_level == 1){
		ds[di++] = '<div class="vertical-space-4px"></div><div class="nav-lev-' + nodeLevel + '">';
	}else{
		ds[di++] = '<div class="nav-lev-' + nodeLevel + '">';
	}

	//ds[di++] += '<div class="nav-lev-' + nodeLevel + '">';
	
	if (node.m_level >= this.m_StartLevel-1 && node.m_level < this.m_EndLevel)
		bDisplay = true;

	if (bDisplay) 
	{
		//ds[di++] = '<tr><td nowrap>';
	}	
		
	for ( ; count < node.m_subNodes.length; count++)
	{
		bSelected = false;
		nodeColor = this.m_TextColor;

		if (count == -1)	// Root/home link 
		{	
			// this is only really applicable if we're working the top level
			// but the same technique could be used to display a generalised "back-up-one-level")
			nodeClass = 'nav-first ';
			
			if ( (this.m_NavPath.length == node.m_level+1) && (this.m_NavPath[node.m_level] == node.m_id) )
			{
				bSelected = true;
			}
			label = node.m_label;
			href  = node.m_href;
		}
		else
		{	
			if (node.m_subNodes[count].cp_Roles != null)
				if (!checkRigths(node.m_subNodes[count].cp_Roles))
					continue;
			else
				if (!checkRigths('public'))
					continue;

			if (this.m_NavPath.length >= node.m_subNodes[count].m_level)
			{
				if (this.m_NavPath[node.m_subNodes[count].m_level] == node.m_subNodes[count].m_id)
				{
					bSelected = true;
					selectedNode = node.m_subNodes[count];
				}
			}
			nodeClass = '';
			label = node.m_subNodes[count].m_label;
			href = node.m_subNodes[count].m_href;
		}

		if (bSelected)
		{
			nodeClass += 'nav-selected';
		}
		else
		{
			nodeClass += 'nav-unselected';
		}

		if (bDisplay)
		{
			if(nodeLevel == 1)
				ds[di++] = '<a href="' + href + '"><span class="' + nodeClass + '">';
			else
				ds[di++] = '<span class="' + nodeClass + '"><a href="' + href + '">';
			ds[di++] = label;
			if(nodeLevel == 1)
				ds[di++] = '</span></a>';
			else
				ds[di++] = '</a></span>';
		}
	} 
	
	if (bDisplay)
	{
		ds[di++] = '</div>';
		document.write(ds.join(''));
	}
	
	if (selectedNode != null)
		this.DisplaySubLevel (selectedNode);
}

function checkAccess(node) 
{
	//alert(node.cp_Products + " "+uProducts+ " "+node.cp_Roles +" "+uRoles);
	
	
	//alert("NavNode= "+SSNavigationNode);
	
	return true;//((node.cp_Products == uProducts) && (node.cp_Roles == uRoles) )
}

function checkRigths(cp_Roles)
{
	var strArray = new Array();
	var bReturn = false;
	
	if (cp_Roles.length > uRoles.length)
	{	
		strArray = splitStrings(cp_Roles);
		 
		for (var i = 0; i < strArray.length ; i++)
		{
			//alert("cp_Role: "+strArray[i]);
			if (uRoles.match(strArray[i]))
			{
				bReturn = true;
				break;
			}
		}
	}
	else
	{
		strArray = splitStrings(uRoles);
		for (var i = 0; i < strArray.length ; i++)
		{
			//alert("uRoles: "+strArray[i]);
			if (cp_Roles.match(strArray[i]))
			{
				bReturn = true;
				break;
			}
		}
	}
	
	return bReturn;
	//return (cp_Roles.match(uRoles))// == uRoles)
}

function splitStrings(strString2Split)
{
	var strArray = new Array();
	strArray = strString2Split.split("|");
	return strArray;
}

