function Tooltip(dd, X, Y) {
    var isIe = document.all ? true : false;
    //var isIe = document.all && !window.opera ? true : false; 
    var d = document.getElementById(dd);
    var posX;
    var posY;
    var body = document.body;
    var vecX = X;
    var vecY = Y;
    var fromX = 10;
    var fromY = 15;
    var working=false;
    
    this.Init = function() {
        if(!isIe) {
            document.captureEvents(Event.MOUSEMOVE);
            document.onmousemove = this.Position;
        }
    }
    
    this.Position = function(event) {
        posX = event.pageX;
        posY = event.pageY;
    }
    
    this.toolMove = function(X, Y) {
        if( d.style.visibility != 'visible') {
        //    return false;
        }

        if(isIe) {
            //alert(event.clientY+'-'+document.documentElement.scrollTop);
            mouseX = event.clientX;
            if(!window.opera)
            {
                mouseY = event.clientY+document.documentElement.scrollTop;
            }
            else
            {
                mouseY = event.clientY+document.documentElement.scrollTop;
/*                mouseY = event.clientY;*/
            }
        } else {
            mouseX = posX - body.scrollLeft;
            mouseY = posY - body.scrollTop;
        }
        
        tempX = mouseX + X;
        
        if(tempX < 0 ) {
            tempX = 0;
        }
        
        tmp = body.clientWidth - mouseX - X - d.offsetWidth - fromX;
        
        if(tmp < 0) {
            tempX += tmp;
            if(tempX < 0) {
                tempX = 0;
            }
        }
        
        d.style.left = body.scrollLeft + tempX+"px";
        
        tempY = mouseY + Y;
        if(tempY < 0) {
            tempY = 0;
        }
        
        tmp = body.clientHeight - mouseY - Y - d.offsetHeight - fromY;
        if(tmp < 0) {
            tmp = mouseY - fromY - d.offsetHeight;
            if(tmp>=0) {
                tempY = tmp;
            }
        }
        d.style.top = body.scrollTop + tempY + "px";
    }
    
    this.Move = function() {
        this.toolMove(vecX, vecY);
    }
    
    this.Display = function(X, Y, src) {
        this.toolMove(X, Y);
        d.innerHTML = src;
        d.style.visibility = 'hidden';
    }
    
    this.Hide = function() {
        d.style.visibility = 'hidden';
        d.innerHTML = '';
        d.style.top = 0;
        d.style.left = 0;
    }
    
    this.Show = function(html) {
        this.Display(5, 20, html);
        d.style.visibility = 'visible';
    }
    
    this.ShowQuick = function(obj, tip, html) {
        if(this.working==true)
        {
            d.style.visibility = 'hidden';
            this.Display(5, 20, html);
            d.style.visibility = 'visible';
        }
        obj.onmousemove = function() { tip.Move(); }
        obj.onmouseout = tip.Hide;
    }
}
