<!--AUFunctions.js-->

var statusflag_;

function oFFD(ssc_)
{
	this.iTempo = this.iTempo - (ssc_*1000);
}

function oTempo()
{
	oR_ = new Date();
	
	if (this.fPausa == false)
	{
		this.fTempo = oR_.getTime();
	}
	else
	{
		this.fTempo = 0 + this.mTempo;
	}
	
	tt_ = this.fTempo - (this.iTempo + this.pTempo);
	
	tt_ = Math.floor(tt_/1000);
	
	if (tt_ > 86400)
	{
		tt_ = 86399;
	}
	
	oR_ = new Date(oR_.getFullYear(), 0, 1, 0, 0, tt_);
	
	Hh_ = oR_.getHours();
	Nn_ = oR_.getMinutes();
	Ss_ = oR_.getSeconds();
	
	if (Ss_ <= 9){Ss_ = "0" + Ss_;}
	
	if (Nn_ <= 9){Nn_ = "0" + Nn_;}
	
	if (Hh_ <= 9){Hh_ = "" + "0" + Hh_;}
	//if (Hh_ > 9 && Hh_ <= 99){Hh_ = "" + "00" + Hh_;}
	//if (Hh_ > 99 && Hh_ <= 999){Hh_ = "" + "0" + Hh_;}
	
	this.cTempo = Hh_ + ":" + Nn_ + ":" + Ss_;
	
	return this.cTempo;
}

function oReset()
{
	this.iData = new Date();
	this.iTempo = this.iData.getTime();
	
	this.mTempo = 0;
	this.pTempo = 0;
	this.fTempo = 0;
	this.cTempo = 0;
	
	this.fPausa = false;
}

function oPause()
{
	if (this.fPausa == false)
	{
		this.iData = new Date();
		
		this.mTempo = this.iData.getTime();
		this.fPausa = true;
	}
}

function oUnPause()
{
	if (this.fPausa == true)
	{
		this.iData = new Date();
		this.pTempo += this.iData.getTime() - this.mTempo;
		
		this.mTempo = 0;
		this.fPausa = false;
	}
}

function Orologio()
{
	this.iData = new Date();
	
	this.iTempo = 0;
	
	this.mTempo = 0;
	this.pTempo = 0;
	
	this.fTempo = 0;
	this.cTempo = 0;
	
	this.fPausa = false;
	
	this.Azzera = oReset;
	
	this.Riprendi = oUnPause;
	
	this.Pausa = oPause;
	
	this.Tempo = oTempo;
	
	this.FFD = oFFD;
}

function startTimer(){
	iOrologio.Azzera();
}
 
function stopTimer(){
	tLocal = iOrologio.Tempo();
}

function completa(){
	stopTimer();
	SetCompleto(tLocal);
	//LMSFinish();
}

function CompletaLezione(idlez){
	stopTimer();
	SetLessonLocation(idlez+1,'1')
	LMSFinish();
}

function inizializza(){
	startTimer();
	SetIniziato();
}

function regTime(){
	stopTimer();
	SetTime(tLocal);
	//LMSFinish();
}

function onlyTime(){
	//LMSInitialize();
	startTimer();
}

function GetTime() {
	var Time_="";
	Time_=LMSGetValue( "cmi.core.session_time");
	return Time_;
}

function TimeManager() {
	tLocal = iOrologio.Tempo();
	//iOrologio.Azzera();
	return tLocal;
}

function GetScore() {
	var Score_="";
	Score_=LMSGetValue( "cmi.core.score.raw");
	return Score_;
}

function GetStatus() {
	var Status_="";
	Status_=LMSGetValue( "cmi.core.lesson_status");
	return Status_;
}
function GetLessonLocation() {
	var LessonLocation_="";
	LessonLocation_=LMSGetValue( "cmi.core.lesson_location");
	return LessonLocation_;
}





/*******************************************************************************
** SG Functions
*******************************************************************************/

function SetIniziato()
{
/*	
   // Se lo stato attuale dell'AU non è COMPLETED lo pone uguale a INCOMPLETE
   // Nel caso in cui lo stato debba essere comunque sovrascritto, usare SGSetStatus()

   LMSInitialize();
   var old_status = LMSGetValue( "cmi.core.lesson_status" );
   UCold_status=old_status.toUpperCase();
   if (UCold_status != "COMPLETED" && UCold_status!="INCOMPLETE" && UCold_status != "C" && UCold_status!="I")
   
   {
	   status_="incomplete";
	   statusflag_=status_;
	   LMSSetValue( "cmi.core.lesson_status", "incomplete" );
   }

   LMSCommit();
   
*/
}

function SetCompleto(t)

// t è il tempo di permanenza

{
	SetStatus("completed");	
	SetTime(t)
}

function SetTime(t)
{
  if (statusflag_=='C' || statusflag_=='completed') 
   	status_='C';
   
   
   time_=t;
   LMSSetValue("cmi.core.session_time", t);
 
   LMSCommit();
   
   //LMSSetValue("cmi.core.session_time", 0); 
 
}

function SetStatus( status )

// Pone lo stato dell'AU = al contenuto della variabile "status"
// "status" può assumere i valori: passed, failed, browsed, completed, incomplete

{
   
   if (statusflag_=='C' || statusflag_=='completed') 
   	status_='C';
   else 
   	status_=status;
   	
   statusflag_=status_; 
   
	
	
   	LMSSetValue( "cmi.core.lesson_status", status );
   	
   	LMSCommit();
   	
   

}

function SetLessonLocation(lessonlocation){
	
   	lessonlocation_=lessonlocation;
   	LMSSetValue( "cmi.core.lesson_location", lessonlocation);	   
   	LMSCommit();
}

// -----------------------------------------

function SetScore( score )
{
      
   if (statusflag_=='C' || statusflag_=='completed') 
   	status_='C';
   
   score_=score;
   //alert (score_);
   LMSSetValue( "cmi.core.score.raw", score );
   LMSCommit();
  


}

// -----------------------------------------





function SGComm(status, score, elapsedtime, urlnext)

{
	
	
   LMSInitialize();

   // status	
      
   if (status != '')
   {
	   LMSSetValue( "cmi.core.lesson_status", status );
   }


   // score	
   
   if (score != '')
   {
	   LMSSetValue( "cmi.core.score.raw", score );
   }


   // time	
   
   if (elapsedtime != '')
   {
	   LMSSetValue("cmi.core.session_time", elapsedtime);
   }


   // urlnext	
   
   if (urlnext != '')
   {
		document.location.replace(urlnext);
   }

   LMSCommit();

   LMSFinish();
	
}

