function createQuery(pushUrl, returnFn)
{
	uid = Math.round(Math.random()*100000);
	rUid = "requester"+uid;
	eval(rUid+" = new xHttpQuery();");
	eval(rUid+".pushUrl = pushUrl;");
	eval(rUid+".returnFn = returnFn;");
	eval(rUid+".selfRef = \""+rUid+"\";");
	eval(rUid+".doRequest();");
}

var updateInProgress = false;
function xHttpQuery()
{
	this.pushUrl = '';
	this.selfRef = '';
	this.returnFn = false;
	this.doRequest = function()
	{
		if(updateInProgress == true)
		{
			setTimeout(this.selfRef+".doRequest()", 5000);
			return;
		}
		//alert(this.pushUrl);
		updateInProgress = true;
		if(window.XMLHttpRequest)
		{
			req = new XMLHttpRequest();
			req.onreadystatechange = this.returnFn;
			req.open("GET", this.pushUrl, true);
			req.send(null);
		}
		else if(window.ActiveXObject)
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if(req)
			{
				req.onreadystatechange = this.returnFn;
				req.open("POST", this.pushUrl, true);
				req.send();
			}
		}
	}
}

function receiveGroupInvite()
{
	if(req.readyState == 4)
	{
		if(req.status == 200)
		{
			//alert(req.getAllResponseHeaders());
			response = req.responseXML.documentElement;
			if(response)
			{
				results = response.getElementsByTagName('results')[0].firstChild.nodeValue;
				updateInProgress = false;
				if(results == "OK")
				{
					alert("Invitation Sent!");
				}
				else
				{
					alert(results + "\n" + status);
				}
			}
		}
	}
}

function invite(inv)
{
	createQuery(inviteUrl + "?invitee="+inv, receiveGroupInvite);
}

