/*
	@Função: createXMLHTTP() -- Cria objeto XML
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 18/09/2008
*/
function createXMLHTTP() {
	try {
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		var xmlhttp = false;
		for (var i=0; i < arrSignatures.length; i++) {
			try {
				var oRequest = new ActiveXObject(arrSignatures[i]);
				xmlhttp = oRequest;
				break;
			} catch (oError) {
			}
		}
		if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
		{
			//PARA O FIREFOX
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	} catch(e){ alert(e); }
}

/*
	@Função: createXMLHTTP() -- DECODA XML
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 18/09/2008
*/
function URLDecode(psEncodeString) {
  var lsRegExp = /\+/g;
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

/*
	@Função: fu_carrega_secao() -- Carrega SUBCATEGORIAS DE PRODUTOS
	@params:
		ID = id da "SQL.prod_categoria.[ID]"
		NIVEL = qual o nivel a buscar filtrando pelo ID
		VALOR_INI = valor que a combo deve selecionar ao carregar
		CARREGA_SUB = 't' ou 'f', carrega ou não, o PROXIMO NIVEL
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 18/09/2008
*/
function fu_carrega_secao(id, nivel, valor_ini, carrega_sub)
{
	try {
		if (id >= 0) {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_secaoprod_ajax.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_secao" + nivel).innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					if (document.getElementById("div_secao" + nivel).innerHTML=="carregando.")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando..";
					else if (document.getElementById("div_secao" + nivel).innerHTML == "carregando..")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando...";
					else
						document.getElementById("div_secao" + nivel).innerHTML = "carregando.";
				}
			}
			if(valor_ini != "")
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&valor_ini=" + valor_ini + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
			else
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
		}
	} catch(e) { alert(e); }	
}


/*
	@Função: fu_carrega_secao_veiculos() -- Carrega SUBCATEGORIAS DE VEICULOS
	@params:
		ID = id da "SQL.prod_categoria.[ID]"
		NIVEL = qual o nivel a buscar filtrando pelo ID
		VALOR_INI = valor que a combo deve selecionar ao carregar
		CARREGA_SUB = 't' ou 'f', carrega ou não, o PROXIMO NIVEL
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 20/12/2008
*/
function fu_carrega_secao_veiculos(id, nivel, valor_ini, carrega_sub)
{
	try {
		if (id >= 0) {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_secaoprodveiculos_ajax.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_secao" + nivel).innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					if (document.getElementById("div_secao" + nivel).innerHTML=="carregando.")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando..";
					else if (document.getElementById("div_secao" + nivel).innerHTML == "carregando..")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando...";
					else
						document.getElementById("div_secao" + nivel).innerHTML = "carregando.";
				}
			}
			if(valor_ini != "")
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&valor_ini=" + valor_ini + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
			else
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
		}
	} catch(e) { alert(e); }	
}



/*
	@Função: LimpaSelect() -- Elimina registros do <Select>
	@params: 
		ID = id do Objeto
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 03/10/2008
*/
function LimpaSelect(id) {
	try {
		while (document.getElementById(id).options.length > 0) {
			document.getElementById(id).remove(document.getElementById(id).options.length-1);
		}
	} catch (e) {}
}


/*
	@Função: Ajax_CarregaFuncMother() -- carrega função mãe
	@params: 
		ID = id do Objeto
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 03/10/2008
*/
function Ajax_CarregaFuncMother(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/carregaXML_funcmother.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA CIDADE
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA CIDADE
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
				
				
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("cod_modulo=" + valor);
	} catch(e) { alert(e); }

}		




/*
	@Função: fu_carrega_secaoMultiple() -- Carrega SUBCATEGORIAS DE PRODUTOS
	@params:
		ID = id da "SQL.prod_categoria.[ID]"
		NIVEL = qual o nivel a buscar filtrando pelo ID
		VALOR_INI = valor que a combo deve selecionar ao carregar
		CARREGA_SUB = 't' ou 'f', carrega ou não, o PROXIMO NIVEL
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 06/10/2008
*/
function fu_carrega_secaoMultiple(id, nivel, valor_ini, carrega_sub)
{
	try {
		if (id >= 0) {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_secaoprodmultiple_ajax.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_secao" + nivel).innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					if (document.getElementById("div_secao" + nivel).innerHTML=="carregando.")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando..";
					else if (document.getElementById("div_secao" + nivel).innerHTML == "carregando..")
						document.getElementById("div_secao" + nivel).innerHTML = "carregando...";
					else
						document.getElementById("div_secao" + nivel).innerHTML = "carregando.";
				}
			}
			if(valor_ini != "")
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&valor_ini=" + valor_ini + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
			else
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
		}
	} catch(e) { alert(e); }	
}




