// Copyright (C) 2002-2004 WEBCOM a.s.
// All rights reserved.

//-------------------------------------------------------------------------------------------
// GLOBAL VARIABLES
//-------------------------------------------------------------------------------------------
var isMenuReady        = false;
var navigationBarCount = 0;
var activeTab          = "";
//-------------------------------------------------------------------------------------------
// CSS setings
//-------------------------------------------------------------------------------------------
// top level tabs
//----------------
var topTabBgcolor           = "#E60019";                          // Top level tab background color
var topTabBgcolorHover      = "#B5B5B5";                          // Active top level tab background color
var topTabBorderLeft        = "1px solid #E60019";                // Top level tab left border
var topTabBorderLeftHover   = "1px solid #B5B5B5";                // Active top level tab left border
var topTabBorderRight       = "1px solid #E60019";                // Top level tab right border
var topTabBorderRightHover  = "1px solid #B5B5B5";                // Active top level tab right border
var topTabBorderTop         = "1px solid #E60019";                // Top level tab top border
var topTabBorderTopHover    = "1px solid #B5B5B5";                // Active top level tab top border
var topTabBorderBottom      = "1px solid #E60019";                // Top level tab bottom border
var topTabBorderBottomHover = "1px solid #B5B5B5";                // Active top level tab bottom border
var topTabFamily            = "Tahoma, Arial, Verdana, Helvetica, sans-serif";   // Top level tab font family
var topTabFamilyHover       = "Tahoma, Arial, Verdana, Helvetica, sans-serif";   // Active top level tab font family
var topTabFontSize          = 11 +"px";                            // Top level tab font size
var topTabFontSizeHover     = 11 +"px";                            // Active top level tab font size
var topTabFontWeight        = 800;                                // Top level tab font weight
var topTabFontWeightHover   = 800;                                // Active top level tab font weight
var topTabFontColor         = "#FFFFFF";                          // Top level tab font color
var topTabFontColorHover    = "#FFFFFF";                          // Active top level tab font color
var topTabHeight			= 24;								  // Height of Tab Table
var topTabSpaceBetweenTabs	= 1;								  // Space between Tabs
var topTabSpaceColor		= "#E60019";						  // Color of Space between Tabs

