// JavaScript Document

function Ajax()
{

	
	
	var Ajax = false;
	this.iniciar = AjaxRequest;
	this.setTipo = setTipo;
	this.setXML = setXML;
	this.setDados = setDados;
	this.envio = buscar;

	
	function setTipo(tipo)
	{
		this.tipo  = tipo;	
	
	}
	
	function setXML(arq)
	{
		this.arq_xml = arq;
	}
	
	function setDados(dados)
	{
		this.dadosEnv = dados;
	
	}
	
	function AjaxRequest()
	{
		
	
					Ajax = false;
	
					if (window.XMLHttpRequest) 
					{ // Mozilla, Safari,...
	
						Ajax = new XMLHttpRequest();
	
					} 
					else if (window.ActiveXObject)
					{ // IE
	
						try 
						{
	
							Ajax = new ActiveXObject("Msxml2.XMLHTTP");
	
						} 
						catch (e) 
						{
	
							try 
							{
	
								Ajax = new ActiveXObject("Microsoft.XMLHTTP");
	
							} 
							catch (e) 
							{
							}
	
						}
	
					}		
	
	}
	
	function buscar(retorno)
	{
		
		var stopResp =0;
		
		if(retorno=="")
		{
			stopResp = 1;	
		}
		if(!Ajax)
		{
			alert('Não foi possivel iniciar o Ajax!');
			return;
		}
		else
		{
			Ajax.onreadystatechange = function()
			{
				
				if(Ajax.readyState==4)
				{ 
					switch(Ajax.status)
					{
						case 200:
						if(!stopResp==1)
						{
						 retorno.main(Ajax);
						}
						break;
						case 404:
						alert('Pagina não encontrada!');
						break;
					}
				}
			}
			Ajax.open('POST',this.arq_xml,true)
			Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			Ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			Ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			Ajax.setRequestHeader("Pragma", "no-cache");
			Ajax.send(this.dadosEnv);
			
		}
		
	
	}
	
	
	
	
	
	

}





