/*
	@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: 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: 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 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("modu_cod=" + 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: 13/10/2008
*/
function Ajax_CarregaCidade(objeto, valor, valor_inicial)
{
	try {
		
		LimpaSelect(objeto);
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", 'admin/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", 'carregacidades.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("id=" + 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", '/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("cida_cod=" + 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("cida_cod=" + valor);
	} catch(e) { alert(e); }
	
}



/*
	@Função: Swap_TipoPessoa()
	@params:
		obj1 = objeto, SHOW
		obj2 = objeto, HIDDEN
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 22/11/2008
*/
function Swap_TipoPessoa(obj1, obj2){
	
	document.getElementById(obj1).style.display = 'block';
	document.getElementById(obj2).style.display = 'none';
	
	if(obj1=="tipo_pessoa_J"){
		document.incluir.tipo_pessoa[0].checked = true;
		document.incluir.tppessoa.value = "J";
		document.incluir.razao_social.focus();
	}else{
		document.incluir.tipo_pessoa2[1].checked = true;
		document.incluir.tppessoa.value = "F";
		document.incluir.nome.focus();
	}
	
}


/*
	@Função: CalcularFrete() -- Calcular Opções de Frete Para o Carrinho de Compras
	@params:
		frm = formulario contendo as informações para calculo
		objeto = objeto destino
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 29/11/2008
*/
function CalcularFrete(frm, objeto, nameForm, sequencia){
	
	try {
		
		if(frm.cep1.value == ""){
			alert("Por favor, preencha o cep!");
			frm.cep1.focus();
			return(false);
		}

		if(frm.cep2.value == ""){
			alert("Por favor, preencha o cep!");
			frm.cep2.focus();
			return(false);
		}
		
		//montando url post - carrinho
		url = "idloja="+ frm.idloja.value;
		url += "&cep1="+ frm.cep1.value;
		url += "&cep2="+ frm.cep2.value;

		tt = frm.elements.length;
		qtde="";
		idproduto="";
		idproduto_detalhe="";
		for(i=0;i<tt;i++){
			if(frm.elements[i].name=="qtde[]"){
				if(qtde==""){ qtde = frm.elements[i].value;	}else{ qtde += ","+frm.elements[i].value; }
			}

			if(frm.elements[i].name=="idproduto[]"){
				if(idproduto==""){ idproduto = frm.elements[i].value;	}else{ idproduto += ","+frm.elements[i].value; }
			}

			if(frm.elements[i].name=="idproduto_detalhe[]"){
				if(idproduto_detalhe==""){ idproduto_detalhe = frm.elements[i].value;	}else{ idproduto_detalhe += ","+frm.elements[i].value; }
			}

		}
		
		url +="&qtde="+qtde;
		url +="&idproduto="+idproduto;
		url +="&idproduto_detalhe="+idproduto_detalhe;
		url +="&itens="+ frm.itens.value;
		url += "&frmAcao=CF";
		url += "&frmName=" + nameForm;
		url += "&sequencia=" + sequencia;
		
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", 'adiciona_carrinho.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(objeto).innerHTML = oHTTPRequest.responseText;
			}
			else
			{
				document.getElementById(objeto).innerHTML = "<p><img src=\"img/carrinho/seta_preta.png\" width=\"6\" height=\"9\" /> Pesquisando o Melhor Frete, por favor aguarde!</p>";
			}
		}
		oHTTPRequest.send(url);
		
	} catch(e) { alert(e); }
	
}


