// so we don't need to include prototype.js
//
//function $(id) {
//    return document.getElementById(id);
//}

// from http://www.dustindiaz.com/seven-togglers/
//
var toggle = {
 show : function(elementID) {
  $('#' + elementID).css('display', '');
  $('#' + elementID).removeAttr('disabled');
 },
 hide : function(elementID) {
  $('#' + elementID).css('display', 'none');
  $('#' + elementID).attr('disabled', true);
 }
};

var toggleList = {
 show : function() {
  for (i=0; i < arguments.length; i++ ) {
   $('#' + arguments[i]).css('display', '');
   $('#' + arguments[i]).removeAttr('disabled');
  }
 },
 hide : function() {
  for (i=0; i < arguments.length; i++ ) {
   $('#' + arguments[i]).css('display', 'none');
   $('#' + arguments[i]).attr('disabled', true);
  }
 }
};

// javascript var_dump
//
// http://snippets.dzone.com/posts/show/4296
//
//
function var_dump(data,addwhitespace,safety,level) {
   var rtrn = '';
   var dt,it,spaces = '';
   if(!level) {level = 1;}
   for(var i=0; i<level; i++) {
      spaces += '   ';
   }//end for i<level
   if(typeof(data) != 'object') {
      dt = data;
      if(typeof(data) == 'string') {
         if(addwhitespace == 'html') {
            dt = dt.replace(/&/g,'&amp;');
            dt = dt.replace(/>/g,'&gt;');
            dt = dt.replace(/</g,'&lt;');
         }//end if addwhitespace == html
         dt = dt.replace(/\"/g,'\"');
         dt = '"' + dt + '"';
      }//end if typeof == string
      if(typeof(data) == 'function' && addwhitespace) {
         dt = new String(dt).replace(/\n/g,"\n"+spaces);
         if(addwhitespace == 'html') {
            dt = dt.replace(/&/g,'&amp;');
            dt = dt.replace(/>/g,'&gt;');
            dt = dt.replace(/</g,'&lt;');
         }//end if addwhitespace == html
      }//end if typeof == function
      if(typeof(data) == 'undefined') {
         dt = 'undefined';
      }//end if typeof == undefined
      if(addwhitespace == 'html') {
         if(typeof(dt) != 'string') {
            dt = new String(dt);
         }//end typeof != string
         dt = dt.replace(/ /g,"&nbsp;").replace(/\n/g,"<br>");
      }//end if addwhitespace == html
      return dt;
   }//end if typeof != object && != array
   for (var x in data) {
      if(safety && (level > safety)) {
         dt = '*RECURSION*';
      } else {
         try {
            dt = var_dump(data[x],addwhitespace,safety,level+1);
         } catch (e) {continue;}
      }//end if-else level > safety
      it = var_dump(x,addwhitespace,safety,level+1);
      rtrn += it + ':' + dt + ',';
      if(addwhitespace) {
         rtrn += '\n'+spaces;
      }//end if addwhitespace
   }//end for...in
   if(addwhitespace) {
      rtrn = '{\n' + spaces + rtrn.substr(0,rtrn.length-(2+(level*3))) + '\n' + spaces.substr(0,spaces.length-3) + '}';
   } else {
      rtrn = '{' + rtrn.substr(0,rtrn.length-1) + '}';
   }//end if-else addwhitespace
   if(addwhitespace == 'html') {
      rtrn = rtrn.replace(/ /g,"&nbsp;").replace(/\n/g,"<br>");
   }//end if addwhitespace == html
   return rtrn;
}//end function var_dump

// runOnLoad.js: portable registration for onload event handlers.
// from Flanagan - Javascript, the Definitive Guide, 5th ed
//
// This module defines a single runOnLoad( ) function for portably registering
// functions that can be safely invoked only when the document is fully loaded
// and the DOM is available.
//
// Functions registered with runOnLoad( ) will not be passed any arguments when
// invoked. They will not be invoked as a method of any meaningful object, and
// the this keyword should not be used. Functions registered with runOnLoad( )
// will be invoked in the order in which they were registered. There is no
// way to deregister a function once it has been passed to runOnLoad( ).
//
// In old browsers that do not support addEventListener( ) or attachEvent( ),
// this function relies on the DOM Level 0 window.onload property and will not
// work correctly when used in documents that set the onload attribute
// of their <body> or <frameset> tags.
//
function runOnLoad(f) {
 if (runOnLoad.loaded) f( );    // If already loaded, just invoke f( ) now.
 else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run( ) more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad( ) to register another function.
runOnLoad.run = function( ) {
 if (runOnLoad.loaded) return;  // If we've already run, do nothing

 for(var i = 0; i < runOnLoad.funcs.length; i++) {
  //alert('firing ' + runOnLoad.funcs[i]);
  try { runOnLoad.funcs[i]( ); }
  catch(e) { /* An exception in one function shouldn't stop the rest */ }
 }
 
 runOnLoad.loaded = true; // Remember that we've already run once.
 delete runOnLoad.funcs;  // But don't remember the functions themselves.
 delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run( ) as the onload event handler 
// for the window
if (window.addEventListener)
 window.addEventListener("load", runOnLoad.run, false);
 //Handler.add(window, 'load', runOnLoad.run);
else if (window.attachEvent) 
 window.attachEvent("onload", runOnLoad.run);
 //Handler.add(window, 'onload', runOnLoad.run);
else window.onload = runOnLoad.run;


