// Provides setting target attribute of various links in the page body

Ext.onReady(function() {
	var pdfTrack = function(e, t) {
		var link = t.href.replace(new RegExp("https?://[^/]+"), "");
		dcsClickTrack('DCS.dcsuri', link, 'WT.ti', t.title);
	},
	    hasAttribute = function(el, att) {
		// IE7 doesn't support the hasAttribute DOM method, so this is
		// a workaround
		if(typeof el.hasAttribute !== "undefined") {
			return el.hasAttribute(att);
		} else {
			return typeof el[att] !== "undefined";
		}
	};
	Ext.select("a[href]").each(function(e) {
		switch(e.dom.rel) {
		case "localpdf":
			e.addClass("pdf");
			e.on("click", pdfTrack);
			if(! (Ext.isWindows && (Ext.isIE || Ext.isGecko) || Ext.isMac && Ext.isSafari) || hasAttribute(e.dom, "onclick")) {
				// Browser probably does not have built-in
				// PDF support, so don't open the PDF in a
				// new window
				break;
			}
		case "navbreak":
		case "external":
		case "nofollow":
			// Open link in a new window
			e.dom.target = "_blank";
			break;
		}
	});
});

