﻿function ExternalLinks()
{
    this.aContainer = new Array();
}

ExternalLinks.prototype.addContainer = function(sContainerId)
{
    this.aContainer.push(sContainerId);
}

ExternalLinks.prototype.execute = function()
{
    var _this = this;
    $(this.aContainer).each
    (
        function(i)
        {
            $("a", "#" + this).each
            (
                function()
                {
                    var sHref = $(this).attr("href");
                    if (_this.checkPathForExternalUrl(sHref))
                    {
                        $(this).attr("target", "_blank");
                    }
                }
            )
        }
    )
}

ExternalLinks.prototype.checkPathForExternalUrl = function(sHref)
{
    var _this = this;
    var rgMatch = sHref.match(/\b(https?|ftps?):\/\/([\-A-Z0-9.]+)(\/[\-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/im);

    if (rgMatch != null)
    {
        // it is an external link
        if (rgMatch[2].indexOf("nhlpa.com") < 0)
        {
            return true;
        }
    }
    return false;
}