
/* StatusBar class scripts --- */ 
function StatusBar(idCont, idIcon, idTitle, idMsg, needalert, type){
    // Ctor arguments check ---
    if(!idCont || !idIcon || !idTitle || !idMsg ||!type){
        alert('JavaScript class \'StatusBar\' cannot be created! Invalid constructor parameters!');
        return;
    }
    // Private fields ---
    var _this = this;
    var _idCont = idCont;
    var _idIcon = idIcon;
    var _idTitle = idTitle;
    var _idMsg = idMsg;
    var _needAlert = (sw_ToBool(needalert));
    var _type = type;
    var _ensured = false;

    var stat_container = null;
    var stat_icon = null;
    var stat_title = null;
    var stat_msg = null;

    // Private const ---
    var _InfoType = 'Info';
    var _ErrorType = 'Error';
    var _SuccessType = 'Success';

    // Public fields ---
    this.InfoImg = '/App_Themes/WinXPReloadedCompact/images/icon_info.gif';
    this.ErrorImg = '/App_Themes/WinXPReloadedCompact/images/icon_stop.gif';
    this.SuccessImg = '/WebResource.axd?d=6OSB_AiFEcPJRoiw33KOP8LS9XUHqjwpRcqySKjlfSXx2Os8XjyGWGWPtkqsd1Ab1bOBrQnDPK-bIx-AStm6faYtRc8khpd-1IX_LJHkIQa9y6E-D_BrzYBk0NqH5uS90&t=633416949660000000';
    this.InfoStyle = '';
    this.ErrorStyle = '';
    this.SuccessStyle = '';
    this.InfoClass = '';
    this.ErrorClass = '';
    this.SuccessClass = '';
    this.InfoText = '';
    this.ErrorText = '';
    this.SuccessText = '';

    // Private methods ---
    var _EnsureElements = function(){
        if(_ensured)
            return;
        stat_container = document.getElementById(_idCont);
        stat_icon = document.getElementById(_idIcon);
        stat_title = document.getElementById(_idTitle);
        stat_msg = document.getElementById(_idMsg);
        if(stat_container && stat_icon && stat_title && stat_msg)
            _ensured = true;
    }
    var _Refresh = function(){
        _EnsureElements();
        switch (_type) {
            case _InfoType :
                stat_icon.src = _this.InfoImg;
			    stat_container.style.cssText = _this.InfoStyle;// +'height: '+stat_container.style.height;
			    stat_container.className = _this.InfoClass;
                break;
            case _ErrorType :
                stat_icon.src = _this.ErrorImg;
			    stat_container.style.cssText = _this.ErrorStyle;// +'height: '+stat_container.style.height;
			    stat_container.className = _this.ErrorClass;
                break;
            case _SuccessType :
                stat_icon.src = _this.SuccessImg;
			    stat_container.style.cssText = _this.SuccessStyle;// +'height: '+stat_container.style.height;
			    stat_container.className = _this.SuccessClass;
                break;
           default : break;               
        }
        // Visual effect
         sw_Splash(stat_title, 300, 25); 
         sw_Splash(stat_msg, 300, 25); 

        // Debug code:
        //alert('_this.ErrorImg = '+_this.ErrorImg+'\n'+'_this.InfoImg = '+_this.InfoImg+'\n'+'stat_icon.src = '+stat_icon.src);
    }
    
    // Public methods ---
    this.Hide = function(){
        _EnsureElements();
        stat_container.style.display='none';
    }
    
    this.Show = function(){
        _Refresh();
        stat_container.style.display='';
        if(_needAlert)
            alert(this.get_Mess());
    }

    this.ToError = function(){
        this.set_Type(_ErrorType);        
    }
    this.ToInfo = function(){
        this.set_Type(_InfoType);        
    }
    this.ToSuccess = function(){
        this.set_Type(_SuccessType);        
    }

    // Public props ---
    this.get_Title = function(){
        _EnsureElements();
        return stat_title.innerHTML.replace('<br/>', '\n');
    }
    this.set_Title = function(val){
        if(!val) return;
        _EnsureElements();
        switch (_type) {
            case _InfoType :
                this.InfoText = val;
                break;
            case _ErrorType :
                this.ErrorText = val;
                break;
            case _SuccessType :
                this.SuccessText = val;
                break;
           default : break;               
        }
        var title = val.replace('\n', '<br/>');
        if (title.length > 200){
            title = title.substr(0, 200)+'...';
        }
        stat_title.innerHTML = title;
    }

    this.get_Mess = function(){
        _EnsureElements();
        return stat_msg.innerHTML.replace('<br/>', '\n');
    }
    this.set_Mess = function(val){
        if(!val){ 
            //return;
            val = '[Message doesn\'t specified]';
        }
        _EnsureElements();
        var mess = val.replace('\n', '<br/>');
        if (mess.length > 200){
            mess = mess.substr(0, 200)+'...';
        }
        stat_msg.innerHTML = mess;
        _Refresh();
    }

    this.get_Type = function(){ return _type; }
    this.set_Type = function(val){
        if(!val || _type==val) return;
        switch (val) {
            case _InfoType :
                _type = val;
                this.set_Title(this.InfoText);
                break;
            case _ErrorType :
                _type = val;
                this.set_Title(this.ErrorText);
                break;
            case _SuccessType :
                _type = val;
                this.set_Title(this.SuccessText);
                break;
           default : 
                alert('Wrong type of StatusBar! Presentation type \''+val+'\' doesn\'t exists. Only \''+ _InfoType +'\', \''+ _ErrorType +'\' is allowed.');
                return;
                break;               
        }
    }

    this.get_NeedAlert = function(){
        return _needAlert;
    }
    this.set_NeedAlert = function(val){
        _needAlert = (sw_ToBool(val));
    }
        
}// end of StatusBar

/* --- */