
// *** health points stuff
theHealthInputBoxStr = "<input type = 'text' size = 20 value = '' name = 'healthInput' onkeypress='{if (event.keyCode==13) parent.middle.processHealthResponse()}'><input type='text' name='d1' style = 'visibility: hidden; width: 1' width = 1>";

var theAnsH1 = "";
var healthLotto = 1;

function dealWithHealthVial() {
healthLotto = pickOne(1,2);
if (healthLotto == 1) doDerivInterpretation();
else doFunctionOfxPlusH()
} // dealWithHealthVial



function doFunctionOfxPlusH() {
if (numHealths <= maxNumHealths) {
	numHealths += 1;
	var theString = "<table><tr><td align = left><class style = '{ font-family: Arial; font-weight: bold; color: blue;font-size: 14px;font-style: italic;}'>Need health?</class><br>";
		var theCoeff = pickOne("2","3","-2","-3");
		var theConstant = pickOne(" + 2", " - 5", " + 1", " - 3");
		var theHealthFunctions = ['<td nowrap><center>1<br><img src = ' + quoteMark + 'SYMB/FR.GIF' + quoteMark + ' height = 1 width =100%><br>' + theCoeff + '<i>x</i>' + theConstant + '</center></td>', '<td nowrap><center><i>x</i>' + theConstant + '<br><img src = ' + quoteMark + 'SYMB/FR.GIF' + quoteMark + ' height = 1 width =100%><br>' + theCoeff + '<i>x</i><sup>2</sup>' + theConstant + '</center></td>', '<td nowrap>2<sup><i>' + theCoeff + 'x</i></sup></td>'];

var theAns = ['1/(' + theCoeff + '*(x+h)' + theConstant + ')', '(x+h' + theConstant + ')/(' + theCoeff + '*(x+h)^2' + theConstant + ')', '2^(' + theCoeff + '(x+h))'];
var theChoice = randomInt(0,2);
theAnsH1 = theAns[theChoice];
theString += "<form name = health1>If<center><table><tr><td><i>f</i>(<i>x</i>) =</td>" + theHealthFunctions[theChoice] + "</tr></table></center>Then <i>f</i>(<i>x</i>+<i>h</i>) equals <br>" + theHealthInputBoxStr + "<p><i>Enter 'undefined' if the derivative does not exist.</form>";


	parent.left.document.getElementById("message").innerHTML = theString;
	parent.left.document.health1.healthInput.focus();
	} // if numHealths <= maxNumHealths

} // doFunctionOfxPlusH




function doDerivInterpretation() {

if (numHealths <= maxNumHealths) {
	numHealths += 1;
	var theString = "<table><tr><td align = left><class style = '{ font-family: Arial; font-weight: bold; color: blue;font-size: 14px;font-style: italic;}'>Need health?</class><br>";

		var theHealthWords = ["is horizontal","is vertical","is inclined at 45 degrees","is declined at 45 degrees","rises 2 units per unit increase of <i>x</i>","drops 2 units per unit increase of <i>x</i>","rises 1 unit per 2-unit increase of <i>x</i>","drops 1 unit per 2-unit increase of <i>x</i>"];
var theAns = ["0","undefined","1","-1","2","-2","1/2","-1/2"];
var theChoice = randomInt(0,7);
theAnsH1 = theAns[theChoice];
theString += "<form name = health1>If the tangent line to the graph of <i>f</i> at <i>x</i> = 2 is " + theHealthWords[theChoice] + ", then <i>f</i><font face = " + quoteMark + "Courier" + quoteMark + ">'</font>(2) equals <br>" + theHealthInputBoxStr + "<p><i>Enter 'undefined' if the derivative does not exist.</form>";


	parent.left.document.getElementById("message").innerHTML = theString;
	parent.left.document.health1.healthInput.focus();
	} // if numHealths <= maxNumHealths

} // doDerivInterpretation



function processHealthResponse() {
if (healthLotto == 1) {
	var uu = 0;
	var inPut = parent.left.document.health1.healthInput.value; 
		try {
			var answerIn = stripSpaces(inPut);
			if (answerIn == '') uu = 0;
			else if (answerIn.toLowerCase() == theAnsH1) uu = 1;
			else if (parseFloat(answerIn) == parseFloat(theAnsH1)) uu = 1;
			else uu = 6;
			}
		catch(error) {
			uu = 6;
			}
	if (uu == 1) {
			beep(5);
			health += 20;
			writeBottomSmile('Your health has increased by 20 points.',2);	
			showMeters();
			}
	else if (uu == 0) {}
	else writeBottomWrong ("Nope. Sorry. No health points earned. The correct answer was " + theAnsH1.toString());
	} //Lotto = 1

	else {
		var uu = 0;
		var inPut = parent.left.document.health1.healthInput.value;
		try {
			var answerIn = stripSpaces(inPut); 
			if (answerIn == '') uu = 0;
			else {
				h = 2.5;x = 1.73;
				var HCorrVal = myEval(theAnsH1);
				var HAnsIn = myEval(answerIn); 
				if (Math.abs(HCorrVal - HAnsIn) <= .0005) uu = 1;
				else uu = 6;
				}
			}
		catch(error) {
			uu = 6;
			}

		if (uu == 1) {
			beep(5);
			health += 20;
			writeBottomSmile('Your health has increased by 20 points.',2);	
			showMeters();
			}
		else if (uu == 0) {}
		else writeBottomWrong ("Nope. Sorry. No health points earned. The correct answer was " + theAnsH1.toString());
	}//Lotto = 2

} // processHealthResponse

