DG_Dialogs = {
    
    close: function (obj) {
        if (typeof(obj) == 'object') {
            obj.dialog('close');
        } else {
            $("#dg_dialog_confirm").dialog('close');
            $("#dg_dialog_alert").dialog('close');
            $("#dg_dialog_video").dialog('close');
        }
    },
	
    destroy: function (obj) {
        if (typeof(obj) == 'object') {
            obj.dialog('destroy');
        } else {
            $("#dg_dialog_confirm").dialog('destroy');
            $("#dg_dialog_alert").dialog('destroy');
            $("#dg_dialog_video").dialog('destroy');
        }
    },
    
    confirm: function(title, htmlorobject, okCallback, cancelCallback, options) {
        DG_Dialogs.destroy();
        var html, obj;
        if (typeof(htmlorobject) == 'object') {
            obj = htmlorobject;
        } else {
            html = htmlorobject;
            obj = $("#dg_dialog_alert");
        }
        
        var confirmtext = 'Ja';
        var canceltext 	= 'Nej';
        var height = "auto";
        var width = 300;
        if (options) {
            if (options.confirmtext) { confirmtext = options.confirmtext; };
            if (options.canceltext) { canceltext = options.canceltext; };
            if (options.height) { height = options.height; };
            if (options.width) { width = options.width; };
        }
        
        var objButtons = new Object;
        objButtons[confirmtext] = function() {
                                        var doClose = true;
                                        if (typeof(okCallback) == 'function') {
                                            doClose = okCallback();
											if (doClose !== false) doClose = true;
                                        }
                                        if (doClose) $(this).dialog('close');
                                    };
                                    
        objButtons[canceltext] = function() {
                                        var doClose = true;
                                        if (typeof(cancelCallback) == 'function') {
                                            doClose = cancelCallback();
											if (doClose !== false) doClose = true;
                                        }
                                        if (doClose) {
                                            $(this).dialog('close');
                                            if (html) obj.html('');
                                            $(this).dialog('destroy');
                                        }
                                    };
        
		
        var position = 'center';
		if (window.parent.frames.length) {
			var x = ($(window).width() - width) / 2
			position = [x,100];
		}
		
        obj.dialog({
                bgiframe: true,
                resizable: false,
                height: height,
                width: width,
                modal: true,
                title: title,
                closeText: 'x',
                buttons: objButtons,
                position: position
            }).dialog('open');
        if (html) obj.html(html);
        
    },
    alert: function(title, htmlorobject, okCallback, options) {
        DG_Dialogs.destroy();
        var html, obj;
        if (typeof(htmlorobject) == 'object') {
            obj = htmlorobject;
        } else {
            html = htmlorobject;
            obj = $("#dg_dialog_alert");
        }
        
        var confirmtext = 'OK';
        var height = "auto";
        var width = 300;
        var dialogClass = "";
        if (options) {
            if (options.confirmtext) { confirmtext = options.confirmtext; };
            if (options.height) { height = options.height; };
            if (options.width) { width = options.width; };
            if (options.dialogClass) { dialogClass = options.dialogClass; };
        }
        
        var objButtons = new Object;
        objButtons[confirmtext] = function() {
                                        if (typeof(okCallback) == 'function') {
                                            okCallback();
                                        }
                                        $(this).dialog('close');
                                        if (html) obj.html('');
                                        $(this).dialog('destroy');
                                    }
									
        var position = 'center';
		if (window.parent.frames.length) {
			var x = ($(window).width() - width) / 2
			position = [x,100];
		}
		
        obj.dialog({
                bgiframe: true,
                resizable: false,
                height: height,
                width: width,
                modal: true,
                title: title,
                closeText: 'x',
                buttons: objButtons,
                position: position
            }).dialog('open');
        if (html) obj.html(html);
    }
};

