/*******************************************************************************
	BI Learning Group
	Contact:	Kevin Heald		kevin.heald@biworldwide.com
	Date:		12.08.2004
	Refactored:	02.10.2006, 10.12.06 (for use with swfobject, elimination of fscommand)		Glen Giefer
	Requires:	APIWrapper.js, SCOFunctions.js
	Standard:	SCORM 1.2
	Data Model Support:	core mandatory elements & student_data.mastery_score
*******************************************************************************/

/* Debugger -------------------------------------------------------------------------------------*/
var flash_debug = false; // toggle (true/false)

//function executed whether from browser exit or flash exit
// use this function when minimal server communication is desired
// NOTE: This function need not be used if lesson sets these values to lms on page navigation
function exitX() {
	if (flash_debug) alert("exitX, objSCO is\n\n" + objSCO);
	
	var api = getAPIHandle();
	if (api != null) {
		//NOTE: scorm properties will be updated in javascript continuously as user navigates through module
		// Send tracking data to LMS
		LMSSetValue("cmi.core.lesson_status", objSCO.lesson_status);
		LMSSetValue("cmi.core.lesson_location", objSCO.lesson_location);
		LMSSetValue("cmi.core.score.raw", objSCO.raw_score);
		LMSSetValue("cmi.suspend_data", objSCO.suspend_data);
	}
}

//----------------------------------
// function called via getURL

// update javascript variable, optionally set value to lms and commit. 
// NOTE: Use appropriate exitSCO based on how values are set and committed. see SCOFunctions.js
// NOTE: isLast is parameter used for custom request to commit on last page of navigation but not on every page of nav
function setSCO(strProp, strOpts, strLoc, strSuspend, strScore, strStatus, isLast) {
	var arrProp = strProp.split(",");
	var arrOpts = strOpts.split(",");
	var set = (arrOpts[0].indexOf("1") != -1);
	var commit = (arrOpts[1].indexOf("1") != -1);
	isLast = (isLast == "1") ? true : false;

	if (flash_debug) {
		var str = "";
		for (var i = 0; i < arguments.length; i++) str += arguments[i] + "\n"; 
		alert("setSCO, arguments are:\n\n" + str + "\nset is " + set + ", commit is " + commit + ", isLast is " + isLast);
	}
	
	//Warning, be careful with arguments length and index into arguments!
	//prevent mismatch of arguments and properties
	if (arrProp.length != arguments.length-3) return;

	for (var i = 0; i < arrProp.length; i++) {
		objSCO[arrProp[i]] = arguments[i+2];
		if (set && lmsInitOk()) LMSSetValue(objLMS[arrProp[i]], objSCO[arrProp[i]]);
	}

	if (set && lmsInitOk()) {
		computeSCOTime();

		if (commit || isLast) LMSCommit();
	}
}

