/***
 * multicastDelegate
 *    Creates a new function that calls both parameter functions if they exist.
 *    This is useful to assign multiple functions to the window's onload event.
 *
 * Example: window.onload = multicastDelegate(window.onload, init);
 *
 * @param func1 the first function to call
 * @param func2 the second function to call
 *
 * @return a new function that calls func1 and func2 in sequence.
 ***/
function multicastDelegate(func1, func2)
{
   return function() {
      if (func1) { func1(); }
      if (func2) { func2(); }
   };
} // end multicastDelegate


/***
 * addOnLoad
 *    Adds a function to the window.onload event.
 *
 * @param func the function to add
 ***/
function addOnLoad(func)
{
   window.onload = multicastDelegate(window.onload, func);
} // end addOnLoad


/***
 * keyPress
 *    Executes a postback when the Enter key is pressed in a form control.  If
 *    the callback parameter is specified, then it is executed instead of the
 *    postback.
 *
 * @param id the ID of the control
 * @param evt the event handler
 * @param callback an optional, parameterless callback function to execute
 *
 * @return true, if the pressed key was not the Enter key; false, otherwise.
 ***/
function keyPress(id, evt, callback)
{
   if (evt.which || evt.keyCode) {
      if (evt.which == 13 || evt.keyCode == 13) {
         if (callback) {
            evt.returnValue = callback();
         } else {
            __doPostBack(id, '')         
            evt.returnValue = false;
         }
      }
   }
   return evt.returnValue;
}