function AjaxConn(){	
	try{
		this.xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				this.xmlhttp = false;
			}
		}
	}// end catch
	
	this.method = "POST";
	this.url 	= "";
	this.parameters = null;
	this.enctype = "text/html; charset=iso-8859-1";	

	this.ResetData = function() {
		this.method = "POST";
  		this.url 	= "";
		this.parameters = null;
  	}
	this.ResetFunctions = function() {
  		this.Preload = function() {};
		this.Result = function() {};
  		this.Erro = function() {};
	}
	this.reset = function() {
		this.ResetFunctions();
		this.ResetData();
	}

	this.Carregar = function(){
		this.Preload();
  		this.xmlhttp.open(this.method, this.url,true);	

		this.xmlhttp.setRequestHeader("Expires", "26 Jul 1997 05:00:00 GMT");
		this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		this.xmlhttp.setRequestHeader("Pragma", "no-cache");
		this.xmlhttp.setRequestHeader("Content-Type",this.enctype);
		
		if(this.parameters){
    		this.xmlhttp.setRequestHeader('Content-length', this.parameters.length);
		}
   	 	this.xmlhttp.setRequestHeader('Connection', 'close');
		this.xmlhttp.send(this.parameters);
		//Executada quando o navegador obtiver o código
		var self = this;
		//Executada quando o navegador obtiver o código
		this.xmlhttp.onreadystatechange=function() {
			
			if (self.xmlhttp.readyState==4){
				self.texto=self.xmlhttp.responseText; //Lê o texto
				self.texto=self.texto.replace(/\+/g," "); //Desfaz o urlencode
				self.texto=unescape(self.texto);	
				if(self.xmlhttp.status==200){
					self.Result();
				}else{
					self.Erro();
				}
			}

		}// end function

	}// end function
}// end function
// função  de exemplo
function AjaxOpenExample(display){
	var obj = document.getElementById(display);
	var conn= new AjaxConn();
	conn.element 	= obj;
	conn.method  	= "GET";
	conn.url 		= "teste.php?teste=0";
	conn.Preload 	= function(){obj.innerHTML = "carregando...";};
	conn.Result 	= function(){obj.innerHTML = this.texto;};
	conn.Erro 		= function(){obj.innerHTML = "<div>&nbsp;Não Encontardo</div>"; };
	conn.Carregar();
}

function AjaxTag(tag,valor){
	var result = "";
	if(valor.indexOf('<'+tag+'>')>=0){
		result =  valor.substring(parseInt(valor.indexOf('<'+tag+'>')+(parseInt(tag.length+2))),valor.indexOf('</'+tag+'>'));
	}
	return result;
}
function JavascriptExecute(valor){
	var script = AjaxTag("script",valor);
	if(script!=""){
		eval(script);
	}
}
function AjaxSubmitExample(form,display){
	var url 		= form.action;
	var enctype 	= form.enctype;
	var method		= form.method;
	var elements	= form.elements;
	var parameters  = "";
	for(var i=0; i < elements.length; i++){
		if(parameters!=""){parameters +="&";}
		parameters += elements[i].name+"="+encodeURI(elements[i].value);		
	}//end for
	var obj = document.getElementById(display);
	var conn= new AjaxConn();
	conn.element 	= obj;
	conn.method  	= method;
	conn.parameters = parameters;
	conn.enctype	= enctype;
	conn.url 		= url;
	conn.Preload 	= function(){obj.innerHTML = "carregando...";};
	conn.Result 	= function(){obj.innerHTML = this.texto;};
	conn.Erro 		= function(){obj.innerHTML = url+"<div>&nbsp;Não Encontardo</div>"; };
	conn.Carregar();
	return false;
}
