/*
 * Copyright (c) 2005 Absolutely Training Limited
 * 
 * Created on 06-Dec-2005
 */
 
 /* JSLint global function comment */
/*global MultipleChoiceQuestion, RomanNumeralQuestion, TrueFalseQuestion, TestUtils  */ 
 
/**
 * Translation of the Java TestHtmlTranslator class into JavaScript
 * 
 * @author paulb
 */
function TestHtmlTranslator() {
	HtmlCreator.call(this);
	this.elementList = new Array();
	this.questionIdSuffixMap = new Array();
	this.radioElementList = new Array();
	this.checkBoxElementList = new Array();
	this.pageDivList = new Array();
	this.contentObjectList = new Array();
	this.correctAnswerMap = new Array();
	this.score = 0;
	this.scoreRaw = 0;
	this.scoreScaled = 0;
	this.assessment = "";
	this.progressMeasure = 0.0;
	this.successStatus = "failed";
}

TestHtmlTranslator.prototype = new HtmlCreator();
TestHtmlTranslator.prototype.constructor = TestHtmlTranslator;

TestHtmlTranslator.prototype.translateTest = function(test) {
	this.clearHtmlText();
	this.testUpdateView(test);
	return this.getHtmlText();
};

TestHtmlTranslator.prototype.translateTestReport = function(test, userAnswers, testContainer) {
	this.clearHtmlText();
	this.testReportView(test, userAnswers, testContainer);
	return this.getHtmlText();
};

TestHtmlTranslator.prototype.testUpdateView = function(test) {
	// test div

//	alert(doGetValue("cmi.learner_id"));
	this.inputHidden("courseId", test.getCourseId() );  //TODO
	
	this.divWithIdAndStyle("test", "");
	this.divWithText("testDivHeader", ASSESSMENT_ON +" " + test.getTestName(), "left");
	this.inputHidden("resultCategories", test.getResultCategoryString());
//	this.property("testDivHeader", "Assessment On: ", test.getTestName(), "left");
	this.divWithStyle("", "padding-left: 15px;")
//	this.property("propertyGeneralOut", "<b>"+DELEGATE+"</b>", doGetValue("cmi.learner_id"), "left");
	this.property("propertyGeneralOut", "<b>"+DATE+"</b>", test.getCreatedDate(), "left");
	this.endDiv();

	var testPages = test.getTestPages(AMOUNT_OF_QUESTIONS_PER_PAGE);
	for (var pageIndex = 0; pageIndex < testPages.length; pageIndex++) {
		var page = testPages[pageIndex];
		this.testPageUpdateView(page, pageIndex + 1, testPages.length);
	}

	this.endDiv();
};

