/*var connection = false;
var http_request = false;
var is_busy = false;
var is_aborted = false;
var Action_onXML = null;
var Action_onText = null;

if (window.XMLHttpRequest)
{ // Mozilla, Safari, ...
	connection = function () {
		var tmp = new XMLHttpRequest();
		if(tmp.overrideMimeType)
			tmp.overrideMimeType('text/xml');

		return tmp;}
}
else if (window.ActiveXObject)
{ // IE
	connection = function () {
		var tmp = new ActiveXObject("Microsoft.XMLHTTP");
		return tmp;}
}

function onChange()
{
	if( is_aborted == true )
	{
		http_request.abort();
		is_busy = false;
	}
	if( http_request.readyState == 4 )
	{
		if( http_request.status == 200 )
		{
			is_busy = false;
			
			//parseXML();
			if( Action_onXML )
			{
				Action_onXML( http_request.responseXML );
				Action_onXML = null;
				return true;
			}
			else if( Action_onText ) 
			{
				Action_onText( http_request.responseText );
				Action_onText = null;
				return true;
			}
			else
				return true;
		}
	}
}

function query( url, feedbackFunc, getXML )
{
	if( is_busy )
		return false;
	is_busy = true;
	if( http_request )
		delete http_request;
	if( getXML == true )
		Action_onXML = feedbackFunc;
	else
		Action_onText = feedbackFunc;
	http_request = connection();
	http_request.onreadystatechange = onChange;
	http_request.open( 'GET', url, true );
	http_request.send(null);
}
*/

function AjaxQuery()
{
	this.is_busy = false;
	this.is_aborted = false;
	this.http_request = null;
	this.Action_onXML = null;
	this.Action_onText = null;
	this.queryOwner = null;
	if (window.ActiveXObject)
		this.AjaxQueryObj = null;

	this.queryQueue = Array();
	this.queueIndex = 0;
	this.queueCounter = 0;
}
AjaxQuery.prototype.query = function ( url, feedbackFunc, isXML )
{
	if ( this.is_busy == true )
		return false;
	this.is_busy = true;
	if( this.http_request )
		delete http_request;

	this.is_aborted = false;
	this.Action_onXML = null;
	this.Action_onText = null;
	if( isXML == true )
		this.Action_onXML = feedbackFunc;
	else
		this.Action_onText = feedbackFunc;
	
	this.http_request = this._connection();

	if( window.ActiveXObject )
		this.AjaxQueryObj = this;
	else
		this.http_request.AjaxQueryObj = this;

	this.http_request.onreadystatechange = function()
											{
												if( !this.AjaxQueryObj )
													with(ajax)
													{
														if( http_request.AjaxQueryObj )
															http_request.AjaxQueryObj._onChange();
														else if( AjaxQueryObj )
															AjaxQueryObj._onChange();
														else
															return false;
													} 
												else
													this.AjaxQueryObj._onChange()
											};

	this.http_request.open( 'GET', url, true );
	this.http_request.send(null);
	return true;
}
AjaxQuery.prototype.ownedQuery = function ( url, obj, member, isXML ) 
{
	if( this.is_busy == true )
		return false;
	this.is_busy = true;
	if( this.http_request )
		delete http_request;
	
	this.is_aborted = false;
	this.Action_onXML = null;
	this.Action_onText = null;
	if( isXML == true )
		this.Action_onXML = member;
	else
		this.Action_onText = member;
	this.queryOwner = obj;
	this.http_request = this._connection();
	
	if( window.ActiveXObject )
		this.AjaxQueryObj = this;
	else
		this.http_request.AjaxQueryObj = this;
		
	this.http_request.onreadystatechange = function()
											{
												if( !this.AjaxQueryObj )
													with(ajax)
													{
														if( http_request.AjaxQueryObj )
															http_request.AjaxQueryObj._onChange();
														else if( AjaxQueryObj )
															AjaxQueryObj._onChange();
														else
															return false;
													} 
												else
													this.AjaxQueryObj._onChange()
											}; 
	this.http_request.open( 'GET', url, true );
	this.http_request.send(null);
	return true;
}
AjaxQuery.prototype.abort = function ()
{
	this.is_aborted = true;
}
AjaxQuery.prototype._onChange = function ()
{
	if( this.is_aborted == true )
	{
		this.http_request.abort();
		return this.is_busy = false
	}

	if( this.http_request.readyState == 4 )
	{
		if( this.http_request.status == 200 )
		{
			if( this.Action_onXML != null )
			{
				if( this.queryOwner == null )
					this.Action_onXML( this.http_request.responseXML );
				else
					this.queryOwner[this.Action_onXML]( this.http_request.responseXML );
			}
			else if( this.Action_onText != null ) 
			{
				if( this.queryOwner == null )
					this.Action_onText( this.http_request.responseText );
				else
					this.queryOwner[this.Action_onText]( this.http_request.responseText );
			}
			this.Action_onXML = null;			
			this.Action_onText = null;
			this.queryOwner = null;
			this.is_busy = false;
			return true;
		}
	}
}

if (window.XMLHttpRequest)
{ // Mozilla, Safari, ...
	AjaxQuery.prototype._connection = function () {
		var tmp = new XMLHttpRequest();
		if(tmp.overrideMimeType)
			tmp.overrideMimeType('text/xml');

		return tmp;}
}
else if (window.ActiveXObject)
{ // IE
	AjaxQuery.prototype._connection = function () {
		var tmp = new ActiveXObject("Microsoft.XMLHTTP");
		return tmp;}
}
AjaxQuery.prototype.addToQueue = function ( url, feedback, isXml )
{
	
}

