var Delay=300;

var OnBrdColor='#000080';
var OnBckColor='#FFEEC2';
var OnTxtColor='#000000';
var GrayedColor='#6A6A6A';

var MaxChildDiv=10;
var TCorr=-1;
var brTCorr=0;
var BCorr=1;
var brBCorr=0;
var LCorr=-1;
var RCorr=1;

var ieCorr=0;

var ShowTimer=0;
var ShowChildPos;
var ShowChildDiv;

var HideTimer=0;
var HideChildDiv;

var StackTimer=0;
var Entry=new Array(MaxChildDiv+1);
var ChildDiv=new Array(MaxChildDiv);
var ParentEntry=new Array(MaxChildDiv);

var PreviousNav=null;
var PreviousEntry=null;

var CurrentDiv=null;
var ChildDivCounter=-1;
var CurrentLevel=-1;

var CurrentEntry;
var CurrentHref=null;
var CurrentTarget=null;
var CurrentLeft;
var CurrentRight;
var CurrentTop;
var CurrentBottom;

function Open_Entry(Item, ChildDiv, Pos)
{
	CurrentLevel=GetCurrentDivision(Item);
	CurrentEntry=Item;
	Current=Href();
	Borders(Current);
	
	if (ChildDiv) {
		if (HideTimer && ChildDiv==HideChildDiv) {
			window.clearTimeout(HideTimer); 
			HideTimer=0;
		}
		else if (!ShowTimer) { 
			if (Pos) {
				ShowChildPos=Pos.toUpperCase()
			}
			else {
				ShowChildPos='B';
			}
			if (ShowChildPos!='L' && ShowChildPos!='R' && ShowChildPos!='T' && ShowChildPos!='B') {
				ShowChildPos='B';
			}
			ShowChildDiv=ChildDiv;
			if (!StackTimer && !HideTimer) {
				Show_ChildDiv();
			}
			else {
				ShowTimer=window.setTimeout('Show_ChildDiv()',Delay);
			}
		}
	}
}

function Close_Entry(Item, ChildDiv)
{
	CurrentDiv=null;
	CurrentEntry=null;
	if (ChildDiv) {
		if (ShowTimer && ChildDiv==ShowChildDiv) {
			window.clearTimeout(ShowTimer); 
			ShowTimer=0;
			ShowChildDiv=null;
		}
		else if (!HideTimer) {
			HideChildDiv=ChildDiv;		
			HideTimer=window.setTimeout('Hide_ChildDiv()',Delay);
		}
	}
	if (StackTimer) {
		window.clearTimeout(StackTimer); 
	}
	StackTimer=window.setTimeout('Clear_Stack()',Delay);
}

function Show_ChildDiv()
{
	if (ShowChildDiv!=CurrentDiv) {
		ChildDivObject=document.getElementById(ShowChildDiv);
	 	if (ChildDivObject.style.visibility=="hidden") {
			ChildDivCounter++;
			ChildDiv[ChildDivCounter]=ShowChildDiv;
			ParentEntry[ChildDivCounter]=CurrentEntry;
			PositionAndSize();
			ChildMenuTable=ChildDivObject.getElementsByTagName("Table")[0];
			DivWidth=ChildMenuTable.offsetWidth;
			DivHeigth=ChildMenuTable.offsetHeight;
			if (ShowChildPos=='L') {
				LeftPos=CurrentLeft-DivWidth+LCorr+ieCorr;
				TopPos=CurrentTop;
			}
			else if (ShowChildPos=='R'){
				LeftPos=CurrentRight+RCorr+ieCorr;
				TopPos=CurrentTop;
			}
			else if (ShowChildPos=='T') {
				LeftPos=CurrentLeft;
				TopPos=CurrentTop-DivHeigth+TCorr+brTCorr+ieCorr;
			}
			else {
				LeftPos=CurrentLeft;
				TopPos=CurrentBottom+BCorr+brBCorr+ieCorr;
			}
			ChildDivObject.style.left=LeftPos;
			ChildDivObject.style.top=TopPos;
			ChildDivObject.style.zIndex=CurrentLevel+1000;
			HrefColors(ChildDivObject);			
			ChildDivObject.style.width=DivWidth;
			ChildDivObject.style.height=DivHeigth;			
		 	ChildDivObject.style.visibility="visible"; 
		 }
	}
	ShowChildDiv=null;
 	ShowTimer=0;
}

function Hide_ChildDiv()
{
	if (HideChildDiv!=CurrentDiv) {
		ChildDivObject=document.getElementById(HideChildDiv);
	 	if (ChildDivObject.style.visibility=="visible") {
			ChildDiv[ChildDivCounter]=null;
			ChildDivCounter--;
		 	ChildDivObject.style.visibility="hidden"; 
		 }
	}
	HideChildDiv=null;
 	HideTimer=0;
}

