// FILENAME:	quizcheckerMMwFB_01.js
//
// DATE:		2002/09/27
//
// PROGRAMMER:	Jervis Thompson (www.epvisual.com)
//
// DESCRIPTION:	Multiple Choice / Multiple Question Quiz checker with instant feedback. 
//
//
//
//

// global variables
//

var gBoxLtrArray = new Array();

var gFeedBackLtrArray = new Array();

var gNumberCorrect = 0;


// functions and handlers
//
///////////////////////////////////////// PRELOAD CODE ///////////////////////////////////////
//

function FeedBackLtrAnswer(a, b, c, d, e, f) {   // Feedback array per question
	this.a = a;
	this.b = b;
	this.c = c;
	this.d = d;
	this.e = e;
	this.f = f;
} // end FeedBackLtrAnswer


function preload() {  //if browser can handle it, pre-load images
	
	// Question set up.
	//

	// Question dummy
	gBoxLtrArray[0]      = "a";
	gFeedBackLtrArray[0] = new FeedBackLtrAnswer("Incorrect. Select again.", "Correct!", "Incorrect. Select again.", "Incorrect. Select again.", "Incorrect. Select again.");


	// Question number 1
	gBoxLtrArray[1]      = "a";

	// Question number 2
	gBoxLtrArray[2]      = "b";

	// Question number 3
	gBoxLtrArray[3]      = "a";

	// Question number 4
	gBoxLtrArray[4]      = "a";
	
	// Question number 5
	gBoxLtrArray[5]      = "a";

	// Question number 6
	gBoxLtrArray[6]      = "b";

	// Question number 7
	gBoxLtrArray[7]      = "a";

	// Question number 8
	gBoxLtrArray[8]      = "a";

	// Question number 9
	gBoxLtrArray[9]      = "b";
	
	// Question number 10
	gBoxLtrArray[10]      = "b";

	// Question number 11
	gBoxLtrArray[11]      = "c";

	// Question number 12
	gBoxLtrArray[12]      = "b";

	// Question number 13
	gBoxLtrArray[13]      = "b";

	// Question number 14
	gBoxLtrArray[14]      = "a";
	
	// Question number 15
	gBoxLtrArray[15]      = "b";


} // end preload


////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////// QUIZ CODE ////////////////////////////////////////////////
//

function epKnowledgeCheckAlert() {
	alert('You must answer at least 12 questions correctly to print the Certificate of Completion');
}

function QuizMMcheck() { 
		
	gNumberOfQuestions = 15;
	
	gNumberCorrect = 0;
	
	for (var qlp = 1; qlp <= gNumberOfQuestions; qlp++) {
		// Number of questions
		vQuestNum_str = qlp.toString();
		
		vNumOfRadioButtons = eval ( "document.mmQuizForm.rb" + vQuestNum_str + ".length" );
				
		for (var rlp = 0; rlp < vNumOfRadioButtons; rlp++) {
			// Number of radio buttons per question
			//
			vRadioNum_str = rlp.toString();
			
			// Extract radio button checked info
			//
			vRadioChecked = eval ( "document.mmQuizForm.rb" + vQuestNum_str + "[" + vRadioNum_str + "].checked" );
			
			if (vRadioChecked) {
				// Extract radio button value info
				//
				pUserPicked = eval ( "document.mmQuizForm.rb" + vQuestNum_str + "[" + vRadioNum_str + "].value" );
				
				vCorrectLtr = gBoxLtrArray[qlp];
				
			    if (pUserPicked  ==  vCorrectLtr) {
					// User got it right
					gNumberCorrect = gNumberCorrect + 1;
				} // end if

				
				/*
				// Pull out feedback for answer
				if ( pUserPicked == 'a') {
					vFeedBack = gFeedBackLtrArray[qlp].a;
				} else { if ( pUserPicked == 'b') {
					vFeedBack = gFeedBackLtrArray[qlp].b;
				} else { if ( pUserPicked == 'c') {
					vFeedBack = gFeedBackLtrArray[qlp].c;
				} else { if ( pUserPicked == 'd') {
					vFeedBack = gFeedBackLtrArray[qlp].d;
				} else { 
					alert("User did not pick a valid answer!");
					return 0;
				}}}} // end if

				// Put Info into feed back field
				//
				eval ( "document.mmQuizForm.fbfield" + vQuestNum_str + ".value = " + "\"" + vFeedBack + "\"" );
				*/
			}
			
		}
			
	}
	
	//vFeedBack2 = "You answered " + gNumberCorrect + " of 30 questions correctly.\r\rLook below each question for feedback on the answer you selected.\rYou can select the print icon on your browser to print this assessment, including the feedback.";
	//alert (vFeedBack2);
	
	/*
	if (gNumberCorrect >= 12) {
		//
		window.location = 'c_17.htm';	
		//
	} else {
	*/
		// Create or recreate feedback window.
		oPopUpWin = window.open('empty.html','fbWin','toolbar=no,directories=no,menubar=yes,resizable=yes,scrollbars=no,width=512,height=250');
					
		oPopUpWin.document.open();
			
		oPopUpWin.document.writeln('<head><title>Feedback</title></head>');
					
		oPopUpWin.document.writeln('<body bgcolor="#E4EBF4" text="#000000" link="#336699" vlink="#003366">');
		
		oPopUpWin.document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="8" bgcolor="#FFFFFF">');
		oPopUpWin.document.writeln('<tr>');
		oPopUpWin.document.writeln('<td>');
		
		oPopUpWin.document.writeln('<font face="arial" size="2">You answered ' + gNumberCorrect + ' of ' + gNumberOfQuestions + ' questions correctly.<br><br>' );	
		oPopUpWin.document.writeln('You may return to the Main Menu and select any title to review a lesson or exit the course by closing the browser window.');
		oPopUpWin.document.writeln('<p align="right"><a href="javascript:self.close();"><img src="../images/close.gif" width="80" height="23" name="closeImg" border="0"></a></p></font>');
			
		oPopUpWin.document.writeln('</td>');
		oPopUpWin.document.writeln('</tr>');
		oPopUpWin.document.writeln('</table>');
	
		oPopUpWin.document.writeln('</body>');
		oPopUpWin.document.close();
				
		// Bring defination window to the front.
		oPopUpWin.focus();	
	/*
	}
	*/

} // end QuizMMcheck

