﻿var g_loadingScreen = null;

function isValue(obj) {
    return !(obj == null || typeof(obj) == 'undefined');
}

function isNullOrEmpty(obj) {
    if (!isValue(obj))
        return true;
    return obj == '';
}

function fn_showLoadingScreen(title, message) {
    if (isValue(g_loadingScreen)) {
        g_loadingScreen.setTitle(title);
        g_loadingScreen.setContent("<span>" + message + "</span>");
        return;
    }
    g_loadingScreen = new Boxy("<span>" + message + "</span>",
                   { draggable: true,
                       modal: true,
                       closeable: false,
                       title: title,
                       show: true,
                       unloadOnHide: true
                   }
                );
}

function fn_hideLoadingScreen(timeout) {
    if (isValue(g_loadingScreen)) {
        if (isValue(timeout))
            setTimeout(function() { if (isValue(g_loadingScreen)) g_loadingScreen.hideAndUnload(); g_loadingScreen = null; }, parseInt(timeout, 10));
        else {
            g_loadingScreen.hideAndUnload();
            g_loadingScreen = null;
        } 
    }
}


function fn_showBigImage(image, title) {
    new Boxy("<div style=\"width:800px;height:400px;text-align:center;vertical-align:middle;\"><img style=\"max-height:400px;max-width:800px;\" src=\"" + image + "\" /></div>",
                   { draggable: true,
                       modal: true,
                       closeable: true,
                       title: "" + title,
                       show: true,
                       unloadOnHide: true
                   }
                );
}


var g_dialogs = {};
var g_dialogsContent = {};
function fn_showDialog(dialogId, title) {
    if (!isValue(g_dialogsContent[dialogId])) {
        g_dialogsContent[dialogId] = "<span>" + $("#" + dialogId).html() + "</span>";
        $("#" + dialogId).html("");
    }
    if (isValue(g_dialogs[dialogId])) {
        g_dialogs[dialogId].setTitle(title);
        g_dialogs[dialogId].setContent(g_dialogsContent[dialogId]);
        return;
    }
    g_dialogs[dialogId] = new Boxy(g_dialogsContent[dialogId],
                   { draggable: true,
                       modal: true,
                       closeable: false,
                       title: title,
                       show: true,
                       unloadOnHide: true
                   }
                );
}
function fn_hideDialog(dialogId, timeout) {
    if (isValue(g_dialogs[dialogId])) {
        if (isValue(timeout))
            setTimeout(function() { if (isValue(g_dialogs[dialogId])) g_dialogs[dialogId].hideAndUnload(); g_dialogs[dialogId] = null; }, parseInt(timeout, 10));
        else {
            g_dialogs[dialogId].hideAndUnload();
            g_dialogs[dialogId] = null;
        }
    }
}