var topTabPadding           = new Array(0, 0, 5, 5);              // Top level tab paddings (top, bottom, left, right)
// menu and menu links
//--------------------
var menuWidth				  = 150;
var menuLeftDistance		  = 0;								  // Distance of submenu left position 
var menuTopDistance			  = 1;								  // Distance of submenu top position 
var menuBorderLeft			  = "1px solid #B5B5B5";			  // Submenu left border style
var menuBorderRight			  = "1px solid #B5B5B5";			  // Submenu right border style
var menuBorderTop			  = "1px solid #B5B5B5";			  // Submenu top border style
var menuBorderBottom		  = "1px solid #B5B5B5";			  // Submenu bottom border style
var menuContainerStyle        = "border: 0px solid #B5B5B5";      // Border style of the menu link container
var menuLinkIconBgColor       = "#B5B5B5";                        // Background color of the menu icon column
var menuLinkFamily            = "Tahoma, Arial, Verdana, Helvetica, sans-serif"; // Menu link font family 
var menuLinkFamilyHover       = "Tahoma, Arial, Verdana, Helvetica, sans-serif"; // Active menu link font family 
var menuLinkFontWeight        = 800;                              // Menu link font weight
var menuLinkFontWeightHover   = 800;                              // Active menu link font weight
var menuLinkFontSize          = 11 +"px";                         // Menu link font size
var menuLinkFontSizeHover     = 11 +"px";                         // Active menu link font size
var menuLinkFontColor         = "#FFFFFF";                        // Menu link font color
var menuLinkFontColorHover    = "#FFFFFF";                        // Active menu link font color
var menuLinkBgcolor           = "#B5B5B5";						  // Menu link background color
var menuLinkBgcolorHover      = "#E60019";                        // Active menu link background color
var menuLinkDecoration        = "none";                           // Menu link text decoration
var menuLinkDecorationHover   = "none";                           // Active menu link text decoration
var menuLinkPadding           = new Array(4, 4, 8, 8);            // Menu link paddings (top, bottom, left, right)
var menuLinkBorderTop         = "0px solid B5B5B5";           // Menu link border top
var menuLinkBorderTopHover    = "0px solid B5B5B5";               // Active menu link border top
var menuLinkBorderBottom      = "0px solid B5B5B5";           // Menu link border bottom
var menuLinkBorderBottomHover = "0px solid B5B5B5";               // Active menu link border bottom
var menuLinkBorderLeft        = "0px";                            // Menu link border left
var menuLinkBorderLeftHover   = "0px";                            // Active menu link border left
var menuLinkBorderRight       = "0px";                            // Menu link border right
var menuLinkBorderRightHover  = "0px";                            // Active menu link border right
//-------------------------------------------------------------------------------------------
var menuLinkStyle             = "border-top: "+ menuLinkBorderTop +"; border-bottom: "+ menuLinkBorderBottom +"; border-left: "+ menuLinkBorderLeft +"; border-right: "+ menuLinkBorderRight +"; padding-top: "+ menuLinkPadding[0] +"; padding-bottom: "+ menuLinkPadding[1] +"; padding-left: "+ menuLinkPadding[2] +"; padding-right: "+ menuLinkPadding[3] +"; text-decoration: "+ menuLinkDecoration +"; font-weight: "+ menuLinkFontWeight +"; font-size: "+ menuLinkFontSize +"; color: "+ menuLinkFontColor +"; background-color: "+ menuLinkBgcolor +"; cursor: hand; position: relative; font-family: "+ menuLinkFamily +"; font-size: "+ menuLinkFontSize +";";
var strTopTabStyle            = "padding-top: "+ topTabPadding[0] +"; padding-bottom: "+ topTabPadding[1] +"; padding-left: "+ topTabPadding[2] +"; padding-right: "+ topTabPadding[3] +"; cursor: hand;background-color: "+ topTabBgcolor + "; border-left: "+ topTabBorderLeft +"; border-right: "+ topTabBorderRight +"; border-top: "+ topTabBorderTop +"; border-bottom: "+ topTabBorderBottom +"; font-family: "+ topTabFamily +"; font-size: "+ topTabFontSize +"; font-weight: "+ topTabFontWeight +"; color: "+ topTabFontColor;
//-------------------------------------------------------------------------------------------


function flipTopTab(tabId, hasSubmenu){
	var currnetTab = document.getElementById(tabId);
	//----------------------------------------------

	if(activeTab == "")
	{
		with(currnetTab.style)
		{
			backgroundColor = topTabBgcolorHover;
			
			borderLeft      = topTabBorderLeftHover;
			
			borderRight     = topTabBorderRightHover;
			
			borderTop       = topTabBorderTopHover;
			
			borderBottom    = topTabBorderBottomHover;
			
			fontFamily      = topTabFamilyHover;
			
			fontSize        = topTabFontSizeHover;
			
			color	        = topTabFontColorHover;
			
			fontWeight      = topTabFontWeightHover;
			
//			if(!hasSubmenu)
//			{
//				borderBottom    = topTabBorderTopHover;
//			}
//			else
//			{
//				borderBottom    = topTabBorderBottomHover;
//			}
			zIndex = 10;
		}
		activeTab = currnetTab;
	}
	else
	{
		if(activeTab != currnetTab)
		{
			with(activeTab.style)
			{
			
				backgroundColor  = topTabBgcolor;
				
				borderLeft       = topTabBorderLeft;
				
				borderRight      = topTabBorderRight;
				
				borderTop        = topTabBorderTop;
				
				borderBottom    = topTabBorderBottom;
				
				fontFamily      = topTabFamily;
				
				fontSize        = topTabFontSize;
				
				color	        = topTabFontColor;
				
				fontWeight      = topTabFontWeight;
				
				zIndex = 0;
				
			}	
			
			with(currnetTab.style)
			{
				backgroundColor = topTabBgcolorHover;

				borderLeft      = topTabBorderLeftHover;

				borderRight     = topTabBorderRightHover;

				borderTop       = topTabBorderTopHover;

				borderBottom    = topTabBorderBottomHover;

				fontFamily      = topTabFamilyHover;

				fontSize        = topTabFontSizeHover;

				color	        = topTabFontColorHover;

				fontWeight      = topTabFontWeightHover;
				
//				if(!hasSubmenu)
//				{
//					borderBottom    = topTabBorderTopHover;
//				}
//				else
//				{
//					borderBottom    = topTabBorderBottomHover;
//				}
				
				zIndex = 10;
			}	
			activeTab = currnetTab;
		}
	}
}

