//CVS:       $Id: external.js,v 1.3 2009/10/28 21:48:06 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';
         }
      }
   }
});


/**
 * PHP print_r functionality
 */
function dump(arr,level) {
   var dumped_text = "";
   if(!level) level = 0;

   //The padding given at the beginning of the line.
   var level_padding = "";
   for(var j=0;j<level+1;j++) level_padding += "    ";

   if(typeof(arr) == 'object') { //Array/Hashes/Objects
      for(var item in arr) {
         var value = arr[item];
 
         if(typeof(value) == 'object') { //If it is an array,
            dumped_text += level_padding + "'" + item + "' ...\n";
            dumped_text += dump(value,level+1);
         } else {
            dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
         }
      }
   } else { //Stings/Chars/Numbers etc.
      dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
   }
   return dumped_text;
}