var modalResult  = false;
var MODAL_CANCEL = 'Cancel';
var MODAL_OK     = 'Ok';
var systemConfirmMessageBox = false;

/**
 * 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.MessageBoxConfirm 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.MessageBoxConfirm = function(objName, message, callbackOkFunction, callbackCancelFunction, winHeaderId, winBodyId)
    {
        // --- Creating Protect Frame for IE --- //
        /**
         * Unique Control ID
         *
         * @var  string
         */
        this.id             = objName;
        document.getElementById(this.id + '_content').innerHTML = message;

        /**
         * Control HTML Element (Messagebox DIV)
         *
         * @var  DomElement
         */
        this.MessageBoxConfirmHTMLObject = document.getElementById(this.id);

        /**
         * Header of Control HTML Element (Messagebox Header DIV)
         *
         * @var  DomElement
         */
        this.MessageBoxConfirmHeaderHTMLObject = document.getElementById('winHeader_' + this.id);

        /**
         * Body of Control HTML Element (Messagebox Body DIV)
         *
         * @var  DomElement
         */
        this.MessageBoxConfirmBodyHTMLObject = document.getElementById('winBody_' + this.id);

        /**
         * Unique Protect Frame ID
         *
         * @var  string
         */
        this.protectFrameId = null;

        this.modalResult = false;
        this.callbackOkFunction = callbackOkFunction;
        this.callbackCancelFunction = callbackCancelFunction ? callbackCancelFunction : function (){};
    }

    PHP2Controls.MessageBoxConfirm.prototype.okClick = function()
    {
        this.modalResult = MODAL_OK;
        this.close();
        if (typeof(this.callbackOkFunction) == 'function') this.callbackOkFunction();
    }

    PHP2Controls.MessageBoxConfirm.prototype.okCancel = function()
    {
        this.modalResult = MODAL_CANCEL;
        this.close();
        if (typeof(this.callbackCancelFunction) == 'function') this.callbackCancelFunction();
    }

    /**
     * Closes MessageBox Window
     *
     * @param   string winObjectId MessageBox object ID
     * @param   string protectFrameId MessageBox Protectd IE Frame ID
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.close = function()
    {
        this.MessageBoxConfirmHTMLObject.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.MessageBoxConfirmHTMLObject, this.MessageBoxConfirmHeaderHTMLObject);

        document.getElementById("divMainSystem").style.display = 'none';
    }

    /**
     * Hides MessageBox Window Body
     *
     * @param   string winObjectId MessageBox object ID
     * @param   string protectFrameId MessageBox Protectd IE Frame ID
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.hide = function()
    {
        if (typeof(this.MessageBoxConfirmBodyHTMLObject) == undefined) return true;

        if (this.MessageBoxConfirmBodyHTMLObject.style.display == 'none')
        {
            this.MessageBoxConfirmBodyHTMLObject.style.display = '';
        }
        else
        {
            this.MessageBoxConfirmBodyHTMLObject.style.display = 'none';
        }

        // --- Reprotecting DIV --- //
        this.protectFrameId   = HTMLElement.protectIEDiv(this.id);
    }

    /**
     * Closes MessageBox Window
     *
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.initScreenPosition = function()
    {
        /*// --- Finding Message Box Screen Position --- //
        var leftPos  = HTMLElement.getBrowserWidth()  / 2; // - HTMLElement.getWidth(this.id)/2
        var topPos   = HTMLElement.getBrowserHeight() / 2; // - HTMLElement.getHeight(this.id)/2;

        var docBody = document.documentElement
                      ? document.documentElement
                      : document.body;

        // --- Setting Message Box Screen Position --- //
        this.MessageBoxConfirmHTMLObject.style.left  = ((leftPos > 0) ? leftPos : '') + docBody.scrollLeft + "px";
        this.MessageBoxConfirmHTMLObject.style.top   = ((topPos > 0) ? topPos : '') + docBody.scrollTop + "px";*/

        // --- Protecting IE --- //
        this.protectFrameId = HTMLElement.protectIEDiv(this.id);
    }

    /**
     * On MessageBox Moved Event Handler
     *
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.onMove = function()
    {
        // --- Protecting IE --- //
        this.protectFrameId = HTMLElement.protectIEDiv(this.id);
    }

    /**
     * Starts MessageBox Dragging
     *
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.initDragAndDrop = function()
    {
        // --- Assining onMove Event --- //
        this.MessageBoxConfirmHTMLObject.onMove = this.onMove;

        // --- Starting Drag Object --- //
        HTMLWindow.setDraggable(this.MessageBoxConfirmHTMLObject, this.MessageBoxConfirmHeaderHTMLObject);
    }

    /**
     * Show Modal Message box
     *
     * @return  void
     */
    PHP2Controls.MessageBoxConfirm.prototype.showModal = function()
    {
        var mainDiv = document.getElementById("divMainSystem");
        if (!mainDiv) return false;
        mainDiv.style.filter = "alpha(opacity=60)";
        mainDiv.style.opacity = 0.6;
        mainDiv.style.display = 'block';

        jQuery(this.MessageBoxConfirmHTMLObject).center();
        document.getElementById(this.id).style.display = 'block';
    }
