/*
* Copyright (c), Eric Wilde, 2005, 2006.
*
* Windows.js contains Javascript functions used for creating and manipulating
* popup windows.
*
* Two kinds of popups are supported, boxes and windows.  The distinction is
* that a box does not have scroll bars and can only show a fixed amount of text
* whereas a window has vertical scroll bars and can show a larger amount of
* text (e.g. help text).
*
* The advantage to using these routines is that the box/window that is popped
* up is centered in the current display.
*/

/*****************************************************************************/

function PopupBox(URL, Width, Height, Modal)
/*
* URL                                   The URL that is to be displayed in the
*                                       box that is created.
*
* Width                                 The width of the box to create.
*
* Height                                The height of the box to create.
*
* Modal                                 An optional parameter that indicates
*                                       whether the popup box is modal or not.
*                                       The default is not, if the parameter is
*                                       omitted.  Otherwise, the parameter
*                                       should be a boolean that is set true to
*                                       make the window modal.
*
* This routine will pop up a fixed size box, of the size defined, with the URL
* given loaded into it.
*/
{
var Day = new Date();
var ID = Day.getTime();

// Pop up the box.
eval("page" + ID + " = window.open(URL, '" + ID + "', " +
  "'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0," +
    "width=" + Width + ", height=" + Height + ", " +
    "left=" + GetPopupLeftInt(Width) + ", top=" + GetPopupTopInt(Height) +
    (((typeof(Modal) == 'boolean') && (Modal)) ? ", modal=1" : "") + "');");
}

/*****************************************************************************/

function PopupWindow(URL, Width, Height, Modal)
/*
* URL                                   The URL that is to be displayed in the
*                                       window that is created.
*
* Width                                 The width of the window to create.
*
* Height                                The height of the window to create.
*
* Modal                                 An optional parameter that indicates
*                                       whether the popup window is modal or
*                                       not.  The default is not, if the
*                                       parameter is omitted.  Otherwise, the
*                                       parameter should be a boolean that is
*                                       set true to make the window modal.
*
* This routine will pop up a window (with scroll bars), of the size defined,
* with the URL given loaded into it.
*/
{
var Day = new Date();
var ID = Day.getTime();

// Pop up the window.
eval("page" + ID + " = window.open(URL, '" + ID + "', " +
  "'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1," +
    "width=" + Width + ", height=" + Height + ", " +
    "left=" + GetPopupLeftInt(Width) + ", top=" + GetPopupTopInt(Height) +
    (((typeof(Modal) == 'boolean') && (Modal)) ? ", modal=1" : "") + "');");
}

/*****************************************************************************/

function GetPopupLeftInt(Width)
/*
* Internal function to get the left pixel offset of the window.
*/
{
var WinWidth;

// See if we can figure out the window's width.
if (window.innerWidth) WinWidth = window.innerWidth - 18;

else if (document.documentElement && document.documentElement.clientWidth) 
  WinWidth = document.documentElement.clientWidth;

else if (document.body && document.body.clientWidth)
  WinWidth = document.body.clientWidth;

else return (20);

// If the window is too narrow, the offset is zero.
if (WinWidth < Width) return (0);

// Return half the remaining width.
return ((WinWidth - Width) / 2);
}

/*****************************************************************************/

function GetPopupTopInt(Height)
/*
* Internal function to get the top pixel offset of the window.
*/
{
var WinHeight;

// See if we can figure out the window's height.
if (window.innerHeight) WinHeight = window.innerHeight - 18;

else if (document.documentElement && document.documentElement.clientHeight)
  WinHeight = document.documentElement.clientHeight;

else if (document.body && document.body.clientHeight)
  WinHeight = document.body.clientHeight;

else return (20);

// If the window is too short, the offset is zero.
if (WinHeight < Height) return (0);

// Return half the remaining height.
return ((WinHeight - Height) / 2);
}