TestHtmlTranslator.prototype.testReportView = function(test, userAnswers, testContainer) {
	// test report div
	var resultsHash = this.calculateResults(userAnswers, testContainer, test);
	this.divWithIdAndStyle("testReport", "padding-top:10px;");
	// this.property("propertyGeneralOut", "<b>"+DELEGATE+"</b>", doGetValue("cmi.learner_name"), "left");
	this.property("propertyGeneralOut", "<b>"+ASSESSMENT_ON+"</b>", test.getTestName(), "left");
	this.property("propertyGeneralOut", "<b>"+DATE+"</b>", test.getCreatedDate(), "left");
	this.propertyWithId("propertyValueDimensions", "<b>"+SCORE+"</b>", resultsHash["score"],
			"score", "left");
	this.propertyWithId("propertyValueDimensions", "<b>"+ASSESSMENT_ON+"</b>", resultsHash["assessment"],
			"assessment", "left");

	this.startTableCollectionProperty("collectionPropertyTableStyle");
	this.tableRow();
	this.header(SUBJECT, "68%", null, null, 0);
	this.header(QUESTIONS, "8%", null, "center", 0);
	this.header(CORRECT_ANSWER, "8%", null, "center", 0);
	this.header(CORRECT_PER, "8%", null, "center", 0);
	this.header(ASSESSMENT, "8%", null, "center", 0);
	this.endTableRow();

	var questionGroupContainers = testContainer.getQuestionGroupContainersRecursive();
	questionGroupContainers.unshift(testContainer);
	for (var i = 0; i < questionGroupContainers.length; i++)
	{
		if (TestUtils.contains(this.contentObjectList, questionGroupContainers[i].getId()))
		{
			this.reportLineView(questionGroupContainers[i].getId(), questionGroupContainers[i].getName(), i, resultsHash);
		}
	}
	this.endTableCollectionProperty();

//	this.startCollectionProperty();
	this.startTableCollectionProperty("collectionPropertyTableStyle");
	this.header("","100%",null,null,0);
	this.tableRow();
	this.tableCellStart();
	var questions = test.getQuestions();
	for (var questionNo = 0; questionNo < questions.length; questionNo++) {
		var question = questions[questionNo];
		this.testQuestionView(question, questionNo, userAnswers);
	}
	this.tableCellEnd();
	this.endTableRow();	
	this.endTableCollectionProperty();
//	this.endCollectionProperty();
	//this.inputButton("Retry", "document.location.reload()");
	this.endDiv();
};

/**
 * Calculates test results based on user input. Returns hash that contains overall results in "total", "correct", "score" and "assessment field.
 * as well as results grouped by contentobject id in "<contentObjectId>total", "<contentObjectId>correct", "<contentObjectId>score" and "<contentObjectId>assessment" fields.
 */
TestHtmlTranslator.prototype.calculateResults = function(userAnswers, testContainer, test) {
	var resultsHash = new Array();
	resultsHash["total"] = 0;
	resultsHash["correct"] = 0;
	for (var i = 0; i < test.getQuestions().length; i++) {
		var question = test.getQuestions()[i];
		var questionSuffix = this.questionIdSuffixMap[question.getId()];
		var userAnswer = userAnswers[questionSuffix];
		var correctAnswer = question.getCorrectChoices();
		resultsHash["total"] = resultsHash["total"] + 1;
		if (!TestUtils.contains(this.contentObjectList, question.getContentObjectId())) {
			this.contentObjectList[this.contentObjectList.length] = question.getContentObjectId();
		}
		if (TestUtils.isDefined(resultsHash[question.getContentObjectId() + "total"])) {
			resultsHash[question.getContentObjectId() + "total"] = resultsHash[question.getContentObjectId() + "total"] + 1;
		}
		else {
			resultsHash[question.getContentObjectId() + "total"] = 1;
		}
		if (userAnswer == correctAnswer) {
			
			resultsHash["correct"] = resultsHash["correct"] + 1;
			if (TestUtils.isDefined(resultsHash[question.getContentObjectId() + "correct"])) {
				resultsHash[question.getContentObjectId() + "correct"] = parseInt(resultsHash[question.getContentObjectId() + "correct"], 10) + 1;
			}
			else {
				resultsHash[question.getContentObjectId() + "correct"] = 1;
			}
		}
	}
	for ( i = 0; i < this.contentObjectList.length; i++) {
		var correct = (!TestUtils.isDefined(resultsHash[this.contentObjectList[i] + "correct"])) ? 0 : resultsHash[this.contentObjectList[i] + "correct"];
		resultsHash[this.contentObjectList[i] + "correct"] = correct;
		var total = resultsHash[this.contentObjectList[i] + "total"];
		var score = Math.floor(correct/total * 100);
		resultsHash[this.contentObjectList[i] + "assessment"] = testContainer.getResultCategoryGroup().getAssessmentForScore(score);
		resultsHash[this.contentObjectList[i] + "score"] = score;
	}

	this.scoreRaw = resultsHash["correct"];
	this.progressMeasure = this.scoreRaw / resultsHash["total"];
	this.scoreScaled = (2 * this.progressMeasure) - 1;
	this.score = Math.floor(this.progressMeasure * 100);
	this.assessment = testContainer.getResultCategoryGroup().getAssessmentForScore(this.score);
	var passed = testContainer.getResultCategoryGroup().getPassMark() <= this.score;
	this.successStatus = passed ? "passed" : "failed";
	resultsHash["assessment"] = this.assessment;
	resultsHash["score"] = this.score;
	return resultsHash;
};


