var ERROR_LEVEL = 1;
var INFO_LEVEL = 2;
var WARNING_LEVEL = 3;
var SUCCESS_LEVEL = 4;
var DELAY_DEFAULT = 3000;
var user_delay = DELAY_DEFAULT;
var user_class = "width: 50%; display: block; margin: 0px auto; position: fixed; top: 50%; left: 25%";
var CONTEUDO_ERROR = "<div class='alert alert-block alert-error' style='" + user_class + "'><button type='button' class='close' data-dismiss='alert' onclick='CloseMessage()'>×</button><strong>Erro!</strong> {MENSAGEM}</div>";
var CONTEUDO_SUCCESS = "<div class='alert alert-block alert-success' style='" + user_class + "'><button type='button' class='close' data-dismiss='alert' onclick='CloseMessage()'>×</button><strong>Sucesso!</strong> {MENSAGEM}</div>";
var CONTEUDO_INFO = "<div class='alert alert-block alert-info' style='" + user_class + "'><button type='button' class='close' data-dismiss='alert' onclick='CloseMessage()'>×</button><strong>Importante!</strong> {MENSAGEM}</div>";
var CONTEUDO_WARN = "<div class='alert alert-block ' style='" + user_class + "'><button type='button' class='close' data-dismiss='alert' onclick='CloseMessage()'>×</button><strong>Aviso!</strong> {MENSAGEM}</div>";

function ShowMessage(mensagem, LEVEL, delay, onlyCloseable) {
    if (delay) {
        user_delay = delay;
    }
    else {
        user_delay = DELAY_DEFAULT;
    }
    if ($("#userMessage_showMessage").length == 0) {
        $('body').append("<div id='userMessage_showMessage' class='alert-message' style='position: fixed;width: 100%;height: 100%;top: 0px;left: 0px;text-align: center;z-index: 9999;'><div style=' background-color: #777777; opacity: 0.5;position: absolute;width: 100%;height: 100%;top: 0px;left: 0px;'></div><span></span></div>");
    }
    var CONTEUDO = CONTEUDO_WARN;
    if (LEVEL == ERROR_LEVEL) {
        CONTEUDO = CONTEUDO_ERROR;
    } else if (LEVEL == INFO_LEVEL) {
        CONTEUDO = CONTEUDO_INFO;
    } else if (LEVEL == WARNING_LEVEL) {
        CONTEUDO = CONTEUDO_WARN;
    } else if (LEVEL == SUCCESS_LEVEL) {
        CONTEUDO = CONTEUDO_SUCCESS;
    }

    $("#userMessage_showMessage span").html(CONTEUDO.replace("{MENSAGEM}", mensagem));
    $("#userMessage_showMessage").fadeIn("slow");
    
    if(!onlyCloseable)
        setTimeout(function () {CloseMessage()}, user_delay );
}
function CloseMessage() {
    $("#userMessage_showMessage").fadeOut("slow");
}