/**
 *  popup.js: Javascript code for popup window demo for the MapViewer project
 *
 *  Depends: none
 */

// Global array containing open window handles
var gWindowHandles = new Array();

/**
 *  Closes all open popup windows based on the contents of the global window
 *  handles array
 */
function closePopupWindows()
{
   // Close all of the open popup windows
   for (index in gWindowHandles)
   {
      var popupWindow = gWindowHandles[index];
      try
      {
         popupWindow.close();
      }
      catch (err)
      {
         // Had a problem closing the window, just move to the next one
      }
   }

   // Reset the global window handles array
   gWindowHandles = new Array();
}

/**
 * Called from flash when a new map is selected from the drop-down.
 */
function OnMapViewerMapChanged()
{
   // closePopupWindows();
}

/**
 *  Opens a new popup window with the specified url and name.  This is
 *  essentially a wrapper call to window.open, but it also adds the handle
 *  for the newly created window to the global array of window handles so that
 *  it can be closed later.
 */
function openPopupWindow(url, name)
{
   // If window already open, don't need to do anything
   if (!window.focus)
   {
      return;
   }

   // Set window characteristics
   var characteristics = 'width=850,height=650,scrollbars=yes,resizable=yes';

   // Set window href
   var href;
   if (typeof(url) == 'string')
   {
      href = url;
   }
   else
   {
      href = url.href;
   }

   // Open the popup window and set the focus on it
   var popupHandle = window.open(href, name, characteristics);
   popupHandle.focus();

   // Store the window handle in the handles array
   gWindowHandles[gWindowHandles.length] = popupHandle;
}

