/**
 * File contains JS Library for Popup window on <DIV> tag
 *
 * JavaScript  version 1
 * @category   JavaScript Libraries
 * @author     Alexey Frolov
 * @copyright  (c) 2004-2007 by ZFort Group
 * @version    SVN: $Id: 206$
 * @link       http://www.zfort.net
 * @since      File available since Release 1.0
 * <script type="text/javascript" src="/javascript/popup.js"></script>
 */

    /**
     * Usage in HTML
     *
     * <div id="pop_up"></div>
     * <script>
     *     popup = new ___Popup('pop_up', 416, 314);
     *    popup.show();
     * </script>
     */

    /**
     * constructor ___Popup
     *
     * @param string id DOM element `id`
     * @param int width
     * @param int height
     */
    function ___Popup(id, width, height){

        this.___popupId = id;
        this.___width   = width;
        this.___height  = height;
        this.___flag    = 1;
        this.___topPos  = null;

    }

       ___Popup.prototype.show = function() {
        var popup = document.getElementById(this.___popupId);
        var left;
        var top;

        if (typeof window.pageXOffset != 'undefined' && typeof window.innerWidth != 'undefined')
        {
            left = (window.innerWidth - this.___width) / 2 + window.pageXOffset;
            top  = (window.innerHeight - this.___height) / 2 + window.pageYOffset;
        }
        else
        {
            left = (document.body.clientWidth - this.___width) / 2 + document.body.scrollLeft;
            top  = (document.body.clientHeight - this.___height) / 2 + document.body.scrollTop;
        }

        // check if popup is bigger then client window
        if (top <= 0) top = 10;

        // set position
        popup.style.left = left.toString() + 'px';
        popup.style.top  = (this.___topPos != null) ? this.___topPos.toString() + 'px' : top.toString() + 'px';

        // show popup
        popup.style.display = 'block';
    }

    ___Popup.prototype.hide = function() {
        var popup = document.getElementById(this.___popupId);
        popup.style.display = 'none';
    }

    ___Popup.prototype.setTopPos = function(topPos) {
        this.___topPos = topPos;
    }
