
//Tests whether 'link' begins with http://(www.)domain. Needn't pass the www., or the .com or .org (though these will narrow the match down).
function linkIsToDomain(link, domain) {
	var re = new RegExp("^http://((www.)|)"+domain, "i"); //i=case insensitive
	return re.test(link);
}

//Add the openInNewWindow function, and an icon to the onclick event of external links
function insertNewWindowLinks() {
// Check that the browser is DOM compliant and not home page
	if (document.getElementById && document.createElement && document.appendChild && typeof(homepage) == 'undefined') {
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i].href;
			if (linkIsToDomain(link, "") && //tests that the link is absolute
				!linkIsToDomain(link, "dl.screenaustralia") && 
				!linkIsToDomain(link, "dev.fawebmin.webfactional") && 
				!linkIsToDomain(link, "staging.fawebmin.webfactional") && 
				!linkIsToDomain(link, "prod.fawebmin.webfactional") && 
				!linkIsToDomain(link, "ether")) {
				// Create an img element containing the new window warning text and insert it after the link text
				links[i].title = links[i].title + " (new window)";
				links[i].onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

window.addEvent('load', insertNewWindowLinks);