function deactiveTopTab()
{
	if(activeTab != "" && menuGuard.activeSubmenu == "")
	{
		with(activeTab.style)
		{
			backgroundColor  = topTabBgcolor;
			
			borderLeft       = topTabBorderLeft;
			
			borderRight      = topTabBorderRight;
			
			borderTop        = topTabBorderTop;
			
			borderBottom    = topTabBorderBottom;
			
			fontFamily      = topTabFamily;
			
			fontSize        = topTabFontSize;
			
			color	        = topTabFontColor;
			
			fontWeight      = topTabFontWeight;
			
			zIndex = 0;
		}	
		
		activeTab = "";
	}
}

function flipIconStyle(cellId, action)
{
	with(document.getElementById(cellId).style)
	{
		if(action == "active")
		{
			fontFamily      = menuLinkFamilyHover;
			
			fontWeight      = menuLinkFontWeightHover;
			
			fontSize        = menuLinkFontSizeHover;
			
			color           = menuLinkFontColorHover;
			
			backgroundColor = menuLinkBgcolorHover;
			
			textDecoration  = menuLinkDecorationHover;
			
			borderTop       = menuLinkBorderTopHover;
			
			borderBottom    = menuLinkBorderBottomHover;
			
			borderLeft      = menuLinkBorderLeftHover;
			
			borderRight     = menuLinkBorderRightHover;
		}
		else if(action == "deactive")
		{
			fontFamily      = menuLinkFamily;
			
			fontWeight      = menuLinkFontWeight;
			
			fontSize        = menuLinkFontSize;
			
			color           = menuLinkFontColor;
			
			backgroundColor = menuLinkBgcolor;
			
			textDecoration  = menuLinkDecoration;
			
			borderTop       = menuLinkBorderTop;
			
			borderBottom    = menuLinkBorderBottom;
			
			borderLeft      = menuLinkBorderLeft;
			
			borderRight     = menuLinkBorderRight;
		}
	}
}

