<!--

function AjaxConnector()
{
	// properties
	this.cObjXmlHttp   = false;
	this.cArrParams    = new Array();
	this.cMethod       = 'GET';
	this.cUrl          = '';
	this.cError        = false;
	this.cParamString  = '';
	this.cResponse     = '';
	this.cHasResults   = false;
	this.cResponseType = '';

	// functions
	this.process          = function ()
	{
		if (!this.cObjXmlHttp)
		{
			this.cError = false;
			return false;
		}

		var params = this.buildQueryString();

		if (this.cUrl == '')
			this.cUrl = 'index.phtml';

		if (this.cMethod == 'GET')
		{
			if (params != "")
			{
				if (this.cUrl.indexOf('?') > - 1)
					this.cUrl += '&' + params;
				else
					this.cUrl += '?' + params;
			}
		}

		this.cObjXmlHttp.open(this.cMethod, this.cUrl, true);

		if (this.cMethod == 'POST')
		{
			// for post request
			this.cObjXmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.cObjXmlHttp.setRequestHeader("Content-length", params.length);
			this.cObjXmlHttp.setRequestHeader("Connection", "close");
		}

		this.cParamString = params;

		this.send();

		return true;
	};

	this.setParams        = function (pArrParams)
	{
		this.cArrParams = pArrParams;
	};

	this.setMethod        = function (pMethod)
	{
		this.cMethod = pMethod.toUpperCase();
	};

	this.setUrl           = function (pUrl)
	{
		this.cUrl = pUrl;
	};

	this.buildQueryString = function ()
	{
		var query = "";
	  for (var i = 0; i < this.cArrParams.length; i++)
	  {
	  	query += (i > 0 ? "&" : "") + escape(this.cArrParams[i][0]) + "=" + escape(this.cArrParams[i][1]);
	 	}

	  return query;
	};

	this.getReadyState    = function ()
	{
		if (this.cHasResults)
			return this.cObjXmlHttp.readyState;
		else
			return false;
	};

	this.getHttpStatus    = function ()
	{
		// Can't call to early otherwise causes an error

		if (this.cHasResults)
			return this.cObjXmlHttp.status;
		else
			return false;
	};

	this.getHasResults    = function ()
	{
		return this.cHasResults;
	};

	this.getError         = function ()
	{
		return this.cError;
	};

	this.send             = function ()
	{
		var pointer = this;

		this.cObjXmlHttp.onreadystatechange = function () {pointer.processResponse()};

		// to send for post shouldn't be post but have params in here
		if (this.cMethod == 'GET')
			var mPostValues = null;
		else
			var mPostValues = this.cParamString;

		//alert(this.cUrl + '-' + mPostValues);

	 	this.cObjXmlHttp.send(mPostValues);
	};

	this.processResponse     = function ()
	{
		//alert(this.cObjXmlHttp.readyState);
		if (this.cObjXmlHttp.readyState == 4)
  	{
  		if (this.cObjXmlHttp.status == 200)
  		{
	   		this.cResponse = this.cObjXmlHttp.responseXML;

	   		if (!this.cResponse)
	   		{
	   			this.cResponseType = 'text';
	   			this.cResponse = this.cObjXmlHttp.responseText;
	   		}
	   		else
	   		{
	   			this.cResponseType = 'xml';
	   		}

				//alert("Response: " + this.cResponse);

	   		this.cHasResults = true;
	   	}
	   	else
	   	{
	   	this.cError = true;
	   	}
  	}
  	else
  	{
  		this.cError = true;
  	}
	};

	this.getResponseType = function()
	{
		return this.cResponseType;
	};

	this.getResponse         = function ()
	{
		return this.cResponse;
	};

	// CREATING XMLHTTP OBJECT

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try
	{
	 this.cObjXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
	 	try
	 	{
	  	this.cObjXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  catch (E)
	  {
	   this.cObjXmlHttp = false;
	  }
	}
	@end @*/
	if (!this.cObjXmlHttp && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			this.cObjXmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			this.cObjXmlHttp = false;
		}
	}
	if (!this.cObjXmlHttp && window.createRequest)
	{
		try
		{
			this.cObjXmlHttp = window.createRequest();
		} catch (e)
		{
			this.cObjXmlHttp = false;
		}
	}
}

// -->

