var Extensions = function(){
    return {
        defaultDialogWidth : 350,
        anim: 0,

        alert : function(alertOptions) {
            
            var title       = (alertOptions.Title) ? alertOptions.Title : 'Figyelmeztetés';
            var html        = (alertOptions.Body) ? alertOptions.Body : '&nbsp;';
            var dialogWidth = (alertOptions.Width) ? (alertOptions.Width) : Extensions.defaultDialogWidth;
            var nonClosable = (alertOptions.nonClosable) ? 'none' : 'block';

            PopupHandler.disableEscapeKey( (alertOptions.disableEscapeKey) ? true : false );

            $('dialog-close-button').setStyle({
              display: nonClosable
            });

            if (alertOptions.Func)
            {
                Extensions.nextFunc = alertOptions.Func;
            }

            $('dialog-top-center').innerHTML = title;
            var alertBody = '<div class="alert-body">'+html+'</div>' +
                '<div class="alert-buttons"><input type="button" value="Rendben" id="dialog-ok-button" onclick="Extensions.alertClose();" class="button-submit" /></div>';

            PopupHandler.showDialogBox(alertBody, dialogWidth);
        },

        alertClose : function() {

            PopupHandler.deactivate();

            if (Extensions.nextFunc != null)
            {
                Extensions.nextFunc.apply();
            }
        },

        dialog :function(alertOptions) {

            var title           = (alertOptions.Title) ? alertOptions.Title : 'Figyelmeztetés';
            var html            = (alertOptions.Body) ? alertOptions.Body : '&nbsp;';
            var buttons         = (alertOptions.Buttons) ? alertOptions.Buttons : {yes : '  Igen  ', no : '  Nem  '};
            var dialogWidth     = (alertOptions.Width) ? (alertOptions.Width) : Extensions.defaultDialogWidth;
            var nonClosable     = (alertOptions.nonClosable) ? 'none' : 'block';

            Extensions.nextFunc = (alertOptions.Func) ? alertOptions.Func : null;

            PopupHandler.disableEscapeKey( (alertOptions.disableEscapeKey) ? true : false );

            $('dialog-close-button').setStyle({
                display: nonClosable
            });

            var buttonLine = '';
            var keys = Object.keys(buttons);
            var vals = Object.values(buttons);
        
            for (var i=0;i<keys.length;i++)
            {
                buttonLine += '<input type="button" value="'+vals[i]+'" onclick="Extensions.dialogClose(\''+keys[i]+'\');" class="button-submit" />';
            }

            $('dialog-top-center').innerHTML = title;
            var dialogBody = '<div class="alert-body">'+html+'</div>' +
                '<div class="alert-buttons">'+buttonLine+'</div>';

            PopupHandler.showDialogBox(dialogBody, dialogWidth);
        },

        dialogClose : function(answer) {

            PopupHandler.deactivate();

            if (Extensions.nextFunc != null)
            {
                Extensions.nextFunc.apply(Extensions.nextFunc, [answer]);
            }
        },

        popup : function (popupOptions){

            var title        = (popupOptions.Title) ? popupOptions.Title : '&nbsp;';
            var html         = (popupOptions.Body) ? popupOptions.Body : '&nbsp;';
            var dialogWidth  = (popupOptions.Width) ? popupOptions.Width : Extensions.defaultDialogWidth;
            var nonClosable  = (popupOptions.nonClosable) ? 'none' : 'block';

            PopupHandler.disableEscapeKey( (popupOptions.disableEscapeKey) ? true : false );

            $('dialog-close-button').setStyle({
              display: nonClosable
            });

            $('dialog-top-center').innerHTML = title;

            PopupHandler.showDialogBox(html, dialogWidth);
        },

        popupClose : function () {
            PopupHandler.deactivate();
        },

        getPageSize : function(){
                
            var xScroll, yScroll;
            
            if (window.innerHeight && window.scrollMaxY) {    
                xScroll = window.innerWidth + window.scrollMaxX;
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            
            var windowWidth, windowHeight;

            if (self.innerHeight) {    // all except Explorer
                if(document.documentElement.clientWidth){
                    windowWidth = document.documentElement.clientWidth; 
                } else {
                    windowWidth = self.innerWidth;
                }
                windowHeight = self.innerHeight;

            } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }    
            
            // for small pages with total height less then height of the viewport
            if(yScroll < windowHeight){
                pageHeight = windowHeight;
            } else { 
                pageHeight = yScroll;
            }

            // for small pages with total width less then width of the viewport
            if(xScroll < windowWidth){    
                pageWidth = xScroll;        
            } else {
                pageWidth = windowWidth;
            }

            return {
                'windowHeight' : windowHeight,
                'pageWidth'    : pageWidth,
                'pageHeight'   : pageHeight,
                'windowWidth'  : windowWidth
            };
        }

    };
}();