//-----------------------------------------------------------------------------
this.PixAjax = function()
{
	this.xmlHttp = this.GetHttpObject();

	this.METHOD_POST = "POST";
	this.METHOD_GET = "GET";
	this.CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
	this.CONTENT_TEXT_HTML = "text/html";
	this.SYNC_TRUE = true;
	this.SYNC_FALSE = false;
}

//-------------------------------------------------------------------------
PixAjax.prototype.sendRequest = function(method, url, contentType, syncType)
{
	// Adiciona um parâmetro com um número aleatório para não fazer cache
	rand=parseInt(Math.random()*99999999);
	complemento = "pixajaxrand=" + rand;
	if (url.indexOf("?") > -1)
	{
		url = url + "&";
	}
	else
	{
		url = url + "?";
	}
	url = url + complemento;
	
	syncType = (syncType == null ? true : syncType);
	var oThis = this;
	this.xmlHttp.open(method, url, syncType);
	this.xmlHttp.onreadystatechange = function(){oThis.ReadyStateChange();}
	if (contentType != null)
	{
		this.xmlHttp.setRequestHeader('Content-Type', contentType);
	}
	this.xmlHttp.send(null);
}

//-----------------------------------------------------------------------------
PixAjax.prototype.GetHttpObject = function()
{
	var xmlhttp;

	/*@cc_on
	@if (@_jscript_version >= 5)
	{
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e1)
			{
				xmlhttp = false;
			}
		}
	}
	@else
	{
		xmlhttp = false;
	}
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

//-----------------------------------------------------------------------------
PixAjax.prototype.ReadyStateChange = function()
{
	if (this.xmlHttp.readyState == 1)
	{
		this.OnLoading();
	}
	else if (this.xmlHttp.readyState == 2)
	{
		this.OnLoaded();
	}
	else if (this.xmlHttp.readyState == 3)
	{
		this.OnInteractive();
	}
	else if (this.xmlHttp.readyState == 4)
	{
		if (this.xmlHttp.status == 0)
		{
			this.OnAbort();
		}
		else if (this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK")
		{
			this.OnComplete(this.xmlHttp.responseText, this.xmlHttp.responseXML);
		}
		else
		{
			this.OnError(this.xmlHttp.status, this.xmlHttp.statusText, this.xmlHttp.responseText);
		}
	}
}

//-----------------------------------------------------------------------------
PixAjax.prototype.AbortCallBack = function()
{
	if (this.xmlHttp)
	{
		this.xmlHttp.abort();
	}
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnLoading = function()
{
	// Loading
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnLoaded = function()
{
	// Loaded
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnInteractive = function()
{
	// Interactive
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnComplete = function(responseText, responseXml)
{
	// Complete
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnAbort = function()
{
	  // Abort
}

//-----------------------------------------------------------------------------
PixAjax.prototype.OnError = function(status, statusText)
{
	// Error
}

