﻿// JScript Fille

var annunciators = new cAnnunciators();

function cAnnunciators()
{
    this.items = new Array();
}

cAnnunciators.prototype.items;


cAnnunciators.prototype.add = function(vTargetID, vBlinkColor, vDelay)
{
    if (document.getElementById(vTargetID))
    {
        var x = new cAnnunciator(vTargetID, vTargetID, vBlinkColor, vDelay)
        this.items[this.items.length]= x;
    }
}


cAnnunciators.prototype.del = function(vInstanceName)
{
    var x;
    var i;
    
    for (i = 0; i < this.items.length; i++)
    {
        x = this.items[i];
        if (x.instanceName == vInstanceName)
        {
            this.items.splice(i,1);
            return;
        }
    }
}

cAnnunciators.prototype.get = function (vInstanceName)
{
    var x;
    var i;
    
    for (i = 0; i < this.items.length; i++)
    {
        x = this.items[i];
        if (x.instanceName == vInstanceName)
        {
            return x;
        }
    }
}


cAnnunciators.prototype.blink = function (vInstanceName)
{
    var annunc = this.get(vInstanceName);
    if (annunc) annunc.blink();
}


cAnnunciators.prototype.startBlink = function (vInstanceName)
{
    var annunc = this.get(vInstanceName);
    if (annunc) 
    {
        annunc.startBlink();
    }  
}


cAnnunciators.prototype.stopBlink = function (vInstanceName)
{
    var annunc = this.get(vInstanceName);
    if (annunc) 
    {
        annunc.stopBlink();
    }  
}




// ------------------------------------------------------

function cAnnunciator(vInstanceName, vTargetID, vBlinkColor, vDelay)
{
    var obj;
    
    this.instanceName = vInstanceName;

    this.targetID = vTargetID;
    obj = document.getElementById(this.targetID)
    this.holdColor = obj.style.color;


    this.blinkColor=vBlinkColor;
    this.delay=vDelay;

    this.blinking = false;
    this.blinkOn = false;
    this.pause = false;

    this.cmd = "annunciators.blink('" + this.instanceName + "');"
}

cAnnunciator.prototype.instanceName;
cAnnunciator.prototype.targetID;
cAnnunciator.prototype.aTimer;
cAnnunciator.prototype.blinking = false;
cAnnunciator.prototype.blinkOn = false;
cAnnunciator.prototype.holdColor = '';
cAnnunciator.prototype.blinkColor = '';




cAnnunciator.prototype.startBlink = function()
{
    this.aTimer = setTimeout(this.cmd, this.delay);
}


cAnnunciator.prototype.stopBlink = function()
{
    var obj;
    if (this.aTimer != 0 )
    {
        clearTimeout(this.aTimer);
        this.aTimer = 0;
    }
    
    obj = document.getElementById(this.targetID)
    
    if (this.blinkOn == true)
    {
        this.blinkOn = false;
        if (this.holdColor)
        {
            obj.style.color = this.holdColor;
        }
        else
        {
            obj.style.color = ''
        }
    }
}


cAnnunciator.prototype.blink = function()
{
    var obj;
    
    obj = document.getElementById(this.targetID)
    
    if (this.blinkOn == true)
    {
        this.blinkOn = false;
        if (this.holdColor)
        {
            obj.style.color = this.holdColor;
        }
        else
        {
            obj.style.color = ''
        }
    }
    else
    {
        this.blinkOn = true;
        obj.style.color = this.blinkColor;
    }
    this.aTimer = setTimeout(this.cmd, this.delay);
}




