﻿    String.prototype.trim = function() {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
    String.prototype.replaceAll = function(source,target) {
        return this.replace(new RegExp(source, 'g'), target);
    }

    function externalLinks() {
        if (!document.getElementsByTagName) return;
        var anchors = document.getElementsByTagName("a");

        for (var i=0; i < anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
                anchor.target = "_blank";
        }
    }

    function EditorPopupLinks(editor) {
        var links = editor.get_document().getElementsByTagName("A");
        for (var i = 0; i < links.length; i++) {
            var link = links[i];
            link.setAttribute("target", "#");
        };
    }
    
    function addOnErrorEventHandler(fn) {
        var existingonerror = window.onerror;
        if (typeof window.onerror == 'function') {
            window.onerror = function() {
                existingonerror();
                fn();
            };
        } else {
            window.onerror = fn;
        }
    }

    function FindControl(sourceObj, id, tagName) {
        var items = sourceObj.getElementsByTagName(tagName);
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.id.endsWith(id)) {
                return item;
            }
        }
        return null;
    }
    
    String.prototype.startsWith = function(str){ 
    return (this.indexOf(str) === 0); 
    }

    window.onload = externalLinks;

