//document.write("<textarea id=JFT rows=10 cols=100></textarea>");
function setJFT(p_Str){
	var l_Obj = document.getElementById("JFT");
	l_Obj.value = l_Obj.value + " - " +  p_Str;
	//document.all.JFT.value = document.all.JFT.value + " - " +  p_Str;
}

/*------------------------------------------------------------------
 File:			menu.js
 Use:			Collection of clients functions
				that used for interface of the menu bar.
-------------------------------------------------------------------*/

var g_MenuMainObj;
var g_TheHeighterDiv = 0;
var g_menuDirection = "rtl";
document.write("<iframe id='MenuIframeHelper' rc='include/blank.htm' frameBorder=0 height=0 width=0 scrolling='no' style='position:absolute;top:0px;left:0px;filter: alpha(Opacity=0);display:none;z-index:98'></iframe>");

var currentMenu; //The last sub menu that open.

/*-----------------------------------------------------------------
	Calculate the top position of the object.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The object
------------------------------------------------------------------*/

function offsetTop(obj)
{
	var top = 0;
	for (; obj; obj=obj.offsetParent)
	{
		top = top + obj.offsetTop;
	}
	return(top);
}

function getHeighterDiv(obj)
{
	var top = 0;
	var l_Height = 0;
	for (; obj; obj=obj.offsetParent)
	{
		if(obj.offsetTop <= offsetTop(g_mainParentMenu))
			break;
		top = top + obj.offsetTop;
		l_Height = top + obj.clientHeight;
		if(g_TheHeighterDiv < l_Height)
			g_TheHeighterDiv = l_Height;
	}
	return(g_TheHeighterDiv-offsetTop(g_mainParentMenu));
}



/*-----------------------------------------------------------------
	Calculate the left position of the object.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The object
------------------------------------------------------------------*/
function offsetLeft(obj)
{
	var left = 0;
	
	for (; obj; obj=obj.offsetParent)
	{
		if (obj.tagName == "BODY") break;
		left = left + obj.offsetLeft;
	}
	return(left);
}

//Iframe that been located under the div
function setIframeHelper(p_W, p_H, p_T, p_L, p_BlockOrNone){
	//var IframeObj = document.all.MenuIframeHelper;
	var IframeObj = document.getElementById("MenuIframeHelper");
	
	IframeObj.style.width = p_W;
	IframeObj.style.height = p_H;
	
	IframeObj.style.top = p_T;
	IframeObj.style.left = p_L;
	IframeObj.style.display = p_BlockOrNone;
}		
		
function calcDivsWidth(p_Obj){
	var l_ObjLeft = offsetLeft(g_MenuMainObj);
	if(g_menuDirection == "rtl"){
		//setJFT((offsetLeft(g_mainParentMenu)+g_mainParentMenu.clientWidth) - offsetLeft(p_Obj));
		return (offsetLeft(g_mainParentMenu)+g_mainParentMenu.clientWidth) - offsetLeft(p_Obj);
	}else{
		return offsetLeft(p_Obj)-l_ObjLeft+p_Obj.clientWidth;
	}	
}


/*-----------------------------------------------------------------
	Loaded the child of the first menu.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The object
    p_Dir				Direction of the web: RTL or LTR
------------------------------------------------------------------*/
var g_mainParentMenu = null;
function loadContextMenu(obj, p_Dir)
{
	var contextMenu;
	var parentMenu;

	if (currentMenu)
	{
		menuOut(currentMenu, window.onmousedown);
		setIframeHelper(0, 0, 0, 0, "none");
	}

	parentMenu = returnContainer(obj);
	g_mainParentMenu = parentMenu;
	contextMenu = document.getElementById(obj.id + "Sub");
	
	if (contextMenu != null)
	{
		contextMenu.style.display = "block";
		contextMenu.style.top = offsetTop(parentMenu) + parentMenu.offsetHeight - 2;
		contextMenu.style.width = contextMenu.firstChild.style.width;
		
		if(parentMenu.clientWidth > contextMenu.clientWidth){
			contextMenu.firstChild.style.width = parentMenu.clientWidth;
			contextMenu.style.width = parentMenu.clientWidth;
		}
		
		contextMenu.parentMenu = parentMenu;
		parentMenu.subMenu = contextMenu;
		currentMenu = parentMenu;
		
		if (p_Dir == 'RTL'){
			if(contextMenu.clientWidth > parentMenu.clientWidth){
				var contextMenuPosition = offsetLeft(parentMenu) - (contextMenu.clientWidth - parentMenu.clientWidth);
			}else{
				var contextMenuPosition = offsetLeft(parentMenu);
			}
			if(contextMenuPosition < 0){
				contextMenu.style.left = 0;
			}else{
				contextMenu.style.left = contextMenuPosition;
			}
			//----Set Iframe under the DIV----
			g_MenuMainObj = parentMenu;
			var l_Width = calcDivsWidth(contextMenu);
			var l_Height = getHeighterDiv(contextMenu);
			g_TheHeighterDiv = 0;
			setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(contextMenu), "block");
			//----------------------------------			
		}else{
			contextMenu.style.left = offsetLeft(parentMenu);
			var l_WindowWidth = document.body.clientWidth;
			var l_DivWidth = contextMenu.clientWidth;
			var contextMenuLeft = offsetLeft(parentMenu)
			if(l_WindowWidth  < l_DivWidth + contextMenuLeft){
				contextMenu.style.left = l_WindowWidth - l_DivWidth;
			}
			//----Set Iframe under the DIV----
			g_menuDirection = "ltr";
			g_MenuMainObj = parentMenu;
			var l_Width = calcDivsWidth(contextMenu);
			var l_Height = getHeighterDiv(contextMenu);
			g_TheHeighterDiv = 0;
			setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(g_MenuMainObj), "block");
			//----------------------------------
		}
		
		
	}
}

