var score1a = 0;
var score1b = 0;
var score1c = 0;
var score2a1 = 0;
var score2a2 = 0;
var score2b1 = 0;
var score2b2 = 0;
var score2c1 = 0;
var score2c2 = 0;
var score2a = 0;
var score2b = 0;
var score2c = 0;

var score = 0;
var counter = 0;
var imagespacer = 0;

//the following code from slopesj.htm, to next comment

var whichgraph = 0;

function Line(ImageNum)
{
   whichgraph = ImageNum;
   document.slopes.src = LineImg[ImageNum].src;
}

	var LineImg = new Array();
	LineImg[0] = new Image();
	LineImg[0].src = "images/line113.gif";
	LineImg[1] = new Image();
	LineImg[1].src = "images/line101.gif";
	LineImg[2] = new Image();
	LineImg[2].src = "images/line102.gif";
	LineImg[3] = new Image();
	LineImg[3].src = "images/line103.gif";
	LineImg[4] = new Image();
	LineImg[4].src = "images/line104.gif";
	LineImg[5] = new Image();
	LineImg[5].src = "images/line105.gif";
	LineImg[6] = new Image();
	LineImg[6].src = "images/line106.gif";
	LineImg[7] = new Image();
	LineImg[7].src = "images/line107.gif";
	LineImg[8] = new Image();
	LineImg[8].src = "images/line108.gif";
	LineImg[9] = new Image();
	LineImg[9].src = "images/line109.gif";
	LineImg[10] = new Image();
	LineImg[10].src = "images/line110.gif";
	LineImg[11] = new Image();
	LineImg[11].src = "images/line111.gif";
	LineImg[12] = new Image();
	LineImg[12].src = "images/line112.gif";
	LineImg[13] = new Image();
	LineImg[13].src = "images/line113.gif";
	LineImg[14] = new Image();
	LineImg[14].src = "images/line114.gif";
	LineImg[15] = new Image();
	LineImg[15].src = "images/line115.gif";
	LineImg[16] = new Image();
	LineImg[16].src = "images/line116.gif";
	LineImg[17] = new Image();
	LineImg[17].src = "images/line117.gif";
	LineImg[18] = new Image();
	LineImg[18].src = "images/line118.gif";
	LineImg[19] = new Image();
	LineImg[19].src = "images/line119.gif";
	LineImg[20] = new Image();
	LineImg[20].src = "images/line120.gif";
	LineImg[21] = new Image();
	LineImg[21].src = "images/line121.gif";
	LineImg[22] = new Image();
	LineImg[22].src = "images/line122.gif"; 
	LineImg[23] = new Image();
	LineImg[23].src = "images/line123.gif";
	LineImg[24] = new Image();
	LineImg[24].src = "images/line124.gif";
	LineImg[25] = new Image();
	LineImg[25].src = "images/line125.gif";
	LineImg[26] = new Image();
	LineImg[26].src = "images/line126.gif";
	LineImg[27] = new Image();
	LineImg[27].src = "images/line127.gif";
	LineImg[28] = new Image();
	LineImg[28].src = "images/line128.gif";

//the above code from slopesj.htm, from previous comment

whichbrowser = navigator.appName;   //identify browser.. this device is no longer needed, but was to be used to deliver different pages depending upon which browser was used by the client
	Ver = parseInt(navigator.appVersion);

		if (whichbrowser == "Netscape")
			imagespacer = 1;
	else
		if (whichbrowser == "Microsoft Internet Explorer")
			imagespacer = 2;
	else
		if (whichbrowser == "Firefox")
			imagespacer = 3;
	else
		imagespacer = 0;

function TestStudentName(form) {

        Ctrl = form.name;

        if (Ctrl.value == "") {

                validatePrompt (Ctrl, "Enter your name at the top of this test")

                return (false);

        } else

                return (true);

}

