//
//  Auxiliary functions
//

function KBSInit (id)
{
    var 
        obj_prev = document.getElementById (id);
    KBSButton_Show (obj_prev);
}

function KBSInt (szPixelValue)
{
    var szNum = szPixelValue;

    szNum = szNum.replace ('px', '');
    szNum = szNum.replace ('pt', '');
    szNum = szNum.replace ('%', '');
    return eval (szNum + " + 0;");
}

function KBSScrollY (id, limit)
{
    var 
        delay = 0,
        offY = 0,
        obj = document.getElementById (id);

    if (obj == null)
        return;

    if (KBSInt (obj.style.top) == -600)
        obj.style.top = 150;
    else
        obj.style.top = KBSInt (obj.style.top) - 1;

    delay = 10;
    if (KBSInt (obj.style.top) == 0 ||
        KBSInt (obj.style.top) == -150 ||
        KBSInt (obj.style.top) == -300 ||
        KBSInt (obj.style.top) == -450 )
    {
        delay = 10000;
    }

    setTimeout ("KBSScrollY ('" + id + "'," + limit + ");", delay);
}

function KBSShowLayer (div_id)
{
    var 
        obj = document.getElementById (div_id),
        obj_prev = document.getElementById (eval (div_id.substring (0, 5)));

    if (obj_prev)
        obj_prev.style.visibility = 'hidden';

    obj.style.visibility = 'visible';
    eval (div_id.substring (0, 5) + " = obj.id");
}

function KBSShowWnd (div_id)
{
    var 
        obj = document.getElementById (div_id);
    obj.style.visibility = 'visible';
}

function KBSHideWnd (div_id)
{
    var 
        obj = document.getElementById (div_id);
    obj.style.visibility = 'hidden';
}

function KBSButton_Show (img)
{
    var
        str,
        idx = img.src.indexOf ('_p.gif');

    if (idx != -1)
        return;

    str = img.src.replace ('.gif', '_p.gif');
    img.src = str;
}

function KBSButton_Hide (img)
{
    var
        str,
        idx = img.src.indexOf ('_p.gif');

    if (idx == -1)
        return;

    str = img.src.replace ('_p.gif', '.gif');
    img.src = str;
}

function KBSLink_Over (img_id)
{
    var
       obj = document.getElementById (img_id),
       obj_prev = document.getElementById (eval(img_id.substring(0, 6)));

    if (obj_prev)
        KBSButton_Hide (obj_prev);
    
    KBSButton_Show (obj);
    eval (img_id.substring (0, 6) + " = obj.id");
}

function KBSCursor_Init (id)
{
    var
       obj = document.getElementById (id);

    if (obj != null)
        obj.style.backgroundColor = "#8a8a8a";
}

function KBSCursor_Over (id)
{
    var
       obj = document.getElementById (id),
       obj_prev = document.getElementById (eval (id.substring (0, 8)));
    
    if (obj_prev != null)
    {
        //obj_prev.style.left = "0";
        obj_prev.style.backgroundColor = "#ffffff";
    }

    if (obj != null)
    {
        //obj.style.left = "25";
        obj.style.backgroundColor = "#8a8a8a";
    }
    
    eval (id.substring (0, 8) + " = obj.id");
}

function KBSSetImageSource (img_id, new_name)
{
    var
       str = "",
       idx = 0,
       img = document.getElementById (img_id);

    if ( ! img)
        return;
    
    idx = img.src.lastIndexOf ('/') + 1;
    if (idx == -1)
        return;

    new_src = img.src.replace (img.src.substr (idx, img.src.length - idx),
                               new_name);
    if ( ! new_src)
        return;
    img.src = new_src;
}

function KBSImageShow (id)
{
    var 
        obj = document.getElementById (id),
        idx = -1,
        str = "";

    if (obj == null)
        return;

    idx = obj.src.indexOf ('_p.gif');
    if (idx != -1)
        return;

    str = obj.src.replace ('.gif', '_p.gif');
    obj.src = str;
}

function KBSImageHide (id)
{
    var 
        obj = document.getElementById (id),
        idx = -1,
        str = "";

    if (obj == null)
        return;

    idx = obj.src.indexOf ('_p.gif');
    if (idx == -1)
        return;

    str = obj.src.replace ('_p.gif', '.gif');
    obj.src = str;
}
