/**
 * @file
 * Popup utilities.
 *
 * @author Shannon M. Rause <shannon.rause@creativeflavor.com>
 * @version $Revision: 1.8 $
 * @version $Name:  $
 * @version $Id: Popup.js,v 1.8 2006/09/20 03:23:39 smr Exp $
 *
 * Copyright 2005-2006 Creative Flavor, Inc. All rights reserved.
 * 
 * Please see the LICENSE file for specific licensing information.
 * If you did not receive this file or are unable to locate it, 
 * please contact licensing@creativeflavor.com.
 */
/**
 * Popup class.
 *
 * @public
 */
function Popup()
{
} // Popup


Popup._tooltip_classes = {
   'bg'           : 'popupTooltipBg',
   'caption_font' : 'popupTooltipCaption',
   'fg'           : 'popupTooltipFg',
   'text_font'    : 'popupTooltipText'
};

Popup._window_classes = {
   'bg'           : 'popupSimpleBg',
   'caption_font' : 'popupSimpleCaption',
   'close_font'   : 'popupSimpleClose',
   'fg'           : 'popupSimpleFg',
   'text_font'    : 'popupSimpleText'
};

Popup._window_close_text = 'X';


/**
 * Hides a specific popup window.
 *
 * @param id   Id of popup to hide.
 *
 * @public
 */
Popup.hide = function(id)
{
   var popup = document.getElementById(id);

   if (popup)
   {
      popup.style.display = 'none';
   } // if
} // hide


/**
 * Hides all simple popups/tooltips.
 * Note that nd() is called 2x because it doesn't always seem to take.
 *
 * @param delay   Number of milliseconds to wait before doing hide.
 *
 * @return Status from overlib's nd().
 *
 * @public
 */
Popup.hideSimple = function(delay)
{
   nd(delay);

   return (nd(delay));
} // hideSimple


/**
 * Shows an existing popup window.
 *
 * @param id   Id of popup to show.
 * @param vpos Vertical position.
 * @param hpos Horizontal position.
 *
 * @public
 */
Popup.show = function(id,
                      vpos,
                      hpos)
{
   var popup = document.getElementById(id);

   if ((popup) &&
       (popup.style.display != 'block'))
   {
      popup.style.display = 'block';
      Utils.positionElem(popup,
                         vpos,
                         hpos);
   } // if
} // show


/**
 * Shows an alert.
 *
 * @param text Text to display.
 *
 * @public
 */
Popup.showAlert = function(text)
{
   alert(text);
} // showAlert


/**
 * Shows a confirmation dialog.
 *
 * @param text Text to display.
 *
 * @return Status from confirm().
 *
 * @public
 */
Popup.showConfirm = function(text)
{
   return (confirm(text));
} // showConfirm


/**
 * Convenience function to show a tooltip popup.
 *
 * @param text    Text to display in window.
 * @param width   Optional width.
 * @param height  Optional height.
 * @param delay   Optional delay in milliseconds to wait before showing (default 800).
 * @param caption Optional caption for window.
 *
 * @return Status from overlib().
 *
 * @public
 */
Popup.showTooltip = function(text,
                             width,
                             height,
                             delay,
                             caption)
{
   if ((width == undefined) || (width == null) || (width <= 0))
   {
      width = 200;
   } // if

   if ((height == undefined) || (height == null) || (height < 0))
   {
      height = -1;
   } // if

   if ((delay == undefined) || (delay != null))
   {
      delay = 800;
   } // if

   if ((caption != undefined) && (caption != null))
   {
      var cap = CAPTION;
      var cap_data = caption;
   } // if
   else
   {
      var cap = DONOTHING;
      var cap_data = DONOTHING;
   } // else

   return (overlib(text,
                   WIDTH, width,
                   HEIGHT, height,
                   DELAY, delay,
                   cap, cap_data,
                   MOUSEOFF,
                   CSSCLASS,
                   BGCLASS, Popup._tooltip_classes.bg,
                   FGCLASS, Popup._tooltip_classes.fg,
                   CAPTIONFONTCLASS, Popup._tooltip_classes.caption_font,
                   CLOSEFONTCLASS, Popup._tooltip_classes.close_font,
                   TEXTFONTCLASS, Popup._tooltip_classes.text));
} // showToolTip


