var opened_tooltip = "";

function closeToolTip(id)
{
    var tooltip = getObject(id);
    
    if (tooltip.hideTimer)
        clearTimeout(tooltip.hideTimer);
    
    tooltip.hideTimer = setTimeout(function()
    {
        tooltip.style.display = 'none';
        opened_tooltip = "";
    }, 1000);
}

function CloseOpenedTooltip()
{
     var tooltip = getObject(opened_tooltip);
    if (tooltip.hideTimer)
        clearTimeout(tooltip.hideTimer);

     tooltip.style.display = 'none';
     opened_tooltip = "";
}

function GetWindowWidth()
{
      var myWidth = 0;
      if( typeof( window.innerWidth ) == 'number' )
        //Non-IE
        myWidth = window.innerWidth;
      else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
      else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        
      return myWidth;
}

function ShowToolTip(e, id) {
    
    if (opened_tooltip != null && opened_tooltip.length > 0)
        CloseOpenedTooltip();
        
    
    var tooltip = getObject(id);
    
    if (tooltip.hideTimer)
        clearTimeout(tooltip.hideTimer);
    
    var current = getCurrentPosition(e);
    var docWidth = getClientWidth();
    
    //определяем положение всплывающих окон так, чтобы они не выпирали за пределы акна браузера
    var windowWidth = GetWindowWidth();
    
    //отступ всплывающих окошек о правого края 
    var paddingright = 40;
    
    if (windowWidth <= 0 || paddingright + 300 + current.left + 15 < windowWidth)
        tooltip.style.left = current.left + 15;
    else
        tooltip.style.left = windowWidth - paddingright - 300;    
        
    tooltip.style.top = current.top + 30;
    tooltip.style.display = 'block';
    opened_tooltip = id;
}

function showTooltipWithTimer(e) {
    if (e.hideTimer)
        clearTimeout(e.hideTimer);
    
     if (opened_tooltip != null && opened_tooltip.length > 0)
        CloseOpenedTooltip();
        
    e.style.display = 'block';
    
    opened_tooltip = e.getAttribute('Id');
}
