// =============================================================================

// 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 != "") {



		// 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

	}



}



function ASCify2(theLink,defaultASC) {



	// 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 == "") {

		asc = defaultASC;

	}



	// Generate string to be appended to the link

	var append = "";

	if (theLink.href.indexOf("?") == -1){

		append = (theLink.href.indexOf("%3F") != -1) ? "&" : "?";

	}else{

		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



}



function grabASC(theFormId,defaultASC) {

	var theURL = document.location.href;



	// Get ASC value from querystring

	var asc = "";

	var qs = '';

	if(theURL.indexOf("?") != -1){

		qs = theURL.substring((theURL.indexOf("?")+1),theURL.length);

	}

	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 == "") {

		asc = defaultASC;

	}



	// Generate string to be appended to the link

	var form = document.getElementById(theFormId);

	form.ASC.value = asc;



}



function submitform(theFormId)

{

	var form = document.getElementById(theFormId);

	form.submit();

}
