// Array of opened windows
var _nyx_openedWindows = new Array();

// Opens a managed window centered on screen
function nyx_openScreenCenteredWindow(page, windowName, windowHeight, windowWidth, reOpen, additionalParams, verticalOffset)
{
  if (screen == null)
  {
    screenWidth   = 800;
    screenHeight  = 600;
  }
  else
  {
    screenWidth   = screen.width;
    screenHeight  = screen.height;
  }
  
  windowHeight == null ? windowHeight = parseInt((screenHeight / 100) * 80)  : windowHeight = parseInt(windowHeight);
  windowWidth == null ? windowWidth = parseInt((screenWidth / 100) * 80)  : windowWidth = parseInt(windowWidth);
  verticalOffset == null ? verticalOffset = parseInt((screenWidth / 100) * 6)  : verticalOffset = parseInt(verticalOffset);
  
  windowTop   = parseInt( ((screenHeight - windowHeight) / 2 ) - verticalOffset );
  windowLeft  = parseInt( (screenWidth - windowWidth) / 2 );
  
  position = "left=" + windowLeft + ", top=" + windowTop;
  
  if (additionalParams != null && additionalParams != "")
    additionalParams += ", " + position;
  else
    additionalParams = position;

  nyx_openWindow(page, windowName, windowHeight, windowWidth, reOpen, additionalParams)
}

// open a managed window (no duplication)
function nyx_openWindow(page, windowName, windowHeight, windowWidth, reOpen, additionalParams)
{
  // var                    defaults              supplied
  reOpen          == null ? reOpen = false      : reOpen = reOpen;

  dimensions = "width=" + windowWidth + ", height=" + windowHeight;
  
  if (additionalParams != null && additionalParams != "")
    additionalParams += ", " + dimensions;
  else
    additionalParams = dimensions;
    
  if ( windowName == null || windowName == '')
    window.open(page, '', additionalParams);
  else
  {
    if ( reOpen || _nyx_openedWindows[windowName] == null || _nyx_openedWindows[windowName].closed )
      _nyx_openedWindows[windowName] = window.open(page, windowName, additionalParams);

    _nyx_openedWindows[windowName].focus();
  }
}

function nyx_checkOpener(redirectPage)
{
  if (opener == null)
    window.location = redirectPage;
}
