// smarttest.js 2008-05-13 JBR

var rootnode;
var isMSIE = ( navigator.appName == "Microsoft Internet Explorer" );

function getHeight() {
	if	( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		return window.innerHeight;
	} else if ( document.documentElement && document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
	} else if ( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		return document.body.clientHeight;
	}
	return 0;
}

function removeAllNodes() {
	var x = rootnode.childNodes;
	var y;
	while ( x.length > 0 ) {
		y = x[ x.length - 1 ];
		rootnode.removeChild( y );
	}
}

function spacedown( n ) {
	var i;
	for ( i = 0; i < n; i++ ) {
		var eleI = document.createElement( 'p' );
		var textI = document.createTextNode( 'INVISIBLE' );
		eleI.style.visibility = 'hidden';
		eleI.appendChild( textI );
		rootnode.appendChild( eleI );
	}
}

function xyzzy() {
	var dummy = 0;
}

function smarttest( lev ) {
	rootnode = document.getElementById( 'tdleft' );
	removeAllNodes();
	if	( lev == 0 ) {
		var ele1 = document.createElement( 'p' );
		ele1.style.textAlign = 'center';
		var text1 = document.createTextNode( 'Click the button below to take the quiz.' );
		ele1.appendChild( text1 );
		rootnode.appendChild( ele1 );

		var divnode = document.createElement( 'center' );
		rootnode.appendChild( divnode );

		if	( isMSIE ) {
			var button1 = document.createElement( 
				'<button onclick="smarttest( 1 );">' );
		} else {
			var button1 = document.createElement( 'button' );
			button1.setAttribute( 'onclick', 'smarttest( 1 );' );
		}
		divnode.appendChild( button1 );

		var text2 = document.createTextNode( "Let's get started!" );
		button1.appendChild( text2 );

		spacedown( 3 );
	//	window.scrollTo( 0, getHeight() );
		return;
	}
	var eleA = document.createElement( 'p' );
	eleA.style.fontWeight = '700';
	var textA = document.createTextNode( 'Question 1: How do you put a giraffe into a refrigerator?' );
	eleA.appendChild( textA );
	rootnode.appendChild( eleA );

	if	( lev == 1 ) {
		var divnode = document.createElement( 'center' );
		rootnode.appendChild( divnode );

		if	( isMSIE ) {
			var button1 = document.createElement( 
				'<button onclick="smarttest( 2 );">' );
		} else {
			var button1 = document.createElement( 'button' );
			button1.setAttribute( 'onclick', 'smarttest( 2 );' );
		}
		divnode.appendChild( button1 );

		var text2 = document.createTextNode( 'Answer' );
		button1.appendChild( text2 );

		spacedown( 3 );
	//	window.scrollTo( 0, getHeight() );
		return;
	}
	var eleB = document.createElement( 'p' );
	eleB.style.marginLeft = '4em';
	eleB.style.marginRight = '4em';
	eleB.style.fontStyle = 'italic';
	var textB = document.createTextNode( 'The correct answer is: Open the refrigerator, put in the giraffe, and close the door. This question tests whether you tend to do simple things in an overly complicated way.' );
	eleB.appendChild( textB );
	rootnode.appendChild( eleB );

	var eleC = document.createElement( 'p' );
	eleC.style.fontWeight = '700';
	var textC = document.createTextNode( 'Question 2: How do you put an elephant into a refrigerator?' );
	eleC.appendChild( textC );
	rootnode.appendChild( eleC );

	if	( lev == 2 ) {
		var divnode = document.createElement( 'center' );
		rootnode.appendChild( divnode );

		if	( isMSIE ) {
			var button1 = document.createElement( 
				'<button onclick="smarttest( 3 );">' );
		} else {
			var button1 = document.createElement( 'button' );
			button1.setAttribute( 'onclick', 'smarttest( 3 );' );
		}
		divnode.appendChild( button1 );

		var text2 = document.createTextNode( 'Answer' );
		button1.appendChild( text2 );

		spacedown( 3 );
	//	window.scrollTo( 0, getHeight() );
		return;
	}
	var eleD = document.createElement( 'p' );
	eleD.style.textAlign = 'center';
	var textD = document.createTextNode( 'Did you say, Open the refrigerator, put in the elephant, and close the refrigerator?' );
	eleD.appendChild( textD );
	rootnode.appendChild( eleD );

	var eleE = document.createElement( 'p' );
	eleE.style.textAlign = 'center';
	var textE = document.createTextNode( 'Wrong Answer!' );
	eleE.appendChild( textE );
	rootnode.appendChild( eleE );

	var eleF = document.createElement( 'p' );
	eleF.style.marginLeft = '4em';
	eleF.style.marginRight = '4em';
	eleF.style.fontStyle = 'italic';
	var textF = document.createTextNode( 'Correct Answer: Open the refrigerator, take out the giraffe, put in the elephant and close the door. This tests your ability to think through the repercussions of your previous actions.' );
	eleF.appendChild( textF );
	rootnode.appendChild( eleF );

	var eleG = document.createElement( 'p' );
	eleG.style.fontWeight = '700';
	var textG = document.createTextNode( 'Question 3: The Lion King is hosting an animal conference. All the animals attend except one. Which animal does not attend?' );
	eleG.appendChild( textG );
	rootnode.appendChild( eleG );

	if	( lev == 3 ) {
		var divnode = document.createElement( 'center' );
		rootnode.appendChild( divnode );

		if	( isMSIE ) {
			var button1 = document.createElement( 
				'<button onclick="smarttest( 4 );">' );
		} else {
			var button1 = document.createElement( 'button' );
			button1.setAttribute( 'onclick', 'smarttest( 4 );' );
		}
		divnode.appendChild( button1 );

		var text2 = document.createTextNode( 'Answer' );
		button1.appendChild( text2 );

		spacedown( 3 );
	//	window.scrollTo( 0, getHeight() );
		return;
	}
	var eleH = document.createElement( 'p' );
	eleH.style.marginLeft = '4em';
	eleH.style.marginRight = '4em';
	eleH.style.fontStyle = 'italic';
	var textH = document.createTextNode( 'Correct Answer: The Elephant. The elephant is in the refrigerator. You just put him in there. This tests your memory.' );
	eleH.appendChild( textH );
	rootnode.appendChild( eleH );

	var eleI = document.createElement( 'p' );
	eleI.style.textAlign = 'center';
	var textI = document.createTextNode( 'Okay, even if you did not answer the first three questions correctly, you still have one more chance to show your true abilities.' );
	eleI.appendChild( textI );
	rootnode.appendChild( eleI );

	var eleJ = document.createElement( 'p' );
	eleJ.style.fontWeight = '700';
	var textJ = document.createTextNode( 'Question 4: There is a river you must cross but it is used by crocodiles, and you do not have a boat. How do you manage it?' );
	eleJ.appendChild( textJ );
	rootnode.appendChild( eleJ );

	if	( lev == 4 ) {
		var divnode = document.createElement( 'center' );
		rootnode.appendChild( divnode );

		if	( isMSIE ) {
			var button1 = document.createElement( 
				'<button onclick="smarttest( 5 );">' );
		} else {
			var button1 = document.createElement( 'button' );
			button1.setAttribute( 'onclick', 'smarttest( 5 );' );
		}
		divnode.appendChild( button1 );

		var text2 = document.createTextNode( 'Answer' );
		button1.appendChild( text2 );

		spacedown( 3 );
	//	window.scrollTo( 0, getHeight() );
		return;
	}
	var eleK = document.createElement( 'p' );
	eleK.style.marginLeft = '4em';
	eleK.style.marginRight = '4em';
	eleK.style.fontStyle = 'italic';

	var textK = document.createTextNode( 'Correct Answer: You jump into the river and swim across. Have you been listening? All the crocodiles are attending the Animal Meeting. This tests whether you learn quickly from your mistakes.' );
	eleK.appendChild( textK );
	rootnode.appendChild( eleK );

	var eleL = document.createElement( 'p' );
	eleL.style.textAlign = 'center';
	var textL = document.createTextNode( "It's been reported that 90% of professional consultants got all questions wrong, but many preschoolers got several correct answers. One could conclude that this shows most professionals do not have the brains of a four-year-old." );
	eleL.appendChild( textL );
	rootnode.appendChild( eleL );

	var eleM = document.createElement( 'p' );
	eleM.style.textAlign = 'center';
	var textM = document.createTextNode( 'Send this out to frustrate all of your smart friends.' );
	eleM.appendChild( textM );
	rootnode.appendChild( eleM );

	spacedown( 3 );
//	window.scrollTo( 0, getHeight() );
}

