function xajax()
{
	var xmlhttp;
	try
	{
		xmlhttp = new XMLHttpRequest(); // más böngésző
	}
	catch( ex )
	{
		if (window.ActiveXObject ) xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0'); //buta IE6
	}
	if ( !xmlhttp ) alert( 'A böngészője nem támogatja a honlap működéséhez szükséges ajax-ot!' );
	return xmlhttp;
}

/**********************************************************
* staticDataLoader osztály                                *
**********************************************************/

function staticDataLoader( address, onsuccess, onfailure, param )
{
	var self       = this;
	var ajax       = xajax();
	this.ajax      = ajax;
	this.free      = true;
	this.address   = address;
	this.onsuccess = onsuccess;
	this.onfailure = onfailure;
	this.param     = param;
	this.ondata    = function( ajax )
	{
		if ( ajax.readyState == 4 )
		{
			if ( ajax.status == 200 )
			{
				if (ajax.responseText.substr(0, 3) == 'OK ') this.onsuccess(ajax.responseText.substr(3), this.param);
				else onfailure(0, ajax.responseText);
			}
			else if ( null != self.onfailure ) this.onfailure( ajax.status, ajax.statusText );
			this.free = true;
		}
	}
	this.loadData = function()
	{
		this.free = false;
		this.ajax.abort();
		this.ajax.onreadystatechange = function()
		{
			if ( !window.XMLHttpRequest || this.toString && this.toString().trim().substr( 0, 8 ) == 'function' ) self.ondata( ajax );
			else self.ondata( this );
		}
		this.ajax.open( 'get', this.address, true );
		this.ajax.send( null );
	}
}

/**********************************************************
* dataLoader osztály                                      *
**********************************************************/

function dataLoader( onsuccess, onfailure )
{
	var self       = this;
	var ajax       = xajax();
	this.ajax      = ajax;
	this.free      = true;
	this.onsuccess = onsuccess;
	this.onfailure = onfailure;
	this.ondata    = function( ajax )
	{
		if ( ajax.readyState == 4 )
		{
			if ( ajax.status == 200 ) this.onsuccess( ajax.responseText );
			else if ( null != self.onfailure ) this.onfailure( ajax.status, ajax.statusText );
			this.free = true;
		}
	}
	this.loadData = function( address )
	{
		this.free = false;
		this.ajax.abort();
		this.ajax.onreadystatechange = function()
		{
			if ( !window.XMLHttpRequest || this.toString && this.toString().trim().substr( 0, 8 ) == 'function' ) self.ondata( ajax );
			else self.ondata( this );
		}
		this.ajax.open( 'get', address, true );
		this.ajax.send( null );
	}
	this.abort = function()
	{
		this.ajax.abort();
		this.free = true;
	}
}

/**********************************************************
* dataUploader osztály                                *
**********************************************************/

function dataUploader( onsuccess, onfailure )
{
	var self = this;
	var ajax = xajax();
	this.ajax = ajax;
	this.free = true;
	this.onsuccess = onsuccess;
	this.onfailure = onfailure;
	this.ondata    = function( ajax )
	{
		if ( ajax.readyState == 4 )
		{
			if ( ajax.status == 200 )
			{
				if ( ajax.responseText == 'OK' ) { if ( null != self.onsuccess ) this.onsuccess( ajax.responseText ); }
				else if ( null != self.onfailure ) this.onfailure( 200, ajax.responseText.substr( 4 ) );
			}
			else if ( null != self.onfailure ) this.onfailure( ajax.status, ajax.statusText );
			this.free = true;
		}
	}
	this.uploadData = function( address )
	{
		this.free = false;
		this.ajax.abort();
		this.ajax.onreadystatechange = function()
		{
			if ( !window.XMLHttpRequest || this.toString && this.toString().trim().substr( 0, 8 ) == 'function' ) self.ondata( ajax );
			else self.ondata( this );
		}
		this.ajax.open( 'get', address, true );
		this.ajax.send( null );
	}
}

/**********************************************************
* staticDataUploader osztály                                *
**********************************************************/

function staticDataUploader( address, onsuccess, onfailure )
{
	var self = this;
	var ajax = xajax();
	this.ajax = ajax;
	this.free = true;
	this.onsuccess = onsuccess;
	this.onfailure = onfailure;
	this.address   = address;
	this.ondata    = function( ajax )
	{
		if ( ajax.readyState == 4 )
		{
			if ( ajax.status == 200 )
			{
				if ( ajax.responseText == 'OK' ) { if ( null != self.onsuccess ) this.onsuccess( ajax.responseText ); }
				else if ( null != self.onfailure ) this.onfailure( 200, ajax.responseText.substr( 4 ) );
			}
			else if ( null != self.onfailure ) this.onfailure( ajax.status, ajax.statusText );
			this.free = true;
		}
	}
	this.uploadData = function()
	{
		this.free = false;
		this.ajax.abort();
		this.ajax.onreadystatechange = function()
		{
			if ( !window.XMLHttpRequest || this.toString && this.toString().trim().substr( 0, 8 ) == 'function' ) self.ondata( ajax );
			else self.ondata( this );
		}
		this.ajax.open( 'get', this.address, true );
		this.ajax.send( null );
	}
}
