var topLevelWnd = null;
function getTopLevelWnd()
{
if (topLevelWnd == null)
{
topLevelWnd = this;
while (topLevelWnd.parent != topLevelWnd && isDispatchableWindow(topLevelWnd.parent))
{
topLevelWnd = topLevelWnd.parent;
}
while (topLevelWnd.opener != null && isDispatchableWindow(topLevelWnd.opener))
{
topLevelWnd = topLevelWnd.opener;
}
}
return topLevelWnd;
}
function getAbsoluteFramePath(frameName)
{
var absolutePath = null;
var framePath = getRelativeFramePath(getTopLevelWnd(), frameName);
if (framePath != null)
{
absolutePath = "getTopLevelWnd()." + framePath;
}
return absolutePath;
}
function getRelativeFramePath(containerFrame, frameName)
{
var framePath = null;
for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
{
var objChildFrame = containerFrame.frames[iChildFrame];
if (isAccessibleWindow(objChildFrame) && objChildFrame.name == frameName)
{
framePath = "frames[" + iChildFrame + "]";
break;
}
}
if (framePath == null)
{
for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
{
var childFramePath = getRelativeFramePath(containerFrame.frames[iChildFrame], frameName);
if (childFramePath != null)
{
framePath = "frames[" + iChildFrame + "]." + childFramePath;
break;
}
}
}
return framePath;
}
function getFrameNamePath(wnd)
{
// recurively build parent's frame path
if (wnd == getTopLevelWnd())
{
return "";
}
var parent = wnd.parent;
if (parent != null)
{
for (var i = 0; i < parent.frames.length; i++)
{
var frameWnd = parent.frames[i];
if (frameWnd == wnd)
{
var parentFrameNamePath = getFrameNamePath(parent);
if (parentFrameNamePath != null)
{
return parentFrameNamePath + '/' + frameWnd.name;
}
}
}
}
return null;
}
function isValidFrameNamePath(frameNamePath)
{
return _isValidFrameNamePath(getTopLevelWnd(), frameNamePath.substring(1));
}
function _isValidFrameNamePath(wnd, frameNamePath)
{
var slash = frameNamePath.indexOf("/");
if (slash != -1)
{
var frameName = frameNamePath.substring(0, slash);
for (var i = 0; i < wnd.frames.length; i++)
{
if (wnd.frames[i].name == frameName)
{
return _isValidFrameNamePath(wnd.frames[i], frameNamePath.substring(slash+1))
}
}
return false;
}
else
{
return true;
}
}
function walkDownFrameSet(strFramePath)
{
var strResult = strFramePath;
if ((strResult != null) && (typeof strResult != "undefined"))
{
var strFrameUrl = eval(strResult).document.location.href;
while ((eval(strResult).isNest != null) && (typeof eval(strResult).isNest != "undefined"))
{
strResult += ".frames[0]";
strFrameUrl = eval(strResult).document.location.href;
}
}
return strResult;
}
function isDispatchableWindow(wnd)
{
var bIsDispatchable = false;
if (typeof(wnd.getTopLevelWnd) != "undefined")
{
bIsDispatchable = isAccessibleWindow(wnd);
}
return bIsDispatchable;
}
function isAccessibleWindow(wnd)
{
var bIsAccessible = false;
if (typeof(wnd.frames) == "object")
{
if ("x" + wnd.location + "x" != "xx")
{
if (typeof(wnd.frames) == "object")
{
bIsAccessible = true;
}
}
}
return bIsAccessible;
}
function isWindowInitialised(wnd)
{
var bWindowInitialised = false;
if (isDispatchableWindow(wnd) == true)
{
if (typeof(wnd.g_bWindowInitialised) != "undefined")
{
bWindowInitialised = wnd.g_bWindowInitialised;
}
else
{
bWindowInitialised = true;
}
}
return bWindowInitialised;
}
function createTestHook(contextPath)
{
var element = window.document.createElement("IMG");
element.id = "wdk_window_initialised";
element.src = contextPath + "/wdk/modalFade.gif";
with (element.style)
{
top = 1;
left = 1;
width = 1;
height = 1;
alt = "";
overflow = "hidden";
position = "absolute";
visibility = "visible";
}
window.document.body.appendChild(element);
}
function setFocusOnFrame(strFrameName)
{
var strFramePath = getAbsoluteFramePath(strFrameName);
var frameWindow = eval(getAbsoluteFramePath(strFrameName));
frameWindow.focus();
}