/*
	@Função: Ajax_CarregaCidadeSistema() -- Carrega cidades na combo via xml 'somente cidades que fazem parte do sistema(lojas participantes)
	@params: 
		objeto = OBJETO DESTINO XML
		uf = FILTRO POR ESTADO
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 13/10/2008
*/
function Ajax_CarregaCidadeSistema(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_cidadesistema_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA CIDADE
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA CIDADE
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
				
				
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("uf=" + valor);
	} catch(e) { alert(e); }

}



/*
	@Função: Ajax_CarregaCidade() -- Carrega cidades na combo via xml 'todas as cidades
	@params: 
		objeto = OBJETO DESTINO XML
		uf = FILTRO POR ESTADO
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 16/04/2009
*/
function Ajax_CarregaCidade(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		
		oHTTPRequest.open("post", '../ajax/carrega_cidade_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA CIDADE
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA CIDADE
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
				
				
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("uf=" + valor);
	} catch(e) { alert(e); }

}


function Ajax_CarregaCidade_LojaVirtual(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		
		oHTTPRequest.open("post", 'carrega_cidade_ajax_site.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA CIDADE
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA CIDADE
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
				
				
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("uf=" + valor);
	} catch(e) { alert(e); }

}


/*
	@Função: Ajax_CarregaPacote() -- Carrega pacote dos produtos
	@params: 
		objeto = OBJETO DESTINO XML
		valor = FILTRAR TABELA POR CIDADE
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 14/10/2008
*/
function Ajax_CarregaPacote(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_pacote_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DO PACOTE
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DO PACOTE
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
				
				
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("id_cidade=" + valor);
	} catch(e) { alert(e); }

}




/*
	@Função: fu_carrega_secao_p() -- Carrega SUBCATEGORIAS DE PRODUTOS PARA O PORTAL
	@params:
		ID = id da "SQL.prod_categoria.[ID]"
		NIVEL = qual o nivel a buscar filtrando pelo ID
		VALOR_INI = valor que a combo deve selecionar ao carregar
		CARREGA_SUB = 't' ou 'f', carrega ou não, o PROXIMO NIVEL
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 27/10/2008
*/
function fu_carrega_secao_p(id, nivel, valor_ini, carrega_sub)
{
	try {
		if (id >= 0) {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_secaoprod_portal_ajax.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_secao_portal" + nivel).innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					if (document.getElementById("div_secao_portal" + nivel).innerHTML=="carregando.")
						document.getElementById("div_secao_portal" + nivel).innerHTML = "carregando..";
					else if (document.getElementById("div_secao_portal" + nivel).innerHTML == "carregando..")
						document.getElementById("div_secao_portal" + nivel).innerHTML = "carregando...";
					else
						document.getElementById("div_secao_portal" + nivel).innerHTML = "carregando.";
				}
			}
			if(valor_ini != "")
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&valor_ini=" + valor_ini + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
			else
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5");
			}
		}
	} catch(e) { alert(e); }	
}



/*
	@Função: ChangeImage() -- Troca Imagens no Portal
	@params:
		ID = id do Produto
		SEQUENCIA = sequencia da Foto
		TAMANHO = tamanho da Foto P, V, M, G
		DIV = div destino do HTML
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 03/11/2008
*/
function ChangeImage(id, sequencia, tamanho, div, linkPop)
{
	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/changeimage.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(div).innerHTML = URLDecode(oHTTPRequest.responseText);
			} else {
				document.getElementById(div).innerHTML = "carregando...";
			}
		}
		oHTTPRequest.send("id=" + id + "&sequencia=" + sequencia + "&tamanho=" + tamanho + "&linkPop="+ linkPop);
	} catch(e) { alert(e); }	
}


