//  Copyright 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 124 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 fraction in the ANSWER BOX before clicking ENTER.";
		noErrors = false;
	    } 
	
	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 == "3/5") || 
            (whichQuestion == 2 && stringEntered == "5/8") ||
            (whichQuestion == 3 && stringEntered == "1/6") ||
			  (whichQuestion == 4 && stringEntered == "3/7") ||
            (whichQuestion == 5 && stringEntered == "7/8")) { 
                form.result.value = "Correct!";
        } else {
            form.result.value = "Incorrect. Please press CLEAR and try again.";
        }                     
        form.entry.focus();
        form.entry.select();
}


var msg = "";
var tempWindow;
var newTags;



// 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();
}


// if second window is open, then close it
function closeSecondWindow() {
	if (tempWindow && !tempWindow.closed) {
		tempWindow.close();
	tempWindow = false;
	return tempWindow;
	}
}


// Determine which definition will be displayed in the second window
function whichDef(Def) {
				if (Def == "fraction_bar") {
					msg = "A" + " <STRONG>fraction bar</STRONG>" + " separates the numerator and denominator of a fraction.  It indicates "; 
					msg += "that a division of the numerator by the denominator will be performed.  Another name for a fraction bar is a ";
					msg += "vinculum.";
					} else {
					 	if (Def == "multiple") {
							msg = "A" + " <STRONG>multiple</STRONG>" + " of a number is the product of that number and any other whole number."; 
						}
					}
return msg;
}

// This function opens a small window that contains a Math definition.
function popUpWindow(definition) {
	passDef = definition;
	whichDef(passDef);
	// assemble HTML for new window
	newTags = "<HTML><HEAD><TITLE>Definition Window</TITLE></HEAD>";
	newTags += "<BODY BGCOLOR='#FFFFFF'>";
	newTags += "<H2>Definition Window</H2>";
	newTags += msg + "<P>";
	newTags += "<form><input TYPE='button' value='close window' name='closeup' onClick='opener.closeSecondWindow()'></form>";
	newTags += "</BODY></HTML>";
	
	
	if (!tempWindow || tempWindow.closed) {
		tempWindow = window.open ("temp.html","tempWindow", "toolbar=no,width=500,height=200,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");

		if (!tempWindow.opener) {
			tempWindow.opener = window;
		}
	
		timerDelay(newTags);
	} else {
		timerDelay(newTags);
	}
	
}

function timerDelay(content) {
	getContent	= content;
	setTimeout("timerDelay",1000);
	
	
	// write HTML to second window
	tempWindow.document.write(getContent);
	tempWindow.document.close(); // end of writing to the Temp window
	tempWindow.focus();
	
}


function changeme()
{
document.getElementById("b1").innerHTML= "three-fifths";
}
function restoreme()
{
document.getElementById("b1").innerHTML= "answer 1"; 
}

function changeme2()
{
document.getElementById("b2").innerHTML= "two-sevenths";
}
function restoreme2()
{
document.getElementById("b2").innerHTML= "answer 2"; 
}

function changeme3()
{
document.getElementById("b3").innerHTML= "five-sixths";
}
function restoreme3()
{
document.getElementById("b3").innerHTML= "answer 3"; 
}

function changeme4()
{
document.getElementById("b4").innerHTML= "three-eighths";
}
function restoreme4()
{
document.getElementById("b4").innerHTML= "answer 4"; 
}








