// JavaScript Document
function setTarget(targetWindow, link, callback) {
// If no target is given (i.e. "_self" or "_blank",
// assume we want to open the link in the current window
if (targetWindow == undefined) { targetWindow = "_self"; }
// If no link is given, assume we want to apply this to
// ALL links in the document
if (link == undefined) { link = document.links; }
// If we are given a list of links, step through each one
// and set the target for it.
if (link.length) {
for (var i=0; i<link.length; i++) {
// If a callback function was given, run it through the function.
if (callback != undefined && typeof callback == "function") {
if (!callback(link[i].href)) { continue; }
}
setTarget(targetWindow, link[i]);
}
return;
}
// Set the target of the link
link.target = targetWindow;
}
function offsiteLink(url) {
var domain = document.location.host.replace(/^www\./gi, '');
// If there is a slash at the beginning of the link, it's a local link
if (url.match('^/')) { return false; }
// If the URL is on our domain, it's not an offsite link
if (url.match(domain)) { return false; }
// If the URL contains a colon, i.e. "http://example.com", it's offsite
if (url.match(':')) { return true; }
// Otherwise, it's a local link (i.e. "page.html")
return false;
}
function onsiteLink(url) {
return !offsiteLink(url);
}