function handleHttpResponse() {

	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
		try
		{
			// Use the XML DOM 
			var xmlDocument = http.responseXML; 
			var next;
			next = 0;

			var nflscores = xmlDocument.getElementsByTagName('nflscores').item(0);
			var nfl_week = nflscores.getAttribute('week');
			var game =  xmlDocument.getElementsByTagName('game').item(next);

			while (game)
			{
				var gid     = game.getAttribute('id');
				var away    = game.getAttribute('away_score');
				var home    = game.getAttribute('home_score');
				var status  = game.getAttribute('status');
				var box     = game.getAttribute('box');
				var recap   = game.getAttribute('recap');
				var preview = game.getAttribute('preview');

				var away_shown = document.getElementById('AS' + gid);
				if (away_shown)
				{
					away = away + '&nbsp;';
					if (away_shown.innerHTML != away) away_shown.innerHTML = away;
				}

				var home_shown = document.getElementById('HS' + gid);
				if (home_shown)
				{
					home = home + '&nbsp;';
					if (home_shown.innerHTML != home) home_shown.innerHTML = home;
				}

				var status_shown = document.getElementById('ST' + gid);
				if (status_shown)
				{
					var line = '';

					if (LinkStyle == 0)	{

						if (preview == 'Y') 
						    line = line + '<a class=whiteLink href=/php/nfl-content.php?ITEM=9&LN=' + LeagueNumber + '&UID=' + UniqueID +
							 	          '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Preview</a> | ';

						if (box == 'Y') 
						    line = line + '<a class=whiteLink href=/php/nfl-content.php?ITEM=6&LN=' + LeagueNumber + '&UID=' + UniqueID +
							  		      '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Box Score</a> | '; 

						if (recap == 'Y') 
						    line = line + '<a class=whiteLink href=/php/nfl-content.php?ITEM=8&LN=' + LeagueNumber + '&UID=' + UniqueID +
							   		      '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Recap</a> | '; 

						line = line + status;

					} else if (LinkStyle == 1) {

						var find_year = /, 2006/;
						status = status.replace(find_year,"");

						if (preview == 'Y') 
							line = line + '<a target=_top class=headerLinks href=' +
							              '/php/nfl-content.php?ITEM=9&LN=' + LeagueNumber + '&UID=' + UniqueID +
							              '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Preview</a> | '; 
						if (box == 'Y') 
							line = line + '<a target=_top class=headerLinks href=' +
							              '/php/nfl-content.php?ITEM=6&LN=' + LeagueNumber + '&UID=' + UniqueID +
							              '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Box Score</a> | '; 
						if (status == 'Final') {
							if (recap == 'Y') 
								line = line + '<a target=_top class=headerLinks href=' +
											  '/php/nfl-content.php?ITEM=8&LN=' + LeagueNumber + '&UID=' + UniqueID +
											  '&NFL_WEEK=' + NFLWeek + '&GID=' + gid + '>Final</a>'; 
							else 
								line = line + 'Final';
						} else {
							line = line + status;
						}

					} else if (LinkStyle == 3) {

						var find_year = /, 2006/;
						status = status.replace(find_year,"");

						if (status == 'Final') {
                     line = line + 'Final';
						} else {
							line = line + status;
						}

					} 

					if (status_shown.innerHTML != line) status_shown.innerHTML = line;
				}


				game = xmlDocument.getElementsByTagName('game').item(++next);
			}

			var topdate = document.getElementById('TopCurrDate');
			if (topdate) {
				var update = xmlDocument.getElementsByTagName('update').item(0);
				if (update) topdate.innerHTML = update.firstChild.data;
			}

			isWorking = false;    

			timerID = setTimeout("UpdateScores()", RefreshRate + Math.floor(Math.random() * 5));

			clearTimeout(WatchDogTimer);
			WatchDogTimer = setTimeout("RefreshPage()", RefreshRate * 2);
		}
		catch (e)
		{
			RefreshPage();
		}

		} else {
			//  invalid xml
			RefreshPage();
		}
	}
}

function UpdateScores() 
{
	if (NFLWeek && !isWorking && http) {
		try
		{
			http.open("GET", "/php/nfl-scores-provider.php?NFL_WEEK=" + escape(NFLWeek), true);

			http.onreadystatechange = handleHttpResponse;
			isWorking = true;
			http.send(null);
		}
		catch (e)
		{
			RefreshPage();
		}
	}
}

function RefreshPage()
{
	document.RefreshForm.submit();
}

function SetWeek(LN,UID,Style,Week)
{
   LeagueNumber = LN;
	UniqueID = UID;
	LinkStyle = Style;
	NFLWeek = Week;

	if (http) {
	   //  set the refresh timer and an emergency timer
	   RefreshTimer = setTimeout("UpdateScores()", RefreshRate);
	   WatchDogTimer = setTimeout("RefreshPage()", RefreshRate * 2);
	} else {
	   //  apparently does not support XMLHTTPRequest
	   ReloadTimer = setTimeout("RefreshPage()", RefreshRate);
	}
}

function SetPublicWeek(Week)
{
   LeagueNumber = 0;
	UniqueID = '';
	LinkStyle = 3;
	NFLWeek = Week;

	if (http) {
	   //  set the refresh timer and an emergency timer
	   RefreshTimer = setTimeout("UpdateScores()", RefreshRate);
	   WatchDogTimer = setTimeout("RefreshPage()", RefreshRate * 2);
	} else {
	   //  apparently does not support XMLHTTPRequest
	   ReloadTimer = setTimeout("RefreshPage()", RefreshRate);
	}
}

var WatchDogTimer = 0;
var RefreshRate = 120000;

var LeagueNumber = 0;
var UniqueID = '';
var NFLWeek = 0;
var LinkStyle = 0;

var isWorking = false;
var http = getHTTPObject(); 

