var BTS_BaseStep=15;
var BTS_P = new Array();
var BTS_T = BTS_BaseStep;
var BTS_mnuTimer=setTimeout("AttemptHide()",100);
var BTS_LTP = -1;
var BTS_MC = 0;
var BTS_newsItem=Math.floor(Math.random()*6)+1;

function getObj(a)
{
	if (document.getElementById)
		return document.getElementById(a)
	else if (document.getElementsByName)
		return document.getElementsByName(a)
	else if (document.all)
		return document.all[a]
	else if (document.layers)
		return document.layers[a]
}

function show(obj)
{	if (obj!=null)
		{obj.style.visibility='visible'; obj.style.height='auto';}
}

function hide(obj)
{	if (obj!=null)
		{obj.style.visibility='hidden';	obj.style.height='0';}
}

function showAllObj(objs)
{	
	var i=0;
	if (objs!=null)
	{
		show(objs);
		for (i=0; i<=objs.length ;i++)
			show(objs[i]);
	}
}

function showAll(obj)
{	
	var objs = getObj(obj);
	if (objs!=null)
	{	show(objs);
		showAllObj(objs);
	}
}

function hideAll(obj)
{	
	var objs = getObj(obj);
	
	var i=0;
	if (objs!=null)
	{
		hide(objs);
		for (i=0; i<=objs.length ;i++)
			hide(objs[i]);
	}
}

function initPage()
{
	showAll("ShowMe");
	hideAll("HideMe");
}

function HideAllNews()
{
	for (var i=0;i<=6;i++)
		hideAll('newsFlash'+i);
}

function BTSShowNews()
{
	var objs=null;
	var finish = false;
	while (!finish)
	{
		BTS_newsItem=BTS_newsItem+1;
		if (BTS_newsItem>6) BTS_newsItem=1;
		objs=getObj('newsFlash'+BTS_newsItem);
		if (objs==null)
			finish=false;
		else if (objs.length==0)
			finish=false;
		else
			finish=true;
	}
	
	HideAllNews();
	showAllObj(objs);
	
	var q=setTimeout("BTSShowNews()",5000);
}


function getParent(thisPID)
{
	var i = 0;
	var found=0;
	while (found==0 && i<=Menu[1].length)
	{	if (Menu[0][i]==thisPID)
			found=1;
		else
		i++;
	}
	if (found==1)
		return Menu[1][i]
	else
		return -1;
}

function FirstDescendant(thisPID,rootPID)
{
	if (thisPID<0 || thisPID==rootPID) 
		return true
	else 
	{
		var parent=getParent(thisPID)
		if (parent==rootPID)
			return true
		else
			return false;
	}
}

function AnyDescendant(thisPID,rootPID)
{
	var result=false;
	
	if (thisPID>-1)
	{
		if (thisPID==rootPID) 
			result=true
		else 
			result=AnyDescendant(getParent(thisPID),rootPID);
	}
	return result;
}

function AttemptHide(pid)
{
	ActualHideMenus();
	var BTS_mnuTimer=setTimeout("AttemptHide()",100);
}

function ActualHideMenus(forced)
{
	BTS_T=BTS_T-1;
	
	if ((BTS_MC == 0 && BTS_T==0)||forced==1)
		ActualHideMenu(BTS_LTP);	
}

function HideMenu()
{
	BTS_MC--;
	BTS_T=BTS_BaseStep;
}

function Delay()
{
	BTS_T=BTS_BaseStep;
}

function ActualHideMenu(pid)
{
	var top=getTopPID(pid,pid);
	var strObjName='BTSMnu'+top;
	var theMenu=getObj(strObjName);
	showChildNodes(pid,0,theMenu,0);
	BTS_LTP = -1;
}

function getPID(e)
{
	if (e.tagName=="A")
		return getFromName('BTSMna',e.id)
	else
		return getFromName('BTSMnu',e.id)
}



function getLevel(strClass)
{
	return getFromName('LEVEL',strClass)
}

function getFromName(strToken,strValue)
{
	if (strValue!=undefined)
	{
		var lAt = strValue.indexOf(strToken);
		if (lAt>-1)
		{
			lAt=lAt+strToken.length;
			var lEnd = strValue.indexOf(' ',lAt);
			if (lEnd<=lAt)
				return strValue.substring(lAt,strValue.length);		
			else
				return strValue.substring(lAt,lEnd);		
		}
		else
			return -1;
	}
	else
		return -2;
		
}

function showChildNodes(pid,pidLevel,element,showMode)
{
	if (element!=undefined)
	{	
		if (element.className=="BTSDDHolder")
			element.style.border="1px solid white";
					
		if (element.length!=undefined)
		{
			var el = element.length;
			for(var i=0;i<=el;i++)
				showChildNodes(pid,pidLevel,element[i],showMode);					
		}
		if (element.hasChildNodes!=undefined)
		{
			if (element.hasChildNodes())
			{
				el=element.childNodes.length;
				for(var j=0;j<=el;j++)
					showChildNodes(pid,pidLevel,element.childNodes[j],showMode);
			}
		}	

		if (element.className!=undefined)
		{
			if (element.style!=undefined)
			{
				if (element.style.visibility!=undefined)
				{
					var thisPID=getPID(element);
					var l = getLevel(element.className);
					//Immediate next level
					var isDescendant=FirstDescendant(thisPID,pid);
					//Ancestors
					var isDescendant2=AnyDescendant(pid,thisPID);
					//Siblings
					var isDescendant3=AnyDescendant(pid,getParent(thisPID));
										
					if (showMode==1 && (isDescendant || isDescendant2 || isDescendant3 ))		
					{
						if (element.style.visibility!="visible")
						{	element.style.visibility="visible";
							element.style.height="auto";
							element.style.lineHeight="normal";
						}
					}
					else 
					{
						if (element.style.visibility!="hidden" && showMode==0)
						{	element.style.visibility="hidden";
							element.style.height="0";
							element.style.lineHeight="0";
						}
							
					}
				}			
			}
		}		
	}
}

function getMenuLevelTrue(pid,initialLevel)
{
	var i = 0;
	var exit = 0;
	while (i<=Menu[1].length && exit==0)
	{	if (Menu[0][i]==pid)
		{
			if (Menu[1][i]==-1)
				return initialLevel
			else
				return getMenuLevelTrue(Menu[1][i],initialLevel+1);
			exit=1;
		}
		else
			i=i+1;
	}
}

function getTopPID(pid,lastpid)
{
	var i = 0;
	var exit = 0;
	var result=-1;
	while (i<=Menu[1].length && exit==0)
	{	if (Menu[0][i]==pid)
		{
			if (Menu[1][i]==-1)
				result= lastpid
			else
				result= getTopPID(Menu[1][i],pid);
			exit=1;
		}
		else
			i=i+1;
	}
	return result;
}

function showMenu(pid)
{
	BTS_MC++;
	var lev=getMenuLevelTrue(pid,0);
	var top=getTopPID(pid,pid);
	if (BTS_LTP!=top)
		ActualHideMenus(1);
	
	var strObjName='BTSMnu'+top;
	var theMenu=getObj(strObjName);

	if (pid!=BTS_LTP)
		showChildNodes(pid,lev,theMenu,1);
	BTS_LTP=top;
	
}

