function HttpRequest () {

	var request = false;

	var response;

	var ext_func;
	
	var mode; // text or xml
	
	var responseLength = null;
	
	var LoadedPercentage = null;
	
	this.post_data = null;
	
	this.Assynchronous = true;
	
	var method;
	
	//this.LoadedPercentageExtHandle = false;
	
 	var PercentageHandle = false;
 	

 	
 	this.setLoadedPercentageExtHandle = function (ExternalFunction) {
 	
 		PercentageHandle = ExternalFunction;
 	
 	};
	
	this.CreateObject = function () { // private

		//request = false;

		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			request = new XMLHttpRequest();
			if (request.overrideMimeType) {

				//request.overrideMimeType('text/xml');	

				// See note below about this line
			}
		} else if (window.ActiveXObject) { // IE

			try {

				request = new ActiveXObject("Microsoft.XMLHTTP.5.0");

			} catch (e) {
				try {

					request = new ActiveXObject("Msxml2.XMLHTTP.4.0");

				} catch (e) {
				
					try {
	
						request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
					
					} catch(e) {

						try {

							request = new ActiveXObject("Msxml2.XMLHTTP");

						} catch(e){

							try {				

								request = new ActiveXObject("Microsoft.XMLHTTP");
						
							} catch(e) {}
							
						}
					
					}
				
				}
			}


		}

		if (!request) {
			// nao foi possivel criar o objeto
			/**
			
			verificar se o navedor eh IE e pedir para ativar ActiveX
			
			*/
			return false;
		}
		
    	    
	};

 	var OptParamExtFunc_1 = false;
 	
 	var OptParamExtFunc_2 = false;
 	
 	var OptParamExtFunc_3 = false;
 	
 	var OptParamExtFunc_4 = false;
 	
 	var OptParamExtFunc_5 = false;
 	
 	var OptParamExtFunc_6 = false;

	this._setParamExtFunc = function (OptParam_1, OptParam_2, OptParam_3, OptParam_4, OptParam_5, OptParam_6) {
	
		if(OptParam_1 || OptParam_1 === 0)
		
			OptParamExtFunc_1 = OptParam_1;

		if(OptParam_2 || OptParam_2 === 0)
		
			OptParamExtFunc_2 = OptParam_2;

		if(OptParam_3 || OptParam_3 === 0)
		
			OptParamExtFunc_3 = OptParam_3;

		if(OptParam_4 || OptParam_4 === 0)
		
			OptParamExtFunc_4 = OptParam_4;

		if(OptParam_5 || OptParam_5 === 0)
		
			OptParamExtFunc_5 = OptParam_5;

		if(OptParam_6 || OptParam_6 === 0)
		
			OptParamExtFunc_6 = OptParam_6;

				
	};

	this.loadText = function (url, ExternalFunction, OptParam_1, OptParam_2, OptParam_3, OptParam_4, OptParam_5, OptParam_6) { // public

		this._setParamExtFunc(OptParam_1, OptParam_2, OptParam_3, OptParam_4, OptParam_5, OptParam_6);

		if(!ExternalFunction) {

			this.Assynchronous = false;
			
			return this.load(url, '', "text");

		}else

			this.load(url, ExternalFunction, "text");
	
	};

	this.loadXML = function (url, ExternalFunction, OptParam_1, OptParam_2, OptParam_3, OptParam_4, OptParam_5, OptParam_6) { // public

		this._setParamExtFunc(OptParam_1, OptParam_2, OptParam_3, OptParam_4, OptParam_5, OptParam_6);

		if(!ExternalFunction) {

			/*
			 *
			 *   AQUI A REQUISICAO NAO EH ASSYCRONA, ELE SUBENTENDE POR QUE NAO FOI PASSADO
			 *   O PARAMETRO ExternalFunction E ENTAO "RETORNA O RESULTADO!!"
			 *
			 */

			this.Assynchronous = false;
			
			return this.load(url, '', "xml");

		}else

			this.load(url, ExternalFunction, "xml");
	
	};
	
	this.load = function (url, ExternalFunction, _mode) { // private
	
		if(!request)
		
			this.CreateObject();
		
		
		ext_func = ExternalFunction;
		mode = _mode;
		
		if(this.Assynchronous)	

			request.onreadystatechange = this.handle;
		
		if(!this.post_data)
		
			method = "GET";
			
		else {
		
			method = "POST";
		
			this.post_data = this.build_query_string(this.post_data);
			
		}
		 
		request.open(method, url, this.Assynchronous);

		if(this.post_data) {

			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			
			request.setRequestHeader("Content-length", this.post_data.length);
			request.setRequestHeader("Connection", "close");
		
		}

		 
		request.send(this.post_data);
		
		if(!this.Assynchronous) {
		
			if(request.status != 200)
			
				return false;
		
			if(mode == "xml")
			
				response = request.responseXML;
				
			else if(mode == "text")
			
				response = request.responseText;
		
			//eval(ext_func+"(response);");
			
			return response;
			
		}
		
		
			
	
	};

	/****************************************************************************
	 *
	 *
	 *	entao!!!!!!
	 *
	 *
	 ***************************************************************************/
	
	/*this.abort = function () {
	
		request.abort();
	
	}*/
	
	this.handle = function () { // private

			//var body = document.getElementsByTagName("body").item(0);
			//alert(request.readyState);
			if(request.readyState == 0) { // não inicializado

				// ainda nao inicializou
		
			} else if(request.readyState == 1)	{ // carregando

	
				// esta carregando
				//body.innerHTML = "Carregando!!!!";			
				
			} else if(request.readyState == 2)	{ // carregado

				// comecou a carregar parece	
			
				/***********************************************************
				*
				*  -- pega todos os headers em uma string
				*  request.getAllResponseHeaders();
				*  -- pega um header em uma string
				*  request.getResponseHeader('Content-Type');
				*
				***********************************************************/
			
				//body.innerHTML = "<pre>"+request.getAllResponseHeaders()+"</pre>";

				if(PercentageHandle) {

					responseLength = null;

					try {

						if(request.getResponseHeader('Content-length')) {
				
							responseLength = request.getResponseHeader('Content-length');
				
						}
					
					}catch(e){
				
						responseLength = null;
						//alert(e);
				
					}
					
				}
			
			} else if(request.readyState == 3)	{ // modo interativo

				// bom aqui parece que ha alguma coisa interessante para estudar

				
				/*********************************************************
				 *
				 *	
				 * 	request.responseText.length;
				 *  ----pega o tamanho do que foi enviado ate o momento, mas nao funcionou no IE
				 *  
				 *
				 ********************************************************/
				 
				 //document.title = request.responseText.length;
				 if(responseLength) {
	
					try {
				 
						 LoadedPercentage = parseInt((request.responseText.length*100) / responseLength);
						 
						 eval(PercentageHandle + "(LoadedPercentage)");
						 
					} catch(e) {
					
						//alert(e);
					
					}
				 
				 }

			} else if(request.readyState == 4)	{ // completado
			
				// o resposta foi entregue por completo
				
				if(request.status == 200) {
					
					/*
					 *
					 *  se chegou ate aqui parece que o documento foi carregado com sucesso!
					 *
					 */

					if(mode == "xml")

						response = request.responseXML;
						
					else if(mode == "text")
					
						response =  request.responseText;
						
					else{
					
						alert("Modo nao especificado, pode ser text ou xml");

						return false;
						
					}

					if(OptParamExtFunc_6 || OptParamExtFunc_6 === 0)
					
						eval(ext_func+"(response,OptParamExtFunc_1,OptParamExtFunc_2,OptParamExtFunc_3,OptParamExtFunc_4,OptParamExtFunc_5,OptParamExtFunc_6)");
					
					else if(OptParamExtFunc_5 || OptParamExtFunc_5 === 0)
					
						eval(ext_func+"(response,OptParamExtFunc_1,OptParamExtFunc_2,OptParamExtFunc_3,OptParamExtFunc_4,OptParamExtFunc_5)");

					else if(OptParamExtFunc_4 || OptParamExtFunc_4 === 0)
					
						eval(ext_func+"(response,OptParamExtFunc_1,OptParamExtFunc_2,OptParamExtFunc_3,OptParamExtFunc_4)");
						
					else if(OptParamExtFunc_3 || OptParamExtFunc_3 === 0)
					
						eval(ext_func+"(response,OptParamExtFunc_1,OptParamExtFunc_2,OptParamExtFunc_3)");
						
					else if(OptParamExtFunc_2 || OptParamExtFunc_2 === 0)

						eval(ext_func+"(response,OptParamExtFunc_1,OptParamExtFunc_2)");
						
					else if(OptParamExtFunc_1 || OptParamExtFunc_1 === 0)						

						eval(ext_func+"(response,OptParamExtFunc_1)");

					else
						
						eval(ext_func+"(response)");
					
				} else {
				
					/*
					 *  aqui deu problema para carregar o documento (http)
					 *  
					 *  pode ver o q houve com request.status (codigo)
					 *  request.statusText (mensagem do erro enviado pelo servidor)
					 *
					 */
					
					alert("Problema ao fazer a chamada no documento\nCodigo respondido pelo servidor: " + request.status + " " + request.statusText);
				
				}

			}else{
			
				// colocar mensagem que houve erro para carregar
				
				alert("Problema fazendo a chamada!");
			
			}
			
	
	};
	
	this.build_query_string = function (data) {

		var query_string = '';

		var isFirst = true;

		for(name in data) {
	
			if(!isFirst)

				query_string += "&";
		
			else
		
				isFirst = false;
	
			query_string += escape(name) + "=" + escape(data[name]);
		
		}
	
		return query_string;

	};		
	
}
/*
//exemplo!!!!!!
http1 = new HttpRequest();

http1.loadXML("teste.xml", "XMLProcess", true); //-- terceiro aparametro diz se eh assicrono ou nao

http2 = new HttpRequest();

http2.loadText("teste.txt", "TextProcess", true);

function XMLProcess(XML) {

	var text = XML.getElementsByTagName("id_tag").item(0);
	alert(text.firstChild.data);

}

function TextProcess(text) {

	alert(text);

}*/