/*
	@Função: fu_carrega_tabela_frete() -- Carrega tabela de Frete
	@params:
		ID_FORMAENTREGA = id para montar tabela de frete
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 10/11/2008
*/
function fu_carrega_tabela_frete(id_formaentrega)
{
	try {
		if (id_formaentrega != "") {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_tabelafrete.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("tabela_frete").innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					document.getElementById("tabela_frete").innerHTML = "<img src=\"../../i/ajax/carregando.png\">";
				}
			}
			oHTTPRequest.send("id=" + id_formaentrega);
		}
	} catch(e) { alert(e); }	
}


/*
	@Função: EnviarFaturaEmail() -- Enviar Fatura por E-mail ao Cliente
	@params:
		RC = código da revenda
		FP = período da fatura formato, ex. = '2008-11'
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 11/11/2008
*/
function EnviarFaturaEmail(rc, fp)
{

	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../../scripts/faturarevenda_enviaremail.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				alert(URLDecode(oHTTPRequest.responseText));
			} else {
			}
		}
		oHTTPRequest.send("reve_cod="+ rc +"&fatura_periodo="+ fp);
		
	} catch(e) { alert(e); }
}



/*
	@Função: Ajax_CarregaLojaXCidade() -- Carrega lojas na combo via xml 'todas as lojas da cidade
	@params: 
		objeto = OBJETO DESTINO XML
		valor = FILTRO POR CIDADE
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 11/11/2008
*/
function Ajax_CarregaLojaXCidade(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_lojaxcidade_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA LOJA
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA LOJA
				for (i = 0 ; i < v.length ; i++) {			
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("cod_cidade=" + valor);
	} catch(e) { alert(e); }
	
}


/*
	@Função: Ajax_CarregaAgenciaLoja() -- Carrega Agências da lojas na combo via xml 'todas as agências bancárias cadastradas para a loja
	@params: 
		objeto = OBJETO DESTINO XML
		valor = FILTRO POR BANCO
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 12/11/2008
*/
function Ajax_CarregaAgenciaLoja(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_agencialoja_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA LOJA
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA LOJA
				for (i = 0 ; i < v.length ; i++) {			
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("banc_cod=" + valor);
	} catch(e) { alert(e); }
	
}


/*
	@Função: Ajax_CarregaSubcategoria() -- Carrega SubCategoria do Financeiro
	@params: 
		objeto = OBJETO DESTINO XML
		valor = FILTRO POR CATEGORIA
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 13/11/2008
*/
function Ajax_CarregaSubcategoria(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_subcategoriafinan_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID DA LOJA
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME DA LOJA
				for (i = 0 ; i < v.length ; i++) {			
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("cate_cod=" + valor);
	} catch(e) { alert(e); }
	
}



/*
	@Função: Ajax_ContaCorrenteExclude() -- Carrega Conta-corrente da Loja, excluindo conta origem
	@params: 
		objeto = OBJETO DESTINO XML
		valor = FILTRO POR CONTA-CORRENTE
		valor_inicial = VALOR QUE DEVE CARREGAR SELECIONADO
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 15/11/2008
*/
function Ajax_ContaCorrenteExclude(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_contacorrenteexclude_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DA DESCRICAO
				for (i = 0 ; i < v.length ; i++) {			
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("conta_cod=" + valor);
	} catch(e) { alert(e); }
	
}



/*
	@Função: CarregaSaldoContaCorrente() -- Carrega Saldo Conta-Corrente Loja
	@params:
		objeto = objeto destino
		valor = id conta-corrente
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 15/11/2008
*/
function CarregaSaldoContaCorrente(objeto, valor)
{

	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/carrega_saldocontacorrente.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
			} else {
			}
		}
		oHTTPRequest.send("conta_cod="+ valor);
	} catch(e) { alert(e); }
}



/*
	@Função: Ajax_CarregarBairro() -- Carrega Bairro da Cidade
	@params:
		objeto = objeto destino
		valor = id cidade
		valor_inicial = id_bairro inicial
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 15/11/2008
*/
function Ajax_CarregarBairro(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", '../ajax/carrega_bairro_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID
				t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DA DESCRICAO
				for (i = 0 ; i < v.length ; i++) {			
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("cod_cidade=" + valor);
	} catch(e) { alert(e); }
	
}