/**
 * Shows a simple popup window.
 *
 * @param html          HTML to display.  Note that all HTML entities as well as ', ;, (, and )
 *                         all need to be escaped properly.
 * @param title         Optional title for window.
 * @param vpos          Optional vertical position (leave null normally).
 * @param hpos          Optional horizontal position (leave null normally).
 * @param width         Optional width.
 * @param height        Optional height.
 * @param delay         Optional delay in milliseconds to wait before showing (default 800).
 * @param timeout       Number of seconds before popup automatically disappears.
 *
 * @return Status from overlib.
 *
 * @public
 */
Popup.showSimple = function(html,
                            title,
                            vpos,
                            hpos,
                            width,
                            height,
                            timeout)
{
   if ((title == undefined) || (title == null))
   {
      var cap = DONOTHING;
      var cap_data = DONOTHING;
   } // if
   else
   {
      var cap = CAPTION;
      var cap_data = title;
   } // else

   if ((width == undefined) || (width == null) || (width <= 0))
   {
      width = 200;
   } // if

   if ((height == undefined) || (height == null) || (height < 0))
   {
      height = -1;
   } // if

   var v = VAUTO;
   var vdata = DONOTHING;

   if ((vpos != null) &&
       (vpos != undefined))
   {
      if (isNaN(vpos))
      {
         if (typeof(vpos) == 'string')
         {
            switch (vpos)
            {
               case Utils.V_POSITION_ABOVE:
                  v = ABOVE;
                  break;

               case Utils.V_POSITION_BELOW:
                  v = BELOW;
                  break;

               default: 
                  var temp = vpos.substr(0,
                                         vpos.length - 2);

                  if ((vpos.substr(vpos.length - 2) == 'ab') &&
                       (!isNaN(temp)))
                  {
                     v = FIXY;
                     vdata = parseInt(temp);
                  } // if
                  break;
            } // switch
         } // if
      } // else if
      else
      {
         v = OFFSETY;
         vdata = parseInt(vpos);
      } // else
   } // if


   var h = HAUTO;
   var hdata = DONOTHING;

   if ((hpos != null) &&
       (hpos != undefined))
   {
      if (isNaN(hpos))
      {
         if (typeof(hpos) == 'string')
         {
            switch (hpos)
            {
               case Utils.H_POSITION_CENTER: 
                  h = CENTER;
                  break;

               case Utils.H_POSITION_LEFT:
                  h = LEFT;
                  break;

               case Utils.H_POSITION_RIGHT:
                  h = RIGHT;
                  break;

               default: 
                  var temp = hpos.substr(0,
                                         hpos.length - 2);

                  if ((hpos.substr(hpos.length - 2) == 'ab') &&
                      (!isNaN(temp)))
                  {
                     h = FIXX;
                     hdata = parseInt(temp);
                  } // if
                  break;
            } // switch
         } // if
      } // else if
      else
      {
         h = OFFSETX;
         hdata = parseInt(hpos);
      } // else
   } // else

   if ((timeout != undefined) &&
       (timeout != null))
   {
      var tout = TIMEOUT;
      var tout_data = timeout;
   } // if
   else
   {
      var tout = DONOTHING;
      var tout_data = DONOTHING;
   } // else

   return (overlib(html,
                   cap, cap_data,
                   WIDTH, width,
                   HEIGHT, height,
                   v,
                   vdata,
                   h,
                   hdata,
                   tout, tout_data,
                   STICKY,
                   CLOSECLICK,
                   CLOSETEXT, Popup._window_close_text,
                   CSSCLASS,
                   BGCLASS, Popup._window_classes.bg,
                   FGCLASS, Popup._window_classes.fg,
                   CAPTIONFONTCLASS, Popup._window_classes.caption_font,
                   CLOSEFONTCLASS, Popup._window_classes.close_font,
                   TEXTFONTCLASS, Popup._window_classes.text));
} // showSimple


/**
 * Initializes popup inteface.
 *
 * @private
 */
Popup._init = function()
{
   document.write('<script type="text/javascript" src="/scripts/libjs/3rdParty/overlib/Mini/overlib_mini.js"></script>');
} // _init

Popup._init();
