OBJECTIVE = function() //pg2-objectives
{
	this.id = "";
	this.desc = "";
	this.isModule = false;
	this.initCompletion = "unknown";
	this.initSuccess = "unknown";
	this.scoreMin = 0;
	this.scoreMax = 100;
	this.score = this.scoreMin;
};

Objectives = function()
{
	this.objectivesList = new Array();
	this.count = 0;
	this.script = "";
};

Objectives.prototype.Add = function(id, isModule, initCompletion, initSuccess, scoreMin, scoreMax)
{
	var obj = new OBJECTIVE();
	obj.id = id;
	obj.isModule = isModule;
	obj.initCompletion = initCompletion;
	obj.initSuccess = initSuccess;
	obj.scoreMin = scoreMin;
	obj.scoreMax = scoreMax;
	obj.score = scoreMin;
	
	this.objectivesList[this.count++] = obj;
};

Objectives.prototype.Commit = function()
{
	//todo
	var str2Execute = "try { " + this.script + " } catch(e) {}; ";
	eval(str2Execute);
	
	for (var i=0; i<this.count; i++) {
		var obj = this.objectivesList[i];
		if (obj != null) {
			lms.LMSSetValue("cmi.objectives." + i + ".id", obj.id);
			lms.LMSSetValue("cmi.objectives." + i + ".completion_status", obj.initCompletion);
			lms.LMSSetValue("cmi.objectives." + i + ".success_status", obj.initSuccess);
			lms.LMSSetValue("cmi.objectives." + i + ".score.min", obj.scoreMin);
			lms.LMSSetValue("cmi.objectives." + i + ".score.max", obj.scoreMax);
			lms.LMSSetValue("cmi.objectives." + i + ".score.raw", obj.score);
			if (obj.score == 100) {
				lms.LMSSetValue("cmi.objectives." + i + ".score.scaled", "1.0");
			} else {
				lms.LMSSetValue("cmi.objectives." + i + ".score.scaled", "0." + obj.score);
			};
		};
	};
};

Objectives.prototype.Free = function()
{
	if (this.count > 0) {
		for (var i=this.count-1; i>=0; i--) {
			var obj = this.objectivesList[i];
			delete obj;
		};
	};
	delete this.objectivesList;
};

var objectives = new Objectives();
//