function Ajax_PesquisaTextual(objeto, valor, tipo)
{
	try {
		
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/pesquisar_produto_keypress.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
				document.getElementById('retornarPesquisa').style.display = 'block';
			}
			else
			{
				document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
			}
		}
		
		oHTTPRequest.send("pesquisa=" + valor + "&tipo_oper=" + tipo);
		
	} catch(e) { alert(e); }

}		


function buscar_item(valor, tipo)
{

	if (tipo=="P") {
		document.getElementById('peso').focus();
	} else {
		document.getElementById('quantidade').focus();
	}

	document.getElementById('codigo_produto').value = valor;
	Ajax_CarregarDescricaoProduto('nom_produto', valor, tipo);
	document.getElementById('retornarPesquisa').style.display = 'none';
}	


function buscar_item_cadastro(valor, tipo)
{
	document.getElementById('cod_cliente').value = valor;
	Ajax_CarregarDescricaoCadastro('nom_fantasia', valor, tipo);	
	document.getElementById('retornarCadastro').style.display = 'none';
	//document.getElementById('nom_fantasia').focus();
}	


function Ajax_PesquisaTextualCadastro(objeto, valor, tipo)
{
	try {
		
		var oHTTPRequest = new createXMLHTTP(); 
		
		if (tipo=='f') {
			oHTTPRequest.open("post", '../ajax/pesquisar_fornecedor_keypress.php', true);
		} else if (tipo=='c') {
			oHTTPRequest.open("post", '../ajax/pesquisar_cliente_keypress.php', true);
		} else if (tipo=='t') {
			oHTTPRequest.open("post", '../ajax/pesquisar_transportador_keypress.php', true);
		}
		
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
				document.getElementById('retornarCadastro').style.display = 'block';
			}
			else
			{
				document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
			}
		}
		
		oHTTPRequest.send("cadastro=" + valor + "&tipo=" + tipo);
		
	} catch(e) { alert(e); }

}		


function Ajax_CarregarDescricaoProduto(objeto, valor, tipo_operacao)
	{
		try {
			
			document.getElementById(objeto).value = '';	
			document.getElementById('valor').value = '';			

			if(valor!="")
			{
			
				var oHTTPRequest = new createXMLHTTP(); 
				oHTTPRequest.open("post", '../ajax/carrega_descricao_produto.php', true);
				oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				oHTTPRequest.onreadystatechange=function() {
					if (oHTTPRequest.readyState==4){
						v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID
						t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME
						u = oHTTPRequest.responseXML.getElementsByTagName('ref'); 						
						z = oHTTPRequest.responseXML.getElementsByTagName('valor'); 
						
						if (tipo_operacao=='P') {
							c1 = oHTTPRequest.responseXML.getElementsByTagName('veloc_pux');
							c2 = oHTTPRequest.responseXML.getElementsByTagName('veloc_maq');
							c3 = oHTTPRequest.responseXML.getElementsByTagName('veloc_inv');
							c4 = oHTTPRequest.responseXML.getElementsByTagName('pressao_ar');
							c5 = oHTTPRequest.responseXML.getElementsByTagName('diametro_enrolador');
							c6 = oHTTPRequest.responseXML.getElementsByTagName('diametro_ext');
							c7 = oHTTPRequest.responseXML.getElementsByTagName('espessura');
							c8 = oHTTPRequest.responseXML.getElementsByTagName('medida');
							c9 = oHTTPRequest.responseXML.getElementsByTagName('peso_prod');							
						}
						
						
						x = 0;
						
						for (i = 0 ; i < v.length ; i++) {
							x = 1;
							
							if (tipo_operacao=='P') {
								document.getElementById('veloc_pux').value = URLDecode(c1[i].firstChild.nodeValue);
								document.getElementById('veloc_maq').value = URLDecode(c2[i].firstChild.nodeValue);
								document.getElementById('veloc_inv').value = URLDecode(c3[i].firstChild.nodeValue);
								document.getElementById('pressao_ar').value = URLDecode(c4[i].firstChild.nodeValue);
								document.getElementById('diametro_enrolador').value = URLDecode(c5[i].firstChild.nodeValue);
								document.getElementById('diametro_ext').value = URLDecode(c6[i].firstChild.nodeValue);
								document.getElementById('espessura').value = URLDecode(c7[i].firstChild.nodeValue);
								document.getElementById('medida').value = URLDecode(c8[i].firstChild.nodeValue);
								document.getElementById('peso_prod').value = URLDecode(c9[i].firstChild.nodeValue);
							}
							
							document.getElementById(objeto).value = URLDecode(t[i].firstChild.nodeValue);
							document.getElementById('valor').value = URLDecode(z[i].firstChild.nodeValue);
						}
						
						if(x == 0)
						{
							document.getElementById(objeto).value = 'Produto não encontrado.';
							document.getElementById('codigo_produto').value = '';
							document.getElementById('codigo_produto').focus();
						}

					}
					else
					{
						document.getElementById(objeto).value = 'Carregando...';
					}
				}
				oHTTPRequest.send("id=" + valor + "&tipo=" + tipo_operacao);
			}
		} catch(e) { alert(e); }
	
	}		


