tool_tip_div_id = "tool_tip_div";
td_js_error     = "td_js_error";
current_balloon = 1;

function balloon_hide(bid)
{
    if(bid != 0 && current_balloon != bid)
        return
    var p   = balloon_get_element_pos(document.getElementById(tool_tip_div_id));
    document.getElementById(tool_tip_div_id).style.visibility = "hidden";
}

function balloon_show(tool_tip, control)
{
    current_balloon++;
    balloon_elem = document.getElementById(tool_tip_div_id);
    balloon_ctrl = document.getElementById(control);
    document.getElementById(td_js_error).innerHTML = tool_tip;
    balloon_elem.style.visibility = "visible";
    var p   = balloon_get_element_pos(balloon_ctrl);
    balloon_elem.style.top = p.y - balloon_elem.offsetHeight + 5;
    balloon_elem.style.left = p.x - balloon_elem.offsetWidth + 50;
    window.setTimeout("balloon_hide(" + current_balloon + ")", 4000);
}

function balloon_get_element_pos (el)
{
    var SL = 0, ST = 0;
    var is_div = /^div$/i.test(el.tagName);
    if (is_div && el.scrollLeft)
        SL = el.scrollLeft;
    if (is_div && el.scrollTop)
        ST = el.scrollTop;
    var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
    if (el.offsetParent)
    {
        var tmp = balloon_get_element_pos(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
}

function balloon_get_visible(obj)
{
    var value = obj.style.visibility;
    if (!value)
    {
        if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function")
        { // Gecko, W3C
            if (false)
                value = document.defaultView.getComputedStyle(obj, "").getPropertyValue("visibility");
            else
                value = '';
        }
        else if (obj.currentStyle) { // IE
            value = obj.currentStyle.visibility;
        }
        else
            value = '';
    }
    return value;
}

function balloon_hide_objects_at(el)
{
    var tags = new Array("applet", "iframe", "select", "object");

    var p   = balloon_get_element_pos(el);
    var EX1 = p.x;
    var EX2 = el.offsetWidth + EX1;
    var EY1 = p.y;
    var EY2 = el.offsetHeight + EY1;

    for (var k = tags.length; k > 0; )
    {
        var ar = document.getElementsByTagName(tags[--k]);
        var cc = null;

        for (var i = ar.length; i > 0;)
        {
            cc = ar[--i];

            p = balloon_get_element_pos(cc);
            var CX1 = p.x;
            var CX2 = cc.offsetWidth + CX1;
            var CY1 = p.y;
            var CY2 = cc.offsetHeight + CY1;

            if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1))
            {
                if (!cc.__msh_save_visibility)
                {
                    cc.__msh_save_visibility = balloon_get_visible(cc);
                }
                cc.style.visibility = cc.__msh_save_visibility;
            }
            else
            {
                if (!cc.__msh_save_visibility)
                {
                    cc.__msh_save_visibility = balloon_get_visible(cc);
                }
                cc.style.visibility = "hidden";
            }
        }
    }
}

function balloon_show_objects_at(el)
{
    var tags = new Array("applet", "iframe", "select", "object");

    var p   = balloon_get_element_pos(el);
    var EX1 = p.x;
    var EX2 = el.offsetWidth + EX1;
    var EY1 = p.y;
    var EY2 = el.offsetHeight + EY1;

    for (var k = tags.length; k > 0; )
    {
        var ar = document.getElementsByTagName(tags[--k]);
        var cc = null;

        for (var i = ar.length; i > 0;)
        {
            cc = ar[--i];

            p = balloon_get_element_pos(cc);
            var CX1 = p.x;
            var CX2 = cc.offsetWidth + CX1;
            var CY1 = p.y;
            var CY2 = cc.offsetHeight + CY1;

            if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1))
            {
                if (!cc.__msh_save_visibility)
                {
                    cc.__msh_save_visibility = balloon_get_visible(cc);
                }
                cc.style.visibility = cc.__msh_save_visibility;
            }
            else
            {
                if (!cc.__msh_save_visibility)
                {
                    cc.__msh_save_visibility = balloon_get_visible(cc);
                }
                cc.style.visibility = "hidden";
            }
        }
    }
}
