// This script checks the value of the form element onblur and displays a message and focus accordingly
function checkAnswer() {
	// Check for an operational DOM
	if(document.getElementById) {
		// set variables
		input = document.getElementById('input');
		feedbackbox = document.getElementById('feedback');
		thenum = input.value;
		// make the text after the form element tabable so the user doesn't jump to the next link or form element (e.g., skip a bunch of stuff when they get it right)
		document.getElementById('aftertext').tabIndex=0;

		if (((thenum / thenum) != 1) && (thenum != 0)) {
			// It's not a number, so set the message and focus
			message = "Please enter only a number into this text box";
			feedbackbox.className = "incorrect";
			feedbackbox.innerHTML = message;
			feedbackbox.setAttribute("role", "alert");
			input.value = '';
			var timer = setTimeout("input.focus()",20);
		}
		else {
			// It's a number, so check value
			if(thenum > 6) {
				// It's too high, so set the message and focus
				message = "Sorry. Try a lower number.";
				feedbackbox.className = "incorrect";
				feedbackbox.innerHTML = message;
				feedbackbox.setAttribute("role", "alert");
				input.value = '';
				var timer = setTimeout("input.focus()",20);
			}
			else if(thenum < 6) {
				// It's too low
				message = "Sorry. Try a higher number.";
				feedbackbox.className = "incorrect";
				feedbackbox.innerHTML = message;
				feedbackbox.setAttribute("role", "alert");
				input.value = '';
				var timer = setTimeout("input.focus()",20);
			}
			else {
				// Correct, so set message and release focus
				message = "You correctly guessed number 6.";
				feedbackbox.className = "correct";
				feedbackbox.innerHTML = message;
				feedbackbox.setAttribute("role", "alert");
			}
		}
	}
}
