//  Copyright 2000-2010 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 135 of our lessons off line by visiting:
//  http://www.mathgoodies.com/cd/


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++) {
			if (isNaN(testZero))  {
				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 == "125") || 
        	(whichQuestion == 1 && stringEntered == "125.0") || 
            (whichQuestion == 2 && stringEntered == "19") || 
            (whichQuestion == 2 && stringEntered == "19.0") || 
            (whichQuestion == 3 && stringEntered == "135") ||
            (whichQuestion == 3 && stringEntered == "135.0") ||
            (whichQuestion == 4 && stringEntered == "123") ||
            (whichQuestion == 4 && stringEntered == "123.0") ||
            (whichQuestion == 5 && stringEntered == "9.00") || 
            (whichQuestion == 5 && stringEntered == "9") ||          
            (whichQuestion == 6 && stringEntered == "810") ||
            (whichQuestion == 6 && stringEntered == "810.0") ||
            (whichQuestion == 7 && stringEntered == "91") ||
            (whichQuestion == 7 && stringEntered == "91.0") ||
            (whichQuestion == 8 && stringEntered == "89") ||
            (whichQuestion == 8 && stringEntered == "89.0") ||
            (whichQuestion == 9 && stringEntered == "8") ||
            (whichQuestion == 9 && stringEntered == "8.0") ||
            (whichQuestion == 10 && stringEntered == "2.715")) {
                form.result.value = "Correct!";
        } else {        
            	form.result.value = "Incorrect.  Please press CLEAR and try again.";
        }                   
        form.entry.focus();
        form.entry.select();
}

// Clear a form
function clearForm(form) {
	form.entry.value="";
	form.entry.focus();
    form.entry.select();
}


