isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isMSIE=document.all && document.all.item //Microsoft Internet Explorer 4+
isNetscape4=document.layers //Netscape 4.*
isOpera=window.opera //Opera
isOpera5=isOpera && isDOM //Opera 5+
isMSIE5=isDOM && isMSIE && !isOpera //MSIE 5+
isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera

var obj;

function getLayer(layerName, parentLayerName){
  if(isDOM){ return document.getElementById(layerName); }
  if(isMSIE){ return document.all[layerName]; }
  if(isNetscape4){ return eval('document.layers[layerName]'); }
  return false;
}

function getEventPos(evnt){
        var ex, ey;
        if (!evnt) {
                evnt = window.event;
        }
        if (evnt) {
                ex=evnt.clientX;
                ey=evnt.clientY;
        }
        return {x:ex,y:ey};
}

function ts(e,what){
    mousex = e.clientX;
    mousey = e.clientY;
    pagexoff = 0;
    pageyoff = 0;
    if ( isMSIE5 ){
        pagexoff = document.body.scrollLeft;
        pageyoff = document.body.scrollTop;
    } else {
        pagexoff = window.pageXOffset;
        pageyoff = window.pageYOffset;
    }    
    if ( getLayer( what ) ){
        if ( isNetscape4 ){
            obj = getLayer(what);
        } else {
            obj = getLayer(what).style;
        }

        if ( obj ){
            leftoff = mousex-pagexoff;
            obj.left= (mousex+pagexoff);

            topoff  = mousey-pageyoff;
            obj.top = (mousey+pageyoff) + 20;

            var cc = getEventPos(e);
            var dw = parseInt(document.body.clientWidth);
            var dh = parseInt(document.body.clientHeight);
            //alert( document.getElementById( what ).style.width );
            
            // Определяем ширину и высоту подсказки
            var tipWidth = obj.width;
            var tipHeight =  obj.height;
            
            // Если они пустые, то выставляем значения по-молчанию            
            if ( tipWidth == "" ){
              tipWidth = 200;
            } else {
              tipWidth = tipWidth.slice(0,-2)*1;
            }
            
            if ( tipHeight == "" ){
              tipHeight = 50;
            } else { // Иначе нам нужны цифры              
              tipHeight = tipHeight.slice(0,-2)*1;
            }
            
            if ( (dw>0) && (cc.x+10+tipWidth>dw)){
              var psn = dw - ( tipWidth + 10 );
              //alert( "cc.x='"+cc.x+"'\npsn = '"+psn+"'" );
              if ( cc.x > psn ){
                obj.left = cc.x - ( tipWidth + 15 );
              } else {
                obj.left = psn;
              }
            } else {
              obj.left = cc.x+10;
            }
            
            if ( (dh>0) && (cc.y+20+tipHeight>dh) ){
                    var sT = document.getElementById( 'body' ).scrollTop;
                    obj.top = sT + dh - ( tipHeight + 20 );
                    //alert( "windowTop = '"+document.getElementById( 'body' ).scrollTop+"'\ndisplayHeight (dh) = '"+dh+"'\ntipHeight = '"+tipHeight+"'"+"\ncursorHeight (cc.y) = '"+cc.y+"'\ndivObjectTop (obj.top) = '"+obj.top+"'");
            }  
            //alert( "obj.left = '"+obj.left+"';\nobj.top = '"+obj.top+"';" );
            if ( isNetscape4 ){
              obj.visibility = 'show';
            } else {
              obj.visibility = 'visible';
            }
        }
    }
    return true;
}

function tc(){
  if(obj){
    if(isNetscape4)
      obj.visibility = 'hide';
    else
      obj.visibility='hidden';
  }
  return true
}