/*
	@Função: CarregaAnoModelo() -- Carrega Ano Modelo, através da informação do ano fabricação
	@params: 
		ano_fabricacao, valor_ini
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 22/12/2008
*/
function CarregaAnoModelo(ano_fabricacao, valor_ini) {
	try {

		LimpaSelect('ano_modelo');		

		var o = new Option("---- Selecione ----" ,"" , false, false);
		document.getElementById('ano_modelo').options[0] = o;
		
		if(ano_fabricacao!=""){		
			valor_ini = parseFloat(valor_ini);
			ano_modelo = parseFloat(ano_fabricacao) + 1;
			
			x = false;
			if(valor_ini == ano_modelo){ x = true; }
			var o = new Option(ano_modelo, ano_modelo, false, x);
			document.getElementById('ano_modelo').options[1] = o;

			x= false;
			if(valor_ini == ano_fabricacao){ x = true; }
			var o = new Option(ano_fabricacao, ano_fabricacao, false, x);
			document.getElementById('ano_modelo').options[2] = o;
		}
		
	} catch (e) {}
}



/*
	@Função: grava_produtoPortal() -- Grava Produto Portal
	@params:
		idProduto = CODIGO DO PRODUTO A GRAVAR
		idCategoriaPortal = CATEGORIA A GRAVAR
		nomeDiv = NOME DA DIV A ZERAR
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 26/12/2008
*/
function grava_produtoPortal(frm, idProduto, nomeDiv)
{
	try {

		if(frm.departamento_portal.value==""){
			alert("Informe o departamento!");
			frm.departamento_portal.focus();
			return false;
		}

		if(frm.categoria_portal2.value==""){
			alert("Selecione a Seção!");
			frm.categoria_portal2.focus();
			return false;
		}
		
		var idCategoriaPortal;
		
		idCategoriaPortal = frm.categoria_portal2.value;
		
		if(frm.categoria_portal3.value!=""){
			idCategoriaPortal = frm.categoria_portal3.value;
		}
		if(frm.categoria_portal4.value!=""){
			idCategoriaPortal = frm.categoria_portal4.value;
		}
		if(frm.categoria_portal5.value!=""){
			idCategoriaPortal = frm.categoria_portal5.value;
		}
		


		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/grava_produtoportal.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function(){
			if (oHTTPRequest.readyState==4){
				document.getElementById(nomeDiv).innerHTML = URLDecode(oHTTPRequest.responseText);
			}
		}
		if(idCategoriaPortal != ""){
			oHTTPRequest.send("idProduto=" + idProduto + "&idCategoriaPortal=" + idCategoriaPortal);
		}else{
			alert("Selecione a categoria Destino!");
			return false;
		}
	} catch(e) { alert(e); }	
}


