function ResetActive(Branch, NewActiveElement)
{
	ListOfNodes = Branch.getElementsByTagName('a');
	for(i = 0; i< ListOfNodes.length; i++)
	{
		LinkNode = $(ListOfNodes[i]);

		if(NewActiveElement != null && LinkNode.id == NewActiveElement.id &&
			!LinkNode.hasClassName('active'))
		{
			LinkNode.removeClassName('inactive');
			LinkNode.addClassName('active');
		}
		else
		{
			if(LinkNode.hasClassName('active'))
			{
				LinkNode.removeClassName('active');
			}
			if(!LinkNode.hasClassName('inactive'))
			{
				LinkNode.addClassName('inactive');
			}
		}
	}
}

function AlterBranch(BranchId,LinkId)
{	
	if(	$(BranchId) == null ||
		$(LinkId) == null)
		return;
	NewClass = ($(LinkId).hasClassName('active') ? 'inactive' : 'active');
	
	$(LinkId).blur();
	// When the branch is about to be opened - ensure all others are closed
	var BranchList = $('content_left').getElementsByTagName('ul');
	for (i = 0; i < BranchList.length; i++)
	{
		//this function should only hide top level branches
		if('branch' == BranchList[i].id.substring(0, 6))
		{
			BranchList[i].style.display = '';
		}
		//it should show sub branches if they're active
		else if('subbranch' == BranchList[i].id.substring(0, 9))
		{
			if('active' == BranchList[i].className)
			{
				ShowSubbranch(BranchList[i].id, '');
			}
		}
	}
	
	/*var BranchLinkList = $('content_left').getElementsByTagName('a');
	for (i = 0; i < BranchLinkList.length; i++)
	{
		if('node' == BranchLinkList[i].id.substring(0, 4))
		{
			BranchLinkList[i].className = 'inactive';
		}
	}*/
	
	$(LinkId).className=NewClass;
	// Expand/Retract the branch (setting display, and removing/adding appropriate class)
	$(BranchId).style.display= (	 NewClass == 'active' ? 'block' :'none');
	$(BranchId).removeClassName(	(NewClass == 'active' ? 'inactive' :'active'));
	$(BranchId).addClassName(		(NewClass == 'active' ? 'active' :'inactive'));
	
	$(LinkId).className
	if(NewClass == 'active')
		return false;
	else
		return true;
}

function ShowSubbranch(BranchId)
{
	if(	$(BranchId) == null)
	{
		return false;
	}
	else
	{
		//hide all other subs
		var BranchList = $('content_left').getElementsByTagName('ul');
		for(b =0; b < BranchList.length; b++)
		{
			if(BranchId != BranchList[b].id && 'subbranch' == BranchList[b].id.substring(0, 9))
			{
				HideSubbranch(BranchList[b]);
			}
		}		
		
		$(BranchId).style.display = 'block';
		$(BranchId).removeClassName ('active');
		$(BranchId).removeClassName ('inactive');
		$(BranchId).addClassName('subsubnav');
		return true;
	}
}

function HideSubbranch(BranchId)
{
	if(	$(BranchId) == null)
	{
		return false;
	}
	else
	{
		$(BranchId).style.display = '';
		$(BranchId).removeClassName ('subsubnav');
		$(BranchId).addClassName('inactive');

		var SubBranchLinkList = $(BranchId).getElementsByTagName('a');

		for (j = 0; j < SubBranchLinkList.length; j++)
		{
			SubBranchLinkList[j].className = 'inactive';
		}
		return true;
	}
}


function CollapseAllFilters()
{
	var BranchList = $('content_left').getElementsByTagName('ul');
	
	for ( var c =0; c < BranchList.length; c++)
	{
	   HideSubbranch(BranchList[c]);
	}
	return true;

}
