/*
 * Copyright (c) 2005 Absolutely Training Limited
 * 
 * Created on 01-Dec-2005
 */
/**
 * Translation of the Java Question class into JavaScript
 * 
 * @author paulb
 */
 
function QuestionType() {}
QuestionType.MULTIPLE_CHOICE = "MULTIPLE_CHOICE";
QuestionType.ROMAN_NUMERAL = "ROMAN_NUMERAL";
QuestionType.TRUE_FALSE = "TRUE_FALSE";
QuestionType.RANDOM = "RANDOM";

 
function Question( props ) {

 	this.id = null;
 	this.contentObjectId = null;
	this.answers = [];
	this.questionText = null;
	this.explanation = null;
	this.type = null;
	
	for ( var p in props ) {
		this[p] = props[p];
	}
}

Question.prototype.copy = function() {
	var result = new Question( this );
	
	// replace all the asnwers with copies
	for ( var i = 0; i < result.answers.length; i++ ) {
		var oldAnswer = result.answers[i];
		result.answers[i] = oldAnswer.copy();
	}
	
	return result;
};

Question.prototype.getId = function() {
	return this.id;
};

Question.prototype.getExplanation = function() {
	return this.explanation;
};

Question.prototype.getType = function() {
	return this.type;
};

Question.prototype.getQuestionText = function() {
	return this.questionText;
};

Question.prototype.getAnswers = function() {
	return this.answers;
};

Question.prototype.getAlwaysPresentCorrectAnswers = function() {
	var result = [];
	for ( var i = 0; i < this.answers.length; i++ ) {
		var a = this.answers[i];
		if (a.isCorrect() && a.isAlwaysPresent()) {
			result.push(a);
		}
	}
	return result;
};

Question.prototype.getAlwaysPresentIncorrectAnswers = function() {
	var result = [];
	for ( var i = 0; i < this.answers.length; i++ ) {
		var a = this.answers[i];
		if (!a.isCorrect() && a.isAlwaysPresent()) {
			result.push(a);
		}
	}
	return result;
};

Question.prototype.getCorrectAnswers = function() {
	var result = [];
	for ( var i = 0; i < this.answers.length; i++ ) {
		var a = this.answers[i];
		if (a.isCorrect() && !a.isAlwaysPresent()) {
			result.push(a);
		}
	}
	return result;
};

Question.prototype.getIncorrectAnswers = function() {
	var result = [];
	for ( var i = 0; i < this.answers.length; i++ ) {
		var a = this.answers[i];
		if (!a.isCorrect() && !a.isAlwaysPresent()) {
			result.push(a);
		}
	}
	return result;
};

Question.prototype.getContentObjectId = function() {
    return this.contentObjectId;
};
    
Question.prototype.getScormHtmlPath = function() {
    return this.scormHtmlPath;
};
    
Question.prototype.toString = function() {
	return "Name: " + this.name + " Description: " + this.description +
			" Question Text: " + this.questionText + " Explanation: " +
			this.explanation;
};

