dialogBoxSettings = {
    id: 'dialogBox',
    overlayContent: '<div id="dialogOverlay" class="ui-widget-overlay"><div class="ui-widget-loading"></div></div>',
    parentSelector: '.ui-dialog',
    removeOverlaySelector: '#dialogOverlay, #dialogOverlay .ui-widget-overlay'
};
dialogBoxSettings.overlayContainer = dialogBoxSettings.id;
dialogBoxSettings.selector = '#' + dialogBoxSettings.id;

function getDialogOverlayContainer() {
    return $dialogBox;
}
    
function getDialogOverlayContent() {
    return dialogBoxSettings.overlayContent;
}

function getDialogParentSelector() {
    return dialogBoxSettings.parentSelector;
}

function getRemoveDialogOverlaySelector() {
    return dialogBoxSettings.removeOverlaySelector;
}

function displayDialogOverlay() {
    getDialog().parents(getDialogParentSelector()).append(getDialogOverlayContent());
    return true;
}

function removeDialogOverlay() {
    $(getRemoveDialogOverlaySelector()).remove();
    return true;
}
function initDialog() {
    if (typeof $dialogBox == 'undefined') {
        $dialogBox = $('<div id="' + dialogBoxSettings.id + '" style="text-align\:left; display\:none;"></div>');
        $dialogBox.appendTo('body');
    }
    
    $dialogBox.dialog({
        title: 'Ecomaids',
        autoOpen: false,
        bgiframe: true,
        draggable: true,
        resizable: true,
        stack: false,
        modal: true,
        width: 500,
        height: 400,
        buttons: { 
            'Close': function() {
                $(this).dialog('close');
            }
        }
    });
    
    // $dialogBox.dialog({ title: 'Ecomaids', autoOpen: false, bgiframe: true, draggable: true, resizable: true, stack: false, modal: true, width: 500, height: 400, buttons: { 'Close': function() { $(this).dialog('close'); } } });
        
    return true;
}

function getDialog() {
    if (typeof $dialogBox == 'undefined') {
        initDialog();
    }
    
    return $dialogBox;
}

function displayDialog(msg, title) {
    getDialog().html(msg).dialog('open');
    return true;
}

function loadDialog(url, title, width, height) {
    var thisTitle = 'Ecomaids';
    var thisWidth = 'auto';
    var thisHeight = 'auto';
    
    if (typeof title != 'undefined') {
        thisTitle = title;
    }
    if (typeof width != 'undefined') {
        thisWidth = width;
    }
    if (typeof height != 'undefined') {
        thisHeight = height;
    }
    
    getDialog().dialog('option', 'width', thisWidth);
    getDialog().dialog('option', 'height', thisHeight);
    getDialog().dialog('option', 'title', thisTitle);
    
    $.get(url, {}, function(data) {
        getDialog().html(data).dialog('open');
    });
}
