////////////////////////////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////////////////////////////

var __CFWINDOW_ERROR_ID = "invalid CFWindow id";

////////////////////////////////////////////////////////////////////////////////
// Static Variables
////////////////////////////////////////////////////////////////////////////////

var __cfWindowMap = {};

////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////

function CFWindow(id, titleBarId, contentPaneId, closeButtonId)
{
    CFPopup.call(this, id);
    var closeButton = cfElementGet(closeButtonId);
    this.__contentPane = cfElementGet(contentPaneId);
    this.__titleBar = cfElementGet(titleBarId);
    __cfWindowMap[id] = this;
    var f = cfEventHandlerCreate(this.__close.bind(this));
    closeButton.onclick = f;
}

CFWindow.extendClasses(CFPopup);

CFWindow.prototype.__close = function()
{
    this.hide();
}

CFWindow.prototype.getContentPane = function()
{
    return this.__contentPane;
}

CFWindow.prototype.getContentPaneHTML = function()
{
    return cfElementGetInnerHTML(this.__contentPane);
}

CFWindow.prototype.setContentPaneHTML = function(html)
{
    cfElementSetInnerHTML(this.__contentPane, html);
}

CFWindow.prototype.setTitle = function(title)
{
    cfElementSetInnerText(this.__titleBar, title);
}

////////////////////////////////////////////////////////////////////////////////
// Public API
////////////////////////////////////////////////////////////////////////////////

function cfWindowGet(id)
{
    var win = __cfWindowMap[id];
    if (! win) {
        return cfErrorTrigger("cfWindowGet: '" + id + "': " +
                              __CFWINDOW_ERROR_ID);
    }
    return win;
}
