// (C) NetLogic, 2006
hitchs.add(
	function() {
		window.layout = document.getElementById('layout');
		setInterval('GetNmatchEvents(window.layout)', 60000);
	}
);

function ProgressBar(show) {
	var img = document.getElementById('progressBar');
	if(img === null) {
		var img = document.createElement('img');
		img.src = '/i/progress.gif';
		img.id = 'progressBar';
		document.body.appendChild(img);
	}

	img.style.display = show ? 'block' : 'none';

	setTimeout('ProgressBar(false)', 2500);
}

function GetNmatchEvents(onlineTable) {
	if(!matchState && refresh != 1) {
		window.location.reload();
	}
	return;

	ProgressBar(true);

	var events = {};

	MAX = 0;

	for(var r in onlineTable.tBodies[0].rows) {
		tr = onlineTable.tBodies[0].rows[r];
		if(typeof tr !== 'object') {
			continue;
		}

		e = tr.getAttribute('event');
		m = tr.getAttribute('modify');

		if(m > MAX) {
			MAX = m;
		}
	}

	var onfunction = GetNmatchEventsOn;
	var onOptions  = {id: matchId, events: MAX};
	
	$.get('/nmatch.json', onOptions, function(req) {
		if (typeof onfunction.call == 'undefined') {
			/* for IE 5.01 */
			req.responseJS.$call = onfunction;
			req.responseJS.$call(req, onOptions);
		} else {
			onfunction.call(req, req, onOptions);
		}
	}, 'json');
}

function GetNmatchEventsOn() {
	tbody = onlineTable.tBodies[0];
	alert(tbody);
	return;

	for(var r in tbody.rows) {
		tr = tbody.rows[r];

		if(typeof tr !== 'object') {
			continue;
		}

		e = tr.getAttribute('event');
		m = tr.getAttribute('modify');

		if(this.events[e] == undefined || typeof this.events[e] === 'object') {
			tbody.removeChild(tr);
		}
	}

	var pos = 0;
	for(var i in this.events) {
		e = this.events[i];

		if(typeof e === 'object') {
			var tr = tbody.insertRow(pos);

			var td = tr.insertCell();
			td.innerHTML = e.time === null ? '' : e.time;

			var td = tr.insertCell();
			td.innerHTML = GetElemFromArray(e.eventtype, evTypes);

			var td = tr.insertCell();
			td.innerHTML = e.title;

			var td = tr.insertCell();
			td.innerHTML = GetElemFromArray(e.team, evTeams);

			var td = tr.insertCell();
			td.innerHTML = GetElemFromArray(e.player, evPlayers);
		}

		pos++;
	}
}

function GetElemFromArray(xElem, xArray) {
	return (xElem == null || isNaN(parseInt(xElem))) ? '' : xArray[parseInt(xElem)]
}

