xOffset = -235;
yOffset = 10;
enableTip = false;
try
{
	if (document.getElementById("tooltip") != null)
		tipFrame = self;
	else if (parent.document.getElementById("tooltip") != null)
		tipFrame = parent;
	else if (parent.parent.document.getElementById("tooltip") != null)
		tipFrame = parent.parent;
	else if (window.opener.document.getElementById("tooltip") != null)
		tipFrame = window.opener;
	else if (window.opener.parent.document.getElementById("tooltip") != null)
		tipFrame = window.opener.parent;
	toolTip = tipFrame.document.getElementById("tooltip");
}
catch(err)
{
}

function showTip(FText,FWidth)
{
if (browserName() == "MacIE")
	return false;
if (!isWhitespace(FText))
{
	toolTip.innerHTML = FText;
	if (typeof FWidth != "undefined")
	{
		toolTip.style.width = FWidth + "px";
		if (toolTip.scrollWidth > FWidth)
			toolTip.style.width = (toolTip.scrollWidth) + "px";
	}
	enableTip = true;
}
return false;
}

function ajaxInfoWindow(FURL,FWidth,FHeight)
{
if (FURL.indexOf("?") == -1)
	ajaxURL = FURL + "?PopupWindow=";
else
	ajaxURL = FURL + "&PopupWindow=";
if (browserName() == "MacIE")
{
	ajaxURL += "True";
	window.open(ajaxURL,"ajaxpopup","width=" + FWidth + ",height=" + FHeight + ",top=20,left=20,screenX=20,screenY=20,scrollbars,resizable");
}
else
{
	ajaxURL += "False";
	ajaxText = ajaxCall(ajaxURL,false);
	showInfoWindow(ajaxText,FWidth);
	showInfoWindow(ajaxText,FWidth);
	return ajaxText;
}
return null;
}

function showInfoWindow(FText,FWidth)
{
if (!isWhitespace(FText))
{
	userBrowser = browserName();
	curX = 20 + tipFrame.document.body.scrollLeft;
	curY = 20 + tipFrame.document.body.scrollTop;
	try
	{
		infoWindow = tipFrame.document.getElementById("tooltip");
	}
	catch(err)
	{
		return;
	}
	infoWindow.style.left = curX + "px";
	infoWindow.style.top = curY + "px";
	infoWindow.innerHTML = FText;
	if (typeof FWidth != "undefined")
	{
		infoWindow.style.width = FWidth + "px";
		if ((infoWindow.scrollWidth) > FWidth)
			infoWindow.style.width = (infoWindow.scrollWidth) + "px";
	}
	if (userBrowser != "IE")
	{
		infoWindow.style.height = "1px"; //reset to get accurate scrollHeight	
		infoWindow.style.height = (infoWindow.scrollHeight) + "px";
	}
	infoWindow.style.visibility = "visible";
}
}

function saveAjaxResponseToCache(FName, FAjaxResponse)
{
	var cacheElement = tipFrame.document.getElementById(FName);
	if (!cacheElement)
	{
		cacheElement = tipFrame.document.createElement("input");
		cacheElement.setAttribute("type", "hidden");
		cacheElement.setAttribute("id", FName);
		cacheElement.setAttribute("name", FName);
		tipFrame.document.body.appendChild(cacheElement);
	}
	cacheElement.setAttribute("value", FAjaxResponse);
}

function clearAjaxResponseCache(FName)
{
	var cacheElement = tipFrame.document.getElementById(FName);
	if (cacheElement)
	{
		var parentElement = cacheElement.parentNode;
		if (parentElement)
		{
			parentElement.removeChild(cacheElement);
		}
	}
}

function relaunchInfoWindow(FURL, FCacheName, FWidth, FHeight)
{
	var cacheElement = tipFrame.document.getElementById(FCacheName);
	if (cacheElement)
	{
		showInfoWindow(cacheElement.value,FWidth);
	}
	else
	{
		var ajaxResponse = ajaxInfoWindow(FURL,FWidth,FHeight);
		saveAjaxResponseToCache(FCacheName, ajaxResponse);
	}
}

function resetCouponActivation()
{
	clearAjaxResponseCache("CouponActivationCache");
}

function showCouponActivation(FCouponCode)
{
	var couponCode = FCouponCode;
	if(couponCode == null || couponCode == "")
	{
		couponCode = document.getElementById("StandardCouponNumber").innerHTML;
	}
	if(couponCode == null || couponCode == "")
	{
		couponCode = document.getElementById("ShippingCouponNumber").innerHTML;
	}
	relaunchInfoWindow("activate_coupon.asp?IsValid=True&CouponNumber=" + couponCode, "CouponActivationCache", 400, 250);
	startCouponCountDown();
}

function positionTip(e)
{
userBrowser = browserName();
if (enableTip)
{
	if (userBrowser == "IE" || userBrowser == "Opera")
	{
		curX = event.clientX + top.document.body.scrollLeft;
		curY = event.clientY + top.document.body.scrollTop;
	}
	else
	{
		curX = e.clientX;
		curY = e.clientY;
		if (userBrowser == "Safari")
		{
			curX -= window.scrollX;
			curY -= window.scrollY;
		}
	}
	if (parent.frames[0] && parent.frames[0] != self)
	{
		try
		{
			curX += parseInt(parent.document.getElementById("MainFrame").width);
		}
		catch(err)
		{
			return;
		}
	}
	tipWidth = toolTip.offsetWidth;
	tipHeight = toolTip.offsetHeight;

	leftEdge = curX + xOffset;
	rightEdge = curX + xOffset + tipWidth;
	topEdge = curY + yOffset;
	bottomEdge = curY + yOffset + tipHeight;

	if (userBrowser == "IE")
	{
		windowWidth = top.document.body.clientWidth;
		windowHeight = top.document.body.clientHeight;
	}
	else
	{
		windowWidth = top.window.innerWidth;
		windowHeight = top.window.innerHeight;
	}

	if (leftEdge < 0)
		toolTip.style.left = "5px";
	else if (rightEdge > windowWidth)
		toolTip.style.left = (windowWidth - tipWidth - 20) + "px";
	else
		toolTip.style.left = leftEdge + "px";
	if ((parseInt(toolTip.style.left) + tipWidth + 5) < curX)
		toolTip.style.left = (curX - tipWidth - 5) + "px";

	if (bottomEdge > windowHeight)
	{
		if ((curY - yOffset - tipHeight) > 0)
			toolTip.style.top = (curY - yOffset - tipHeight) + "px";
		else
		{
			toolTip.style.top = "0px";
			leftEdge = parseInt(toolTip.style.left);
			rightEdge = leftEdge + tipWidth;
			if (leftEdge <= curX && rightEdge >= curX)
			{
				if ((curX - 5 - tipWidth) > 0)
					toolTip.style.left = (curX - 5 - tipWidth) + "px";
				else
					toolTip.style.left = (curX + 5) + "px";
			}
		}
	}
	else
		toolTip.style.top = topEdge + "px";

	toolTip.style.visibility = "visible";
}
}

function hideTip()
{
if (browserName() == "MacIE")
	return false;
enableTip = false;
toolTip.style.visibility = "hidden";
toolTip.style.left = "-1000px";
toolTip.style.backgroundColor = "";
toolTip.style.width = "";
return false;
}

document.onmousemove = positionTip;
