﻿function WrapExternalLinks()
{
	var restrictedDomains = new Array();
	restrictedDomains.push('highschoolsports.net');
	restrictedDomains.push('eteamz.com');
	restrictedDomains.push('hometeamsonline.com');
	
	var restrictedExpressions = new Array(restrictedDomains.length);
	for(var i = 0; i < restrictedDomains.length; i++)
	{
		restrictedExpressions[i] = new RegExp('^((.*\\.)|)' + restrictedDomains[i].replace('.', '\\.') + '$');
	}
						
    var linkCount = document.links.length;
    var restrictedExpressionsCount = restrictedExpressions.length;
    
    for(var i = 0; i < linkCount; i++)
    {
        var link = document.links[i];
        
        var href = link.href;
        
        var urlExpression = /^(?=[^&])(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;
        var expMatch = href.match(urlExpression);
        var authority = expMatch[2];

		for(var j = 0; j < restrictedExpressionsCount; j++)
		{
            if(authority.match(restrictedExpressions[j]))
            {
        	    link.href = 'javascript:alert(\'You are leaving the Boulder Valley School District site.\'); window.location.href =\'' + href + '\'';
            }
		}
    }
}