var gc_strHideOnlyArg	= "!";
var gc_strShowOnlyArg	= "+";


//	Allow some content to be dynamically hidden,
//	based on a query string argument.
//
function DisplayStuff_Wrapper( arrArgs, oCol)
{
	//	Hide all "illegal" blocks
	//
	try	
	{
		DisplayStuff( arrArgs, oCol );
	}
	catch (e)
	{
		emitEx(e, "Showing / hiding stuff");
	}
}


//	Dynamically hide / show stuff
//
function DisplayStuff( arrArgs, oCol )
{

	//	Args from the query string.
	//
	if (null == arrArgs)
	{
		arrArgs	= GetAllQueryStringArgs();

		//	We want to treat the empty query string
		//	like it has one arg (empty) so people
		//	can specify, for example, to show only on
		//	empty.
		//
		if (0 == arrArgs.length)
			arrArgs.push("");
	}


	//	If one is not specified, then do all!
	//
	if (null == oCol)
		oCol	= document.getElementsByTagName("SPAN");


	//	Check all SPAN elements
	//
	for (var i=0; i<oCol.length; ++i)
	{
		//	We're going to turn this into a true/false string
		//	for evaluation.
		//
		var strTrue	= oCol[i].className;


		//	Do a quick replace, to normalize escaped entities.
		//
		strTrue	= strTrue.replace("&amp;", "&");


		//	Strip out all unknown strings that LOOK like they should be known.
		//
		strTrue	= strTrue.replace( /(^|\|\||\&\&)[\s]*[\w]+[\s]*($|\|\||\&\&)/gi ,   "$1$2");	// undefined, so error out.



		//	If the class name is not empty, then
		//		Check to see if we find a match of the class name
		//		to a query string arg.
		//
		if ("" == strTrue)
			continue;


		//	Looping through querystrings
		//
		for (var j=0; j<arrArgs.length; ++j)
		{
			var strArgValue	= GetQueryStringArg(arrArgs[j], null, document.location.href);

			//	"OFF" flags don't need to be dealt with in this loop.
			//
			if ((null != strArgValue) && ("on" != strArgValue))
				continue;

			//	The arg is ON. 
			//		1. For those elements which require the flag ON, set 'em to true.
			//		2. For those elements which require the flag OFF, set 'em to false.
			//
			var oShowArgReg		= new RegExp("(^|\\&\\&|\\|\\|)[\\s]*\\+" + arrArgs[j] + "[\\s]*($|\\&\\&|\\|\\|)", "gi");
			var oHideArgReg		= new RegExp("(^|\\&\\&|\\|\\|)[\\s]*!"   + arrArgs[j] + "[\\s]*($|\\&\\&|\\|\\|)", "gi");

			strTrue	= strTrue.replace( oShowArgReg, "$1true$2" );
			strTrue	= strTrue.replace( oHideArgReg, "$1false$2" );
		}


		//	The arg is OFF
		//
		strTrue	= strTrue.replace( /(^|\|\||\&\&)[\s]*\+[\w]*[\s]*($|\|\||\&\&)/gi , "$1false$2");	// it was required, but not found
		strTrue	= strTrue.replace( /(^|\|\||\&\&)[\s]*\+[\w]*[\s]*($|\|\||\&\&)/gi , "$1false$2");	// it was required, but not found
		strTrue	= strTrue.replace( /(^|\|\||\&\&)[\s]*\![\w]*[\s]*($|\|\||\&\&)/gi ,  "$1true$2");	// it was not found, cool!

		//	Only change display if we KNOW we can turn off.
		//
		var fShow	= true;
		try
		{
			eval("fShow = " + strTrue);

			if (fShow)
				oCol[i].style.display	= "";
			else
				oCol[i].style.display	= "none";
		}
		catch(ex) 
		{
			emitEx(ex, "Dynamically hiding / showing stuff; trueString = " + strTrue + "; original = " + oCol[i].className);
		}
	}
}
