/**
 * @file
 * @author Shannon M. Rause <shannon.rause@creativeflavor.com>
 * @version $Revision: 1.23 $
 * @version $Name: HUTDOGS_2010-06-29_24 $
 * @version $Id: Popup.js,v 1.23 2008/09/25 18:18:48 smr Exp $
 *
 * These files are copyrighted to Creative Flavor Inc. and are
 * subject to the terms of the applicable Service Agreement.
 * If no service agreement is available you must contact us at
 * legal@creativeflavor.com or 303-379-9450.
 * 
 * These files may be watermarked to ensure traceability.
 */
/**
 * Popup class.
 */
function Popup()
{
} // Popup


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

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

Popup._windowCloseText = 'X';


/**
 * Hides a specific popup window.
 *
 * @param id   Id of popup to hide.
 */
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().
 */
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.
 */
Popup.show = function(id,
                      vpos,
                      hpos)
{
   var popup = document.getElementById(id);

   if ((popup) &&
       (popup.style.display != 'block'))
   {
      // reparent so z-index works correctly in IE.
      // note that doing this in FF will break the CMS editor.
      var info = Utils.getBrowserInfo();

      if (info['0'] == 'ie')
      {
         var elem = document.getElementById('popupParent');

         if (elem)
         {
            elem.appendChild(popup);
         } // if
      } // if

      // set visibility and then move to give element a size but not
      // show so we don't see a moving window.
      popup.style.visibility = 'hidden';
      popup.style.display = 'block';
      Utils.positionElem(popup,
                         vpos,
                         hpos);
      popup.style.visibility = '';
   } // if
} // show


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


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


/**
 * Convenience function to show an image.
 *
 * @param src     Image source file.
 * @param title   Optional title for window (default: Image).
 * @param width   Optional image width.
 * @param height  Optional image height.
 * @param alt     Optional alt text.
 * @param extra   Optional extra img tag info.
 * @param caption Optional caption that will go below image.
 * @param vpos    Optional vertical position (leave null normally).
 * @param hpos    Optional horizontal position (leave null normally).
 * @param timeout Number of seconds before popup automatically disappears.
 *
 * @return Status from overlib.
 */
Popup.showImage = function(src,
                           title,
                           width,
                           height,
                           alt,
                           extra,
                           caption,
                           vpos,
                           hpos,
                           timeout)
{
   if ((title == undefined) ||
       (title == null))
   {
      title = 'Image';
   } // if

   var html = '<div style="text-align:center;" onclick="Popup.hideSimple();">';
   html += '<img src="' + src + '"';
       
   if (width)
   {  
      html += ' width="' + width + '"';
   } // if
                         
   if (height)
   {  
      html += ' height="' + height + '"';
   } // if
                                           
   html += ' vspace="10" hspace="10" alt="' + alt + '" ' + extra + ' />';

   if ((caption != undefined) &&
       (caption != null))
   {
      html += '<div>' + caption + '</div>';
   } // if

   html += '</div>';

   return (Popup.showSimple(html, title, vpos, hpos, width, height, timeout));
} // showImage


/**
 * 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().
 */
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._tooltipClasses.bg,
                   FGCLASS, Popup._tooltipClasses.fg,
                   CAPTIONFONTCLASS, Popup._tooltipClasses.caption_font,
                   CLOSEFONTCLASS, Popup._tooltipClasses.close_font,
                   TEXTFONTCLASS, Popup._tooltipClasses.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 timeout Number of seconds before popup automatically disappears.
 *
 * @return Status from overlib.
 */
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) &&
       (vpos != ''))
   {
      if (isNaN(vpos))
      {
         if (typeof(vpos) == 'string')
         {
            switch (vpos)
            {
               case Utils.V_POSITION_ABOVE_MOUSE:
                  v = ABOVE;
                  break;

               case Utils.V_POSITION_BELOW_MOUSE:
                  v = BELOW;
                  break;

               case Utils.V_POSITION_CENTER:
                  v = RELY;
                  vdata = (Utils.getWindowHeight() - height) / 2;
                  break;

               case Utils.V_POSITION_CENTER_MOUSE:
                  v = OFFSETY;
                  vdata = -1 * (height / 2);
                  break;

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

                     if (!isNaN(temp))
                     {
                        v = RELY;
                        vdata = parseInt(temp);
                     } // if
                  } // 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) &&
       (hpos != ''))
   {
      if (isNaN(hpos))
      {
         if (typeof(hpos) == 'string')
         {
            switch (hpos)
            {
               case Utils.H_POSITION_CENTER: 
                  h = RELX;
                  hdata = (Utils.getWindowWidth() - width) / 2;

                  if (hdata < 0)
                  {
                     hdata = 0;
                  } // if
                  break;

               case Utils.H_POSITION_CENTER_MOUSE: 
                  h = CENTER;
                  break;

               case Utils.H_POSITION_LEFT_MOUSE:
                  h = LEFT;
                  break;

               case Utils.H_POSITION_RIGHT_MOUSE:
                  h = RIGHT;
                  break;

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

                  if ((hpos.substr(hpos.length - 2) == 'ab') &&
                      (!isNaN(temp)))
                  {
                     h = RELX;
                     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,
                   OFFSETX, 0,
                   OFFSETY, 0,
                   v, vdata,
                   h, hdata,
                   tout, tout_data,
                   STICKY,
                   CLOSECLICK,
                   CLOSETEXT, Popup._windowCloseText,
                   CSSCLASS,
                   BGCLASS, Popup._windowClasses.bg,
                   FGCLASS, Popup._windowClasses.fg,
                   CAPTIONFONTCLASS, Popup._windowClasses.caption_font,
                   CLOSEFONTCLASS, Popup._windowClasses.close_font,
                   TEXTFONTCLASS, Popup._windowClasses.text));
} // showSimple


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

Popup._init();