/*-----------------------------------------------------------------
	Loaded the child of the submenus.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The  object
------------------------------------------------------------------*/
function loadContextMenuSub(obj) {
	var contextMenu;
	var parentMenu;
	parentMenu = returnContainer(obj);
	contextMenu = document.getElementById(obj.id + "Sub");
	contextMenu.style.display = "block";
	var l_TopHelper = 3;
	if(navigator.appVersion.indexOf("MSIE")!=-1)
		l_TopHelper = 0;
	contextMenu.style.top = obj.offsetTop + parentMenu.offsetTop+l_TopHelper;
		
	if (parentMenu.offsetLeft - contextMenu.offsetWidth + 1 < 0)
		contextMenu.style.left = parentMenu.offsetLeft + parentMenu.offsetWidth - 7;
	else
		contextMenu.style.left = parentMenu.offsetLeft - contextMenu.offsetWidth + 7;
	contextMenu.parentMenu = parentMenu;
	parentMenu.subMenu = contextMenu;
	
	var l_Width = calcDivsWidth(contextMenu);
	var l_Height = getHeighterDiv(contextMenu);
	setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(contextMenu), "block");
}

/*-----------------------------------------------------------------
	Loaded the child of the submenus.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The  object
------------------------------------------------------------------*/
function loadContextMenuSubRight(obj) {
	g_menuDirection = "ltr";
	var contextMenu;
	var parentMenu;
	parentMenu = returnContainer(obj);
	contextMenu = document.getElementById(obj.id + "Sub");
	contextMenu.style.display = "block";
	var l_TopHelper = 3;
	if(navigator.appVersion.indexOf("MSIE")!=-1)
		l_TopHelper = 0;
	contextMenu.style.top = obj.offsetTop + parentMenu.offsetTop+l_TopHelper;
	
	var contextMenuLeft = parentMenu.offsetLeft + parentMenu.offsetWidth - 7;
	var l_WindowWidth = document.body.clientWidth;
	var l_DivWidth = contextMenu.clientWidth;
	if(l_WindowWidth  < l_DivWidth + contextMenuLeft){
		contextMenu.style.left = l_WindowWidth - parentMenu.offsetWidth - l_DivWidth;
	}else{
		contextMenu.style.left = contextMenuLeft;
	}

	contextMenu.parentMenu = parentMenu;
	parentMenu.subMenu = contextMenu;
	
	var l_Width = calcDivsWidth(contextMenu);
	var l_Height = getHeighterDiv(contextMenu);
	setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(g_MenuMainObj), "block");
}


/*-----------------------------------------------------------------
	function that change the interface of the menu item on mouseover event.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    obj					The object
------------------------------------------------------------------*/
function menuOver(obj)
{
	var parentMenu;
	var subMenu;
	var i;

	parentMenu = returnContainer(obj);

	for (i=0; i < obj.childNodes.length; i++)
	{
		//obj.childNodes[i].style.backgroundColor = obj.getAttribute("background");
		obj.childNodes[i].className = obj.getAttribute("SubMenuTextClassOver");
	}
	try{
		if (parentMenu.subMenu != null && parentMenu != parentMenu.subMenu)
		{
			subMenu = parentMenu.subMenu;
			while (subMenu != null)
			{
				subMenu.style.display = "none";
				subMenu = subMenu.subMenu;
			}
		}
	}catch(e){
	}
	
	var l_Width = calcDivsWidth(parentMenu);
	var l_Height = getHeighterDiv(parentMenu);
	if(g_menuDirection == "rtl")
		setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(obj), "block");
	else
		setIframeHelper(l_Width, l_Height, offsetTop(g_MenuMainObj)+g_mainParentMenu.clientHeight, offsetLeft(g_MenuMainObj), "block");
	
	
}