//*******************
// OBJECT Navigation
//*******************
function Navigation(renderDirection){
	this.renderDirection    = renderDirection;		//horizontal or vertical
	this.topLevelTab        = new Array();
	this.tab                = new Array();
	this.tabCounter         = 0;
	this.topLevelTabCounter = 0;
	this.menu               = new Array;
	this.menCounter         = 0;
	//--------------------------------------
	
	// Method divides tabs to top level tabs and the other tabs and save them in to the array
	this.addTab = function(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon)
	{
		//tab is top level tab
		if(parentId == "")
		{
			this.topLevelTab[this.topLevelTabCounter] = new TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon);
			
			this.topLevelTabCounter ++;
		}
		//tab isn't top level tab
		else
		{
			this.tab[this.tabCounter] = new TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon);

			this.tabCounter ++;
		}
	}

	// Method creates top level tabs
	this.createTopLevelTabs = function()
	{
		var strOutpu = "";
		var isLocked = "";
		//----------------

		strOutpu += "<table cellpadding=0 cellspacing=0 border='0' height="+topTabHeight+"><tr>";
		
		for(i = 0; i < this.topLevelTabCounter; i ++)
		{
			// Tab isn't locked
			if(this.topLevelTab[i].isLocked == "False")
			{
				isLocked = "onClick='document.location = \""+ this.topLevelTab[i].linkValue +"\"'";
			}
			// Tab is locked
			else
			{
				isLocked = "";	
			}
			
			// space between menu items
			if(topTabSpaceBetweenTabs > 0 & i > 0)
				strOutpu += "<td width='"+topTabSpaceBetweenTabs+"' bgcolor='"+topTabSpaceColor+"'><img border='0' width='"+topTabSpaceBetweenTabs+"' src='"+appImagesRoot+"iReadyCommon_1x1_Transparent.gif'></td>";
			

			// current tab has some submenu
			if(this.topLevelTab[i].hasSubmenu)
			{
				//strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;<img src='"+appImagesRoot+"iReadyCommon_Tab_Arrow.gif' width=8 height=4 border=0></td>";
				//oldrem strOutpu += "<td nowrap style='"+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;<img src='"+appImagesRoot+"iReadyCommon_Tab_Arrow.gif' width=8 height=4 border=0></td>";
				strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
			}
			// current tab hasn't submenu
			else
			{
				strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
				//strOutpu += "<td nowrap style='"+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
			}
		}
		
		strOutpu += "</tr></table>";
		
		// open document, writes result and closes the document
		with(document)
		{
			open();
			
			write(strOutpu);
			
			close();
		}	
	}
	
	// Method creates menus
	this.createMenus = function()
	{
		var parentElement;
		var currentParent;
		var parentsCount   = 0
		var strOutpu       = "";
		var isLocked       = "";
		var isNextParent   = true;
		var oldParent      = new Array();
		//-------------------------------
		
		// for all non top level tabs
		for(i = 0; i < this.tabCounter; i ++)
		{
			currentParent = this.tab[i].parentId;
			
			// search for the tabs with the same parentId
			for(u = 0; u < parentsCount; u++)
			{
				if(parseInt(currentParent) == parseInt(oldParent[u]))
				{
					isNextParent = false;
				}
				else
				{
					isNextParent = true;
				}
			}
			
			// for the tabs with the same parentId renders html output (creates menu)
			if(isNextParent)
			{
				//strOutpu += "<table cellpadding=0 cellspacing=0 border=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden; border-left:"+menuBorderLeft+"; border-right:"+menuBorderRight+"; border-top:"+menuBorderTop+"; border-bottom:"+menuBorderBottom+"' width='160'><tr><td>";
				strOutpu += "<table cellpadding=0 cellspacing=0 border=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden; border-left:"+menuBorderLeft+"; border-right:"+menuBorderRight+"; border-top:"+menuBorderTop+"; border-bottom:"+menuBorderBottom+"'><tr><td>";

				//strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle +";width:160px'>";
				strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle +"'>";
				
				strOutpu += "<table cellpadding=0 cellspacing=0 border=0 width='100%'>";
				
				for(k = 0; k < this.tabCounter; k ++)
				{
					if(currentParent == this.tab[k].parentId)
					{
						// Tab isn't locked
						if(this.tab[k].isLocked == "False")
						{
							isLocked = "onClick='document.location=\""+ this.tab[k].linkValue +"\"'"
						}
						// Tab is locked
						else
						{
							isLocked = "";	
						}
						
						// Tab has icon
						if(this.tab[k].icon != "")
						{	
							icon = "<div style='padding: 2px'><img src='"+ this.tab[k].icon +"' width=14 height=14 border=0></div>"
						}
						// Tab hasn't icon
						else
						{
							//icon = "<div style='padding: 2px'><img src='images/m_dot.gif' width=14 height=14 border=0></div>";
							icon = "";
						}
						
						// Current tab has some submenu
						if(this.tab[k].hasSubmenu)
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/m_dot.gif' width=5 height=8 border=0><img src='images/arrow01.gif' width=4 height=8 border=0><img src='images/m_dot.gif' width=5 height=8 border=0></td></tr>";
							strOutpu += "<tr><td nowrap width='100%'><div onMouseOver='flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td></tr>";
						}
						// current tab hasn't submenu
						else
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/m_dot.gif' width=14 height=8 border=0></td></tr>";
							strOutpu += "<tr><td nowrap width='100%'><div onMouseOver='flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td></tr>";
						}
						
					}	
				}
				strOutpu += "</table>";
								
				strOutpu += "</div>";

				strOutpu += "</td></tr></table>";
				
				oldParent[parentsCount] = currentParent;

				parentsCount ++;
				
				for(a = 0; a < this.topLevelTab.length; a ++)
				{
					if(this.topLevelTab[a].id == currentParent)
					{
						parentElement = "topTab_"+ currentParent;
						
						break;
					}
					else
					{
						parentElement = "tab_"+ currentParent;
					}
				}

				this.menu[this.menCounter] = new Menu("menu_"+ currentParent, parentElement);

				this.menCounter ++;
			}	
		}
		
		// open document, writes result and closes the document
		with(document)
		{
			open();

			write(strOutpu);

			close();
		}	
	}
	
	// Method recalculate positions of all menu objects when event onResize or onLoad of the BODY element is catched
	this.recalculatePositions = function()
	{
		// for each menu objects calculate absolute position in the document
		for(r = 0; r < this.menu.length; r++)
		{
			positionMenus(this.menu[r]);
		}
	}
}

