/**
 * Opens certain links in new windows.
 * Adds a target attribute and a warning message to affected links.
 */
JSTarget = function() {
    // Default configuration
    var config = {
        strAtt: 'class', // The attribute to be examined
        strVal: 'new-window', // The value that tells the script that the link should open in a new window
        strWarning: ' (nytt fönster)' // The text that is appended to the link to warn the user that a new window will open
    };
    /**
    * @param {object} props Optional object containing configuration properties in the format
    * {property1:value, property2:value}
    */
    function init(props) {
        if (!document.getElementById || !document.createTextNode) {
            return;
        } // Check for DOM support
        // If any properties were supplied, apply them to the config Object.
        for (var key in props) {
            if (config.hasOwnProperty(key)) {
                config[key] = props[key];
            }
        }
        var oWarning;
        var oLink;
        var arrLinks = document.getElementsByTagName('a');
        var oRegExp = new RegExp("(^|\\s)" + config.strVal + "(\\s|$)");
        for (var i = 0, len = arrLinks.length; i < len; i++) {
            oLink = arrLinks[i];
            // If the attribute is class, check for className
            if ((config.strAtt === 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(config.strAtt)))) {
                oWarning = document.createElement("em");
                oWarning.appendChild(document.createTextNode(config.strWarning));
                oLink.appendChild(oWarning);
                oLink.target = '_blank';
            }
        }
    }
    return {
        init: init
    };
}();
