﻿function NotificationBar (id)
{
    this.ElementId     = id ;
    this.ElementTextId = id + "Text" ;

    this.Element     = document.getElementById (this.ElementId) ;
    this.ElementText = document.getElementById (this.ElementTextId) ;
    
    this.Severity    = 2    ; // Normal
    this.Text        = ""   ;
    this.ShowTimeout = -1   ; // Infinite, in ms
    this.Timer       = null ; // Timeout timer
}

NotificationBar.prototype.Show = function (text)
{
    var className    = this.Element.className ;
    var severityName = this.ElementText.className ;
    var displaySeverityClassName = this.GetSeverityDisplayClassName () ;
    
    this.Element.className     = className.replace ("Invisible", "Visible").replace (/Severity[^\s]+/, displaySeverityClassName) ;
    this.ElementText.innerHTML = text ;
    this.Text = text ;
    if (this.ShowTimeout != -1)
    {
        clearTimeout (this.Timer) ;
        this.Timer = setTimeout ("HideNotificationBar ('" + this.ElementId + "') ;", this.ShowTimeout) ;
    }
}

NotificationBar.prototype.Hide = function ()
{
    var className = this.Element.className ;
    this.Element.className = className.replace ("Visible", "Invisible") ;
}

NotificationBar.prototype.GetSeverityDisplayClassName = function ()
{
    switch (this.Severity)
    {
    case 1:
        return "SeverityLow" ;
        break ;

    case 2:
        return "SeverityNormal" ;
        break ;

    case 3:
        return "SeverityHigh" ;
        break ;
        
    default:
        throw "Unknown severity level" ;
    }
}

function HideNotificationBar (id)
{
    var element = document.getElementById (id) ;
    var className = element.className ;
    element.className = className.replace ("Visible", "Invisible") ;
}

