function AJAX()
{	var _conexao=null;
	var _parametros=null;
	var _abortando=false;
	var tipo_retorno=null; // xml txt
	var ao_receber=null;
}

AJAX.prototype._processa_estado=function()
{	if(this._conexao.readyState==4)
	{	if(this._conexao.status==200)
		{	if(this.tipo_retorno=="txt")
			{	this.ao_receber(this._conexao.responseText);
			}
			else
			{	this.ao_receber(this._conexao.responseXML);
			}
		}
		else
		{	alert("Erro "+this._conexao.status);
		}
	}
}

AJAX.prototype._ocupado=function()
{	return (this._conexao.readyState && (this._conexao.readyState<4)); }

AJAX.prototype.inicializa=function()
{	this._conexao=false;
	try
	{	this._conexao=new XMLHttpRequest();
	}
	catch(e)
	{	try
		{	this._conexao=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{	this._conexao=false;
		}
	}
	if(!this._conexao)
	{	this._conexao=null;
		alert("Navegador sem suporte a requisicao XML");
		return false;
	}
	this._parametros=new Array();
	return true;
}

AJAX.prototype.reinicializa=function()
{	if(this._conexao)
	{	this._abortando=true;
		this._conexao.abort();
		this._abortando=false;
	}
	this._parametros=new Array();
	return true;
}

AJAX.prototype.adiciona_parametro=function(_nome,_valor)
{	_valor=escape(_valor.toString());
	_valor=_valor.replace(/\+/g,"%2B");
	this._parametros.push(_nome+"="+_valor);
	return true;
}

AJAX.prototype.envia=function(_metodo,_endereco)
{	if(!this._conexao)
	{	alert("Objeto nao inicializado");
		return false;
	}
	if(this._ocupado())
	{	alert("Objeto ja em uso");
		return false;
	}
	if(this.ao_receber==null)
	{	alert("Funcao de retorno nao definida");
		return false;
	}
	this.tipo_retorno=(this.tipo_retorno==null)?("txt"):(this.tipo_retorno.toLowerCase());
	if((this.tipo_retorno=="xml") && (this._conexao.overrideMimeType))
	{	this._conexao.overrideMimeType("text/xml");
	}
	switch(this._parametros.length)
	{	case 0:
			this._parametros="";
			break;
		case 1:
			this._parametros=this._parametros[0];
			break;
		default:
			this._parametros=this._parametros.join("&");
	}
	_metodo=_metodo.toUpperCase();
	var _this=this;
	switch(_metodo)
	{	case "GET":
			_endereco+=(_endereco.indexOf("?")==-1)?("?"):("&");
			_endereco+=this._parametros;
			this._conexao.open("GET",_endereco,true);
			this._conexao.onreadystatechange=function()
			{	if(!_this._abortando)
				{	_this._processa_estado();
				}
			}
			this._conexao.setRequestHeader("User-Agent",navigator.userAgent);
			this._conexao.setRequestHeader("Referer",_endereco);
			this._conexao.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
			this._conexao.setRequestHeader("Cache-Control","post-check=0, pre-check=0");
			this._conexao.setRequestHeader("Pragma","no-cache");
			this._conexao.setRequestHeader("Encoding","ISO-8859-1");
			this._conexao.send(null);
			break;
		case "POST":
			this._conexao.open("POST",_endereco,true);
			this._conexao.onreadystatechange=function()
			{	if(!_this._abortando)
				{	_this._processa_estado();
				}
			}
			this._conexao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			this._conexao.setRequestHeader("Method","POST "+_endereco+" HTTP/1.1");
			this._conexao.setRequestHeader("User-Agent",navigator.userAgent);
			this._conexao.setRequestHeader("Referer",_endereco);
			this._conexao.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
			this._conexao.setRequestHeader("Cache-Control","post-check=0, pre-check=0");
			this._conexao.setRequestHeader("Pragma","no-cache");
			this._conexao.setRequestHeader("Encoding","ISO-8859-1");
			this._conexao.send(this._parametros);
			break;
		default:
			alert("Metodo de envio invalido ou nao implementado");
			return false;
	}
	return true;
}