var timerID = 0;
var tStart  = null;
var countUpdate = 0;
var userId = '';
var couresId = '';

function UpdateTimer() {
	if(timerID) {
		clearTimeout(timerID);
		clockID  = 0;
	}
	
	if(!tStart)
	tStart   = new Date();
	
	var   tDate = new Date();
	var   tDiff = tDate.getTime() - tStart.getTime();
	
	tDate.setTime(tDiff);
	
   	if (((tDate.getMinutes()*60 + tDate.getSeconds()) % 60) == 0)
   	{
   		setTimeout('AjaxUpdateServer("'+userId + '",' + courseId + ',1);',0);
   	}
   
   	timerID = setTimeout("UpdateTimer()", 1000);
}


function UpdateTimerFreeTrial() {
	if(timerID) {
		clearTimeout(timerID);
		clockID  = 0;
	}
	
	if(!tStart)
	tStart   = new Date();
	
	var   tDate = new Date();
	var   tDiff = tDate.getTime() - tStart.getTime();
	
	tDate.setTime(tDiff);
	
   	if (((tDate.getMinutes()*60 + tDate.getSeconds()) % 60) == 0)
   	{
   		//setTimeout('AjaxUpdateServer("'+userId + '",' + courseId + ',1);',0);
   		document.getElementById("timer").innerHTML = tDate.getMinutes();
   	}
   
   	timerID = setTimeout("UpdateTimerFreeTrial()", 1000);
}


function StartTimer(userid, courseid) {
	userId = userid;
	courseId = courseid;
	countUpdate = 0;
	AjaxUpdateServer(userId, courseId, 0);
	tStart   = new Date();	
	timerID  = setTimeout("UpdateTimer()", 1000);
}

function StopTimer() {
	if(timerID) {
		clearTimeout(timerID);
		timerID  = 0;
	}
	tStart = null;
}

function ResetTimer() {
	tStart = null;
}

