var arrWeight = new Array();
var arrScore = new Array();
var iCoursePassingScore = 100;
var iBookPassingScore = 100;
var arrBookName = new Array();
var arrBook;
var iTest = -1;
var iSCOLevel = 0;
var nTest = 0;
var nWeightedTest = 0;
var arrMaxTestScore     = new Array();
var arrGainedTestScore  = new Array();
var bQuestionBasedScoring = false;
function registerTest(weight)
{
	arrWeight[nTest] = weight;
	arrScore[nTest] = 0;
 arrGainedTestScore[nTest] = 0;
	nTest = nTest + 1;
	if (weight > 0)
		nWeightedTest = nWeightedTest + 1;
}
function trackScore(testIndex, score)
{
	arrScore[testIndex] = score;
	iTest = testIndex;
}
function setTestScore(testIndex, iMaxScore, iGainedScore)
{
    arrMaxTestScore[testIndex]    = iMaxScore;
    arrGainedTestScore[testIndex] = iGainedScore;
}
function isBookInTest(TestIndex)
{
	arrTestBook = arrBookName[TestIndex];
	for(j=0; j<arrTestBook.length; j++)
	{
		if(arrTestBook[j] == parent.strLaunchingSCOBook)
			return 1;
	}
	return 0;
}
function calScoreSCORM()
{
	var sum, nWeight;
	sum = 0;
	nWeight = 0;
	
	if (nWeightedTest == 0)
		return 0;
	if(parent.strLaunchingSCOBook != '')
	{
		for (i = 0; i < nTest; i++)
		{
			if(isBookInTest(i) == 1)
			{
				sum = sum + arrScore[i] * arrWeight[i];
				nWeight = nWeight + arrWeight[i];
			}
		}
		if(nWeight == 0)
			return 0;
		return Math.round(sum/nWeight);
	}
	for (i = 0; i < nTest; i++)
	{
		sum = sum + arrScore[i] * arrWeight[i];
		nWeight = nWeight + arrWeight[i];
	}
	if(nWeight == 0)
		return 0;
	return Math.round(sum / nWeight);
}
function calScore()
{
	var sum, nWeight;
	sum = 0;
	nWeight = 0;
	
	if (nWeightedTest == 0)
		return 0;
	for (i = 0; i < nTest; i++)
	{
		sum = sum + arrScore[i] * arrWeight[i];
		nWeight = nWeight + arrWeight[i];
	}
 return Math.round(sum/nWeight);
}
function isPassed()
{
	score = calScore();
	return score >= iCoursePassingScore;
}
function getNumberOfTest()
{
	if (iSCOLevel == 0)// COURSE LEVEL
	{
		var totalWeight = 0;
		for (i = 0; i < nTest; i++)
			totalWeight = totalWeight + arrWeight[i];
		if(totalWeight == 0)// If total weight = 0, the SCO will be treated as No Test
			return 0;
		return nTest;
	}
	else if (iSCOLevel == 1)// BOOK LEVEL
	{
		if(parent.strLaunchingSCOBook != '')
		{
			var num=0;
			var totalWeight = 0;
			for (i = 0; i < nTest; i++)
			{
				if(isBookInTest(i) == 1)
				{
					num = num + 1;
					totalWeight = totalWeight + arrWeight[i];
				}
			}
			if(totalWeight == 0)// If total weight = 0, the SCO will be treated as No Test
				return 0;
			return num;
		}
		return 0;
	}
	return 0;
} 
function isPassedSCORM()
{
	score = calScoreSCORM();
	if (iSCOLevel == 0)
	{
		return score >= iCoursePassingScore;
	}
	else if (iSCOLevel == 1)
	{
		return score >= iBookPassingScore;
	}
	return true;
}