/*
	@Função: fu_carrega_secao_p_multi() -- Carrega SUBCATEGORIAS DE PRODUTOS PARA O PORTAL
	@params:
		ID = id da "SQL.prod_categoria.[ID]"
		NIVEL = qual o nivel a buscar filtrando pelo ID
		VALOR_INI = valor que a combo deve selecionar ao carregar
		CARREGA_SUB = 't' ou 'f', carrega ou não, o PROXIMO NIVEL
		BOX = id do BOX
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 26/12/2008
*/
function fu_carrega_secao_p_multi(id, nivel, valor_ini, carrega_sub, box)
{
	try {
		if (id >= 0) {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_secaoprod_portalmulti_ajax.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("div_secao_portal" + nivel + "_" + box).innerHTML = URLDecode(oHTTPRequest.responseText);
				} else {
					document.getElementById("div_secao_portal" + nivel + "_" + box).innerHTML = "carregando..";
				}
			}
			if(valor_ini != "")
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&valor_ini=" + valor_ini + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5&box=" + box);
			}
			else
			{
				oHTTPRequest.send("id=" + id + "&nivel=" + nivel + "&carrega_subnivel=" + carrega_sub + "&limite_nivel=5&box=" + box);
			}
		}
	} catch(e) { alert(e); }	
}


/*
	@Função: InsereTagsProduto() -- Testa e Chama Inserção de Tags para o Produto
	@params:
		TAGS = tags a serem inseridas, separadas por virgula
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 18/04/2009
*/
function InsereTagsProduto(tags, id_grupotag, tp)
{
	try {
		if (tags.value != "") {
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/grava_tagsproduto.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById("produtos_tagueados").innerHTML = URLDecode(oHTTPRequest.responseText);
					tags.value='';
					tags.focus();
				} else {
					document.getElementById("produtos_tagueados").innerHTML = "carregando...";
				}
			}
			oHTTPRequest.send("tags=" + tags.value + "&id_grupotag=" + id_grupotag.value + "&tp=" + tp);
		}else{
			alert("Por favor preencha as tags para o produto!");
			document.incluir.tags.focus();
		}
	} catch(e) { alert(e); }
}


/*
	@Função: Check_TagsProduto() -- Carrega, descarrega sessão de controle de tags
	@params:
		TAGS = objeto que contem valores de tags
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 19/04/2009
*/
function Check_TagsProduto(tags)
{
	try {
		
		var_tags = '';
		
		for(i=0;i<tags.length;i++){
			
			if(tags[i].checked){
			
				if(var_tags==''){
					var_tags = tags[i].value;
				}else{
					var_tags = var_tags + ', ' + tags[i].value;
				}
			
			}
			
		}
		
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", '../ajax/check_tagsproduto.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				//alert(URLDecode(oHTTPRequest.responseText));
			}
		}
		oHTTPRequest.send("tags=" + var_tags);
		
	} catch(e) { alert(e); }
}


function Ajax_CarregaSubGrupo(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		
		oHTTPRequest.open("post", '../ajax/carrega_subgrupo_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); 
				t = oHTTPRequest.responseXML.getElementsByTagName('nome');
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
								
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("id=" + valor);
	} catch(e) { alert(e); }

}

