var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var toggle = false;
var interval_id = 0;
var heartbeat_id = 0;

function PageSize() 
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	return myWidth;
}

function UpdateDisplay()
{
	document.getElementById('display_text').innerHTML = ((hours < 10) ? '0' : '') + hours + (toggle ? ':' : ' ') + (minutes < 10 ? '0' : '') + minutes;
}
	
function IncHour(hour)
{
	++hour;
	return (hour > 23) ? 0 : hour;
}
	
function OnMinutePulse()
{
	++minutes;
	if (minutes > 59) 
		{
		hours = IncHour(hours);
		minutes = 0;
		}
	UpdateDisplay();
}
	
function OnHeartBeat()
{
	toggle = !toggle;
	UpdateDisplay();
}

function ConvertFactorToMilliSec(n)
{
	return (60000 * n / 24);
}
	
function OnIncHour()
{
	hours = IncHour(hours);
	UpdateDisplay();
}
	
function OnIncMinute()
{
	OnMinutePulse();
}

function OnZeroMinute()
{
	minutes = 00;
	UpdateDisplay();
}
	
function OnZeroHour()
{
	hours = 12;
	minutes = 0;
	UpdateDisplay();
}

function DecHour(hour)
{
	--hour;
	return (hour < 0) ? 23 : hour;
}
	
function OnDecHour()
{
	hours = DecHour(hours);
	UpdateDisplay();
}
	
function DecMinute(minute)
{
	--minute;
	return (minute < 0) ? 59 : minute;
}

function OnDecMinute()
{
	minutes = DecMinute(minutes);
	UpdateDisplay();
}
	
function ResetHeartbeat()
{
	heartbeat_id = setInterval("OnHeartBeat()", 1000);
}
	
function SetScaleTimer()
{
	interval_id = setInterval("OnMinutePulse()", ConvertFactorToMilliSec(document.getElementById('factor').value));
}
	
function OnPauseResume()
{
	if  (heartbeat_id) 
	{
		clearInterval(interval_id);
		clearInterval(heartbeat_id);
		interval_id = 0;
		heartbeat_id = 0;
		toggle = true;
		UpdateDisplay();
		document.getElementById("pause_resume").value = "Resume";
	}
	else 
	{
		ResetHeartbeat();
		SetScaleTimer();
		document.getElementById("pause_resume").value = "Pause";
	}
}

function InitializePage()
{
	ResetHeartbeat();
	interval_id = setInterval("OnMinutePulse()", 60000);
}	

	