// Copyright 2009, BMT Defence Services Ltd, All rights reserved.
var omPopupMenu=new Object();var omPopupMenuShowing=new Array();
function popupMenuLoad(){$addHandler(document.body,"mouseup",function(){popupMenuHide()});$addHandler(document.body,"focus",function(){popupMenuHide()});}
function popupMenuExists(zMenuID){if(omPopupMenu[zMenuID])return true;else return false;}
function popupMenuGet(zMenuID){return omPopupMenu[zMenuID];}
function popupMenuShow(zMenuID,lX,lY,bReload){popupMenuHide();omPopupMenu[zMenuID].Show(lX,lY);}
function popupMenuHide(){var zpMenuID;for(var lpLoop=0;lpLoop<omPopupMenuShowing.length;lpLoop++){zpMenuID=omPopupMenuShowing[lpLoop];omPopupMenu[zpMenuID].Hide();}}
function PopupMenu(zMenuID,oDiv){this.MenuID=zMenuID;if(oDiv)this.Div=oDiv;else this.Div=document.body;this.SubMenus=new Object();this.SubMenuID="";this.MenuItemsIndex=new Object();this.MenuItems=new Array();this.MenuType={Item:1,SubMenu:2,Divider:3};this.Iframe=null;this.NoImages=false;omPopupMenu[this.MenuID]=this;}PopupMenu.prototype={AddMenuItem:function(zItemID,zText,zImagePath,oClickFunction,bHidden){var opMenuItem={MenuType:this.MenuType.Item,ItemID:zItemID,Text:zText,ImagePath:zImagePath,ClickFunction:oClickFunction,Hidden:bHidden};this.MenuItemsIndex[zItemID]=this.MenuItems.length;this.MenuItems[this.MenuItems.length]=opMenuItem;},AddSubMenuItem:function(zItemID,zText,zMenuID,bHidden){var opMenuItem={MenuType:this.MenuType.SubMenu,ItemID:zItemID,Text:zText,MenuID:zMenuID,Hidden:bHidden};this.MenuItemsIndex[zItemID]=this.MenuItems.length;this.MenuItems[this.MenuItems.length]=opMenuItem;},AddDivider:function(zItemID){var opMenuItem={MenuType:this.MenuType.Divider,ItemID:zItemID};this.MenuItemsIndex[zItemID]=this.MenuItems.length;this.MenuItems[this.MenuItems.length]=opMenuItem;},HideMenuItem:function(zItemID){this.MenuItems[this.MenuItemsIndex[zItemID]].Hidden=true;if(this.Iframe!=null){this.Iframe.contentWindow.document.getElementById(zItemID).style.display="none";this.ResizeIframe();}},ShowMenuItem:function(zItemID){this.MenuItems[this.MenuItemsIndex[zItemID]].Hidden=false;if(this.Iframe!=null){this.Iframe.contentWindow.document.getElementById(zItemID).style.display="block";this.ResizeIframe();}},Show:function(lX,lY,zParentMenuID,bReload){if(this.Iframe!=null&&bReload!=true){var opIframe=this.Iframe;}else{if(bReload==true&&this.Iframe!=null)this.Div.removeChild(this.Iframe);opIframe=document.createElement("iframe");opIframe.style.display="none";opIframe.marginWidth=0;opIframe.marginHeight=0;opIframe.frameBorder="0";opIframe.style.position="absolute";opIframe.id="PopupMenuIframe_"+this.MenuID;opIframe.scrolling="no";opIframe.style.zIndex=999999;if(this.Div.firstChild)this.Div.insertBefore(opIframe,this.Div.firstChild);else this.Div.appendChild(opIframe);var zpContent="<head>"+"<link href='"+bmtWebResolveURL("~/Style.css")+"' type='text/css' rel='stylesheet'>"+"</head>"+"<body ";if(!bmtWebDebug())zpContent+="ondrag='event.returnValue = false;' onselectstart='event.returnValue = false;' oncontextmenu='event.returnValue = false;'";zpContent+="></body>";opIframe.contentWindow.document.write(zpContent);var opDocument=opIframe.contentWindow.document;var opBody=opIframe.contentWindow.document.body;opBody.style.margin="0px;";var opTableOuter=opDocument.createElement("table");opTableOuter.cellPadding="2";opTableOuter.cellSpacing="0";opTableOuter.className="popupMenuTable";var opTBodyOuter=opDocument.createElement("tbody");var opTR=opDocument.createElement("tr");var opTD=opDocument.createElement("td");opTD.style.backgroundImage="url('"+bmtWebResolveURL("~/Controls/Popup/ImageCellBackground.gif")+"')";opTD.style.backgroundRepeat="repeat-y";var opTable=opDocument.createElement("table");opTable.cellPadding="0";opTable.cellSpacing="0";opTable.style.width="100%";var opTBody=opDocument.createElement("tbody");var opMenuItem;for(var lpLoop=0;lpLoop<this.MenuItems.length;lpLoop++){opMenuItem=this.MenuItems[lpLoop];switch(opMenuItem.MenuType){case this.MenuType.Item:opTBody.appendChild(this.CreateItem(opDocument,opMenuItem));break;case this.MenuType.SubMenu:opTBody.appendChild(this.CreateSubMenu(opDocument,opMenuItem));break;case this.MenuType.Divider:opTBody.appendChild(this.CreateGap(opDocument,opMenuItem));break;}}opTable.appendChild(opTBody);opTD.appendChild(opTable);opTR.appendChild(opTD);opTBodyOuter.appendChild(opTR);opTableOuter.appendChild(opTBodyOuter);opBody.appendChild(opTableOuter);this.Iframe=opIframe;}var lpScrollHeight=0;var lpScrollWidth=0;if(document.body.scrollHeight>document.body.clientHeight)lpScrollHeight=17;if(document.body.scrollWidth>document.body.clientWidth)lpScrollWidth=17;opIframe.style.left=lX;opIframe.style.top=lY;opIframe.style.zIndex=999999;opIframe.style.display="block";this.ResizeIframe();if((parseInt(opIframe.offsetTop)+parseInt(opIframe.offsetHeight))>(document.body.clientHeight+document.body.scrollTop+lpScrollHeight)){lpPosition=parseInt(document.body.offsetHeight)-opIframe.offsetHeight+document.body.scrollTop-lpScrollHeight;if(lpPosition<0)lpPosition=0;opIframe.style.top=lpPosition;}if((parseInt(opIframe.offsetLeft)+parseInt(opIframe.offsetWidth))>(document.body.clientWidth+document.body.scrollLeft)){if(zParentMenuID!=""&&zParentMenuID){lpPosition=bmtWebGetOffsetLeft(omPopupMenu[zParentMenuID].Iframe)-parseInt(opIframe.style.width)+1;if(lpPosition<0)lpPosition=0;opIframe.style.left=lpPosition;}}opIframe.focus();omPopupMenuShowing[omPopupMenuShowing.length]=this.MenuID;},AddSubMenu:function(oPopupMenu){SubMenus[oPopupMenu.MenuID]=oPopupMenu;},Hide:function(){if(this.Iframe!=null)this.Iframe.style.display="none";},ResizeIframe:function(){var opIframe=this.Iframe;opIframe.style.width=opIframe.contentWindow.document.body.firstChild.clientWidth+2;opIframe.style.height=opIframe.contentWindow.document.body.firstChild.clientHeight+2;},CreateItem:function(oDocument,oMenuItem){var opTable=oDocument.createElement("table");opTable.cellPadding="0";opTable.cellSpacing="0";opTable.style.width="100%";var opTBody=oDocument.createElement("tbody");var opTR=oDocument.createElement("tr");var opTD=oDocument.createElement("td");if(this.NoImages==false){opTR.appendChild(this.CreateImage(oDocument,oMenuItem));}opTD.style.paddingTop="3px";opTD.style.paddingBottom="3px";opTD.style.paddingRight="3px";opTD.nowrap="nowrap";opTD.appendChild(oDocument.createTextNode(oMenuItem.Text));opTR.appendChild(opTD);opTBody.appendChild(opTR);opTable.appendChild(opTBody);return this.CreateAnchorCell(opTable,oDocument,oMenuItem);},CreateSubMenu:function(oDocument,oMenuItem){var opTable=oDocument.createElement("table");opTable.cellPadding="0";opTable.cellSpacing="0";opTable.style.width="100%";var opTBody=oDocument.createElement("tbody");var opTR=oDocument.createElement("tr");var opTD=oDocument.createElement("td");if(this.NoImages==false){opTR.appendChild(this.CreateImage(oDocument,oMenuItem));}opTD.style.paddingTop="3px";opTD.style.paddingBottom="3px";opTD.style.paddingRight="3px";opTD.nowrap="nowrap";opTD.appendChild(oDocument.createTextNode(oMenuItem.Text));opTR.appendChild(opTD);opTD=oDocument.createElement("td");opTD.style.paddingRight="3px";opTD.style.paddingLeft="3px";opTD.style.width="4px";var opImage=oDocument.createElement("img");opImage.src=bmtWebResolveURL("~/Controls/Popup/RightArrow.gif");opImage.style.width="4px";opImage.style.height="7px";opTD.innerHTML=opImage.outerHTML;opTR.appendChild(opTD);opTBody.appendChild(opTR);opTable.appendChild(opTBody);return this.CreateAnchorCell(opTable,oDocument,oMenuItem);},CreateGap:function(oDocument,oMenuItem){var opTable=oDocument.createElement("table");opTable.cellPadding="0";opTable.cellSpacing="0";opTable.style.width="100%";var opTBody=oDocument.createElement("tbody");var opTR=oDocument.createElement("tr");var opTD=oDocument.createElement("td");if(this.NoImages==false){opTR.appendChild(this.CreateImage(oDocument,oMenuItem));}opTD.style.backgroundRepeat="repeat-x";opTD.style.backgroundImage="url("+bmtWebResolveURL("~/Controls/Popup/Gap.gif")+")";var opImage=oDocument.createElement("img");opImage.style.height="3px";opImage.style.width="1px";opImage.src=bmtWebResolveURL("~/Controls/Popup/Gap.gif");opTD.innerHTML=opImage.outerHTML;opTR.appendChild(opTD);opTBody.appendChild(opTR);opTable.appendChild(opTBody);return this.CreateAnchorCell(opTable,oDocument,oMenuItem);},CreateImage:function(oDocument,oMenuItem){var opTD=oDocument.createElement("td");opTD.style.width="27px";opTD.style.paddingLeft="2px";if(oMenuItem.MenuType!=this.MenuType.Divider){var opImage=oDocument.createElement("img");opImage.style.height="16px";opImage.style.width="16px";if(oMenuItem.ImagePath==""||!oMenuItem.ImagePath)opImage.src=bmtWebResolveURL("~/Controls/Popup/BlankImage.gif");else opImage.src=oMenuItem.ImagePath;opTD.innerHTML=opImage.outerHTML;}return opTD;},CreateAnchorCell:function(oTable,oDocument,oMenuItem){var opTR=oDocument.createElement("tr");opTR.id=oMenuItem.ItemID;if(oMenuItem.Hidden==true)opTR.style.display="none";var opAnchor=oDocument.createElement("a");var opTD=oDocument.createElement("td");opTD.style.width="100%";if(oMenuItem.MenuType!=this.MenuType.Divider){opAnchor.href="#";if(oMenuItem.MenuType==this.MenuType.Item){opAnchor.onclick=function(){oMenuItem.ClickFunction.call();popupMenuHide();};var zpMenuID=this.MenuID;opAnchor.onmouseover=function(){popupMenuSubMenuHide(zpMenuID);popupMenuMouseOver(this);};opAnchor.onfocus=function(){popupMenuSubMenuHide(zpMenuID);popupMenuMouseOver(this);};}else{var zpMenuID=this.MenuID;opAnchor.onmouseover=function(){popupMenuSubMenuHide(zpMenuID);popupMenuMouseOver(this);popupMenuSubMenuShow(zpMenuID,this,oMenuItem.MenuID);};opAnchor.onfocus=function(){popupMenuMouseOver(this);};opAnchor.onclick=function(){popupMenuSubMenuHide(zpMenuID);popupMenuSubMenuShow(zpMenuID,this,oMenuItem.MenuID);};}opAnchor.onmouseout=function(){popupMenuMouseOut(this);};opAnchor.onblur=function(){popupMenuMouseOut(this);};opAnchor.className="popupMenuAnchor";opAnchor.appendChild(oTable);opTD.appendChild(opAnchor);opTR.appendChild(opTD);}else{opTD.appendChild(oTable);opTR.appendChild(opTD);}return opTR;}}
function popupMenuMouseOver(oAnchor){oAnchor.className="popupMenuAnchorHover";oAnchor.style.backgroundImage="url("+bmtWebResolveURL("~/Controls/Popup/HoverBg.gif")+")";}
function popupMenuMouseOut(oAnchor){oAnchor.className="popupMenuAnchor";oAnchor.style.backgroundImage="";}
function popupMenuSubMenuHide(zMenuID){var opPopupMenu=omPopupMenu[zMenuID];if(opPopupMenu.SubMenuID!=""){opPopupMenu.Iframe.focus();omPopupMenu[opPopupMenu.SubMenuID].Hide();opPopupMenu.SubMenuID="";}}
function popupMenuSubMenuShow(zMenuID,oAnchor,zSubMenuID){var opPopupMenu=omPopupMenu[zMenuID];opPopupMenu.SubMenuID=zSubMenuID;var opPopupMenu=omPopupMenu[zMenuID];var opIframe=opPopupMenu.Iframe;var lpX=parseInt(opIframe.style.left)+bmtWebGetOffsetLeft(oAnchor)+oAnchor.clientWidth+4;var lpY=parseInt(opIframe.style.top)+bmtWebGetOffsetTop(oAnchor)-3;omPopupMenu[zSubMenuID].Show(lpX,lpY,zMenuID);}
function popupFolder(){return bmtWebResolveURL("~/Controls/Popup/");}
function popupMenuSetFunction(zMenuID,zItemID,oFunction){omPopupMenu[zMenuID].MenuItems[omPopupMenu[zMenuID].MenuItemsIndex[zItemID]].ClickFunction=oFunction;}