function TestEmailAddress(form) {

	Ctrl = form.email;

	if ((Ctrl.value.length > 5) && (Ctrl.value.indexOf ('@', 0) > -1)){

		return (true);

		// the following mechanism for modifying the sender address was replaced in 2002 by a server script "mailquiz.pl"

		//} else

		//if ((Ctrl.value.length > 5) && (Ctrl.value.indexOf ('@', 0) > -1)){

		//        form.mailto.value = form.mailto.value + "," + Ctrl.value;

		//        return (true);

	} else

		validatePrompt (Ctrl, "Enter your complete email address, including the symbol @ and whatever follows")

		return (false);

}

function TestStudentID(form) {

        Ctrl = form.StudentID;

        if (Ctrl.value.length < 7) {

                validatePrompt (Ctrl, "Please enter your 7-digit student ID")

                return (false);

        } else

                return (true);

}

function Test1(form) {

	Ctrla = form.quiz1_1a1;
	Ctrlb = form.quiz1_1a2;
	Ctrlc = form.quiz1_1c1;
	Ctrld = form.quiz1_1c2;

	if (Ctrla.value == ""){

		validatePrompt (Ctrla, "Please enter the first number in problem 1a");

		return (false);

	} else

	if (Ctrlb.value == ""){

		validatePrompt (Ctrlb, "Please enter the second number in problem 1a");

		return (false);

	} else

	if (Ctrlc.value == ""){

		validatePrompt (Ctrlc, "Please enter the first number in problem 1b");

		return (false);

	} else

	if (Ctrld.value == ""){

		validatePrompt (Ctrld, "Please enter the second number in problem 1b");

		return (false);

	} else

		return (true);

}

function Test2(form) {

	Ctrla = form.quiz1_2a2;
	Ctrlb = form.quiz1_2b2;
	Ctrlc = form.quiz1_2c2;

	if (Ctrla.value == ""){

		validatePrompt (Ctrla, "Please enter the amount Lara paid in problem [2a]");

		return (false);

	} else

	if (Ctrla.value.indexOf (',', 0) > -1){

		validatePrompt (Ctrla, "Please re-write your answer to problem [2a] without using a comma. For example, write 23456 rather than 23,456");

		return (false);

	} else

	if (Ctrlb.value == ""){

		validatePrompt (Ctrlb, "Please enter the amount the bank pays to Ace Rentals in problem 2b");

		return (false);

	} else

	if (Ctrlc.value == ""){

		validatePrompt (Ctrlc, "Please enter Chris' monthly payment in problem 2c");

		return (false);

	} else

		return (true);

} 

