////////////////////////////////////////////////////////////////////////
// BackLinkHandler.js
//
// Copyright 2007 CCH, a Wolters Kluwer business.
//
// Intended to recreate the back link functionality as found on other
// pages.  It's a buffering issue.
////////////////////////////////////////////////////////////////////////
function BackLinkHandler( )
{
	var parameterName = "returl";
	var paramList = location.search.split("&");
	var backLink = "";
	
	//////////
	// Check to see if we have a parameter that should force the back link.
	for (var i = 0; i < paramList.length; i++)
	{
		if (paramList[i].substring(0,1) == "?")
		{
			paramList[i] = paramList[i].substring(1);
		}
		if (paramList[i].substring(0, parameterName.length).toLowerCase() == parameterName.toLowerCase())
		{
			/////////
			// Yes, we have a back link specified in the URL.  We should make note of this,
			// and store that value in a cookie that expires in 30 minutes.
			backLink = decodeURIComponent(paramList[i].substring(parameterName.length + 1, paramList[i].length - 1));
			var expDate = new Date();
			expDate.setTime(expDate.getTime() + 1800000);
			document.cookie = parameterName + "=" + encodeURIComponent(backLink) + "; expires=" + expDate.toGMTString() + "; path=/";
			break;
		}
	}
	if (backLink == "")
	{
		/////////
		// We didn't have a parameter in the URL.  It is still possible, though
		// that we have a back link stored in a cookie.  We should check that now.
		var idx = document.cookie.indexOf(parameterName + "=");
		if (idx >= 0)
		{
			//////////
			// Hey, what do you know!  We have a cookie!
			idx += (parameterName.length + 2);
			var endIdx = document.cookie.indexOf(";", idx);
			if (endIdx < 0) endIdx = document.cookie.length;
			backLink = decodeURIComponent(document.cookie.substring(idx, endIdx));
		}
	}
	/////////
	// At this point, we either have a back link or we don't.
	if (backLink != "")
	{
		/////////
		// We have a back link.  Get the proper area that we will need
		// to place the link in, and appendChild.
		var siGradientLeft = document.getElementById("siGradientLeft");
		siGradientLeft.appendChild(document.createTextNode("Return to "));
		var retLink = document.createElement("a");
		retLink.setAttribute("href", backLink);
		retLink.appendChild(document.createTextNode("Previous Site"));
		siGradientLeft.appendChild(retLink);
	}
}
////////////////////////////////////////////////////////////////////////
// Attach the BackLinkHandler function to the window's onload event.
////////////////////////////////////////////////////////////////////////
EventAttacher(window, "load", BackLinkHandler);