﻿var ExtConfirm = {

    ShowDialog: function(title, string, callback, cancelcallback, preload) {
        document.body.scroll = 'no';
        document.body.style.overflow = 'hidden';
        this.callback = callback;
        this.cancelcallback = cancelcallback;
        this.preload = preload;
        this.returnvalue = false;
        return this._ShowDialog(title, string, callback);

    },

    HideDialog: function(toreturn) {
        return this._HideDialog(toreturn);
    },

    _ShowDialog: function(title, string) {

        var _height = 0;
        var _width = 0;
        var divWidth = 0;
        var divHeight = 0;

        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            _width = window.innerWidth;
            _height = window.innerHeight;
            divWidth = 300;
            divHeight = 150;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            _width = document.documentElement.clientWidth;
            _height = document.documentElement.clientHeight;
            divWidth = 300;
            divHeight = 165;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            _width = document.body.clientWidth;
            _height = document.body.clientHeight;
            divWidth = 300;
            divHeight = 165;
        }

        var div = document.createElement('div');
        div.id = 'ConfirmMainDiv';
        div.className = 'transparent';
        div.style.width = _width + "px";
        //div.style.height = _height + "px";
        div.style.position = 'absolute';
        div.style.left = document.documentElement.scrollLeft + 'px';

        var ScrollTop = document.body.scrollTop;
        if (ScrollTop == 0) {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }

        div.style.top = ScrollTop + 'px';
        div.style.zIndex = 9999;

        var div1 = document.createElement('div');
        div1.id = 'ConfirmSubDiv';
        div1.style.border = 'solid 1px Maroon';
        div1.style.position = 'absolute';
        div1.style.width = divWidth + "px";
        //div1.style.height = divHeight + "px";
        div1.style.left = (((_width - (_width / 4)) / 2) + document.documentElement.scrollLeft) + 'px';
        div1.style.top = (((_height - (_height / 4)) / 2) + ScrollTop) + 'px';
        div1.style.backgroundColor = '#ffffe0';
        div1.style.zIndex = 9999 + 1;



        var TableText = '<table cellpadding="0" cellspacing="0"  width="100%">';
        TableText += '<tr><td>';
        TableText += '<table cellpadding="2" cellspacing="2" style="height:100%" width="100%">';
        TableText += '<tr><td colspan="2" id="tdDrag" style="cursor:move;background-color:#f4a62b;color:white;font-weight:bold;">' + title + '</td></tr>';
        TableText += '<tr><td colspan="2" style="height:5px;"></td>';
        TableText += '<tr><td width="30px" align="center" valign="top"><img src="images/questionmark.gif"/></td><td align="left" valign="top" style="color:red;background-color:#ffffe0;">' + string + '</td></tr>';
        TableText += '</td><tr>';
        TableText += '<tr><td colspan="2" align="right" style=padding-bottom:5px>';
        TableText += '<a class="linkStyle" href="javascript:ExtConfirm.HideDialog(1);">Yes</a>&nbsp&nbsp&nbsp&nbsp;';
        TableText += '<a class="linkStyle" href="javascript:ExtConfirm.HideDialog(0);">No</a><br>';
        TableText += '</td></tr>';
        TableText += '</table>';

        div1.innerHTML = TableText;


        document.body.appendChild(div);
        document.body.appendChild(div1);
        Drag.init(document.getElementById("tdDrag"), document.getElementById("ConfirmSubDiv"));
    },


    _HideDialog: function(toreturn) {
        this.toreturn = toreturn;
        $('#ConfirmSubDiv').fadeOut("slow", function() {
            document.body.removeChild(document.getElementById('ConfirmMainDiv'));
            document.body.removeChild(document.getElementById('ConfirmSubDiv'));
            document.body.scroll = 'yes';
            document.body.style.overflow = 'auto';
            if (ExtConfirm.toreturn == 1) {
                if (ExtConfirm.callback != undefined)
                    ExtConfirm.callback();
            }
            else {
                if (ExtConfirm.cancelcallback != undefined)
                    ExtConfirm.cancelcallback();
            }
        }
	        );

    }

}
