// JavaScript Document

var score = 0;

function checkAnswer(q, a) {
	var url = '/programs/trivia_night/answers.php';
	msg = 'q=' + q + '&a=' + a;
	$('q' + q).disabled = true;
	var myAjax = new Ajax.Request( 
			url, 
			{ 
					method: 'get', 
					parameters: msg, 
					onLoading: Element.update("r" + q, "Checking answer..."),
					onComplete: showResponse 
			}
	);
}

function showResponse(originalRequest) {
	var reply = originalRequest.responseText.split("|");
	var message;
	if (reply[1] == "true") { message = "<span style='color:green'>Correct!</span> "; }
	else { message = "<span style='color:red'>Sorry</span>, the answer was <strong>" + reply[3] + "</strong>."; }
	Element.update("r" + reply[0], message + " You're at <strong>" + addScore(reply[2]) + "</strong> points.");
}

function addScore(amt) {
	score += (amt - 0);
	return score;
}

function getScore() {
	return score;	
}
