function myTooltip(callerId, tooltipId, showOnFocus, type, alignment)
{
	if (callerId == "" || tooltipId == "")
		return;
	var tooltipObj = $(tooltipId);
	var callerObj = $(callerId);
	if (tooltipObj && callerObj)
	{
		callerObj.tooltipObj = tooltipObj;
		callerObj.tooltipObj.iframeObj = null;
		callerObj.tooltipObj.tooltipType = type;
		tooltipObj.className = "TooltipType" + type;
		var Show = function()
		{
			var pos = calcPosition(null, this);
			switch (this.tooltipObj.tooltipType)
			{
				case "1":
					if (alignment == "Right")
						this.tooltipObj.style.left = (pos.Left + this.offsetWidth) + "px";
					else
						this.tooltipObj.style.left = pos.Left + "px";
					this.tooltipObj.style.top = (pos.Top - this.tooltipObj.offsetHeight) + "px";
					break;
				case "2":
					if (alignment == "Left")
						this.tooltipObj.style.left = (pos.Left - this.tooltipObj.offsetWidth) + "px";
					else
						this.tooltipObj.style.left = (pos.Left - this.tooltipObj.offsetWidth + this.offsetWidth) + "px";
						
					this.tooltipObj.style.top = (pos.Top - this.tooltipObj.offsetHeight) + "px";
					break;
				case "3":
					if (alignment == "Right")
						this.tooltipObj.style.left = (pos.Left + this.offsetWidth) + "px";
					else
						this.tooltipObj.style.left = pos.Left + "px";
					this.tooltipObj.style.top = (pos.Top + this.offsetHeight) + "px";
					break;
				case "4":
					if (alignment == "Left")
						this.tooltipObj.style.left = (pos.Left - this.tooltipObj.offsetWidth) + "px";
					else
						this.tooltipObj.style.left = (pos.Left - this.tooltipObj.offsetWidth + this.offsetWidth) + "px";
					this.tooltipObj.style.top = (pos.Top + this.offsetHeight) + "px";
					break;
			}
			if (isIE())
			{
				var insider = getElementsByClassName(this.tooltipObj, "div", "Insider");
				if (insider.length > 0)
				{
					this.tooltipObj.style.width = insider[0].offsetWidth + "px";
					//alert(this.tooltipObj.style.width);
				}
				//iframe
				if (!this.tooltipObj.iframeObj)
				{
					//create one
					var iframe = document.createElement("iframe");
					iframe.src = "javascript:false;";
					iframe.style.position = "absolute";
					iframe.style.visibility = "hidden";
					iframe.style.filter = "alpha(opacity=0)";
					document.body.insertBefore(iframe, document.body.firstChild);
					this.tooltipObj.iframeObj = iframe;
				}
				this.tooltipObj.iframeObj.style.left = this.tooltipObj.style.left;
				this.tooltipObj.iframeObj.style.top = this.tooltipObj.style.top;
				this.tooltipObj.iframeObj.style.width = this.tooltipObj.offsetWidth + "px";
				this.tooltipObj.iframeObj.style.height = this.tooltipObj.offsetHeight + "px";
				this.tooltipObj.iframeObj.style.visibility = "visible";
			}
			this.tooltipObj.style.visibility = "visible";
		}
		var Hide = function()
		{
			this.tooltipObj.style.visibility = "hidden";
			if (this.tooltipObj.iframeObj)
				this.tooltipObj.iframeObj.style.visibility = "hidden";
			this.tooltipObj.style.left = "0";
			this.tooltipObj.style.top = "0";
		}
		
		if (showOnFocus)
		{
			callerObj.onfocus = Show; 
			callerObj.onblur = Hide;
		}else
		{
			callerObj.onmouseover = Show;
			callerObj.onmouseout = Hide;
		}
	}
}
function InitTooltips()
{
	var tooltips = searchElementsByClassName(document, "div", "TooltipType");
	for (var i = 0; i < tooltips.length; i++)
	{
		//get target control id
		var controls = getElementsByClassName(tooltips[i], "input", "tooltipTargetControlId");
		var tooltipType = getElementsByClassName(tooltips[i], "input", "tooltipType");
		var tooltipShowOnFocus = getElementsByClassName(tooltips[i], "input", "tooltipShowOnFocus");
		var tooltipAlignment = getElementsByClassName(tooltips[i], "input", "tooltipAlignment");
		if (tooltipShowOnFocus.length > 0)
		{
			tooltipShowOnFocus = tooltipShowOnFocus[0].value != "";
		}else
			tooltipShowOnFocus = false;
		if (tooltipType.length > 0)
			tooltipType = tooltipType[0].value;
		else
			tooltipType = 1;
		if (tooltipAlignment.length > 0)
			tooltipAlignment = tooltipAlignment[0].value;
		else
			tooltipAlignment = "Default";
		if (controls.length > 0)
			myTooltip(controls[0].value, tooltips[i].id, tooltipShowOnFocus, tooltipType, tooltipAlignment);
	}
}