function PartScore1a(form)
{
	Ctrla = form.quiz1_1a1;
	Ctrlb = form.quiz1_1a2;

	if ((((Ctrla.value - 0.5)*(Ctrla.value - 0.5) < 0.0001) || (Ctrla.value == "1/2")) && (Ctrlb.value - (-20))*(Ctrlb.value - (-20)) < 0.01){ // javascript would not correctly interpret  "+ 20" but would accept "- (-20)"

		score1a = 2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

	else

	if ((((Ctrla.value - 0.5)*(Ctrla.value - 0.5) < 0.0001) || (Ctrla.value == "1/2")) || (Ctrlb.value - (-20))*(Ctrlb.value - (-20)) < 0.01){ // javascript would not correctly interpret  "+ 20" but would accept "- (-20)"

		score1a = 1;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

	}

	else

		score1a = 0;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

}

function PartScore1b(form)
{
	if (whichgraph == "19"){

		score1b = 1;
		score1 = score1a + score1b + score1c;
		score = score1a + score1b + score1c + score2a + score2b + score2c;
	}

	else

	score1b = 0;
	score1 = score1a + score1b + score1c;
	score = score1a + score1b + score1c + score2a + score2b + score2c;
}

function PartScore1c(form)
{

	Ctrla = form.quiz1_1c1;
	Ctrlb = form.quiz1_1c2;

	if (((Ctrla.value - (-2))*(Ctrla.value - (-2)) < 0.001) && ((Ctrlb.value - 4)*(Ctrlb.value - 4) < 0.08)){ // javascript would not correctly interpret  "+ 2" but would accept "- (-2)"

		ProblemScore = 2;
		score1c = ProblemScore;
		score = score1a + score1b + score1c + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

	else

	if (((Ctrla.value - (-2))*(Ctrla.value - (-2)) < 0.001) || ((Ctrlb.value - 4)*(Ctrlb.value - 4) < 0.08)){ // 0.08 error tolerance assures y-intercept accurate to within 0.2

		ProblemScore = 1;
		score1c = ProblemScore;
		score = score1a + score1b + score1c + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

	} else

		ProblemScore = 0;
		score1c = ProblemScore;
		score = score1a + score1b + score1c + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
}

function PartScore2a1(form)
{
	Ctrla = form.quiz1_2a11;
	Ctrlb = form.quiz1_2a12;
	Ctrlc = form.quiz1_2a13;

	if ((Ctrla.checked == true) && (Ctrlb.checked == false) && (Ctrlc.checked == false)) {

	score2a1 = 0.5;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

	}

	else

	score2a1 = 0;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

}

function PartScore2a2(form)
{

	Ctrla = form.quiz1_2a2;

	if ((Ctrla.value - (30255.9))*(Ctrla.value - (30255.9)) < 1){ 

		ProblemScore2a2 = 0.5;
		score2a2 = ProblemScore2a2;
		score2a = score2a1 + score2a2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

	else 

		ProblemScore2a2 = 0;
		score2a2 = ProblemScore2a2;
		score2a = score2a1 + score2a2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
}

function PartScore2b1(form)
{
	Ctrla = form.quiz1_2b11;
	Ctrlb = form.quiz1_2b12;
	Ctrlc = form.quiz1_2b13;

	if ((Ctrla.checked == false) && (Ctrlb.checked == false) && (Ctrlc.checked == true)) {

	score2b1 = 1;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

	}

	else

	score2b1 = 0;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

}

function PartScore2b2(form)
{

	Ctrlb = form.quiz1_2b2;

	if ((Ctrlb.value - (9850))*(Ctrlb.value - (9850)) < 1.01){ 

		ProblemScore2b2 = 1;
		score2b2 = ProblemScore2b2;
		score2b = score2b1 + score2b2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

	else 

		ProblemScore2b2 = 0;
		score2b2 = ProblemScore2b2;
		score2b = score2b1 + score2b2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

function PartScore2c1(form)
{
	Ctrla = form.quiz1_2c11;
	Ctrlb = form.quiz1_2c12;
	Ctrlc = form.quiz1_2c13;

	if ((Ctrla.checked == false) && (Ctrlb.checked == false) && (Ctrlc.checked == true)) {

	score2c1 = 1;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

	}

	else

	score2c1 = 0;
	score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;

}

function PartScore2c2(form)
{

	Ctrlc = form.quiz1_2c2;

	if ((Ctrlc.value - (299))*(Ctrlc.value - (299)) < 1.01){ 

		ProblemScore2c2 = 1;
		score2c2 = ProblemScore2c2;
		score2c = score2c1 + score2c2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

	else 

		ProblemScore2c2 = 0;
		score2c2 = ProblemScore2c2;
		score2c = score2c1 + score2c2;
		score = score1a + score1b + score2a1 + score2a2 + score2b1 + score2b2 + score2c1 + score2c2;
	}

function RunSubmit (form, button)  {

	PartScore1a(form);
	PartScore1b(form);
	PartScore1c(form);
	PartScore2a1(form);
	PartScore2a2(form);
	PartScore2b1(form);
	PartScore2b2(form);
	PartScore2c1(form);
	PartScore2c2(form);
	if (!TestStudentName(form)) return;
	if (!TestEmailAddress(form)) return;  //use this test if Bennette revises his mailform.pl program
	if (!TestStudentID(form)) return;
	if (!Test1(form)) return;
	if (!Test2(form)) return;

	score2a = score2a1 + score2a2;
	score2b = score2b1 + score2b2;
	score2c = score2c1 + score2c2;
	score = score1a + score1b + score1c + score2a + score2b + score2c;

	gradevalueAA = (score > 8.5) ? " Before deadline, worth 2 points." : "";
	gradevalueBB = ((score > 7.5) && (score < 9)) ? " Before deadline, worth 1 point." : "";
	gradevalueCC = (score < 8.0) ? " Worth 0 points." : "";

	document.test.scoretotal.value=score;  //added by Brad in Lorna's office

	document.test.scorevalue.value=('[1a]='+ score1a + ',' + '[1b graph]='+ score1b +',' + '[1c]='+ score1c + ',' + '[2a]=' + score2a + ',' + '[2b]=' + score2b + ',' +'[2c]=' + score2c + ',' +' with total= ' + score + ' for ' + form.name.value + ' on Math 143 web quiz 1. [perfect is 10] .' + gradevalueAA + gradevalueBB + gradevalueCC + ' [counter = ' + counter + ']. Browser = ' + imagespacer+ '. ' + (RightNow.getMonth()+1) +  '-' + (RightNow.getDate()) + '-' + (RightNow.getFullYear()) + ' ; ' + (RightNow.getHours()) +  ':' + (RightNow.getMinutes()) + ':' + (RightNow.getSeconds()));<!--added by Brad in Lorna's office-->

	document.test.submit(form);  //added by Brad in Lorna's office

	alert ("The scores on each question are as follows, with the last being your total score: [1a]="+score1a+", [1b graph]="+score1b+", [1c]="+score1c+", [2a]="+score2a+", [2b]="+score2b+", [2c]="+score2c+", with total ="+score);


	return;

}

function RunScore (form, button)  {

	PartScore1a(form);
	PartScore1b(form);
	PartScore1c(form);
	PartScore2a1(form);
	PartScore2a2(form);
	PartScore2b1(form);
	PartScore2b2(form);
	PartScore2c1(form);
	PartScore2c2(form);
	counter = counter + 1;
	score = score1a + score1b + score1c + score2a + score2b + score2c;

	gradevalueA = (score > 8.5) ? "If submitted before the deadline, your quiz score is 90% or better and will be worth 2 points toward your semester grade." : "";
	gradevalueB = ((score > 7.5) && (score < 9)) ? "If submitted before the deadline, your quiz score is between 80% and 89%, and will be worth 1 point toward your semester grade." : "";
	gradevalueC = (score < 8.0) ? "Your current quiz score is less than 80%, and will be worth 0 points toward your semester grade." : "";

	if (!TestStudentName(form)) return;
	if (!TestEmailAddress(form)) return;  //use this test if Bennette revises his mailform.pl program

	if (!TestStudentID(form)) return;
	if (!Test1(form)) return;
	if (!Test2(form)) return;

	alert ("The scores on each question are as follows, with the last being your total score: [1a]="+score1a+", [1b for graph]="+score1b+", [1c]="+score1c+", [2a]="+score2a+", [2b]="+score2b+", [2c]="+score2c+", with total ="+score+" [perfect = 10]. " + gradevalueA + gradevalueB + gradevalueC);

	return;

}

function validatePrompt (Ctrl, PromptStr) {

	alert (PromptStr)

	Ctrl.focus();

	return;

}

function validatePrompt (Ctrla, PromptStr) {

	alert (PromptStr)

	Ctrla.focus();

	return;

}

function validatePrompt (Ctrlb, PromptStr) {

	alert (PromptStr)

	Ctrlb.focus();

	return;

}

function validatePrompt (Ctrlc, PromptStr) {

	alert (PromptStr)

	Ctrlc.focus();

	return;

}

function validatePrompt (Ctrld, PromptStr) {

	alert (PromptStr)

	Ctrld.focus();

	return;

}

function validatePrompt (Ctrle, PromptStr) {

	alert (PromptStr)

	Ctrle.focus();

	return;

}
