
function Assessment31()
{
	this.numAnswers = 0;
	this.ordered = false;
	this.chosenAnswers = null;
	this.correctAnswers = new Array();
	
	this.type = 31;
	
	return this;	
}

Assessment31.prototype = new BaseAssessmentContent();

// get answers from form and populate chosen answer array
Assessment31.prototype.collect = function( form )
{
	this.chosenAnswers = new Array();
	
	var ansValue = "";
	//alert('length = ' + form.elements.length);
	for (var i=0; i<form.elements.length; i++)
	{
		ansValue = eval("form.Answer" + (i+1) + this.contentID + ".value");
		
		if (ansValue == '') {    answerValue = '-1,-1'; }
        
        this.chosenAnswers[i] = ansValue;
        
    }
	
	return true;
}

Assessment31.prototype.collectPractice = function( form )
{
	return this.collect(form);
}

Assessment31.prototype.isMatch = function( obj, chosen )
{
	var clickX = "0";
	var clickY = "0";
	var coords = chosen.split(",");
	
	if ( coords[0] != null && coords[0] != "X" )
		clickX = parseInt( coords[0] );
	
	if ( coords[1] != null && coords[1] != "Y" )
		clickY = parseInt( coords[1] );
				
	var retVal = false;
	
	var minX = 0;
	var maxX = 0;
	var minY = 0;
	var maxY = 0;
	
	minX = obj.getX();
	maxX = minX + obj.getWidth();
	
	minY = obj.getY();
	maxY = minY + obj.getHeight();
	
	if ( (clickX >= minX) && (clickX <= maxX) && (clickY >= minY) && (clickY <= maxY) )
		retVal = true;
		
	return retVal;
}

// compare chosen answers with correct answers and score
Assessment31.prototype.score = function()
{
	var form = this.getFormRef( this.questionNumber );
	this.collect( form );
	
	return this.calculateScore();
}

Assessment31.prototype.calculateScore = function()
{
	
	var tcaScore	= 0;
	var tiaScore	= 0;
	var tqv			= 0;
	
	//alert( this.ordered );
	if (this.ordered)
	{
		var correctObj = null;
		var match = false;
		for (var i=0; i<this.correctAnswers.length; i++)
		{
			correctObj 	= this.correctAnswers[i];
			match 		= false;
			
			match = this.isMatch( correctObj, this.chosenAnswers[i] );
			if (match)
			{
				
				if ( correctObj.getCorrect() )
					tcaScore += correctObj.getWeight();
				else
					tiaScore += correctObj.getWeight();
					
			}
			
			tqv += correctObj.getWeight();			
		}
		
	}
	else
	{
		
		var correctObj = null;
		var match = false;
		for (var i=0; i<this.correctAnswers.length; i++)
		{
			correctObj 	= this.correctAnswers[i];
			match 		= false;
			
			for (var j=0; j<this.chosenAnswers.length; j++)
			{
				match = this.isMatch( correctObj, this.chosenAnswers[j] );
				if (match)
				{
					
					if ( correctObj.getCorrect() )
						tcaScore += correctObj.getWeight();
					else
						tiaScore += correctObj.getWeight();
					
					break;
				}
				
				// don't let them click all day
				if (j==this.correctAnswers.length-1)
					break;
			}
			
			tqv += correctObj.getWeight();
			
		}
			
	}
	
	var score = new AssessmentScore( tcaScore, tiaScore, tqv );
	this.setResult( score.getScore() );
	return score;
}


Assessment31.prototype.getOrdered = function()
{
	return this.ordered;
}

Assessment31.prototype.setOrdered = function( val )
{
	this.ordered = val;
}


Assessment31.prototype.getNumAnswers = function()
{
	return this.numAnswers;
}

Assessment31.prototype.setNumAnswers = function( val )
{
	this.numAnswers = val;
}
