<!-- Hide this script from old browsers.

// Copyright 2006 Jason Cheever. All rights reserved.

//---------------------------------------------------------------------------------------------------------
//
// jdc_tally_results();
//
//   Validates the quiz answers, reports the results, and recommends a workshop.
//
//---------------------------------------------------------------------------------------------------------

function jdc_tally_results() {

  var index_total;
  var index_question;
		var index_answer;
		var valid_answer;
  var element_name;
		var number_answers;
		var totals = new Array( 3 );
		var message;
		var new_tally_message;
		var tally_element;
		
		// Initialization.
		for ( index_total = 0; index_total < totals.length; index_total++ ) {
				totals[ index_total ] = 0;
		}

  // Make sure the user answered all the questions.
		
		// Loop thru each question.
		for ( index_question = 0; index_question < 10; index_question++ ) {
	
	   // Determine the number of answers for this question.
	   element_name = "question_" + ( index_question + 1 );
				number_answers = document.forms[ 0 ].elements[ element_name ].length

    // Loop thru each answer.
				valid_answer = false;
				for ( index_answer = 0; index_answer < number_answers; index_answer++ ) {
					 if ( document.forms[ 0 ].elements[ element_name ][ index_answer ].checked == true ) {
							 valid_answer = true;
								totals[ index_answer ]++;
							 break;
						}
				}
     
				// If none of the radio buttons was checked, then we have a problem.
				if ( valid_answer == false ) {
					 alert( "You did not provide an answer to Question #" + ( index_question + 1 ) + "." );
						return;
				}
		}
		
		// Tally the quiz results.
		
		// Write the quiz results for A's.
		message = totals[ 0 ] + " A";
		if ( totals[ 0  ] != 1 ) {
			 message += "'s";
		}
		new_tally_message = document.createTextNode( message );
		tally_element = document.getElementById( "quiz_tally_a" );
		tally_element.replaceChild( new_tally_message, tally_element.firstChild );
		
		// Write the quiz results for B's.
		message = totals[ 1 ] + " B";
		if ( totals[ 1  ] != 1 ) {
			 message += "'s";
		}
		new_tally_message = document.createTextNode( message );
		tally_element = document.getElementById( "quiz_tally_b" );
		tally_element.replaceChild( new_tally_message, tally_element.firstChild );
		
		// Write the quiz results for C's.
		message = totals[ 2 ] + " C";
		if ( totals[ 2  ] != 1 ) {
			 message += "'s";
		}
		new_tally_message = document.createTextNode( message );
		tally_element = document.getElementById( "quiz_tally_c" );
		tally_element.replaceChild( new_tally_message, tally_element.firstChild );
		
		// Make the results visible (and the Tally button invisible).
		document.getElementById( "quiz_tally_button" ).style.display = "none";
		document.getElementById( "quiz_results_div" ).style.display = "block";

  return;
}


  
// End of hiding script from old browsers. -->
