function RadInputHint(parent, skin)
{
	this.textBox = parent;
	this.skin = skin;
}

RadInputHint.prototype.Show = function(currentChunk, selectionRect)
{
	if (currentChunk)
	{
		var rect = this.GetRect(this.textBox.field);
		this.Container = document.createElement("div");
		
		if (currentChunk.ShowHint(this.Container))
		{
			this.Container.className = "radHint_" + this.skin;
			document.body.appendChild(this.Container);
			this.Container.style.position = "absolute";
			
			if (selectionRect)
			{
				this.Container.style.left = selectionRect.left + this.BodyScrollWidth() + "px";
				this.Container.style.top = rect.Y + rect.Height + "px";
			}
			else
			{
				this.Container.style.left = rect.X + "px";
				this.Container.style.top = rect.Y + rect.Height + "px";
			}			
			this.CreateOverlay();
			this.textBox.OnShowHint(this);
		}else
		{
			this.Container = null;
		}
	}
}

RadInputHint.prototype.HideOverlay = function()
{
	if (this.shim)
	{
		this.shim.style.visibility = "hidden";
	}
}

RadInputHint.prototype.CreateOverlay = function()
{
	if (window.opera)
	{
		return;
	}
	
	if (!this.shim)
	{
		this.shim = document.createElement("IFRAME");
		this.shim.src="javascript:false;";
		this.shim.frameBorder = 0;
		this.shim.id = this.Container.parentNode.id + "Overlay";
		this.shim.style.position = "absolute";
		this.shim.style.visibility = "hidden";		
		this.shim.style.border = "1px solid red";
		this.shim.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
		this.shim.allowTransparency = false;
		this.Container.parentNode.insertBefore(this.shim, this.Container);
    }
	var rect = this.GetRect(this.Container);
	this.shim.style.cssText = this.Container.style.cssText;
	this.shim.style.left = rect.X + "px";
	this.shim.style.top = rect.Y + "px";
	this.shim.style.width = rect.Width + "px";
	this.shim.style.height = rect.Height + "px";
    this.shim.style.visibility = "visible";
}

RadInputHint.prototype.FindScrollPosX = function (node)
{
	var x = 0;
	var currentElement = node;
	while (currentElement.parentNode && currentElement.parentNode.tagName != "BODY")
	{		
		if (typeof(currentElement.parentNode.scrollLeft) == "number")
		{
			x += currentElement.parentNode.scrollLeft;
		}
		currentElement = currentElement.parentNode;
	}

	return x;
};

RadInputHint.prototype.FindScrollPosY = function (node)
{
	var y = 0;
	var currentElement = node;

	while (currentElement.parentNode && currentElement.parentNode.tagName != "BODY")
	{		
		if (typeof(currentElement.parentNode.scrollTop) == "number")
		{			
			y += currentElement.parentNode.scrollTop;
		}
		currentElement = currentElement.parentNode;
	}
	return y;
};

RadInputHint.prototype.BodyScrollWidth = function()
{
	var width = 0;
	if (typeof(document.body.scrollLeft) == "number")
	{
		width += document.body.scrollLeft;
	}
	if (typeof(document.documentElement.scrollLeft) == "number")
	{
		width += document.documentElement.scrollLeft;
	}
	return width;

}

RadInputHint.prototype.BodyScrollHeight = function()
{
	var height = 0;
	
	if (typeof(document.body.scrollTop) == "number")
	{
		height += document.body.scrollTop;
	}
	if (typeof(document.documentElement.scrollTop) == "number")
	{
		height += document.documentElement.scrollTop;
	}
	return height;
}

RadInputHint.prototype.FindScrollPosXOpera = function (node)
{
	var x = 0;
	var currentElement = node;
	while (currentElement.offsetParent && currentElement.offsetParent.tagName != "BODY")
	{		
		if (typeof(currentElement.offsetParent.scrollLeft) == "number")
		{
			x += currentElement.offsetParent.scrollLeft;
		}
		currentElement = currentElement.offsetParent;
	}

	return x;
};

RadInputHint.prototype.FindScrollPosYOpera = function (node)
{
	var y = 0;
	var currentElement = node;

	while (currentElement.offsetParent && currentElement.offsetParent.tagName != "BODY")
	{		
		if (typeof(currentElement.offsetParent.scrollTop) == "number")
		{			
			y += currentElement.offsetParent.scrollTop;
		}
		currentElement = currentElement.offsetParent;
	}
	return y;
};

RadInputHint.prototype.Hide = function()
{
	if (this.Container)
	{
		this.HideOverlay();
		this.Container.parentNode.removeChild(this.Container);
		this.Container = null;
	}
}

RadInputHint.prototype.GetRect = function(element)
{
	var width = element.offsetWidth;
	var height = element.offsetHeight;
	
	var x = 0;
	var y = 0;
	var node = element;
	
	while (node.offsetParent)
	{
		x += node.offsetLeft;
		y += node.offsetTop;
		node = node.offsetParent;
	}
	var offsetX = 0;
	var offsetY = 0;
		
	if (window.opera)
	{
		x -= this.FindScrollPosXOpera(element);
		y -= this.FindScrollPosYOpera(element); 
	}
	else
	{
		x -= this.FindScrollPosX(element);
		y -= this.FindScrollPosY(element);
		
	}
	return {X : x, Y : y, Width : width, Height : height};
}

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

