// скрипт вывода тултипов
// obj - объектЮ относительно которого позиционируем
// textid - идентификатор текстоволого блока для тултипа
// position - расположение (1 - вверху, 2 - спарва, 3 - снизу, 4 - слева)
// over - перекрытие родительского объекта в пикселях
function ShowTooltip(obj, textid, position, over)
{
	if (obj && textid)
	{
		position = (!position || position == 0) ? 3 : position;
		over = (!over) ? 10 : over;
		var windowX = document.body.scrollWidth;//(document.compatMode == 'CSS1Compat' && !window.opera) ? document.documentElement.clientWidth : document.body.clientWidth;
		var windowY = document.body.scrollHeight;//(document.compatMode =='CSS1Compat' && !window.opera) ? document.documentElement.clientHeight : document.body.clientHeight;
		var left = obj.offsetLeft;
		var top = obj.offsetTop;
		var parent = obj.offsetParent;
		var width = obj.offsetWidth;
		var height = obj.offsetHeight;
		while(parent && parent.tagName != "BODY")
		{
			 left += parent.offsetLeft;
			 top += parent.offsetTop;
			 parent = parent.offsetParent;
		}
		CachObjects['tooltip'].style.display = "block";
		CachObjects['tooltip'].innerHTML = gid(textid)?gid(textid).innerHTML:textid;
		if(CachObjects['tooltip'].offsetWidth>='316') CachObjects['tooltip'].style.width='316';
		//CachObjects['tooltip'].style.width=(CachObjects['tooltip'].offsetWidth>='316')? '316' : CachObjects['tooltip'].offsetWidth;
		var objwidth = CachObjects['tooltip'].offsetWidth;
		var objheight = CachObjects['tooltip'].offsetHeight;
		var bytop = 0;
		var byleft = 0;
		if (position == 1)
		{
			bytop = ((top - objheight + over) < 0) ? bytop : (top - objheight + over);
			//byleft = ((left + over + objwidth) > windowX) ? (windowX - objwidth) : (left + over); убрали, чтобы ровнение шло всегда по краю объекта-родителя
			byleft = ((left + objwidth) > windowX) ? (windowX - objwidth) : (left);
		}
		else if (position == 2)
		{
			//bytop = ((top + over + objheight) > windowY) ? (windowY - objheight) : (top + over); убрали, чтобы ровнение шло всегда по краю объекта-родителя
			bytop = ((top + objheight) > windowY) ? (windowY - objheight) : (top);
			byleft = ((left + width - over) > (windowX - objwidth)) ? (windowX - objwidth) : (left + width - over);
		}
		else if (position == 3)
		{
			bytop = ((top + height - over) > (windowY - objheight)) ? (windowY - objheight) : (top + height - over);
			//byleft = ((left + over + objwidth) > windowX) ? (windowX - objwidth) : (left + over); убрали, чтобы ровнение шло всегда по краю объекта-родителя
			byleft = ((left + objwidth) > windowX) ? (windowX - objwidth) : (left);
		}
		else if (position == 4)
		{
			//bytop = ((top + over + objheight) > windowY) ? (windowY - objheight) : (top + over); убрали, чтобы ровнение шло всегда по краю объекта-родителя
			bytop = ((top + objheight) > windowY) ? (windowY - objheight) : (top);
			byleft = ((left - objwidth + over) < 0) ? byleft : (left - objwidth + over);
		}
		CachObjects['tooltip'].style.left = byleft + "px";
		CachObjects['tooltip'].style.top = bytop + "px";
	}
}

function HideTooltip()
{
	CachObjects['tooltip'].style.display = "none";
}
