<?xml version="1.0" encoding="windows-1251"?>
<rmml>
<!--
-->
<composition name="CSCORMSupport">
	<script><![CDATA[

	/* Evgenei */
		this.newTotalResult=0;
		this.startDuration=0;
		this.finishDuration=0;
		this.totalSteps=0;
		this.totalStepsCurScene=0;
		this.curStep = 0;
		this.curScene = 0;
		this.scenes = new Array();
		this.countScenes=0;
		this.countModuleScenes=0;
	/**/

		this.startTime = 0;

		this.attemptAbsoluteDurationLimit = 0;
		this.timeLimitAction = null;
		this.completionThreshold = -1;

		this.SCORM = null;
		this.CMI_completion_status = "";
		this.CMI_success_status = "";
		this.CMI_completion_threshold = "";
		this.CMI_progress_measure = "";
		this.CMI_exit = "";

		//	начальная инициализация
		function initializeScormSupport(){
			this.SCORM = API_1484_11;

			var newDate = new Date();
			this.startHours = newDate.getHours();
			this.startMinutes = newDate.getMinutes();
			this.startSeconds = newDate.getSeconds();

	trace(this.startHours + ":" + this.startMinutes + ":" + this.startSeconds);

			this.SCORM.Initialize("");
		//	cmi.completion_status
			//this.CMI_completion_status = this.SCORM.GetValue("cmi.completion_status");
			this.CMI_completion_status = "incomplete";
			this.SCORM.SetValue("cmi.completion_status", this.CMI_completion_status);

		//	completed, incomplete, not_attempted, unknown
			this.CMI_completion_threshold = this.SCORM.GetValue("cmi.completion_threshold");
			//this.completionThreshold = 0.75;
		//	float
			this.CMI_progress_measure = this.SCORM.GetValue("cmi.progress_measure");
		//	float
			this.CMI_exit = this.SCORM.GetValue("cmi.exit");
		//	причина выхода: timeout, suspend, logout, normal, _nil_
			//var CMI_max_time_allowed = this.SCORM.GetValue("cmi.max_time_allowed", "");
			/* Evgenei */
			var startDate = new Date();
			startDuration = startDate.getHours()*3600 + startDate.getMinutes()*60 + startDate.getSeconds();
			/**/
			this.countModuleScenes = Player.module.scenes.length;
		}

		/*Evgenei */
		// устанавливается порог завершения, если не используем этапы
		function setCompletionThreshold(acompletionThreshold)
		{
			this.completionThreshold = acompletionThreshold;
		}

		function updateResutlsValues(anewTotalResult)
		{
			this.updateResutlsValues();
			this.newTotalResult = anewTotalResult;
			//trace("#FF0000 results=" + this.newTotalResult);
		}

		function updateResutlsValues()
		{
			var finishDate = new Date();
			this.finishDuration = finishDate.getHours()*3600 + finishDate.getMinutes()*60 + finishDate.getSeconds();
		}

		function getTotalDuration()
		{
			return finishDuration-startDuration;
		}

		function setCountModules(aTotalModules)
		{
			this.countModuleScenes = aTotalModules;
			trace("#FF0000 countModuleScenes=" + this.countModuleScenes);
		}

		// функции с этапами
		function setTotalSteps(aTotalSteps)
		{
			this.totalStepsCurScene=aTotalSteps;
			this.totalSteps = aTotalSteps;
		}


		// функция для добавления этапов, при загрузке новой сцены в модуле
		function addSteps(aiScene, aSteps)
		{
			this.totalStepsCurScene = aSteps;
			for(i=0;i<this.countScenes;i++)
			{
				if(this.scenes[i][0]==aiScene)
				{
					this.curScene = i;
					return false;
				}
			}
			var sceneSteps = new Array();
			sceneSteps[0]=aiScene; // номер сцены
			sceneSteps[1]=0; // номер этапа
			sceneSteps[2]=new Array(); // номер этапа
			sceneSteps[2][0]=0;
			this.scenes[this.countScenes]=sceneSteps;
			this.curScene = this.countScenes;
			//trace("#FF0000 curStepScene=" + this.scenes[this.curScene][1] + " " + this.curScene);
			this.countScenes++;
			this.totalSteps += aSteps;
			trace("#FF0000 totalSteps=" + this.totalSteps);
		}

		function setCurrentStep(aStep)
		{
			this.curStep = aStep;
		}

		function incStep(numStep)
		{
			trace("#000000 numStep=" + numStep);
			if(numStep==0)
				return;
			if(this.totalStepsCurScene>this.scenes[this.curScene][1])
			{
				for(var i=0;i<this.totalStepsCurScene && numStep!=undefined && this.scenes[this.curScene][2][i]!=undefined;i++)
				{
					if(this.scenes[this.curScene][2][i]==numStep)
						return;
				}
				this.scenes[this.curScene][2][this.scenes[this.curScene][1]]=numStep;
				this.scenes[this.curScene][1]++;
				this.curStep++;
				this.updateResutlsValues();
			}
			trace("#0000FF curStep=" + this.curStep);
		}

		/*function incStep()
		{
			trace("#FF0000 numStep=ttttttttt");
			//trace("#FF0000 curStepScene=" + this.scenes[this.curScene][1] + " " + this.totalStepsCurScene);
			//trace("#FF0000 this.scenes=" + this.scenes);
			if(this.totalStepsCurScene>this.scenes[this.curScene][1])
			{
				this.scenes[this.curScene][1]++;
				this.curStep++;
			}
			trace("#FF0000 curStep=" + this.curStep);
		}*/
		/**/

		function updateScormValues(){
			//if(scene){
	trace("NEW TOTAL == " + newTotalResult);
				//trace("#FF0000 cmi.progress_measure=" + newTotalResult);
				if (!isNaN(newTotalResult))
					this.SCORM.SetValue("cmi.progress_measure", (newTotalResult).toString());
				this.SCORM.SetValue("cmi.session_time", this.convertIntegerToScormFormat(this.getTotalDuration()));

				if(this.CMI_completion_status != "completed"){
					if(this.completionThreshold > 0){
						if(newTotalResult==0 && this.totalSteps>0)
						{
							newTotalResult = this.curStep/this.totalSteps;
						}
						if(newTotalResult>0.54)
						{
							this.CMI_success_status = "passed";
						}
						else
						{
							this.CMI_success_status = "failed";
						}
						this.SCORM.SetValue("cmi.success_status", this.CMI_success_status);
						if(newTotalResult >= this.completionThreshold){
							//trace("#FF0000 !!!!!!!!!!!!!!!!!!!!!");
							this.CMI_completion_status = "completed";
							this.SCORM.SetValue("cmi.completion_status", this.CMI_completion_status);
						}
					} else {
						if(this.curStep==this.totalSteps)
						{
							this.CMI_success_status = "passed";
							this.SCORM.SetValue("cmi.success_status", this.CMI_success_status);
							//trace("#FF0000 !!!!!!!!!!!!!!!!!!!!!");
							this.CMI_completion_status = "completed";
							this.SCORM.SetValue("cmi.completion_status", this.CMI_completion_status);
						}
						else
						{
							this.CMI_success_status = "failed";
							this.SCORM.SetValue("cmi.success_status", this.CMI_success_status);
						}
					}
				}
	//trace("cmi.completion_status == " + this.CMI_completion_status);
			//}
		}

		function uninitializeScormSupport(){
			this.SCORM.Commit("");
			this.SCORM.Terminate("");
			this.SCORM = null;
		}

		function convertDateToScormFormat(obj){
			if(obj){
				var seconds = obj.getSeconds();
				var minutes = obj.getMinutes();
				var hours = obj.getHours();
				var resultString = "PT" + hours + "H" + minutes+ "M" + seconds + "S";
				return resultString;
			}
		}

		function convertIntegerToScormFormat(secondsValue){
			if(secondsValue){
				var seconds = secondsValue % 60;
				var minutes = parseInt(((secondsValue - seconds)/60) % 60);
				var hours = parseInt(((secondsValue - minutes*60) - seconds)/3600);
				var resultString = "PT" + hours + "H" + minutes+ "M" + seconds + "S";
				return resultString;
			}
			return "PT0H0M0S";
		}
		function finish()
		{
			this.countScenes=this.countModuleScenes;
			this.saveAndUninitScorm();
		}
		function saveAndUninitScorm()
		{
			if(this.SCORM==null)
				return;
			//trace("countModuleScenes="+this.countModuleScenes);
			if(this.countScenes<this.countModuleScenes)
				return;
			trace("SAVE AND TERMITATE SCROM");
			this.updateScormValues();
			this.uninitializeScormSupport();
			if(Player.globals!=null && Player.globals.scorm!=null)
				Player.globals.scorm=null;
		}
	]]></script>
	<script event="Player.module.onUnload"><![CDATA[
		/*if(Player.globals.scorm!=null)
		{*/
			this.finish();
		//}
	]]></script>
</composition>
</rmml>