if (typeof(getTopLevelWnd().modalWnd) == "undefined")
{
getTopLevelWnd().modalWnd = null;
}
if (typeof(wdk) == "undefined")
{
wdk = {};
}
if (typeof(wdk.modalPopupConfig) == "undefined")
{
wdk.modalPopupConfig = {};
}
if (typeof wdk.modalPopupConfig.WindowSize == "undefined")
{
g_frameMap = new FrameMap();
wdk.modalPopupConfig.WindowSize = new function()
{
this.widthByName = {};
this.heightByName = {};
this.register = function(strSizeName, nWidth, nHeight)
{
this.widthByName[strSizeName] = nWidth;
this.heightByName[strSizeName] = nHeight;
}
this.getWidth = function(strSizeName)
{
var nWidth = 550;
if (strSizeName != null && typeof(strSizeName) != "undefined")
{
var nVal = this.widthByName[strSizeName];
if (nVal)
{
nWidth = nVal;
}
}
return nWidth;
}
this.getHeight = function(strSizeName)
{
var nHeight = 450;
if (strSizeName != null && typeof(strSizeName) != "undefined")
{
var nVal = this.heightByName[strSizeName];
if (nVal)
{
nHeight = nVal;
}
}
return nHeight;
}
}
} // end if (typeof wdk.modalPopupConfig.WindowSize == "undefined")
function beginModal()
{
var topLevelWnd = getTopLevelWnd();
// We're Initiating modality if this is the first window to call beginModal [ since the last endModal ]
var bInitiatingModality = (topLevelWnd.modalWnd == null);
// We're Maintaining modality when another window has already called beginModal but this window has been removed.
var bMaintainingModality = ((topLevelWnd.modalWnd != null) && doesWindowExist(topLevelWnd.modalWnd) == false);
if (bInitiatingModality || bMaintainingModality)
{
topLevelWnd.modalWnd = window;
// Only resize if we're Initiating modality. If we try to resize while maintaining
if (bInitiatingModality)
{
if (topLevelWnd.document.body.tagName == 'FRAMESET')
{
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
g_frameMap.fill(topLevelWnd);
}
resizeFrameset(topLevelWnd.document.body);
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
g_frameMap.clear();
}
}
}
// we don't want to invoke this as focus is already on the modal dialog -
if (!isModalPopup())
{
window.focus();
}
}
}
function endModal(bForced)
{
var topLevelWnd = getTopLevelWnd();
var bAllowEndModal = (doesWindowExist(topLevelWnd.modalWnd) == false || bForced);
if (topLevelWnd.modalWnd != null && bAllowEndModal)
{
topLevelWnd.modalWnd = null;
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
g_frameMap.fill(topLevelWnd);
}
restoreFrameset(topLevelWnd.document.body);
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
g_frameMap.clear();
}
}
}
function FrameMap()
{
this.prefix = "DCTM_FRAME";
this.map = new Array();
this.fill = function(win)
{
if (win.frames.length > 0)
{
for (var j=0; j < win.frames.length; j++)
{
var frame = win.frames[j];
if (isAccessibleWindow(frame))
{
this.addFrame(frame);
if (frame.frames.length > 0)
{
this.fill(frame);
}
}
}
}
};
this.getWindow = function(frame)
{
var lookup = null;
try
{
lookup = frame.document.lookup;
}
catch(e)
{
}
return (lookup == null) ? null : this.map[lookup];
};
this.clear = function()
{
this.map = new Array();
};
this.addFrame = function(frame)
{
var uniqueName = this.generateUniqueLookup(frame.name);
frame.document.lookup = uniqueName;
if (Trace_MODAL) modal_trace("Adding - " + frame.document.lookup + "," + frame.name);
this.map[uniqueName] = frame;
};
this.generateUniqueLookup = function(frameName)
{
var idx = 0;
var noName = false;
var uniqueName = frameName;
// The check for "<!--" is a Safari 1.2 issue
// If you don't have a frame name, or you have duplicate names,
if (!uniqueName || uniqueName.indexOf("<!--") != -1)
{
noName = true;
uniqueName = this.prefix + "_" + idx;
}
while (typeof this.map[uniqueName] != 'undefined')
{
if (noName)
{
uniqueName = this.prefix + "_" + (idx++)
}
else
{
uniqueName = frameName + "_" + (idx++);
}
}
return uniqueName;
};
}
function resizeFrameset(frameset)
{
var framesetSize = null;
// get the frameset's rows/cols
var rowsCols;
if (frameset.rows != null && frameset.rows != "")
{
rowsCols = frameset.rows;
}
else
{
rowsCols = frameset.cols;
}
var rowsColsArray = rowsCols.split(',');
var newRowsCols = "";
var bCollapseAll = true;
var childFrames = getChildFrames(frameset);
for (var i = 0; i < childFrames.length; i++)
{
var size = rowsColsArray[i];
var childFrame = childFrames[i];
if (childFrame.tagName == 'FRAME')
{
if (Trace_MODAL) modal_trace("Resizing Frame : " + childFrame.name);
setCustomAttribute(childFrame, 'resized', true);
setCustomAttribute(childFrame, 'prev_noResize', getCustomAttribute(childFrame, 'noResize'));
setCustomAttribute(childFrame, 'prev_marginHeight', getCustomAttribute(childFrame, 'marginHeight'));
setCustomAttribute(childFrame, 'prev_marginWidth', getCustomAttribute(childFrame, 'marginWidth'));
setCustomAttribute(childFrame, 'prev_scrolling', getCustomAttribute(childFrame, 'scrolling'));
setCustomAttribute(childFrame, 'noResize', false);
setCustomAttribute(childFrame, 'marginHeight', 0);
setCustomAttribute(childFrame, 'marginWidth', 0);
// applets on the page to be initialized several times. Not setting this here doesn't
if (!g_clientInfo.isBrowser(ClientInfo.FIREFOX))
{
childFrame.scrolling    = 'no';
}
var childWnd = getWindowReference(childFrame);
if (childWnd && isAccessibleWindow(childWnd) == true)
{
if (childWnd.document.body && childWnd.document.body.tagName == 'FRAMESET')
{
childFrame = childWnd.document.body;
}
else
{
if (childWnd == getTopLevelWnd().modalWnd || resizeIFrames(childWnd, getTopLevelWnd().modalWnd))
{
size = "100%";
framesetSize = "100%";
}
else if (typeof(childWnd.ignoreModal) == "undefined")
{
size = "0";
blockKeyboardAccess(childFrame);
}
else
{
bCollapseAll = false;
}
}
}
}
if (childFrame.tagName == 'FRAMESET')
{
var newsize = resizeFrameset(childFrame);
if (newsize != null)
{
size = newsize;
if (size == "100%")
{
framesetSize = "100%";
}
}
}
if (newRowsCols != "")
{
newRowsCols += ',';
}
newRowsCols += size;
}
if (frameset.rows != null && frameset.rows != "")
{
setCustomAttribute(frameset, 'prev_rows', getCustomAttribute(frameset, 'rows'));
setCustomAttribute(frameset, 'rows', newRowsCols);
}
else
{
setCustomAttribute(frameset, 'prev_cols', getCustomAttribute(frameset, 'cols'));
setCustomAttribute(frameset, 'cols', newRowsCols);
}
setCustomAttribute(frameset, 'resized', true);
setCustomAttribute(frameset, 'prev_border', getCustomAttribute(frameset, 'border'));
setCustomAttribute(frameset, 'prev_frameBorder', getCustomAttribute(frameset, 'frameBorder'));
setCustomAttribute(frameset, 'prev_frameSpacing', getCustomAttribute(frameset, 'frameSpacing'));
setCustomAttribute(frameset, 'border', 0);
setCustomAttribute(frameset, 'frameBorder', 0);
setCustomAttribute(frameset, 'frameSpacing', 0);
if (bCollapseAll && framesetSize == null)
{
framesetSize = "0";
}
return framesetSize;
}
function restoreFrameset(frameset)
{
var childFrames = getChildFrames(frameset);
for (var i = 0; i < childFrames.length; i++)
{
var childFrame = childFrames[i];
if (childFrame.tagName == 'FRAME')
{
if (getCustomAttribute(childFrame,'resized'))
{
if (Trace_MODAL) modal_trace("Restoring Frame :" + childFrame.name);
setCustomAttribute(childFrame, 'noResize', getCustomAttribute(childFrame, 'prev_noResize'));
setCustomAttribute(childFrame, 'marginHeight', getCustomAttribute(childFrame, 'prev_marginHeight'));
setCustomAttribute(childFrame, 'marginWidth', getCustomAttribute(childFrame, 'prev_marginWidth'));
setCustomAttribute(childFrame, 'scrolling', getCustomAttribute(childFrame, 'prev_scrolling'));
setCustomAttribute(childFrame, 'resized', false);
}
var childWnd = getWindowReference(childFrame);
if (childWnd && isAccessibleWindow(childWnd) == true)
{
restoreKeyboardAccess(childFrame);
if (childWnd.frames.length > 0)
{
if (childWnd.document.body.tagName == "BODY")
{
restoreIFrames(childWnd);
}
else
{
childFrame = childWnd.document.body;
}
}
}
}
if (childFrame && childFrame.tagName == 'FRAMESET')
{
restoreFrameset(childFrame);
}
}
if (getCustomAttribute(frameset, 'resized'))
{
setCustomAttribute(frameset, 'border', getCustomAttribute(frameset, 'prev_border'));
setCustomAttribute(frameset, 'frameBorder', getCustomAttribute(frameset, 'prev_frameBorder'));
setCustomAttribute(frameset, 'frameSpacing', getCustomAttribute(frameset, 'prev_frameSpacing'));
var framesetRows = getCustomAttribute(frameset, 'rows');
if (framesetRows != null && framesetRows != "")
{
setCustomAttribute(frameset, 'rows', getCustomAttribute(frameset,'prev_rows'));
}
else
{
setCustomAttribute(frameset, 'cols', getCustomAttribute(frameset,'prev_cols'));
}
setCustomAttribute(frameset, 'resized', false);
}
}
function getChildFrames(frameset)
{
var childFrames = [];
var iChildFrames = 0;
for (var iChild = 0; iChild < frameset.childNodes.length; iChild++)
{
var child = frameset.childNodes[iChild];
if (child.tagName == 'FRAME' || child.tagName == 'FRAMESET')
{
childFrames[iChildFrames++] = child;
}
}
return childFrames;
}
function getWindowReference(frame)
{
var win = (frame.contentWindow) ? frame.contentWindow : g_frameMap.getWindow(frame);
return win;
}
function setCustomAttribute(frame, attrName, attrValue)
{
if (frame && attrName)
{
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
frame.setAttribute(attrName, attrValue);
}
else
{
frame[attrName] = attrValue;
}
}
}
function getCustomAttribute(frame, attributeName)
{
var attributeValue = null;
if (frame && attributeName)
{
if (g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
attributeValue = frame.getAttribute(attributeName);
}
else
{
attributeValue = frame[attributeName];
}
}
return attributeValue;
}
function blockKeyboardAccess(frame)
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
frame.prev_tabIndex = frame.tabIndex;
frame.tabIndex = -1;
}
else
{
var frameWnd = getWindowReference(frame);
if (frameWnd)
{
frameWnd.prev_onfocus = frameWnd.onfocus;
frameWnd.onfocus = function() {
if (getTopLevelWnd().modalWnd)
{
getTopLevelWnd().modalWnd.focus();
}
};
}
}
}
function restoreKeyboardAccess(frame)
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
frame.tabIndex = (frame.prev_tabIndex) ? frame.prev_tabIndex : null;
}
else
{
var frameWnd = getWindowReference(frame);
if (frameWnd)
{
frameWnd.onfocus = (frameWnd.prev_onfocus) ? frameWnd.prev_onfocus : null;
}
}
}
function isModal()
{
var topLevelWnd = getTopLevelWnd();
return (topLevelWnd.modalWnd != null);
}
function doesWindowExist(wnd)
{
return _doesWindowExist(getTopLevelWnd(), wnd);
}
function _doesWindowExist(parentWnd, wnd)
{
for (var i = 0; i < parentWnd.frames.length; i++)
{
var childWnd = parentWnd.frames[i];
if (childWnd == wnd || _doesWindowExist(childWnd, wnd) == true)
{
return true;
}
}
return false;
}
function modal_trace(msg)
{
Trace_println("modal.js: " + msg);
}
if (typeof(getTopLevelWnd().modalPopupWindow) == "undefined")
{
getTopLevelWnd().modalPopupWindow = null;
}
function registerModalPopupWindow(modalPopupWindow)
{
getTopLevelWnd().modalPopupWindow = modalPopupWindow;
}
function unregisterModalPopupWindow()
{
getTopLevelWnd().modalPopupWindow = null;
}
function getRegisteredModalPopupWindow()
{
return getTopLevelWnd().modalPopupWindow;
}
function beginModalPopupMode(strFrameName, strFormId, strPopupWindowSize, strRefreshParentWindow)
{
var targetWindow = null;
var formElement = null;
if (strFrameName != null && strFrameName.length > 0)
{
targetWindow = eval(getAbsoluteFramePath(strFrameName));
}
if (targetWindow == null)
{
targetWindow = window;
}
if (strFormId != null && strFormId.length > 0)
{
formElement = targetWindow.document.forms[strFormId];
}
else
{
formElement = targetWindow.document.forms[0];
}
if (formElement  != null)
{
formElement.__dmfUseModalPopup.value = "true";
formElement.__dmfModalPopupWindowSize.value = strPopupWindowSize;
formElement.__dmfRefreshParentWindow.value = strRefreshParentWindow;
}
else
{
throw "Cannot locate formElement given these frame and form names : " + strFrameName + ", " + strFormId + ".";
}
}
function endModalPopupMode(strFrameName, strFormId)
{
var targetWindow = null;
var formElement = null;
unregisterModalPopupWindow();
if (strFrameName != null && strFrameName.length > 0)
{
targetWindow = eval(getAbsoluteFramePath(strFrameName));
}
if (targetWindow == null)
{
targetWindow = window;
}
if (strFormId != null && strFormId.length > 0)
{
formElement = targetWindow.document.forms[strFormId];
}
else
{
formElement = targetWindow.document.forms[0];
}
if (formElement  != null)
{
formElement.__dmfUseModalPopup.value = "false";
formElement.__dmfModalPopupWindowSize.value = "";
formElement.__dmfRefreshParentWindow.value = "";
}
else
{
throw "Cannot locate formElement given these frame and form names : " + strFrameName + ", " + strFormId + ".";
}
}
function getPopupWindowName(win, nestDepth)
{
var postFix = "_popup_window_";
var windowName = win.name;
var popupName = windowName + postFix;
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
var index = parseInt(nestDepth) + 1;
if (windowName.indexOf(postFix) > -1)
{
popupName = windowName.substring(0, windowName.lastIndexOf("_") + 1) + index;
}
else
{
popupName = windowName + postFix + index;
}
}
return popupName;
}
function openModalPopupWindow(parentWin, strParentFormId, strPopupWindowSize, strPopupWindowName, strUrl)
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
var args = new Object();
args.m_parentWindow = parentWin;
args.m_parentFormId = strParentFormId;
args.m_popupWindowName = strPopupWindowName;
args.m_isWDKModalPopup = true;
var topLevelWindow = parentWin;
if((!!(topLevelWindow.dialogArguments)) && (!!(topLevelWindow.dialogArguments.m_isWDKModalPopup))) {
topLevelWindow = dialogArguments.topLevelWindow;
}
args.topLevelWindow = topLevelWindow;
var width = getModalPopupWindowWidth(strPopupWindowSize);
var height = getModalPopupWindowHeight(strPopupWindowSize);
var left = getWindowLeft(parentWin) + getWindowWidth(parentWin)/2  - width/2;
var top = getWindowTop(parentWin) + getWindowHeight(parentWin)/2 - height/2;
var strFeatures = "dialogWidth:" + width + "px;" + "dialogHeight:" + height + "px;" +
"dialogLeft:" + left + "px;" + "dialogTop:" + top + "px;" +
"status:no;resizable:yes;scroll:no;";
var strClientEvents = showModalDialog(strUrl, args, strFeatures);
if (typeof (strClientEvents) != "undefined")
{
var clientEvents = eval(strClientEvents);
processClientEvents(clientEvents);
}
}
}
function getModalPopupWindowWidth(strSize)
{
return wdk.modalPopupConfig.WindowSize.getWidth(strSize);
}
function getModalPopupWindowHeight(strSize)
{
return wdk.modalPopupConfig.WindowSize.getHeight(strSize);
}
function resizeModalPopupWindowWithDimension(win, width, height)
{
if (win.getWindowOpener() != null)
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
win.dialogWidth = width + "px";
win.dialogHeight = height + "px";
}
}
}
function resizeModalPopupWindow(win, size)
{
resizeModalPopupWindowWithDimension(win, getModalPopupWindowWidth(size), getModalPopupWindowHeight(size));
}
function centerModalPopupWindow(win)
{
if (win.getWindowOpener() != null)
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
var parentWin = win.getWindowOpener();
win.dialogLeft = getWindowLeft(parentWin) + getWindowWidth(parentWin)/2 - getWindowWidth(win)/2;
win.dialogTop = getWindowTop(parentWin) + getWindowHeight(parentWin)/2 - getWindowHeight(win)/2;
}
}
}
function getWindowWidth(win)
{
var width = screen.availWidth;
if (win)
{
if (win.dialogWidth)
{
// showModalDialog dialogWidth format is "[num]px". Need to strip the "px" and return [num].
width = parseInt(win.dialogWidth.substring(0, win.dialogWidth.length - 2))
}
}
return width;
}
function getWindowHeight(win)
{
var height = screen.availHeight;
if (win)
{
if (win.dialogHeight)
{
// showModalDialog dialogHeight format is "[num]px". Need to strip the "px" and return [num].
height = parseInt(win.dialogHeight.substring(0, win.dialogHeight.length - 2));
}
}
return height;
}
function getWindowLeft(win)
{
var left = 0;
if (win)
{
if (win.dialogLeft)
{
// showModalDialog dialogLeft format is "[num]px". Need to strip the "px" and return [num].
left = parseInt(win.dialogLeft.substring(0, win.dialogLeft.length - 2));
}
else if (win.screenLeft)
{
var topWin = getTopLevelWnd();
left = topWin.screenLeft;
}
}
return left;
}
function getWindowTop(win)
{
var top = 0;
if (win)
{
if (win.dialogTop)
{
// showModalDialog dialogTop format is "[num]px". Need to strip the "px" and return [num].
top = parseInt(win.dialogTop.substring(0, win.dialogTop.length - 2));
}
}
return top;
}
function onBeforeUnloadModalPopup(evt)
{
if (typeof(evt) == 'undefined')
{
evt = window.event;
}
//Bug 159990 - Don't consider event coordinates during unload.
if (evt)
{
var parentWindow = window.getWindowOpener();
if (parentWindow != null)
{
parentWindow.endModalPopupMode(null, parentWindow.document.forms[0].name);
}
}
}
if (window.isModalPopup())
{
if (g_clientInfo.isBrowser(ClientInfo.MSIE))
{
attachEvent("onbeforeunload", onBeforeUnloadModalPopup);
}
}
function resizeIFrames(wnd, modalWnd)
{
var isFound = false;
for (var i=0; i<wnd.frames.length; i++)
{
if (wnd.frames[i] === modalWnd)
{
isFound = true;
break;
}
else
{
if (resizeIFrames(wnd.frames[i], modalWnd))
{
isFound = true;
break;
}
}
}
if (isFound)
{
setCustomAttribute(wnd, "visited", true)
if (typeof (wnd.beginModalHandler) === 'function')
{
wnd.beginModalHandler(modalWnd);
}
}
return isFound;
}
function restoreIFrames(wnd)
{
if (wnd.visited)
{
setCustomAttribute(wnd, "visited", false);
if (typeof (wnd.endModalHandler)  === 'function')
{
wnd.endModalHandler();
}
}
for (var i=0; i< wnd.frames.length; i++)
{
restoreIFrames(wnd.frames[i]);
}
}

