﻿var ProcessingRequestBox = Class.create({
    initialize: function(titleTxt, options) {
        
        this.content = null;
        this.notfWindow = null;
        this.isVisible = false;
        this.manualHide = false;
        
        var mFrame = $(document.createElement('span'));
        mFrame.addClassName('notoficationBox');
        mFrame.addClassName('processingBox');
        
        var mTab = $(document.createElement('table'));
        mTab.cellSpacing = 0;
        mTab.cellPadding = 0;
        mTab.border = 0;
        mFrame.appendChild(mTab);
        
        var mTabBody = $(document.createElement('tbody'));
        mTab.appendChild(mTabBody);
        var tr = $(document.createElement('tr'));
        mTabBody.appendChild(tr);
        var td = $(document.createElement('td'));        
        tr.appendChild(td);
        
        var img = $(document.createElement('img'));
        img.src = '/images/interface/icons/loading-circle.gif';
        img.alt = titleTxt;
        img.align = 'absmiddle';
        td.appendChild(img);
        
        // add the title
        var titleDiv = $(document.createElement('span'));
        titleDiv.innerText = titleTxt;
        titleDiv.innerHTML = titleDiv.innerText;
        titleDiv.addClassName('title');
        td.appendChild(titleDiv);
        
        this.loadingIcon = img;
        this.titleContainer = titleDiv;
        this.content = mFrame;
        this.tdContainer = td;
    },
    show: function(afterFinishFunct) {
        if (!this.isVisible) {
            this.notifyWindow = new WindowTranspBg(null, null, this.content, {afterFinish: afterFinishFunct});        
            this.isVisible = true;
        }
    },
    hide: function(afterFinishFunct) {
        if (this.isVisible && !this.manualHide) this.notifyWindow.remove({afterFinish: afterFinishFunct});
    },
    setTitle: function(titleTxt) {
        this.titleContainer.innerText = titleTxt;
        this.titleContainer.innerHTML = this.titleContainer.innerText;
    }
    ,addOkButton: function(btnPath, altTxt) {
        var img = $(document.createElement('img'));
        img.src = btnPath;
        img.alt = altTxt;
        img.align = 'absmiddle';
        img.addClassName('okBtn');
        this.tdContainer.appendChild(img);
        
        var nw = this.notifyWindow;
        
        Event.observe(img, 'click', function() { nw.remove(); });
    }
});