//CVS:       $Id: external.js,v 1.1.1.1 2010/05/10 20:44:12 cvsdevel Exp $
//Title:     external.js
//Version:   1.01
//Copyright: Copyright (c) 2008
//Author:    REVIE
//Company:   Rhino Internet

/**
 * Utility library which parses the DOM tree and points all anchor tags
 * within the tree and marked with a rel="external" tag to open in a
 * new window.  Created to provide XHTML-strict compatability.
 * <p>
 * Original version of functionality provided by
 * <a href="http://www.sitepoint.com/article/standards-compliant-world/"
 *    rel="external">SitePoint</a>.
 *
 * <p>
 * <b>Changelog:</b><pre>
 *  1.00  REVIE 2006/10/31  created.
 *  1.01  REVIE 2008/06/24  added addLoadEvent() to improve onload handling.
 * </pre>
 *
 * @author  REVIE
 * @version 1.01
 */

// -----------------------------------------------
//
//  main methods
//

/**
 * Adds the selected function to the list of functions designated to
 * run once the page loads.
 *
 * @param func the function to be executed on page load.
 */
function addLoadEvent(func) {
   var oldonload = window.onload;
   if (typeof func != 'function') {
      //alert('Invalid: ' + func + ' [' + typeof func + ']');
   } else if (typeof window.onload != 'function') {
      window.onload = func;
   } else {
      window.onload = function() {
         if (typeof oldonload == 'function') {
            oldonload();
         }
         func();
      }
   }
} // addLoadEvent

addLoadEvent(function() {
   if (document.getElementsByTagName) {
      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';
         }
      }
   }
});