function Ajax_CarregaItemSubGrupo(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		
		oHTTPRequest.open("post", '../ajax/carrega_itemsubgrupo_ajax.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				var o = new Option("-- Selecione --" ,0 , false, false);
				document.getElementById(objeto).options[0] = o;
				v = oHTTPRequest.responseXML.getElementsByTagName('id'); 
				t = oHTTPRequest.responseXML.getElementsByTagName('nome');
				for (i = 0 ; i < v.length ; i++) {			
				
					start_option = false;
					if(valor_inicial == v[i].firstChild.nodeValue){
						start_option = true;
					}
								
					var o = new Option(URLDecode(t[i].firstChild.nodeValue),v[i].firstChild.nodeValue, false, start_option);
					document.getElementById(objeto).options[document.getElementById(objeto).options.length] = o;
				}
				
			}
			else
			{
				var o = new Option("Carregando...." ,"" , false, false);
				document.getElementById(objeto).options[0] = o;
			}
		}
		oHTTPRequest.send("id=" + valor);
	} catch(e) { alert(e); }

}


	function Ajax_InserirItemCompra(objeto)
	{
		try {
			
			//validacao
			if(document.getElementById('codigo_produto').value == '')
			{
				alert("Por favor, informe o código do produto!");
				document.getElementById('codigo_produto').focus();
				return(false);
			}
			
			if(document.getElementById('quantidade').value == '')
			{
				alert("Por favor, informe a quantidade!");
				document.getElementById('quantidade').focus();
				return(false);
			}
	
			if(document.getElementById('valor').value == '')
			{
				alert("Por favor, informe o valor de compra!");
				document.getElementById('valor').focus();
				return(false);
			}		
			
			
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_itens_compra.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){					
					document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
					document.getElementById('codigo_produto').value = '';
					document.getElementById('nom_produto').value = '';
					document.getElementById('quantidade').value = '';
					document.getElementById('valor').value = '';
				}
				else
				{
					document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
				}
			}		
			oHTTPRequest.send("id=" + document.getElementById('codigo_produto').value + "&quantidade=" + document.getElementById('quantidade').value + "&valor=" + document.getElementById('valor').value + "&fornecedor=" + document.getElementById('cod_cliente').value);
		} catch(e) { alert(e); }
	
	}		
	
	
	function Ajax_InserirItemProducao(objeto)
	{
		try {
			
			if(document.getElementById('peso').value == '')
			{
				alert("Por favor, informe o peso!");
				document.getElementById('peso').focus();
				return(false);
			}
	
			if(document.getElementById('nom_produto').value == '')
			{
				alert("Por favor, informe o produto!");
				document.getElementById('nom_produto').focus();
				return(false);
			}		
			
			
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_itens_producao.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){					
					document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);					
					//document.getElementById('codigo_produto').value = '';
					document.getElementById('peso').value = '';
					document.getElementById('peso').focus();
				}
				else
				{
					document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
				}
			}		
			oHTTPRequest.send("id=" + document.getElementById('codigo_produto').value + "&peso=" + document.getElementById('peso').value);
		} catch(e) { alert(e); }
	
	}		
	
	
	function Ajax_RemoverItemProducao(objeto, id_item)
	{
		try {
			
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_itens_producao.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
				}
				else
				{
					document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
				}
			}
			oHTTPRequest.send("id=" + id_item + "&acao=EXC");
		} catch(e) { alert(e); }
	
	}		
	
	function Ajax_RemoverItemCompra(objeto, id_item)
	{
		try {
			
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_itens_compra.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
				}
				else
				{
					document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
				}
			}
			oHTTPRequest.send("id=" + id_item + "&acao=EXC");
		} catch(e) { alert(e); }
	
	}		
	
	
	function Ajax_CarregarItensCompra(objeto)
	{
		try {
			
			var oHTTPRequest = new createXMLHTTP(); 
			oHTTPRequest.open("post", '../ajax/carrega_itens_compra.php', true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					document.getElementById(objeto).innerHTML = URLDecode(oHTTPRequest.responseText);
				}
				else
				{
					document.getElementById(objeto).innerHTML = '<img src="../../i/ajax/carregando.png">';
				}
			}
			oHTTPRequest.send("id=0&acao=EXC");
		} catch(e) { alert(e); }
	
	}		
	
	
	function Ajax_CarregarDescricaoCadastro(objeto, valor, tipo)
	{
		try {
			
			document.getElementById(objeto).value = '';			
			
			if(valor!="")
			{
			
				var oHTTPRequest = new createXMLHTTP(); 
				
				if (tipo=='f') {
					oHTTPRequest.open("post", '../ajax/carrega_descricao_fornecedor.php', true);
				} else if (tipo='c') {
					oHTTPRequest.open("post", '../ajax/carrega_descricao_cliente.php', true);
				} else if (tipo='t') {
					oHTTPRequest.open("post", '../ajax/carrega_descricao_transportador.php', true);
				}
				
				oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				oHTTPRequest.onreadystatechange=function() {
					if (oHTTPRequest.readyState==4){
						v = oHTTPRequest.responseXML.getElementsByTagName('id'); //VALOR DO ID
						t = oHTTPRequest.responseXML.getElementsByTagName('nome'); //VALOR DO NOME
						x = 0;
						
						for (i = 0 ; i < v.length ; i++) {
							x = 1;
							document.getElementById(objeto).value = URLDecode(t[i].firstChild.nodeValue);
						}
						
						if(x == 0)
						{
							document.getElementById(objeto).value = 'Registro não encontrado.';
							document.getElementById('cod_cliente').value = '';
							document.getElementById('nom_fantasia').focus();
						}

					}
					else
					{
						document.getElementById(objeto).value = 'Carregando...';
					}
				}
				oHTTPRequest.send("id=" + valor);
			}
		} catch(e) { alert(e); }
	
	}		
