        function newWin_addEvent(obj, type, fn) {
            if (obj.attachEvent) {
                obj['e' + type + fn] = fn;
                obj[type + fn] = function() { obj['e'+type+fn](window.event); }
                obj.attachEvent('on' + type, obj[type + fn]);
            } else
                obj.addEventListener(type, fn, false);
        }
        function newWinLinks(){
           var thishost = location.hostname;
           var links = document.getElementsByTagName('A');
           for( i=0; i<links.length; i++ ) {

              // don't check remaining conditions where rel="media" or rel="external",
              // this is a manually forced action:
              linkExtension = links[i].href.substr(links[i].href.lastIndexOf('.'), links[i].href.length);
              
              if( (links[i].rel!='media') && (links[i].rel!='external') && (linkExtension!='.pdf') ){
                
                
                 //retrieve the hostname part of the url:
                 linkHostname = links[i].hostname.substr(0, links[i].hostname.indexOf(':'));

                 //some browsers ignore the protocol, so double check here:
                 if( linkHostname=='' ){
                    linkHostname=links[i].hostname; //back to original state.
                 }

                 // integrity check for rel settings - older safari versions seem to need it:
                 if( (links[i].rel!='media') && (links[i].rel!="external") ) {
                    // conditional checks go here - matching these conditions meens same window:
                    // hostname is unretrievable - shouldn't be encountered but prevents possible
                    // error on next condition...
                    if( linkHostname=='' ) {
                       continue;
                    }
                    else if( linkHostname==thishost ) { // if this is the same domain no new window.
                       continue;
                    }
                    else if( links[i].protocol=='mailto:' ) { // don't add new window link for mailto links.
                       continue;
                    }
                    else if( links[i].rel=='alternate' ) { // don't add new window links for alternate versions (same page)
                       continue;
                    }
                    else if( links[i].rel=='internal' ) { // manual force no new window link
                       continue;
                    }
                    
                    
                 }
              }

              //If we've got this far we are ready to make the current link open in a new window:
              links[i].target='_blank';

              //Give the link a tooltip (or append existing one):
              if( links[i].title!='' ) {
                 links[i].title += ' (opens in a new window)';
              }
              else {
                 links[i].title = 'opens in a new window';
              }

              //Add the "new window" icon to the end of the link - but only if the anchor doesn't contain an image already:
              if( links[i].getElementsByTagName('IMG').length<=0 ) {
                 var img = document.createElement("img");
                     
                 img.setAttribute( "src", "style/images/newwinlink.png" );
                     
                 img.setAttribute( "alt", "(opens in a new window)" );
                 img.style.verticalAlign = "middle";
                     
                 links[i].appendChild( img );
              }

           } //end for() through links.
        } //end func newWinLinks.

        //This function gets called as soon as this JS file is sourced in the HTML head - but it creates a window.onload() function that then calls the above function:
        newWin_addEvent(window, 'load', newWinLinks);
