    // set 'url' to the location of the nascar-storefront login action
    // production: "https://account.nascar.com/storefront/login.do";
    // var url = "http://tenint1.nascar.com/nascar-storefront-qa/login.do"; <--  QA Url
    var url = "https://account.nascar.com/storefront/login.do";
    
    
    function truncate(value, maxLength)
    {
        if (value != null && value.length > maxLength) {
            value = value.substring(0, maxLength);
        }
        return value;
    }
    
    // Go to the specified offer.
    //    offerID: the ID of the offer to link to
    //    newWindow: open in a new window? if true, a new window will open,
    //               if false, the link will open in the same window.
    function goToOffer(offerID, newWindow, rpcode, mcNotPassed)
    {
        var link = url + "?offerID=" + offerID;
        if (mcNotPassed) {
			var mc = mcNotPassed;
		} else {
			var mc = getMarketingCode(window.location);
		}
        if (mc != null) {
            link += "&mc=" + mc;
        }
        var referID = getReferralID(window.location);
        if (referID != null) {
            link += "&referralId=" + referID;
        }
        var pc = getPartnerCode(window.location);
        if (pc != null) {
            link += "&pc=" + pc;
        }
		if (rpcode) {
			link += "&rpcode=" + rpcode;
		}


        //add link back to purchase/linking page
        //link += "&url=" + escape(window.location);
        
        if (newWindow) {
            window.open(link, "NASCAR");
        }
        else
        {
            window.location = link;
        }
    }

    function goToCouponCode(newWindow)
    {
        var mc = getMarketingCode(window.location);
		var couponCode = getCouponCode(window.location);
		var link = url + "?couponCode=" + couponCode;
        if (mc != null) {
            link += "&mc=" + mc;
        }
        var pc = getPartnerCode(window.location);
        if (pc != null) {
            link += "&pc=" + pc;
        }

        
        //add link back to purchase/linking page
        //link += "&url=" + escape(window.location);
        
        if (newWindow) {
            window.open(link, "NASCAR");
        }
        else
        {
            window.location = link;
        }
    }

    function getMarketingCode(url)
    {
        var regex = /mc=([^&]+)/
        if (regex.test(url)) {
            var matches = regex.exec(url);
            var mc = matches[1];
            return mc;
        }
        else
        {
            return null;
        }
    }

    function getReferralID(url)
    {
        var regex = /referralId=([^&]+)/
        if (regex.test(url)) {
            var matches = regex.exec(url);
            var referId = matches[1];
            return referId;
        }
        else
        {
            return null;
        }
    }


    function getPartnerCode(url)
    {
        var regex = /pc=([^&]+)/
        if (regex.test(url)) {
            var matches = regex.exec(url);
            var pc = matches[1];
            return pc;
        }
        else
        {
            return null;
        }
    }

    
    function getCouponCode(url)
    {
        var regex = /couponCode=([^&]+)/
        if (regex.test(url)) {
            var matches = regex.exec(url);
            return matches[1];
        }
        else
        {
            return null;
        }
    }
    
    function writeHiddenFields()
    {
        var mc = getMarketingCode(window.location);
        if (mc != null) {
            document.write("<input type=\"hidden\" name=\"mc\" value=\"");
            document.write(getMarketingCode(window.location));
            document.write("\">");
        }
        
        document.write("<input type=\"hidden\" name=\"url\" value=\"");
        document.write(window.location);
        document.write("\">");
    }
	


// Redirect to AOL Pages //
function aolRedirect() {
	var baseUrl		= 'http://www.nascar.com';
	var basePath	= '/multimedia/trackpass/landing/'
	var ref 		= document.referrer;
	var aol_site	= (ref.indexOf('.aol.') != -1);
	var agt			= navigator.userAgent.toLowerCase();
	var is_aol		= (agt.indexOf("aol") != -1);
	/*
	if ((is_aol) || (aol_site))
	{
	*/
		var parameter = location.search;	// Grabs "?" + "string"
		if ( location.pathname == (basePath+'aol.html')) {
			location.replace( baseUrl+basePath+'main.html'+parameter );	  // Adds Param (empty or string) //
		} else if ( location.pathname == (basePath+'scanner_aol.html')) {
			location.replace( baseUrl+basePath+'scanner.html'+parameter);
		}
	/*
	}
	*/
}