//////////////////////////////////////////////////////////////////////
// COPYRIGHT (C) 1999-2004 PeopleSoft(R), Inc.  All Rights Reserved //
//////////////////////////////////////////////////////////////////////
// We will stop render of portlets as soon as we detect there are portlets from more than one release on the same page.
function setAndValidateVersion(currentVersion)
{

    if (window.storedVersion && window.storedVersion != currentVersion)
    {
        var message = "Portlets from different releases are not supported on the same page. Please contact your administrator to put these portlets in separate pages.";
        alert(message);
        if (document.all) // stop scrip processing in IE
            document.execCommand('Stop');
        else
        {
            // stop script processing in FF. We have to clear the inner HTML since
            // otherwise Firefox by default renders all portlets from the first release
            // and stops only at the first portlet of the second release.
            document.body.innerHTML="";          
            window.stop();
            
        }
    }
    window.storedVersion = currentVersion;
}
setAndValidateVersion("898_200");
var webguiDebug = false;
function webguiDebugToggle()
{
    webguiDebug = !webguiDebug;
    if (webguiDebug)
        alert("WebGUI debug is enabled.");
    else
        alert("WebGUI debug is disabled.");
}

///////////////////////////////////////////////////////////////////////
// START OF SCRIPTS FOR COLLAPSIBLE TREES

function jdeWebGuiToggleTreeNode(domObjectID, toggleType/*unused*/, overrideExpandedURL, overrideCollapsedURL)
{
	var theToggledObject = document.getElementById(domObjectID);
	var theToggleButton = document.getElementById(domObjectID+"_BUTTON");
	if (theToggledObject.style.display == "none")
	{
		theToggledObject.style.display = "block";
		if (overrideExpandedURL)
			theToggleButton.src = overrideExpandedURL;
		else
			theToggleButton.src = window["WEBGUIRES_images_treeexpanded_gif"];
	}
	else
	{
		theToggledObject.style.display = "none";
		if (overrideCollapsedURL)
			theToggleButton.src = overrideCollapsedURL;
		else
		{
			var treeCollapsedImg = window["WEBGUIRES_images_treecollapsed_gif"];
			if (document.documentElement.dir == "rtl")
				treeCollapsedImg = window["WEBGUIRES_images_treecollapsed_rtl_gif"];
			theToggleButton.src = treeCollapsedImg;
		}
	}
}

// END OF SCRIPTS FOR COLLAPSIBLE TREES
//////////////////////////////////
// START OF SCRIPTS FOR INTERACTIVE TREES

self.webGuiInteractiveTree = new function()
{
	this.isFocusableElement = function(node)
	{
		return ( (node != null) && node.getAttribute && (node.getAttribute("arrownav") == "yes") );
	};
	this.getFirstFocusableElement = function(nodesToExamine)
	{
		for (var i=0; i<nodesToExamine.length; i++)
		{
			var currentNode = nodesToExamine[i];
			if (this.isFocusableElement(currentNode))
			{
				return currentNode; // we found it!
			}
			var firstFocusableElementInChild = this.getFirstFocusableElement(currentNode.childNodes);
			if (firstFocusableElementInChild != null)
			{
				return firstFocusableElementInChild;
			}
		}
		return null; // didn't find the element
	};
	this.getLastFocusableElement = function(nodesToExamine)
	{
		for (var i=nodesToExamine.length-1; i>=0; i--)
		{
			var currentNode = nodesToExamine[i];
			if (this.isFocusableElement(currentNode))
			{
				return currentNode; // we found it!
			}
			var lastFocusableElementInChild = this.getLastFocusableElement(currentNode.childNodes);
			if (lastFocusableElementInChild != null)
			{
				return lastFocusableElementInChild;
			}
		}
		return null; // didn't find the element
	};
	this.getDeepestChildNode = function(ancestorNode)
	{
		if (ancestorNode.hasChildNodes())
		{
			return this.getDeepestChildNode(ancestorNode.lastChild);
		}
		else
		{
			return ancestorNode;
		}
	};
	this.getPreviousFocusableElement = function(currentNode, overallParentNode)
	{
		if (currentNode == overallParentNode)
		{
			return null;
		}
		var potentialNode;
		if (currentNode.previousSibling)
		{
			potentialNode = this.getDeepestChildNode(currentNode.previousSibling);
			if (this.isFocusableElement(potentialNode))
			{
				return potentialNode;
			}
			return this.getPreviousFocusableElement(potentialNode, overallParentNode);
		}
		else if (currentNode.parentNode)
		{
			potentialNode = currentNode.parentNode;
			if (this.isFocusableElement(potentialNode))
			{
				return potentialNode;
			}
			return this.getPreviousFocusableElement(potentialNode, overallParentNode);
		}
		return null;
	};
	this.getFirstFocusableChild = function(parent)
	{
		if (parent.hasChildNodes())
		{
			var childNodes = parent.childNodes;
			for (var i=0; i<childNodes.length; i++)
			{
				var child = childNodes[i];
				if (this.isFocusableElement(child))
				{
					return child; // we found it!
				}
				var firstFocusableChild = this.getFirstFocusableChild(child);
				if (firstFocusableChild != null)
					return firstFocusableChild;
			}
		}
		return null;
	};
	this.getNextFocusableElement = function(currentNode, overallParentNode)
	{
		// examine children
		var potentialNode = this.getFirstFocusableChild(currentNode);
		if (potentialNode != null)
		{
			return potentialNode; // we found it!
		}
		
		// for each next sibling (examine it and its children)
		potentialNode = currentNode;
		while (potentialNode.nextSibling)
		{
			potentialNode = potentialNode.nextSibling;
			if (this.isFocusableElement(potentialNode))
			{
				return potentialNode; // we found it!
			}
			var firstFocusableChild = this.getFirstFocusableChild(potentialNode);
			if (firstFocusableChild != null)
			{
				return firstFocusableChild;
			}
		}
		
		// if no more siblings, go up to parents and and then use it's next siblings
		var parentNode = currentNode;
		while (parentNode.parentNode)
		{
			parentNode = parentNode.parentNode;
			if (parentNode == overallParentNode)
			{
				return null;
			}
			var sibling = parentNode;
			while (sibling.nextSibling)
			{
				sibling = sibling.nextSibling;
				potentialNode = this.getNextFocusableElement(sibling, overallParentNode);
				if (potentialNode != null)
				{
					return potentialNode;
				}
			}
		}
		
		return null;
	};
}
function doWebInteractiveKeyDown(eventElement, event, parentContainerID)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var parentContainer = document.getElementById(parentContainerID);
	var leftArrow = 37;
	var rightArrow = 39;
	if (document.documentElement.dir == "rtl")
	{
		leftArrow = 39;
		rightArrow = 37;
	}
	switch (keyCode)
	{
		case 40: /*down arrow*/
			self.currentFound = false;
			var treeRootNodes = parentContainer.childNodes;
			var foundElement = self.webGuiInteractiveTree.getNextFocusableElement(eventElement, parentContainer);
			if (foundElement == null)
			{
				foundElement = self.webGuiInteractiveTree.getFirstFocusableElement(treeRootNodes);
			}
			if (foundElement != null)
			{
				try
				{
					foundElement.focus();
				}
				catch (problem)
				{
					window.status = problem;
				}
			}
			return false;
		case 38: /*up arrow*/
			self.previousNode = null;
			var treeRootNodes = parentContainer.childNodes;
			var foundElement = self.webGuiInteractiveTree.getPreviousFocusableElement(eventElement, parentContainer);
			self.previousNode = null;
			if (foundElement == null)
			{
				foundElement = self.webGuiInteractiveTree.getLastFocusableElement(treeRootNodes);
			}
			if (foundElement != null)
			{
				try
				{
					foundElement.focus();
				}
				catch (problem)
				{
					window.status = problem;
				}
			}
			return false;
		case leftArrow:
			if (eventElement.getAttribute)
			{
				var collapseScript = eventElement.getAttribute("collapseScript");
				if (collapseScript != "null")
					eval(collapseScript);
			}
			try
			{
				event.returnValue = false;
				event.cancelBubble = true;
			}
			catch (e) {}
			return false;
		case rightArrow:
			if (eventElement.getAttribute)
			{
				var expandScript = eventElement.getAttribute("expandScript");
				if (expandScript != "null")
					eval(expandScript);
			}
			try
			{
				event.returnValue = false;
				event.cancelBubble = true;
			}
			catch (e) {}
			return false;
	}
	return true;
}

function doActivateNodeWebGUI(nodeId, parentNodeId, indentLevel, activeNodeRememberedInCookie, treeId)
{
	// these 2 global values are in text fields so the content can easily be transferred between frames
	var currentActiveTreeSectionField = document.getElementById("currentActiveTreeSection" + treeId);
	var currentActiveTreeSection = currentActiveTreeSectionField.value;
	var currentActiveTreeItemField = document.getElementById("currentActiveTreeItem" + treeId);
	var currentActiveTreeItem = currentActiveTreeItemField.value;

	if (currentActiveTreeSection != "")
	{
		try
		{
			document.getElementById(currentActiveTreeSection).className = "";
		}
		catch (problem) {}
	}
	if (currentActiveTreeItem != "")
	{
		try
		{
			document.getElementById(currentActiveTreeItem).className = "";
		}
		catch (problem) {}
	}
	if (parentNodeId == "")
	{
		currentActiveTreeSection = "";
		currentActiveTreeSectionField.value = currentActiveTreeSection;
	}
	else
	{
		currentActiveTreeSection = "node" + treeId + parentNodeId; // NODE_DIV_PREFIX
		currentActiveTreeSectionField.value = currentActiveTreeSection;
	}
	if (currentActiveTreeSection != "")
	{
		try
		{
			if (parentNodeId == nodeId)
				document.getElementById(currentActiveTreeSection).className = "treeactivesectionbottomonly";
			else
				document.getElementById(currentActiveTreeSection).className = "treeactivesection";
		}
		catch (problem)
		{
			currentActiveTreeSection = "";
			currentActiveTreeSectionField.value = currentActiveTreeSection;
		}
	}
	currentActiveTreeItem = "nodeHead" + treeId + nodeId; // NODE_HEAD_DIV_PREFIX
	currentActiveTreeItemField.value = currentActiveTreeItem;
	try
	{
		document.getElementById(currentActiveTreeItem).className = "treeactiveitem";
	}
	catch (problem)
	{
		currentActiveTreeItem = "";
		currentActiveTreeItemField.value = currentActiveTreeItem;
	}

	if (activeNodeRememberedInCookie)
	{
		jdeWebGUIsetExpirableSubCookie("webguiinteractivetree", treeId+"ActiveNodeId", nodeId, "");
		jdeWebGUIsetExpirableSubCookie("webguiinteractivetree", treeId+"ActiveParent", parentNodeId, "");
		jdeWebGUIsetExpirableSubCookie("webguiinteractivetree", treeId+"ActiveIndent", indentLevel, "");
	}
}

function doTreeIframeWebGUI(nodeId, indentLevel, nodeIconId, collapsedIconURL, expandedIconURL, toggleMode, activeNodeRememberedInCookie, treeId)
{
	doActivateNodeWebGUI(nodeId, nodeId/*parent*/, indentLevel, activeNodeRememberedInCookie, treeId);
	var childDiv = document.getElementById("treechild" + treeId + nodeId); // CHILD_DIV_PREFIX
	var expanded = (childDiv.style.display == "block");
	if (expanded && (toggleMode == 'expand'))
	{
		return;
	}
	else if (expanded)
	{
		var theToggleIcon = document.getElementById(nodeIconId);
		theToggleIcon.src = collapsedIconURL;
		childDiv.innerHTML = "";
		childDiv.style.display = "none";
	}
	else if (toggleMode == 'collapse')
	{
		return;
	}
	else
	{
		var theToggleIcon = document.getElementById(nodeIconId);
		theToggleIcon.src = expandedIconURL;
		childDiv.style.display = "block";
		var loadingIndent = indentLevel * 12; // INDENT_SIZE
		var loadingMessage = document.getElementById("loadingMessage" + treeId).value;
		childDiv.innerHTML = "<table cellpadding=0 cellspacing=0><tr><td><img src='" + window["WEBGUIRES_images_spacer_gif"] +"' alt=\"\" width=" + loadingIndent + " height=3></td><td>&nbsp;" + loadingMessage + "</td></tr></table>";
	}
	var iframeDiv = document.getElementById("treeiframediv" + treeId); // IFRAME_DIV_ID
	iframeDiv.style.display = "";
	var callBackUrlPrefix = document.getElementById("callBackUrlPrefix" + treeId).value;
	var nodeIdParam = document.getElementById("nodeIdParam" + treeId).value;
	var indentLevelParam = document.getElementById("indentLevelParam" + treeId).value;
	iframeDiv.innerHTML = "<iframe tabindex=\"-1\" width=1 height=1 scrolling=no frameborder=0 src='" + callBackUrlPrefix + nodeIdParam + "=" + escape(nodeId) + "&" + indentLevelParam + "=" + escape(indentLevel) + "'></iframe>";
}

function doLoadActiveNodeWebGUI(activeNodeRememberedInCookie, treeId)
{
	try
	{
		var nodeId = jdeWebGUIgetSubCookie("webguiinteractivetree", treeId + "ActiveNodeId");
		var parentNodeId = jdeWebGUIgetSubCookie("webguiinteractivetree", treeId + "ActiveParent");
		var indentLevel = jdeWebGUIgetSubCookie("webguiinteractivetree", treeId + "ActiveIndent");
		var indentLevelInt = 0;
		if (indentLevel != "")
			indentLevelInt = parseInt(indentLevel);
		if (nodeId != "")
			doActivateNodeWebGUI(nodeId, parentNodeId, indentLevelInt, activeNodeRememberedInCookie, treeId);
	}
	catch (problem) {}
}

// END OF SCRIPTS FOR INTERACTIVE TREES
//////////////////////////////////
// START OF SCRIPTS FOR MULTISELECTS

function jdeWebGuiMultiSelectCategory(category_id, category_desc)
{
	this.category_id = category_id;
	this.category_desc = category_desc;
}

function jdeWebGuiMultiSelectItem(item_id, item_name, item_desc, category_id)
{
	this.item_id = item_id;
	this.item_name = item_name;
	this.item_desc = item_desc;
	this.category_id = category_id;
}

// END OF SCRIPTS FOR MULTISELECTS
//////////////////////////////////
// START OF SCRIPTS FOR MENUS
var g_jdeWebGUIMenuShown=false;
var g_PrevFocusedElement = null;

function jdeWebGUISaveFocusedElement(evt)
{
	g_PrevFocusedElement = document.all?document.activeElement:evt.target;
}

function jdeWebGUICheckToRestorePrevFocus()
{
	if(g_jdeWebGUIMenuShown==false && g_PrevFocusedElement)
	{	
		try{
			g_PrevFocusedElement.focus();
		}
		catch(error){
		}
		g_PrevFocusedElement = null;
	}
}

function jdeWebGUIUpdateMenuShownFlag()
{
	if(jdeWebGUIGetMenuStackDepth() >0 )
		g_jdeWebGUIMenuShown = true;
	else
		g_jdeWebGUIMenuShown = false;
}

function jdeWebGUIOnMenuUpKey()
{
	var activeMenuItem = jdeWebGUIGetActiveMenuItem();
	if(activeMenuItem != null)
	{
		var nextElement = jdeWebGUIGetPreviousVisibleElementWithFlag(activeMenuItem, "jdeMenuHighlightable", "yes");
		if(nextElement != null){
			jdeWebGUIHighlightMenuItem(nextElement);
			return true;	
		}
	}
	return false;	
}

function jdeWebGUIOnMenuDownKey()
{
	var activeMenuItem = jdeWebGUIGetActiveMenuItem();
	if(activeMenuItem != null)
	{
		var nextElement = jdeWebGUIGetNextVisibleElementWithFlag(activeMenuItem, "jdeMenuHighlightable", "yes");
		if(nextElement != null){
			jdeWebGUIHighlightMenuItem(nextElement);
			return true;
		}
	}
	return false;	
}

function jdeWebGUIOnMenuExpandKey(evt)
{
	var activeMenuItem = jdeWebGUIGetActiveMenuItem();
	if(activeMenuItem != null)
	{
		var subMenuId = activeMenuItem.getAttribute("id");
		//truncate the substring "-show" to get the ID of the submenu
		subMenuId = subMenuId.substring(0, subMenuId.lastIndexOf("-"));		
		jdeWebGUIdoToggleSubMenuOnKeyDown(activeMenuItem, subMenuId, false, evt);				
		return true;
	}
	return false;
}

function jdeWebGUIOnMenuEnterKey(evt)
{
	var activeMenuItem = jdeWebGUIGetActiveMenuItem();
	if(activeMenuItem != null)
	{
		if(jdeWebGUIIsElementAttributeOn(activeMenuItem, "subMenu", "yes"))
		{
			jdeWebGUIOnMenuExpandKey(evt);
		}
		else{
			var menuItemId = activeMenuItem.getAttribute("id");
			//strip out the prefix "outer"
			menuItemId = menuItemId.substring(5);
			jdeWebGUIhideAllMenus(null, null, null);
			jdeWebGUICheckToRestorePrevFocus();
			document.getElementById(menuItemId).onclick();
		}
		return true;
	}
	return false;
}

function jdeWebGUIOnDefaultKeyDown(e)
{
	var event=document.all?window.event:e;
	jdeWebGUIhideAllMenus(null, null, null);
	jdeWebGUICheckToRestorePrevFocus();
	return true;		
}

function jdeWebGUIOnMenuKeyDown(e)
{
	var event=document.all?window.event:e;
	var cancelBubbling = false;
	
	if(g_jdeWebGUIMenuShown==false)
		return false;
		
	if(event.keyCode==38) //Up Arrow
	{
		jdeWebGUIOnMenuUpKey();
		cancelBubbling = true;
	}
	else if(event.keyCode==40) //Down Arrow
	{
		jdeWebGUIOnMenuDownKey();
		cancelBubbling = true;
	}
	else if(event.keyCode==39) //right arrow key
	{
		var activeMenuItem = jdeWebGUIGetActiveMenuItem();
		if(activeMenuItem != null)
		{
			if(jdeWebGUIIsElementAttributeOn(activeMenuItem, "subMenu", "yes"))
			{
				jdeWebGUIOnMenuExpandKey(event);
			}
		}
		cancelBubbling = true;
	}
	else if(event.keyCode==37) //left arrow
	{
		if(jdeWebGUIGetMenuStackDepth() > 1)
		{
			jdeWebGUIHideLastLevelMenu();
		}
		cancelBubbling = true;
	}
	else if(event.keyCode==13){  //Enter key
		jdeWebGUIOnMenuEnterKey(event)
		cancelBubbling = true;
	}
	else
	{
		jdeWebGUIOnDefaultKeyDown(event)
		if(event.keyCode!=17 && event.keyCode!=18) //For Ctrl and Alt key, leave it to document level
			cancelBubbling = true; 
	}
	if(cancelBubbling)
	{
		if(document.all){
			event.cancelBubble = true;
			event.returnValue = false;
		}
		else{
			event.stopPropagation();
			event.preventDefault();
        }
	}
	return cancelBubbling;
}

