/*
Shouldn't need to be changed unless there's a conflict in class names or js variable names.
*/

/* Make Results page display like quiz/questions page - Added 8/15/08 - ail */

/* Gives you variables from query strings...
   If the url is results.html?q1=a
   You'll have a variable named q1 with a value of a
*/

tmp = window.location.toString().split('?');

if (tmp[1]) {
	tmp2 = tmp[1].split('&');
	for (i=0; i<tmp2.length; i++) {
		tmp = tmp2[i].split('=');
	eval(tmp[0] + ' = "' + tmp[1] + '"');
	}
}

var correct = 0;
var questions = 0;

function printAnswer(question,correctAnswer) {
	var status = false;
	questions++;
	userAnswer = question + eval(question);
	document.write('<div class="result_answers">');
	
	if (userAnswer == correctAnswer) {
		status = true;
		correct++;
	}
	
	if (eval(question)) {
		eval('printUserAnswer('+userAnswer+','+status+');');
	} else {
		//status = "none";
		printUserAnswer('No answer provided.',status);
	}
	if (correctAnswer != '') {
		eval('printCorrectAnswer('+correctAnswer+')');
	}
	document.write('</div>');
	scoreQuiz(correct, questions);
}
function printUserAnswer(text,status) {
	/*if (status == "none") {
		document.write('<p class="result_answer_none"><strong>You answered:</strong> ');
	}
	else*/
	if (status) {
		document.write('<img src="http://images.medicinenet.com/images/quiz/quiz_check.gif" width="18" height="18" border="0" alt="" /><p class="result_answer_correct"><strong>You answered:</strong> ');
	}
	else {
		document.write('<img src="http://images.medicinenet.com/images/quiz/quiz_x.gif" width="17" height="16" border="0" alt="" /><p class="result_answer_wrong"><strong>You answered:</strong> ');
	}
	document.write(text);
	document.write('</p>');
}
function printCorrectAnswer(text) {
	document.write('<p><strong>The correct answer is:</strong> ');
	document.write(text);
	document.write('</p>');
}

function processQuiz(form, resultsURL) {
	/* Set form action */
	//var url = window.location.toString().split('?')[0];
	// Grab article ID from url
	//var articleID = parseInt(window.location.toString().split('?')[1].split('=')[1]);
	
	// grabs the redirect value for the SDC results page
	
	//var theURL = document.getElementById("redirectUrl").value;
	var theURL = resultsURL;
	// appends the quiz results to that URL
	
	for (i=0; i<form.length; i++) {
		if (form.elements[i].checked) {
			theURL += "&" + form.elements[i].name + "=" + form.elements[i].value
		}
	}
	// resets the redirectURL before sending user there
	//document.getElementById("redirectUrl").value = theURL;
	//window.location = theURL;
	window.location = theURL;
	return false;
}

/* START for the print friendly version of the page */   
var wmdUrl= location.href;
var is_print = (wmdUrl.indexOf("print=true") != -1);

/* if printable, add the print friendly CSS stylesheet */
if (is_print) {
	document.write('<link rel="stylesheet" type="text/css" href="http://img.webmd.com/dtmcms/live/webmd/PageBuilder_Assets/CSS/print_preview.css"/>');
}
/* END for the print friendly version of the page */  

/* function to set the height on parents iframe for font sizer */
function setHeight(theDiv,theHeight) {
	parent.document.getElementById(theDiv).style.height = theHeight;
}
	  
/* function to change a class */
function setClass(objectID,newClass) {
	var object = document.getElementById(objectID);
	if (object) {
		object.className = newClass;
	}
}

/* Code for correct out of questions text */

function scoreQuiz(numCorrect, numQuestion) {
	if (document.getElementById('quiz_score')) {
		document.getElementById('quiz_score').innerHTML = "You answered " + numCorrect + " out of " + numQuestion + " questions correctly. Your quiz results:";
	}
}

