/*
* Function used to get elements which have a certain classname. The classname does not have to be
* the only classname an object has.
*/

document.getElementsWithExternalRel = function () {
        var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e;
        var re = new RegExp('^external$'); // '(^|\\s)external(\\s|$)'
 
        do {
                e = s[i];
 
                while (e) {
                        /* Element nodes only */
                        if (e.nodeType == 1) {
                                if (e.rel && re.test(e.rel)) r[l++] = e;
 
                                s[i++] = e.firstChild;
                        }
 
                        e = e.nextSibling;
                }
        }
 
        while (i--);
 
        return r;
}
 
/*
* Open a certain URL in a new window. If a popup blocker prevents this the link is opened in the
* current window.
*/
function fnDOM1Open( event ) {
        if ( window.event ) {
                var shiftKey = window.event.shiftKey;
        } else {
                var shiftKey = event.shiftKey;
        }
 
        if ( !shiftKey ) {
                var strURL = this.href;
                var oNewWindow = window.open( strURL );
 
                if ( !oNewWindow ) {
                        window.location.href = strURL;
                }
 
                return false;
        } else {
                return true;
        }
}
 
/*
* Assign an onclick event handler to all links having the classname "newWindow"
*/
function fnAssignPopupLinks() {
        var aAnchorList  = document.getElementsWithExternalRel();
        i               = aAnchorList.length;
 
        while (i--) {
                oAnchor  = aAnchorList[i];
 
                if ( oAnchor.href ) {
                        oAnchor.onclick = fnDOM1Open; // DOM level 1 approach
                }
        }
}
