var DivPopUp = new Object(); DivPopUp.open = function (divId, close, title) { // Disable all selects var selects = document.getElementsByTagName('select'); for (var i = 0; i < selects.length; i++) { selects[i].readOnly = true; } // Create transparent background DivPopUp.oDiv = document.createElement('div'); var oDiv = DivPopUp.oDiv; // Style the transparent background oDiv.style.position = 'absolute'; oDiv.style.backgroundColor = 'black'; oDiv.style.zIndex = '500'; oDiv.style.MozOpacity = '0.5'; oDiv.style.filter = 'alpha(opacity=50)'; oDiv.style.opacity = '0.5'; document.body.appendChild(oDiv); DivPopUp.popUp = $(divId); var popUp = DivPopUp.popUp; // Create and append container div if (popUp.parentNode.id != 'popUpContainer') { // The container div does not already exist and is created var container = document.createElement('div'); popUp.parentNode.appendChild(container); DivPopUp.container = container; container.id = 'popUpContainer'; if (close == null || close == true) { var closeDiv = document.createElement('div'); var titleDiv = document.createElement('div'); titleDiv.style.paddingLeft = '5px'; titleDiv.innerHTML = (title || ''); var closeButtonDiv = document.createElement('div'); closeButtonDiv.innerHTML = 'x'; closeButtonDiv.style.cursor = 'pointer'; closeButtonDiv.style.textAlign = 'center'; closeButtonDiv.style.fontWeight = 'bold'; closeDiv.id = 'popUpClose'; closeDiv.appendChild(closeButtonDiv); closeDiv.appendChild(titleDiv); closeButtonDiv.style.height = '18px'; closeButtonDiv.style.width = '25px'; closeButtonDiv.onclick = function () {DivPopUp.close();}; closeDiv.style.height = '18px'; closeDiv.style.width = parseInt(popUp.style.width) + parseInt(popUp.style.paddingLeft || 0) + parseInt(popUp.style.paddingRight || 0) + parseInt(popUp.style.borderLeftWidth || 0) + parseInt(popUp.style.borderRightWidth || 0); container.appendChild(closeDiv); closeDiv.style.width = '100%'; closeButtonDiv.style.styleFloat = 'right'; closeButtonDiv.style.cssFloat = 'right'; } container.style.width = (parseInt(popUp.style.width) + parseInt(popUp.style.paddingLeft || 0) + parseInt(popUp.style.paddingRight || 0) + parseInt(popUp.style.borderLeftWidth || 0) + parseInt(popUp.style.borderRightWidth || 0)) + 'px'; container.style.height = (parseInt(popUp.style.height) + parseInt(popUp.style.paddingTop || 0) + parseInt(popUp.style.paddingBottom || 0) + parseInt(popUp.style.borderTopWidth || 0) + parseInt(popUp.style.borderBottomWidth || 0) + (close == null || close == true ? parseInt($('popUpClose').style.height || 0) + 1 : 0)) + 'px'; popUp.style.display = ''; popUp.parentNode.removeChild(popUp); container.appendChild(popUp); if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) { var iframe = document.createElement('iframe'); DivPopUp.container.overlayFrame = iframe; iframe.src = 'about:blank'; iframe.scrolling = 'no'; iframe.frameBorder = '0'; iframe.style.position = 'absolute'; iframe.style.width = container.style.width; iframe.style.height = container.style.height; iframe.style.top = iframe.style.left = 0; container.parentNode.appendChild(iframe); } } else { var container = popUp.parentNode; DivPopUp.container = container; } var yOffset = (window.pageYOffset || document.body.scrollTop); DivPopUp.yOffset = yOffset; var xOffset = (window.pageXOffset || document.body.scrollLeft); DivPopUp.xOffset = xOffset; document.body.style.overflow = 'hidden'; document.body.parentNode.style.overflow = 'hidden'; container.style.position = 'absolute'; container.style.zIndex = '502'; scrollTo(xOffset,yOffset); DivPopUp._centerDiv(); container.style.display = ''; if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) { container.overlayFrame.style.display = ''; } window.onscroll = DivPopUp._noScroll; window.onresize = DivPopUp._centerDiv; if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) document.body.onkeyup = DivPopUp._catchKey; else window.onkeyup = DivPopUp._catchKey; } DivPopUp._catchKey = function (e) { var e = e || window.event; if (e.keyCode == 27 || e.which == 27) DivPopUp.close(); } DivPopUp._noScroll = function (e) { scrollTo(DivPopUp.xOffset,DivPopUp.yOffset); } DivPopUp._centerDiv = function () { var container = DivPopUp.container; var innerWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; DivPopUp.oDiv.style.top = DivPopUp.yOffset + 'px'; DivPopUp.oDiv.style.left = DivPopUp.xOffset + 'px'; DivPopUp.oDiv.style.width = innerWidth + 'px'; DivPopUp.oDiv.style.height = innerHeight + 'px'; var emptyWidth = innerWidth - parseInt(container.style.width); var emptyHeight = innerHeight - parseInt(container.style.height); container.style.left = (emptyWidth < 0 ? 0 : (emptyWidth/2) + DivPopUp.xOffset) + 'px'; container.style.top = (emptyHeight < 0 ? 0 : (emptyHeight/2) + DivPopUp.yOffset) + 'px'; if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) { container.overlayFrame.style.left = container.style.left; container.overlayFrame.style.top = container.style.top; } scrollTo(DivPopUp.xOffset,DivPopUp.yOffset); } DivPopUp.close = function () { var selects = document.getElementsByTagName('select'); for (var i = 0; i < selects.length; i++) { selects[i].readOnly = false; } DivPopUp.oDiv.parentNode.removeChild(DivPopUp.oDiv); DivPopUp.container.style.display = 'none'; if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) { DivPopUp.container.overlayFrame.style.display = 'none'; } document.body.style.overflow = ''; document.body.parentNode.style.overflow = ''; // Detach event functions window.onscroll = null; window.onresize = null; if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) document.body.onkeyup = null; else window.onkeyup = null; scrollTo(DivPopUp.xOffset,DivPopUp.yOffset); // Execute an optional onclose function if (DivPopUp.onClose) { DivPopUp.onClose(); } }