<!-- ------------------------------------------------------------- -->
<!--            Developed by Vladimir AGEENKO 2003                 -->
<!--        E-commerce, Web Development, UI and Web Design.        -->
<!--                                                               -->
<!--                Web: http://www.valdersoft.com/                -->
<!--                E-mail: vladimir@valdersoft.com                -->
<!--                          ICQ: #45658511                       -->
<!-- ------------------------------------------------------------- -->

function ButtonsBar ( imagesPath, drawTarget )
{
    this.data       = new Array ();
    this.imagesPath = imagesPath;
    this.drawTarget = drawTarget;

    this.Begin              = ButtonsBarBegin;
    this.Clear              = ButtonsBarClear;
    this.Button             = ButtonsBarButton;
    this.InactiveButton     = ButtonsBarInactiveButton;
    this.TextButton         = ButtonsBarTextButton;
    this.InactiveTextButton = ButtonsBarInactiveTextButton;
    this.HTML               = ButtonsBarHTML;
    this.Separator          = ButtonsBarSeparator;
    this.End                = ButtonsBarEnd;
    this.Update             = ButtonsBarUpdate;
    this.Draw               = ButtonsBarDraw;

    return this;
}

function ButtonsBarClear ()
{
    this.data = new Array ();
}

function ButtonsBarBegin ()
{
    this.data[this.data.length] = '<TD><DIV class="toolbarSeparator"></DIV></TD>';
}

function ButtonsBarButton ( id, imageName, onClickEvent, note, visible )
{
    onClickEvent = (onClickEvent != undefined) ? onClickEvent : '';
    note = (note != undefined) ? note : '';
    visible = (visible == undefined || visible == true) ? true : false;

    this.data[this.data.length] = '<TD id="' + id + '" style="display: ' + 
        ((visible!='') ? 'inline' : 'none') + '">' + 

        '<DIV class="buttonDefault"' + 
            ((onClickEvent!='') ? 
                ' onClick="javascript:' + onClickEvent + '"' : '')+ 

            ' onMouseOver="javascript:this.className=\'buttonMouseOver\';' + 
                ((top.Note!=null && note!='') ? "top.Note('" + note + "')" : "") + '"' +
            ' onMouseOut="this.className=\'buttonDefault\';' + 
                ((top.Note!=null && note!='') ? "top.Note('')" : "") + '"' +
            ' onMouseDown="this.className=\'buttonMouseDown\'" onMouseUp="this.className=\'buttonMouseOver\'"' + 
                ((note!='') ? ' title="' + note + '"' : '') + '>'+

        '<IMG src="' + this.imagesPath + imageName + '" width=16 height=16 border=0></DIV></TD>\n';
}

function ButtonsBarInactiveButton ( id, imageName, visible )
{
    visible = (visible == undefined || visible == true) ? true : false;

    this.data[this.data.length] = '<TD id="' + id + '" style="display: ' + 
        ((visible!='') ? 'inline' : 'none') + '">' + 
        '<DIV class="buttonDefault"><IMG src="' + this.imagesPath + imageName + '" width=16 height=16 border=0></DIV></TD>\n';
}

function ButtonsBarTextButton ( id, buttonText, onClickEvent, note, visible )
{
    onClickEvent = (onClickEvent != undefined) ? onClickEvent : '';
    note = (note != undefined) ? note : '';
    visible = (visible == undefined || visible == true) ? true : false;

    this.data[this.data.length] = '<TD id="' + id + '" style="vertical-align: baseline; display: ' + 
        ((visible!='') ? 'block' : 'none') + '">' + 

        '<DIV class="textButtonDefault"' + 
            ((onClickEvent!='') ? 
                ' onClick="javascript:' + onClickEvent + '"' : '')+ 

            ' onMouseOver="this.className=\'textButtonMouseOver\';' + 
                ((top.Note!=null && note!='') ? "top.Note('" + note + "')" : "") + '"' +
            ' onMouseOut="this.className=\'textButtonDefault\';' + 
                ((top.Note!=null && note!='') ? "top.Note('')" : "") + '"' +
            ' onMouseDown="this.className=\'textButtonMouseDown\'" onMouseUp="this.className=\'textButtonMouseOver\'"' + 
                ((note!='') ? ' title="' + note + '"' : '') + '><NOBR>&nbsp;' +

            buttonText +

        '&nbsp;</NOBR></DIV></TD>\n';
}

function ButtonsBarInactiveTextButton ( id, buttonText, visible )
{
    visible = (visible == undefined || visible == true) ? true : false;

    this.data[this.data.length] = '<TD id="' + id + '" style="vertical-align: baseline; display: ' + 
        ((visible!='') ? 'inline' : 'none') + '">' + 
        '<DIV class="textButtonDefault" DISABLED><NOBR>&nbsp;' + buttonText + '&nbsp;</NOBR></DIV></TD>\n';
}

// Insert HTML code in buttons bar.
function ButtonsBarHTML ( buttonText )
{
    this.data[this.data.length] = '<TD><NOBR>' + buttonText + '</NOBR></TD>';
}

function ButtonsBarSeparator ()
{
    this.data[this.data.length] = '<TD><DIV class="buttonSeparator"></DIV></TD>';
}

function ButtonsBarEnd ()
{
    this.data[this.data.length] = '<TD><DIV class="toolbarEndGroup"></DIV></TD>';
}

// Update buttons visibility.
function ButtonsBarUpdate ()
{
    var drawTarget = (arguments.length % 2) ? arguments[0] : this.drawTarget;

    // Parse drawTarget to define frame target only.
    var drawTargetSplit = drawTarget.split('.');

    if ( drawTargetSplit.length > 2 ) 
    {
        drawTarget = drawTargetSplit[0] + '.' + drawTargetSplit[1];
    }

    for (var i = ((arguments.length % 2) ? 1 : 0); i < arguments.length; i+=2)
    {
        var buttonID = arguments[i];
        var buttonVisible = arguments[i+1];

        if ( eval(drawTarget + '.' + buttonID) != null )
        {
            eval(drawTarget + '.' + buttonID + '.style.display = "' + ((buttonVisible) ? 'inline' : 'none') + '"');
        }
    }
}

function ButtonsBarDraw ()
{
    if (eval(this.drawTarget) != null)
    {
        eval(this.drawTarget).innerHTML = '<TABLE height=22 cellspacing=0 cellpadding=0 border=0 onMouseOver="javascript:selection.empty()" onClick="javascript:selection.empty()" onSelectStart="javascript:selection.empty()"><TR>' + this.data.join('') + '</TR></TABLE>';
    }
}
