//  Copyright 2009 Gisele Glosser.  All Rights Reserved.
//
//  Our interactive math lessons are shareware. You may use our free demo lessons
//  on mathgoodies.com only.  You may NOT download nor save them. You can purchase
//  a license to use all 124 of our lessons off line by visiting:
//  http://www.mathgoodies.com/cd/

var msg = "";
var tempWindow;
var newTags;

// Check to see if answer is valid
function checkData(form, whichQuestion) {
	var msg;
	var noErrors = true;
	var testValue = form.entry.value;
	var testChar = "";
	var testZero = "";
	var i = 0;
	var temp = "false";
	if (testValue == "" || testValue == null) {
		msg = "Please enter a number in the ANSWER BOX before clicking ENTER.";
		noErrors = false;
	} else {
		testZero = testValue.toString();
		for (i = 0; i < testZero.length; i++) {
				testChar = testZero.charAt(i);
				if (i == 0 && testChar == "-" && testValue != "-")  {
					msg = "Please enter a positive number.";
					noErrors = false;
					break;
					
					} else {
						temp = parseFloat(testChar);
						if (isNaN(temp) && testValue == ".")  {
							msg = "Please enter a number.";
							noErrors = false;
							break;
						} else {
							if (isNaN(temp) && testChar != ".") {
								msg = "Please enter a number.";
								noErrors = false;
								break;
							}
					}
				}
			}		
	}
	if (noErrors) {
			checkAnswer(form, whichQuestion);
	} else {
			alert(msg);
			form.entry.focus();
			form.entry.select();
	}
}
	
// Compare form input with correct answer and output response accordingly
function checkAnswer(form, whichQuestion) {
        var stringEntered = form.entry.value;
        if ((whichQuestion == 1 && stringEntered == 9.1) || 
            (whichQuestion == 2 && stringEntered == 35.7) || 
            (whichQuestion == 3 && stringEntered == 18) ||
            (whichQuestion == 4 && stringEntered == 7.4) ||
            (whichQuestion == 5 && stringEntered == 28)) {
                form.result.value = "Correct!";
        } else {
            form.result.value = "Incorrect.  Please press CLEAR and try again.";
        }                     
        form.entry.focus();
        form.entry.select();
}	

// Control message in the status bar
function setMsg(msg) {
	window.status = msg;
	return true;
}

// Clear a form
function clearForm(form) {
	form.entry.value="";
	form.entry.focus();
    form.entry.select();
}