/*
	@Função: SomarFrete() -- Somar Frete e Embutir no Carrinho de Compras
	@params:
		frm = formulario contendo as informações para calculo
		sequencia = sequencia para abrir os divs corretamente
		CartFrete = Area da Página que contém somente o valor do frete
		CartTotal = Area da Página que contém o Valor total da Compra
		CartDesconto = Area da Página que traz Desconto A Vista
		CartParcelamento = Area da Página que traz Valores Parcelados
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 29/11/2008
*/
function SomarFrete(frm, CartFrete, CartTotal, CartDesconto, CartParcelamento){
	
	try {
		
		//montando url post - carrinho
		tt = frm.elements.length;
		id_formaentrega = "";
		for(i=0;i<tt;i++){
			if(frm.elements[i].name=="id_formaentrega" && frm.elements[i].checked==true){
				if(id_formaentrega==""){ id_formaentrega = frm.elements[i].value; }
			}
		}
		//montando url post - carrinho
		url = "idloja="+ frm.idloja.value;
		url +="&id_formaentrega="+ id_formaentrega;

		//calculo 1, valor do frete isolado
		var oHTTPRequest = new createXMLHTTP();
		oHTTPRequest.open("post", 'adiciona_carrinho.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
			if (oHTTPRequest.readyState==4){
				document.getElementById(CartFrete).innerHTML = oHTTPRequest.responseText;
			}else{
				document.getElementById(CartFrete).innerHTML = "Aguarde, recalculando!";
			}
		}
		oHTTPRequest.send(url+"&frmAcao=SFE");


		var oHTTPRequest2 = new createXMLHTTP();
		oHTTPRequest2.open("post", 'adiciona_carrinho.php', true);
		oHTTPRequest2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest2.onreadystatechange=function() {
			if (oHTTPRequest2.readyState==4){
				document.getElementById(CartTotal).innerHTML = oHTTPRequest2.responseText;
			}else{
				document.getElementById(CartTotal).innerHTML = "Aguarde, recalculando!";
			}
		}
		oHTTPRequest2.send(url+"&frmAcao=STC");


		var oHTTPRequest3 = new createXMLHTTP();
		oHTTPRequest3.open("post", 'adiciona_carrinho.php', true);
		oHTTPRequest3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest3.onreadystatechange=function() {
			if (oHTTPRequest3.readyState==4){
				document.getElementById(CartDesconto).innerHTML = oHTTPRequest3.responseText;
			}else{
				document.getElementById(CartDesconto).innerHTML = "Aguarde, recalculando!";
			}
		}
		oHTTPRequest3.send(url+"&frmAcao=STD");

		var oHTTPRequest4 = new createXMLHTTP();
		oHTTPRequest4.open("post", 'adiciona_carrinho.php', true);
		oHTTPRequest4.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest4.onreadystatechange=function() {
			if (oHTTPRequest4.readyState==4){
				document.getElementById(CartParcelamento).innerHTML = oHTTPRequest4.responseText;
			}else{
				document.getElementById(CartParcelamento).innerHTML = "Aguarde, recalculando!";
			}
		}
		oHTTPRequest4.send(url+"&frmAcao=SPSJ");


		
	} catch(e) { alert(e); }
	
	
	
}


/*
Nome da Função: LoadHeader(div)
	Parametro div: div que irá receber o conteudo
Descrição da Função: carrega o header independente do sistema de cache
Desenvolvido por: Joao Paulo Wodiani
Data: 04/05/2009
*/
function LoadHeader(div, url)
{
	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", url + '/LoadHeader.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 = '<img src="http://www.ecompleto.com.br/i_padrao/loading.gif">';
			}
		}
		oHTTPRequest.send("id=1");
	} catch(e) { alert(e); }
}


/*
Nome da Função: LoadHistoricoVisitas(div)
	Parametro div: div que irá receber o conteudo
Descrição da Função: carrega o historico de visitas independentemente do cache
Desenvolvido por: Joao Paulo Wodiani
Data: 04/05/2009
*/
function LoadHistoricoVisitas(div, url)
{
	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", url + '/LoadHistoricoVisitas.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 = '<img src="http://www.ecompleto.com.br/i_padrao/loading.gif">';
			}
		}
		oHTTPRequest.send("id=1");
	} catch(e) { alert(e); }
}


function GetContent(url,id) {
var httpRequest;
if (window.XMLHttpRequest) {
   try { httpRequest = new XMLHttpRequest(); }
   catch(e) {}
   } 
else if (window.ActiveXObject) {
   try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 
      catch(e) {}
      }
   }
if(! httpRequest) {
   alert('\n\nSorry, unable to open a connection to the server.');
   return false;
   }
httpRequest.onreadystatechange = function() { PublishContent(httpRequest,id); };
httpRequest.open('GET',url,true);
httpRequest.send('');
}

