
function getAjaxObject()
{
	var xmlHttp;
	try { // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) { // Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
    		catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

var shoutboxLastID = false;

function shoutboxUpdate(timeAgain, lastID)
{
	if (lastID !== false) {
		shoutboxLastID = lastID;
	}
	var ajax = getAjaxObject();
	var url = '/chat.php?newrows='+shoutboxLastID;
	ajax.open('GET', url, true);
	ajax.onreadystatechange = function ()
	{
		if (ajax.readyState == 4)
		{
			var response = ajax.responseText;
			if (response != '') {
				shoutboxUpdateB(response);
			}
		}
	};
	ajax.send(null);

	if (timeAgain) {
		setTimeout("shoutboxUpdate(true, false)", 4000);
	}

	return true;
}

function shoutboxUpdateB(response)
{
	var res = response.split('::');
	shoutboxLastID = res[0];
	var shoutbox = document.getElementById('shoutboxtable');
	var rows = shoutbox.rows;
	var nRows = rows.length;
	var tbody = shoutbox.tBodies[0];
	
	var newRow = tbody.insertRow(nRows-2);
	newRow.className = 'shout_'+res[3];
	
	var dateCell = newRow.insertCell(0);
	dateCell.align = 'right';
	dateCell.innerHTML = res[1]+'<br/>'+res[2];

	var msgCell = newRow.insertCell(1);
	msgCell.innerHTML = res[4];
	
	shoutboxUpdate(false, false);
}

