top.pl4e_Ajax = {};
top.pl4e_Ajax.AjaxObject = function()
{
	var r = null;
	try
	{
		r = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e)
	{
		try
		{
			r = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(ee){}
	}
	return r;
};
top.pl4e_Ajax.Requests = [];
top.pl4e_Ajax.Stop = function ()
{
	for(var i=0; i<AjaxRequests.length; i++)
	{
		if(AjaxRequests[i] != null)
			AjaxRequests[i].abort();
	}
};
top.pl4e_Ajax.CreateRequest =function (Context)
{
	for(var i=0; i<top.pl4e_Ajax.Requests.length; i++)
	{
		if(top.pl4e_Ajax.Requests[i].readyState == 4)
		{
			top.pl4e_Ajax.Requests[i].abort();
			top.pl4e_Ajax.Requests[i].Context = Context;
			return top.pl4e_Ajax.Requests[i];
		}
	}

	var p = top.pl4e_Ajax.Requests.length;
	
	top.pl4e_Ajax.Requests[p] = [];
	top.pl4e_Ajax.Requests[p].obj = new top.pl4e_Ajax.AjaxObject();
	top.pl4e_Ajax.Requests[p].Context = Context;
	
	return top.pl4e_Ajax.Requests[p];
};
top.pl4e_Ajax.Request = function (url, data, callback, Context)
{
	var req = top.pl4e_Ajax.CreateRequest(Context);
	var async = typeof(callback) == 'function';

	if(async) req.obj.onreadystatechange = function()
	{
		if(req.obj.readyState == 4)
			callback(new top.pl4e_Ajax.Response(req));
	};
	
	with(req.obj)
	{
		open("POST", url, async);
		setRequestHeader("Connection","close");
		setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		setRequestHeader("Method", "POST " + url + "HTTP/1.1");
	
		try
		{
			req.obj.send(data);
		}
		catch(e)
		{
			return "";
		}
	}
	if(!async)
	{
		return new top.pl4e_Ajax.Response(req);
	}
};
top.pl4e_Ajax.Response = function (request)
{
	this.Request = request.obj;
	this.Error = null;
	this.Value = null;
	this.Context = request.Context;
	
	if(request.obj.status == 200)
	{
		try
		{
			this.Value = top.pl4e_Ajax.GetObject(request);
			
			if(this.Value && this.Value.error)
			{
				this.Error = this.Value.error;
				this.Value = null;
			}
		}
		catch(e)
		{
			this.Error = new top.pl4e_Ajax.Error(e.name, e.description, e.number);
		}
	}
	else
	{
		this.Error = new top.pl4e_Ajax.Error("HTTP request failed with status: " + request.obj.status, request.obj.status);
	}
	
	return this;
};
top.pl4e_Ajax.GetObject = function (request)
{
	if(request.obj.responseXML != null && request.obj.responseXML.xml != null && request.obj.responseXML.xml != '')
		return request.obj.responseXML;
	
	var r = null;
	try
	{
		eval("r=" + request.obj.responseText + ";");
	}
	catch(e)
	{
		return request.obj.responseText;
	}
	return r;
};
top.pl4e_Ajax.Error = function (n, d, no)
{
	this.name = n;
	this.description = d;
	this.number = no;
	return this;
};
top.pl4e_Ajax.Error.prototype.toString = function()
{
	return this.name + " " + this.description;
};
top.pl4e_Ajax.Encode = function (str)
{
	return str.replace(/\\r/g,"");
}
