/////////////////////////////////////////////////////////////////////////////
// Function : Site_Map
// Comments :   This is the constructor method  to set up and hold the parameter values
//                             passed into it.
/////////////////////////////////////////////////////////////////////////////

function SiteMap(intLineMax, strNumLevels, strStartLevel, strIncludeNodeList, strExcludeNodeList)
{
	this.m_ClassName  = 'siteMap';
	
	this.m_NumLevels = 7;
	this.m_EndLevel = 8;

	this.m_ColMax = 3;
	this.m_ColCounter = 0;
	this.m_LineMax = 25;
	this.m_LineCounter = 0;
	this.m_NodeHeadingLevel = 2;
	
	// create array of include node ids from comma delimited string
	if (strIncludeNodeList != '')
		this.m_IncludeIds = strIncludeNodeList.replace(/ /g, '').split(',');
	else
		this.m_IncludeIds = new Array(0);
		
	// create array of excusion node ids from comma delimited string
	if (strExcludeNodeList != '')
		this.m_ExcludeIds = strExcludeNodeList.replace(/ /g, '').split(',');
	else
		this.m_ExcludeIds = new Array(0);
	this.m_NavPath    = g_navNode_Path;
		
	SiteMap.prototype.Display = SiteMap_Display;
	SiteMap.prototype.DisplayNode = SiteMap_DisplayNode;
	
	if (intLineMax != 0)
		this.m_LineMax = intLineMax;

	if (strNumLevels != '') {
		var value = parseInt(strNumLevels);
		if (value != NaN && value < this.m_NumLevels)
			this.m_NumLevels = value;
	}

	if (strStartLevel != '') {
		var value = parseInt(strStartLevel);
		if (value != NaN)
			this.m_StartLevel = value;
		else
			this.m_StartLevel = 1;
	}
	
	if (this.m_StartLevel > this.m_NodeHeadingLevel)
		this.m_NodeHeadingLevel = this.m_StartLevel;
	
	this.m_EndLevel = this.m_StartLevel + this.m_NumLevels;
}

function SiteMap_Display (node)
{
	document.write ('<table width="770" border="0" align="center" valign="top" cellpadding="0" cellspacing="0">');
	document.write ('<tr valign="top" height="12">');
	document.write ('<td width="6">&nbsp;</td>');
	document.write ('<td width="253" class="columnTop">&nbsp;</td>');
	document.write ('<td width="6">&nbsp;</td>');
	document.write ('<td width="253" class="columnTop">&nbsp;</td>');
	document.write ('<td width="6">&nbsp;</td>');
	document.write ('<td width="253" class="columnTop">&nbsp;</td>');
	document.write ('</tr>');
	document.write ('<tr height="400" valign="top">');
	document.write ('<td width="6">&nbsp;</td>');
	document.write ('<td width="253" class="columnBkgd">');
	document.write ('<ul id="' + this.m_ClassName + '">');
	this.DisplayNode(node);
	
	document.write ('</ul></td></tr></tbody></table>');
}

function SiteMap_DisplayNode(node)	
{
	var nodeClass = this.m_ClassName;

	var nodeLevel = node.m_level;
	var nodeId = node.m_id;
	var secIdArray = new Array();
	
	if (nodeLevel >= this.m_StartLevel && nodeLevel < this.m_EndLevel)
	{
		var ds = new Array();
		var di = 0;
		
		//check if we should start new column
		if (nodeLevel <= this.m_NodeHeadingLevel && this.m_LineCounter > this.m_LineMax) {
			if (this.m_ColCounter < this.m_ColMax - 1) {
				ds[di++] = '</ul></td><td width="6">&nbsp;</td>';
				ds[di++] = '<td width="253" class="columnBkgd">';
				ds[di++] = '<ul id="' + nodeClass + '">';
				this.m_LineCounter = 0;
			}
			this.m_ColCounter++;
		}
		
		if (nodeLevel > 0)
			nodeClass += '-' + nodeLevel;

		ds[di++] = '<li id="' + nodeClass + '">';
		ds[di++] = '<a href="' + node.m_href + '" id="' + nodeClass + '">' + node.m_label + '</a></li>';
				
		this.m_LineCounter++;
		
		document.write(ds.join(''));
	}
	
	// expand sub-levels (if any)
	if (nodeLevel != 0)
		for (var i = 0; i < node.m_subNodes.length; i++) {
			var blnExcluded = false;
			for (var j = 0; j < this.m_ExcludeIds.length; j++) {
				if (node.m_subNodes[i].m_id == this.m_ExcludeIds[j]) {
					blnExcluded = true;
					break;
				}
			}
			if (!blnExcluded) this.DisplayNode(node.m_subNodes[i]);
		}
	else
		for (var i = 0; i < node.m_subNodes.length; i++)
			for (var j = 0; j < this.m_IncludeIds.length; j++)
				if (node.m_subNodes[i].m_id == this.m_IncludeIds[j])
					this.DisplayNode(node.m_subNodes[i]);
}