String.prototype.urlEncode = function()
{
	return escape(this).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
}

function Parameter(name, value)
{
	this.name = name;
	this.value = value;
}



function Request(url, method, type)
{
	this.url = url ? url : "";
	this.method = method ? method.toUpperCase() : "GET";
	this.type = type ? type.toLowerCase() : "html";
	this.callback = function(){};
	this.parameters = new Array();

	//alert("url=" + this.url + "\nmethod=" + this.method + "\ntype=" + this.type);
}

Request.prototype.addParameter = function(name, parameter)
{
	this.parameters.push(new Parameter(name, parameter));
}



Request.prototype.send = function()
{
	httpRequest = false;
	var callback = this.callback;

	if (window.XMLHttpRequest)  // Mozilla, Safari,...
	{
		httpRequest = new XMLHttpRequest();

		if (httpRequest.overrideMimeType) // set type accordingly to anticipated content type
		{
			// type = xml | html
			//http_request.overrideMimeType('text/xml');
			httpRequest.overrideMimeType("text/" + this.type);
		}
	}
	else
	{
		if (window.ActiveXObject) // IE
		{
			try
			{
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}
	}

	if(httpRequest)
	{
		var type = this.type;
		
		httpRequest.onreadystatechange = function()
		{
			if (httpRequest.readyState == 4)
			{
				if (httpRequest.status == 200)
				{
					if(type == "xml")
					{
						callback(httpRequest.responseXML);
					}
					else
					{
						callback(httpRequest.responseText);
					}
				}
				else
				{
					//alert('There was a problem with the request.');
				}
			}
		}

		var temp = "";

		for(var i=0; i<this.parameters.length; i++)
		{
			temp += this.parameters[i].name + "=" + this.parameters[i].value.urlEncode() + "&";
		}

		var date = new Date();
		temp += "ignore=" + date.getTime();

		if(this.method == "POST")
		{
			httpRequest.open(this.method, this.url, true);
			httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			httpRequest.setRequestHeader("Content-length", temp.length);
			httpRequest.setRequestHeader ("Connection", "close");
			httpRequest.send(temp);
		}
		else
		{
			httpRequest.open(this.method, this.url + "?" + temp, true);
			httpRequest.send(null);
		}

	}
	else return false;
}