function positionMenus(objMenu)
{
	var objParentEl	    = document.getElementById(objMenu.parentId);    // parent object of the menu ... object(link) which opens and closes this menu
	var objCurrentMenu  = document.getElementById(objMenu.id);          // object which represents menu
	var objParentMenu;                                                  // object which represents parent menu. parent menu contains parent object(link) which opens the submenu
	var numParentTop    = parseInt(objParentEl.offsetTop);
	var numParentLeft   = parseInt(objParentEl.offsetLeft);
	var numParentWidth  = parseInt(objParentEl.offsetWidth);
	var numParentHeight = parseInt(objParentEl.offsetHeight);
	var strParentId     = objMenu.parentId;                             // parent object(link) id ... object which opens the submenu
	var isTopLevelTab   = false;
	var clientWidth     = document.body.clientWidth;
	var clientHeight    = document.body.clientHeight;
	//-------------------------------------------------------------

	// true = top bar tab, false = every other tabs
	isTopLevelTab = (strParentId.indexOf("topTab") != -1) ? true : false;
	
	with(objCurrentMenu.style)
	{
		// sets position of each menu
		// top bar tab
		if(isTopLevelTab)
		{
			top  = numParentTop + numParentHeight + menuTopDistance +"px";
			left = numParentLeft + menuLeftDistance +"px";
		}
		// other tabs
		else
		{
			objParentMenu = objParentEl.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode

			if(objParentMenu.offsetTop + numParentTop > clientHeight)
			{
				top  = objParentMenu.offsetTop - objParentEl.parentNode.offsetTop + "px";
			}
			else
			{
				top  = objParentMenu.offsetTop + objParentEl.parentNode.offsetTop + "px";
			}
			
			if(objParentMenu.offsetLeft + objParentMenu.offsetWidth + objParentMenu.offsetWidth > clientWidth)
			{
				left = objParentMenu.offsetLeft - objParentMenu.offsetWidth + 10 +"px";
			}
			else
			{
				left = objParentMenu.offsetLeft + objParentMenu.offsetWidth - 10 +"px";
			}	
		}	
	}
}

function MainMenuOverlaps(o1,o2)
{
	/*var o1x1=o1.offsetLeft;
	var o1y1=o1.offsetTop;
	var o1x2=o1.offsetLeft+o1.offsetWidth;
	var o1y2=o1.offsetTop+o1.offsetHeight;
	var o2x1=o2.offsetLeft;
	var o2y1=o2.offsetTop;
	var o2x2=o2.offsetLeft+o2.offsetWidth;
	var o2y2=o2.offsetTop+o2.offsetHeight;*/


	var o1x1=GetOffsetLeft(o1);
	var o1y1=GetOffsetTop(o1);
	var o1x2=o1x1+GetOffsetWidth(o1);
	var o1y2=o1y1+GetOffsetHeight(o1);

	var o2x1=GetOffsetLeft(o2);
	var o2y1=GetOffsetTop(o2);
	var o2x2=o2x1+GetOffsetWidth(o2);
	var o2y2=o2y1+GetOffsetHeight(o2);


	//alert(o1x1+"-"+o1y1+":"+o1x2+"-"+o1y1+":"+o1x1+"-"+o1y2+":"+o1x2+"-"+o1y2);

	if ((o1x1 <= o2x1) && (o1x2 >= o2x1) && (o1y1<=o2y1) && (o1y2>=o2y1)||
	(o1x1 <= o2x2) && (o1x2 >= o2x2) && (o1y1<=o2y1) && (o1y2>=o2y1)||
	(o1x1 <= o2x1) && (o1x2 >= o2x1) && (o1y1<=o2y2) && (o1y2>=o2y2)||
	(o1x1 <= o2x2) && (o1x2 >= o2x2) && (o1y1<=o2y2) && (o1y2>=o2y2)||
	(o1x1 <= o2x1) && (o1x2 >= o2x2) && (o1y1>=o2y1) && (o1y2>=o1y2)
)
		return true;
	else
		return false;
}