TestHtmlTranslator.prototype.reportLineView = function(contentObjectId, sectionName, lineNo, resultsHash) {
	this.tableRow();
	this.tableCell("propertyGeneralOutTable", sectionName, null, null, 0);
	this.tableCell("propertyGeneralOutTable", 
					resultsHash[contentObjectId + "total"], null, "center", 0);
	this.tableCellWithDiv("correctQuestions_" + lineNo, resultsHash[contentObjectId + "correct"], false, "center");
	this.tableCellWithDiv("correctQuestionsPercent_" + lineNo, resultsHash[contentObjectId + "score"], false, "center");
	this.tableCellWithDiv("assessment_" + lineNo, resultsHash[contentObjectId + "assessment"], false, "center");
	this.endTableRow();
};

TestHtmlTranslator.prototype.testPageUpdateView = function(page, pageNo, noOfPages) {
	// style to show first page only
	var style = pageNo == 1 ? "display:block" : "display:none";
	var pageDivName = PAGINATION_PREFIX + "_" + pageNo;
	this.divWithIdAndStyle(pageDivName, style);
	this.pageDivList[this.pageDivList.length] = pageDivName;

	this.divWithStyle("", "padding-left: 15px;")
	this.property("propertyGeneralOut", "<b>"+QUESTIONS+"</b>", page.getFirst() +
			" - " + page.getLast() + " of " + page.getTotal(), "left");
	this.endDiv();

//	this.startCollectionProperty();
	this.divWithStyle("", "width:100%;float:left;padding:10px;");
	var noInPage = 0;
	var questions = page.getQuestions();
	for (var i = 0; i < questions.length; i++) {
		var question = questions[i];
		noInPage++;
		var questionSuffix = pageNo + "_" + noInPage;
		this.testQuestionUpdateView(question, questionSuffix);
	}
//	this.endCollectionProperty();
	this.endDiv();

	this.div("collectionPropertyPaginationNavAlignment");
	if (pageNo > 1) {
		this.inputButton(PREVIOUS_QUESTION, "previousPage();return false;");
	}
	if (pageNo != noOfPages) {
		this.inputButton(NEXT_QUESTION, "nextPage();return false;");
	} else {
		this.inputButton(FINISH_TEST, "finishTest();return false;");
	}
	this.endDiv();

	this.endDiv();
};


TestHtmlTranslator.prototype.testQuestionUpdateView = function(question, questionSuffix) {
	if (question instanceof TrueFalseQuestion) {
		this.trueFalseQuestionUpdateView(question, questionSuffix);
	} else if (question instanceof RomanNumeralQuestion) {
		this.romanNumeralQuestionUpdateView( question, questionSuffix);
	} else if (question instanceof MultipleChoiceQuestion) {
		this.multipleChoiceQuestionUpdateView( question, questionSuffix);
	}
};

TestHtmlTranslator.prototype.trueFalseQuestionUpdateView = function(question, questionSuffix) {
	this.beginQuestion(question, questionSuffix);
	this.answerChoicesCheckbox(question, questionSuffix);
	this.checkBoxElementList[this.checkBoxElementList.length] = questionSuffix;
};

TestHtmlTranslator.prototype.multipleChoiceQuestionUpdateView = function( question, questionSuffix) {
	this.divWithStyle("testQuestionBackground","");
	this.propertyNoLabel("testQueAlignment", "Q." + question.getOrderNum());
	this.divWithStyle("testQuestionTitle","");
	this.beginQuestion(question, questionSuffix);
	this.endDiv();
	this.endDiv();
	this.answerChoices(question, questionSuffix);
};

