/* Questions show/hide CSS toy

Don't forget to define qCount as a global var - this is the
number of questions on the page. This fails nice and gracefully
if JavaScript is not enabled too :o)
*/

function layerExists(whichLayer) {
	/* Not used but this may be useful as some point... :o)
	*/
	var l;

	if (document.getElementById)
		l = document.getElementById(whichLayer);
	else if (document.all)
		l = document.all[whichLayer];
	else if (document.layers)
		l = document.layers[whichLayer];

	return (l != null);
}

function doShowLayer(whichLayer, show)
{
/* Kindly offered by http://www.netlobo.com/div_hiding.html
Subsequently modified by Jon H / BBB
Not sure why, but if this is called showLayer, it causes probs? erk...!
*/
var showStr = show? "block":"";

if (!layerExists(whichLayer)) alert('Argh, layer ' + whichLayer + ' does not exist!');

if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
if (show)
	style2.display = style2.display? "":showStr;
else
	style2.display = showStr;
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}

// Wrapper to make it easier to refer to toggleLayer
function toggleLayerInt(intLayer) {
	for(var i=1; i<=qCount; i++)
		if(i != intLayer) doShowLayer('a' + i, false);
	doShowLayer('a' + intLayer, true);
}

// This is a custom bit to write show/hide things
function writeToggler(myDate, intQuestion) {
	var strClass = 'smalltext';
	
	document.write('<p class="' + strClass + '">');
	document.write('Added ' + myDate + ' [');
	document.write('<a href="javascript:toggleLayerInt(');
		document.write(intQuestion);
	document.write(');" ');
	document.write('title="Show the answer to question ' + intQuestion + '">');
		document.write('Show/hide answer');
	document.write('</a>]');
	document.write('</p>');
}

function defineHideCss(className, strCss) {

	document.writeln('<style>');
	document.writeln('<!--');
	for(i=1; i<=qCount; i++) {
		document.write('div#' + className + i);
		if (i<qCount) document.write(', ');
	}
	document.writeln('{ display: none; ' + strCss + ' }');
	document.writeln('-->');
	document.writeln('</style>');
}