function HideControlsMenu(tagName,menuId)
{
	if (menuId!=null)
	{
		var menu=document.getElementById(menuId);
		var objekty=document.getElementsByTagName(tagName);


		
		//alert(left);
	
		if(menu!=null)
			for(i=0;i<objekty.length;i++)
			{
				
				//alert(GetOffsetLeft(objekty[i])+"-"+GetOffsetTop(objekty[i])+"-"+GetOffsetWidth(objekty[i])+"-"+GetOffsetHeight(objekty[i]));

				if (MainMenuOverlaps(objekty[i],menu) || MainMenuOverlaps(menu,objekty[i]))  
					objekty[i].style.visibility="hidden";
			}
	}
}



function GetOffsetLeft(obj)
{

	var left=0;
	while (obj.offsetParent!=null)
	{
		left=left+obj.offsetLeft;
		obj=obj.offsetParent;
	
	}

return left;
}


function GetOffsetTop(obj)
{

	var top=0;
	while (obj.offsetParent!=null)
	{
		top=top+obj.offsetTop;
		obj=obj.offsetParent;
	
	}

return top;
}


function GetOffsetWidth(obj)
{

	return obj.offsetWidth;
}

function GetOffsetHeight(obj)
{

	return obj.offsetHeight;
}



function openMenu(menuId, parentMenuId){
	var objMmenuToOpen  = eval("document.getElementById('"+ menuId +"')");        // object menu to open
	var objMpenFromMenu = eval("document.getElementById('"+ parentMenuId +"')");  // object menu from which will be opened submenu
	var activeMenu;
	var openFromMenu    = "";                                                     // id of object menu to open
	var menuToOpen      = "";                                                     // id of object menu from which will be opened submenu
	//---------------------------------------------------------------------------
	
	colapseAll2();

	if(!isMenuReady)
	{
		return;
	}
	
if (navigator.appName=="Microsoft Internet Explorer")
{
	if (parentMenuId==null)
		ShowControlsMenu("select");

	if (parentMenuId==null)
		HideControlsMenu("select",menuId);
}
	openFromMenu = (objMpenFromMenu) ? objMpenFromMenu.id : "";
	
	menuToOpen   = (objMmenuToOpen) ? objMmenuToOpen.id : "";
	
	// open demand menu which is not submenu
	if(openFromMenu == "")
	{
		// if function receive some menu object to open
		if(menuToOpen != "")
		{
			// if there is not other menu opened
			if(menuGuard.getSelectedMenu() == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addSelectedMenu(objMmenuToOpen);
				
				menuGuard.addActiveSubMenu(menuToOpen, "xxx");
			}
			// if some other menu is opened
			else
			{
				// if some submenu is opened
				if(menuGuard.activeSubmenu != "")
				{
					document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					
					menuGuard.closeSubMenuChain((openFromMenu));
				}
				menuGuard.activeSubmenu = "";
				
				activeMenu = menuGuard.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addSelectedMenu(objMmenuToOpen);
				
				menuGuard.addActiveSubMenu(menuToOpen, "xxx");
			}
		}
		// if function doesn't receive some menu object to open
		else
		{
			// if some other menu is opened
			if(menuGuard.getSelectedMenu() != "")
			{
				activeMenu = menuGuard.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				menuGuard.closeSubMenuChain((openFromMenu));
				
				menuGuard.activeSubmenu = "";
			}
		}
	}
	// open demand submenu
	else
	{
		// if function receive some menu object to open
		if(menuToOpen != "")
		{
			// if there is not other submenu opened
			if(menuGuard.activeSubmenu == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addActiveSubMenu(menuToOpen, openFromMenu);
			}
			else
			{
				if(openFromMenu == menuGuard.activeSubmenu.parentId)
				{
					if(menuGuard.activeSubmenu.parentId != "xxx")
					{
						document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					}	
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
				else if(openFromMenu == menuGuard.activeSubmenu.id)
				{
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.addActiveSubMenu(menuToOpen, openFromMenu);
				}
				else
				{
					menuGuard.closeSubMenuChain(openFromMenu);
					
					document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
			}
		}
		// if some other menu is opened
		else
		{
			if(openFromMenu == menuGuard.activeSubmenu.parentId)
			{
				document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
				
				menuGuard.closeLastSubMenu();
			}	
		}	
	}
}


function ShowControlsMenu(tagName)
{
	var objekty=document.getElementsByTagName(tagName);
	for(i=0;i<objekty.length;i++)
	{
		objekty[i].style.visibility="visible";
	}
}


// Function closes all open menus and its submenus
function colapseAll()
{
if (navigator.appName=="Microsoft Internet Explorer")
{
	ShowControlsMenu("select");
}
	if(menuGuard.activeSubmenu != "")
	{
		document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
		
		menuGuard.closeSubMenuChain((menuGuard.activeSubmenu.id));
		
		menuGuard.activeSubmenu = "";
	}
	if(activeTab != "")
	{
		with(activeTab.style)
		{
			backgroundColor  = topTabBgcolor;
			
			borderLeft       = topTabBorderLeft;
			
			borderRight      = topTabBorderRight;
			
			borderTop        = topTabBorderTop;
			
			borderBottom    = topTabBorderBottom;
			
			fontFamily      = topTabFamily;
			
			fontSize        = topTabFontSize;
			
			color	        = topTabFontColor;
			
			fontWeight      = topTabFontWeight;
			
			zIndex          = 0;
		}	
		
		activeTab = "";
	}
}

//*******************
// OBJECT MenuGuard
//*******************
function MenuGuard(){
	this.openMenu       = "";
	this.selectedItem   = "";
	this.openFromMenu   = "";
	this.activeSubMenu  = new Array();
	this.submenuCounter = 0;
	this.activeSubmenu  = "";
	//--------------------------------
	
	this.closeSubMenuChain = function(openFromMenu)
	{
		for (i = this.submenuCounter -1; i >= 0; i--)
		{
			if(this.activeSubMenu[i].parentId != openFromMenu)
			{
				document.getElementById(this.activeSubMenu[i].id).style.visibility = "hidden";
			}
			else
			{
				break;
			}
		}
		this.submenuCounter = i + 1;
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.closeLastSubMenu = function()
	{
		this.submenuCounter--;
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.replaceLastSubMenu = function(menuId, openFromMenu)
	{
		this.activeSubMenu[this.submenuCounter - 1] = new Menu(menuId, openFromMenu);
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.addActiveSubMenu = function(menuId, openFromMenu)
	{
		this.activeSubMenu[this.submenuCounter] = new Menu(menuId, openFromMenu);
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter];
		
		this.submenuCounter++;
	}
	
	this.addSelectedMenu = function(menuName)
	{
		this.openMenu = menuName;
	}
	
	this.removeSelectedMenu = function()
	{
		this.openMenu = "";
	}
	
	this.getSelectedMenu = function()
	{
		return this.openMenu;
	}
	
	this.addOpenFromMenu = function(menuName)
	{
		this.openFromMenu = menuName;
	}
	
	this.removeOpenFromMenu = function()
	{
		this.openFromMenu = "";
	}
	
	this.getOpenFromMenu = function()
	{
		return this.openFromMenu;
	}
}

var menuGuard = new MenuGuard();


//*******************
// OBJECT Menu
//*******************
function Menu(id, parentId){
	this.id       = id;
	this.parentId = parentId;
}


//*******************
// OBJECT TabObject
//*******************
function TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon){
	this.id         = id;
	this.parentId   = parentId;
	this.caption    = caption;
	this.linkType   = linkType;
	this.linkValue  = linkValue;
	this.isLocked   = isLocked;
	this.hasSubmenu = hasSubmenu;
	this.icon       = icon;
}
