if( typeof g_aRfgCommandQueue   == 'undefined') g_aRfgCommandQueue = new Array();
if( typeof g_bRfgOnLoadComplete == 'undefined') g_bRfgOnLoadComplete = false;

//Window event handlers
if( !window.onload || (window.onload.toString().indexOf( 'RfgOnPageLoad' ) == -1) ) {
   g_pOldOnLoad = window.onload;
   window.onload = RfgOnPageLoad;
}


/*----------------------------------------------------------------------\
| 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.           |
| ****HACKED VERSION**** DO NOT USE                                     |
\----------------------------------------------------------------------*/
function RfgQueueCommand( strEncodedCommand )
{
   var strCommand = null;
   if( typeof strEncodedCommand === "string" ) {
      strCommand = unescape(strEncodedCommand.replace(/\+/g," "));
   } else {
      strCommand = strEncodedCommand;
   }
   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{
	//This is a bad hack, and will not work with the Microsoft mapping services which is where this originates, since the command
	//Is sent to a WEB SERVICE, and round trips to the server and back before being executed.  You can not pass a pointer reference in
	//an XML file.  (sigh) this won't work.
            if(typeof strCmd==="string")
               eval(strCmd);
            else
               strCmd();
      } catch( xE ) {
         //Do not error on user defined code.
      }
   }

   if( g_pOldOnLoad ) g_pOldOnLoad();
}


RfgQueueCommand( function(){alert(myVar);} );


