﻿function MessageBox() {
    this.Styles = { Blue: 1, Olive: 2, Gray: 3 };
    this._Style;
    this._MsgBoxCaption = "";
    this._MsgBoxString = "";
}

MessageBox.prototype.Show = function() {
    try {
        var Style = this._Styles;
        switch (Style) {
            case 1:
                Style = "Blue"
                break;
            case 2:
                Style = "Olive"
                break;
            case 3:
                Style = "Gray"
                break;
            default:
                Style = "Blue"
                break;
        }

        if ($get("MessageBoxBack") != null) { $get("MessageBoxBack").parentNode.removeChild($get("MessageBoxBack")); }
        if ($get("MessageBox") != null) { $get("MessageBox").parentNode.removeChild($get("MessageBox")); }

        var divMsgBoxBack = document.createElement("div");
        divMsgBoxBack.id = "MessageBoxBack";
        divMsgBoxBack.style.height = document.getElementById('container-page').offsetHeight;

        var divMsgBox = document.createElement("div");
        divMsgBox.id = "MessageBox";


        var msg = "";

        msg += "<div class=\"" + Style + "_Ust-Sol\"></div>";
        msg += "<div class=\"" + Style + "_Ust-Orta\"><div class=\"" + Style + "_Ust-Icon\"></div><div class=\"" + Style + "_Ust-Msg\">" + this._MsgBoxCaption + "</div><div class=\"" + Style + "_Ust-Kapat\" onclick=\"MessageBox.prototype.Close('MessageBox');\"></div></div>";
        msg += "<div class=\"" + Style + "_Ust-Sag\"></div>";

        msg += "<div class=\"" + Style + "_Orta-Sol\"></div>";
        msg += "<div class=\"Orta\">";
        msg += "<div class=\"" + Style + "_Orta-Icon\"></div>";
        msg += "<div class=\"" + Style + "_Mesaj\">" + this._MsgBoxString + "</div>";
        msg += "<div class=\"" + Style + "_Tamam\" onclick=\"MessageBox.prototype.Close('MessageBox');\"></div>";
        msg += "</div>";
        msg += "<div class=\"" + Style + "_Orta-Sag\"></div>";

        msg += "<div class=\"" + Style + "_Alt-Sol\"></div>";
        msg += "<div class=\"" + Style + "_Alt-Orta\"></div>";
        msg += "<div class=\"" + Style + "_Alt-Sag\"></div>";

        divMsgBox.innerHTML = msg;

        document.body.appendChild(divMsgBox);
        document.body.appendChild(divMsgBoxBack);

        var divMessageBox = $("#MessageBox");

        divMessageBox.easydrag();
        divMessageBox.vCenter();
        divMessageBox.css('left', $(window).width() / 2 - divMessageBox.width() / 2);

    } catch (e) {
        alert("Error On MsgBox:" + e);
    }
}

MessageBox.prototype.Close = function() {
    try {

        if ($get("MessageBox")) {
            $get("MessageBoxBack").parentNode.removeChild($get("MessageBoxBack"));

            //$("#MessageBox").animate({ top: "+=25px", opacity: 0 }, "slow");
            $get("MessageBox").parentNode.removeChild($get("MessageBox"));
        }
    }
    catch (e) { alert("Error On MsgBox :" + e); }
}

function msgbox(caption, message) {
    $(document).ready(function() {
        var WebMsgBox = new MessageBox();
        WebMsgBox._MsgBoxCaption = caption;
        WebMsgBox._MsgBoxString = message;
        WebMsgBox._Styles = WebMsgBox.Styles.Blue;
        WebMsgBox.Show();
    });
}

