/*
    baseWindow.js Popup base window
    Dependencies : Prototype JavaScript framework 1.6
                   utilities.js
*/

var SOSCuisine = SOSCuisine || {};

SOSCuisine.BaseWindow = Class.create(
{
    container: null,
    window: null,
    windowName: null,

    initialize: function(windowName)
    {
        this.windowName = windowName;
        this.createContainer();
    },

    createContainer: function()
    {
        this.window = new Element("table");
        var tbody = new Element("tbody");
        var tr = new Element("tr");
        var td = new Element("td");
        this.container = new Element("div");
        var innerDiv = new Element("div");

        this.window.className = "modal_dialog";
        this.window.id = "modal_dialog_" + this.windowName;

        td.style.verticalAlign = "middle";

        this.container.className = "modal_dialog_content";
        this.container.id = "modal_dialog_content_" + this.windowName;

        innerDiv.className = "modal_dialog_content_inner";
        innerDiv.id = "modal_dialog_content_inner_" + this.windowName;

        this.container.appendChild(innerDiv);
        td.appendChild(this.container);
        tr.appendChild(td);
        tbody.appendChild(tr);
        this.window.appendChild(tbody);
        document.body.appendChild(this.window);
    },

    setSelectVisibility: function(visible)
    {
        nodes = document.getElementsByTagName('select');
        for (var i = 0; i < nodes.length; i++)
        {
            nodes[i].style.visibility = visible;
        }
    },

    show: function(args)
    {
        if (window.scrollTo)
        {
            window.scrollTo(0, 0);
        }
        this.setSelectVisibility("hidden");
        SOSCuisine.overlay.showOverlay();
        this.window.style.visibility = "visible";
        document.getElementById("sidebar_ads").style.display = "none";
        this.container.style.backgroundImage = "url(" + SOSCuisine.config.urlRoot + "media/images/ajax-loader.gif)";

        if (this.loadContents)
        {
            this.loadContents(args);
        }
    },

    hide: function(returnData)
    {
        this.setSelectVisibility("visible");
        this.window.style.visibility = "hidden";
        document.getElementById("sidebar_ads").style.display = "block";
        SOSCuisine.overlay.hideOverlay();
        this.container.innerHTML = "";
    },

    load: function(url, parameter)
    {
        new Ajax.Request(SOSCuisine.config.urlRoot + url,
       {
           method: "get",
           encoding: 'iso-8859-1',
           parameters: parameter,
           onSuccess: function(transport)
           {
               this.container.style.height = "auto";
               this.container.style.backgroundImage = "";
               var response = transport.responseText || "";
               this.container.innerHTML = response;
               if (this.onLoadingCompleted)
               {
                   this.onLoadingCompleted();
               }
           } .bind(this)
       });
    }
});
