function ajax_request()
{
	this.xmlhttp         = null;
	this.loading_message = null;
}

ajax_request.prototype.xml_init = function()
{
	try
	{
		this.xmlhttp = new XMLHttpRequest();
		return true;
	}
	catch(e)
	{
		try
		{
			this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			return true;
		}
		catch(e)
		{
			return false;
		}
	}
};

ajax_request.prototype.process = function( url, type, post )
{
	if ( ! this.xmlhttp )
	{
		this.xml_init();
	}

	if ( ! this.readystate_not_ready() )
	{
		type = type == "POST" ? "POST" : "GET";

		url += "&ajax=1";

		this.xmlhttp.open(type, url, true);

		if ( type == "GET" )
		{
			this.xmlhttp.send(null);
		}
		else
		{
			if ( typeof( this.xmlhttp.setRequestHeader ) != "undefined" )
			{
				this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			}

			this.xmlhttp.send( this.format_for_post(post) );
		}

		if ( this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 )
		{
			return true;
		}
	}

	return false;
};

ajax_request.prototype.format_for_post = function( arrayfields )
{
	var str = '';

	try
	{
		for( var i in arrayfields )
		{
			str += i + '=' + this.encodeurl(arrayfields[i]) + '&';
		}
	}
	catch(e)
	{
	}

	return str;
};

ajax_request.prototype.encodeurl = function( url )
{
	url = url.toString();

	var regcheck = url.match(/[\x90-\xFF]/g);

	if ( regcheck )
	{
		for (var i = 0; i < i.length; i++)
		{
			url = url.replace(regcheck[i], '%u00' + (regcheck[i].charCodeAt(0) & 0xFF).toString(16).toUpperCase());
		}
	}

	return escape(url).replace(/\+/g, "%2B");
};

ajax_request.prototype.readystate_not_ready = function()
{
	return ( this.xmlhttp.readyState && ( this.xmlhttp.readyState < 4 ) );
};

ajax_request.prototype.readystate_ready_and_ok = function()
{
	return ( this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200 ) ? true : false;
};

ajax_request.prototype.onreadystatechange = function( event )
{
	if ( ! this.xmlhttp )
	{
		this.xml_init();
	}

	if ( typeof(event) == 'function' )
	{
		this.xmlhttp.onreadystatechange = event;
	}
};

ajax_request.prototype.show_loading = function()
{
	this.loading_message  = this.loading_message == '' ? 'Please wait for loading' : this.loading_message;

    my_getbyid('loading-message').innerHTML = this.loading_message + '...';

    var obj = my_getbyid('loading');
    move_to_center(obj);
    obj.style.display = '';
}

ajax_request.prototype.hide_loading = function()
{
	my_getbyid('loading').style.display = 'none';
    this.loading_message = '';
}