


/*******************************************************************************
**
** Object: TRACKING_MAP_OBJECT
**
** Description:
**	This is all the mapping information for tracking
**	it includes scorm variables and other tracking types
**	supported by Epic
**
** 18.06.07 	mp 	safari bug, error unless object member functions are anonymous, 
**					made all func anonymous
**
*******************************************************************************/
// set the SCO variables
var API_MAPPING = {
	/*******************************************************************************
	**	Supported variables and validation function
	*******************************************************************************/
	// list of tracking types supported - future methods: "scorm 2004", "AICC", "cookie"
	methods:			new Array( "scorm 1.2" ),
	method:				"scorm 1.2",

	// list of all the variable mappings in an array
	variables:			new Array(),

	/*******************************************************************************
	**	Variable functions
	*******************************************************************************/
	tracking_object:	function (inName, inType, inNullValue, inVocabulary)
				{
					if (DEBUG)
					{
						DEBUG.lert("new tracking_object(inName: " + inName + ", inType: " + inType + ", inNullValue: " + inNullValue + ", inVocabulary: " + inVocabulary + "):",1, false, false, "API_MAPPING")
					}

					// holder for the above details
					this.name 		= inName;	// name of the variable been setup
					this.value 		= "";		// text value of variable
					this.type 		= inType; 	// type of variable r,w,rw
					this.nullValue 		= inNullValue	// variables null value
					this.vocabulary 	= ""; 		// array of vocab values
					this.active 		= true;
					if(inVocabulary)
					{
						this.vocabulary = inVocabulary; // vocab list, or string definition
					}
				},
	set_scorm_method:	function ( inMethod )
				{

					this.debugMessage("set_scorm_method(inMethod: " + inMethod + ")",1,this,true)
					// If using the scorm 1.2 mapping
					if( this.method == "scorm 1.2" )
					{
						// child node
						this.variables["_children"]			= new this.tracking_object( "cmi._children", "r" );
						// core variables
						this.variables["core_children"]			= new this.tracking_object( "cmi.core._children", "r" );
						this.variables["core_student_id"]		= new this.tracking_object( "cmi.core.student_id", "r" );
						this.variables["core_student_name"] 		= new this.tracking_object( "cmi.core.student_name", "r" );
						this.variables["core_credit"]	 		= new this.tracking_object( "cmi.core.credit", "r", ["credit","no-credit"] );
						this.variables["core_entry"]			= new this.tracking_object( "cmi.core.entry", "r", ["ab-initio","resume"] );
						this.variables["core_total_time"]		= new this.tracking_object( "cmi.core.total_time", "r" );
						this.variables["core_session_time"]		= new this.tracking_object( "cmi.core.session_time", "w", "Time[hh:mm:ss]" );
						this.variables["core_lesson_mode"]		= new this.tracking_object( "cmi.core.lesson_mode", "r", ["browse","normal","review"] );
						this.variables["core_lesson_location"]		= new this.tracking_object( "cmi.core.lesson_location", "rw" );
						this.variables["core_lesson_status"] 		= new this.tracking_object( "cmi.core.lesson_status", "rw", ["passed","completed","failed","incomplete","browsed","not attempted","error text 986"] );
						this.variables["core_exit"]	 		= new this.tracking_object( "cmi.core.exit", "w", ["time-out","suspend","logout",""] );
						// core score variables
						this.variables["core_score_children"] 		= new this.tracking_object( "cmi.core.score._children", "r" );
						this.variables["core_score_raw"]		= new this.tracking_object( "cmi.core.score.raw", "rw", "Int[0-100]" );
						this.variables["core_score_max"] 		= new this.tracking_object( "cmi.core.score.max", "rw", "Int[0-100]");
						this.variables["core_score_min"]		= new this.tracking_object( "cmi.core.score.min", "rw", "Int[0-100]");
						// suspend data
						this.variables["suspend_data"] 			= new this.tracking_object( "cmi.suspend_data", "rw" );
						// launch data
						this.variables["launch_data"]			= new this.tracking_object( "cmi.launch_data", "r" );
						// comments
						this.variables["comments"]			= new this.tracking_object( "cmi.comments", "rw" );
						this.variables["comments_from_lms"] 		= new this.tracking_object( "cmi.comments_from_lms", "r" );
						// student data
						this.variables["student_data_children"] 	= new this.tracking_object( "cmi.student_data._children", "r" );
						this.variables["student_data_mastery_score"] 	= new this.tracking_object( "cmi.student_data.mastery_score", "r" );
						this.variables["student_data_max_time_allowed"] = new this.tracking_object( "cmi.student_data.max_time_allowed", "r" );
						this.variables["student_data_time_limit_action"]= new this.tracking_object( "cmi.student_data.time_limit_action", "r" );
						// student preference
						this.variables["student_preference_children"] 	= new this.tracking_object( "cmi.student_preference._children", "r" );
						this.variables["student_preference_audio"]	= new this.tracking_object( "cmi.student_preference.audio", "rw" );
						this.variables["student_preference_language"] 	= new this.tracking_object( "cmi.student_preference.language", "rw" );
						this.variables["student_preference_speed"] 	= new this.tracking_object( "cmi.student_preference.speed", "rw" );
						this.variables["student_preference_text"]	= new this.tracking_object( "cmi.student_preference.text", "rw", [-1, 0, 1] );
					} // end of scorm 1.2 mapping
					else
					{
						this.debugMessage("set_scorm_method(), this.method != 'scorm 1.2'",2,this,true)
					}
				},

	/*******************************************************************************
	**	Variable functions
	*******************************************************************************/

	// function to check the value is valid within the vocab
	checkVocabulary: 	function ( inMapName, inValue )
				{
					this.debugMessage("checkVocabulary( inMapName: " + inMapName + ", inValue: " + inValue + " )",1,false,false)
					// check if variable exists
					var trackingVariable = this.getTrackingObject(inMapName);
					if( trackingVariable == null ) return false;
					// if no vocab, return true
					var vocab = trackingVariable.vocabulary;
					if( vocab == "" ) return true;
					// if array...
					if( vocab.typeOf == "Array" )
					{
						var validMatch = false;
						for( var i = 0; i < vocab.length; i++ )
						{
							if( vocab[i] == inValue )
							{
								validMatch = true;
							}
						}
						return validMatch;
					}
					else
					{
						// if is int[0-100] validate...
						// if time value, validate...
						// check string
						return true;
					}
				},
	// function to check if the variable is readable and writeable
	isReadable: 		function ( inMapName, isWritable )
				{
					this.debugMessage("checkVocabulary( inMapName: " + inMapName + ", isWritable: " + isWritable + " )",1, false, false)
					// check if variable exists
					var trackingVariable = this.getTrackingObject(inMapName);
					if( trackingVariable == null ) return false;
					// if readable, return true
					var objectType = trackingVariable.type;
					if( objectType == "" ) return false;
					// otherwise check value matches the options
					var validMatch = false;
					if( isWritable ) 	var matchValue = "w";
					else			var matchValue = "r";
					for( var i = 0; i < objectType.length; i++ )
					{
						if( objectType.substr(i,1).toLowerCase() == matchValue )
						{
							validMatch = true;
						}
					}
					return validMatch;
				},
	// function to get the name of the variable, from the relevant object
	variableName: 		function ( inMapName )
				{
					this.debugMessage("checkVocabulary( inMapName: " + inMapName + " )",1, false, false)
					// get tracking object
					var myTackingObject = this.getTrackingObject(inMapName);
					// get varaible name
					if( myTackingObject == null )
					{
						return null;
					}
					else
					{
						return myTackingObject.name;
					}
				},
	// function to find a tracking object with a specific Mapping name
	getTrackingObject:	function ( inMapName )
				{
					this.debugMessage("getTrackingObject( inMapName: " + inMapName + " )",1, false, false)
					// check if found
					if( inMapName == "" || inMapName == null )
					{
						return null;
					}
					// check if variable exists
					if( this.variables )
					{
						if( this.variables[inMapName] )
						{
							return this.variables[inMapName];
						}
					}

					this.debugMessage("getTrackingObject():: Failed to find requested object, returning null.",2, false, false)
					// otherwise return null
					return null;
				},
	// isActive

	// Debug messages are piper off to the debug object.
	debugMessage:	function (inText, priority, whatObj, showCallee)
				{
					if (DEBUG)
						DEBUG.lert(inText, priority, whatObj, showCallee, "API_MAPPING")
				}

} // end of EPIC_TRACKING function/object

API_MAPPING.debugMessage("API_MAPPING INITIALIZED.",0)
API_MAPPING.debugMessage("Object:",1,API_MAPPING,true)

// set the method of tracking that will be used
API_MAPPING.set_scorm_method();

/*******************************************************************************
** initialize lms
*******************************************************************************/
	var lmsResult = doLMSInitialize();
	if ((lmsResult == "true") || (lmsResult == true))
	{
		LMSAvailable = true;
	}
	else
	{
		LMSAvailable = false;
	}
