
function liteAJaX(uri)
{
	var self = this;
	try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { this.xmlhttp = new XMLHttpRequest(); }
	catch (e) { this.xmlhttp = false; }}}
	
	this.callback = uri;
	if (!this.callback) this.callback = ".";
	
	this.method = "POST";
	
	this.fastencoding = 0;
	
	this.responseText = false;
}



liteAJaX.prototype.call = function(sFunction, sVars)
{
	out = false;
 	vars = new Array(sVars.length);
	for(i=0;i<sVars.length;i++){
		vars[i] = sVars[i];
	}
	vars = vars.join("&");
	
	
	// *** Define default helper function
	if (!sFunction) sFunction = "callhelper";
	if (!this[sFunction]) this[sFunction] = this.callhelper;
	
	// *** Make Call
	try
	{
		if (this.fastencoding == 8) vars = this.varsToUTF8(vars);
		
		out = this.rawCall(this.callback, "fx=" + sFunction + "&" + vars, this.method, this[sFunction]);
	}
	catch (e) { out = false; }
	
	return out;
}


liteAJaX.prototype.callhelper = function(oXML)
{
	alert("Default Callhelper:\n" + oXML.responseText);
}

/****************************************************************************************************
 * Calls a specific URI using the XMLHTTPRequest object with the specified paramteres.
 *
 * Based upon XHConn (http://xkr.us/code/javascript/XHConn/) - brad@xkr.us - 2005-01-24
 * Licenced under CC-ShareAlike license (http://creativecommons.org/licenses/by-sa/2.0/).
 * 
 * @param	URI file locator to call
 * @param	parameters to be passed
 * @param	connection method [GET|POST]
 * @param	ready state helper function callback
 */
liteAJaX.prototype.rawCall = function(sURI, sVars, sMethod, fxReady)
{
	var out = false;
	
	if (this.xmlhttp)
	{
		var self = this; // js closure fix for 'this' misbehave
		sMethod = sMethod.toUpperCase();
		
		try
		{
			// ****** Method switch [GET|POST]
			if (sMethod == "GET")
			{
				this.xmlhttp.open(sMethod, sURI + "?" + sVars, true);
				sVars = "";
			}
			else
			{
				this.xmlhttp.open(sMethod, sURI, true);
				this.xmlhttp.setRequestHeader("Method", "POST " + sURI + " HTTP/1.1");
				this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			
			// ****** Defines the onreadystatechange function
			this.xmlhttp.onreadystatechange = function()
			{
				switch (self.xmlhttp.readyState)
				{
					case 1: // *** Loading...
						break;
					case 2: // *** Parsing...
						break;
					case 3: // *** Available...
						break;
					case 4: // *** Ready
						self.responseText = self.xmlhttp.responseText;
						fxReady(self.xmlhttp);
						break;
				}
			};
			
			// ****** Send Request
			this.xmlhttp.send(sVars);
			out = true;
		}
		catch(z) { out = false; }
	}
	
	return out;
}

/****************************************************************************************************
 * Linear conversion to UTF-8 encoding, making care to split apart the URI variables that are
 * to be passed.
 * 
 * @param	string
 * @return	UTF-8 encoded string
 */
liteAJaX.prototype.varsToUTF8 = function(string)
{
	strArr = string.split('&');
	
	for (i = 0; i < strArr.length; i++)
	{
		strVar = strArr[i].split('=');
		strVar[0] = encodeURIComponent(strVar[0]);
		strVar[1] = encodeURIComponent(strVar[1]);
		strArr[i] = strVar.join("=");
	}
	
	return strArr.join('&')
}
