
/**
 * File contains JS Library for MessageBox Control
 *
 * JavaScript  version 1
 * @category   JavaScript Libraries
 * @author     Eugene A. Kalosha <aristarch@zfort.net>
 * @copyright  (c) 2004-2006 by ZFort Group
 * @version    SVN: $Id: 206$
 * @link       http://www.zfort.net
 * @since      File available since Release 2.3.0
 */

if (typeof(PHP2Controls) == 'undefined') PHP2Controls = new Object();

    /**
     * PHP2Controls.MessageBox is the namespace and JS Class for HTMLMessageBox.
     *
     * @author   Eugene A. Kalosha <aristarch@zfort.net>
     * @version  $Id: messagebox.common.js, v 2.3.0 2006/09/14 $
     * @access   public
     * @package  php2
     */
    PHP2Controls.MessageBox = function(objectName, winHeaderId, winBodyId)
    {
        // --- Creating Protect Frame for IE --- //
        /**
         * Unique Control ID
         *
         * @var  string
         */
        this.id             = objectName;
        
        /**
         * Control HTML Element (Messagebox DIV)
         *
         * @var  DomElement
         */
        this.messageBoxHTMLObject = document.getElementById(this.id);
        
        /**
         * Header of Control HTML Element (Messagebox Header DIV)
         *
         * @var  DomElement
         */
        this.messageBoxHeaderHTMLObject = document.getElementById('winHeader_' + this.id);
        
        /**
         * Body of Control HTML Element (Messagebox Body DIV)
         *
         * @var  DomElement
         */
        this.messageBoxBodyHTMLObject = document.getElementById('winBody_' + this.id);
        
        /**
         * Unique Protect Frame ID
         *
         * @var  string
         */
        this.protectFrameId = null;
        
    }
    
    /**
     * Closes MessageBox Window
     *
     * @param   string winObjectId MessageBox object ID
     * @param   string protectFrameId MessageBox Protectd IE Frame ID
     * @return  void
     */
    PHP2Controls.MessageBox.prototype.close = function()
    {
        this.messageBoxHTMLObject.style.display = 'none';
        if (this.protectFrameId && (document.all.item(this.protectFrameId) != null))
        {
            var frmHover            = document.all.item(this.protectFrameId);
            frmHover.style.zIndex   = -1;
            frmHover.style.left     = "1px";
            frmHover.style.top      = "1px";
            frmHover.style.width    = 1;
            frmHover.style.height   = 1;
            frmHover.style.display  = 'none';
        }
        
        // --- Unset Drag And Drop --- //
        HTMLWindow.unsetDraggable(this.messageBoxHTMLObject, this.messageBoxHeaderHTMLObject);
    }
    
    /**
     * Hides MessageBox Window Body
     *
     * @param   string winObjectId MessageBox object ID
     * @param   string protectFrameId MessageBox Protectd IE Frame ID
     * @return  void
     */
    PHP2Controls.MessageBox.prototype.hide = function()
    {
        if (typeof(this.messageBoxBodyHTMLObject) == undefined) return true;
        
        if (this.messageBoxBodyHTMLObject.style.display == 'none')
        {
            this.messageBoxBodyHTMLObject.style.display = '';
        }
        else
        {
            this.messageBoxBodyHTMLObject.style.display = 'none';
        }
        
        // --- Reprotecting DIV --- //
        this.protectFrameId   = HTMLElement.protectIEDiv(this.id);
    }
    
    /**
     * Closes MessageBox Window
     *
     * @return  void
     */
    PHP2Controls.MessageBox.prototype.initScreenPosition = function()
    {
        // --- Finding Message Box Screen Position --- //
        var leftPos  = (HTMLElement.getBrowserWidth() - HTMLElement.getWidth(this.id)) / 2;
        var topPos   = (HTMLElement.getBrowserHeight() / 2) - 200;
        
        // --- Setting Message Box Screen Position --- //
        this.messageBoxHTMLObject.style.left  = ((leftPos > 0) ? leftPos : '') + "px";
        this.messageBoxHTMLObject.style.top   = ((topPos > 0) ? topPos : '') + "px";
        
        // --- Protecting IE --- //
        this.protectFrameId = HTMLElement.protectIEDiv(this.id);
    }
    
    /**
     * On MessageBox Moved Event Handler
     *
     * @return  void
     */
    PHP2Controls.MessageBox.prototype.onMove = function()
    {
        // --- Protecting IE --- //
        this.protectFrameId = HTMLElement.protectIEDiv(this.id);
    }
    
    /**
     * Starts MessageBox Dragging
     *
     * @return  void
     */
    PHP2Controls.MessageBox.prototype.initDragAndDrop = function()
    {
        // --- Assining onMove Event --- //
        this.messageBoxHTMLObject.onMove = this.onMove;
        
        // --- Starting Drag Object --- //
        HTMLWindow.setDraggable(this.messageBoxHTMLObject, this.messageBoxHeaderHTMLObject);
    }
    
