﻿function doCallback(callback, item)
{
	eval(callback + '(item)');
}


function getXMLHTTPRequest()
{
	try {
	req = new XMLHttpRequest();
	}catch (err1) {
		try {
		req = new ActiveXObject('Msxm12.XMLHettp');
		} catch (err2) {
			try {
			req = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (err3) {
				req = false;
			}
		}
	}
	return req;
}

function requestGET(url, query, req)
{
	myRand = parseInt(Math.random()*99999999999);
	req.open('GET', url + '?' + query + '&rand=' + myRand, true);
	req.send(null);
}

function requestPOST(url, query, req)
{
	req.open('POST',url, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(Query);
}

function getServerText(url,query,callback,reqtype,getxml) 
{
	var http = getXMLHTTPRequest();
	http.onreadystatechange =  function(){
	if (http.readyState == 4) 
	{
		if(http.status == 200)
		{
			var item = http.responseText;
			//alert('We got back ' + item);
			if(getxml==1)
			{
				item = http.responseXML;
			}
			doCallback(callback, item);
		}
	}
	else
	{
		//alert('We got nothing');
	}
}
	
	if(reqtype == 'post')
	{
		requestPOST(url, query, http);
	}
	else
	{
		requestGET(url,query, http);
	}
}

function useHttpResponse()
{
	if (http.readyState == 4) 
	{
		if(http.status == 200)
		{
			var mytext = http.responseText;
		}
	}
	else
	{
		//alert('We got nothing');
	}
}

