/* ------------------------------------------------------------------------ * * SAS Institute, Inc. * * * * Copyright (c) 2005 SAS Institute, Inc. All rights reserved. * * * * ------------------------------------------------------------------------ */ //if (window.opener != undefined) { // window.onunload = sas_modalSelector_unloadIfModal; //} var currentDialog = null; var browserName=navigator.appName; var debug = false; if (debug) { w = window.open("", "winname", "width=200 height=200 resizable=1 scrollbars=1 status=0"); w.document.bgColor = "#FFCC00"; } function sas_modalSelector_setFocusOnModal() { if (browserName=="Netscape") sas_modalSelector_setFocusOnSelectorDialog(); else if (browserName=="Microsoft Internet Explorer") setTimeout("sas_modalSelector_setFocusOnSelectorDialog()", 25); return true; } function sas_modalSelector_openModal(url, browsername, features, modal) { /* The following code ensures that we have a new window each time a selector is displayed. There is a problem with reusing the window, in that the unload thread doesn't complete before we set the focus event handlers. Since our onUnload is resetting the focus event handler, it was overriding the handlers we set immediately after doing the window.open. If we could delay the setting of the event handlers after window.open until the onunload is complete, the extra window.open below would not be necessary, but this does not seem to work. */ if (browserName=="Netscape") currentDialog = window.open("StreamContentServlet?NOOP=true", browsername, "width=20 height=20 screenX=5000 screenY=5000"); else if (browserName=="Microsoft Internet Explorer") currentDialog = window.open("StreamContentServlet?NOOP=true", browsername, "width=20 height=20 left=5000 top=5000"); if (currentDialog != null) currentDialog.close(); currentDialog = window.open(url, browsername, features, true); parent.window.selectorDialog = currentDialog; if (window.attachEvent != null) { window.attachEvent("onfocus",sas_modalSelector_setFocusOnModal); window.attachEvent("onunload",sas_modalSelector_closeModal); } else if (window.addEventListener != null) { window.addEventListener("focus",sas_modalSelector_setFocusOnModal,false); window.addEventListener("unload",sas_modalSelector_closeModal,false); } currentDialog.modal = modal; return currentDialog; } function sas_modalSelector_setFocusOnSelectorDialog() { if (currentDialog != null) { try{ currentDialog.focus(); } catch (e) { sas_modalSelector_clearCurrent(); } } } function sas_modalSelector_closeModal() { if (currentDialog != null) { if (currentDialog.closed) { // This happens sometimes. //alert("Dialog is already closed!"); } else { if (currentDialog.modal) sas_modalSelector_clearCurrent(); if (currentDialog) currentDialog.close(); } } sas_modalSelector_unloadIfModal(); currentDialog = null; } function sas_modalSelector_clearCurrent() { currentDialog = null; if (window.detachEvent != null) { window.detachEvent("onfocus",sas_modalSelector_setFocusOnModal); window.detachEvent("onunload",sas_modalSelector_closeModal); } else if (window.removeEventListener != null) { window.removeEventListener("focus",sas_modalSelector_setFocusOnModal,false); window.removeEventListener("unload",sas_modalSelector_closeModal,false); } } function sas_modalSelector_unloadIfModal() { if (window.opener != undefined) { try { window.opener.sas_modalSelector_clearCurrent(); } catch (e) { // parent has probably unloaded already } } }