/*
	module name: fnc_createContainer.js
	date: Thursday, March 27, 2009
	version: 1.0
	author: Jay Dansand (jay.dansand@gmail.com) for Lawrence University ITS
	purpose:
		Create a DIV with a unique ID, to become a container for JavaScript or Flash-derived data.
	configuration:
		None.
	usage:
		createContainer(div, base)
				div - if a string, either the ID of the destination DIV or the name of the DIV
					to be made.
					- if a number, a new DIV will be created with ID = "base#", where # is the
					next available index after [div], inclusive.
						Example: [div] = 4 means base4, base5, base6, etc. will be tried until
						an available ID (does not already exist) is found.
					- if undefined, same as above but [div] is treated as 0.
					***NOTE*** If any of the above result in the creation of a new DIV, this MUST
						happen BEFORE the document finishes loading, and the calling script scope MUST
						be within the document body.
					- if an object, this is considered the actual destination DIV.  Unlike all
						of the above options, this is the only safe method to use if the document
						has already been loaded, or the calling function is outside the document body.
				base - optional string for base name of DIV if div parameter is number or undefined (see above).
			Returns false on error, otherwise the DIV created.
*/
function createContainer(div, base)
{
	if (!base) base = "GenericContainer";
	if (div == null) div = 0;
	try
	{
		switch (typeof(div))
		{ //This switch unrolls in a very specific manner, do not insert breaks or change the order
			case "undefined": //If no kind of DIV handle was passed
				div = 0; //Start at index 0 and fall-through to the number-based ID generator
			case "number": //If an index was passed instead, try making an index base# element
				for (var i = div, div = base + div; document.getElementById(div); div = base + (++i))
					; //do nothing, we're just iterating until we get an opening
				//fall-through to the string-based DIV creator
			case "string": //A name has been given, see if it exists, create it not
				var d = document.getElementById(div);
				if (d) div = d; //If a so-named DIV exists, use it
				else
				{ //Otherwise, create it
					document.writeln("<div id=\"" + div + "\"></div>");
					div = document.getElementById(div);
				}
				//fall-through to the object-exists-based setup
			case "object":
				return div;
			default: //Don't do anything if we have nothing to go on (bogus input)
				break;
		}
	}
	catch (e) { }
	return false;
};

