

var timerID = null;


function InitializeTimer(secs, timer) {
	
	if (timer == 'Disabled') {
		StatusMessage(secs);
	} else {
		StartTheTimer(secs);
	}
}


function StartTheTimer(secs) {
	
	if (secs == 0) {
		location = '/user/logout';
	}
	else {
		secs          = secs - 1;
		time          = SecToTime(secs);
		window.status = time + ' minutes to automatic logout.';
		timerRunning  = true;
		timerID       = self.setTimeout("StartTheTimer("+ secs +")", 1000);
	}
}


function StatusMessage(secs) {
	
	if (secs == 0) {
		location = '/user/logout';
	} else {
		window.status = 'You have been logged out.';
		secs          = secs - 1;
		timerRunning  = true;
		timerID       = self.setTimeout("StatusMessage("+ secs +")", 1000);
	}
}

function SecToTime(sec)
{

//From JS FAQ by Liorean
Number.prototype.toDecimals=function(n){
n=(isNaN(n))?
2:
n;
var
nT=Math.pow(10,n);
function pad(s){
s=s||'.';
return (s.length>n)?
s:
pad(s+'0');
}
return (isNaN(this))?
this:
(new String(
Math.round(this*nT)/nT
)).replace(/(\.\d*)?$/,pad);
}
if(sec>59)
{
var hrs=sec/3600;
if(hrs<0)
{
hrs="00";
var min=hrs*60;
min=min.toDecimals(8);
var snd=min.substring(min.indexOf('.'),min.length);
min=min.substring('0',min.indexOf('.'));

if(min<10)
{
min='0'+min
}
snd=Math.round(snd*60);
if(snd<10)
{
snd='0'+snd;
}
var tm=hrs+':'+min+':'+snd;
}
else
{

hrs=hrs.toDecimals(8);
var min=hrs.substring(hrs.indexOf('.'),hrs.length)

hrs=hrs.substring('0',hrs.indexOf('.'));

if(hrs<10)
{
hrs='0'+hrs;
}
min=min*60
min=min.toDecimals(8);
var snd=min.substring(min.indexOf('.'),min.length);
min=min.substring('0',min.indexOf('.'));

if(min<10)
{
min='0'+min
}
snd=Math.round(snd*60);
if(snd<10)
{
snd='0'+snd;
}
var tm= min+':'+snd;
}
}
else
{
if(sec<10)
{
sec="0"+sec;
}
var tm="00:"+sec
}
return tm;
}