TestHtmlTranslator.prototype.romanNumeralQuestionUpdateView = function( question, questionSuffix) {
	this.divWithStyle("testQuestionBackground","");
	this.propertyNoLabel("testQueAlignment", "Q." + question.getOrderNum());
	this.divWithStyle("testQuestionTitle","");
	this.beginQuestion(question, questionSuffix);
	this.inputHidden("answerText" + questionSuffix, question.getEncodedCorrectAnswers());

	var possibleAnswers = question.getPossibleAnswers();
	for (var i = 0; i < possibleAnswers.length; i++) {
		var possibleAnswer = possibleAnswers[i];
		this.testAnswerView(possibleAnswer);
	}
	this.endDiv();
	this.endDiv();
	this.newline();
	this.answerChoices(question, questionSuffix);
};

TestHtmlTranslator.prototype.testQuestionView = function(question, questionNo, userAnswers) {
	if (question instanceof TrueFalseQuestion) {
		this.trueFalseQuestionView(question, questionNo, userAnswers);
	} else if (question instanceof RomanNumeralQuestion) {
		this.romanNumeralQuestionView(question, questionNo, userAnswers);
	} else if (question instanceof MultipleChoiceQuestion) {
		this.multipleChoiceQuestionView(question, questionNo, userAnswers);
	}
};

TestHtmlTranslator.prototype.trueFalseQuestionView = function( question, questionNo, userAnswers) {
	this.startTableCollectionProperty("testReportQue_collectionPropertyTableStyle");
	this.beginReportQuestion(question);
	this.answerChoicesFullDetail(question, questionNo, false, userAnswers);
	this.endReportQuestion(question, questionNo);
	this.endTableCollectionProperty();
};

TestHtmlTranslator.prototype.multipleChoiceQuestionView = function( question, questionNo, userAnswers) {
	this.startTableCollectionProperty("testReportQue_collectionPropertyTableStyle");
	this.beginReportQuestion(question);
	this.answerChoicesFullDetail(question, questionNo, false, userAnswers);
	this.endReportQuestion(question, questionNo);
	this.endTableCollectionProperty();
};

TestHtmlTranslator.prototype.romanNumeralQuestionView = function( question, questionNo, userAnswers) {
	this.startTableCollectionProperty("testReportQue_collectionPropertyTableStyle");
	this.beginReportQuestion(question);
	this.possibleAnswersFullDetail(question, questionNo);
	this.answerChoicesFullDetail(question, questionNo, true, userAnswers);
	this.endReportQuestion(question, questionNo);
	this.endTableCollectionProperty();
};

TestHtmlTranslator.prototype.beginQuestion = function(question, questionSuffix) {
	var correctChoices = question.getCorrectChoices();	
//	this.propertyNoLabel("testQuestionTitle", question.getQuestionText());
	this.propertyNoLabel("", question.getQuestionTextWithoutNumber());
	this.elementList[this.elementList.length] = questionSuffix;
	this.correctAnswerMap[questionSuffix] = correctChoices;
	this.questionIdSuffixMap[question.getId()] = questionSuffix;
};

TestHtmlTranslator.prototype.answerChoices = function(question, questionSuffix) {
	var choices = question.getAnswerChoices();
	this.radioElementList[this.radioElementList.length] = questionSuffix;
	for (var choiceNo = 0; choiceNo < choices.length; choiceNo++) {
		var choice = choices[choiceNo];
		this.div("refPropertyRadioListLine");
//		var choiceText = choice.getLetter() + ". " + choice.getAnswerText();
//		this.divWithText("refPropertyRadioListText", choiceText, null);

		this.divWithText("testAnsChoiceAlignment", choice.getLetter() + ". ", null);
		this.divWithText("refPropertyRadioListText", choice.getAnswerText(), null);

		var elementName = RADIOCHOICE_PREFIX + questionSuffix;
		this.div("refPropertyRadioListPadding");
		this.inputRadio(elementName, choiceNo);
		this.endDiv();

		this.endDiv();
	}
};

