function get_position_left(obj) {
    if (!obj) {
        return null;
    }
    if (obj.offsetParent.tagName != 'BODY') {
        return obj.offsetLeft + get_position_left(obj.offsetParent);
    } else {
        return obj.offsetLeft;
    }
}

function get_position_top(obj) {
    if (!obj) {
        return null;
    }
    if (obj.offsetParent.tagName != 'BODY') {
        return obj.offsetTop + get_position_top(obj.offsetParent);
    } else {
        return obj.offsetTop;
    }
}

var oBaloon = null;
var t_x, t_y, t_obj;

function hide_balloon() {
    if (oBaloon != null) {
        oBaloon.style.display = "none";
        oBaloon = null;
        }
    }

function show_balloon(obj, x, y, t_url) {
    if (oBaloon != null) {
        hide_balloon();
        if (t_obj == obj) {
            return;
        }
    }
    if (!obj) {
        return null;
    }

    t_x = x;
    t_y = y;
    t_obj = obj;
    
    $.get(
        t_url, {},
        onAjaxSuccessLoadedText
    );
}

function show_balloon_from_text(obj, x, y, t_text) {
    if (oBaloon != null) {
        hide_balloon();
        if (t_obj == obj) {
            return;
        }
    }
    if (!obj) {
        return null;
    }

    t_x = x;
    t_y = y;
    t_obj = obj;
    onAjaxSuccessLoadedText(t_text);
}


function onAjaxSuccessLoadedText(data) {
    var t_div = null;
    if (!(t_div = document.createElement('div'))) {
        return null;
    }
    //t_div.style.backgroundColor = 'white';
    t_div.innerHTML = data;
    t_div.style.width = 'auto';
    t_div.style.position = 'absolute';
    t_div.style.left = get_position_left(t_obj) + t_x + 'px';
    t_div.style.top = get_position_top(t_obj) + t_y + 'px';
    document.body.appendChild(t_div);
    oBaloon = t_div;
}