﻿IModelPopup = new Class.create();
IModelPopup.prototype = {
    initialize: function (target, closewindow) {

        if (target.empty()) {
            alert('Popup target control id is null');
        }
        var instance = this;
        this.target = $(target);
        this.target.setStyle({ position: 'absolute', zIndex: 101 });
        this.setMargin();
        this.overlay();
        $(closewindow).onclick = function () {
            instance.hide();
        }
    },
    setMargin: function () {
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            this.windowWidth = window.innerWidth;
            this.windowHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            this.windowWidth = document.documentElement.clientWidth;
            this.windowHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            this.windowWidth = document.body.clientWidth;
            this.windowHeight = document.body.clientHeight;
        }
        var pW = this.target.getWidth();
        var pH = this.target.getHeight();

        var left = (this.windowWidth - pW) / 2;
        var top = (this.windowHeight - pH) / 2;

        this.target.setStyle({ left: '3px', top: top + 'px' });
    },
    overlay: function () {
        var ovr = document.createElement('div');
        ovr.setAttribute('id', 'Ipopup_overlay');
        this.target.up(0).appendChild(ovr);
        ovr = $('Ipopup_overlay');
        ovr.setStyle({
            left: '0px',
            top: '0px',
            zIndex: 100,
            width: this.windowWidth + 'px',
            height: this.windowHeight + 'px',
            position: 'fixed',
            visibility: 'hidden'
        });
    },
    show: function () {
        var top = window.document.documentElement.scrollTop || window.document.body.scrollTop;
        this.target.setStyle({ visibility: 'visible', top: top + 'px' });
        $('Ipopup_overlay').setStyle({ visibility: 'visible' });
    },
    hide: function () {
        this.target.setStyle({ visibility: 'hidden' });
        $('Ipopup_overlay').setStyle({ visibility: 'hidden' });
    }
}
