﻿//To ensure, server not bombarded with numerous calls when
//the previous ones haven't been fully executed.
var blnSent = false;

function outputResult(oResponse)
{
	var arrResponse = oResponse.responseText.split("||");	
	$('divOnlineUsers').innerHTML = arrResponse[0];
	$('iChatUsers').innerHTML = arrResponse[1];
	$('iTotalOnlineUsers').innerHTML = arrResponse[2];
	blnSent = false;
}

function outputResultError()
{
	$('divOnlineUsers').innerHTML = "Service Unavailable";
}

function addPoll()
{
	var sRan = "ran=" + Math.random();
	
	var ajax = new Ajax.Request('/Chat/onlineuser.asp?' + sRan,
		{
			method: 'get',
			onSuccess: outputResult,
			onFailure: outputResultError
		}
	);
}

function getUsers()
{
	if (!blnSent)
	{
		addPoll();
		blnSent = true;
	}
}

function intiateCom()
{
	//loadPage();
	addPoll();
	setInterval( getUsers, 10000 );
}

window.onload += setTimeout( intiateCom, 800 );