
function AjaxRequest(url, type, params, OnOkFunctionName, OnFailFunctionName)
{
	var http_request = false;

	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
/*		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}*/

	}
	else
		if (window.ActiveXObject)
		{
			// IE
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}

	if (!http_request)
	{
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function()
							{
								if (http_request.readyState == 4)
								{
									if (http_request.status == 200)
									{
										//alert('merge');
										http_request.onreadystatechange = function() {};
										OnOkFunctionName = AddParameterToFunction(OnOkFunctionName, 'http_request', true);										
										eval(OnOkFunctionName + ';');
									}
									else
									{
										//alert('There was a problem with the request.');
										OnFailFunctionName = AddParameterToFunction(OnFailFunctionName, 'http_request', true);										
										eval(OnFailFunctionName + ';');
									}
								}
								/*else
								{
									alert('There was a problem with the request.');
									eval(OnFailFunctionName + ';');
								}*/
							};
	http_request.open(type, url, true);

	//needed in order to send variables over post
	if (type.toLowerCase() == 'post')
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http_request.send(params);

	return true;
}

function AddParameterToFunction(FunctionString, Parameter, First)
{
	myReg = new RegExp(unescape("%5C") + '((.*)' + unescape("%5C") + ')', 'gi');
	result = myReg.exec(FunctionString);

	if (myReg.lastIndex > 0)
	{
		FunctionString = FunctionString.replace(myReg, '');		
		
		if (result.length > 1)
		{
			if (result[1])
			{
				if (First)
				{
					FunctionString = FunctionString + '(' + Parameter + ', ' + result[1] + ')'; 	
				}
				else
					FunctionString = FunctionString + '(' + result[1] + ', ' + Parameter + ')'; 	
			}
			else
				FunctionString = FunctionString + '(' + Parameter + ')';
		}
		else
			FunctionString = FunctionString + '(' + Parameter + ')';
		
		return FunctionString;
	}
	else
		return FunctionString + '(' + Parameter + ')';
}
