function Ajax(mimeType, async)
{
    this.MimeType = mimeType ? mimeType : 'text/xml';
	this.Async = async || async == undefined ? true : false;
	return;
}
Ajax.prototype.Execute = function(url, params, callback, useGetMethod, identifier)
{
	var v_xmlhttp = new Ajax.XmlHttpWrapper(this.MimeType, this.Async, String(url), identifier);
	if (this.Async)
	{
	    v_xmlhttp.XmlHttp.onreadystatechange = function()
	    {
	        if (v_xmlhttp.XmlHttp.readyState == 4)
	        {
	            __StateChangedCallback();
	        }
	        return;
	    }
	}
	v_xmlhttp.Send(String(params), useGetMethod);
	if (!this.Async)
	{
	    return __StateChangedCallback();
	}

	function __StateChangedCallback()
	{
		var v_status = 0;
		var v_response = '';
		try
		{
			v_status = v_xmlhttp.XmlHttp.status;
			v_response = v_xmlhttp.XmlHttp.responseText;
		}
		catch(e)
		{
			v_status = 500;
			v_response = e.toString();
		}
		if(!v_xmlhttp.Async)
		{
		    if (v_status != 200)
		    {
		        throw new Error(v_status, v_response);
			}
			return v_response;
		}
		else if (typeof (callback) == 'function')
		{
		    callback(v_status == 200, v_response, v_status, v_xmlhttp.Id);
		}
		return null;
	}
	return null;
}
Ajax.XmlHttpWrapper = function(mimeType, async, url, id)
{
	this.Id = id;
	this.Async = async;
	this.Url = url;
	this.XmlHttp = Ajax.GetXmlHttpObject(mimeType);
	return;
}
Ajax.XmlHttpWrapper.prototype.Send = function(params, useGetMethod)
{
    var v_method = useGetMethod ? 'GET' : 'POST';
    if (v_method == 'POST')
    {
        this.XmlHttp.open(v_method, this.Url, this.Async);
        this.XmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        this.XmlHttp.setRequestHeader('Content-length', params.length);
        this.XmlHttp.setRequestHeader('Connection', 'close');
        this.XmlHttp.send(params);
    }
    else
    {
        var v_url_string = this.Url;
        if (params != null && params.length > 0)
        {
            v_url_string += '?' + params;
        }
        this.XmlHttp.open(v_method, v_url_string, this.Async);
        this.XmlHttp.send('');
    }
    return;
}
Ajax._IEProgId = '';
Ajax.GetXmlHttpObject = function(mimeType)
{
	if(window.ActiveXObject)
	{
	    if (Ajax._IEProgId != '')
	    {
	        return new ActiveXObject(Ajax._IEProgId);
		}
		var v_ieprogids = ['Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
		for(var i = 0; i < v_ieprogids.length; i++)
		{
			try
			{
				var v_xmlhttp = new ActiveXObject(v_ieprogids[i]);
				Ajax._IEProgId = v_ieprogids[i];
				return v_xmlhttp;
			}
			catch(e) {  }
		}
	}
	else if(window.XMLHttpRequest)
	{
		var v_xmlhttp = new XMLHttpRequest();
		if (typeof (mimeType) == 'string' && mimeType.length > 0 && v_xmlhttp.overrideMimeType)
		{
		    v_xmlhttp.overrideMimeType(mimeType);
		}
		if(v_xmlhttp.readyState == null) 
		{
			v_xmlhttp.readyState = 1;
			v_xmlhttp.addEventListener('load', function() { v_xmlhttp.readyState = 4; if(typeof(v_xmlhttp.onreadystatechange) == 'function') { v_xmlhttp.onreadystatechange(); } return; }, false);
		}
		return v_xmlhttp;
	}
	alert('Your browser does not fully support the technology used on this page. Some features may not work the way they were intended to.');
	return null;
}
