/*
 * Copyright (c) 2005 Absolutely Training Limited
 * 
 * Created on 10-Feb-2005
 *
 * @author roberto, fritzd
 */

//init
new Attempt();  
Attempt.prototype = new RTEDataObject();
Attempt.prototype.constructor = Attempt;

//constructor
function Attempt(){

	// navigation
	this.request ="_none_";
	this.request_valid = new Request_valid();
	this.completion_status = "unknown";
	// THIS HAS TO BE VALIDATED BEFORE SET IT IN THE CONSTRUCTOR
	this.completion_threshold = null;
	this._version = "1.0";
	this.credit = "credit";
	this.entry = "ab-initio";
	this.exit = "";
	this.launch_data = null;
	this.learner_id = null;
	this.learner_name = null ;
	this.location = null;
	this.comments = null;
	this.max_time_allowed = null;
	this.mode = "normal";
	this.progress_measure = null;
	this.scaled_passing_score = null;
	this.session_time = null;
	this.success_status = "unknown";
	this.suspend_data = "";
	this.time_limit_action = "continue,no message";
	this.total_time = "PT0H0M0S";
	this.score = new Score();
	this.learner_preference=new Learner_preference();
	this.student_data = new Student_data();
	this.core = new Core();
	this.interactions = new SCORMArray(new Interactions());
	this.objectives = new SCORMArray(new Objectives());
	this.comments_from_lms = new SCORMArray(new Comment("comments_from_lms"));
    this.comments_from_learner = new SCORMArray(new Comment("comments_from_learner"));
    this.propertiesArray = new Array("completion_status","completion_threshold",
            "credit","entry", "exit", "launch_data", "learner_id", "learner_name",
            "location", "comments","max_time_allowed", "mode", "progress_measure",
            "scaled_passing_score", "session_time", "success_status", "suspend_data",
            "time_limit_action", "total_time");
    this.objectsArray = new Array("score", "interactions", 
            "objectives", "comments_from_learner", "comments_from_lms", "student_data", "core", "request_valid");
    this.propertiesArrayForTest = new Array("completion_status");
	this.objectsArrayForTest = new Array("score", "interactions");
    this.type="cmi";
	this.validator = new Validator();	
}

Attempt.prototype.setCompletion_threshold = function(completion_threshold){
	return VariableInfo.ERROR_404;;
};

Attempt.prototype.setCompletion_status = function(completion_status) {
	if (!this.validator.listContainsState(this.validator.ATTEMPT_COMPLETION_STATUS_LIST, completion_status)){
		return VariableInfo.ERROR_406;
	}
	this.completion_status = completion_status;
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.set_version = function(version){
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setCredit = function(credit) {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setEntry = function(entry)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.getExit = function()  {
	return VariableInfo.ERROR_405;
};

Attempt.prototype.getSession_time = function()  {
	return VariableInfo.ERROR_405;
};

Attempt.prototype.setExit  = function(exit)  {
	if (!this.validator.listContainsState(this.validator.EXIT_STATUS_LIST, exit)){
		return VariableInfo.ERROR_406;
	}
	// TODO this may not be correct!
	if (exit == "time-out" || exit == "normal" || exit == "") {
		this.entry = "";
	} else if (exit=="suspend") {
		this.entry = "resume";
	} else if (exit=="logout") {
		this.entry = "resume";
	}
	this.exit = exit;
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.setLaunch_data = function(launch_data)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setLearner_id = function(learner_id)  {
	return VariableInfo.ERROR_404;

};

Attempt.prototype.setLearner_name = function(learner_name)  {
	return VariableInfo.ERROR_404;
	
};

Attempt.prototype.getRequest = function()  {
	return this.request;
};


Attempt.prototype.setLocation = function( location) {
	this.location = location;
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.setComments = function( comments) {
	this.comments = comments;
	return VariableInfo.NO_SET_ERROR;
};


Attempt.prototype.setMax_time_allowed = function(max_time_allowed)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setMode = function(mode)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setProgress_measure = function(progress_measure)  {
	if (!this.validator.validateReal(progress_measure))
		return VariableInfo.ERROR_406;
	else if (!this.validator.validateRange(progress_measure, "0", "1"))
		return VariableInfo.ERROR_407;

	else {
		this.progress_measure = progress_measure;
		return VariableInfo.NO_SET_ERROR;

	}
};

Attempt.prototype.setScaled_passing_score = function(scaled_passing_score)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setSession_time = function(session_time)  {
	if (!this.validator.validateTimeIntervalFormat(session_time))
		return VariableInfo.ERROR_406;
	this.session_time = session_time;
	//TODO now add it to the total time.
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.setSuccess_status = function(success_status)  {
	if (!this.validator.listContainsState(this.validator.OBJECTIVE_SUCCESS_STATUS_LIST, success_status)){
		return VariableInfo.ERROR_406;
	 }
	this.success_status = success_status;
	return VariableInfo.NO_SET_ERROR;
};

// TODO this may not be correct because the exit value may have change before I call this!
Attempt.prototype.getSuspend_data= function()  {
	if (this.suspend_data == null || !this.exit=="suspend") {
		this.suspend_data = null;
		return VariableInfo.ERROR_403;
	}
	return new VariableInfo("0", "", this.suspend_data);
};

Attempt.prototype.setSuspend_data = function(suspend_data) {
	this.suspend_data = suspend_data;
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.setTime_limit_action = function(time_limit_action)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setTotal_time = function(totalTime)  {
	return VariableInfo.ERROR_404;
};

Attempt.prototype.setRequest = function(request)  {
	this.request = request;
	return VariableInfo.NO_SET_ERROR;
};

Attempt.prototype.request = function(request)  {
	if (!this.validator.listContainsState(this.validator.NAVIGATION_REQUEST_LIST, request)){
		return VariableInfo.ERROR_406;
	 }
	this.request = request;
	return VariableInfo.NO_SET_ERROR;
	
};

