/** * POPUP WINDOW CODE v1.3 * Used for displaying DHTML only popups instead of using buggy modal windows. * * By Seth Banks (webmaster at subimage dot com) * http://www.subimage.com/ * * Contributions by: * Eric Angel - tab index code * Scott - hiding/showing selects for IE users * Todd Huss - inserting modal dynamically and anchor classes * * Up to date code can be found at http://www.subimage.com/dhtml/subModal * * * This code is free for you to use anywhere, just keep this comment block. */ // Popup code var lockedParent=true; var gPopupMask = null; var gPopupContainer = null; var gPopFrame = null; var gPopupIsShown = false; var gHideSelects = false; var defaultWidth; var defaultHeight; var topBarH=10; var botBarH=10; var gTabIndexes = new Array(); // Pre-defined list of tags we want to disable/enable tabbing into var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME","DIV"); /** * Initializes popup code on load. */ function initPopUp(closable,maximizable,html) { // Add the HTML to the body theBody = document.getElementsByTagName('BODY')[0]; popmask = document.createElement('div'); popmask.id = 'popupMask'; popcont = document.createElement('div'); popcont.id = 'popupContainer'; popcont.className='resizeMe'; var topBar=''; if(!(maximizable==false && closable==false)){ topBar=topBar+'.'; if(!(maximizable==false)) topBar=topBar+'' if(!(closable==false)) topBar=topBar+''; topBar=topBar+''; } var body=''; if(html){ body=''; body=body+html; }else body=body+''; body=body+''; var botBar =''; if(!(maximizable==false && closable==false)){ botBar = botBar+'.'; } popcont.innerHTML='
'+topBar+body+botBar+'
'; theBody.appendChild(popmask); theBody.appendChild(popcont); gPopupMask = getElementById("popupMask"); gPopupContainer = getElementById("popupContainer"); if (getElementById("popupFrame")) gPopFrame = getElementById("popupFrame"); // check to see if this is IE version 6 or lower. hide select boxes if so // maybe they'll fix this in version 7? var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) { gHideSelects = true; } } function isClosable(){ return (parent.getElementById('isClosable')&& parent.getElementById('isClosable').value=='true') } function startDragging(){ if (gHideSelects == true){ xEnableDrag(getElementById("popupContainer"),null,null,onPopMove);//IE won't lock the pop up window inside the parent page }else{ xEnableDrag(getElementById("popupContainer"),null,onMouseDrag,onPopMove); } } function stopDragging(){ if(window._xDrgMgr){ var tmp=getElementById('popupContainer'); xRemoveEventListener(tmp,'mousedown',_xOMD,false); _xDrgMgr.mm=false; xRemoveEventListener(tmp,'mousemove',_xOMM,false); tmp.xDraggable=false; tmp.xODS=null; tmp.xOD=null; tmp.xODE=null; } } function maximize(){ if(gPopFrame==null) gPopFrame=getElementById("popupFrame"); if (gPopFrame){ gPopFrame.style.width=getViewportWidth()+ 'px'; gPopFrame.style.height=(getViewportHeight()-(topBarH+botBarH))+'px'; centerPopWin(); var max_restore_but=getElementById("max_restore_but"); var max_restore_img=getElementById("max_restore_img"); if(max_restore_but!=null && max_restore_img!=null){ max_restore_but.href="javascript:restore()"; max_restore_img.src="./restore.gif"; } xMoveTo(gPopupContainer,0,0); onPopMove(); } } function restore(){ if(gPopFrame==null) gPopFrame=getElementById("popupFrame"); if (gPopFrame){ gPopFrame.style.width=defaultWidth; gPopFrame.style.height=defaultHeight-topBarH+botBarH; centerPopWin(); var max_restore_but=getElementById("max_restore_but"); var max_restore_img=getElementById("max_restore_img"); if(max_restore_but!=null && max_restore_img!=null){ max_restore_but.href="javascript:maximize()"; max_restore_img.src="./maximize.png"; } } } /** * @argument width - int in pixels * @argument height - int in pixels * @argument url - url to display * @argument scrolling - yes,no,auto * @argument closable - null or false when the frame won't have a close button * @argument maximizable - false when the frame won't have maximize button * @argument html - if the url is ignored and we prefer a custom html * @argument lockParent - false if parent won't be locked */ function showPopWin(url, width, height,scrolling,par,closeCauseRefr,closable,maximizable,html,isLocked) { if(isLocked==false) lockedParent=isLocked; lockParent(); //If the given height is longer than the view if (getViewportHeight()getViewportWidth() || gPopupContainer.offsetHeight>getViewportHeight()){ maximize(); } lockParent(); } function onMouseDrag(ele, mdx, mdy){ if (gPopupContainer==null) gPopupContainer=getElementById("popupContainer"); xMoveTo(gPopupContainer,xLeft(gPopupContainer)+mdx,xTop(gPopupContainer)+mdy); onPopMove(); } function onPopMove(){ if (xLeft(gPopupContainer)<0 ) xMoveTo(gPopupContainer,0,xTop(gPopupContainer)); if (xLeft(gPopupContainer)>(getViewportWidth()-10)) xMoveTo(gPopupContainer,(getViewportWidth()-10),xTop(gPopupContainer)); if (xTop(gPopupContainer)<0) xMoveTo(gPopupContainer,xLeft(gPopupContainer),0); if (xTop(gPopupContainer)>(getViewportHeight()-topBarH)) xMoveTo(gPopupContainer,xLeft(gPopupContainer),(getViewportHeight()-topBarH)); lockParent(); } // var gi = 0; function centerPopWin(width, height) { if (gPopupIsShown == true) { if (width == null || isNaN(width)) { width = gPopupContainer.offsetWidth; } if (height == null) { height = gPopupContainer.offsetHeight; } //var theBody = document.documentElement; var theBody = document.getElementsByTagName("BODY")[0]; theBody.style.overflow = "hidden"; var scTop = parseInt(theBody.scrollTop,10); var scLeft = parseInt(theBody.scrollLeft,10); gPopupMask.style.top = scTop + "px"; gPopupMask.style.left = scLeft + "px"; setMaskSize(); var fullHeight = getViewportHeight(); var fullWidth = getViewportWidth(); gPopupContainer.style.top = (scTop + ((fullHeight - height) / 2)) + "px"; gPopupContainer.style.left = (scLeft + ((fullWidth - width) / 2)) + "px"; } } function displayElementById(id) { if(getElementById(id)!=null) getElementById(id).style.visibility="visible"; } function hideElementById(id) { if(getElementById(id)!=null) getElementById(id).style.visibility="hidden"; } function getElementById(id){ var tmp =window.top.document.getElementById(id); if(tmp!=null) return tmp; return document.getElementById(id); } var menuDisplay; /** * Hopping that there is only one menu.. */ function hideMenu(){ if(typeof gmobj!="undefined"){ var menu=gmobj('menu0'); if(menu){ menu.style.display="none"; } } if(getElementById('menu0')) getElementById('menu0').style.visibility="hidden"; } function displayMenu(){ if(typeof gmobj!="undefined"){ var menu=gmobj('menu0'); if(menu){ menu.style.display=""; } } if(getElementById('menu0')) getElementById('menu0').style.visibility="visible"; } function hideTree() { if(getElementById('tree_td')){ getElementById('tree_td').style.display='none'; } } function displayTree() { if(getElementById('tree_td')){ getElementById('tree_td').style.display=''; } } function setMaskSize() { var theBody = document.getElementsByTagName("BODY")[0]; var fullHeight = getViewportHeight(); var fullWidth = getViewportWidth(); // Determine what's bigger, scrollHeight or fullHeight / width if (fullHeight > theBody.scrollHeight) { popHeight = fullHeight; } else { popHeight = theBody.scrollHeight } if(!gPopupMask) gPopupMask=getElementById("popupMask"); if(gPopupMask){ gPopupMask.style.height = popHeight + "px"; gPopupMask.style.width = theBody.scrollWidth + "px"; } } // Tab key trap. iff popup is shown and key was [TAB], suppress it. // @argument e - event - keyboard event that caused this function to be called. function keyDownHandler(e) { if (gPopupIsShown && e.keyCode == 9) return false; } // For IE. Go through predefined tags and disable tabbing into them. function disableTabIndexes() { if (document.all) { var i = 0; for (var j = 0; j < gTabbableTags.length; j++) { var tagElements = document.getElementsByTagName(gTabbableTags[j]); for (var k = 0 ; k < tagElements.length; k++) { gTabIndexes[i] = tagElements[k].tabIndex; tagElements[k].tabIndex="-1"; i++; } } } } // For IE. Restore tab-indexes. function restoreTabIndexes() { if (document.all) { var i = 0; for (var j = 0; j < gTabbableTags.length; j++) { var tagElements = document.getElementsByTagName(gTabbableTags[j]); for (var k = 0 ; k < tagElements.length; k++) { tagElements[k].tabIndex = gTabIndexes[i]; tagElements[k].tabEnabled = true; i++; } } } } /** * Hides all drop down form select boxes on the screen so they do not appear above the mask layer. * IE has a problem with wanted select form tags to always be the topmost z-index or layer * * Thanks for the code Scott! */ function hideSelectBoxes() { for(var i = 0; i < window.document.forms.length; i++) { for(var e = 0; e < window.document.forms[i].length; e++){ if(window.document.forms[i].elements[e].tagName == "SELECT") { if ((window.document.forms[i].elements[e].id == "popupMask")|| (window.document.forms[i].elements[e].id == "popupContainer")){ alert(window.document.forms[i].elements[e].id+' -> hidden'); } window.document.forms[i].elements[e].style.visibility="hidden"; } } } } /** * Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed. * IE has a problem with wanted select form tags to always be the topmost z-index or layer */ function displaySelectBoxes() { for(var i = 0; i < window.document.forms.length; i++) { for(var e = 0; e < window.document.forms[i].length; e++){ if(window.document.forms[i].elements[e].tagName == "SELECT") { if ((window.document.forms[i].elements[e].id == "popupMask")|| (window.document.forms[i].elements[e].id == "popupContainer")){ alert(window.document.forms[i].elements[e].id+' -> visible'); } window.document.forms[i].elements[e].style.visibility="visible"; } } } }