//Window event handlers
var g_pOldOnLoad = window.onload;
window.onload = RfgOnPageLoad;

//Globals
var g_aRfgCommandQueue = new Array();
var g_bRfgOnLoadComplete = false;

/*----------------------------------------------------------------------\
| FUNCTION:    RfgQueueCommand                                          |
| RETURNS:     N/A                                                      |
| PARAMETERS:  Command text to later execute.                           |
| PURPOSE:     Requests a command be executed after the page has fully  |
|              loaded, or if the page is already loaded, now.           |
\----------------------------------------------------------------------*/
function RfgQueueCommand( strEncodedCommand )
{
   var strCommand = unescape(strEncodedCommand.replace(/\+/g," "));
   if( !g_bRfgOnLoadComplete ) {
      g_aRfgCommandQueue.push( strCommand );
   } else {
      eval( strCommand );
   }
}

/*----------------------------------------------------------------------\
| FUNCTION:    RfgOnPageLoad                                            |
| RETURNS:     N/A                                                      |
| PARAMETERS:  N/A                                                      |
| PURPOSE:     Internal document.onload handler -- saves previous       |
|              onload events and fires them after our onload events are |
|              complete.                                                |
\----------------------------------------------------------------------*/
function RfgOnPageLoad()
{
   g_bRfgOnLoadComplete = true;
   while( g_aRfgCommandQueue.length > 0 ) {
      var strCmd = g_aRfgCommandQueue.shift();
      try{
         eval(strCmd);
      } catch( xE ) {
         //Do not error on user defined code.
      }
   }

   if( g_pOldOnLoad ) g_pOldOnLoad();
}


