


// Provide a single place to register commands to execute once the page is loaded completely.
// This allows DHTML routines to co-exist and have initialization code be defined internally
// rather than externally in the document's BODY tab. 

// Note: Using this will override the onload command(s) defined in the HTML.
// Instead of using <body onLoad="myFunction();"> use <script>onLoad("myFunction();");</script>
// This will ensure that the command will be executed as well as other commands defined elsewhere.

// Additional note: This process is way simpler than it sounds.  Who knew that something less
// that 10 lines in length could be so useful?

var onLoadCommands = new Array();								// Internal array where commands are stored
var onLoadLastCommands = new Array();							// Internal array where commands are stored to be done last
var onLoadProcessed = false;
// Add a command to be called once the page is loaded
// Takes a string as a parameter -- an executable statement.
// Example: onLoad("alert('test!');");
function onLoad(command) {
	if (!onLoadProcessed) {
		onLoadCommands[onLoadCommands.length] = command;			// Add command to the stack
		window.onload = performOnLoad;								// Make sure the body tag will process the commands
	} else {
		eval(command);	
	}
}

function onLoadLast(command) {
	if (!onLoadProcessed) {
		onLoadLastCommands[onLoadLastCommands.length] = command;	// Add command to the stack
		window.onload = performOnLoad;								// Make sure the body tag will process the commands
	} else {
		eval(command);	
	}
}

// Process all defined commands, called once the page is completely loaded
// This function should probably not be called from anywhere else directly.
function performOnLoad() {
	for (var x=0; x < onLoadCommands.length; x++) {
		eval(onLoadCommands[x]);								// Brendan Eich, thank you for adding the eval command!!!
	}
	for (var x=0; x < onLoadLastCommands.length; x++) {
		eval(onLoadLastCommands[x]);
	}
	onLoadCommands = new Array(); 								// Once done, empty out the arrays.
	onLoadLastCommands = new Array(); 						
	onLoadProcessed = true;
}

