/* ######################### /common/js/quizfuncs.js #########################
define all variables and set defaults
these are can be overidden in a local, (quiz-specific) "quiz.js"
*/

var path = "";
var score = 0; 					// holds cumulative/final score
var qscore = 100; 				// points for correct answer
var q_num = 4; 				// total # of questions

var strR = "<b>That's correct!</b>";
var strW = "<b>Sorry, try again.</b>";

// ans[] array holds answers:
var ans = new Array();

/* checkAnswer is called with question # to be checked and nextpage to be sent to */
// #########################
function checkAnswer(q,np) { 
	var ltr;
	for (var i = 0; i < document.quiz.question.length; i++) {
		if (document.quiz.question[i].checked == "1") {
			var isChecked = true;
			score = getScore();
			ltr = document.quiz.question[i].value;
			if (ltr == ans[q]) score += qscore;
		}
	}
	if (!isChecked) {
		alert("Please make a selection");
		return false;
	} else {
		location.href = path + np + "?currentPoints=" + score + "&ltr=" + ltr;
		return;
	}
}

//#########################
function getScore() {
	var qryStr = window.location.search;
	var pts = 0;

	if (qryStr.charAt(0) == "?") {
		qryStr = qryStr.substring(1,qryStr.length); // get rid of starting "?"
		pts = parseInt(qryStr.substring((qryStr.indexOf("=")+1),qryStr.length));
	}

	return (pts);
}

/* #########################
function writeAnswer()
This function evaluates the answer submitted on the previous page, and prints the appropriate response. The first two conditions test if the answer is wrong. If the answer passes the first two conditions, then it is right. Be sure to substitute the correct letter into the evaluation, as well as changing the output message.
*/

function getAnswer(q) {
	var qryStr = window.location.search;
	var ltr = qryStr.substring((qryStr.lastIndexOf("="))+1,qryStr.length);
	var strAns = getResponse(q,ltr);

	document.write(strAns);

}

/*function getResponse(q,ltr) {
	var strResp;
	if (ltr == ans[q]) strResp = "<strong>" + strR + "</strong>";
	else strResp = "<strong>" + strW + "</strong>";

	return (strResp);
}*/

function getTotal() {
	var totalscore = parseInt(qscore * q_num);
	return totalscore;
}