TestHtmlTranslator.prototype.answerChoicesCheckbox = function(question, questionSuffix) {
	var choices = question.getAnswerChoices();
	for (var choiceNo = 0; choiceNo < choices.length; choiceNo++) {
		var choice = choices[choiceNo];
		this.div("refPropertyTickListLine");
		var choiceText = choice.getLetter() + ". " + choice.getAnswerText();
		this.divWithText("refPropertyTickListText", choiceText, null);
		
		var elementName = CHECKBOXCHOICE_PREFIX + questionSuffix;
		this.div("refPropertyTickListPadding");
		this.inputCheckBox(elementName, choiceNo);
		this.endDiv();

		this.endDiv();
	}
};

TestHtmlTranslator.prototype.testAnswerView = function(answer) {
	// TODO do we need to do this here - existing XSLT produces this
	this.startCollectionProperty();
	var text = answer.getLetter() + ". " + answer.getAnswer().getAnswerText();
	this.propertyNoLabel("propertyGeneralOut", text);
	this.endCollectionProperty();

//	var text = answer.getLetter() + ". " + answer.getAnswer().getAnswerText();
//	this.propertyNoLabel("testQuestionTitle", text);
	

};

TestHtmlTranslator.prototype.beginReportQuestion = function(question) {
	this.header("Q." + question.getOrderNum(), "3%", null, null, 0);
	this.header(question.getQuestionTextWithoutNumber(), "98%", null, null, 3);
};

TestHtmlTranslator.prototype.endReportQuestion = function(question, questionNo) {

	var id = "scormHtmlPath_" + questionNo;
	var scormPath = question.getScormHtmlPath();
	this.inputHidden(id, scormPath);
	var onClick = "openCourseInNewWindow('" + escape(scormPath) + "',false);return false;";

	if (question.getQuestion().getExplanation() ) {
		this.tableCell("","",null,null,0)
		this.tableCell("propertyGeneralOutTable",
				"<br><b>"+EXPLANATION+"</b><br>" +
						question.getQuestion().getExplanation() + "<br>", null, null, 3);
	}
};

TestHtmlTranslator.prototype.answerChoicesFullDetail = function(question, questionNo, mc, userAnswers) {
	this.tableRow();
	this.header(LETTER, "3%", null, "center", 0);
	this.header(ANSWER_TEXT, "87%", null, null, 0);
	this.header(YOUR_ANSWER, "5%", null, "center", 0);
	this.header(CORRECT_ANSWER, "5%", null, "center", 0);
	// header( "", "30%" );
	this.endTableRow();

	var choices = question.getAnswerChoices();
	var questionSuffix = this.questionIdSuffixMap[question.getId()];
	var userAnswerArr;
	if (userAnswers){
		userAnswerArr = (userAnswers[questionSuffix] == "undefined" || userAnswers[questionSuffix] == null) ? new Array() : userAnswers[questionSuffix].split(",");
	}
	for (var choiceNo = 0; choiceNo < choices.length; choiceNo++) {
		var choice = choices[choiceNo];
		this.tableRow();
		this.tableCell("propertyGeneralOutTable", choice.getLetter() + ".",
				null, "", 0);
		var explanation = choice.getExplanation() ? "<br><b>Explanation</b><br>" + choice.getExplanation() + "" : "";
		this.tableCell(
				"propertyGeneralOutTable",
				choice.getAnswerText() + explanation, null, null, 0);
		var ticked;
		if (userAnswerArr)
		{
			ticked = TestUtils.contains(userAnswerArr, choiceNo);
		}else{
			ticked =choice.selected;
		}
		
		this.tableCellAnswer("userAnswer", questionNo, choiceNo, null, "center", 0, ticked);
		this.tableCellAnswer("correctAnswer", questionNo, choiceNo, null,
				"center", 0, choice.isCorrect());
		// tableCell( "propertyGeneralOutTable",) );
		this.endTableRow();
	}
};

