var arCities = new Array();
var format24 = false;
var utcStartTime = 0;
var bShadowUpdate = false;

function addCity(dayID,timeID,offsetHours,offsetMins,altOffsetHours,altOffsetMins,altStartDay,altStartHours,altStartMins)
{
	arCities[arCities.length] = new City(dayID,timeID,offsetHours,offsetMins,altOffsetHours,altOffsetMins,altStartDay,altStartHours,altStartMins);
}

function updateGrid()
{
	var d = new Date();
	var utcDay = d.getUTCDay();
	var utcHours = d.getUTCHours();
	var utcMins = d.getUTCMinutes();

	if (bShadowUpdate)
	{
		var diff = ((utcHours * 60) + utcMins) - utcStartTime;
		if (diff < 0 || diff > 16)
			window.location.reload();
	}	

	var max = arCities.length;
	var count = 0;
	for (count = 0; count<max; count++)
	{
		arCities[count].calcLoaclTime(utcDay,utcHours,utcMins);
		arCities[count].updateDisplay(format24);
	}
}

function supportsUpdateing()
{
	// we need these to do the local time calcs
	var d = new Date();
	if (!d.getUTCDay || !d.getUTCHours || !d.getUTCMinutes)
		return false;

	// we need this to find the text to update
	if (!document.getElementById)
		return false;
	
	return true;
}

function checkSupportsUpdateing(messageID)
{
	if (supportsUpdateing())
	{
		var elem = document.getElementById(messageID);
		if (elem)
		{
//			elem.style.visibility = "hidden";
			elem.style.display = "none";
		}
	}
}

function startTimer(fmt,supdate)
{
//	debugger;

//	return;

	// check the client has the functions we need before starting the timer
	if (supportsUpdateing())
	{
		bShadowUpdate = supdate;
		format24 = fmt;
	
		if (bShadowUpdate)
		{
			var dStartTime = new Date();
			utcStartTime = (dStartTime.getUTCHours() * 60) + dStartTime.getUTCMinutes();
		}
		updateGrid();
		window.setInterval(updateGrid, 1000);
	}
}

function setTime(fmt,utcDay,utcHours,utcMins)
{
	// check the client has the functions we need before starting the timer
	if (supportsUpdateing())
	{
		format24 = fmt;
		var max = arCities.length;
		var count = 0;
		for (count = 0; count<max; count++)
		{
			arCities[count].calcLoaclTime(utcDay,utcHours,utcMins);
			arCities[count].updateDisplay(format24);
		}
	}
	else
		alert("You browser cannot support this page");
}

