﻿/// <reference path="jquery-1.5-vsdoc.js" />
function initExternalLinkTracking() {
	$("#ColumnRight, #ColumnLeft, #FooterContainer").delegate("a", "click", function () {
		var href = $(this).attr("href");
		if (trackableHref(href)) {
			recordOutboundLinkLabeled("OutboundLink", href, "Footer Outbound Link");

			if (useFrame(href)) {
				//href = escape(href.replace("http://", ""));
				//href = encodeURI(href);

				var pathName = window.location.pathname;
				var title = document.title;
				$(this).attr("href", "/Frame.aspx?l=" + href + "&r=" + pathName + "&t=" + title);
			}
		}
	});

}

function checkExternalLink(href) {
	if (trackableHref(href)) {
		recordOutboundLinkLabeled("OutboundLink", href, "Footer Outbound Link");
	}

	if (useFrame(href)) {
		//href = escape(href.replace("http://", ""));
		//href = encodeURI(href);

		var pathName = window.location.pathname;
		var title = document.title;
		window.open("/Frame.aspx?l={0}&r={1}&t={2}".format(href, pathName, title));
	}
	else {
		window.open(href);
	}
}

function trackableHref(href) {
	if (href.indexOf("http") >= 0
			      && (locationOrigin == "" || href.indexOf(locationOrigin) < 0 || href.indexOf(".pdf") > 0)
                && href.indexOf("javascript:") < 0) {
		return true;
	} else {
		return false;
	}
}

function useFrame(href) {
	if (href.toLowerCase().indexOf("shop.jacklinks.com") < 0
               && href.toLowerCase().indexOf("youtube.com") < 0
			   && href.toLowerCase().indexOf("sponsorwise.com") < 0
			   && href.toLowerCase().indexOf("facebook.com") < 0
               && href.toLowerCase().indexOf("Frame.aspx") < 0
               ) {
		return true;
	} else {
		return false;
	}
}