TestHtmlTranslator.prototype.possibleAnswersFullDetail = function(question, questionNo) {

	this.tableRow();
	this.header(OPTION, "3%", "top", "center", 0);
	this.header("", "92%", null, null, 2);
	this.header(CORRECT_ANSWER, "5%", null, "center", 0);
	// header( "Explanation", "20%" );
	this.endTableRow();

	var answers = question.getPossibleAnswers();
	for (var answerNo = 0; answerNo < answers.length; answerNo++) {
		var answer = answers[answerNo];
		this.tableRow();
		this.tableCell("propertyGeneralOutTable", answer.getLetter(), null, "", 0);
		var originalAnswer = answer.getAnswer();
		var explanation = originalAnswer.getExplanation() ? "<br><b>Explanation</b><br>" + originalAnswer.getExplanation() + "" : "";
		this.tableCell(
				"propertyGeneralOutTable",
				originalAnswer.getAnswerText() + explanation,
						null, null, 2);
		this.tableCellAnswer("correctSingleAnswer", questionNo, answerNo, "top", "center", 0, answer.isCorrect());
		// tableCell( "propertyGeneralOutTable", ) );
		this.endTableRow();
	}

};

TestHtmlTranslator.prototype.property = function(propertyCssClass, label, value, floatSide) {
	this.divWithStyle("labelPadding", "width:98%;float:left;");

	this.divWithText("labelFont labelDimensions", label, floatSide);
	this.divWithText(propertyCssClass, TestUtils.format(value), floatSide);

	this.endDiv();
};

TestHtmlTranslator.prototype.propertyWithId = function(propertyCssClass, label, value, id, floatSide) {
	this.divWithStyle("labelPadding", "width:98%;float:left;");

	this.divWithText("labelFont labelDimensions", label, floatSide);
	if (!id ) {
		this.divWithText(propertyCssClass, TestUtils.format(value),
				floatSide);
	} else {
		this.div(propertyCssClass);
		this.divWithTextAndId(propertyCssClass, id, value, floatSide);
		this.endDiv();
	}

	this.endDiv();
};

TestHtmlTranslator.prototype.propertyNoLabel = function(propertyCssClass, value) {
	this.divWithText(propertyCssClass, TestUtils.format(value), null);
};

TestHtmlTranslator.prototype.startCollectionProperty = function() {
	// TODO do we need two nested divs?
	this.div("collectionPropertyListLayoutPadding");
	this.div("collectionPropertyListLayoutBottomPadding");
};

TestHtmlTranslator.prototype.endCollectionProperty = function() {
	this.endDiv();
	this.endDiv();
};

TestHtmlTranslator.prototype.startTableCollectionProperty = function(cssClass) {
	this.div("collectionPropertyListLayoutPadding");
	this.div("collectionPropertyListLayoutBottomPadding");
	this.line("<table class=\"" + cssClass +"\">");
};

TestHtmlTranslator.prototype.endTableCollectionProperty = function() {
	this.line("</table>");
	this.endDiv();
	this.endDiv();
};

TestHtmlTranslator.prototype.header = function(text, width, valign, align, span) {
	this.line("<th " + (span > 0 ? "colspan=\"" + span + "\" " : "") +
			" class=\"\" style=\"width:" +
			width + ";\" align=" +
			(align ? "\"" + align + "\"" : "\"left\"") +
			" valign=" +
			(valign ? "\"" + valign + "\"" : "\"top\"") + "\">" +
			text + "</th>");
};

TestHtmlTranslator.prototype.tableCellStart = function(cssClass) {
	this.line("<td class=\"" + cssClass + "\" >");
}

