//CVS:       $Id: external.js,v 1.1.1.1 2011/06/16 23:12:15 cvsdevel Exp $
//Title:     external.js
//Version:   1.02
//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.
 *  1.02  REVIE 2009/09/10  added spellcheck attribute setting for FF.
 * </pre>
 *
 * @author  REVIE
 * @version 1.02
 */

// -----------------------------------------------
//
//  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';
         }
      }

      // for setting "spellcheck" attribute on form inputs
      // (recognized by FF to spell-check text input)
      var inputs = document.getElementsByTagName('input');
      for (var i = 0; i < inputs.length; i++) {
         var classname = inputs[i].getAttribute('class');
         if (classname != null && classname.indexOf('spellcheck') >= 0) {
            inputs[i].spellcheck = 'true';
         }
      }
   }
});