/*-----------------------------------------------------------------
	function that change the interface of the menu item on mouseout event.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    row					The object
------------------------------------------------------------------*/
function menuOut(row, p_Event)
{
	var parentMenu;
	parentMenu = returnContainer(row);
	if (typeof(p_Event) != "undefined" || navigator.appVersion.indexOf("MSIE")!=-1){
		
		var subMenu;
		var i;
		if (parentMenu != row){
			for (i=0; i < row.childNodes.length; i++){
				//row.childNodes[i].style.backgroundColor = "";
				row.childNodes[i].className =  row.getAttribute("SubMenuTextClass");
			}
		}
		var toElement;
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			toElement = returnContainer(event.toElement);
		}else{
			if(p_Event.relatedTarget == null)
				toElement = returnContainer(p_Event.currentTarget);
			else
				toElement = returnContainer(p_Event.relatedTarget);
		}
		var toHide = true;
		if (toElement == null){
			if (parentMenu.subMenu) parentMenu = parentMenu.subMenu;
				while (parentMenu.parentMenu != null){
					parentMenu.style.display = "none";
					parentMenu = parentMenu.parentMenu;
				}
			setIframeHelper(0, 0, 0, 0, "none");
		}else{
			while (toElement){
				if (toElement == parentMenu){
					toHide = false;
					//window.event.cancelBubble = true;
					break;
				}
				toElement = toElement.parentMenu;
			}
			if (toHide){
				subMenu = parentMenu.subMenu;
				while (subMenu != null){
					subMenu.style.display = "none";
					subMenu = subMenu.subMenu;
				}
				setIframeHelper(0, 0, 0, 0, "none");
			}
		}
	}else{
		//setJFT(1);
		if (parentMenu.subMenu) parentMenu = parentMenu.subMenu;
		while (parentMenu.parentMenu != null){
			parentMenu.style.display = "none";
			parentMenu = parentMenu.parentMenu;
		}
	}
}


/*-----------------------------------------------------------------
	function that return the parent of the item.
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    container			The Item
------------------------------------------------------------------*/
function returnContainer(container){
	if (container){
		while (!container.getAttribute("menuElement")){
			if (container.offsetParent){
				container = container.offsetParent;
			}else{
				container = null;
				break;
			}
		}
	}
	return(container);
}


/*-----------------------------------------------------------------
	Open new window 
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    p_Id					Category Id
*/
	function loadCategoryFile(p_Id){
		window.open ("OpenFileById.asp?Id=" + p_Id,"");
	}
	


/*-----------------------------------------------------------------
	Redirect function
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    lngCategoryID		The CategoryID
------------------------------------------------------------------*/
function loadCategory(lngCategoryID)
{
	window.location = "main.asp?lngCategoryID=" + lngCategoryID;
}

function loadCategoryAsList(lngCategoryID)
{
	window.location = "displayNodesInSiteByParentId.asp?lngCategoryID=" + lngCategoryID;
}


/*-----------------------------------------------------------------
	function that handling the onclick event
	Parameters: 
    Name				Description
    -------------------------------------------------------------------
    item				The object that on click occured in
    lngCategoryID		The CategoryID
------------------------------------------------------------------*/
function clickMenu(item, lngCategoryID)
{
	lngCategoryID = parseInt(lngCategoryID.substr(1));
	switch (item.getAttribute("TypeRef"))
	{
	case "1":
		break;
	case "2":
		switch (item.getAttribute("TargetRef"))
		{
			case "1":
				window.open(item.getAttribute("Link"));
				break;
			case "2":
				window.location = item.getAttribute("Link");
				break;
			case "3":
				parent.location = item.getAttribute("Link");
				break;
		}
		break;
	case "3":
		window.location = "main.asp?lngCategoryID=" + lngCategoryID;
		break;
	case "6":
		// item of the menu is a folder
		window.location = "PublicLibrary.asp?lngCategoryID=" + lngCategoryID;
		break;
		
	case "8":
		window.location = "DisplayNodeList.asp?lngCategoryID=" + lngCategoryID;
		break;
	case "11":
		window.location = "displayNodesInSiteByParentId.asp?lngCategoryID=" + lngCategoryID;
		break;
	}
}
//-------------------------------------------------------------------------

