var ttEnabled=false;
var ttObject;

function ttInit() {  
    if (DOM||MS||NS) {     
        ttObject=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
        document.onmousemove=positiontip;
    }
}

function ttIETrueBody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thecolor, thewidth){
    if (DOM||MS||NS){
        if (typeof thewidth!="undefined") ttObject.style.width=thewidth+"px";
        if (typeof thecolor!="undefined" && thecolor!="") ttObject.style.backgroundColor=thecolor;
        ttObject.innerHTML='<div class="top"></div><div class="content">'+thetext+'</div><div class="bottom"></div>';
        ttEnabled=true;
        return false;
    }
}

function opentip(thetext) {
    ttwin = window.open("", "", "width=200,height=200,left=100,top=200,menubar=no,resizable=no,scrollbars=no,toolbar=no,location=no");
    ttwin.document.write(thetext);

    ttwin.focus();  
}

function positiontip(e){
    
    if (ttEnabled){
        
        var offsetxpoint=-60;
        var offsetypoint=20;
        
        var curX=(DOM && !isIE)?e.pageX : event.clientX+ttIETrueBody().scrollLeft;
        var curY=(DOM && !isIE)?e.pageY : event.clientY+ttIETrueBody().scrollTop;

        var rightedge=isIE&&!window.opera? ttIETrueBody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
        var bottomedge=isIE&&!window.opera? ttIETrueBody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;

        var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

        if (rightedge<ttObject.offsetWidth){            
            ttObject.style.left=isIE? ttIETrueBody().scrollLeft+event.clientX-ttObject.offsetWidth+"px" : window.pageXOffset+e.clientX-ttObject.offsetWidth+"px";
        } else if (curX<leftedge) {
            ttObject.style.left="5px";
        } else {           
            ttObject.style.left=curX+offsetxpoint+"px";
        }

        if (bottomedge<ttObject.offsetHeight) {
            ttObject.style.top=isIE? ttIETrueBody().scrollTop+event.clientY-ttObject.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-ttObject.offsetHeight-offsetypoint+"px";
        } else {            
            ttObject.style.top=curY+offsetypoint+"px";
            ttObject.style.visibility="visible";
        }
    }
}

function getElPos(elem, prop) {    
    var result = 0;
    while (elem != null) {
        result += elem[prop];
        elem = elem.offsetParent;
    }
    return result;
}

function hideddrivetip(){
    if (DOM||MS||NS){
        ttEnabled=false;
        ttObject.style.visibility="hidden";
        ttObject.style.left="-1000px";
        ttObject.style.backgroundColor='';
        ttObject.style.width='';
    }
}