var WindowObjectReferenceOfRequestedPopup , WindowObjectReferenceOfIntermediaryPopup;

function OpenRequestedPopup(strUrl, strTarget)
{
var windowWidth, windowHeight, windowLeft, windowTop;

if(typeof window.screenX == "number" && typeof window.innerWidth == "number")
 {
 windowWidth = 1024;
 windowHeight = 768;
 windowLeft = 0;
 windowTop = 0;
 }
else if(typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number")
 {
 windowWidth = 1024;
 windowHeight = 768;
 windowLeft = 0;
 windowTop = 0;
 }
else
 {
var windowWidth = 1024;
var windowHeight = 768;
var windowLeft = 0;
var windowTop = 0;
 };

/* The above code is just to define reasonable sizes and initial positions to the popup to be. */

if (WindowObjectReferenceOfRequestedPopup == null || WindowObjectReferenceOfRequestedPopup.closed)
 {
 WindowObjectReferenceOfRequestedPopup = window.open(strUrl, strTarget, "top=" + windowTop + ",left=" + windowLeft + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar,toolbar,location,resizable,scrollbars,status");
 }
else
 {
 WindowObjectReferenceOfRequestedPopup.focus();
 };

/*
The above 9 lines of code creates the popup; if the popup is already opened, then it is only brought on top. This feature is possible only if the user allows it via the setting Edit/Preferences.../category:Advanced/Scripts & Plugins/Allow webpages to:/Raise or lower windows
*/
}

function OpenIntermediaryPopup(strUrl, strTarget)
{
var windowWidth, windowHeight, windowLeft, windowTop;

if(typeof window.screenX == "number" && typeof window.innerWidth == "number")
 {
 windowWidth = 1024;
 windowHeight = 768;
 windowLeft = 0;
 windowTop = 0;
 }
else if(typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number")
 {
 windowWidth = 1024;
 windowHeight = 768;
 windowLeft = 0;
 windowTop = 0;
 }
else
 {
var windowWidth = 1024;
var windowHeight = 768;
var windowLeft = 0;
var windowTop = 0;
 };

if (WindowObjectReferenceOfIntermediaryPopup == null || WindowObjectReferenceOfIntermediaryPopup.closed)
 {
 WindowObjectReferenceOfIntermediaryPopup = window.open(strUrl, strTarget, "top=" + windowTop + ",left=" + windowLeft + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar,toolbar,location,resizable,scrollbars,status");
 }
else
 {
 WindowObjectReferenceOfIntermediaryPopup.focus();
 };
/*
The above 9 line of code creates the popup, unless it is already opened (or minimized) in which case the popup window is brought in front of other windows. This feature is possible only if the user has the "Raise or lower windows" checkbox checked.
*/
}

function BringRequestedPopupOnTop()
{
if(WindowObjectReferenceOfRequestedPopup != null && !WindowObjectReferenceOfRequestedPopup.closed)
 {
 WindowObjectReferenceOfRequestedPopup.focus();
 };

/*
The above 4 lines of code verify if the popup exists and if the popup has not been closed: it that's the case, then the popup window is given focus and the popup window is brought on top of other windows.
*/
}

