// Hack Claroline : suppression de la recherche scorm2004 car implémentation 2004 présente mais non aboutie.
if(scServices.scorm2k4) {
	scServices.scorm2k4.xInitScorm2k4 = function(){ return false;};
}

//optimisation : Désactivation des events unload inopérants sur Claroline
scServices.scorm12.onUnload = function(){};
scServices.suspendDataStorage.onUnload = function(){};
scServices.exitModeStorage.onUnload = function(){};
scServices.assmntMgr.onUnload = function(){};

//optimisation : Bug Scenari 3.4.1.02 : ajout de this._Dirty = false;
scServices.suspendDataStorage.commit = function() {
	if( ! this._Dirty) return;
	if(scServices.scorm2k4 && scServices.scorm2k4.isScorm2k4Active()) {
		var vApi = scServices.scorm2k4.getScorm2k4API();
		vApi.SetValue("cmi.suspend_data", scServices.dataUtil.serialiseObjJs(this._Fields));
		vApi.Commit("");
	} else if(scServices.scorm12 && scServices.scorm12.isScorm12Active()) {
		var vApi = scServices.scorm12.getScorm12API();
		vApi.LMSSetValue("cmi.suspend_data", scServices.dataUtil.serialiseObjJs(this._Fields));
		vApi.LMSCommit("");
	} else if(scServices.storage && scServices.storage.isStorageActive()) {
		scServices.storage.getStorage().setItem(scServices.storage.getRootKey()+"suspend_data", scServices.dataUtil.serialiseObjJs(this._Fields));
	}
	this._Dirty = false;
}

//Enregistrement régulier pour compenser l'echec durant l'évènement unload.
function clarolineCycle(){
	if(scServices.scorm12 && scServices.scorm12.isScorm12Active()) {
		var vApi = scServices.scorm12.getScorm12API();
		
		//en multi-SCO : on passe en completed, incomplete en mono-SCO
		var vStatus = vApi.LMSGetValue("cmi.core.lesson_status");
		if( ! vStatus || vStatus == "not attempted" ) vApi.LMSSetValue("cmi.core.lesson_status", scServices.storage ? "incomplete" : "completed");
		
		if(scServices.suspendDataStorage._Dirty) {
			vApi.LMSSetValue("cmi.suspend_data", scServices.dataUtil.serialiseObjJs(scServices.suspendDataStorage._Fields));
			scServices.suspendDataStorage._Dirty = false;
		}
		
		var vDur = new Date().getTime() - scServices.exitModeStorage._timeStart;
		var vH = vDur > 3600000 ? Math.floor(vDur / 3600000) : 0;
		var vM = Math.floor(vDur / 60000) % 60;
		var vS = Math.floor(vDur / 1000) % 60;
		var vMs = Math.round(Math.floor(vDur % 1000)/10);
		var vTime = (vH<10 ? "0"+vH : vH) + ":" + (vM<10 ? "0"+vM : vM) + ":" + (vS<10 ? "0"+vS : vS) + "." + (vMs<10 ? "0"+vMs : vMs);
		vApi.LMSSetValue("cmi.core.session_time", vTime);
		vApi.LMSSetValue("cmi.core.exit", "");
		
		vApi.LMSCommit("");
	}
}
window.setInterval(clarolineCycle, 5000);
