
var HintLevel=0;
var TimeOut;
var TimeWait = 500;
var closeIvent = '';

// ---------------------------------
// Show hint message
// ---------------------------------

function ShowControlHint(evt, cName, Text, size)
    {
    // Get control
    ShowHint(evt, Text, size);
    }


// ---------------------------------
// Show hint message
// ---------------------------------

function ShowHint(evt,Text,size)
    {

    HideHint();

    var s = document.createElement('DIV');
    s.id = 'hintmes';
    s.style.position = "absolute";
    if(evt.clientX)
        s.style.left = evt.clientX + 15 + document.body.scrollLeft;
    else
        //s.style.left = (GetControlX(evt) + 10) + 'px';

    if(evt.clientY)
        s.style.top = evt.clientY + 15 + document.body.scrollTop;
    else
        //s.style.top = (GetControlY(evt) +  evt.offsetHeight) + 'px';

    if( !parseInt(size) ) s.style.width=400;
    s.innerHTML = Text;

    document.getElementsByTagName('body')[0].appendChild(s);

    if( parseInt(s.offsetHeight) + parseInt(s.style.top) - document.body.scrollTop > document.body.clientHeight) 
        {
        s.style.top = parseInt(document.body.clientHeight)  - s.offsetHeight - 10 + document.body.scrollTop;
        }

    if( parseInt(s.offsetWidth) + parseInt(s.style.left) - document.body.scrollLeft > document.body.clientWidth) 
        {
//        s.style.left = parseInt(document.body.clientWidth)  - s.offsetWidth - 10 + document.body.scrollLeft;
        s.style.left = parseInt(s.style.left) - parseInt(s.offsetWidth)  - 20;
        }
    }

// ---------------------------------
// Hide hint message
// ---------------------------------

function HideHint()
    {

    if(TimeOut)
        {
        clearTimeout(TimeOut);
        }

    var old_s = document.getElementById('hintmes');
    if (old_s)
        {
        old_s.parentNode.removeChild(old_s);            
        }
    }


function CloseHint(doclose)
    {

    if(HintLevel)
        {
        var s = document.getElementById('hintmes');

        if(s)
            {
            var x = parseInt(s.style.left);
            var y = parseInt(s.style.top);

            var w = parseInt(s.offsetWidth)+5;
            var h = parseInt(s.offsetHeight)+5;
            

            if(!doclose && ( (CurrentMousePosX > x - 10) && (CurrentMousePosX < x + w)) && ((CurrentMousePosY > y - 40) && (CurrentMousePosY < y + h)) )
                {
                if(TimeOut)
                    clearTimeout(TimeOut);

                TimeOut = setTimeout('CloseHint();', TimeWait);
                }
            else
                {
                if(closeIvent)
                    eval(closeIvent);
                HideHint();
                HintLevel = 0;
                }
            }
        }
    else
        {
        if(TimeOut)
            clearTimeout(TimeOut);
        }
    }



