/*******************************************
 * JS for In story Quiz IE 
 * \quizzes\2009\fortune\layoff\quiz.exclude.html
 *******************************************/

// this is a workaround for IE3, which refuses to work
function callSubmitForm(theForm)
{
	submitForm(theForm);
}//  callSubmitForm()

function submitForm(theForm) {
	var score	= 0;  // quiz score

	// 1) Get get quiz score by getting values for all checkboxes
	score = getScore(theForm.elements);
	// 2) Display results
	displayResults(score);

}// end submitForm()

/*
 * pre: formElements is an array of form element
 * post: returns total of checkbox elements in formElements that are checked.
 */
function getScore(formElements) {
	var score = 0;
	
	for (var i = 0; i < formElements.length; i++) {
		var element = formElements[i];
		if (element.type == 'checkbox'  && element.checked) score ++;
 	}

	return score;
}// end getScore()

/*
 * pre: score is a numerical value
 * post: displays score in div with id "quizResults"
 */
function displayResults(score) {
	var commentStr = "";	//comment string
	var resultsHTMLObj;

	// If you answered yes to two or less.
	if (score < 3)		commentStr = "You're not likely to get a pink slip anytime soon.";
	// If you responded yes to three to six questions.
	else if (score < 7) commentStr = "You've got some work to do to hang onto your job.";
	// If you answered yes to seven or more. 	
	else 				commentStr = "You might as well start packing up your desk.";
	
	commentHTMLObj = document.getElementById('cnnQuiz_comment');
	commentHTMLObj.innerHTML = commentStr;
	resultsHTMLObj = document.getElementById('cnnQuizLayoffRisk_results');
	resultsHTMLObj.className = 'cnnUnhide';

}// end displayResults()
