window.$Ajax = { };


$Ajax.REPLY = function(RESPONSE) {
//----=====---------------------

	if ($Ajax.PENDING_REQUEST && $Ajax.PENDING_REQUEST.readyState == 4) {
		if ($Ajax.PENDING_REQUEST.status == 200)
			if ($Ajax.PENDING_REQUEST.responseText.indexOf('\'sIW Error:') == 0)
				alert(eval($Ajax.PENDING_REQUEST.responseText));
			else
				$Ajax.PENDING_REQUEST.CALLBACK($Ajax.PENDING_REQUEST.responseText);
		else
			alert(
				'Communication error: status=' + $Ajax.PENDING_REQUEST.status + '\n\n' +
				'More info about error status:\n' +
				'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html'
			);
		$Ajax.PENDING_REQUEST = null;
	}
};


$Ajax.Send = function(URL, QUERY, CALLBACK) {
//----====---------------------------------

	var
		REQUEST;

	if ($Ajax.PENDING_REQUEST)
		throw new Error('Ajax Error : Attempt to send concurrent requests.');
    REQUEST = null;
    if (window.XMLHttpRequest != undefined) {
		try { REQUEST = new XMLHttpRequest(); }
		catch(e) { REQUEST = null; }
    }
    else if (window.ActiveXObject != undefined) {
		try { REQUEST = new ActiveXObject('Msxml2.XMLHTTP'); }
		catch(e) {
			try { REQUEST = new ActiveXObject('Microsoft.XMLHTTP'); }
			catch(e) { REQUEST = null; }
		}
    }
	if (REQUEST) {
		REQUEST.onreadystatechange = $Ajax.REPLY;
		REQUEST.open('post', URL, true); // true = asynchrone.
		REQUEST.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		REQUEST.CALLBACK = CALLBACK;
		$Ajax.PENDING_REQUEST = REQUEST;
		REQUEST.send(QUERY);
	}
	else
		throw new Error('Ajax Error : Unable to send request.');
};

