﻿function Confirmer() {
    this.displayHtml = "";
    this.buttons = new Array();
    var divC;
    var divCtn;
    var isClicked = false;
    var displayContainer;
    this.fontFamily = "Tahoma";
    this.fontSize = "12px";
    this.width = "200px";
    this.height = "100px";
    this.top = "40%";
    this.left = "40%";
    this.bgColor = "#787878";
    this.padding = "10px 10px 10px 10px";
    this.borderLeft = "1px solid #aaaaaa";
    this.borderTop = "1px solid #aaaaaa";
    this.borderRight = "2px outset #888888";
    this.borderBottom = "2px outset #888888";
    this.buttonCss = "";
    this.animatePopup = false;
    this.isModalPopup = true;
}
Confirmer.prototype.AddButton = function (btn) {
    this.buttons.push(btn);
}
Confirmer.prototype.Render = function () {
    if (this.isModalPopup) {
        this.Container = document.createElement("div");
        $(this.Container).attr("id", "divContainer");
        $(this.Container).css({
            "z-index": "200",
            "position": "absolute",
            "cursor": "pointer",
            "top": "0px",
            "left": "0px",
            "background-color": "#787878",
            "filter": "alpha(opacity=70)",
            "opacity": "0.7",
            "-moz-opacity": ".70",
            "height": document.body.scrollHeight + "px",
            "width": "100%",
            "display": "block"
        });

        $(document.body).prepend(this.Container);


    }
    this.Content = document.createElement("div");
    $(this.Content).attr("id", "divContent");

    $(this.Content).css({
        "display": ((this.animatePopup) ? "none" : "block"),
        "width": this.width,
        "height": this.height,
        "top": this.top,
        "left": this.left,
        "text-align": "center",
        "position": "absolute",
        "background-color": this.bgColor,
        "z-index": "205",
        "padding": this.padding,
        "border-left": this.borderLeft,
        "border-top": this.borderTop,
        "border-bottom": this.borderBottom,
        "border-right": this.borderRight,
        "font-family": this.fontFamily,
        "font-size": this.fontSize
    });

    //    var topBar = document.createElement("div");
    //    $(topBar).css({ "width": "100%","cursor":"pointer", "top": "0px", "height":"10px", "background-color": "#111111" });
    //    $(topBar).attr("id", "contentTopBar");
    //    $(topBar).mousedown(function() { this.isClicked = true; });
    //    $(topBar).mouseup(function() { this.isClicked = false; });
    //    $(topBar).mousemove(function(e) {
    //        if (this.isClicked) {
    //            $(this.Content).css("top", e.pageY + "px");
    //            $(this.Content).css("left", e.pageX + "px");
    //        }
    //    });
    //    $(this.Content).append(topBar);

    var htmlDiv = document.createElement("div");
    $(htmlDiv).css({ "width": "90%", "top": "10px", "padding": "8px", "text-align": "left" });
    $(htmlDiv).html(this.displayHtml);
    $(this.Content).append(htmlDiv);

    $(this.Content).append(document.createElement("br"));
    $(this.Content).append(document.createElement("br"));

    var buttonContainer = document.createElement("div");
    $(buttonContainer).attr("id", "buttonContainer");
    $(buttonContainer).css({ "width": "90%", "top": "50px", "padding": "10px", "text-align": "center" });
    for (var i = 0; i < this.buttons.length; i++) {
        var curButton = this.buttons[i];
        var button = curButton.GetButton();
        $(button).attr("class", this.buttonCss);
        $(buttonContainer).append(button);
        $(buttonContainer).append(document.createTextNode(" "));
    }
    $(this.Content).append(buttonContainer);

    document.body.appendChild(this.Content);

    if (this.animatePopup) {
        $(this.Content).fadeIn(800);
    }


}
Confirmer.prototype.Dispose = function () {
    try {
        document.body.removeChild(this.Content);
        if (this.isModalPopup) {
            document.body.removeChild(this.Container);
        }
    }
    catch (e) {

    }
}
function ConfirmerButton(name, text, onclick) {
    this.text = text;
    this.name = name;
    this.onclick = onclick;
}
function Evaluate(clkCode) {
    return function () { eval(clkCode); };
}

ConfirmerButton.prototype.GetButton = function () {
    var button = document.createElement("input");
    $(button).attr("id", "btn_" + this.name);
    //$(button).css("width", this.text.length * 12 + "px");
    $(button).attr("name", this.name);
    $(button).attr("type", "button");
    //$(button).attr("onclick", this.onclick);
    $(button).val(this.text);
    $(button).click(Evaluate(this.onclick));

    return button;
}

