/* Version: 15.0.rup */
/*
	Copyright (c) Microsoft Corporation.  All rights reserved.
*/
<PUBLIC:COMPONENT NAME="HtcMenu" lightWeight="true">
	<PUBLIC:METHOD NAME="show" INTERNALNAME="ShowRoot" />
	<PUBLIC:METHOD NAME="hide" INTERNALNAME="HideMenu" />
	<PUBLIC:METHOD NAME="isOpen" INTERNALNAME="IsOpen" />
	<PUBLIC:METHOD NAME="item" INTERNALNAME="GetItem" />
</PUBLIC:COMPONENT>
<script language="JavaScript">
var kfnDisableEvent = new Function("return false");
var _wzPrefixID = uniqueID;		
var _oContents;						
var _oRoot;								
var _nLevel = 0;						
var _arrPopup = new Array();		
var _arrSelected = new Array();	
var _fIsRtL = false;					
var _wzMGradPath;
var _wzMGradPathRtL;
var _wzChkMrkPath;
var _wzMArrPath;
var _wzMArrPathRtL;
function PrepContents()
{
	_oContents = element.document.createElement("span");
	_oContents.innerHTML = innerHTML;
	_wzMGradPath = "/LAYOUTS_RMJ/images/MGrad.gif";
	_wzMGradPathRtL = "/LAYOUTS_RMJ/images/MGradRtL.gif";
	_wzChkMrkPath = "/LAYOUTS_RMJ/images/ChkMrk.gif";
	_wzMArrPath = "/LAYOUTS_RMJ/images/MArr.gif";
	_wzMArrPathRtL = "/LAYOUTS_RMJ/images/MArrRtL.gif";
	var rgThemeMeta = element.document.getElementsByName("Microsoft Theme");
	if (rgThemeMeta && rgThemeMeta.length > 0)
		{
		var wzTheme = rgThemeMeta[0].content;
		if (wzTheme && !FIStringStartsWith(wzTheme, "none") &&
			 (L_Menu_SiteTheme || !FIStringEndsWith(wzTheme, "default")))
			{
			_wzMGradPath = "/LAYOUTS_RMJ/images/MGrTh.gif";
			_wzMGradPathRtL = "/LAYOUTS_RMJ/images/MGrThRtL.gif";
			}
		}
	if (L_Menu_BaseUrl)
		{
		_wzMGradPath = L_Menu_BaseUrl + _wzMGradPath;
		_wzMGradPathRtL = L_Menu_BaseUrl + _wzMGradPathRtL;
		_wzChkMrkPath = L_Menu_BaseUrl + _wzChkMrkPath;
		_wzMArrPath = L_Menu_BaseUrl + _wzMArrPath;
		_wzMArrPathRtL = L_Menu_BaseUrl + _wzMArrPathRtL;
		}
}
function Show(oParent, y, fFlipTop)
{
	var oPopup = _arrPopup[_nLevel];	
	var oPopupDoc							
	var oPopupBody;						
	var oWnd;								
	var oWndDoc;							
	var oWndBody;							
	var nIndex;								
	var fTopLevel;							
	if (!_oContents) PrepContents();
	if (!_oContents || IsOpen()) return;
	if (!oPopup && !_oRoot)
		{
		_nLevel = 0;
		_oRoot = _oContents;
		}
	fTopLevel = _nLevel == 0;
	fFlipTop = fFlipTop && fTopLevel; 
	oWnd = fTopLevel ? window : _arrPopup[_nLevel - 1].document.parentWindow;
	oWndDoc = oWnd.document;
	oWndBody = oWndDoc.body;
	if (!oPopup)
		{
		_arrPopup[_nLevel] = oWnd.createPopup();
		oPopup = _arrPopup[_nLevel];
		oPopupDoc = oPopup.document;
		oPopupBody = oPopupDoc.body;
		oPopupDoc.title = WzGetInnerText(oParent);
		oPopupBody.dir = fTopLevel && oParent ? oParent.currentStyle.direction : oWndBody.currentStyle.direction;
		var oStyleSheetSrc, oStyleSheetNew = oPopupDoc.createStyleSheet();
		var wzCssText;
		if (fTopLevel)
			{
			for (var nSS = 0; nSS < oWndDoc.styleSheets.length; nSS++)
				{
				oStyleSheetSrc = oWndDoc.styleSheets[nSS];
				if (FIStringContains(oStyleSheetSrc.href, "Menu.css"))
					{
					for (var nRule = 0; nRule < oStyleSheetSrc.rules.length; nRule++)
						{
						var oRule = oStyleSheetSrc.rules[nRule];
						wzCssText = oRule.style.cssText;
						if (!wzCssText) continue;
						oStyleSheetNew.addRule(oRule.selectorText, wzCssText);
						}
					}
				}
			_fIsRtL = FIStringEquals(oPopupBody.dir, "rtl");
			}
		else
			{
			oStyleSheetSrc = oWndDoc.styleSheets.length > 0 ? oWndDoc.styleSheets[0] : null;
			if (oStyleSheetSrc)
				{
				wzCssText = oStyleSheetSrc.cssText;
				if (wzCssText) oStyleSheetNew.cssText = wzCssText;
				}
			}
		var oTable = oPopupDoc.createElement("table");
		var oTBody = oPopupDoc.createElement("tbody");
		oTable.appendChild(oTBody);
		oPopupBody.appendChild(oTable);
		var lastMenuSeparatorRow = null;
		for (nIndex = 0; nIndex < _oRoot.children.length; nIndex++)
			{
			var menuRow = _oRoot.children[nIndex];
			var deleteRow = false;
			if (menuRow.style.display == 'none')
				{
				deleteRow = true;
				}
			else if (FIsIType(menuRow, "separator"))
				{
				if (lastMenuSeparatorRow != null || nIndex == 0)
					deleteRow = true;
				else
					lastMenuSeparatorRow = menuRow;
				}
			else
				{
				lastMenuSeparatorRow = null;
				}
			if (deleteRow == true)
				{
				menuRow.removeNode(true);
				nIndex--;
				}
			}
		if(lastMenuSeparatorRow != null)
			lastMenuSeparatorRow.removeNode(true);
		var id = 0;
		for (nIndex = 0; nIndex < _oRoot.children.length; nIndex++)
			{
			var oNode = _oRoot.children[nIndex];
			if (!FIsIType(oNode, "label"))
				{
				var oItem = CreateMenuItem(oNode, MakeID2(_nLevel, id));
				if (oItem) oTBody.appendChild(oItem);
				id++;
				}
			}
		oPopupBody.className = "ms-MenuUIPopupBody";
		oPopupBody.style.setExpression("overflow", "offsetHeight < window.screen.height && offsetWidth < window.screen.width ? 'visible' : 'auto'");
		oTable.className = "ms-MenuUI";
		oTable.cellSpacing = 0;
		oTable.cellPadding = 0;
		var wzImgSrc, wzImgPosX;
		if (!_fIsRtL)
			{
			wzImgSrc = _wzMGradPath;
			wzImgPosX = "left";
			}
		else
			{
			wzImgSrc = _wzMGradPathRtL;
			wzImgPosX = "right";
			}
		oTable.style.backgroundImage = "url(" + wzImgSrc + ")";
		oTable.style.backgroundPositionX = wzImgPosX;
		oTable.style.backgroundRepeat = "repeat-y"
		oPopupBody.oncontextmenu = kfnDisableEvent;
		oPopupBody.ondragstart = kfnDisableEvent;
		oPopupBody.onselectstart = kfnDisableEvent;
		oPopupBody.onkeydown = PopupKeyDown;
		oPopupBody.onmouseup = PopupMouseUp;
		oPopupBody.onmouseover = PopupMouseOver;
		oPopupBody.onmouseleave = PopupMouseLeave;
		if (fTopLevel)
			{
			var wzOnUnload = getAttribute("onunloadtext");
			if (wzOnUnload) oPopupBody.onunload = new Function(wzOnUnload);
			}
		}
	else
		{
		oPopupDoc = oPopup.document;
		oPopupBody = oPopupDoc.body;
		var oOld = _arrSelected[_nLevel];
		if (oOld) UnselectItem(oOld);
		}
	oPopupDoc.documentElement.style.fontSize = oWndDoc.documentElement.currentStyle.fontSize;
	_arrSelected[_nLevel] = null;
	oPopup.show(0, 0, 0, 0, oParent);
	var nRealWidth	= oPopupBody.scrollWidth + oPopupBody.offsetWidth - oPopupBody.clientWidth;
	var nRealHeight = oPopupBody.scrollHeight + oPopupBody.offsetHeight - oPopupBody.clientHeight;
	if (nRealWidth > window.screen.width) nRealWidth = window.screen.width;
	if (nRealHeight > window.screen.height) nRealHeight = window.screen.height;
	oPopup.hide();
	var EdgeLeft = window.screenLeft;
	var EdgeRight = EdgeLeft + window.document.body.clientWidth;
	var ParentLeft = 0;
	if (fTopLevel)
		{
		var oCurrent;
		for (oCurrent = oParent; oCurrent && oCurrent != window.document.body; oCurrent = oCurrent.offsetParent)
			ParentLeft += oCurrent.offsetLeft - oCurrent.scrollLeft;
		if (oCurrent) ParentLeft += oCurrent.clientLeft - oCurrent.scrollLeft;
		ParentLeft += EdgeLeft;
		}
	else
		{
		ParentLeft = oWnd.screenLeft;
		}
	var xDefault = 0, xFlipped = 0, nParentWidth = oParent ? oParent.offsetWidth : 0;
	var fTryGoDefault = !fFlipTop && !oWndBody.getAttribute("flipped");
	var fFlippedDefault, fFlippedNonDefault;
	if (!_fIsRtL)
		{
		xDefault = fTopLevel ? 0 : nParentWidth;
		var MenuRightDefault = ParentLeft + xDefault + nRealWidth;
		var MenuLeftFlipped = ParentLeft - nRealWidth;
		if (fTopLevel) MenuLeftFlipped += nParentWidth;
		xFlipped = MenuLeftFlipped - ParentLeft;
		fFlippedDefault = MenuRightDefault > EdgeRight && MenuLeftFlipped > EdgeLeft;
		fFlippedNonDefault = !(MenuLeftFlipped < EdgeLeft && MenuRightDefault < EdgeRight);
		}
	else 
		{
		xDefault = fTopLevel ? nParentWidth - nRealWidth : -nRealWidth;
		var MenuLeftDefault = ParentLeft + xDefault;
		var MenuRightFlipped = ParentLeft + nRealWidth;
		if (!fTopLevel) MenuRightFlipped += nParentWidth;
		xFlipped = MenuRightFlipped - ParentLeft - nRealWidth;
		fFlippedDefault = MenuLeftDefault < EdgeLeft && MenuRightFlipped < EdgeRight;
		fFlippedNonDefault = !(MenuRightFlipped > EdgeRight && MenuLeftDefault > EdgeLeft);
		}
	var fFlipped = fTryGoDefault ? fFlippedDefault : fFlippedNonDefault;
	var x = fFlipped ? xFlipped : xDefault;
	oPopupBody.setAttribute("flipped", fFlipTop ? fFlipped && fFlippedDefault : fFlipped);
	oPopup.show(x, y, nRealWidth, nRealHeight, oParent);
}
function HideMenu()
{
	if (IsOpen()) _arrPopup[0].hide();
}
function IsOpen()
{
	var oPopup = _arrPopup[_nLevel];
	return oPopup && oPopup.isOpen;
}
function FindLabel(oParent)
{
	var arrNodes = oParent ? oParent.children : null;
	if (arrNodes)
		{
		for (var nIndex = 0; nIndex < arrNodes.length; nIndex++)
			{
			var oNode = arrNodes[nIndex];
			if (FIsIType(oNode, "label")) return oNode;
			}
		}
	return null;
}
function ShowRoot(oParent, fForceRefresh, fFlipTop, yOffset)
{
	UpdateLevel(0);
	if (fForceRefresh)
		{
		_oContents = null;
		_oRoot = null;
		_nLevel = 0;
		_arrPopup = new Array();
		_arrSelected = new Array();
		}
	else
		{
		_oRoot = _oContents;
		}
	var y = 0;
	if (oParent) y += oParent.offsetHeight;
	if (yOffset) y += yOffset;
	fFlipTop = fFlipTop != false;
	Show(oParent, y, fFlipTop);
}
function ShowSubMenu(nLevel, oParent)
{
	if (!oParent) return;
	UpdateLevel(nLevel);
	_oRoot = oParent.submenuRoot;
	_nLevel = nLevel + 1;
	Show(oParent, -1);
}
function ShowSubMenuEvnt()
{
	var oPopup = _arrPopup[_nLevel];
	if (oPopup)
		{
		var oPopupBody = oPopup.document.body;
		oPopupBody.removeAttribute("timeoutID");
		ShowSubMenu(_nLevel, _arrSelected[_nLevel]);
		}
}
function SetShowSubMenuEvnt()
{
	var oPopup = _arrPopup[_nLevel];
	var oWnd = _nLevel == 0 ? window : _arrPopup[_nLevel - 1].document.parentWindow;
	if (oPopup && oWnd)
		{
		var oPopupBody = oPopup.document.body;
		oPopupBody.setAttribute("timeoutID", oWnd.setTimeout(ShowSubMenuEvnt, 100));
		}
}
function ClearShowSubMenuEvnt()
{
	var oPopup = _arrPopup[_nLevel];
	var oWnd = _nLevel == 0 ? window : _arrPopup[_nLevel - 1].document.parentWindow;
	if (oPopup && oWnd)
		{
		var oPopupBody = oPopup.document.body;
		var id = oPopupBody.getAttribute("timeoutID");
		if (typeof(id)=="number")
			{
			oWnd.clearTimeout(id);
			}
		oPopupBody.removeAttribute("timeoutID");
		}
}
function GetEventFromLevel(nLevel)
{
	if (nLevel >= 0 && nLevel <= _nLevel)
		{
		var oPopup = _arrPopup[nLevel];
		if (oPopup) return oPopup.document.parentWindow.event;
		}
	return null;	
}
function GetEventLevel()
{
	for (var nIndex = _nLevel; nIndex >= 0; nIndex--)
		if (GetEventFromLevel(nIndex)) return nIndex;
	return -1;
}
function GetEventSrcItem(oEvent)
{
	if (oEvent)
		for (var oSrc = oEvent.srcElement; oSrc && !FIStringEquals(oSrc.tagName, "BODY"); oSrc = oSrc.parentNode)
			if (FIStringEquals(oSrc.tagName, "TR") && oSrc.id.substring(0, _wzPrefixID.length) == _wzPrefixID) return oSrc;
	return null;
}
function UpdateLevel(nLevel)
{
	var oPopup;
	while (_nLevel > nLevel)
		{
		oPopup = _arrPopup[_nLevel];
		if (oPopup)
			{
			ClearShowSubMenuEvnt();
			oPopup.hide();
			}
		_arrPopup[_nLevel] = null;
		_arrSelected[_nLevel] = null;
		_oRoot = _oRoot.parentNode;
		_nLevel--;
		}
	oPopup = _arrPopup[_nLevel];
	if (oPopup) ClearShowSubMenuEvnt();
}
function PopupMouseOver()
{
	var nLevel = GetEventLevel();
	if (nLevel < 0) return;
	var oPopupEvent = GetEventFromLevel(nLevel);
	var oSrcElem = GetEventSrcItem(oPopupEvent);
	if (oSrcElem)
		{
		if (oSrcElem != _arrSelected[nLevel])
			{
			if (FIsIType(oSrcElem, "separator")) return;
			ToggleMenuItem(nLevel, oSrcElem);
			if (FIsIType(oSrcElem, "submenu")) EngageSelection(true, true, false);
			}
		else if (nLevel < _nLevel)
			{
			UnselectCurrentOption();
			}
		}
}
function PopupMouseLeave()
{
	if (GetEventLevel() == _nLevel) UnselectCurrentOption();
}
function PopupMouseUp()
{
	var nLevel = GetEventLevel();
	if (nLevel < 0) return;
	var oItem = _arrSelected[nLevel];
	if (GetEventFromLevel(nLevel).button == 1 || FIsIType(oItem, "submenu"))
		{
		UpdateLevel(nLevel);
		EngageSelection(true, false, false);
		}
}
function PopupKeyDown()
{
	var nLevel = GetEventLevel();
	if (nLevel < 0) return;
	var oPopupEvent = GetEventFromLevel(nLevel);
	var nKeyCode = oPopupEvent.keyCode;
	if (_fIsRtL)
		{
		if (nKeyCode == 37) nKeyCode = 39;
		else if (nKeyCode == 39) nKeyCode = 37;
		}
	if (nKeyCode == 9) nKeyCode = !oPopupEvent.shiftKey ? 40 : 38;
	ClearShowSubMenuEvnt();
	switch (nKeyCode)
		{
	case 38:	
		MoveMenuSelection(-1);
		break;
	case 40:	
		MoveMenuSelection(1);
		break;
	case 37:	
	case 27: 
		CloseCurrentLevel(nKeyCode == 27);
		break;
	case 39:	
	case 13:	
		EngageSelection(nKeyCode == 13, false, true);
		break;
		}
	oPopupEvent.returnValue = false;
}
function EngageSelection(fDoSelection, fDelayExpandSM, fEnterSM)
{
	var oItem = _arrSelected[_nLevel];
	if (!oItem || oItem.optionDisabled) return;
	if (FIsIType(oItem, "submenu"))
		{
		if (fDelayExpandSM)
			{
			SetShowSubMenuEvnt();
			}
		else
			{
			ShowSubMenu(_nLevel, oItem);
			if (fEnterSM) MoveMenuSelection(1);
			}
		}
	else if (fDoSelection)
		{
		var fnOnClick = oItem.getAttribute("onMenuClick");
		if (fnOnClick)
			{
			if (FIStringEquals(typeof(fnOnClick), "string"))
				fnOnClick = new Function("var document=window.document; {" + fnOnClick + "}");
			var oTemp = window.document.body.appendChild(window.document.createElement("span"));
			oTemp.onclick = fnOnClick;
			oTemp.click();
			oTemp.removeNode();
			HideMenu();
			}
		}
}
function CloseCurrentLevel(fAllowHideRoot)
{
	if (_nLevel > 0) UpdateLevel(_nLevel - 1);
	else if (fAllowHideRoot) HideMenu();
}
function UnselectCurrentOption()
{
	if (_nLevel >= 0)
		{
		var oItem = _arrSelected[_nLevel];
		if (FIsIType(oItem, "option"))
			{
			UnselectItem(oItem);
			_arrSelected[_nLevel] = null;
			}
		}
}
function MakeID2(nLevel, nIndex)
{
	return _wzPrefixID + "_" + String(nLevel) + "_" + String(nIndex);
}
function GetItem(nLevel, nIndex)
{
	var  oPopup = _arrPopup[nLevel];
	return oPopup ? oPopup.document.getElementById(MakeID2(nLevel, nIndex)) : null;
}
function MoveMenuSelection(iDir)
{
	var nIndex = -1;
	var nNumItems = _oRoot.children.length;
	var oSelected = _arrSelected[_nLevel];
	if (oSelected)
		{
		var wzSelectedID = oSelected ? oSelected.id : null;
		if (wzSelectedID)
			{
			var nCurIndex = parseInt(wzSelectedID.substring(wzSelectedID.lastIndexOf("_") + 1, wzSelectedID.length));
			nIndex = (nCurIndex + nNumItems + iDir) % nNumItems; 
			}
		}
	if (nIndex < 0)
		nIndex = iDir > 0 ? 0 : (nNumItems - 1);
	var oItem;
	var nIndexStart = nIndex;
	do
		{
		oItem = GetItem(_nLevel, nIndex);
		nIndex = (nIndex + nNumItems + iDir) % nNumItems; 
		}
	while (nIndex != nIndexStart &&
			 (!oItem || oItem.style.display == "none" ||
			  !(FIsIType(oItem, "option") || FIsIType(oItem, "submenu"))));
	ToggleMenuItem(_nLevel, oItem);
}
function ToggleMenuItem(nLevel, oItem)
{
	var oOld = _arrSelected[nLevel];
	if (!oItem || (oOld && oItem.id == oOld.id)) return;
	if (oOld) UnselectItem(oOld);
	UpdateLevel(nLevel);
	SelectItem(oItem);
	_arrSelected[nLevel] = oItem;
	oItem.tabIndex = 0;
	oItem.setActive();
}
function SelectItem(oItem)
{
	if (!oItem) return;
	var oItemTableCell = oItem.firstChild;
	var oItemTable = oItemTableCell.firstChild;
	oItemTableCell.className = "ms-MenuUIItemTableCellHover";
	oItemTable.className = "ms-MenuUIItemTableHover";
}
function UnselectItem(oItem)
{
	if (!oItem) return;
	var oItemTableCell = oItem.firstChild;
	var oItemTable = oItemTableCell.firstChild;
	oItemTableCell.className = "ms-MenuUIItemTableCell";
	oItemTable.className = "ms-MenuUIItemTable";
}
function CreateMenuOption(oRow, oNode, wzID, wzHtml)
{
	var oPopup = _arrPopup[_nLevel];
	if (!oPopup) return;
	var oPopupDoc = oPopup.document;
	var oIcon = oPopupDoc.createElement("td");
	var oLabel = oPopupDoc.createElement("td");
	var oAccKey = oPopupDoc.createElement("td");
	var oArrow = oPopupDoc.createElement("td");
	oRow.appendChild(oIcon);
	oRow.appendChild(oLabel);
	oRow.appendChild(oAccKey);
	oRow.appendChild(oArrow);
	oIcon.className = !_fIsRtL ? "ms-MenuUIIcon" : "ms-MenuUIIconRtL";
	oLabel.className = !_fIsRtL ? "ms-MenuUILabel" : "ms-MenuUILabelRtL";
	oAccKey.className = "ms-MenuUIAccessKey";
	oArrow.className = "ms-MenuUISubmenuArrow";
	oIcon.noWrap = true;
	oLabel.noWrap = true;
	oAccKey.noWrap = true;
	oArrow.noWrap = true;
	oLabel.id = oNode.id;
	if (!wzHtml) wzHtml = oNode.innerHTML;
	if (oNode.getAttribute("enabled") == "false")
	{
		oRow.disabled = true;
	}
	var wzIconSrc = null, wzIconAlt = null;
	if (oNode.getAttribute("checked") == "true")
		{
		wzIconSrc = _wzChkMrkPath;
		wzIconAlt = "*";
		}
	else
		{
		wzIconSrc = oNode.getAttribute("iconSrc");
		wzIconAlt = oNode.getAttribute("iconAltText");
		}
	if (wzIconSrc)
		{
		var oImg = oPopupDoc.createElement("IMG");
		var oImgLbl = oPopupDoc.createElement("LABEL");
		oIcon.appendChild(oImg);
		oLabel.appendChild(oImgLbl);
		var wzIconId = wzID + "_" + "ICON";
		oImg.id = wzIconId;
		oImg.src = wzIconSrc;
		if (wzIconAlt) 
			{
			oImg.alt = wzIconAlt;
			oImg.title = "";
			}
		oImgLbl.htmlFor = wzIconId;
		oImgLbl.innerHTML = wzHtml;
		}
	else
		{
		oIcon.innerHTML = "&nbsp;";
		oLabel.innerHTML = wzHtml;
		}
	var wzAccKey = oNode.getAttribute("accessKeyText");
	if (wzAccKey) oAccKey.innerText = wzAccKey;
	SetIType(oRow, "option");
}
function CreateMenuSeparator(oRow, oNode)
{
	var oPopup = _arrPopup[_nLevel];
	if (!oPopup) return;
	var oPopupDoc = oPopup.document;
	var oCell = oPopupDoc.createElement("td");
	var oDiv = oPopupDoc.createElement("div");
	oRow.appendChild(oCell);
	oCell.appendChild(oDiv);
	oDiv.className = !_fIsRtL ? "ms-MenuUISeparator" : "ms-MenuUISeparatorRtL";
	oDiv.innerHTML = "&nbsp;";
	SetIType(oRow, "separator");
}
function CreateSubmenu(oRow, oNode, wzID)
{
	var oLabelNode = FindLabel(oNode);
	CreateMenuOption(oRow, oNode, wzID, oLabelNode ? oLabelNode.innerHTML : null);
	var oPopup = _arrPopup[_nLevel];
	if (!oPopup) return;
	var oArrow = oRow.children[3];
	var oArrowImg = oPopup.document.createElement("IMG");
	oArrow.appendChild(oArrowImg);
	oArrowImg.src = !_fIsRtL ? _wzMArrPath : _wzMArrPathRtL;
	oArrowImg.alt = !_fIsRtL ? ">" : "<";
	oArrowImg.title = "";
	SetIType(oRow, "submenu");
	oRow.submenuRoot = oNode;
}
function CreateMenuItem(oNode, wzID)
{
	if (FIsIType(oNode, "label")) return;
	var oPopup = _arrPopup[_nLevel];
	if (!oPopup) return;
	var oPopupDoc = oPopup.document;
	var oRow = oPopupDoc.createElement("tr");
	oRow.mergeAttributes(oNode);
	oRow.setAttribute("onMenuClick", oNode.getAttribute("onMenuClick"));
	if (FIsIType(oNode, "separator"))
		{
		CreateMenuSeparator(oRow, oNode);
		return oRow;
		}
	if (!GetIType(oNode)) SetIType(oNode, "option");
	var oFmtTableRow = oPopupDoc.createElement("tr");
	var oFmtTableCell = oPopupDoc.createElement("td");
	var oFmtTable = oPopupDoc.createElement("table");
	var oFmtTableBody = oPopupDoc.createElement("tbody");
	oFmtTableRow.appendChild(oFmtTableCell);
	oFmtTableCell.appendChild(oFmtTable);
	oFmtTable.appendChild(oFmtTableBody);
	oFmtTableBody.appendChild(oRow);
	oFmtTableCell.className = "ms-MenuUIItemTableCell";
	oFmtTable.className = "ms-MenuUIItemTable";
	oFmtTable.cellSpacing = 0;
	oFmtTable.cellPadding = 0;
	if (FIsIType(oNode, "submenu"))
		CreateSubmenu(oRow, oNode, wzID);
	else if (FIsIType(oNode, "option"))
		CreateMenuOption(oRow, oNode, wzID);
	if (oRow.isDisabled)
		{
		oRow.disabled = false;
		for (var nIndex = 0; nIndex < oRow.children.length; nIndex++)
			oRow.children(nIndex).disabled = true;
		oRow.optionDisabled = true;
		}
	oFmtTableRow.mergeAttributes(oRow);
	oFmtTableRow.id = wzID;
	SetIType(oFmtTableRow, GetIType(oRow));
	return oFmtTableRow;
}
function GetItems()
{
	if (null == _oContents) PrepContents();
	return _oContents.children;
}
function GetIType(oItem)
{
	return null != oItem ? oItem.getAttribute("type") : null;
}
function FIsIType(oItem, wzType)
{
	return FIStringEquals(GetIType(oItem), wzType);
}
function SetIType(oItem, wzType)
{
	if (oItem) oItem.setAttribute("type", wzType);
}
function FIStringEquals(wzX, wzY)
{
	return wzX != null && wzY != null && wzX.toLowerCase() == wzY.toLowerCase();
}
function FIStringContains(wzX, wzY)
{
	return wzX != null && wzY != null && wzX.toLowerCase().indexOf(wzY.toLowerCase()) >= 0;
}
function FIStringStartsWith(wzX, wzY)
{
	return wzX != null && wzY != null && wzX.toLowerCase().indexOf(wzY.toLowerCase()) == 0;
}
function FIStringEndsWith(wzX, wzY)
{
	return wzX != null && wzY != null && wzX.length >= wzY.length &&
		(wzY == "" || wzX.toLowerCase().indexOf(wzY.toLowerCase()) == wzX.length - wzY.length);
}
function WzGetInnerText(oElem, iDepth)
{
	if (!oElem) return "";
	if (!iDepth || iDepth < 0) iDepth = 0;
	if (iDepth == 0 && oElem.innerText) return oElem.innerText; 
	if (oElem.title) return oElem.title;
	var wzTagName = oElem.tagName;
	if (FIStringEquals(wzTagName, "INPUT") && oElem.value) return oElem.value;
	if (FIStringEquals(wzTagName, "IMG"))
		{
		if (oElem.alt) return oElem.alt;
		if (iDepth == 0) 
			{
			var oElemParent = oElem.parentNode;
			if (oElemParent && oElemParent.innerText) return oElemParent.innerText;
			}
		}
	if (iDepth < 5)
		{
		for (var nIndex = 0; nIndex < oElem.children.length; nIndex++)
			{
			var wzText = WzGetInnerText(oElem.children[nIndex], iDepth + 1);
			if (wzText) return wzText;
			}
		}
	return "";
}
</script>
