﻿function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;        
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function showTT(id, text, ttID, top, left, className)
{
    hideTT(ttID);
	$("body").append("<p id='" + ttID + "'>"+ text +"</p>");
	$("#" + ttID)
	    .attr("class", className)
		.css("top",(findPosY(document.getElementById(id))+top) + "px")
		.css("left",(findPosX(document.getElementById(id))+left) + "px")
		.show()
		.click(function(){
		    $(this).remove();
		});
}

function hideTT(ttID)
{
    $("#" + ttID).remove();
}