function jdeWebGUIexecuteLinkInFrame(linkurl, linktarget)
{
	// linktarget must be a valid frame or iframe name or nothing will happen ("_new" will not work)
	eval(linktarget + ".location=\"" + linkurl + "\"");
}

function jdeWebGUIstartMenu(menuID)
{
	writeString = "<div ID=\"" + menuID + "\" ALIGN=LEFT jdeWebGUIPopupMenu=\"yes\" style=\"display:none;position:absolute;z-index:9;\" class=MenuDropdownBack";
	if (document.documentElement.dir == "rtl")
		writeString += "_rtl";
	writeString += " onclick=\"jdeWebGUIhideAllMenus(this,'" + menuID + "', event);\">\n";
	if (document.documentElement.dir == "rtl")
		writeString += "<table ID=\"" + menuID + "_rtl\" cellpadding=0 cellspacing=0><tr><td>";
	if (!document.all)
		writeString += "<table cellpadding=0 cellspacing=0><tr><td>\n";
}

function jdeWebGUIstartSubMenu(menuID)
{
	writeString = "<div ID=\"" + menuID + "\" align=left style=\"display:none;position:absolute;z-index:9;\" class=MenuDropdownBack";
	if (document.documentElement.dir == "rtl")
		writeString += "_rtl";
	writeString +=" jdeWebGUIPopupMenu=\"yes\" onclick=\"jdeWebGUIhideAllMenus(this, '" + menuID + "', event);\">\n";
	if (document.documentElement.dir == "rtl")
		writeString += "<table ID=\"" + menuID + "_rtl\" cellpadding=0 cellspacing=0><tr><td>";
	if (!document.all)
		writeString += "<table cellpadding=0 cellspacing=0><tr><td>\n";
}

function jdeWebGUIwriteMenu()
{
	if (!document.all)
		writeString += "</td></tr></table>";
	if (document.documentElement.dir == "rtl") // workaround for Mozilla in RTL
		writeString += "</td></tr></table>";
	writeString += "</div>";
	document.writeln(writeString);
	writeString = ""; // free up the memory
}

function jdeWebGUIaddMenuItem(MenuID, MenuItemStr, MenuItemHref, Type, MenuItemID, menuAltDesc, blankAltDesc, accessibilityMode, menuType, menuItemChecked, dummy , namespace)
{
    if (Type.indexOf("DISABLEDSUB") != -1 && MenuItemID.indexOf('FavoritesLabel') == -1 && MenuItemID.indexOf('FormRowLabels') == -1)
	{
		writeString += "<span jdeWebGUIPopupMenu=\"yes\" style=\"cursor: pointer;\" onclick=\"jdeWebGUIpreventHideAll=true;\"><table jdeWebGUIPopupMenu=\"yes\" cellpadding=0 cellspacing=0 width=100%><tr jdeWebGUIPopupMenu=\"yes\"><td style=\"width: 20px;\" width=20 jdeWebGUIPopupMenu=\"yes\"><nobr jdeWebGUIPopupMenu=\"yes\">&nbsp;<IMG jdeWebGUIPopupMenu=\"yes\" align=absmiddle border=0 width=9 height=10 SRC='"+ window["WEBGUIRES_images_menuitemblank_gif"] +"' alt=\"" + blankAltDesc + "\">&nbsp;</nobr></td><td jdeWebGUIPopupMenu=\"yes\" width=100% class=MenuItemDisabled><span class=MenuItemDisabled><nobr jdeWebGUIPopupMenu=\"yes\">" + MenuItemStr + "&nbsp;&nbsp;&nbsp;</nobr></span></td><td jdeWebGUIPopupMenu=\"yes\" style=\"width: 20px;\" width=20 align=right><nobr jdeWebGUIPopupMenu=\"yes\"><IMG jdeWebGUIPopupMenu=\"yes\" align=absmiddle border=0 width=9 height=10 SRC='";
		if (document.documentElement.dir == "rtl")
		{
			writeString += window["WEBGUIRES_images_submenuitem_disabled_rtl_gif"]; 
		}
		else
		{
		    writeString += window["WEBGUIRES_images_submenuitem_disabled_gif"]; 
		}
		writeString += "' alt=\"" + menuAltDesc + "\">&nbsp;</nobr></td></tr></table></span>\n";
	}
    else if (Type.indexOf("SUBMENU") != -1 && MenuItemID.indexOf('FavoritesLabel') == -1  &&  MenuItemID.indexOf('FormRowLabels') == -1)
	{
		writeString += "<SPAN jdeWebGUIPopupMenu=\"yes\" jdeMenuHighlightable=\"yes\" subMenu=\"yes\" style=\"cursor: pointer;\" ID='" + MenuID + "-" + MenuItemID + "-Show' onmouseover=\"jdeWebGUIHighlightMenuItemById('"+MenuID + "-" + MenuItemID + "-Show');jdeWebGUIpreventHideAll=false;jdeWebGUIdoToggleSubMenu(this, '" + MenuID + "-" + MenuItemID + "', event);\" onclick=\"jdeWebGUIpreventHideAll=true;jdeWebGUIdoToggleSubMenu(this, '" + MenuID + "-" + MenuItemID + "', event);\"><table jdeWebGUIPopupMenu=\"yes\" cellpadding=0 cellspacing=0 width=100%><tr jdeWebGUIPopupMenu=\"yes\"><td style=\"width: 20px;\" width=20 jdeWebGUIPopupMenu=\"yes\"><nobr jdeWebGUIPopupMenu=\"yes\">&nbsp;<IMG jdeWebGUIPopupMenu=\"yes\" align=absmiddle border=0 width=9 height=10 SRC='"+ window["WEBGUIRES_images_menuitemblank_gif"] + "' alt=\"" + blankAltDesc + "\">&nbsp;</nobr></td><td jdeWebGUIPopupMenu=\"yes\" style=\"WIDTH: 100%\" class=MenuItemSubMenu ID=\"SubMenu_" + MenuItemID + "\"><span class=MenuItemSubMenu><nobr style=\"WIDTH: 100%\" jdeWebGUIPopupMenu=\"yes\">" + MenuItemStr + "&nbsp;&nbsp;&nbsp;</nobr></span><nobr><LABEL FOR=\"SubMenu_" + MenuItemID + "\"><span STYLE=\"display:none;\">&nbsp;" + Type + "&nbsp;</span></LABEL></nobr></td><td jdeWebGUIPopupMenu=\"yes\" style=\"width: 20px;\" width=20 align=right><nobr jdeWebGUIPopupMenu=\"yes\"><IMG jdeWebGUIPopupMenu=\"yes\" align=absmiddle border=0 width=9 height=10 SRC='";
		if (document.documentElement.dir == "rtl")
		{
			writeString += window["WEBGUIRES_images_submenuitem_rtl_gif"];
	    }
		else
		{
		    writeString += window["WEBGUIRES_images_submenuitem_gif"];
		}
		writeString += "' alt=\"" + menuAltDesc + "\">&nbsp;</nobr></td></tr></table></SPAN>\n";
	}
    else if (Type.indexOf("SEPARATOR") != -1 && MenuItemID.indexOf('FavoritesLabel') == -1 && MenuItemID.indexOf('FormRowLabels') == -1)
	{
		writeString += "<table width=100% cellpadding=0 cellspacing=0><tr><td jdeWebGUIPopupMenu=\"yes\" style=\"cursor: pointer;\" onclick=\"jdeWebGUIpreventHideAll=true;\"><HR style=\"cursor: pointer;\" onclick=\"jdeWebGUIpreventHideAll=true;\" jdeWebGUIPopupMenu=\"yes\" class=HR1 SIZE=1></td></tr></table>\n";
	}
    else
	{
                jdeWebGUIsetNamespace(namespace);
                // add the Favorite menuItem to the fav array
                if (MenuItemID.indexOf('FEFA') !=-1)
                {                
                addFormExitFavMenuStack(MenuItemID);
                }
                else if (MenuItemID.indexOf('REFA') !=-1)
                {
                addRowExitFavMenuStack(MenuItemID);
                }

                // Align the Default Favorites, ROW & FORM Labels to left
               if(MenuItemID.indexOf('FavoritesLabel') == -1  && MenuItemID.indexOf('FormRowLabels') == -1)
               {
                writeString += "<span id=\"outer" + MenuItemID+"\" align=left";
               }
               else
               {
		writeString += "<span id=\"outer" + MenuItemID+"\"";
               }
		//Disabled item should not be hilightable
		if ( Type.indexOf("DISABLED") == -1 )
			writeString += " jdeMenuHighlightable=\"yes\"";
		writeString += ">";
                if (Type.indexOf("DISABLED") == -1)
		writeString += getWebGUIMenuItemInnerHTML(MenuID, MenuItemStr, MenuItemHref, Type, MenuItemID, accessibilityMode, menuType, menuItemChecked, dummy);
		writeString += "</span>\n";
	}
}

function jdeWebGUIChangeDisplayStyle(theElementID, newDisplayStyle)
{
	var theElement = document.getElementById(theElementID);
	if (theElement)
	{
		if (newDisplayStyle) // true means to show it
			theElement.style.display = "";
		else // false means to hide it
		theElement.style.display = "none";
	}
}

function getWebGUIMenuItemInnerHTML(MenuID, MenuItemStr, MenuItemHref, Type, MenuItemID, accessibilityMode, menuType, menuItemChecked, dummy)
{
	var writeString = "";
	var onClick = "";
        if (Type.indexOf("DISABLED") != -1)
        {
        writeString = "<table jdeWebGUIPopupMenu=\"yes\" ID=\"" + MenuItemID + "\" cellpadding=0 cellspacing=0 width=100% style=\"cursor: default;\"";
        }
        else 
        {
	writeString = "<table jdeWebGUIPopupMenu=\"yes\" ID=\"" + MenuItemID + "\" cellpadding=0 cellspacing=0 width=100% style=\"cursor: pointer;\"";
        }

	if ( Type.indexOf("DISABLED") == -1 && MenuItemID.indexOf('FavoritesLabel') == -1 && MenuItemID.indexOf('FormRowLabels') == -1)
	{
		writeString += " onmouseover=\"jdeWebGUIHighlightMenuItemById('outer"+ MenuItemID +"');\" ";
                writeString += " onmousedown=\"menuItemMouseDown('outer"+ MenuItemID +"', event);\" ";
		if (MenuItemHref.indexOf("javascript:") == -1) // not a JavaScript call
		{
			onClick = "onclick=\"self.location='";
			var hrefDelimitedItems = MenuItemHref.split("'");
			var i = 0;
			for (; i<hrefDelimitedItems.length-1; i++)
				onClick += hrefDelimitedItems[i] + "\\'";
			onClick += hrefDelimitedItems[i];
			onClick += "';\"";
		}
		else // is a JavaScript call, immediately evaluate it when clicked
		{
			onClick = "onclick=\"eval('";
			var hrefDelimitedItems = MenuItemHref.split("'");
			var i = 0;
			for (; i<hrefDelimitedItems.length-1; i++)
				onClick += hrefDelimitedItems[i] + "\\'";
			onClick += hrefDelimitedItems[i];
			onClick += "');\"";
		}
		}
		else
		{
			onClick += "onclick=\"jdeWebGUIpreventHideAll=true;\""
		}
        writeString += onClick;
        writeString += "><tr jdeWebGUIPopupMenu=\"yes\"><td jdeWebGUIPopupMenu=\"yes\" style=\"width: 20px;\" width=20><nobr jdeWebGUIPopupMenu=\"yes\">&nbsp; " ; 
        var imgString = "<IMG jdeWebGUIPopupMenu=\"yes\" align=absmiddle border=0 width=9 height=10 SRC='";

		if (Type.indexOf("DISABLEDCHECK") != -1)
			imgString += window["WEBGUIRES_images_menuitemcheckdisabled_gif"] + "'>";
		else if (Type.indexOf("CHECK") != -1)
			imgString += window["WEBGUIRES_images_menuitemcheck_gif"] + "'>";
		else if (Type.indexOf("DISABLEDRADIO") != -1)
			imgString += window["WEBGUIRES_images_menuitembulletdisabled_gif"] + "'>";
		else if (Type.indexOf("RADIO") != -1)
			imgString += window["WEBGUIRES_images_menuitembullet_gif"] + "'>";
		else
		 {
                    //Display the image only for normal mode. for Accessibility Mode
                    //Don't display the image
                    if (accessibilityMode == false && MenuItemID.indexOf('FavoritesLabel') == -1 && MenuItemID.indexOf('FormRowLabels') == -1)
                    {
                        imgString += window["WEBGUIRES_images_menuitemblank_gif"] + "'>";
                    }
                    else
                    {
                        imgString = "" ;
                    }
                }
                
                writeString += imgString  ;

                writeString += "&nbsp;</nobr></td><td jdeWebGUIPopupMenu=\"yes\" style=\"width: 100%;\" class=";
		if (Type.indexOf("DISABLED") != -1)
			writeString += "MenuItemDisabled";
                else if (MenuItemID.indexOf('FavoritesLabel') != -1)
                        writeString += "FavoritesLabel";
                else if (MenuItemID.indexOf('FormRowLabels') != -1)   
                        writeString += "FormRowLabels";
		else
			writeString += "MenuItem";
            writeString += "><span jdeWebGUIPopupMenu=\"yes\" CLASS=";
         if (Type.indexOf("DISABLED") != -1)
          {
            if (dummy == true)
            {
               writeString += "accessibility";
            } else 
            {
               writeString += "MenuItemDisabled";
            }
          }
          else
          {
            writeString += "MenuItem";
          }
                //For Accessibilty Mode render text equivalent of Disabled class 'MenuItemDisabled'
                if (Type.indexOf("DISABLED") != -1 && accessibilityMode == true)
                {
			MenuItemStr += "<span class=\"accessibility\"> Status : Disabled </span>";
                }
	writeString += "><nobr jdeWebGUIPopupMenu=\"yes\">" + MenuItemStr + "&nbsp;</nobr>" ;
        if (accessibilityMode)
        {
            writeString += getAccessibilityString (Type) ;
        }
        writeString += "</span>";
	writeString += "</td><td jdeWebGUIPopupMenu=\"yes\" style=\"width: 20px;\" width=20 align=right> " ; 
        if (accessibilityMode == false)
        {
            writeString += " <img src='"+ window["WEBGUIRES_images_spacer_gif"] +"' alt=\"\" width=10 height=1>" ;
        } 

        writeString += "</td></tr></table>";
	return writeString;
}
// Return a String that represents the status of the image.
function getAccessibilityString (Type)
{
        var imgString = "<span class=\"accessibility\">";
        if (Type.indexOf("DISABLEDCHECK") != -1)
                imgString += "Disabled Check";
        else if (Type.indexOf("CHECK") != -1)
                imgString += "Check";
        else if (Type.indexOf("DISABLEDRADIO") != -1)
                imgString += "Disabled Radio";
        else if (Type.indexOf("RADIO") != -1)
                imgString += "Radio";
        imgString += "</span>" ;
        return imgString ;
}

var jdeWebGUIcurrentMenu = null;
var jdeWebGUIcurrentSubMenu = null;
var jdeWebGUIbaseTriggerAbsolutePositioned = false;

var jdeWebGUIPopupMenuEventHandlerEnabled = false;
var jdeWebGUIPopupMenuEventHandlerParent = null;
var jdeWebGUIPopupMenuEventHandlerMenuID = null;
function jdeWebGUIPopupMenuEventHandler(event)
{
	if (document.all)
	{
		if (jdeWebGUIPopupMenuEventHandlerEnabled)
		{
			// check to see if we need to hide the menus or not
			if (window.event.srcElement.jdeWebGUIPopupMenu != "yes")
			{
				jdeWebGUIhideAllMenus(jdeWebGUIPopupMenuEventHandlerParent, jdeWebGUIPopupMenuEventHandlerMenuID, window.event);
			}
		}
	}
	else
	{
		if (jdeWebGUIPopupMenuEventHandlerEnabled)
		{
			// check to see if we need to hide the menus or not
			if (event.currentTarget.jdeWebGUIPopupMenu != "yes")
			{
				if (event.target.parentNode.jdeWebGUIPopupMenu != "yes") //work around for Safari
					jdeWebGUIhideAllMenus(jdeWebGUIPopupMenuEventHandlerParent, jdeWebGUIPopupMenuEventHandlerMenuID, event);
			}
		}
	}
	jdeWebGUIPopupMenuEventHandlerEnabled = true;
}

