//  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/


var msg = "";
var tempWindow;
var newTags;
	
// Check to see if answer is valid
function getChoice(whichSelected) {
	var index = 0;
	for (i = 0; i < whichSelected.length; i++) {
		if (whichSelected[i].checked) {
			return i;
		}
	}
	return 0;

}

// Compare form input with correct answer and output response accordingly
function checkAnswer(form, whichQuestion) {

        var optionChosen = getChoice(form.entry);
        
        if ((whichQuestion == 1) && (form.entry[optionChosen].value == "Choice 3") || 
           	(whichQuestion == 2) && (form.entry[optionChosen].value == "Choice 2") ||
          	(whichQuestion == 3) && (form.entry[optionChosen].value == "Choice 3") ||
            (whichQuestion == 4) && (form.entry[optionChosen].value == "Choice 4") ||
            (whichQuestion == 5) && (form.entry[optionChosen].value == "Choice 1")) {
                form.result.value = "Correct!";
        } else {
        	choice = optionChosen+1;
            form.result.value = "Choice " + choice + " is incorrect.  Please try again.";
       	}     
}
	

// Control message in the status bar
function setMsg(msg) {
	window.status = msg;
	return true;
}

// 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 == "numerical_expression") {
		msg = "A" + " <STRONG>numerical expression</STRONG>" + " represents a single value.  It consists of ";
		msg += "one or more numbers and operations.";
	} else {
		if (Def == "algebraic_expression") {
			msg = "An" + " <STRONG>algebraic expression</STRONG>" + " is a mathematical expression that consists of variables, numbers and operations. "; 
			msg += "The value of this expression can change.";
		} 
	}

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
	var newTags = "<HTML><HEAD><TITLE>Definition Window</TITLE></HEAD>";
	newTags += "<BODY BGCOLOR='#FFFFFF'>";
	newTags += "<H2>Definition</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=180,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");

		if (!tempWindow.opener) {
			tempWindow.opener = window;
		}
	
		timerDelay(newTags);
	} else {
		timerDelay(newTags);
	}
	
}

// timer delay
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();
	
}