function PublishContent(content,id) {
try {
   if (content.readyState == 4) {
      if(content.status == 200) { document.getElementById(id).innerHTML=content.responseText; }
      else { alert('\n\nContent request error, status code:\n'+content.status+' '+content.statusText); }
      }
   }
catch(error) { alert('Error: '+error.name+' -- '+error.message); }
}


/*
Nome da Função: LoadHeader_Produto(div)
	Parametro div: div que irá receber o conteudo
Descrição da Função: carrega o header independente do sistema de cache
Desenvolvido por: Joao Paulo Wodiani
Data: 15/06/2009
*/
function LoadHeader_Produto(div, url)
{
	try {
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", url + '/LoadHeader_Produto.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 = '<img src="http://www.ecompleto.com.br/i_padrao/loading.gif">';
			}
		}
		oHTTPRequest.send("id=1");
	} catch(e) { alert(e); }
}


/*
	@Função: Ajax_ProcessaCupom() -- Processa Cupom Desconto
	@params:
		frm = formulario contendo as informações para calculo
	Criado por: Joao Paulo W Siqueira <joaopaulo@ecompleto.com.br>
	Data: 31/08/2009
*/
function Ajax_ProcessaCupom(frm){
	
	try {
		
		erro = 0;
		if(frm.cupom1.value.length != 4){
			alert("Por favor, preencha o Cupom Corretamente!");
			frm.cupom1.focus();
			erro = 1;
		}

		if(frm.cupom2.value.length != 4 && erro!=1){
			alert("Por favor, preencha o Cupom Corretamente!");
			frm.cupom2.focus();
			erro = 1;
		}

		if(frm.cupom3.value.length != 4 && erro!=1){
			alert("Por favor, preencha o Cupom Corretamente!");
			frm.cupom3.focus();
			erro = 1;
		}

		if(frm.cupom4.value.length != 4 && erro!=1){
			alert("Por favor, preencha o Cupom Corretamente!");
			frm.cupom4.focus();
			erro = 1;
		}
		
		if(erro!=1){
			url = "processa_cupom.php?couponcode="+ frm.cupom1.value +"-"+ frm.cupom2.value +"-"+ frm.cupom3.value +"-"+ frm.cupom4.value;
			window.location.href=url;
		}

		
	} catch(e) { alert(e); }
	
}


/*
Nome da Função: CalcularFreteProduto(idp, idl, qtde, cep1, cep2)
	Parametro idp: id_produto
	Parametro idl: id_loja
	Parametro qtde: quantidade
	Parametro cep1: cep-principal (5)
	Parametro cep2: cep-sufixo (3)
Descrição da Função: Carregar as cidades filtradas pelo estado
Desenvolvido por: Joao Paulo Wodiani
Data: 16/01/2010
*/
function CalcularFreteProduto(idp, idl, qtde, cep1, cep2, url)
{
	try {
		
		if(qtde==""){
			alert("Preencha a Quantidade!");
			document.getElementById('quantidade').focus();
			return false;
		}

		if(cep1.length<5){
			alert("CEP Incorreto, são necessários 5 caracteres!");
			document.getElementById('cep1').focus();
			return false;
		}

		if(cep2.length<3){
			alert("CEP Incorreto, são necessários 3 caracteres!");
			document.getElementById('cep2').focus();
			return false;
		}

		document.getElementById("frete_calculado").style.display = 'block';
		var oHTTPRequest = new createXMLHTTP(); 
		oHTTPRequest.open("post", url+'/carregacalcularfrete.php', true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function(){
			if (oHTTPRequest.readyState==4){
				document.getElementById("frete_calculado").innerHTML = URLDecode(oHTTPRequest.responseText);
			} else {
				document.getElementById("frete_calculado").innerHTML = "<img src='http://www.ecompleto.com.br/i_padrao/loading.gif'>";
			}
		}
		oHTTPRequest.send("idproduto="+idp+"&idloja="+idl+"&quantidade="+qtde+"&cep1="+cep1+"&cep2="+cep2);
	} catch(e) { alert(e); }
}