TestHtmlTranslator.prototype.tableCellEnd = function() {
	this.line("</td>");
}

TestHtmlTranslator.prototype.tableCell = function(cssClass, text, valign, align, span) {
	if (!cssClass) {
		this.line("<td " + (span > 0 ? "colspan=\"" + span + "\" " : "") +
				" align=" +
				(align ? "\"" + align + "\"" : "\"left\"") +
				" valign=" +
				(align ? "\"" + align + "\"" : "\"top\"") + ">" +
				text + "</td>");
	} else {
		this.line("<td  " + (span > 0 ? "colspan=\"" + span + "\" " : "") +
				" class=\"" + cssClass + "\" align=" +
				(align ? "\"" + align + "\"" : "\"left\"") +
				" valign=" + (valign ? valign : "\"top\"") + ">" +
				text + "</td>");
	}
};

TestHtmlTranslator.prototype.tableCellWithDiv = function(divId, text, valign, align) {
	this.line("<td align=" + (align ? "\"" + align + "\"" : "\"left\"") +
			" valign=" +
			(align ? "\"" + align + "\"" : "\"top\"") +
			"><div id=\"" + divId + "\" name=\"" + divId +
			"\">" + text + "</div></td>");
};

TestHtmlTranslator.prototype.tableCellAnswer = function(id, questionNo, choiceNo, valign, align, span, checked) {
	var answerId = id + questionNo + "_" + choiceNo;
	this.line("<td " + (span > 0 ? "colspan=\"" + span + "\" " : "") + " align=" +
			(align ? "\"" + align + "\"" : "\"left\"") +
			" valign=" +
			(valign ? "\"" + valign + "\"" : "\"top\"") +
			"><img src=\"images/" + (checked ? "checked" : "unChecked") + ".gif\" name=\"" + answerId +
			"\" /></td>");

};


TestHtmlTranslator.prototype.recreateTest = function(testSummaryPage) {
	// test report div
	this.clearHtmlText();
	this.divWithIdAndStyle("testReport", "padding-top:10px;align:centre;width:80%;");
	this.property("propertyGeneralOut", "Student Full Name: ", testSummaryPage.user, "left");
	this.property("propertyGeneralOut", "Assessment On: ", testSummaryPage.courseName, "left");
	this.property("propertyDateOut", "Created Date: ", testSummaryPage.date, "left");
	this.propertyWithId("propertyValueDimensions", "Score: ", testSummaryPage.score,
			"score", "left");
	this.propertyWithId("propertyValueDimensions", "Assessment: ", testSummaryPage.assessment,
			"assessment", "left");

	//this.startCollectionProperty();
	this.startTableCollectionProperty("collectionPropertyTableStyle");
	this.header("","100%",null,null,0);
	this.tableRow();
	this.tableCellStart();
	var questions = testSummaryPage.questionSummaries;
	var userAnswers = testSummaryPage.getUserAnswers();
	for (var questionNo = 0; questionNo < questions.length; questionNo++) {
		var question = questions[questionNo];
		this.testQuestionViewForReport(question, questionNo, userAnswers);
	}

	this.tableCellEnd();
	this.endTableRow();	
	this.endTableCollectionProperty();
	//this.endCollectionProperty();
	//this.inputButton("Retry", "document.location.reload()");
	this.endDiv();
	return	this.getHtmlText();
};

TestHtmlTranslator.prototype.testQuestionViewForReport = function(question, questionNo, userAnswers) {
	if (question.type=="MULTIPLE_CHOICE") {
		this.multipleChoiceQuestionView(question, questionNo, userAnswers);
	} 

	else if (question.type=="ROMAN_NUMERAL") {
		this.romanNumeralQuestionView(question, questionNo, userAnswers);
	} 
};

TestHtmlTranslator.prototype.showError = function(text) {
	return "<div style='font-size:15pt;font-weight:900;text-align:center;padding-top:200px'>"
	+text+"</div>";
};
