function catchExternalLinks()
{
    var extClassName = 'external';  // the class to set for external links
    var defClassName = 'defSearch'; // the class to set for definition searches

    if (document.links && document.getElementById)
    {
        // 'www.domain.tld' and 'domain.tld' are considered the same
        var h  = window.location.host;
        var hx = (h.substr(0, 4) != 'www.') ? h : h.substr(4) ;
        h  = window.location.protocol + '//' + h;
        hx = window.location.protocol + '//' + hx;
        var l = document.links;
        for (var i = 0; i < l.length; i++)
        {
            var target = l[i].href.toLowerCase();
            if (target.substr(0, 11) != 'javascript:') // only work on links that aren't JavaScript directives
            {
                // tag external links
                if ( // neither 'www.domain.tld' nor 'domain.tld'
                    target.substr(0, h.length).indexOf(h) == -1
                    &&
                    target.substr(0, hx.length).indexOf(hx) == -1
                   )
                {
                    l[i].className += ' ' + extClassName;
                }

                // tag Google definition search links
                if (l[i].childNodes[0]) // does this link have a text node for anchor text?
                {
                    var anchor = l[i].childNodes[0].nodeValue;
                }
                var s = '?q=define:' + anchor;
                if (target.substr(0, target.length).indexOf(s) != -1)
                {
                    l[i].className += ' ' + defClassName;
                    l[i].title = 'Definitions for ' + anchor + ' on the Web.';
                }
            }
        }
    }
}
window.onload = catchExternalLinks;