function Clear_Stack()
{
	for (i=ChildDivCounter; i>=0 && ChildDiv[i]!=CurrentDiv && ChildDiv[i]!=ShowChildDiv && ChildDiv[i]!=HideChildDiv; i--) {
		if (ChildDiv[i]) {
			ChildDivObject=document.getElementById(ChildDiv[i]);
		 	if (ChildDivObject.style.visibility=="visible") {
				if (Entry[i+1]) {
					Border_Off(Entry[i+1]);
				}
				ChildDiv[i]=null;
			 	ChildDivObject.style.visibility="hidden"; 
			 } 
		}
	}
	ChildDivCounter=i;
	StackTimer=0;
	if (!CurrentEntry && Entry[0]) {
		Border_Off(Entry[0]);
	}
}

function Href()
{
	InCurrent=false;
	if (CurrentEntry!=PreviousEntry) {
		PreviousEntry=CurrentEntry;
		crow=CurrentEntry.parentNode.rowIndex;
		ccol=CurrentEntry.cellIndex;
		if (NavEntry=GetNavEntry(CurrentDiv, crow, ccol)) {
			CurrentHref=NavEntry.href;
			CurrentTarget=NavEntry.target;
			window.status=CurrentHref;
		}
		else {
			CurrentHref=null;
			CurrentTarget=null;
			window.status="";
		}
	} 
	if (CurrentHref) {
		CurrentEntry.style.cursor='pointer';
		if (document.URL.toUpperCase()==CurrentHref.toUpperCase()) {
			InCurrent=true;	
		}
	}
	else {
		CurrentEntry.style.cursor='default';
	}
	return(InCurrent);
}

function GetNavEntry(Division, Row, Col) 
{
	NavEntry=null;
	if (NavDiv=document.getElementById(Division+"Nav")) {
		if (NavTable=NavDiv.getElementsByTagName("Table")[0]) {
			if (NavList=NavTable.rows[Row].cells[Col]) { 
				NavEntry=NavList.getElementsByTagName("A")[0];
			}
		}
	}
	return (NavEntry);
}

function HrefColors(Division)
{
	if (Division!=PreviousNav) {
		PreviousNav=Division;
		MenuTable=Division.getElementsByTagName("Table")[1];
		CurrentURL=document.URL.toUpperCase();
		for (i=0; i<MenuTable.rows.length; i++) {
			for (j=0; j<MenuTable.rows[i].cells.length; j++) {
				NavEntry=GetNavEntry(Division.id,i,j);
				if (NavEntry && CurrentURL==NavEntry.href.toUpperCase()) {
					Color=GrayedColor;
				}
				else {
					Color='';
				}	
				Content=MenuTable.rows[i].cells[j].getElementsByTagName("TD");
				for (t=0; t<Content.length; t++) {
					Content[t].style.color=Color;
				}
			}
		}	
	}
}

function GetCurrentDivision(Object)
{
	Level=-1;
	ieCorr=0;
	Container=Object;

	while(Container.tagName.toUpperCase()!="DIV" && Container.tagName.toUpperCase()!="BODY"){
		Container=Container.parentNode;
	}
	if (Container.tagName.toUpperCase()=="DIV") {
		CurrentDiv=Container.id;
		for (i=ChildDivCounter; i>=0  && ChildDiv[i]!=CurrentDiv ; i--);
		Level=i+1;
		if (Container.style.position=='relative' && navigator.appName=="Microsoft Internet Explorer") {
			ieCorr=1;	
		}
		Colors(Container);
	}
	BackTable=Container.getElementsByTagName("Table")[0];
	if (BackTable.className=="xpbrback") {
		brTCorr=+2;
		brBCorr=-2;
	}
	return (Level);
}

function Borders (Current)
{
	if (Entry[CurrentLevel+1]) {
		Border_Off(Entry[CurrentLevel+1]);	
	}
	if (Entry[CurrentLevel] && Entry[CurrentLevel]!=CurrentEntry) {
		Border_Off(Entry[CurrentLevel]);	
	}
	for (i=CurrentLevel-1; i>=0; i--) {
		if (ParentEntry[i] != Entry[i]) {
			Border_Off(Entry[i]);	
			Entry[i]=ParentEntry[i];
		}	
		Border_On(ParentEntry[i], null);
	}
	if (CurrentEntry.className.toLowerCase()!="xpmnsepar") {
		Entry[CurrentLevel]=CurrentEntry;	
		Border_On(CurrentEntry, Current);	
	}
}

