// Global Definitions ---------------------------------------------------------------------------------------------------------

	// An array of answers.
	var answers = new Array();

// Function Definitions -------------------------------------------------------------------------------------------------------

	/** This method checks the user's answer to a quiz.                                                                     **/
	function checkAnswer (form_id, which)
		{	// Get the form.
			var form = document.getElementById(form_id);

			// The input form was not found.
			if ( !form )
				{	return false;
				}; // if ( !form )

			// Get the user's answer and the correct answer.
			var answer		= getAnswer(which);
			var user_answer	= getUsersAnswer(which);

			// Invalid answer.
			if ( !answer || !user_answer || answer != user_answer )
				{	giveAnswerFocus(form, which);
					setAnswerStatus(which, false);
				} // if ( !answer || !user_answer || answer != user_answer )

			// Correct answer.
			else
				{	enableAnswer(which, false);										
					showAnswer(which);
					setAnswerStatus(which, true);					
				}; // else

			return false;
		}; // function checkAnswer (form_id, which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function enables/disables an answer form.                                                                      **/
	function enableAnswer (which, enable)
		{	// Get the answer input controls.
			var text_field		= getAnswerInput(which);
			var submit_button	= getAnswerSubmitInput(which);

			// Disable/Enable the text field.
			if ( text_field )
				{	//text_field.disabled			= !enable;
					text_field.value			= "";
					text_field.style.display	= enable ? "block" : "none";
				}; // if ( text_field )

			// Disable/Enable the submit button.
			if ( submit_button )
				{	//submit_button.disabled		= !enable;
					submit_button.style.display	= enable ? "block" : "none";
				}; // if ( submit_button)
		}; // function enableAnswer (which, enable)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the nth answer.                                                                               **/
	function getAnswer (which)
		{	return which >= 0 && which < answers.length ? answers[which] : false;
		}; // function getAnswer (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the answer input text field.                                                                  **/
	function getAnswerInput (which)
		{	return getAnswerInputControl("input", "answer_", which);
		}; // function getAnswerInput (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the answer input control.                                                                     **/
	function getAnswerInputControl (tag, id, which)
		{	// Get the input name to look for.
			var input_name = id + which;
			
			// Get the input elements.
			var inputs = document.getElementsByTagName(tag);

			// Now find the element.
			for ( var index = 0; index < inputs.length; index++ )
				{	if ( inputs[index].id == input_name )
						{	return inputs[index];
						}; // if ( inputs[index].id== input_name )
				}; // for ( var index = 0; index < inputs.length; index++ )

			return false;
		}; // function getAnswerInputControl (tag, id, which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the answer status image.                                                                      **/
	function getAnswerStatusInput (which)
		{	return getAnswerInputControl("img", "answer_status_", which);
		}; // function getAnswerStatusInput (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the answer submit button.                                                                     **/
	function getAnswerSubmitInput (which)
		{	return getAnswerInputControl("input", "answer_submit_", which);
		}; // function getAnswerSubmitInput (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function returns the user's answer to the nth question.                                                        **/
	function getUsersAnswer (which)
		{	// Get the input control.
			var input	= getAnswerInput(which);
			input		= input ? input.value : false;

			return input != "" ? input : false;
		}; // function getUsersAnswer (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function gives the specifed answer the input focus.                                                            **/
	function giveAnswerFocus (form, which)
		{	// Get the input control.
			var input	= getAnswerInput(which);
			
			// Give the control the focus.
			if ( input )
				{	input.focus();
				}; // if ( input )
		}; // function giveAnswerFocus (form, which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function hides the answer controls.                                                                             **/
	function hideAnswerControls (which)
		{	// Get the text field and submit buttons.
			var text_field		= getAnswerInput(which);
			var submit_button	= getAnswerSubmitInput(which);

			// Hide the text field.
			if ( text_field )
				{	text_field.style.display = "none";
				}; // if ( text_field )

			// Hide the submit button.
			if ( submit_button )
				{	submit_button.style.display = "none";
				}; // if ( submit_button )
			
			// Get both correct and incorrect icons.
			var correct_icon	= getAnswerInputControl("span", "answer_correct_", which);
			var incorrect_icon	= getAnswerInputControl("span", "answer_incorrect_", which);

			// Toggle the correct status icon on/off depending on value.
			if ( correct_icon )
				{	correct_icon.style.display = "none";
				}; // if ( correct_icon )

			// Toggle the incorrect status icon on/off depending on value.
			if ( incorrect_icon )
				{	incorrect_icon.style.display = "none";
				}; // if ( incorrect_icon )
		}; // function hideAnswerControls (which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function reveals all the answers to the quiz.                                                                  **/
	function revealAnswers ()
		{	// Get all the spans.
			var spans = document.getElementsByTagName("span");

			// Display all with an id set to spelling_(\d+).
			for ( var index = 0; index < spans.length; index++ )
				{	if ( spans[index].id.match(/^spelling_(\d+)$/) )
						{	// Show the spelling.
							spans[index].style.display = "inline";

							// Get the answer id.
							var id	= spans[index].id;
							id		= id.substring(9, id.length);

							// Now hide the answer controls.
							hideAnswerControls(id);
						}; // if ( spans[index].id.match(/^spelling_(\d+)$/) )
				}; // for ( var index = 0; index < spans.length; index++ )

			return false;
		}; // function revealAnswers ()

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function sets the given answer.                                                                                **/
	function setAnswer (answer, which)
		{	answers[which] = answer;
		}; // function setAnswer (answer, which)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function sets the answer status.                                                                               **/
	function setAnswerStatus (which, value)
		{	// Get both correct and incorrect icons.
			var correct_icon	= getAnswerInputControl("span", "answer_correct_", which);
			var incorrect_icon	= getAnswerInputControl("span", "answer_incorrect_", which);

			// Toggle the correct status icon on/off depending on value.
			if ( correct_icon )
				{	correct_icon.style.display = value ? "inline" : "none";
				}; // if ( correct_icon )

			// Toggle the incorrect status icon on/off depending on value.
			if ( incorrect_icon )
				{	incorrect_icon.style.display = value ? "none" : "inline";
				}; // if ( incorrect_icon )
		}; // function setAnswerStatus (which, value)

	// ------------------------------------------------------------------------------------------------------------------------

	/** This function shows the specified answer.                                                                           **/
	function showAnswer (which)
		{	// Get the answer.
			var answer = document.getElementById("spelling_" + which);

			// Found the answer.
			if ( answer )
				{	answer.style.display = "inline";
				}; // if ( answer )
		}; // function revealAnswers ()

