
<!-- hide from older browsers
function clean(txt, ttf){
	var reg= new RegExp(ttf, "g");
	return (txt.replace(reg, ""))
}
function multipleChoiceScore(i, theform){
	/*
	Given the index of a multiple choice question
	in a form, returns whether it was right or wrong
	*/
		var mx=theform["q" + i + "_a"].length;
		var checkedAnswer="";
		for (var x=0; x<mx; x++){
			if (theform["q" + i + "_a"][x].checked==true){
				checkedAnswer=checkedAnswer + theform["q" + i + "_a"][x].value + "|";
			}
		}
		var rightanswer=theform["q" + i + "_answer"].value;
		if (rightanswer.lastIndexOf("|")!=rightanswer.length-1){
			rightanswer=rightanswer + "|";
		}
		if (clean(rightanswer, "q" + i + "_a")==clean(checkedAnswer, "q" + i + "_a")){
			return(1);
		}
		else{
			return(0);
		}
}
function checkAnswers(thisform){
	/*
	Given a form, iterates through each question
	looking for correct answers.
	*/
	var numright=0;
	for (var i=1; i<=thisform.numquestions.value; i++){
		var type=thisform["q" + i + "_type"].value;
		if (type=="mc" || type=="ma"){
			numright=numright+multipleChoiceScore(i, thisform);
		}
		// don't have an option for other types, but it's possible.
	}
	var pc=numright/thisform.numquestions.value*100;
	var advisory="";
	var randomReinforcementArr=new Array("Great job!", "Keep going!", "You're doing well!", "Nice work!", "Keep it up!");
	var randomIndex=Math.round((Math.random()*randomReinforcementArr.length) + 0.5)-1;

	if (pc>90){advisory=randomReinforcementArr[randomIndex];}
	else if (90>=pc>80){advisory="Good job! You might want to review a little though.";}
	else{advisory="You should review this content again";}
	if(thisform.numquestions.value=="1" && numright==1){
		alert("You got it right. " + randomReinforcementArr[randomIndex]);
	}
	else if (thisform.numquestions.value=="1" && numright==0){
		alert("Review this content and try again");
	}
	else{
		alert("You got " + numright + " right.  " + advisory);
	}
}
function checkText(str, arr, flMustInclude){
	if (str.length==0){
		alert("Oh, ha! ha! very funny");	
	}
	str=str.toLowerCase();
	var evalString="str.indexOf(arr[i].toLowerCase())>-1";
	var isOrNot="IS NOT";
	if (flMustInclude){
		evalString="str.indexOf(arr[i].toLowerCase())==-1";
		isOrNot="IS";
	}
	var flBreak=false;
	for (var i=0;i<arr.length;i++){
		if(eval(evalString)){
			alert("\"" + arr[i] + "\" probably " + isOrNot + " necessary.  Edit and try again");
			flBreak=true;
			break;
		}
	}
	return(flBreak);
}
//-->