function Border_On(Item, Current)
{
	if (Current)
		Item.style.borderStyle='dashed'; 
	else
		Item.style.borderStyle='solid'; 
	Item.style.borderColor=OnBrdColor;
	if (Item.className.toLowerCase()=='xpmnentry') {	
		Item.style.paddingTop='2'; 			
		Item.style.borderTopWidth='1px'; 
		Item.style.paddingRight='2'; 			
		Item.style.borderRightWidth='1px'; 
		Item.style.paddingBottom='2'; 
		Item.style.borderBottomWidth='1px'; 
		Item.style.paddingLeft='2'; 			
		Item.style.borderLeftWidth='1px'; 
	}
	Item.style.backgroundColor=OnBckColor;
	Content=Item.getElementsByTagName("TD");
	for (t=0; t<Content.length; t++) {
		if (Content[t].style.color=='')
			Content[t].style.color=OnTxtColor;
	}
}

function Border_Off(Item) 
{
	Item.style.backgroundColor='';
	if (Item.className.toLowerCase()=='xpmnentry') {
		Item.style.borderStyle='None'; 
		Item.style.paddingTop='3'; 			
		Item.style.paddingRight='3'; 			
		Item.style.paddingBottom='3'; 
		Item.style.paddingLeft='3'; 			
	}
	else {
		Item.style.borderColor='#FFFFFF';
	}
	Content=Item.getElementsByTagName("TD");
	for (t=0; t<Content.length; t++) {
		if (Content[t].style.color==OnTxtColor.toLowerCase())	
			Content[t].style.color='';
	}
}

function Navigate_Menu()
{
	if (!CurrentHref) { return;	}
	
	if (!CurrentTarget) {
     	if (BaseTarget=document.getElementsByTagName("base")) {
			if (BaseTarget[0]) {
				CurrentTarget=BaseTarget[0].target;	
			}
		}
	}
	if (!CurrentTarget || CurrentTarget=="_self")
		TargetWindow=window;
	else if (CurrentTarget=="_blank")
		TargetWindow=window.open();
	else if (CurrentTarget=="_top")
		TargetWindow=top;
	else if (CurrentTarget=="_parent") 
		TargetWindow=parent;
	else if (top.frames.length) {
		for (i=0; i<top.frames.length && top.frames[i].name!=CurrentTarget; i++);
		if (i<top.frames.length) {
			TargetWindow=top.frames[i];
		}
		else {
			TargetWindow=window.open();
		}
	}
	else {
		TargetWindow=window.open();
	}
	TargetWindow.location=CurrentHref;
}

function PositionAndSize()
{
	CurrentLeft=0;
	CurrentTop=0;
	Container=CurrentEntry;
	while(Container.tagName.toUpperCase()!="BODY"){
		Count=true;		
		if(Container.tagName.toUpperCase()=="DIV"){
			if (Container.id!=CurrentDiv) {
				Count=false;
			}
		}
		if (Count){
	    	CurrentLeft+=Container.offsetLeft;
			CurrentTop+=Container.offsetTop;
		}
		Container=Container.offsetParent;

	}
	CurrentRight=CurrentLeft+CurrentEntry.offsetWidth;
	CurrentBottom=CurrentTop+CurrentEntry.offsetHeight;
}

function Colors(Division)
{
	if (ColDiv=document.getElementById(Division.id+"Col")) {
		if (ColTable=ColDiv.getElementsByTagName("Table")[0]) {
			if (ColTable.rows.length>=4) {
				if (ColTable.rows[0].cells[0].bgColor!="") {
					OnBrdColor=ColTable.rows[0].cells[0].bgColor;
				}
				if (ColTable.rows[1].cells[0].bgColor!="") {
					OnBckColor=ColTable.rows[1].cells[0].bgColor;
				}
				if (ColTable.rows[2].cells[0].bgColor!="") {
					OnTxtColor=ColTable.rows[2].cells[0].bgColor;
				}
				if (ColTable.rows[3].cells[0].bgColor!="") {
					GrayedColor=ColTable.rows[3].cells[0].bgColor;
				}
			}
		}
	}
}

function Init_Menu()
{
	var i=Init_Menu.arguments.length-1;
	if (i>=0) {
		Delay=Init_Menu.arguments[i--];

	}
	while (i>=0) {
		DivisionID=Init_Menu.arguments[i--];
	  	if (Division=document.getElementById(DivisionID)) {
			Division.style.zIndex=1000;
			Colors(Division);
			HrefColors(Division);			
			MenuTable=Division.getElementsByTagName("Table")[0];
			Division.style.width=MenuTable.offsetWidth;
			Division.style.height=MenuTable.offsetHeight;
		 	Division.style.visibility="visible"; 
		}
	}
}
