/*
window_alert.js Popup for generic alert
Dependencies : Prototype JavaScript framework 1.6
               window.js
utilities.js
*/

var SOSCuisine = SOSCuisine || {};

SOSCuisine.WindowAlert = Class.create(SOSCuisine.BaseWindow,
{
    container: null,
    id: null,
    title: null,
    message: null,
    cancelButton: null,
    submitButton: null,
    options: {},
    args: [],

    initialize: function($super, id, options)
    {
        $super("window_alert_" + id);
        this.options = options;
        this.create();
    },

    create: function()
    {
        this.title = new Element("h2");
        if (this.options.title)
        {
            this.title.innerHTML = this.options.title;
        }
        this.container.appendChild(this.title)

        this.message = new Element("div");
        if (this.options.message)
        {
            this.message.innerHTML = this.options.message;
        }
        this.container.appendChild(this.message);

        this.container.appendChild(new Element("br"));

        var buttonContainer = new Element("div");
        buttonContainer.addClassName("right_align_container");
        this.container.appendChild(buttonContainer)

        if (this.options.showSubmit && this.options.showSubmit == true)
        {
            this.submitButton = new Element("input");
            if (this.options.submitValue)
            {
                this.submitButton.value = this.options.submitValue;
            }
            else
            {
                this.submitButton.value = "Submit";
            }
            this.submitButton.type = "button";
            this.submitButton.style.minWidth = "100px";
            this.submitButton.observe('click', this.submitButton_click.bind(this));
            buttonContainer.appendChild(this.submitButton);
        }

        if (this.options.showCancel && this.options.showCancel == true)
        {
            buttonContainer.appendChild(document.createTextNode(" "));
            
            this.cancelButton = new Element("input");
            if (this.options.cancelValue)
            {
                this.cancelButton.value = this.options.cancelValue;
            }
            else
            {
                this.cancelButton.value = "Cancel";
            }
            this.cancelButton.type = "button";
            this.cancelButton.style.minWidth = "100px";
            this.cancelButton.observe('click', this.cancelButton_click.bind(this));
            buttonContainer.appendChild(this.cancelButton);
        }
    },

    loadContents: function(args)
    {
        this.container.style.backgroundImage = "";
        this.args = args;
        //var title = args.title
    },

    hide: function($super, returnData)
    {
        this.setSelectVisibility("visible");
        this.window.style.visibility = "hidden";
        document.getElementById("sidebar_ads").style.display = "block";
        SOSCuisine.overlay.hideOverlay();
    },

    cancelButton_click: function()
    {
        this.hide();
        this.options.callback.cancel(this.args);
    },

    submitButton_click: function()
    {
        this.hide();
        this.options.callback.success(this.args);
    }

});