function getXmlHttpRequest()
{	XmlHTTP   = false;
	
	if (window.XMLHttpRequest) 
	{	xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) 
		{	xmlhttp.overrideMimeType('text/xml'); }
		return xmlhttp;
	} 
	else 
	if (window.ActiveXObject) 
	{	try 
		{ 	xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			return xmlhttp; }
		catch (e)
		{ 	xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			return xmlhttp; }
	}

	if (!xmlhttp) 
	{	alert('XMLHTTP NÃP pode ser instanciado !');
        return false;
    }
}
var XmlHTTP = getXmlHttpRequest();

function BuscaXML(wFrame, wUrl, wVarObj) 
{	XmlHTTP.open('GET', AntiChache(wUrl), true);
	XmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	XmlHTTP.setRequestHeader('Content-Type', 'text/xml');
	XmlHTTP.setRequestHeader('encoding','ISO-8859-1');
  	XmlHTTP.setRequestHeader("Cache-Control", "no-cache");
  	XmlHTTP.setRequestHeader("Pragma", "no-cache");
    XmlHTTP.onreadystatechange = function()
	{	if (XmlHTTP.readyState == 4) 
		{	xVetor1 = xmlhttp.responseText.split('||');
			if (xVetor1.length >= 0)
			{	document.getElementById(wVarObj).disabled = false;
				if (navigator.userAgent.indexOf("MSIE") >= 0)
				{	AdicionaXML(xmlhttp.responseText);
				}
				else
				{	document.getElementById(wVarObj).innerHTML = xmlhttp.responseText; }
 			}
       	}
	}

	XmlHTTP.send(null);
	

	// SubFuncao para NÃO haver Cache na chamada
	function AntiChache()
	{	var dt = new Date();
    	if(wUrl.indexOf("?") >= 0)
		{	return wUrl + "&" + encodeURI(Math.random() + "_" + dt.getTime()); }
		else
		{	return wUrl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
	}
	// SubFuncao remover Lista	
	function RemoveTudo() 
	{	var tam = document.getElementById(wVarObj).length+1;
		for (x=0; x <= tam; x++)
			document.getElementById(wVarObj).remove(x);
	}
	// SubFuncao popular Lista
	function Adiciona(texto,valor) 
	{	linha       = document.createElement("OPTION");
		linha.text  = texto;
		linha.value = valor;
		document.getElementById(wVarObj).add(linha);
	}
	// SubFuncao popular Lista
	function AdicionaXML(innerHTML) 
	{	innerHTML = "<select name='" +wVarObj+ "' size='1' class='campo' id='" +wVarObj+ "'>" + innerHTML + "</select>";
		document.getElementById(wFrame).innerHTML = innerHTML;
	}
}

function ProdutoXML(wProduto, wCliente, wUrl) 
{	wUrl = wUrl + wProduto + "&idCliente=" + wCliente;
	XmlHTTP.open('GET', AntiChache(wUrl), true);
	XmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	XmlHTTP.setRequestHeader('Content-Type', 'text/xml');
	XmlHTTP.setRequestHeader('encoding','ISO-8859-1');
  	XmlHTTP.setRequestHeader("Cache-Control", "no-cache");
  	XmlHTTP.setRequestHeader("Pragma", "no-cache");
    XmlHTTP.onreadystatechange = function()
	{	if (XmlHTTP.readyState == 4) 
		{	xVetor1 = parseInt(xmlhttp.responseText);
			if (xVetor1 >= 0)
			{	if (xVetor1 == 1)
				{	alert('Produto : ' + wProduto + ' cadastrado com SUCESSO !'); }
				else
				{	alert('Produto : ' + wProduto + ' já cadastrado !'); }
			}
			else
			{	alert('Produto : ' + wProduto + ' NÃO cadastrado !'); }
			seleciona(0);
       	}
	}

	XmlHTTP.send(null);
	

	// SubFuncao para NÃO haver Cache na chamada
	function AntiChache()
	{	var dt = new Date();
    	if(wUrl.indexOf("?") >= 0)
		{	return wUrl + "&" + encodeURI(Math.random() + "_" + dt.getTime()); }
		else
		{	return wUrl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
	}
}