function jdeWebGUIdoMenu(Parent, MenuID, event)
{
    var thisMenu = document.getElementById(MenuID);

    // register the custom onclick trapping method
    jdeWebGUIPopupMenuEventHandlerEnabled = false;
    jdeWebGUIPopupMenuEventHandlerParent = Parent;
    jdeWebGUIPopupMenuEventHandlerMenuID = MenuID;
	
    if (document.all)
    {
        document.onclick = jdeWebGUIPopupMenuEventHandler;
    }
    else // Netscape's version
    {
        document.addEventListener("click", jdeWebGUIPopupMenuEventHandler, false);
    }
	
    var x, y;

    // Set dropdown menu display position
    x = Parent.offsetLeft + document.body.offsetLeft;
    y = Parent.offsetTop + Parent.offsetHeight + document.body.offsetTop;
	
    var vaParent = Parent.offsetParent;

    if (!jdeWebGUIbaseTriggerAbsolutePositioned)
    {
            if (document.all)
            {
		while (vaParent && vaParent.id!="WebMenuBar")
		{
			x += vaParent.offsetLeft;
			y += vaParent.offsetTop;
			vaParent = vaParent.offsetParent;
		}
                y += 20; // Add extra image height to because we want the menu is below the clicked image
            }
            else
            {
        while (vaParent)
        {
            x += vaParent.offsetLeft;
            y += vaParent.offsetTop;
            vaParent = vaParent.offsetParent;
	}

            }
    }
    
    //adjust by the tab on modeless forms
    var modelessTabDiv = document.getElementById("modelessTabDiv");
    if (modelessTabDiv != null) 
    {
        y -= 25;
    }
    //lock toolbar -menubar table relative position adjust in IE
    if(document.all || modelessTabDiv != null)
    {
        //top banner
        var topBanner = document.getElementById("topimagecell");
        if(topBanner != null)
        {
            //adjust with topbanner height plus its border and padding
            y -= (topBanner.offsetHeight + 8);
        }

       if(document.getElementById("jdeFormTitle") != null) { 
        var jdeFormTitle = document.getElementById("jdeFormTitle");
        y -=  jdeFormTitle.offsetHeight + 12       
       }
       else
       {
        //adjust by the form title height
        var formtitle = document.getElementById("formTitle0");
        if(formtitle == null)
            formtitle = document.getElementById("formTitle");
        if(formtitle != null)
            y -= formtitle.offsetHeight;
       }
    }
                    
    thisMenu.style.top  = y;
    thisMenu.style.left = x;

// want to executes the Row Contextmenu Logic only when the event.type == "contextmenu"
   var mousepos = getCursorPosition(event);
   if(event.type == "contextmenu")
   {
    if (document.all)
    {
    thisMenu.style.top  = mousepos[1] - getAbsoluteTopPos(thisMenu.parentNode);
    }
    else
    { 
     thisMenu.style.top  = mousepos[1] - getAbsoluteTopPos(thisMenu.parentNode)+20;    //to Adjust the Context menu in FF2,FF3 an extra top 20 is padded
    }
    thisMenu.style.left = mousepos[0];   
    
    jdeWebGUIPopupMenuEventHandlerEnabled = true;
  }
   
   //OPS WSRP in IE has an issue with the E1Menu dropdowns
   var isWSRP = (gContainerId == E1URLFactory.prototype.CON_ID_WSRP);  
   if(document.all && isWSRP)
   thisMenu.style.top=mousepos[1] - getAbsoluteTopPos(thisMenu.parentNode);

    thisMenu.style.clip = "rect(auto auto auto auto)";
    thisMenu.style.display = "block";
    thisMenu.style.zIndex = 2000000000; // assuming minimum 32-bit integer
    // This is a hack to force IE display high zindex div correctly in portal
    // by setting the same zindex on the parent table element as well. TABLE-TBODY-TR-TD-DIV 
    if (document.all) // TODO: add javascript check of portal, since we only need this hack for IE portal
    {
        thisMenu.parentNode.parentNode.parentNode.parentNode.style.zIndex = thisMenu.style.zIndex;
    }
    
    var isRTL = document.documentElement.dir == "rtl";
    if (isRTL) //only support in IE
    {
        var rtlWrapper = document.getElementById(MenuID+"_rtl");
	var theWidth = rtlWrapper.offsetWidth;
	thisMenu.style.width = theWidth;
        
        // flip menus by changing their left positions	
        if(x > theWidth)
            x = x - theWidth;
        else
            x = x - Parent.offsetWidth;
            
        if(document.all)
        {
            x  = getAbsoluteLeftPos(Parent.offsetParent, true) + Parent.offsetWidth - thisMenu.offsetWidth;
            var menuTable = document.getElementById("WebMenuBar");
            if(menuTable != null)
            {                
                x -= menuTable.offsetLeft;
            }
        }
           
	thisMenu.style.left = x;
    if(event.type == "contextmenu")
    {
      thisMenu.style.left = mousepos[0] - ( x + menuTable.offsetLeft + thisMenu.offsetWidth+30); 
    }
    }
    
    //HFE - lock toolbar. If the menu is outside the window width, need show it in the left side
    var bodyElem = document.body;
    var windowWidth = bodyElem.offsetWidth;
    var windowHeight = bodyElem.offsetHeight;
    //for FireFox
    if((!document.all) && window.innerWidth != null)
    {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
    }
    if(!isRTL && ((x + thisMenu.offsetWidth)> windowWidth))
    {        
        x  = getAbsoluteLeftPos(Parent.offsetParent, true) + Parent.offsetWidth - thisMenu.offsetWidth;
        var menuTable = document.getElementById("WebMenuBar");
        if(menuTable != null)
        {
            x -= menuTable.offsetLeft;
        }
        thisMenu.style.left = x;
    }
    //if the RowExit Context menu is outside window width, need to show in top
    if(event.type == "contextmenu" && !isRTL && ((mousepos[1] + thisMenu.offsetHeight) > windowHeight))
    {
        if(document.all)
        thisMenu.style.top  = mousepos[1] - (Parent.offsetHeight + thisMenu.offsetHeight);
        else
        thisMenu.style.top  = mousepos[1] - thisMenu.offsetHeight;    
    }
    
    hideOSDrawnControls();
    if (jdeWebGUIcurrentMenu != null) // get rid of any old menu if present 
    {
        jdeWebGUIcurrentMenu.style.display = "none";
	removeItemShadow(jdeWebGUIcurrentMenu);
    }
    jdeWebGUIcurrentMenu = thisMenu;
    if (document.all)
    {
	jdeWebGUIcurrentMenu.setActive();
	if(jdeWebGUIcurrentMenu.document.activeElement.id != ""){
	jdeWebGUIcurrentMenu.focus();
    }
    }
    showItemShadow(thisMenu);
    
    if(((thisMenu.offsetTop + thisMenu.offsetHeight)> windowHeight)
       || ((thisMenu.offsetLeft + thisMenu.offsetWidth)> windowWidth) )
        document.body.style.overflow= "auto";
}

function jdeWebGUIshowMenu()
{
	if (jdeWebGUIcurrentMenu != null)
		jdeWebGUIcurrentMenu.style.clip = "rect(auto auto auto auto)";
}

function jdeWebGUIshowSubMenu()
{
	if (jdeWebGUIcurrentSubMenu != null)
		jdeWebGUIcurrentSubMenu.style.clip = "rect(auto auto auto auto)";
}

function showItemShadow(el, maskFrame)
{
    // IE has problems with comboboxes and native controls. Putting an iframe underneath fixes it.
    if (document.all)  //IE
    {
        var itemMask = (maskFrame != null)?maskFrame:window.GlobalMaskFrame;
        itemMask.attachMask(el);
    }
	
    var elmID = el.id + "-shadow";
    var elmBorder = document.getElementById(elmID+0);
    if (elmBorder == null){
        if ( (el.style.zIndex == undefined) || (parseInt(el.style.zIndex) <= 2) ){
                el.style.zIndex = 3;
        }
        var elTop = parseInt(el.style.top);
        var elLeft = parseInt(el.style.left);
        var elWidth = el.offsetWidth;
        var elHeight = el.offsetHeight;
        var isRtl = (document.documentElement.dir == "rtl");
        var isSafari = (navigator.userAgent.toUpperCase().indexOf("SAFARI") >= 0);
        var ssTop = elTop + 1;
        var ssLeft = elLeft;
        for (var i=0; i<6; i++){
                var shade = document.createElement('div');
                var ss = shade.style;
                ss.position = "absolute";
                ss.left = ssLeft;
                ss.top = ssTop;
                if (i%2 == 0){
                        if (isRtl)
                                ssLeft--;
                        else
                                ssLeft++;
                }
                else
                        ssTop++;
                ss.width = elWidth;
                ss.height = elHeight;
                if ( !isSafari && (null != el.style.zIndex) )
                        ss.zIndex = parseInt(el.style.zIndex) - 1;
                else
                        ss.zIndex = 2;
                ss.backgroundColor = "#000000";
                webguiSetOpacity(shade,10);
                if (el.nextSibling) 
                        el.parentNode.insertBefore(shade,el.nextSibling);
                else
                        el.parentNode.appendChild(shade);
                shade.id = elmID + i;
        }
        el.style.opacity = 0.99; // fix for Safari 1.2
    }
}
function webguiSetOpacity(el, opacityPercent)
{
    el.style.opacity = (opacityPercent / 100);
    el.style.filter = "alpha(opacity=" + opacityPercent + ")"; 
    el.style.MozOpacity = (opacityPercent / 100);
}

function moveItemShadow(el)
{
    if (document.all)  //IE
    {
        var maskframe = document.getElementById(el.id + "-maskframe");
        if(null != maskframe){
                maskframe.style.top = parseInt(el.style.top);
                maskframe.style.left = parseInt(el.style.left);
                maskframe.style.width = el.offsetWidth;
                maskframe.style.height = el.offsetHeight;
        }
    }

    var elmID, elmBorder;
    elmID = el.id + "-shadow";
    var elTop = parseInt(el.style.top);
    var elLeft = parseInt(el.style.left);
    var elWidth = el.offsetWidth;
    var elHeight = el.offsetHeight;
    var isRtl = (document.documentElement.dir == "rtl");
    var ssTop = elTop + 1;
    var ssLeft = elLeft;
    for (var i=0; i<6; i++){
            elmBorder = document.getElementById(elmID+i);
            if (elmBorder != null){
                    var ss = elmBorder.style;
                    ss.left = ssLeft;
                    ss.top = ssTop;
                    if (i%2 == 0){
                            if (isRtl)
                                    ssLeft--;
                            else
                                    ssLeft++;
                    }
                    else
                            ssTop++;
                    ss.width = elWidth;
                    ss.height = elHeight;
            }
    }
}

function removeItemShadow(el, maskFrame)
{
    if (document.all)  //IE
    {
        var itemMask = (maskFrame != null)?maskFrame:window.GlobalMaskFrame;
        itemMask.detachMask();
    }
	
    var elmID, elmBorder;
    elmID = el.id + "-shadow";
    for (var i=0; i<6; i++)
    {
            elmBorder = document.getElementById(elmID+i);
            if (elmBorder != null)
            {
                    var elmBorderParent = elmBorder.parentNode;
                    elmBorderParent.removeChild(elmBorder);
            }
    }
}

var jdeWebGUIpreventHideAll = false;
var jdeWebGUImenuStack = new Array(50);
var formexitfavstackSize = 0;
var rowexitfavstackSize = 0;
var formexitfavmenuStack = new Array();
var rowexitfavmenuStack = new Array();

function jdeWebGUIdoToggleSubMenuOnKeyDown(Parent, MenuID, isBaseMenu, evt)
{
	if(document.all)
	{
		Parent.click(); //mimic click to fix accessability
	}
	else
	{	
	jdeWebGUIdoToggleSubMenu(Parent, MenuID, evt, isBaseMenu);
	}	
	jdeWebGUIPopupMenuEventHandlerEnabled = true;
	var menuElement = document.getElementById(MenuID);
	if(menuElement != null)
	{
		var hilightableMenuItemOuterElement = jdeWebGUIGetFirstVisibleDescendentWithFlag(menuElement, "jdeMenuHighlightable", "yes");
		if(hilightableMenuItemOuterElement != null)
		{
			jdeWebGUIHighlightMenuItem(hilightableMenuItemOuterElement);
		}
	}
}

function jdeWebGUIHighlightMenuItem(element)
{
	jdeWebGUIUnhighlightAllItemsInParentMenu(element);
	element.className = "MenuActive";
	element.setAttribute("highlighted", "yes");
}

function jdeWebGUIUnhighlightAllItemsInParentMenu(element)
{
	var siblingNodes = element.parentNode.childNodes;
	for (var i=0; i <siblingNodes.length; i++)
	{
		if(siblingNodes[i].className=="MenuActive")
		{
			jdeWebGUIUnhighlightMenuItem(siblingNodes[i]);
		}
	}
}

function jdeWebGUIHighlightMenuItemById(Id)
{
	var element = document.getElementById(Id);
	if(element)
		jdeWebGUIHighlightMenuItem(element);
}

function jdeWebGUIUnhighlightMenuItem(menuItemElement)
{
	if(menuItemElement != null)
	{
		menuItemElement.className = "MenuNormal";
		menuItemElement.removeAttribute("highlighted");
	}
}

function menuItemMouseDown(ID, e)
{
    var menuID;
    var isRTL = document.documentElement.dir == "rtl";
    
    var element = document.getElementById(ID);
    if(document.all)
    {
         if (!isRTL) 
        {
          menuID = element.parentNode.id;    
        }
        else
        {
          menuID = element.ownerDocument.activeElement.id;
        }
    }
    //FF Check
    if(!document.all)
    {
    // Firefox 3 begin to support HTML5 include document.getElementsByClassName
        // The easier way to distiguish FF2 and FF3 is to check document.getElementsByClassName.
        if(!document.getElementsByClassName) // firefox version < 3
        {
            menuID = element.parentNode.parentNode.parentNode.parentNode.parentNode.id;
        }
        else
        {
        // FF3
        if(element.ownerDocument.activeElement.firstChild != undefined)
          menuID = element.ownerDocument.activeElement.firstChild.id;
          //if the Context menu is on Form/Grid,need to get the MenuID from DOM differently in FF3.6/FF3.0
          if(menuID == null)
          menuID = element.parentNode.parentNode.parentNode.parentNode.parentNode.id;
        }
    }
    
    //Drag N drop feature is not available in ToolsMenu/Report_Exit/View_Exit
    if (menuID == "ToolsMenu" || menuID.indexOf("Report_Exit") > 0 || menuID.indexOf("View_Exit") > 0 )
    {
        if(document.all)
        {
            e.cancelBubble = true;
            e.returnValue = false;
        }
        else
        {
            e.stopPropagation();
            e.preventDefault();
        }
        return;
    }
    //disable the highlight of menuitem
    if(element)
    jdeWebGUIUnhighlightMenuItem(element);
    
    // update the style to show we're dragging
     element.style.backgroundColor = "#CFE0F1";

   //A representation of the menuItem that moves along with mouse
    var menuItemDragClone = element.cloneNode(true);
    menuItemDragClone.className = 'menuItemDragClone';
    menuItemDragClone.style.position = 'absolute';
    menuItemDragClone.setAttribute('id','menuItemDragClone');
    
    document.body.appendChild(menuItemDragClone);
    dragDrop.initElement(element);    
}

