function SAjax(sURL, sMethod) {
	this.debugMode = false;
	this.requestType = sMethod ? sMethod : "GET";
	this.url = sURL;
}
var _protSAjax = SAjax.prototype;

_protSAjax.debug = function(sText) {
	if (this.debugMode) {
		alert("RSD: " + sText);
	}
}

_protSAjax.initObjects = function() {
	this.debug("initObjects() called..");

	var a;
	try {
		a = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			a = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			a = null;
		}
	}
	if (!a && typeof XMLHttpRequest != "undefined") {
		a = new XMLHttpRequest();
	}
	if (!a) {
		this.debug("Could not create connection object.");
	}

	return a;
}

_protSAjax.doCall = function(sFunctionName, aArguments) {
	var i, x, n;
	var post_data;

	var uri = this.url;
	var len;
	if (typeof aArguments[aArguments.length-1] == "function") {
		len = aArguments.length-1;
	} else {
		len = aArguments.length;
	}
	if (this.requestType == "GET") {
		if (uri.indexOf("?") == -1)
			uri = uri + "?rs=" + escape(sFunctionName);
		else
			uri = uri + "&rs=" + escape(sFunctionName);
		for (i = 0; i < len; i++)  {
			uri = uri + "&rsaArguments[]=" + escape(aArguments[i]);
		}
		uri = uri + "&rsrnd=" + new Date().getTime();
		post_data = null;
	} else {
		post_data = "rs=" + escape(sFunctionName);
		for (i = 0; i < len; i++)
			post_data = post_data + "&rsaArguments[]=" + escape(aArguments[i]);
	}

	x = this.initObjects();
	x.open(this.requestType, uri, true);

	if (this.requestType == "POST") {
		x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
		x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	var ajaxLink = this;
	x.onreadystatechange = function() {
		if (x.readyState != 4)
			return;
		ajaxLink.debug("received " + x.responseText);

		var status;
		var data;

		status = x.responseText.charAt(0);

		data = x.responseText.substring(2);
		if (status == "-") {
			alert("Error: " + data);
		} else {
			if (typeof aArguments[aArguments.length-1] == "function") {
				aArguments[aArguments.length-1](data);
			}
		}
	}
	x.send(post_data);
	this.debug(sFunctionName + " uri = " + uri + "/post = " + post_data);
	this.debug(sFunctionName + " waiting..");
	delete x;
}


