// =============================================================================
// Shared Landing Page Enabler
// Version: 1.0.0
// =============================================================================

// -----------------------------------------------------------------------------
// Appends ASC obtained from the querystring to the given link in order to
// propagate the ASC.
// Note: IE6 workaround has been commented out since it breaks IE on the Mac
// -----------------------------------------------------------------------------
function ASCify(theLink) {

	// Get ASC value from querystring
	var asc = "";
	var qs = location.search.replace(/^\?/, "");
	var pairs = qs.split("&");
	for (var i=0; i<pairs.length; i++) {
		var namevalue = pairs[i].split("=", 2);
		var name = unescape(namevalue[0]);
		var value = unescape(namevalue[1]);
		if (name == "ASC") {
			asc = value;
			break;
		}
	}

	// Nothing to append if ASC not available
	if (asc == "") {
		return;
	}

	// Generate string to be appended to the link
	var append = (theLink.href.indexOf("?") != -1) ? "&" : "?";
	append += "ASC=" + asc;

	// Append querystring to link
	//var saveHTML = theLink.innerHTML;    // Workaround bug in IE6 that sometimes erroneously modifies innerText/innerHTML whenever href is modified if innerText starts with www.something
	theLink.href += append;
	theLink.href = theLink.href.replace(/(#.*)(\?.*)$/, "$2$1"); // Move hash (if any) to the end
	//theLink.innerHTML = saveHTML;        // Workaround bug in IE6 that sometimes erroneously modifies innerText/innerHTML whenever href is modified if innerText starts with www.something

}