//dragdrop object
dragDrop = {
	draggedObject: undefined,
	initElement: function (element) {
		element.onmousedown = dragDrop.startDragMouse;
	},
	startDragMouse: function (e) {
		dragDrop.startDrag(this);
		var evt = e || window.event;
		addMouseEvent(document,'mousemove',dragDrop.dragMouse);
		addMouseEvent(document,'mouseup',dragDrop.releaseElement);
		return false;
	},
	startDrag: function (obj) {
		if (dragDrop.draggedObject)
			dragDrop.releaseElement();
		dragDrop.draggedObject = obj;
		obj.className += ' dragged';
	},
        dragMouse: function (e) {
            if (dragDrop.draggedObject){
                var evt = e || window.event;

            var curpos = getCursorPosition(e);

            //Take into account the scroll positions on the 'e1formDiv' also (after HFE - lock toolbar project)
            var formDiv = document.getElementById('e1formDiv');
            var formDivScrollTop = 0;
            var formDivScrollLeft = 0;

            if (formDiv)
            {
                formDivScrollTop = formDiv.scrollTop;
                formDivScrollLeft = formDiv.scrollLeft;
            }  

            if(menuItemDragClone.style != null){
            menuItemDragClone.style.left = curpos[0] - formDivScrollLeft;
            menuItemDragClone.style.top = curpos[1]+25 - formDivScrollTop;
            }

            //set zIndex to display the Drag Clone on top of the page       
            menuItemDragClone.style.zIndex = 2000000000;
            
            return false;
            }
        },
      releaseElement: function(e) {
      
      var dragObjMenuID;
      var isRTL = document.documentElement.dir == "rtl";
      var isWSRP = (gContainerId == E1URLFactory.prototype.CON_ID_WSRP);

        if(document.all)
        {
            if (!isRTL) 
            {
                dragObjMenuID = dragDrop.draggedObject.parentNode.id;  
            }
            else
            {
                dragObjMenuID = dragDrop.draggedObject.parentNode.parentNode.parentNode.parentNode.parentNode.id;
            }
        }

       //FF Check
        if(!document.all)
        {
            // Firefox 3 begin to support HTML5 include document.getElementsByClassName
            // The easier way to distiguish FF2 and FF3 is to check document.getElementsByClassName.
            if(!document.getElementsByClassName) // firefox version < 3
            {
             dragObjMenuID = dragDrop.draggedObject.parentNode.parentNode.parentNode.parentNode.parentNode.id;
            }
            else
            {
            // FF3
             if(dragDrop.draggedObject.ownerDocument.activeElement.firstChild != undefined)
              dragObjMenuID = dragDrop.draggedObject.ownerDocument.activeElement.firstChild.id;
			 
             //if the Context menu is on Form/Grid,need to get the MenuID from DOM differently in FF3.6/FF3.0
              if(dragObjMenuID == null || dragObjMenuID.indexOf("Form_Exit") == -1 || dragObjMenuID.indexOf("Row_Exit") == -1)
              dragObjMenuID = dragDrop.draggedObject.parentNode.parentNode.parentNode.parentNode.parentNode.id;
            }
        }
      
        var menuType = getMenuType(dragObjMenuID);

        if (menuType == "FORM_EXIT_TYPE")
        {
             var dragObjectClone =  dragDrop.draggedObject.cloneNode(true);
             // Favorites menuItem ID starts with outerFEFA
			if(dragObjectClone.id.indexOf("outerFEFA") == 0)
			{   
			    var selectedElement = getSelectedElement();
                
			   // Check if the favmenu item is Drag N dropped on another fav menuitem.Don't allow the invalid Drag N Drop
			    if(selectedElement != undefined &&  dragObjectClone.id != selectedElement.id  && selectedElement.id.indexOf("outerFEFA") != 0)
			    {
                   removeFormExitFavMenuStack(dragObjectClone.id.substring(5));
                   getDtaInstance().doAsynPostById("formExitFavRemove", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1)); 
			    }                
				
			    // If the selectedElement menuItem ID starts with outerFEFA, It means the menuItem Drag and dropped on the another favorite menuItem
                            //Note: Below if loop code has logic to re-order the favorites
			    else if(selectedElement != undefined && dragObjectClone.id != selectedElement.id && selectedElement.id.indexOf("outerFEFA") == 0) 
			    {
					var selectedElmID = selectedElement.id.substring(5);
					var dragCloneID = dragObjectClone.id.substring(5);

				       // get the OldPos, NewPos of the favorites menuitems from the formExitarray
					var favOldPos = formexitfavmenuStack.findIndex(dragCloneID);
					var favNewPos = formexitfavmenuStack.findIndex(selectedElmID);
					if(selectedElmID !=  undefined && favNewPos != -1)
					{
					 getDtaInstance().doAsynPostById("formExitFavReorder", null, favOldPos+'|'+dragObjectClone.id.substring(11)+'|'+favNewPos+'|'+selectedElement.id.substring(11));                    
				    }
			    }
			   else
			    {
				// remove dragObjectClone
				dragObjectClone= null;                    
			    }				
			}
			else
			{
             var origDragCloneID = dragObjectClone.id;

			 // ID comes with prefix outerHE- Replace the HE with FA[Favorites]
			// to maintain unique ID's for the FormExit/RowExit Fav MenuItems
			dragObjectClone.setAttribute('id',dragObjectClone.id.replace("HE","FEFA"));
                    
			//replace all Occurrences of HE with FA
			dragObjectClone.innerHTML = dragObjectClone.innerHTML.replace(/HE/g,"FEFA"); 
                    
		        // in webClient the DragCloneID starts with prefix outerFEFA+FullQulifiedID of menuItem(ex:0_89)
			// In WSRP we get the namespace appended to MenuID, remove the namespace from the ID to ensure 
			// that it works similarly as Normal webClient
			if(isWSRP)
			{
			var favFormPrefix = dragObjectClone.id.substring(0,dragObjectClone.id.indexOf("_"));
			dragObjectClone.id = favFormPrefix.concat(dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") - 1));
			}

			//if it's a New Formexit favorite 
			if(isFavoritesSection(e) && isNewFormExitFavorite(dragObjectClone.id))
			{
        if(isWSRP)
        {
        addFormExitFavMenuStack(favFormPrefix.concat(dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_"))));
        getDtaInstance().doAsynPostById("formExitFavAdd", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1));
        }
        else
        {
         addFormExitFavMenuStack(dragObjectClone.id.substring(5));
         getDtaInstance().doAsynPostById("formExitFavAdd", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1)); 
        }
      }
      else 
      {
         dragObjectClone= null;
      }
		    }         
        }
        else if (menuType == "ROW_EXIT_TYPE")
        {
             var dragObjectClone =  dragDrop.draggedObject.cloneNode(true);

			//Favorite Row Exit menuitem ID comes with the prefix -outerREFA
			if(dragObjectClone.id.indexOf("outerREFA") == 0)
			{   
			  var selectedElement = getSelectedElement();

			  // check if the favmenu item is droped on another fav menuitem (OR) User did not do a proper Drag n drop,don't allow 
				if(selectedElement != undefined &&  dragObjectClone.id != selectedElement.id  && selectedElement.id.indexOf("outerREFA") != 0)
				{
				   //remove the Fav menuItem from the rowexitfavmenu Array
                    removeRowExitFavMenuStack(dragObjectClone.id.substring(5));
                    getDtaInstance().doAsynPostById("rowExitFavRemove", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1));                    
				}

			   // If the selectedElement menuItem ID starts with outerREFA, It means the menuItem Drag and dropped on the 
			   // another favorite menuItem
			    else if(selectedElement != undefined && dragObjectClone.id != selectedElement.id && selectedElement.id.indexOf("outerREFA") == 0) 
			    {
				   var selectedElmID = selectedElement.id.substring(5);
				   var dragCloneID = dragObjectClone.id.substring(5);
				   // get the OldPos, NewPos of the favorites menuitems from the formExitarray
				   var favOldPos = rowexitfavmenuStack.findIndex(dragCloneID);
				   var favNewPos = rowexitfavmenuStack.findIndex(selectedElmID);
				   if(selectedElmID !=  undefined && favNewPos != -1)
				   {            
				     getDtaInstance().doAsynPostById("rowExitFavReorder", null, favOldPos+'|'+dragObjectClone.id.substring(11)+'|'+favNewPos+'|'+selectedElement.id.substring(11));                    
				   }
			    }
			    else
			    {
				dragObjectClone= null;                    
			    }
			}
		   else
		   {
			 var origDragCloneID = dragObjectClone.id;
			// ID comes with prefix outerHE- Replace the HE with FA[Favorites]
			// to maintain unique ID's for the FormExit/RowExit Fav MenuItems
			dragObjectClone.setAttribute('id',dragObjectClone.id.replace("HE","REFA"));
			
			//replace all Occurrences of HE with FA
			dragObjectClone.innerHTML = dragObjectClone.innerHTML.replace(/HE/g,"REFA"); 
			
			if(isWSRP)
			{
				var favRowPrefix = dragObjectClone.id.substring(0,dragObjectClone.id.indexOf("_"));
				dragObjectClone.id = favRowPrefix.concat(dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") - 1));
			}

			  if(isFavoritesSection(e) && isNewRowExitFavorite(dragObjectClone.id))
			  {
					if(isWSRP)
					{
						addRowExitFavMenuStack(favRowPrefix.concat(dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_"))));
						getDtaInstance().doAsynPostById("rowExitFavAdd", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1));
					}
					else
					{
						addRowExitFavMenuStack(dragObjectClone.id.substring(5));                             
						getDtaInstance().doAsynPostById("rowExitFavAdd", null, dragObjectClone.id.substring(dragObjectClone.id.lastIndexOf("_") + 1));
					 }
        }
        else
        {
          // remove dragObjectClone
          dragObjectClone= null;
        }
           }
        }

        //reset the Color back
        dragDrop.draggedObject.style.backgroundColor = 'transparent';
        if(dragObjectClone != null)
        dragObjectClone.style.backgroundColor = 'transparent';
        
        //Reset the JIT handlers
        removeMouseEvent(document,'mousemove',dragDrop.dragMouse);
        removeMouseEvent(document,'mouseup',dragDrop.releaseElement);
        dragDrop.draggedObject.className = dragDrop.draggedObject.className.replace(/dragged/,'');
        dragDrop.draggedObject = null;
        
        //Remove the dragged 'clone'
        var menuItemDragClone = document.getElementById('menuItemDragClone');
        if(menuItemDragClone != null)
        document.body.removeChild(menuItemDragClone);
	}
}

function isFavoritesSection(e)
{
  var srcElement = document.all ? event.srcElement : e.target;
  while (srcElement.parentNode)
  {
    srcElement = srcElement.parentNode;
    // stop search when we find a accend who is row exit or form exit fravorite or className is FavoritesLabel
    if (srcElement.className == "FavoritesLabel" || (srcElement.id && (srcElement.id.indexOf('REFA') !=-1 || srcElement.id.indexOf('FEFA') !=-1)))
      return true;
  }
  
  return false;
}

function isNewFormExitFavorite(dragObjectCloneID) {
    var newFormExitFav = true;
    var formexitfavstackSize = 0;

    // Check is the menuItem is a New FormExit Favorite Item or Not
    if( (formexitfavmenuStack[formexitfavstackSize] != null) && (formexitfavmenuStack[formexitfavstackSize] != ""))
    {
        for (i=0; i < formexitfavmenuStack.length; i++)
        {
                if (formexitfavmenuStack[i] == dragObjectCloneID.substring(5))
                {
                      newFormExitFav = false;
                }
        }
    }
    return newFormExitFav;
}

function isNewRowExitFavorite(dragObjectCloneID) {
    var newRowExitFav = true;
    var rowexitfavstackSize = 0;

// Check is the menuItem is a New RowExit Favorite Item or Not
 if( (rowexitfavmenuStack[rowexitfavstackSize] != null) && (rowexitfavmenuStack[rowexitfavstackSize] != ""))
 {
    for (i=0; i < rowexitfavmenuStack.length; i++)
    {
            if (rowexitfavmenuStack[i] == dragObjectCloneID.substring(5))
            {
                  newRowExitFav = false;
            }
    }
  }
  return newRowExitFav;
}

function getMenuType(dragObjMenuID) {
   var menuType;

 if(dragObjMenuID.indexOf("Form_Exit") > 0  || dragObjMenuID.indexOf("FORM_EXIT_BUTTON") == 0 )
 {  
         menuType = "FORM_EXIT_TYPE";
 }
 else if(dragObjMenuID.indexOf("Row_Exit") > 0 || dragObjMenuID.indexOf("ROW_EXIT_BUTTON") == 0)
 {
     menuType = "ROW_EXIT_TYPE";
 }
 return menuType;

}

function getDtaInstance() {

var isWSRP = (gContainerId == E1URLFactory.prototype.CON_ID_WSRP); 

    if(document.all || isWSRP){
     return JDEDTAFactory.getInstance(this.namespace);
     }
     else{
     return JDEDTAFactory.getInstance("");
     }
}
function addMouseEvent(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}
function removeMouseEvent(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}
function addFormExitFavMenuStack(favId)
{
     //update the formexit Favorite Array and increment the favstacksize
    formexitfavmenuStack[formexitfavstackSize] = favId;
    while ( (formexitfavmenuStack[formexitfavstackSize] != null) && (formexitfavmenuStack[formexitfavstackSize] != "") && (formexitfavstackSize < formexitfavmenuStack.length) )
    {
            formexitfavstackSize++;
    }
}
function addRowExitFavMenuStack(favId)
{
     //update the rowexit Favorite Array and increment the favstacksize
    rowexitfavmenuStack[rowexitfavstackSize] = favId;
    while ( (rowexitfavmenuStack[rowexitfavstackSize] != null) && (rowexitfavmenuStack[rowexitfavstackSize] != "") && (rowexitfavstackSize < rowexitfavmenuStack.length) )
    {
            rowexitfavstackSize++;
    }
}
function removeFormExitFavMenuStack(favId)
{
      for( j = 0; j < formexitfavstackSize; j++)
      {
          if (formexitfavmenuStack[j] == favId){
          formexitfavmenuStack.splice(j,1);
          formexitfavstackSize--;
          }
      }
}

function removeRowExitFavMenuStack(favId)
{
      for( j = 0; j < rowexitfavstackSize; j++)
      {
          if (rowexitfavmenuStack[j] == favId){
          rowexitfavmenuStack.splice(j,1);
          rowexitfavstackSize--;
          }
      }
}

function jdeWebGUIsetNamespace(namespace){
this.namespace = namespace;
}

function getSelectedElement(){
// get the active MenuItem
    var stackSize = 0;
    
    while ( (jdeWebGUImenuStack[stackSize] != null) && (jdeWebGUImenuStack[stackSize] != "") && (stackSize < jdeWebGUImenuStack.length) )
    {
            stackSize++;
    }
   for (j=stackSize-1; j>=0; j--)
    {
        var thisMenu = document.getElementById(jdeWebGUImenuStack[j]);
        var activeItem = jdeWebGUIGetActiveItemInMenu(thisMenu);
    }

    // get the highlighted MenuItem Element
    if(activeItem != null)
     var selectedElement =  document.getElementById(activeItem.id);
     
     return selectedElement;
}

function jdeWebGUIdoToggleSubMenu(Parent, MenuID, event, isBaseMenu)
{
	// get the real number of items in this array
	var stackSize = 0;
	while ( (jdeWebGUImenuStack[stackSize] != null) && (jdeWebGUImenuStack[stackSize] != "") && (stackSize < jdeWebGUImenuStack.length) )
	{
		stackSize++;
	}
	// determine if the stack contains this menu (so we know whether to show it or not)
	var needToShow = true;
	var menuLevel = 0;
	if (MenuID == "")
	{
		needToShow = false;
	}
	else
	{
		for (i=0; i<stackSize; i++)
		{
			if (jdeWebGUImenuStack[i] == MenuID)
				needToShow = false;
		}
		menuLevel = jdeWebGUIgetMenuLevel(MenuID);
	}
	needToShow = true;
	// hide all submenus that are at the same level as this one or deeper
	for (j=stackSize-1; j>=0; j--)
	{
		if (jdeWebGUIgetMenuLevel(jdeWebGUImenuStack[j]) >= menuLevel)
		{
			if (isBaseMenu)
                            jdeWebGUIhideMenu(Parent, jdeWebGUImenuStack[j], event);
                        else
                            jdeWebGUIhideSubMenu(Parent, jdeWebGUImenuStack[j], event);
                            
			jdeWebGUImenuStack[j] = "";
		}
	}
	if (needToShow)
	{
		stackSize = 0;
		while ( (jdeWebGUImenuStack[stackSize] != null) && (jdeWebGUImenuStack[stackSize] != "") && (stackSize < jdeWebGUImenuStack.length) )
		{
			stackSize++;
		}
		if (isBaseMenu)
			jdeWebGUIdoMenu(Parent, MenuID, event);
		else
			jdeWebGUIdoSubMenu(Parent, MenuID, event);
		jdeWebGUImenuStack[stackSize] = MenuID;
	}
	showOSDrawnControls();
	jdeWebGUIUpdateMenuShownFlag();
}
function jdeWebGUIhideAllMenus(Parent, MenuID, event)
{
        if (jdeWebGUIpreventHideAll && event !=null)
	{
		jdeWebGUIpreventHideAll = false;
		if (!document.all)
		{
			event.stopPropagation();
			event.preventDefault();
		}
		return;
	}
	
	// get the real number of items in this array
	var stackSize = 0;
	while ( (jdeWebGUImenuStack[stackSize] != null) && (jdeWebGUImenuStack[stackSize] != "") && (stackSize < jdeWebGUImenuStack.length) )
	{
		stackSize++;
	}
	// hide all submenus that are at the same level as this one or deeper
    for (j=stackSize-1; j>=0; j--)
    {
        try
        {
        var thisMenu = document.getElementById(jdeWebGUImenuStack[j]);
        jdeWebGUIUnhighlightMenuItem(jdeWebGUIGetActiveItemInMenu(thisMenu));
        thisMenu.style.display = "none";
        removeItemShadow(thisMenu);
        }
        catch (problem)
        {
            // the object no longer exists on the page so let's just remove it from the stack
        }
        jdeWebGUImenuStack[j] = "";
    }
	
        if(jdeWebGUIcurrentMenu != null)
        {
            jdeWebGUIcurrentMenu.style.display = "none";
            removeItemShadow(jdeWebGUIcurrentMenu);
            jdeWebGUIcurrentMenu = null;
        }
	showOSDrawnControls();
	jdeWebGUIUpdateMenuShownFlag();
}

function jdeWebGUIgetMenuLevel(MenuID)
{
	return MenuID.split("_").length;
}

function jdeWebGUIdoSubMenu(Parent, MenuID, event)
{
    var thisMenu = document.getElementById(MenuID);
    var parString = MenuID.substring(0, MenuID.lastIndexOf("-"));
    var ParentMenu = document.getElementById(parString);
    var x, y;
    var clipVal;

	// Reset dropdown menu
    jdeWebGUIcurrentSubMenu = thisMenu;

    // Set dropdown menu display position
    if (document.all)
        x  = Parent.offsetParent.style.posLeft + Parent.offsetParent.offsetWidth;
    else
        x  = parseInt(ParentMenu.style.left) + ParentMenu.offsetWidth;

    y = Parent.offsetTop + document.body.offsetTop;
    
    var vaParent = Parent.offsetParent;

    if (!jdeWebGUIbaseTriggerAbsolutePositioned)
    {
        while (vaParent && vaParent.id!="WebMenuBar")
	{
            y += vaParent.offsetTop;
            vaParent = vaParent.offsetParent;
	}
	y +=23
    }
    else
    {
	y += 15;
    }
    
    //lock toolbar -menubar table relative position adjust in IE
    if(document.all)
    {
        //top banner
        var topBanner = document.getElementById("topimagecell");
        if(topBanner != null)
        {
            //adjust with topbanner height plus its border and padding
            y -= (topBanner.offsetHeight + 8);
        }

       if(document.getElementById("jdeFormTitle") != null) 
       { 
          var jdeFormTitle = document.getElementById("jdeFormTitle");
          y -=  jdeFormTitle.offsetHeight + 12       
       }
       else
       {
        //adjust by the form title height
        var formtitle = document.getElementById("formTitle");
        if(formtitle == null)
            formtitle = document.getElementById("formTitle0");
        if(formtitle != null)
            y -= formtitle.offsetHeight;
       }
    }
    //adjust by the tab on modeless forms
    var modelessTabDiv = document.getElementById("modelessTabDiv");
    if (modelessTabDiv != null) 
    {
        y -= 25;
    }
    
    thisMenu.style.top  = y;
    thisMenu.style.left = x;

    thisMenu.style.clip =  "rect(auto auto auto auto)";
    thisMenu.style.display = "block";
    thisMenu.style.zIndex = 2000000000; // assuming minimum 32-bit integer

    if (document.documentElement.dir == "rtl")
    {
	var rtlWrapper = document.getElementById(MenuID+"_rtl");
	var theWidth = rtlWrapper.offsetWidth;
	thisMenu.style.width = theWidth;
               
        x = getAbsoluteLeftPos(Parent.offsetParent);
        // flip menus by changing their left positions	
        if(x > theWidth)
            x = x - theWidth;
        else
            x = x + Parent.offsetParent.offsetWidth;
            
        if(document.all)
        {
            var menuTable = document.getElementById("WebMenuBar");
            if(menuTable != null)
            {                
                x -= menuTable.offsetLeft;
            }
        }
        
	thisMenu.style.left = x;
    }

    //HFE - lock toolbar. If the menu is outside the window width, need show it in the left side
    var bodyElem = document.body;
    var windowWidth = bodyElem.offsetWidth;
    var windowHeight = bodyElem.offsetHeight;
    //for FireFox
    if((!document.all) && window.innerWidth != null)
    {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
    }
    
    if((x + thisMenu.offsetWidth)> windowWidth)
    {
        if (document.all)
            x  = Parent.offsetParent.style.posLeft - thisMenu.offsetWidth;
        else
            x  = parseInt(ParentMenu.style.left) - thisMenu.offsetWidth;
        
        thisMenu.style.left = x;
    }
    
    if (document.all)
    {
	thisMenu.setActive();
	thisMenu.focus();
    }
    showItemShadow(thisMenu);
    if(((thisMenu.offsetTop + thisMenu.offsetHeight)> windowHeight)
       || ((thisMenu.offsetLeft + thisMenu.offsetWidth)> windowWidth) )
        document.body.style.overflow= "auto";
}

function jdeWebGUIhideMenu(Parent, MenuID, event)
{
    var thisMenu = document.getElementById(MenuID);
	if (thisMenu != null)
	{
		var cX, cY;
		var bHideMenu = true;
		//If pass in null event, that is a keydown command, hide it always
		if(event != null)
		{
		if (document.all)
		{
			cX = event.clientX + document.body.scrollLeft;
			cY = event.clientY + document.body.scrollTop;
		}
		else
		{
			cX = event.clientX + window.pageXOffset;
			cY = event.clientY + window.pageYOffset;
		}
		var x, x2, y, y2;

        // Get menu position, width and height
		if (document.all)
		{
	        x  = thisMenu.style.posLeft;
    	    y  = thisMenu.style.posTop;
		}
		else
		{
			x  = parseInt(thisMenu.style.left);
	        y  = parseInt(thisMenu.style.top);
		}
		
        x2 = x + thisMenu.offsetWidth;
        y2 = y + thisMenu.offsetHeight;

		if (cY > y-2 && cY < y2-2)
		{
			if (cX > x && cX < x2-2) bHideMenu = false;
		}
		// this prevents it from opening multiple exit menus.  32 is the size of the bitmap.
		if (cX > x + 32 && cX < x2)
		{
			if (cY < y)	bHideMenu = true;
		}

        // see if we have popped up a child menu and we are jumping over to it
        if (jdeWebGUIcurrentSubMenu != null)
        {
			if (document.all)
			{
	            if ( (cX >= jdeWebGUIcurrentSubMenu.style.posLeft && cX <= (jdeWebGUIcurrentSubMenu.style.posLeft + jdeWebGUIcurrentSubMenu.offsetWidth)) &&
   	              (cY >= jdeWebGUIcurrentSubMenu.style.posTop && cY <= (jdeWebGUIcurrentSubMenu.style.posTop + jdeWebGUIcurrentSubMenu.offsetHeight)) )
   	         {
   	             bHideMenu = false;
   	         }
			}
			else
			{
	            x  = parseInt(jdeWebGUIcurrentSubMenu.style.left);
	            y  = parseInt(jdeWebGUIcurrentSubMenu.style.top);
	
            	if( (cX >= x && cX <= (x + jdeWebGUIcurrentSubMenu.offsetWidth)) &&
            	    (cY >= y && cY <= (y + jdeWebGUIcurrentSubMenu.offsetHeight)) )
            	{
            	    bHideMenu = false;
            	}
	      }
           }
        }
		if (! bHideMenu)
		{
			return;
		}
		jdeWebGUIUnhighlightMenuItem(jdeWebGUIGetActiveItemInMenu(thisMenu));
                if(jdeWebGUIcurrentMenu != null)
                {
                    jdeWebGUIcurrentMenu.style.display = "none";
                    removeItemShadow(jdeWebGUIcurrentMenu);
                    jdeWebGUIcurrentMenu = null;
                }
		thisMenu.style.display = "none";
		removeItemShadow(thisMenu);
		showOSDrawnControls();
	}
        
    if(!document.all && document.body.style.overflow=="auto")
        document.body.style.overflow=="hidden";
}

function jdeWebGUIhideSubMenu(Parent, MenuID, event)
{
    var thisMenu = document.getElementById(MenuID);
    var parString = MenuID.substring(0, MenuID.lastIndexOf("-"));
    var ParentMenu = document.getElementById(parString);
    if (thisMenu != null)
    {
        var bHideMenu = true;
	if(event != null)
        {
            var cX, cY;
            if (document.all)
            {
		cX = event.clientX + document.body.scrollLeft;
		cY = event.clientY + document.body.scrollTop;
            }
            else
            {
                cX = event.clientX + window.pageXOffset;
		cY = event.clientY + window.pageYOffset;
            }
            var x, x2, y, y2;

	    // Get menu position, width and height
            if (document.all)
            {
                x  = Parent.offsetParent.style.posLeft;
	    	y  = Parent.offsetParent.style.posTop + Parent.offsetTop;

	    	x2 = x + Parent.offsetParent.offsetWidth;
		y2 = y + Parent.offsetHeight;
            }
            else
            {
		x  = parseInt(ParentMenu.style.left);
	    	y  = Parent.offsetTop;

	    	x2 = x + ParentMenu.offsetWidth;
		y2 = y + Parent.offsetHeight;
            }

            if ((cX < x2) && (cX > x ))
            {
                if ((cY > y+2) && (cY < y2-2))
	        bHideMenu = false;
            }

            // if we are jumping back to the submenu dont hide it
	    if (document.all)
            {
		x  = thisMenu.style.posLeft;
                if(document.documentElement.dir == "rtl")
                {
                    var menuTable = document.getElementById("WebMenuBar");
                    if(menuTable != null)
                    {
                        x -= menuTable.offsetLeft;
                    }
                }
                
	    	y  = thisMenu.style.posTop;
            }
            else
            {
		x  = parseInt(thisMenu.style.left);
	    	y  = parseInt(thisMenu.style.top);
            }

	    x2 = x + thisMenu.offsetWidth;
            y2 = y + thisMenu.offsetHeight;

            if ((cX <= x2 + 2) && (cX > x - 2 ))
            {
                if ((cY > y) && (cY < y2))
                    bHideMenu = false;
            }
        }
	if (! bHideMenu)
	{
            return;
	}

	jdeWebGUIUnhighlightMenuItem(jdeWebGUIGetActiveItemInMenu(thisMenu));
        jdeWebGUIcurrentSubMenu  = null;
	thisMenu.style.display = "none";
	removeItemShadow(thisMenu);
    }
    
    if(!document.all && document.body.style.overflow=="auto")
        document.body.style.overflow=="hidden";
}

function jdeWebGUIHideLastLevelMenu()
{
	var lastLevelMenuID = jdeWebGUIGetLastLevelMenuID();
	var menuDepth = jdeWebGUIGetMenuStackDepth();
	if(menuDepth == 1)
	{
		jdeWebGUIhideMenu(null, lastLevelMenuID, null);
	}
	else if(menuDepth >0){
		jdeWebGUIhideSubMenu(null, lastLevelMenuID, null);
	}
	jdeWebGUImenuStack[menuDepth-1] = "";
	jdeWebGUIUpdateMenuShownFlag();
	if(g_jdeWebGUIMenuShown == false)
		showOSDrawnControls();
	jdeWebGUICheckToRestorePrevFocus();		
	return true;
}

function jdeWebGUIGetMenuStackDepth()
{
	var stackSize = 0;
	while ( (jdeWebGUImenuStack[stackSize] != null) && (jdeWebGUImenuStack[stackSize] != "") && (stackSize < jdeWebGUImenuStack.length) )
	{
		stackSize++;
	}
	return stackSize;
}

function jdeWebGUIGetLastLevelMenuID()
{
	var menuDepth = jdeWebGUIGetMenuStackDepth();
	if(menuDepth > 0)
		return jdeWebGUImenuStack[menuDepth-1];
	else
		return null;
}

function jdeWebGUIGetActiveMenuItem()
{
	var menuDepth = jdeWebGUIGetMenuStackDepth();
	var activeItem = null;
	if(menuDepth > 0){
		var menuElement = document.getElementById(jdeWebGUIGetLastLevelMenuID());
		activeItem = jdeWebGUIGetActiveItemInMenu(menuElement);
	}
	return activeItem;	
}

function jdeWebGUIGetActiveItemInMenu(menuElement)
{
	if(menuElement != null){
		return jdeWebGUIGetFirstVisibleDescendentWithFlag(menuElement, "highlighted", "yes");
	}
	return null;	
}

function jdeWebGUIRecurseHideMenu(MenuID, event)
{
    var thisMenu = document.getElementById(MenuID);
	var Parent = document.getElementById(MenuID+'-Show');
	var bDoNotHide = false;
	
	if (thisMenu != null)
	{
		var cX, cY;
		if (document.all)
		{
			cX = event.clientX + document.body.scrollLeft;
			cY = event.clientY + document.body.scrollTop;
		}
		else
		{
			cX = event.clientX + window.pageXOffset;
			cY = event.clientY + window.pageYOffset;
		}
		var x, x2, y, y2;
		var bHideMenu = true;
        var lastIndex = -1;
        var tempStr = MenuID;
        var tempMenu;

	    // Get menu position, width and height
		if (document.all)
		{
		    x  = thisMenu.style.posLeft;
		    y  = thisMenu.style.posTop;
		}
		else
		{
			x  = parseInt(thisMenu.style.left);
	        y  = parseInt(thisMenu.style.top);
		}

	    x2 = x + thisMenu.offsetWidth;
		y2 = y + thisMenu.offsetHeight;

		if (cY < (y + Parent.offsetHeight -2) && cY > y)
		{
			if (cX >= (x2-2) && cX <= (x2 + Parent.offsetWidth - 2)) bHideMenu = false;
		}

		if (! bHideMenu)
		{
			return;
		}

		if (cY > y+2 && cY < y2-2)
		{
			if (cX > (x-3) && cX < x2-2) bHideMenu = false;
		}

        // see if we have popped up a child menu and we arejumping over to it
        if (jdeWebGUIcurrentSubMenu != null && jdeWebGUIcurrentSubMenu != thisMenu)
        {
			if (! document.all)
			{
	            if ( (cX >= jdeWebGUIcurrentSubMenu.style.posLeft && cX <= 	(jdeWebGUIcurrentSubMenu.style.posLeft + jdeWebGUIcurrentSubMenu.offsetWidth)) &&
	                 (cY >= jdeWebGUIcurrentSubMenu.style.posTop && cY <= (jdeWebGUIcurrentSubMenu.style.posTop + jdeWebGUIcurrentSubMenu.offsetHeight)) )
	            {
	                bHideMenu = false;
	            }
			}
			else
			{
	            x  = parseInt(jdeWebGUIcurrentSubMenu.style.left);
	            y  = parseInt(jdeWebGUIcurrentSubMenu.style.top);
	
            	if( (cX >= x && cX <= (x + jdeWebGUIcurrentSubMenu.offsetWidth)) &&
            	    (cY >= y && cY <= (y + jdeWebGUIcurrentSubMenu.offsetHeight)) )
            	{
            	    bHideMenu = false;
            	}
			}
        }

		if (! bHideMenu)
		{
			return;
		}

		jdeWebGUIcurrentSubMenu = null;
		thisMenu.style.display = "none";
        removeItemShadow(thisMenu);
        // now recursively start hiding the parent menus
        while (true)
        {
            lastIndex = tempStr.lastIndexOf("_");
            if (lastIndex == -1)
                break;
            // get the previous menu
            tempStr = tempStr.substring(0,lastIndex);
			tempMenu = document.getElementById(tempStr);

            // if the mouse is on the previous menu dont hide it
			if (document.all)
			{
            	if ( (cX >= tempMenu.style.posLeft && cX <= (tempMenu.style.posLeft + tempMenu.offsetWidth)) &&
            	     (cY >= tempMenu.style.posTop && cY <= (tempMenu.style.posTop + tempMenu.offsetHeight)) )
            	{
            	    bDoNotHide = true;
            	    break;
            	}
			}
			else
			{
				x  = parseInt(tempMenu.style.left);
            	y  = parseInt(tempMenu.style.top);            
            	if( (cX >= x && cX <= (x + tempMenu.offsetWidth)) &&
            	    (cY >= y && cY <= (y + tempMenu.offsetHeight)) )
            	{
            	    bDoNotHide = true;
            	    break;
            	}
			}
            // just hide the menu
            tempMenu.style.display = "none";
            removeItemShadow(tempMenu);
            showOSDrawnControls();
        }

		if (!bDoNotHide)
        {
			jdeWebGUIcurrentMenu = null;
		}
	}
}

/////Menu Key Handling

	//Check if the DOM element has the passed attribute with the passed in value 
	function jdeWebGUIIsElementAttributeOn(node, attribute, value)
	{
		return ( (node != null) && node.getAttribute && (node.getAttribute(attribute) == value) );
	}

	function jdeWebGUIGetFirstVisibleDescendentWithFlag(parent, attribute, value)
	{
		if (parent.hasChildNodes())
		{
			var childNodes = parent.childNodes;
			for (var i=0; i<childNodes.length; i++)
			{
				var child = childNodes[i];
				if(child.style && child.style.display != "none")
				{
					if (jdeWebGUIIsElementAttributeOn(child, attribute, value))
					{
						return child;
					}
				}
				var result = jdeWebGUIGetFirstVisibleDescendentWithFlag(child, attribute, value);
				if (result != null)
					return result;
			}
		}
		return null;
	}

	function jdeWebGUIGetPreviousVisibleElementWithFlag(currentNode, attribute, value)
	{
		// for each previous sibling (examine it and its children)
		var potentialNode = currentNode;
		do{
			if(potentialNode.previousSibling)
				potentialNode = potentialNode.previousSibling;
			else{ 
				potentialNode = potentialNode.parentNode.lastChild;
			}
			if(potentialNode == currentNode)
				break;
			
			if(potentialNode.style && potentialNode.style.display=="none")
				continue;
			if (jdeWebGUIIsElementAttributeOn(potentialNode, attribute, value))
			{
				return potentialNode; // we found it!
			}			
		}while (potentialNode != currentNode);	
		return null;
	}
	
	
	function jdeWebGUIGetNextVisibleElementWithFlag(currentNode, attribute, value)
	{
		// for each next sibling (examine it and its children)
		var potentialNode = currentNode;
		do{
			if(potentialNode.nextSibling)
				potentialNode = potentialNode.nextSibling;
			else{ 
				potentialNode = potentialNode.parentNode.firstChild;
			}
			if(potentialNode == currentNode)
				break;
			
			if(potentialNode.style && potentialNode.style.display=="none")
				continue;
			if (jdeWebGUIIsElementAttributeOn(potentialNode, attribute, value))
			{
				return potentialNode; // we found it!
			}			
		}while (potentialNode != currentNode);	
		return null;
	}


/////End Menu Key handling

function declareOSDrawnControl(anotherControlID)
{
}

function temporarilyExcludeOSDrawnControl(controlID)
{
}

function hideOSDrawnControls()
{
}

function showOSDrawnControls()
{

}

// END OF SCRIPTS FOR MENUS
///////////////////////////
// START OF SCRIPTS FOR COOKIES

function jdeWebGUIsetSubCookie(cookiename, subcookiename, setting)
{
	var expiration = "";
	var expire = new Date();
	expire.setTime(expire.getTime() + ( 180 * 24*60*60*1000 ) ); // expire in 180 days
	jdeWebGUIsetExpirableSubCookie(cookiename, subcookiename, setting, expire.toGMTString());
}
function jdeWebGUIsetExpirableSubCookie(cookiename, subcookiename, setting, expiration, path)
{
	var bigcookievalue = "";
	var oldbigcookie = jdeWebGUIgetCookie(cookiename, false);
	var subarray = oldbigcookie.split("&");
	for (i=0; i<subarray.length; i++)
	{
		var curVal = subarray[i].split("=");
		if (curVal.length > 1)
		{
			var curName = curVal[0];
			var curVal = unescape(curVal[1]);
			if (curName != subcookiename)
				bigcookievalue += curName + "=" + escape(curVal) + "&";
		}
	}
	
	bigcookievalue += subcookiename + "=" + escape(setting);
	
	var theCookie = cookiename + "=" + bigcookievalue + ";";
	if (!path)
		theCookie += " path=/;";
	else
		theCookie += " path=" + path + ";";

	theCookie += " " + expiration;
	document.cookie = theCookie;
}
function jdeWebGUIgetSubCookie(cookiename, subcookiename)
{
	var bigcookie = jdeWebGUIgetCookie(cookiename, false);
	var subarray = bigcookie.split("&");
	for (i=0; i<subarray.length; i++)
	{
		var curVal = subarray[i].split("=");
		if (curVal.length > 1)
		{
			var curName = curVal[0];
			var curVal = unescape(curVal[1]);
			if (curName == subcookiename)
				return curVal;
		}
	}
	return "";
}
function jdeWebGUIresetCookie(cookiename)
{
	var expire = new Date();
	expire.setTime(expire.getTime() + 1 ); // expire in 1 millisecond
	document.cookie = cookiename + "=" + escape("zzz") + "; path=/; expires=" + expire.toGMTString();
}
function jdeWebGUIsetCookie(cookiename, setting)
{
	var expire = new Date();
	expire.setTime(expire.getTime() + ( 180 * 24*60*60*1000 ) ); // expire in 180 days
	document.cookie = cookiename + "=" + escape(setting) + "; path=/; expires=" + expire.toGMTString();
}
function jdeWebGUIgetCookie(cookiename, unescapeResult)
{
	var arg = cookiename + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		{
			var endstr = document.cookie.indexOf(";", j);
			if (endstr == -1)
				endstr = document.cookie.length;
			if (unescapeResult)
				return unescape(document.cookie.substring(j, endstr));
			else
				return document.cookie.substring(j, endstr);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return "";
}

// END OF SCRIPTS FOR COOKIES
//////////////////////////////////

///////////////////////////////////////////////////////////////
// START OF CALENDAR SCRIPTS

function jdeWebGUIshowCalendar(updateFieldId, dateSeparator, dateFormatEnum, timeFormatEnum)
{
	var dateFormat = "MDE";
	if (dateFormatEnum == "1")
		dateFormat = "EMD";
	else if (dateFormatEnum == "2")
		dateFormat = "DME";

	var utcEnabled = false;
	var utc24 = false;
	if (timeFormatEnum == "1")
		utcEnabled = true;
	else if (timeFormatEnum == "2")
	{
		utcEnabled = true;
		utc24 = true;
	}
	var windowHeight = 210;
	if (utcEnabled)
		windowHeight = 310;

	var minYear = 1500;
	var maxYear = 2500;

	var calWindow = window.open("", "jdeCalendarWindow"+updateFieldId, "height="+windowHeight+",width=240,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1" );

	// build the calendar window content
	var writeString;
	if (document.documentElement.dir == "rtl")
		writeString = "<html dir=rtl>";
	else
		writeString = "<html>";
	writeString += "\n<head>\n";
	writeString += "<title>"+jdeWebGUIcalendarStrings[0]+"</title>\n";
	writeString += "<SCRIPT LANGUAGE=\"JavaScript\" SRC='"+jdeWebGUIjavaScriptPath+"'></SCRIPT>\n";
	writeString += "<style>\n";
	writeString += "BODY {\n";
	writeString += "font-size: 9pt;\n";
	writeString += "margin-left: 0;\n";
	writeString += "margin-top: 0;\n";
	writeString += "margin-right: 0;\n";
	writeString += "margin-bottom: 0;\n";
	writeString += "font-family: Arial,Helvetica,Verdana,Sans-Serif;\n";
	writeString += "color: #000000;\n";
	writeString += "background-color: #FFFFFF;\n";
	writeString += "}\n";
	writeString += "TABLE TD {\n";
	writeString += "font-size: 9pt;\n";
	writeString += "}\n";
	writeString += "INPUT {\n";
	writeString += "font-size: 8pt;\n";
	writeString += "}\n";
	writeString += "SELECT {\n";
	writeString += "font-size: 9pt;\n";
	writeString += "}\n";
	writeString += ".textfield {\n";
	writeString += "font-size: 9pt;\n";
	writeString += "color: #000000;\n";
	writeString += "background-color: #FFFFFF;\n";
	writeString += "border-width: 1px;\n";
	writeString += "border-style: solid;\n";
	writeString += "border-top-color: #999999;\n";
	writeString += "border-bottom-color: #CCCCCC;\n";
	writeString += "border-left-color: #999999;\n";
	writeString += "border-right-color: #CCCCCC;\n";
	writeString += "}\n";
	writeString += "</style>\n";
	writeString += "</head>\n";
	if (document.documentElement.dir == "rtl")
		writeString += "<body dir=rtl";
	else
		writeString += "<body";
	writeString += " onload=\"jdeWebGUIinitToday();jdeWebGUIbuildCaln();\">\n";
	writeString += "<div id=\"calendar\" align=\"center\"></div>\n";
	writeString += "<script>\n";
	writeString += "var jdeWebGUIdateseparator = \""+dateSeparator+"\";\n";
	writeString += "var jdeWebGUIdateformat = \""+dateFormat+"\";\n";
	writeString += "var jdeWebGUIisUTimeAMPM = !"+utc24+";\n";
	writeString += "var jdeWebGUIisUTime = "+utcEnabled+";\n";
	writeString += "var jdeWebGUIcalendarTextFieldId = \""+updateFieldId+"\";\n";
	writeString += "var jdeWebGUIcalendarStrings = new Array(";
	for (var i=0; i<jdeWebGUIcalendarStrings.length; i++)
	{
		if (i > 0)
			writeString += ", ";
		writeString += "\""+jdeWebGUIcalendarStrings[i]+"\"";
	}
	writeString += ");\n";
	writeString += "var jdeWebGUI_MINYEAR = "+minYear+";\n";
	writeString += "var jdeWebGUI_MAXYEAR = "+maxYear+";\n";
	writeString += "</script>\n";
	writeString += "</body>\n</html>\n";
	
	try
	{
		calWindow.focus();
	}
	catch (problem)
	{
		// Netscape 7 may not allow this
	}
	calWindow.document.write(writeString);
	calWindow.document.close(); // close the layout stream
}

var jdeWebGUImonthdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var jdeWebGUItodayDate;
var jdeWebGUIcurday;
var jdeWebGUIcurmonth;
var jdeWebGUIcurdate;
var jdeWebGUIcuryear;
var jdeWebGUIstartspaces;
var jdeWebGUIdays;
var jdeWebGUIcurDateObj = new Date();

function jdeWebGUIinitToday()
{
	jdeWebGUItodayDate = new Date();
	jdeWebGUIcurmonth = jdeWebGUItodayDate.getMonth();
	jdeWebGUIcurdate = jdeWebGUItodayDate.getDate();
	jdeWebGUIcuryear = jdeWebGUItodayDate.getFullYear();
	
	// Abbreviate the days
	jdeWebGUIdays = new Array(jdeWebGUIcalendarStrings[13], jdeWebGUIcalendarStrings[14], jdeWebGUIcalendarStrings[15], jdeWebGUIcalendarStrings[16], jdeWebGUIcalendarStrings[17], jdeWebGUIcalendarStrings[18], jdeWebGUIcalendarStrings[19]);
	for (var i=0; i<7; i++)
	{
		var startChar = jdeWebGUIdays[i].charAt(0);
		var need2Day = false;
		for (var j=0; j<7; j++)
		{
			if (i != j)
			{
				if (startChar == jdeWebGUIdays[j].charAt(0))
				{
					need2Day = true;
					continue;
				}
			}
		}
		if (need2Day)
			jdeWebGUIdays[i] = jdeWebGUIdays[i].substring(0,2);
		else
			jdeWebGUIdays[i] = startChar;
	}
}

function jdeWebGUIcalcCurrentValues()
{
	jdeWebGUIcurDateObj.setDate(jdeWebGUIcurdate);
	jdeWebGUIcurDateObj.setYear(jdeWebGUIcuryear);
	jdeWebGUIcurDateObj.setMonth(jdeWebGUIcurmonth);

	jdeWebGUIcurday = jdeWebGUIcurDateObj.getDay();

	if (((jdeWebGUIcuryear % 4 == 0) && !(jdeWebGUIcuryear % 100 == 0)) ||(jdeWebGUIcuryear % 400 == 0))
		jdeWebGUImonthdays[1] = 29;
	else
		jdeWebGUImonthdays[1] = 28;

	jdeWebGUIstartspaces=jdeWebGUIcurdate;

	while (jdeWebGUIstartspaces > 7)
		jdeWebGUIstartspaces-=7;

	jdeWebGUIstartspaces = jdeWebGUIcurday - jdeWebGUIstartspaces + 1;
	if (jdeWebGUIstartspaces < 0)
		jdeWebGUIstartspaces+=7;
}

function jdeWebGUIprevMonth()
{
	jdeWebGUIcurmonth--;

	if (jdeWebGUIcurmonth < 0)
	{
		jdeWebGUIcurmonth=11;
		jdeWebGUIcuryear--;
		if (jdeWebGUIcuryear < jdeWebGUI_MINYEAR)
			jdeWebGUIcuryear = jdeWebGUI_MAXYEAR;
	}
	jdeWebGUIbuildCaln();
}

function jdeWebGUInextMonth()
{
	jdeWebGUIcurmonth++;

	if (jdeWebGUIcurmonth > 11)
	{
		jdeWebGUIcurmonth=0;
		jdeWebGUIcuryear++;
		if (jdeWebGUIcuryear > jdeWebGUI_MAXYEAR)
			jdeWebGUIcuryear = jdeWebGUI_MINYEAR;
	}
	jdeWebGUIbuildCaln();
}

function jdeWebGUIprevYear()
{
	jdeWebGUIcuryear--;
	if (jdeWebGUIcuryear < jdeWebGUI_MINYEAR)
		jdeWebGUIcuryear = jdeWebGUI_MAXYEAR;

	jdeWebGUIbuildCaln();
}

function jdeWebGUInextYear()
{
	jdeWebGUIcuryear++;
	if (jdeWebGUIcuryear > jdeWebGUI_MAXYEAR)
		jdeWebGUIcuryear = jdeWebGUI_MINYEAR;

	jdeWebGUIbuildCaln();
}

function jdeWebGUIhighlightSel(field)
{
	field.style.color = "red";
}

function jdeWebGUIremHighlight(field, isWeekend)
{
	if (isWeekend)
		field.style.color = "black";//"#666666";
	else
		field.style.color = "black";
}

function jdeWebGUIremHighlightBtn(field)
{
	field.style.borderColor = "gray";
}

function jdeWebGUIsetCurDate(dateval)
{
	jdeWebGUIcurdate = dateval;
	jdeWebGUIbuildCaln();
}

function jdeWebGUIformatDate(strVal)
{
	var strDay = "" +jdeWebGUIcurDateObj.getDate(), strMonth = "", strYear = "";

	if (jdeWebGUIcurDateObj.getDate() < 10)
		strDay = "0" + jdeWebGUIcurDateObj.getDate();

	if (jdeWebGUIcurDateObj.getMonth() < 9)
		strMonth = "0" + (jdeWebGUIcurDateObj.getMonth()+1);
	else
		strMonth += (jdeWebGUIcurDateObj.getMonth()+1);

	var yrVal = jdeWebGUIcurDateObj.getYear();
	if(!document.all)
		yrVal = jdeWebGUIcurDateObj.getFullYear();
	if (jdeWebGUIdateformat.indexOf("E") != -1)
		strYear += yrVal;
	else
	{
		var yrTmp = yrVal%100;
		if (yrTmp < 10)
			strYear += "0" + yrTmp;
		else
			strYear += yrTmp;
	}
	if (jdeWebGUIdateformat == "DME" || jdeWebGUIdateformat =="DMY")
	{
		strVal = strDay + jdeWebGUIdateseparator + strMonth + jdeWebGUIdateseparator + strYear;
	}
	else if (jdeWebGUIdateformat =="EMD" || jdeWebGUIdateformat =="YMD")
	{
		strVal = strYear + jdeWebGUIdateseparator + strMonth + jdeWebGUIdateseparator + strDay;
	}
	else if (jdeWebGUIdateformat=="MDE" || jdeWebGUIdateformat=="MDY")
	{
		strVal = strMonth + jdeWebGUIdateseparator + strDay + jdeWebGUIdateseparator + strYear;
	}
	//UTime stuff
	if (jdeWebGUIisUTime)
	{
		var hrVal = new Number(document.getElementById("utimeHR").value);
		if (jdeWebGUIisUTimeAMPM )
		{
			var ampmField = document.getElementById("utimeAMPM");
			if (ampmField.innerHTML == jdeWebGUIcalendarStrings[28]) // PM
				hrVal += 12;
		}
		var theHours = ""+hrVal;
		if (theHours == "")
			theHours = "00";
		var theMinutes = ""+document.getElementById("utimeMIN").value;
		if (theMinutes == "")
			theMinutes = "00";
		var theSeconds = ""+document.getElementById("utimeSEC").value;
		if (theSeconds == "")
			theSeconds = "00";
		strVal +=" " + theHours;
		strVal +=":" + theMinutes;
		strVal +=":" + theSeconds;
		strVal +=" " + document.getElementById("utimeTZ").options[document.getElementById("utimeTZ").selectedIndex].text;
	}

	return strVal;
}

function jdeWebGUIdoAMPM(amString, pmString)
{
	var ampmField = document.getElementById("utimeAMPM");
	if (ampmField.innerHTML == amString)
		ampmField.innerHTML = pmString;
	else
		ampmField.innerHTML = amString;
}

function jdeWebGUIbuildCaln()
{
	jdeWebGUIcalcCurrentValues();
	writeString = "<table dir=ltr><tr><td>";
	var rtlEnabled = false;
	if (document.documentElement.dir == "rtl")
	{
		rtlEnabled = true;
	}
	writeString += "<table border=0 cellpadding=0 cellspacing=0>\n";
	writeString += "<tr valign=MIDDLE>\n";
	if (rtlEnabled)
	{
		writeString += "<td align=left>";
		writeString += "<A ID=va_caln_cancel title=\""+jdeWebGUIcalendarStrings[21]+"\" href=\"javascript:jdeWebGUIonCancelCaln()\"><IMG onmouseover=\"this.src='"+ window["WEBGUIRES_images_tiny_cancel_mo_gif"] +"'\" onmouseout=\"this.src='"+ window["WEBGUIRES_images_tiny_cancel_gif"] + "'\" src=\""+ window["WEBGUIRES_images_tiny_cancel_gif"] +"\" alt=\"" + jdeWebGUIcalendarStrings[21] + "\" border=0></A>";
		writeString += "<A ID=va_caln_ok title=\""+jdeWebGUIcalendarStrings[20]+"\" href=\"javascript:jdeWebGUIonOKCaln()\"><IMG onmouseover=\"this.src='"+ window["WEBGUIRES_images_tiny_ok_mo_gif"] + "'\" onmouseout=\"this.src='"+ window["WEBGUIRES_images_tiny_ok_gif"] + "'\" src=\""+ window["WEBGUIRES_images_tiny_ok_gif"] +"\" alt=\"" +jdeWebGUIcalendarStrings[20]+ "\" border=0></A>";
		writeString += "</td>\n";
		writeString += "<td align=right><b>"+ jdeWebGUIcalendarStrings[0]+ "</b></td>\n";
	}
	else
	{
		writeString += "<td align=left><b>"+ jdeWebGUIcalendarStrings[0]+ "</b></td>\n";
		writeString += "<td align=right>";
		writeString += "<A ID=va_caln_ok title=\""+jdeWebGUIcalendarStrings[20]+"\" href=\"javascript:jdeWebGUIonOKCaln()\"><IMG onmouseover=\"this.src='"+ window["WEBGUIRES_images_tiny_ok_mo_gif"] + "'\" onmouseout=\"this.src='"+ window["WEBGUIRES_images_tiny_ok_gif"] + "'\" src=\""+ window["WEBGUIRES_images_tiny_ok_gif"] + "\" alt=\"" +jdeWebGUIcalendarStrings[20]+ "\" border=0></A>";
		writeString += "<A ID=va_caln_cancel title=\""+jdeWebGUIcalendarStrings[21]+"\" href=\"javascript:jdeWebGUIonCancelCaln()\"><IMG onmouseover=\"this.src='"+ window["WEBGUIRES_images_tiny_cancel_mo_gif"] + "'\" onmouseout=\"this.src='"+ window["WEBGUIRES_images_tiny_cancel_gif"] + "'\" src=\""+ window["WEBGUIRES_images_tiny_cancel_gif"] + "\" alt=\"" + jdeWebGUIcalendarStrings[21]+ "\" border=0></A>";
		writeString += "</td>\n";
	}
	writeString += "</tr>\n";
	writeString += "<tr valign=top>\n";
	writeString += "<td colspan=2 align=center><HR></td>\n";
	writeString += "</tr>\n";
	writeString += "<tr><td colspan=2 align=center><table border=0 cellpadding=0 cellspacing=0>\n";
	writeString += "<tr valign=MIDDLE>\n";
	writeString += "<td colspan=7><table width=100% border=0 cellpadding=0 cellspacing=0><tr>";
	if (rtlEnabled)
	{
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUInextYear()\" title=\"" + jdeWebGUIcalendarStrings[25] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><img src='"+ window["WEBGUIRES_images_tiny_moveallleft_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[25] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallleft_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallleft_gif"] + "'\" border=0 width=20 height=20></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUInextMonth()\" title=\"" + jdeWebGUIcalendarStrings[24] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><nobr><img src='"+ window["WEBGUIRES_images_tiny_moveleft_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[24] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveleft_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveleft_gif"] + "'\" border=0 width=20 height=20 align=absmiddle>&nbsp;</nobr></td>\n";
		writeString += "<td width=120 nowrap align=center><b>" + jdeWebGUIcalendarStrings[jdeWebGUIcurmonth+1] + " " + jdeWebGUIcuryear + "</b></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUIprevMonth()\" title=\"" + jdeWebGUIcalendarStrings[23] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><nobr>&nbsp;<img src='"+ window["WEBGUIRES_images_tiny_moveright_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[23] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveright_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveright_gif"] + "'\" border=0 width=20 height=20 align=absmiddle></nobr></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUIprevYear()\" title=\"" + jdeWebGUIcalendarStrings[22] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><img src='"+ window["WEBGUIRES_images_tiny_moveallright_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[22] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallright_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallright_gif"] + "'\" border=0 width=20 height=20></td>\n";
	}
	else
	{
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUIprevYear()\" title=\"" + jdeWebGUIcalendarStrings[22] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><img src='"+ window["WEBGUIRES_images_tiny_moveallleft_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[22] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallleft_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallleft_gif"] + "'\" border=0 width=20 height=20></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUIprevMonth()\" title=\"" + jdeWebGUIcalendarStrings[23] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><nobr>&nbsp;<img src='"+ window["WEBGUIRES_images_tiny_moveleft_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[23] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveleft_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveleft_gif"] + "'\" border=0 width=20 height=20 align=absmiddle></nobr></td>\n";
		writeString += "<td width=120 nowrap align=center><b>" + jdeWebGUIcalendarStrings[jdeWebGUIcurmonth+1] + " " + jdeWebGUIcuryear + "</b></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUInextMonth()\" title=\"" + jdeWebGUIcalendarStrings[24] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><nobr><img src='"+ window["WEBGUIRES_images_tiny_moveright_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[24] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveright_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveright_gif"] + "'\" border=0 width=20 height=20 align=absmiddle>&nbsp;</nobr></td>\n";
		writeString += "<td style=\"cursor:pointer\" onclick=\"javascript:jdeWebGUInextYear()\" title=\"" + jdeWebGUIcalendarStrings[25] +"\" onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlightBtn(this)\"><img src='"+ window["WEBGUIRES_images_tiny_moveallright_gif"] + "' alt=\"" + jdeWebGUIcalendarStrings[25] + "\" onMouseOver=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallright_mo_gif"] + "'\" onMouseOut=\"this.src='"+ window["WEBGUIRES_images_tiny_moveallright_gif"] + "'\" border=0 width=20 height=20></td>\n";
	}
	writeString += "</tr></table></td>\n"
	writeString += "</tr>\n";
	writeString += "<tr valign=top>\n";
	writeString += "<td colspan=7 align=center><HR></td>\n";
	writeString += "</tr>\n";
	writeString += "<tr style=\"text-decoration: underline\" valign=MIDDLE>\n";
	for (var i=0; i<7; ++i)
		writeString += "<td width=25 align=center>" + jdeWebGUIdays[i] +"</td>\n";
	writeString += "</tr>\n";
	writeString += "<tr valign=MIDDLE>\n";
	for (s=0;s<jdeWebGUIstartspaces;s++)
		writeString += "<td> </td>\n";

	x = jdeWebGUIstartspaces; count=1;
	var rowsDrawn = 0;

	while (count <= jdeWebGUImonthdays[jdeWebGUIcurmonth])
	{
		for (b = jdeWebGUIstartspaces;b<7;b++)
		{
			linktrue=false;

			writeString += "<td align=right style='cursor:pointer;";
			if ( (((count + x) % 7) == 0) || (((count + x) % 7) == 1) ) // is weekend
			{
				writeString += "font-style:italic;'";

				if (count <= jdeWebGUImonthdays[jdeWebGUIcurmonth])
				{
					if (count==jdeWebGUIcurdate) // if this day is selected, next click shall select it
						writeString += " onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlight(this, true)\" onclick=\"javascript:jdeWebGUIonOKCaln()\"";
					else // a single click will highlight it
						writeString += " onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onDblClick=\"javascript:jdeWebGUIonOKCaln()\" onmouseout=\"javascript:jdeWebGUIremHighlight(this, true)\" onclick=\"javascript:jdeWebGUIsetCurDate("+count+")\"";
				}
			}
			else
			{
				writeString += "'";

				if (count <= jdeWebGUImonthdays[jdeWebGUIcurmonth])
				{
					if (count==jdeWebGUIcurdate) // if this day is selected, next click shall select it
						writeString += " onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onmouseout=\"javascript:jdeWebGUIremHighlight(this, false)\" onclick=\"javascript:jdeWebGUIonOKCaln()\"";
					else // a single click will highlight it
						writeString += " onmouseover=\"javascript:jdeWebGUIhighlightSel(this)\" onDblClick=\"javascript:jdeWebGUIonOKCaln()\" onmouseout=\"javascript:jdeWebGUIremHighlight(this, false)\" onclick=\"javascript:jdeWebGUIsetCurDate("+count+")\"";
				}
			}

			writeString += ">";

			if (count==jdeWebGUIcurdate)
				writeString += "<font color='#FF0000'><strong>";

			if (count <= jdeWebGUImonthdays[jdeWebGUIcurmonth])
				writeString += count;
			else
				writeString += " ";

			if (count==jdeWebGUIcurdate)
				writeString += "</strong></font>";

			writeString += "&nbsp;&nbsp;</td>\n";
			count++;
		}
		writeString += "</tr>\n";
		if (count <= jdeWebGUImonthdays[jdeWebGUIcurmonth])
			writeString += "<tr valign=MIDDLE>\n";
		rowsDrawn++;
		jdeWebGUIstartspaces=0;
	}
	while (rowsDrawn++ < 6) // months can have from 4 to 6 actual rows in the calendar
		writeString += "<tr valign=MIDDLE><td>&nbsp;</td></tr>";

	writeString += "</table></td></tr>\n";
	if(jdeWebGUIisUTime)
	{
		writeString += "<tr valign=MIDDLE><td colspan=7 align=center><HR></td></tr>";
		writeString += "<tr valign=MIDDLE><td colspan=7>";
		if (rtlEnabled)
			writeString += "<table align=right dir=rtl><tr>";
		else
			writeString += "<table><tr>";
		writeString += "<td width=20>&nbsp;</td><td><b>"+jdeWebGUIcalendarStrings[26]+"</b></td>";
		writeString += "<td width=30>&nbsp;</td><td width=35>&nbsp;</td>";
		writeString += "<td colspan=3><b>+/- UTC</b></td>";
		writeString += "</tr></table>";
		writeString += "</td></tr>";
		writeString += "<tr valign=MIDDLE><td colspan=7 align=center><HR></td></tr>";
		writeString += "<tr valign=MIDDLE><td colspan=7 align=center>";

		if (rtlEnabled)
			writeString += "<table dir=rtl><tr>";
		else
			writeString += "<table><tr>";

		var utimeHrs = jdeWebGUItodayDate.getHours();
		var isPM=false;
		if (jdeWebGUIisUTimeAMPM && utimeHrs>=12)
		{
			utimeHrs -= 12;
			isPM=true;
		}

		if (utimeHrs < 10)
			utimeHrs = "0" + utimeHrs;

		var utimeMin = jdeWebGUItodayDate.getMinutes();
		if (utimeMin < 10)
			utimeMin = "0" + utimeMin;

		var utimeSec = jdeWebGUItodayDate.getSeconds();
		if (utimeSec < 10)
			utimeSec = "0" + utimeSec;

		if (rtlEnabled)
		{
			writeString += "<td><nobr><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeSEC\" value="+utimeSec +">:</td>";
			writeString += "<td><nobr><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeMIN\" value="+utimeMin +">:</nobr></td>"
			writeString += "<td><nobr><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeHR\" value="+utimeHrs+"></nobr>"
			if (jdeWebGUIisUTimeAMPM)
			{
				writeString += "<td><A href=\"javascript:jdeWebGUIdoAMPM('"+jdeWebGUIcalendarStrings[27]+"', '"+jdeWebGUIcalendarStrings[28]+"')\" id=\"utimeAMPM\">";
				if (isPM)
					writeString += jdeWebGUIcalendarStrings[28]; // PM
				else
					writeString += jdeWebGUIcalendarStrings[27]; // AM
				writeString += "</A>";
			}
			writeString += "</td>";
		}
		else
		{
			writeString += "<td><nobr><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeHR\" value="+utimeHrs+">:</nobr></td>"
			writeString += "<td><nobr><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeMIN\" value="+utimeMin +">:</nobr></td>"
			writeString += "<td><input type=text class='textfield' style='width:20' maxlength=2 id=\"utimeSEC\" value="+utimeSec +">";
			if (jdeWebGUIisUTimeAMPM)
			{
				writeString += "<td><A href=\"javascript:jdeWebGUIdoAMPM('"+jdeWebGUIcalendarStrings[27]+"', '"+jdeWebGUIcalendarStrings[28]+"')\" id=\"utimeAMPM\">";
				if (isPM)
					writeString += jdeWebGUIcalendarStrings[28]; // PM
				else
					writeString += jdeWebGUIcalendarStrings[27]; // AM
				writeString += "</A>";
			}
			writeString += "</td>";
		}

		writeString += "<td width=20>&nbsp;</td>";
		writeString += "<td><select size=1 id=\"utimeTZ\">";
		writeString += "<option>UTC </option>";
		writeString += "<option>UTC-12:00</option>";
		writeString += "<option>UTC-11:00</option>";
		writeString += "<option>UTC-10:00</option>";
		writeString += "<option>UTC-09:00</option>";
		writeString += "<option>UTC-08:00</option>";
		writeString += "<option>UTC-07:00</option>";
		writeString += "<option>UTC-06:00</option>";
		writeString += "<option>UTC-05:00</option>";
		writeString += "<option>UTC-04:00</option>";
		writeString += "<option>UTC-03:00</option>";
		writeString += "<option>UTC-02:00</option>";
		writeString += "<option>UTC-01:00</option>";
		writeString += "<option>UTC+01:00</option>";
		writeString += "<option>UTC+02:00</option>";
		writeString += "<option>UTC+03:00</option>";
		writeString += "<option>UTC+03:30</option>";
		writeString += "<option>UTC+04:00</option>";
		writeString += "<option>UTC+04:30</option>";
		writeString += "<option>UTC+05:00</option>";
		writeString += "<option>UTC+05:30</option>";
		writeString += "<option>UTC+05:45</option>";
		writeString += "<option>UTC+06:00</option>";
		writeString += "<option>UTC+06:30</option>";
		writeString += "<option>UTC+07:00</option>";
		writeString += "<option>UTC+08:00</option>";
		writeString += "<option>UTC+09:00</option>";
		writeString += "<option>UTC+09:30</option>";
		writeString += "<option>UTC+10:00</option>";
		writeString += "<option>UTC+11:00</option>";
		writeString += "<option>UTC+12:00</option>";
		writeString += "<option>UTC+13:00</option>";
		writeString += "</select></td>\n";

		writeString += "</tr></table></td>";
		writeString += "</tr>\n";
	}
	writeString += "</table>\n"; // close of above UTime

	writeString += "</table>\n"; // close of dates
	writeString += "</td></tr></table>\n"; // close of internal layout
	writeString += "</td></tr></table>\n"; // close of outer border
	document.getElementById("calendar").innerHTML = writeString;
}

function jdeWebGUIonOKCaln()
{
	var strVal = jdeWebGUIformatDate();
	jdeWebGUIupdateOpenerFieldValue(jdeWebGUIcalendarTextFieldId, strVal, true);
}

function jdeWebGUIonCancelCaln()
{
	self.close();
}

// END OF SCRIPTS FOR CALENDAR
//////////////////////////////////

///////////////////////////////////////////////////////////////
// START OF UTILITY SCRIPTS

function isCSSLevel1Supported()
{
	try { return jdeWebGUICSS1; } catch (problem) { return false; }
}

function isDOMLevel1Supported()
{
	try { return jdeWebGUIDOM1; } catch (problem) { return false; }
}

function isDOMLevel2Supported()
{
	try { return jdeWebGUIDOM2; } catch (problem) { return false; }
}

function isDynamicMenusSupported()
{
	try { return jdeWebGUIDynamicMenus; } catch (problem) { return false; }
}

function isDynamicOptionsSupported()
{
	try { return jdeWebGUIDynamicOptions; } catch (problem) { return false; }
}

function isEventOffsetCoordsSupported()
{
	try { return jdeWebGUIEventOffsetCoords; } catch (problem) { return false; }
}

function isSmallScreenSupported()
{
	try { return jdeWebGUISmallScreen; } catch (problem) { return false; }
}

function isAppletsSupported()
{
	try { return jdeWebGUIApplets; } catch (problem) { return false; }
}

function getAbsoluteLeftPos(item, adjustScrollbars)
{
	var itemLeft= item.offsetLeft + document.body.offsetLeft;
	var itemParent = item.offsetParent;

	while(itemParent)
	{
		if (document.documentElement.dir == "rtl" && itemParent.offsetLeft < 0)
			itemLeft += itemParent.style.posLeft;
		else
			itemLeft += itemParent.offsetLeft;
		if(true == adjustScrollbars && itemParent != document.body)
			itemLeft -= itemParent.scrollLeft;
		itemParent = itemParent.offsetParent;
	}

	return itemLeft;
}

function getAbsoluteTopPos(item, adjustScrollbars)
{
	var itemTop= item.offsetTop + document.body.offsetTop;
        try
        {
	var itemParent = item.offsetParent;

	while(itemParent)
	{
		itemTop += itemParent.offsetTop;
		if(true == adjustScrollbars && itemParent != document.body)
			itemTop -= itemParent.scrollTop;

		itemParent = itemParent.offsetParent;
	}
        }
        catch(problem)
        {
            // OPS gets an unspecified exception on a refresh.
        }

	return itemTop;
}

function showMotion(elem)
{
        if(elem.name)
        {
            // if element.name exists then use it and create the url using _e1URLFactory
            var dot = elem.name.indexOf('.gif');
            if (dot != -1)
                    elem.name= elem.name.substring(0,dot)+ "mo.gif";    
            e1UrlCreator = _e1URLFactory.createInstance(_e1URLFactory.URL_TYPE_RES);
            e1UrlCreator.setURI(elem.name);  
            elem.src = e1UrlCreator.toString();
        }
        else
        {
	var dot = elem.src.indexOf('.gif');
	if (dot != -1)
		elem.src= elem.src.substring(0,dot)+ "mo.gif";
}
}

function removeMotion(elem)
{
        if(elem.name)
        {
            // if element.name exists then use it and create the url using _e1URLFactory
            var dot = elem.name.indexOf('mo.gif');
            if (dot != -1)
                    elem.name= elem.name.substring(0,dot)+ ".gif";    
            e1UrlCreator = _e1URLFactory.createInstance(_e1URLFactory.URL_TYPE_RES);
            e1UrlCreator.setURI(elem.name);  
            elem.src = e1UrlCreator.toString();
        }
        else
        {
	var dot = elem.src.indexOf('mo.gif');
	if (dot != -1)
		elem.src= elem.src.substring(0,dot)+ ".gif";

        }
}

// This function Completely equivilant to "showMotion" but it deals with RTL images.
// N.B Some images fliped in RTL, then we add _rtl to the end of the image file name
function showMotion_rtl(elem)
{
        if(elem.name)
        {
            // if element.name exists then use it and create the url using _e1URLFactory
            var dot = elem.name.indexOf('_rtl.gif');
            if (dot != -1)
                    elem.name= elem.name.substring(0,dot)+ "mo_rtl.gif";    
            e1UrlCreator = _e1URLFactory.createInstance(_e1URLFactory.URL_TYPE_RES);
            e1UrlCreator.setURI(elem.name);  
            elem.src = e1UrlCreator.toString();
        }
        else
        {
	var dot = elem.src.indexOf('_rtl.gif');
	if (dot != -1)
		elem.src= elem.src.substring(0,dot)+ "mo_rtl.gif";
}
}

// This function completely equivilant to "removeMotion" but it deals with RTL images.
function removeMotion_rtl(elem)
{
        if(elem.name)
        {
            // if element.name exists then use it and create the url using _e1URLFactory
            var dot = elem.name.indexOf('mo_rtl.gif');
            if (dot != -1)
                    elem.name= elem.name.substring(0,dot)+ "_rtl.gif";    
            e1UrlCreator = _e1URLFactory.createInstance(_e1URLFactory.URL_TYPE_RES);
            e1UrlCreator.setURI(elem.name);  
            elem.src = e1UrlCreator.toString();
        }
        else
        {
	var dot = elem.src.indexOf('mo_rtl.gif');
	if (dot != -1)
		elem.src= elem.src.substring(0,dot)+ "_rtl.gif";
}
}

function jdeWebGUIgetLocationParameter(parameterName)
{
	// @todo handle multiple params of the same name
	// @todo lookup the parameter name with a leading "?" and leading "&" so other params that contain the name will not be mistakenly received
	var myURL = ""+self.location;
	var index = myURL.lastIndexOf(parameterName+"=");
	var parameterValue = "";
	if (index > 1)
	{
		myURL = myURL.substr(index+parameterName.length+1, myURL.length);
		index = myURL.indexOf("&");
		if (index == -1)
			parameterValue = myURL;
		else
			parameterValue = myURL.substring(0,index);
	}
	return parameterValue;
}

function jdeWebGUIupdateOpenerFieldValue(documentFieldId, theValue, closeSelf)
{
	window.opener.document.getElementById(documentFieldId).value=theValue;
	if (closeSelf)
	{
		self.close();
	}
}

function jdeWebGUIReplaceSubstring(source, pattern, replace)
{
	return source.replace(new RegExp(pattern, "g"), replace);
}

function PSStringBuffer()
{
	this.maxStreamLength = (document.all?100:10000);
	this.data = new Array(100);
	this.iStr = 0;
	this.append = function(obj)
	{
		this.data[this.iStr++] = obj;
		if (this.data.length > this.maxStreamLength)
		{
			this.data = [this.data.join("")];
			this.data.length = 100;
			this.iStr = 1;
		}
		return this;
	};
	this.toString = function()
	{
		return this.data.join("");
	};
}

PSStringBuffer._joinFunc = Array.prototype.join;
PSStringBuffer.concat = function () {
	arguments.join = this._joinFunc;
	return arguments.join("")
}

var PI_MOTION_TIMER=document.all?500:100;
var piStopTimout;

function ProcessingIndicator()
{
}

ProcessingIndicator.createInstance = function(procText, maxWidth, height, topOffset, rightOffset){
    ProcessingIndicator.theInstance = new ProcessingIndicator();
    ProcessingIndicator.theInstance.PIText = procText;
    ProcessingIndicator.theInstance.isProcIndDisplayed = false;
    ProcessingIndicator.theInstance.procIndicatorElem = null;
    ProcessingIndicator.theInstance.movePIIndicatorTimer = null;
    ProcessingIndicator.theInstance.height=height;
    ProcessingIndicator.theInstance.maxWidth=maxWidth;
    ProcessingIndicator.theInstance.topOffset=topOffset;
    ProcessingIndicator.theInstance.rightOffset=rightOffset;
    return ProcessingIndicator.theInstance;
}

ProcessingIndicator.getInstance = function()
{
    return ProcessingIndicator.theInstance;
}

ProcessingIndicator.positionProcessingIndicator = function()
{
	if(ProcessingIndicator.theInstance != null)
		ProcessingIndicator.theInstance.position();
}
ProcessingIndicator.stopProcessingIndicator= function()
{
    if(ProcessingIndicator.theInstance != null){
        ProcessingIndicator.theInstance.display(false);
        //delete ProcessingIndicator.theInstance;
        ProcessingIndicator.theInstance = null;
    }
    if(piStopTimout != null){
        window.clearTimeout(piStopTimout);
        piStopTimout = null;
    }
}

// Create the processing indicator element
ProcessingIndicator.prototype.createPIElem = function(){
	var elem = document.createElement("div");
	var leftPos = document.body.clientWidth + document.body.scrollLeft - this.maxWidth - this.rightOffset;
	if(document.documentElement.dir == "rtl")
		leftPos = this.rightOffset;

	document.body.appendChild(elem);
	elem.id = "procIndicatorFloatLyr";
	elem.noWrap = "true";
	elem.innerHTML = PSStringBuffer.concat("<table cellpadding=0 cellspacing=0 border=0><tr nowrap>",
                     "<td style='padding-top:1px; padding-left:3px; padding-right:2px;'>",
                     "<img src='", window["WEBGUIRES_images_circular_slush_gif"], "' width=16 height=16>",
                     "</td><td>",
                     "<span id=\"procIndicatorTextSpan\" nowrap style='height:",this.height,"; padding-top:2px; font-family:arial; color:rgb(65,65,65); font-size:10pt; font-weight:bold; overflow:hidden; text-overflow:ellipsis; white-space:nowrap'>",
                     this.PIText,"...&nbsp;&nbsp;" ,
                     "</span>",
                     "</td></tr></table>");                           
	elem.style.display = "none";
	elem.style.position = "absolute";
	elem.style.left = leftPos;
	elem.style.top = this.topOffset + "px";
	elem.style.height = this.height + "px";
	elem.style.zIndex = 2000000000; // assuming minimum 32-bit integer
	elem.style.backgroundColor = "#FFF2A9"; 
	elem.style.borderWidth = "1px"; 
	elem.style.borderStyle = "solid"; 
	elem.style.borderColor = "#B3A976";   

        return elem;
}

	
ProcessingIndicator.prototype.position = function(){		
	var oldY = document.all? this.procIndicatorElem.style.pixelTop : this.procIndicatorElem.style.top; 
	var newY = document.body.scrollTop + this.topOffset;
	var posChanged = false;
	//in Mozilla/Firefox/Safari, the oldY is in the format of "123px", so strip the px
	if(!document.all)
	    oldY = oldY.substring(0, oldY.length-2);

	if(oldY != newY){	
		if(document.all)
			this.procIndicatorElem.style.pixelTop = newY;
		else
			this.procIndicatorElem.style.top = newY + "px";
		posChanged = true;
	}
	var oldX = document.all? this.procIndicatorElem.style.pixelLeft : this.procIndicatorElem.style.left; 
	var newX = document.body.clientWidth + document.body.scrollLeft - this.maxWidth - this.rightOffset;
	if(document.documentElement.dir == "rtl")
		newX = document.body.scrollLeft + this.rightOffset;	
	if(!document.all)
	    oldX = oldX.substring(0, oldX.length-2);
	if(oldX != newX){
		if(document.all)
			this.procIndicatorElem.style.pixelLeft = newX;
		else
			this.procIndicatorElem.style.left = newX + "px";
		posChanged = true;
	}

	if(posChanged)
	{
		removeItemShadow(this.procIndicatorElem, this.procIndMask);
		showItemShadow(this.procIndicatorElem, this.procIndMask);
	}
}
	
ProcessingIndicator.prototype.display = function(show, overrideText)
{
	this.procIndicatorElem = document.getElementById("procIndicatorFloatLyr");

	if(this.procIndicatorElem == null)
        {
            this.procIndicatorElem = this.createPIElem();
            if (document.all)  //IE
            {
                this.procIndMask = new MaskFrame("procIndMask", this.procIndicatorElem);
            }
            else
            {
                this.procIndMask = null;
            }
	}

        else
        {
            if (overrideText)
            {
                removeItemShadow(this.procIndicatorElem);
                document.getElementById("procIndicatorTextSpan").innerHTML = this.PIText + "...&nbsp;&nbsp;";
                showItemShadow(this.procIndicatorElem);
            }
        }
	if(this.procIndicatorElem != null)
	{
		if(show && !this.isProcIndDisplayed)
		{
			this.procIndicatorElem.style.display = "block";
			showItemShadow(this.procIndicatorElem, this.procIndMask);
			this.movePIIndicatorTimer = window.setInterval("ProcessingIndicator.positionProcessingIndicator()", PI_MOTION_TIMER);
			this.isProcIndDisplayed = true;
		}
		else
		{
			removeItemShadow(this.procIndicatorElem, this.procIndMask);
			this.procIndicatorElem.style.display = "none";
			if(this.isProcIndDisplayed){ // clear our timer
				window.clearInterval(this.movePIIndicatorTimer);	
			}
			this.isProcIndDisplayed = false; 		
		}	
	}
}

// Since IFRAME masking techniques for floating DIVs are only required to address 
// a zIndex bug in IE, don't even define this object if using Firefox
if (document.all)  //IE
{
    function MaskFrame(defaultId, fixedParentElem) 
    {
        var maskFrame = document.createElement('iframe')
        maskFrame.src = window["WEBGUIRES_https_dummy_html"];
        maskFrame.style.display = "none";
        maskFrame.style.position = "absolute";
        maskFrame.id = this.defaultId = defaultId;
        this.domElement = maskFrame;
        if (fixedParentElem)
        {
            this.setFixedParent(fixedParentElem);
        }
    }
    
    /**
      The setFixedParent method is ONLY used by non-shared Masks (currently this
      is only the ProcessingInd mask).  It is used to stop resetting the 
      parentNode for the IFRAME element repeatedly, which appears to be doing
      nasty things to the DOM.  Once the parent is fixed to the IFRAME, it can
      never be reset using the attach or detach methods.
    **/
    MaskFrame.prototype.setFixedParent = function(elem)
    {
        if (!elem)
        {
            return;
        }
        
        elem.parentNode.appendChild(this.domElement);
        
        //now repoint the attach/detach methods to just show/hide instead
        //this allows an "owned" maskFrame item to maintain it's place in
        //the DOM without being added and removed incessently.
        this.attachMask = this.showMask;
        this.detachMask = this.hideMask;
    }
    
    MaskFrame.prototype.attachMask = function(elem)
    {
        if (!elem)
        {
            return;
        }
        
        var maskFrame = this.domElement;
        
        if (maskFrame.parentNode != null)  //already attached to something
        {
            this.detachMask();
        }
        elem.parentNode.appendChild(maskFrame);
        this.showMask(elem);
    }
    
    MaskFrame.prototype.showMask = function(elem)
    {
        if (!elem)
        {
            return;
        }
        
        var maskFrame = this.domElement;
        
        maskFrame.style.top = parseInt(elem.style.top);
        maskFrame.style.left = parseInt(elem.style.left);
        maskFrame.style.width = elem.offsetWidth;
        maskFrame.style.height = elem.offsetHeight;
        maskFrame.style.zIndex = elem.style.zIndex - 1;
        maskFrame.style.display = "block";
        maskFrame.id = elem.id + "-maskframe";
    }
    
    MaskFrame.prototype.detachMask = function()
    {
        
	this.hideMask();

        var maskFrame = this.domElement;

        //test parent first, in case detach called twice consecutively
        if (maskFrame.parentNode != null)
        {
            maskFrame.parentNode.removeChild(maskFrame);
        }
    }

    MaskFrame.prototype.hideMask = function()
    {
        var maskFrame = this.domElement;
        
        maskFrame.style.display = "none";
        maskFrame.id = this.defaultId;
    }
    /** Create a single multi-use masking IFRAME for generic floating DIV needs **/
    var GlobalMaskFrame = new MaskFrame("globalMask");
}

function PopupWindow(id, resizable, titleInfo, eventListener){
	this.id = id;
	this.resizable = resizable;
	this.eventListener = eventListener;

	window[id] = this;
	
	this.titleInfo = titleInfo;
	this.minWidth = 188;
	this.minHeight = 60;		
	this.windowElem = null;
	this.contentHTML = null;
        this.namespace=null;
		
	//variables used for moving the window
	this.titleElem = null;
	this.titleHasCapture = false; 
	this.initWindowX = this.initWindowY = this.initClientX = this.initClientY = 0;

	//variables used for resizing the window
	this.containerHasCapture = false;
	this.initDirection = "";
	this.initWindowWidth = this.initWindowHeight = 0;
	
    this.windowElem = document.getElementById(id);
	if(this.windowElem == null){
		this._createPopupElem(id);
		this.windowElem = document.getElementById(id);
	}	
}

PopupWindow.prototype.RESIZE_TOLERANCE = 8;
PopupWindow.prototype.currentInstance = null;
//this should be larger than the layer(z-index) defined as 
//UIBLOCKING_LAYER_ZINDEX for UIBlocking layer in UIBlocking.js
var MSGFORM_LAYER_ZINDEX = 100002;
PopupWindow.prototype.setMinSize = function(width, height){
	this.minWidth = width;
	this.minHeight = height;
}

PopupWindow.prototype.resize = function (width, height)
{
    this.windowElem.style.width = width;
    this.windowElem.style.height = height;
}

PopupWindow.prototype._createPopupElem = function(id){
	var elem = document.createElement("div");
	document.body.appendChild(elem);
	elem.id = id;
	elem.style.backgroundColor = "#ffffff";
	elem.style.zIndex = MSGFORM_LAYER_ZINDEX;
	elem.style.position = 'absolute';
	elem.style.overflow = 'hidden';	
}

PopupWindow.prototype.setContent = function(htmlContent){
    this.contentHTML = htmlContent;
}

PopupWindow.prototype.setNameSpace = function(namespace){
    this.namespace = namespace;
}

PopupWindow.prototype.getWidth = function(){
	return parseInt(this.windowElem.style.width);
}

PopupWindow.prototype.getHeight = function(){
	return parseInt(this.windowElem.style.height);
}

PopupWindow.prototype._buildHTML = function(){
	var sb = new PSStringBuffer();
	sb.append("<table border=0 cellspacing=0 cellpadding=0 width=100% height=100%>");
	sb.append("<tr><td style=\"height:18px;\"><table width=100% height=100% border=0 cellspacing=0 cellpadding=0>");
	sb.append("<tr");
	if(!this.titleInfo.backgroundImage)
		sb.append(" style=\"background-color: #C9DAEB\"");
	sb.append("><td");
	if(this.titleInfo.backgroundImage)
		sb.append(" background='").append(this.titleInfo.backgroundImage).append("'");
	sb.append(">");
	
	if(this.titleInfo.titleIcon){
		sb.append("<img border=0 hspace=3 src='"); 
		sb.append(this.titleInfo.titleIcon).append("' alt=\"").append(this.titleInfo.titleText).append("\">"); 
	}else{
		sb.append("&nbsp;");
	}
	
	var titleTextColor = this.titleInfo.titleTextColor?this.titleInfo.titleTextColor: "#ffffff";
	sb.append("</td><td style=\"font-size:10pt;font-weight:bold;color:").append(titleTextColor).append("\"");
	if(this.titleInfo.backgroundImage)
		sb.append(" background='").append(this.titleInfo.backgroundImage).append("'");
	sb.append("><nobr><div id=popupWindowTitle").append(this.id);
	sb.append(" title=\"").append(this.titleInfo.titleText).append("\"");
	sb.append(" style=\"overflow:hidden; text-overflow:ellipsis;\">").append(this.titleInfo.titleText);
	sb.append("</div></nobr></td>");

	if(this.titleInfo.hasAbout){
		sb.append("<td align=right");
                if(this.titleInfo.backgroundImage)
                    sb.append(" background='").append(this.titleInfo.backgroundImage).append("'");
		sb.append("><img style=\"cursor:pointer\" onclick=javascript:" + this.namespace + "about() align=absmiddle alt=\"").append(this.titleInfo.aboutText).append("\"; title = \"").append(this.titleInfo.aboutText).append("\"");
		sb.append(" src='").append(window["E1RES_img_jdeabout_gif"]).append("' name='/img/jdeabout.gif' onmouseOver=showMotion(this) onmouseOut=removeMotion(this) hspace=3 border=0>");
		sb.append("</td>");
	}
	if(this.titleInfo.hasClose){
		sb.append("<td align=right");
		if(this.titleInfo.backgroundImage)
			sb.append(" background='").append(this.titleInfo.backgroundImage).append("'");
		sb.append(">");		
		sb.append("<img style=\"cursor:pointer\" onclick=\"javascript:window['").append(this.id).append("'].onClose()\"");
	        sb.append(" src='").append(window["E1RES_img_close_gif"]).append("' alt=\"").append(this.titleInfo.titleText).append("\" name='/img/close.gif' onmouseOver=showMotion(this) onmouseOut=removeMotion(this) hspace=3 border=0>");
		sb.append("</td>");
	}
	sb.append("</tr></table></td></tr>");

	sb.append("<tr><td>");
	sb.append(this.contentHTML);	
	sb.append("</td></tr>");
	sb.append("</table>");
	this.windowElem.innerHTML = sb.toString();
	delete this.contentHTML;
}

PopupWindow.prototype.display = function(left,top,width, height){
	this._buildHTML();
	this.titleElem = document.getElementById("popupWindowTitle"+this.id);
	this.titleElem.style.width = width - 50;
	this.titleElem.style.cursor = "move";
	
	this.windowElem.style.left = left + "px";
	this.windowElem.style.top = top + "px";
	this.windowElem.style.width = width + "px";
	this.windowElem.style.height = height + "px";
	this.windowElem.className = "RaisedBorders";
    this.windowElem.style.display = "block";

	if (this.resizable){
		this.windowElem.onmousedown = new Function("window['"+this.id+"'].mouseDownContainer(arguments[0])");
		this.windowElem.onmousemove = new Function("window['"+this.id+"'].mouseMoveContainer(arguments[0])");
		this.windowElem.onmouseup = new Function("window['"+this.id+"'].mouseUpContainer(arguments[0])");
	}
	
	if(this.titleElem != null){	
		this.titleElem.onmousedown = new Function("window['"+this.id+"'].mouseDownTitle(arguments[0])");
		this.titleElem.onmousemove = new Function("window['"+this.id+"'].mouseMoveTitle(arguments[0])");
		this.titleElem.onmouseup = new Function("window['"+this.id+"'].mouseUpTitle(arguments[0])");
	}
	
	showItemShadow(this.windowElem);
}

PopupWindow.prototype.hide = function(left,top,width, height){
	this.windowElem.style.display = "none";
	removeItemShadow(this.windowElem);
}

PopupWindow.prototype.moveTo = function(left, top){
	this.windowElem.style.left = left;
    this.windowElem.style.top = top;
    moveItemShadow(this.windowElem);
}

PopupWindow.prototype.onClose = function(){
	if(this.eventListener && this.eventListener.onClose)
		this.eventListener.onClose();
	this.hide();
}

PopupWindow.prototype.mouseDownTitle = function(e){
	if(this.eventListener && this.eventListener.mouseDown)
		this.eventListener.mouseDown();

	var evt = document.all ? window.event : e;	
	if (document.all)
		this.titleElem.setCapture();
	else {		
	    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	    this.oldMouseMove = document["onmousemove"];
	    document["onmousemove"] = this.mouseMoveTitle;
	    this.oldMouseUp = document["onmouseup"];
	    document["onmouseup"] = this.mouseUpTitle;
	}
	this.initWindowX = parseInt(this.windowElem.style.left);
	this.initWindowY = parseInt(this.windowElem.style.top);
	this.initClientX = evt.clientX;
	this.initClientY = evt.clientY;
	this.titleHasCapture = true;
	PopupWindow.prototype.currentInstance = this;
	if(document.all){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	else{
		if (evt.cancelable){
			evt.stopPropagation();
			evt.preventDefault();
		}
    }
}
	
PopupWindow.prototype.mouseMoveTitle = function(e){
  	var popupWin = this;
  	if(!document.all && this != PopupWindow.prototype.currentInstance && 
  		PopupWindow.prototype.currentInstance!=null){
		popupWin = PopupWindow.prototype.currentInstance;
	}
  	if (!popupWin.titleHasCapture) 
  		return;
  	var evt = document.all ? window.event : e;
  	popupWin.windowElem.style.left=popupWin.initWindowX+evt.clientX-popupWin.initClientX; 
  	popupWin.windowElem.style.top= popupWin.initWindowY+evt.clientY-popupWin.initClientY;
  	moveItemShadow(popupWin.windowElem);

  	if(popupWin.eventListener && popupWin.eventListener.movedTo)
  		popupWin.eventListener.movedTo(popupWin.windowElem.style.left, popupWin.windowElem.style.top);
}

PopupWindow.prototype.mouseUpTitle = function(e){
  	var popupWin = this;
  	if(this != PopupWindow.prototype.currentInstance && 
  		PopupWindow.prototype.currentInstance!=null){
		popupWin = PopupWindow.prototype.currentInstance;
	}
	
	PopupWindow.prototype.currentInstance = null;
	if (true == popupWin.titleHasCapture){
	    if (document.all)
	        popupWin.titleElem.releaseCapture();
	    else {
	        window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	        document["onmousemove"] = popupWin.oldMouseMove;
	        document["onmouseup"] = popupWin.oldMouseUp;
        }
	    popupWin.titleHasCapture = false;
	}
	
}

PopupWindow.prototype.getContainerMoveDirection = function(e, containerElm){
	var direction = "";
	var evt = document.all ? window.event : e;
	var container = document.all ? event.srcElement : e.target;
	var x,y,windowX,windowY;
	
	if(document.all){
		x = evt.x + document.body.scrollLeft;
		y = evt.y + document.body.scrollTop;
	}
	else{
		x = evt.pageX;
		y = evt.pageY;
	}
	
	windowX = getAbsoluteLeftPos(containerElm);
	windowY = getAbsoluteTopPos(containerElm);	
	
	if ((y-windowY) < PopupWindow.prototype.RESIZE_TOLERANCE)
		direction += "";
	else if ((y-windowY) > containerElm.offsetHeight - PopupWindow.prototype.RESIZE_TOLERANCE)
		direction += "s";
	if ((x-windowX) < PopupWindow.prototype.RESIZE_TOLERANCE)
		direction += "w";
	else if ((x-windowX) > containerElm.offsetWidth - PopupWindow.prototype.RESIZE_TOLERANCE)
		direction += "e";
	return direction;
}

PopupWindow.prototype.mouseDownContainer = function(e){
	if(this.eventListener && this.eventListener.mouseDown)
		this.eventListener.mouseDown();
	
	var evt = document.all ? window.event : e;
	var container = document.all ? event.srcElement : e.target;
		
	this.initDirection = this.getContainerMoveDirection(e, this.windowElem);
	if (this.initDirection == ""){
		return;
	}
	this.containerHasCapture = true;	
	if (document.all)
		this.windowElem.setCapture();
	else {
	    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	    this.oldMouseMove = document["onmousemove"];
	    document["onmousemove"] = this.mouseMoveContainer;
	    this.oldMouseUp = document["onmouseup"];
	    document["onmouseup"] = this.mouseUpContainer;
	}		
	this.initWindowX = parseInt(this.windowElem.offsetLeft);
	this.initWindowY = parseInt(this.windowElem.offsetTop);
	this.initClientX = evt.clientX;
	this.initClientY = evt.clientY;
	this.initWindowWidth = parseInt(this.windowElem.offsetWidth);
	this.initWindowHeight = parseInt(this.windowElem.offsetHeight);
	PopupWindow.prototype.currentInstance = this;
	if(document.all){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	else{
		if (evt.cancelable){
			evt.stopPropagation();
			evt.preventDefault();
		}
    }
}

PopupWindow.prototype.mouseMoveContainer = function(e){
  	var popupWin = this;
  	if(!document.all && this != PopupWindow.prototype.currentInstance && 
  		PopupWindow.prototype.currentInstance!=null){
		popupWin = PopupWindow.prototype.currentInstance;
	}

  	var evt = document.all ? window.event : e;
	
	if (!popupWin.containerHasCapture){ 
		var direction = popupWin.getContainerMoveDirection(e, popupWin.windowElem);  	
		if (direction == "")
			popupWin.windowElem.style.cursor = "default";
		else
		  	popupWin.windowElem.style.cursor = direction + "-resize";	
  		return;
  	}
  		
	if (popupWin.initDirection.indexOf("e") != -1)
		popupWin.windowElem.style.width = Math.max(popupWin.minWidth, 
			popupWin.initWindowWidth + evt.clientX - popupWin.initClientX);
	if (popupWin.initDirection.indexOf("s") != -1)
		popupWin.windowElem.style.height = Math.max(popupWin.minHeight, 
			popupWin.initWindowHeight + evt.clientY - popupWin.initClientY);
	if (popupWin.initDirection.indexOf("w") != -1) {
		popupWin.windowElem.style.left = Math.min(popupWin.initWindowX + evt.clientX - popupWin.initClientX, 
			popupWin.initWindowX + popupWin.initWindowWidth - popupWin.minWidth);
		popupWin.windowElem.style.width = Math.max(popupWin.minWidth, 
			popupWin.initWindowWidth - evt.clientX + popupWin.initClientX);
	}
	if (popupWin.initDirection.indexOf("n") != -1) {
		popupWin.windowElem.style.top = Math.min(popupWin.initWindowY + evt.clientY - popupWin.initClientY, 
			popupWin.initWindowY + popupWin.initWindowHeight - popupWin.minHeight);
		popupWin.windowElem.style.height = Math.max(popupWin.minHeight, 
			popupWin.initWindowHeight - evt.clientY + popupWin.initClientY);
	}
  	moveItemShadow(popupWin.windowElem);
	
	this.titleElem.style.width = parseInt(popupWin.windowElem.style.width) - 50;
  	
  	if(popupWin.eventListener && popupWin.eventListener.resizedTo)
  		popupWin.eventListener.resizedTo(popupWin.windowElem.style.width, popupWin.windowElem.style.height);
}

PopupWindow.prototype.mouseUpContainer = function(e){
  	var popupWin = this;
  	if(!document.all && this != PopupWindow.prototype.currentInstance && 
  		PopupWindow.prototype.currentInstance!=null){
		popupWin = PopupWindow.prototype.currentInstance;
	}
	
	PopupWindow.prototype.currentInstance = null;
	
	if (true == popupWin.containerHasCapture){
	    if (document.all)
	        popupWin.windowElem.releaseCapture();
	    else {
	        window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	        document["onmousemove"] = popupWin.oldMouseMove;
	        document["onmouseup"] = popupWin.oldMouseUp;
	    }
	    popupWin.containerHasCapture = false;
	}
}

/**
 * This is the customized E1 tooltip component.<br> 
 * User can set the follwing parameters: background color, 
 * show delay time, hide delay time, show delay, hide delay, 
 * vertical offset, horizontal offset.<br> 
 */
function Tooltip(id)
{
	this.id = id;
	window[id] = this;
	
	this.showDelayTime = 800;
	this.hideDelayTime = 0;
		
	this.xOffset = 9;
	this.yOffset = 12;
		
	this.showDelay = null;
	this.hideDelay = null;
	
      this.tooltipElem = document.getElementById(this.id);
	if(this.tooltipElem == null)
	{
	    this.tooltipElem = this._createTooltip(this.id);
	}
}

Tooltip.prototype.NEW_LINE = "<br>";

Tooltip.prototype._createTooltip = function(id)
{
	var elem = document.createElement("div");
	elem.id = id;
	elem.className = 'JSGridTooltip';

	document.body.appendChild(elem);
	return elem;
}

Tooltip.prototype.setTooltip = function(tooltipContent, obj, e)
{	
	if (window.event) 
	{
		event.cancelBubble = true;
	}
	else if (e.stopPropagation) 
	{
		e.stopPropagation();
	}	
		
	this.tooltipElem.innerHTML = tooltipContent;
	this.tooltipElem.x = getAbsoluteLeftPos(obj, true);
	this.tooltipElem.y = getAbsoluteTopPos(obj, true);		
	this.tooltipElem.style.left = 
        this.tooltipElem.x + this.xOffset + "px";
	this.tooltipElem.style.top = 
        this.tooltipElem.y + obj.offsetHeight + this.yOffset + "px";	
}

Tooltip.prototype.showTooltip = function()
{
	if (this.tooltipElem != null)
	{
		this.tooltipElem.style.visibility = "visible";
	}
}

Tooltip.prototype.hideTooltip = function()
{
	if (this.tooltipElem != null)
	{
		this.tooltipElem.style.visibility = "hidden";
	}
}

Tooltip.prototype.clearHideTooltipDelay = function()
{
	if (this.hideDelay != null)
	{
		clearTimeout(this.hideDelay);
	}
}

Tooltip.prototype.clearShowTooltipDelay = function()
{
	if (this.showDelay != null)
	{
		clearTimeout(this.showDelay);
	}
}

Tooltip.prototype.setShowTooltipDelay = function(showDelay)
{
	this.showDelay = showDelay;
}

Tooltip.prototype.setHideTooltipDelay = function(hideDelay)
{
	this.hideDelay = hideDelay;
}

Tooltip.prototype.setShowDelayTime = function(showDelayTime)
{
	this.showDelayTime = showDelayTime;
}

Tooltip.prototype.setHideDelayTime = function(hideDelayTime)
{
	this.hideDelayTime = hideDelayTime;
}

Tooltip.prototype.getShowDelayTime = function()
{
	return this.showDelayTime;
}

Tooltip.prototype.getHideDelayTime = function()
{
	return this.hideDelayTime;
}

Tooltip.prototype.setXOffset = function(xOffset)
{
	this.xOffset = xOffset;
}

Tooltip.prototype.setYOffset = function(yOffset)
{
	this.yOffset = yOffset;
}

Tooltip.prototype.setBGColor = function(bgColor)
{
	if (this.tooltipElem != null)
	{
		this.tooltipElem.style.backgroundColor = bgColor;
	}
}

function getCursorPosition(evt)
{
    var evt = document.all ? window.event : evt;
    if(evt)
    {
       //Take into account the scroll positions on the 'e1formDiv' also (after HFE - lock toolbar project)
        var formDiv = document.getElementById('e1formDiv');
        var formDivScrollTop = 0;
        var formDivScrollLeft = 0;
        if (formDiv)
        {
            formDivScrollTop = formDiv.scrollTop;
            formDivScrollLeft = formDiv.scrollLeft;
        }

        if (evt.pageX || evt.pageX == 0)  //FF
        {
            return [evt.pageX+formDivScrollLeft, evt.pageY+formDivScrollTop];
        }
        var dE = document.documentElement || {};
        var dB = document.body || {};
        if ((evt.clientX || evt.clientX == 0) && ((dB.scrollLeft || dB.scrollLeft == 0) || (dE.clientLeft || dE.clientLeft == 0))) 
        {
            return [evt.clientX + (dE.scrollLeft || dB.scrollLeft || 0) + formDivScrollLeft - (dE.clientLeft || 0), evt.clientY + (dE.scrollTop || dB.scrollTop || 0) + formDivScrollTop - (dE.clientTop || 0)];
        }
    }
    return null;
}

