/* the array of questions */
questions = new Array();


/* class definition of question */

/* constructor is the correct answer as string */
function Question(correctAnswer){

	this.correct = correctAnswer;
	this.feedback = new Array();
	this.incorrectFeedback = null;
	
	this.setFeedback = function(answer, feedback){
		this.feedback[answer] = feedback;
	};
	
	this.setCorrectFeedback = function(corrFeed){
		this.feedback[this.correct] = corrFeed;
	}
	
	this.setIncorrectFeedback = function(wrongFeed){
		this.incorrectFeedback = wrongFeed;
	}
	
	this.getCssClass = function(answer){
		
		if(answer == null || answer.length == 0){
			return "notanswered";
		}else if(this.correct == answer){
			return "correct";
		}else{
			return "wrong";
		}
	}
	
	this.check = function(answer){
		if(this.feedback[answer]){
			return this.feedback[answer];
		}else if(answer == null || answer.length == 0){
			return 'You didn\'t answer this question';
		}else if(this.correct == answer){
				return 'Well done, <b>\'' + answer + '\'</b> is the correct answer.';
		}else{
				if(this.incorrectFeedback){
					return this.incorrectFeedback
				}else{
					return 'Sorry, <b>\'' + answer + '\'</b> is not the right answer.';
				}
		}
	};
}


/* this is the function that prints out the feedback window */

function yourscore(thetext, width, height)
{
if(!width) width='300';
if(!height) height='400'
var thefeedback=window.open('','gapfeedback','height='+height + ',width='+ width +',scrollbars=yes');
  
  thefeedback.document.write('<html><head><title>BBC Learning English | How to ... | Feedback</title>');
  thefeedback.document.write('<link rel="stylesheet" href="/worldservice/learningenglish/css/how_to.css">');
  thefeedback.document.write('</head><body class="dropdownfeedback">');
  thefeedback.document.write(thetext);
  thefeedback.document.write('<p><a href="/worldservice/learningenglish/grammar/how_to" onClick="self.close(); return false"> Close this window</a></p>');
  thefeedback.document.write('</body></html>');
  thefeedback.document.close();
}




function checkanswers(thegapfill, width, height) {
feedback = "";
feedback = "<h2>Feedback</h2><br/><b>How to ...</b>";

for(var i = 0; i < questions.length; i++){
	answer = thegapfill.elements['sel' + i].value;
	questionFeedback = questions[i].check(answer);
	feedback = feedback + '<p class="' + questions[i].getCssClass(answer)+ '">Q' + (i+1) + ': ' +  questionFeedback + "</p>";
}

yourscore(feedback, width, height);
}

