var RequestObject = false; // XMLHttpRequest Object
var Backend = 'http://localhost/stikes2010/script/who_online.txt'; // Counter url
window.setInterval("update_timer()", 1); // update the data every 1 sec

/*
* Main AJAX online Visitor counter request
*/
function AJAXRequest(){
	// change the message to Checking online ...
	document.getElementById("online").innerHTML = "Checking online ...";
	// Prepare the request
	RequestObject.open("GET", Backend , true);
	// Set the onreadystatechange function
	RequestObject.onreadystatechange = ReqChange;
	// Send
	RequestObject.send(null);
}

/*
* onreadystatechange function
*/
function ReqChange(){
	// If data received correctly
	if (RequestObject.readyState==4){
		// if data is valid
		if (RequestObject.responseText.indexOf('invalid') == -1){
			// getting the response
			var msgs = RequestObject.responseText.split('|');
			// Tell the reader the everything is done
			document.getElementById("online").innerHTML = msgs[0]+" visitors online";
		}
		else {
			// Tell the reader that there was error requesting data
			document.getElementById("online").innerHTML = "Error Requesting data";
		}
	}
}
