//'-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
//' Loja Exemplo Locaweb 
//' Versão: 6.0
//' Data: 12/09/06
//' Arquivo: funcoes_js.js
//' Versão do arquivo: 0.0
//' Data da ultima atualização: 12/09/06
//'
//'-----------------------------------------------------------------------------
//' Licença Código Livre: http://comercio.locaweb.com.br/gpl/gpl.txt
//'-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

//# FUNCOES CEP

//###################################################################################
function disable_form() {
	document.frm.cep.disabled		= true;
	document.frm.cep.value			= '';

}
//###################################################################################
function mostraiframe(linha) {
var linha = document.getElementById(linha);
  if (linha.style.display=='none') {
   linha.style.display='';
  } else {
   linha.style.display='none';
  }
}
//###################################################################################
function alteraiframe(linha,acao) {
var linha = document.getElementById(linha);
  if (acao=='exibe') {
   linha.style.display='';
  } else {
   linha.style.display='none';
  }
}
//###################################################################################
function enable_form() {
	document.frm.cep.disabled		= false;
}


//###################################################################################
function pesquisar_cep(pais,cep,pesofrete) {

    var tempIFrame=document.createElement('iframe');
	tempIFrame.setAttribute('id','iframe_cep');
	tempIFrame.setAttribute('name','iframe_cep');

	tempIFrame.style.border			= '0px';
	tempIFrame.style.width			= '0px';
	tempIFrame.style.height			= '0px';

	tempIFrame.setAttribute('src','cep_frete.asp?pais='+pais+'&cep='+cep+'&pesofrete='+pesofrete);
	IFrameObj = document.body.appendChild(tempIFrame);
}

//###################################################################################
function valida_pesquisar_cep() {

    // pais
    var DROPpais = document.frm.paises;
    var pais = DROPpais.options[DROPpais.selectedIndex].value;

    // cep
    var format_cep = document.frm.cep.value.replace("-", "");
	
    if (pais == 'BR') {
        if (format_cep.length == 8){
            executar_pesquisar_cep();
        } else {
            alert('CEP inválido. Por favor verifique o mesmo');
            document.frm.cep.focus();
        }
    } else {
        executar_pesquisar_cep();
    }

}

//###################################################################################
function executar_pesquisar_cep() {
	// pais
    var DROPpais = document.frm.paises;
    var pais = DROPpais.options[DROPpais.selectedIndex].value;
    document.frmCarrinho.pais_frete.value = pais;

    // cep
    var cep = document.frm.cep.value.replace("-", "");

    //peso
    var peso = document.frm.pesofrete.value;
    
    pesquisar_cep(pais,cep,peso);
}

//###################################################################################
function send_frete(string) {

 var vfrete = string.split('#');
 
 var conf_frete = confirm("A opção de frete escolhida foi " + vfrete[0] + " no valor de " + vfrete[1] +"?")
 if (conf_frete==true) {
   document.frmCarrinho.opcao_frete.value = vfrete[0];
   document.frmCarrinho.frete.value = vfrete[2];
   document.frmCarrinho.cep_frete.value = vfrete[3];
   document.frmCarrinho.submit();
 }
}

//###################################################################################
//Antiga function handleResponse(informacoes, TxtRefCEP, status) {
function MontaOpcaoFrete(informacoes, TxtRefCEP, status) {

    var tbl = document.getElementById('freteTable'); 
    var lastRow = tbl.rows.length; 
    if (lastRow > 0) tbl.deleteRow(lastRow - 1);

    if (informacoes != 0) {
	
        var verify_informacoes = informacoes.indexOf("#");

        if (verify_informacoes>=0) {
		
            var CEP = document.frm.cep.value;
            var textoCEP = document.frm.textocep.value;
        
            var x=document.getElementById('freteTable').insertRow(0);
            var y=x.insertCell(0);
            y.innerHTML="<table id='"+ CEP +"' border='0' width='100%' cellpadding='2' cellspacing='2'></table>";

            /////////////////////

            var array_informacoes = informacoes.split("#");
            var x=document.getElementById(CEP).insertRow(0);
            var y=x.insertCell(0);		// Coluna "Prazo de entrega"
            x.height="25"
            x.bgColor="#FEE247"
	        y.width="120";
			//Wagner - 09/03/2007 - Se o CEP foi validado mostra os dados do endereco
			//caso contrario, a funcao PopUpCEP() faz consulta do CEP no site dos Correios.
			if (status=='VALIDO')
			{
		        var y=x.insertCell(0);	// Coluna "Valor"
				//y.align="left";
				//y.textAlign="justify"; não funciona nenhum align nem com tag FONT
	            y.width="70";
	            var y=x.insertCell(0);	// Coluna "Opções de frete"
	            y.width="360";
				y.innerHTML='<b>CEP ' + CEP + ' : &nbsp;' + TxtRefCEP + '</b>';
			}
			else
			{
				//Wagner - 21/03/2007 - Passado para tabela e acrescentado o prazo de entrega
				//y.innerHTML='<b>' + textoCEP + " " + CEP + ' : </b>' + TxtRefCEP + " " + '<br><A href="javascript:PopUpCEP();"><img align="right" src="config/imagens_conteudo/padrao/bt_calc_frete_endcep.gif" height="28" width="93" border="0"></A>';
	            var y=x.insertCell(0);
	            //y.width="100";
				//y.innerHTML='<A href="javascript:PopUpCEP();"><img align="center" src="config/imagens_conteudo/padrao/bt_calc_frete_endcep.gif" height="28" width="93" border="0"></A>';
				//y.align="left";
				//y.textAlign="justify"; não funciona nenhum align nem com tag FONT
	            y.width="70";
	            var y=x.insertCell(0);
	            y.width="360";
				y.innerHTML='<b>CEP ' + CEP + ' : </b>&nbsp;&nbsp;' + TxtRefCEP;
			}

            var part_num=0;
            var count = 0;
            var mod = 1;
            var color;

            while (part_num < array_informacoes.length) {
                
                if (mod==0) {
                    mod = 1;
                    color = '#FFFFFF';
                } else {
                    mod = 0;
                    color = '#F5F5F5';
                }
                
                var array_frete = array_informacoes[part_num].split(":");
				//Wagner - 01/08/2007 - Se não tem frete OK, não precisa mostrar a opção. Ex.: CEP 01000300 p/ 01000400. Sedex-10 não é aceito.                
                if (array_frete[2] != "ok") {
                    // // Insere o option na tabela
                    // var x=document.getElementById(CEP).insertRow(1)
                    // var y=x.insertCell(0)
                    // y.innerHTML= array_frete[0] + " : " + array_frete[2] 
                    // count+=1;
                } else {
                    
                    if (array_frete[1] != "vazio") {
                        //Trata o valor do frete conforme a moeda utilizada
                        var verify_vlrFRETE = array_frete[1].indexOf("|");
                        if (verify_vlrFRETE>=0) {
                            var vlrFRETE = array_frete[1].split("|");
                            var vlrFRETE_REAL = vlrFRETE[0];
                            var vlrFRETE_VIS = vlrFRETE[1];
                        } else {
                            var vlrFRETE_REAL = array_frete[1];
                            var vlrFRETE_VIS = array_frete[1];
                        }
                        // Insere o option na tabela
		                var x=document.getElementById(CEP).insertRow(1)
		                var y=x.insertCell(0)
                        x.height="10"
                        x.bgColor=color
						if (array_frete.length >= 4)	//Wagner 21/03/2007 - Mostra prazo de entrega divide em 3 colunas
						{
	                        //y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + " ( " + vlrFRETE_VIS + " ) Prazo : " + array_frete[3]
	                        y.innerHTML='&nbsp;&nbsp;&nbsp;' + array_frete[3];
			                var y=x.insertCell(0)
							y.align="right";
	                        y.innerHTML=vlrFRETE_VIS + '&nbsp;&nbsp;&nbsp;';
			                var y=x.insertCell(0)
	                        y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0];
	                    }
						else	//Caso de FEDEX e Retirar na loja
						{
	                        y.innerHTML="<input type='radio' name='opcao' value='"+ array_frete[0] + "#" + vlrFRETE_VIS + "#" + vlrFRETE_REAL + "#" + CEP + "' onclick='send_frete(this.value);'>" + array_frete[0] + " ( " + vlrFRETE_VIS + " )"
	                    }
   		                count+=1;
                    }
                
                }
                part_num+=1;
            }
            
            if (count == 0)
            {
                var x=document.getElementById('freteTable').insertRow(0)
                var y=x.insertCell(0)
                y.innerHTML="Não há um tipo de frete disponível para esse CEP."
            }
            else
            {
				//Wagner - 21/03/2007 - Insere cabecalho de tabela de frete
				var x=document.getElementById(CEP).insertRow(1);
				x.height="10";
				x.bgColor='#FFF7C4';
				var y=x.insertCell(0);
				y.innerHTML= '<b>&nbsp;&nbsp;&nbsp;Prazo de entrega</b>';
				var y=x.insertCell(0);
				y.align="right";
				y.innerHTML= '<b>Valor&nbsp;&nbsp;&nbsp;</b>'
				var y=x.insertCell(0);
				y.innerHTML= '<b>' + textoCEP + " " + CEP + ' : </b>';
            }
            
            enable_form();
        
        } else {
            
            var vfrete = informacoes.split(":");
            //Trata o valor do frete conforme a moeda utilizada
            var verify_vlrFRETE = vfrete[1].indexOf("|");
            
            if (verify_vlrFRETE>=0) {
			    var vlrFRETE = vfrete[1].split("|");
			    var vlrFRETE_REAL = vlrFRETE[0];
			    var vlrFRETE_VIS = vlrFRETE[1];
		    } else {
			    var vlrFRETE_REAL = vfrete[1];
			    var vlrFRETE_VIS = vfrete[1];
		    }
            
            document.frmCarrinho.opcao_frete.value = vfrete[0];
            document.frmCarrinho.frete.value = vlrFRETE_REAL;
            document.frmCarrinho.cep_frete.value = document.frm.cep.value;
            document.frmCarrinho.submit();
	    
        }
    
    } else {
        disable_form();
        document.frm.cep.disabled = false;
        var x=document.getElementById('freteTable').insertRow(0)
		var y=x.insertCell(0)
		y.innerHTML="Não há um tipo de frete disponível para esse CEP."
    }

	//Wagner - 20/11/2007 - Coloca foco na tabela FreteTable assim que mostra as opcoes de frete.
	document.getElementById('freteTable').focus();

}

//###################################################################################
function mostra_cep() {

  Form = document.carrinho;
  if ( (Form.cep1.value.length == 5) && (checatab) ) { 
   Form.cep2.focus();
   checatab=false;
  } 
} 

//###################################################################################
/*VERIFICA*/
function cadastro_cep_verificar(cep){
	if (!alterado_cep)	{
		alterado_cep = true;
		document.all.cep.focus();
		document.all.numero.value = '';
		document.all.complemento.value = '';
	}
}

//###################################################################################
function check_meiopag(opcaopag){
	var fr = document.OpcaoPag;
	//Wagner - 27/04/2008 - Pode ocorrer em caso de retorno para alterar pedido
	//que não mostre as opções de pagamento.
	if( fr != undefined )
	{
		for(a=0;a<fr.elements.length;a++)
		{
			if(fr.elements[a].value == opcaopag)
			{
				fr.elements[a].checked = true;
			}
		}
	}
}



//# FUNCOES LOJA

//###################################################################################
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
return true;
}

//###################################################################################
function remover_produto(nome) {
	eval("document.carrinho."+nome+".value = 0");  // estamos zerando o carrinho.
	document.carrinho.submit ();
}

//###################################################################################
function atualizar_carrinho() {
	var resposta, Form;
	Form = document.carrinho;
	resposta = true;
	if (Form.tipofrete.value == "SEDEX" && (Form.cep1.value.length != 0 || Form.cep2.value.length != 0)) {
		resposta = valida_cep();
	}
	if (resposta == true)
		document.carrinho.submit ();
}

//###################################################################################
function calcular_frete() {
	var resposta;
	resposta = valida_cep();
	if (resposta == true)
		document.carrinho.submit ();
}

//###################################################################################
function mostra_calculo_frete() {
	var Form;
	Form = document.pagamento;
	janela = window.open('calculo_frete.asp?valor=' + Form.subtotal.value + '&frete=' + Form.taxa_envio.value + '&cepdestino=' + Form.cep.value + '&peso=' + Form.peso.value + '&tipo_sedex=' + Form.tipo_sedex.value,'promocao','width=600,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes')
	if (janela != null) {
		janela.location.href ='calculo_frete.asp?valor=' + Form.subtotal.value + '&frete=' + Form.taxa_envio.value + '&cepdestino=' + Form.cep.value + '&peso=' + Form.peso.value + '&tipo_sedex=' + Form.tipo_sedex.value
	}
}

//###################################################################################
function metodo_pagamento(nome)
{ 
	var carteira, i, sel, num_pag, temp, metodo_pag, ssl, acao;
	var Form;
	Form = document.carrinho;
	num_pag = document.pagamento.num_pagamentos.value;
	
	if (document.pagamento.forma_pagamento.value == false) {
		alert("Selecione uma opção de pagamento");
		return false;
	} 

	if (document.pagamento.taxa_envio.value == 0 && !document.carrinho.frete_teste) {
		alert("Por favor, calcule a taxa de envio...");
		return false;
	} else { 
		if (num_pag == "1") {
			temp = document.pagamento.forma_pagamento.value;
			acao = document.pagamento.URL_Autentica.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
			eval("document.pagamento.action='" + acao + "'");
			document.pagamento.submit();
		} else {
			for (i=0; i<num_pag; i++) {
				if (document.pagamento.forma_pagamento.value == true) {
					sel = i;
				break;
				}
			}
			temp = document.pagamento.forma_pagamento.value;
		}
		// VISA1
		// VISA - VisaNet, 1 - com SSL

		// temp = document.pagamento.tipo[sel].value;
		metodo_pag = temp.substring(0,temp.length-1);

		if (metodo_pag == "AMEX" || metodo_pag == "AMEXPOS"|| metodo_pag == "REDECARD" || metodo_pag == "RCARDPOS"|| metodo_pag == "VISA" || metodo_pag == "VISAPOS") metodo_pag = "CARTAO"; 
			ssl = temp.substring(temp.length-1,temp.length);
	
		if (ssl == "0") {
			acao = document.pagamento.URL_Autentica.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
			//eval("document.pagamento.action='" + document.pagamento.URL_Autentica.value + "?acao=login" + "&forma_pagamento=" + metodo_pag + "'");
		} else {
			acao = document.pagamento.URL_Autentica_seguro.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
			//eval("document.pagamento.action='" + document.pagamento.URL_Autentica_seguro.value + "?acao=login" + "&forma_pagamento=CARTAO&cartao=" + document.pagamento.tipo[sel].value + "'");
		}

		if (metodo_pag == "CARTAO") {
			acao = acao + "&cartao=" + temp.substring(0,temp.length-1);
		}

		eval("document.pagamento.action='" + acao + "'");

		document.pagamento.submit();
	}
}

//###################################################################################
function valida_busca() {

	Form = document.busca;
	
    if (Form.produto.value.length == 0) {
		alert("Por favor preencha o campo de busca !");
		Form.produto.focus();
		return false;
	}

    if (Form.produto.value.length < 3) {
		alert("A palavra digitada deve conter mais de 3 caracteres !");
		Form.produto.focus();
		return false;
	}
	
    //if (Form.codigo_categoria.value == '') {
	//	alert("Por favor escolha uma categoria para a busca !");
	//	Form.codigo_categoria.focus();
	//	return false;
	//}
}


//###################################################################################
function valida_cep() {

	Form = document.carrinho;
	if (Form.cep1.value.length == 0) {
		alert("Por favor digite um CEP !");
		Form.cep1.focus();
		return false;
	}
	if (Form.cep2.value.length == 0) {
		alert("Por favor digite um CEP !");
		Form.cep2.focus();
		return false;
	}
	s = limpa_string(Form.cep1.value);
	if (s.length != 5) {
		alert("O CEP deve ter caracteres numericos !");
		Form.cep1.focus();
		return false;
	}
	s = limpa_string(Form.cep2.value);
	if (s.length != 3) {
		alert("O CEP deve ter caracteres numericos !");
		Form.cep2.focus();
		return false;
	}
	return true;
}

//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){temp=temp+digito}
	}
	return temp
}

//###################################################################################
function mostra_cep() {
	Form = document.carrinho;
	if ( (Form.cep1.value.length == 5) && (checatab) ) { 
		Form.cep2.focus();
		checatab=false;
	} 
}

//###################################################################################
function semtab() { checatab=false; }
function comtab() { checatab=true; } 
checatab=true;
        
//###################################################################################
function mostra_cep() {
	Form = document.carrinho;
	if ( (Form.cep1.value.length == 5) && (checatab) ) { 
		Form.cep2.focus();
		checatab=false;
	} 
} 

//###################################################################################
function menu_goto( menuform ) {
	selecteditem = menuform.local_frete_Exporta.selectedIndex ;
	local_frete_Exporta = menuform.local_frete_Exporta.options[ selecteditem ].value ;
	if (local_frete_Exporta.length != 0) {
		location.href = local_frete_Exporta ;
	}
}

//###################################################################################
function valida_trocapassword(Form) {

	if (Form.senha_atual.value.length == 0) {
		alert("A senha atual é obrigatória !");
		Form.senha_atual.focus();
		return false;
	}
	if (Form.nova_senha.value.length == 0 || Form.confirma_senha.value.length == 0) {
		alert("A senha é obrigatória !");
		Form.nova_senha.focus();
		return false;
	}
	if (Form.nova_senha.value != Form.confirma_senha.value) {
		alert("As senhas não são iguais (senha e confirmação) !");
		Form.nova_senha.focus();
		return false;
	}

}

//###################################################################################
function valida_faleconosco(Form) {

	if (Form.nome.value.length == 0) {
		alert("O nome é obrigatório !");
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert("O e-mail é um campo obrigatório !");
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert("O assunto é obrigatório !");
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert("O comentário é obrigatório !");
		Form.comentarios.focus();
		return false;
	}

    return true;

}

//###################################################################################
function valida_newsletter(Form) {

	if (Form.nome.value.length == 0) {
		alert("O nome é obrigatório !");
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert("O e-mail é um campo obrigatório !");
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.email.focus();
        return false;
    }

    return true;

}

//###################################################################################
function valida_cartao(Form) {

    var s;

    s = limpa_string(Form.ccn.value);
    if (s.length != 16) {
        alert("O campo cartão deve conter 16 caracteres numéricos !");
        Form.ccn.focus();
        return false;
    }
    
    if (Form.ccn.value.length == 0) {
        alert("O número do cartão é obrigatório !");
        Form.ccn.focus();
        return false;

    }

    if (Form.exp.value.length == 0) {
        alert("A data de validade do cartão é obrigatória !");
        Form.exp.focus();
        return false;

    }

    if (Form.cvv2.value.length == 0) {
        alert("O código de segurança do cartão é obrigatório !");
        Form.cvv2.focus();
        return false;

    }

    return true;

}

//###################################################################################
function valida_visa() {
	if (valida_endereco() == true) {
		document.Endereco.submit();
	}
	else return;
}

//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function limpa_string(S){
    // Deixa so' os digitos no numero
    var Digitos = "0123456789";
    var temp = "";
    var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}

//###################################################################################
function valida_CPF(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

//###################################################################################
function valida_CNPJ(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

//###################################################################################
function valida_numeros(s)
{
	var i; 
	var dif = 0;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!((c >= "0") && (c <= "9")))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		return false;
	}
	return true;
}

//###################################################################################
function copia_entrega(){
	var n='';
	var v='';
	var s='';
	var i=0;
	var form=document.Endereco;
	var x=form.length-1;
	if(form.cobranca_igual.checked){
		for(var y = 0; y <= x; y++){
			n=form.elements[y].name;			
			if(n.substring(0,2)=='b_'){
				s=n.substring(2,n.length);
				if(form.elements[s].type == "select-one"){					
					i=form.elements[s].selectedIndex;
					form.elements[n].selectedIndex=i;
				}
				else{
					
					v=form.elements[s].value;
					form.elements[n].value=v;
				}
			}
		}
	}
}

//###################################################################################
function mostradados(pri) {
  var element = document.getElementById(pri);

  if (element.style.display=='none') {
   element.style.display='';
  } else {
   element.style.display='none'
  }

}

//###################################################################################
function reenvio_pwd() {
   var fr = document.autent;

   if (fr.esquecisenha.checked == true) {
      fr.senha.disabled = true;
      fr.senha.value = '';
      fr.enviar.value = "Reenviar senha";
   } else {
      fr.senha.disabled = false;
      fr.enviar.value = "Autenticar usuário";
   }
}

//###################################################################################
function check_login()
{
	var fr = document.autent;

	if (fr.user_id.value.length == 0)
	{
		alert("Por favor, digite o seu e-mail.");
		fr.esquecisenha.value = "off"
		fr.user_id.focus();
		return false;
	}

	if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1)
	{
		alert("Por favor, preencha corretamente o campo e-mail."); 
		fr.esquecisenha.value = "off"
		fr.user_id.focus();
		return false;
	}

	//Wagner - 18/11/2007 - Botão esqueci senha ao invés de checkbox
	//if (fr.esquecisenha.checked == false)
	if (fr.senha.value.length == 0)
	{
		if (fr.esquecisenha.value != "on")
		{
			alert("Digite a senha. Se você não se lembra da senha, clique no botão [Esqueci minha senha] .");
			fr.esquecisenha.value = "off"
			fr.senha.focus();
			return false;
		}
	}
	return true;
}

//###################################################################################
function check_newlogin()
{
	var fr = document.new_user;

	if (fr.user_id.value.length == 0)
	{
		alert("Por favor, digite o seu e-mail.");
		fr.user_id.focus();
		return false;
	}

	if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1)
	{
		alert("Por favor, preencha corretamente o campo e-mail."); 
		fr.user_id.focus();
		return false;
	}

	if (fr.tipo_login.value == "user_new")
	{
		if (fr.cep_cobranca.value.length == 0)
		{
			alert("Por favor, digite o seu CEP.  O CEP de entrega é necessário se você é um usuário novo !");
			fr.cep_cobranca.focus();
			return false;
		}
	}
	return true;
}

//###################################################################################
function pagamento() {
	vpos=window.open('','vpos','toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=600,height=400');
	document.pagamento.submit();
}

//###################################################################################
function JanelaNova(URLBoleto) {
	window.open(URLBoleto,'NOME','width=680,height=400,menubar,scrollbars,resizable','NOME','width=600,height=400,menubar,scrollbars,resizable');
}

//###################################################################################
function brasil() {
	vpos=window.open('','vpos','toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');
	document.brasil.submit();
}

//###################################################################################
function itaushopline() {
	vpos=window.open('','vpos','toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');
	document.itaushopline.submit();
}

//###################################################################################
function boletogenerico()
{
	vpos=window.open('','vpos','toolbar=no,menubar=no,resizable=no,status=no,scrollbars=yes,width=685,height=500,top=20,left=60,directories=no,location=no');
	document.boletogenerico.submit();
}
//Se alterar aqui, copiar para ADM_funcoes_pedidos
function boletogenerico2(urlboleto)
{
	window.open(urlboleto,'_blank','toolbar=no,menubar=no,resizable=no,status=no,scrollbars=yes,width=685,height=500,top=20,left=60,directories=no,location=no');
}
function winhelp(url)
{
	help = window.open(url,'help','toolbar=no,menubar=no,resizable=no,status=no,scrollbars=yes,width=500,height=250,top=20,left=160,directories=no,location=no');
	help.focus();
}
//###################################################################################
function Start(VarForm,x,y) {
	vpos = window.open('','vpos','toolbar=no,menubar=no,resizable=yes,status=no,scrollbars=yes,width='+ x +',height='+ y +'');
	document.abnfinanc.submit();
}

//###################################################################################

function submit_bradesco(metodo_pag) {
	Form = document.Confirmacao;

	if (metodo_pag == "cc") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=CC'");
	} else if (metodo_pag == "transfer") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=TRANSFER'");                
	} else if (metodo_pag == "financiamento") {
		eval("Form.action='inicia_transacao.asp?metodo_pag=FINANCIAMENTO'");                
	}
	document.Confirmacao.submit();
}

//###################################################################################
// formata data
function formata_data(formato, keypress, objeto) {
    campo = eval (objeto);

    if (formato=='DATA'){ 
        separador = '/'; 
        conjunto1 = 2; 
        conjunto2 = 5;
    }

    if (campo.value.length == conjunto1){ 
        campo.value = campo.value + separador; 
    }

    if (campo.value.length == conjunto2){ 
        campo.value = campo.value + separador; 
    } 

}

//###################################################################################
function mostraCarrinho(pri) {
	var textview = document.getElementById(pri);
		if (textview.style.display=='none') {
			textview.style.display='';
			} else {
			textview.style.display='none';
	}
}

//###################################################################################
function PopUpCEP()							//Wagner - 09/03/2007 - Consulta CEP no site dos Correios
{
	PopUp('calcfreteenderecocep.htm','ConsultaCEP','width=412,height=400,left=100,top=100,scrollbars=no,resizable=no,toolbar=no');
}

//###################################################################################
function PopUp(theURL,winName,features)		//Wagner - 08/03/2007
{
	newWindow = window.open(theURL,winName,features); 
	newWindow.focus( );
}

//###################################################################################
function check_opcaopag() 
{
	var fr = document.OpcaoPag;
	var check = false;
	for(a=0;a<fr.elements.length;a++)
	{
		if(fr.elements[a].name == 'forma_pagamento')
		{
			if (fr.elements[a].checked == true)
			{
				check = true;
				break;
			}
		}
	}
	if (check == false)
	{
		alert("Selecione uma opção de pagamento");
	}
	else
	{
		atualiza_carrinho();	//Wagner - 29/11/2007 - Chama a função de recalcular (atualiza_carrinho) caso não tenha clicado no botão Recalcular.
		fr.submit();
	}
}

//###################################################################################
function valida_VisaMoset(Form) {

	if (Form.ccn.value.length == 0) {
		alert("O número do cartão é obrigatório !");
		Form.ccn.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert("O e-mail é um campo obrigatório !");
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert("O assunto é obrigatório !");
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert("O comentário é obrigatório !");
		Form.comentarios.focus();
		return false;
	}

    return true;

}

//###################################################################################
function fncLimpaValue(objTexto, sString)

	{

	if (sString == objTexto.value) {

		objTexto.value = '';
	}

}

//###################################################################################
function fncPreencheValue(objTexto, sString)

	{

	if (objTexto.value == '') {

		objTexto.value = sString;

	}

}
//###################################################################################
function atualiza_carrinho()
{
    var fr = document.frmCarrinho;
    var qte_elements = 0;
    var liberado = true;
    var qte_escolhida, qte_atual, qte_maxima;
    var qte_diferenca;

    for (a=0;a<fr.elements.length;a++)
    {
        if(fr.elements[a].name == 'quantidade_produto')
        {
            qte_elements = qte_elements + 1;
        }
    }

    qte_elements = (qte_elements - 1);

    if (qte_elements>=1)
    {
        for (i=0;i<=qte_elements;i++)
        {
            qte_escolhida = fr.quantidade_produto[i].value;
            qte_atual = fr.quantidade_atual[i].value;
            qte_maxima = fr.quantidade_maxima[i].value

            qte_diferenca = qte_escolhida - qte_atual;
            var qte_tratada = String(qte_diferenca);
            
            if (qte_tratada.indexOf('-') == -1)
            {
                qte_tratada = Number(qte_tratada);

                if ((qte_tratada > qte_maxima) && (qte_maxima != 0))
                {
                    alert('A quantidade escolhida para o produto é superior a disponível em nosso estoque.');
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

                if ((qte_escolhida > qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0))
                {
                    alert('A quantidade escolhida para o produto é superior a disponível em nosso estoque.');
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

            }

        }
    
    }
    else
    {
        qte_escolhida = fr.quantidade_produto.value;
        qte_atual = fr.quantidade_atual.value;
        qte_maxima = fr.quantidade_maxima.value

        qte_diferenca = qte_escolhida - qte_atual;
        var qte_tratada = String(qte_diferenca);
        
        if (qte_tratada.indexOf('-') == -1)
        {
            qte_tratada = Number(qte_tratada);

            if ((qte_tratada > qte_maxima) && (qte_maxima != 0))
            {
                alert('A quantidade escolhida para o produto é superior a disponível em nosso estoque.');
                fr.quantidade_produto.focus();
                liberado = false;
            }

            if ((qte_escolhida > qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0))
            {
                alert('A quantidade escolhida para o produto é superior a disponível em nosso estoque.');
                fr.quantidade_produto.focus();
                liberado = false;
            }

        }
    }

    if (liberado == true)
    {
        //document.forms(2).submit();
        document.forms("frmCarrinho").submit();
    }
}
//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function valida_cadastro(formname, cep_frete)
{
	var Form;
	Form = formname;
	if ((valida_endereco(Form) == false) || (valida_password(Form) == false) || (verifica_cep(cep_frete) == false))
	{
		return false;
	}
}
//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function valida_password(Form)
{
	if (Form.tipo_login.value == "user_new")
	{
		if (Form.senha1.value.length == 0 || Form.senha2.value.length == 0)
		{
			alert("A senha é obrigatória !");
			Form.senha1.focus();
			return false;
		}
		if (Form.senha1.value != Form.senha2.value)
		{
			alert("As senhas não são iguais (senha e confirmação) !");
			Form.senha1.focus();
			return false;
		}
	}
}
//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function valida_endereco(Form)
{
	var s;
	var pos;
	
	if ((Form.tipcliente[0].checked==false) && (Form.tipcliente[1].checked==false))
	{
		alert("Escolha a opção de cadastro entre Pessoa Física ou Pessoa Jurídica !");
		return false;
	}

    //Dados Cobrança
	if (Form.tipcliente[1].checked==true)
	{
		if (Form.razaosocial_cobranca.value.length == 0)
		{
			alert("A Razão Social é um campo obrigatório !");
			Form.razaosocial_cobranca.focus();
			return false;
		}

		if (Form.pais_cobranca.options[Form.pais_cobranca.selectedIndex].value == "BR")
		{
			var cnpj_cob = Form.cnpj_cobranca_b1.value + Form.cnpj_cobranca_b2.value + Form.cnpj_cobranca_b3.value + Form.cnpj_cobranca_b4.value + Form.cnpj_cobranca_b5.value;
			if (cnpj_cob.length == 0)
			{
				alert("O CNPJ é um campo obrigatório !");
				Form.cnpj_cobranca_b1.focus();
				return false;
			}

			s = limpa_string(cnpj_cob);

			if (s.length == 14)
			{
				if (valida_CNPJ(cnpj_cob) == false )
				{
					alert("O CNPJ não é válido !");
					Form.cnpj_cobranca_b1.focus();
					return false;
				}
			}
			else
			{
				alert("O CNPJ não é válido !");
				Form.cnpj_cobranca_b1.focus();
				return false;
			}

			Form.cnpj_cobranca.value = cnpj_cob;
		}
	}

	if (Form.nome_cobranca.value.length == 0)
	{
		alert("O nome é um campo obrigatório !");
		Form.nome_cobranca.focus();
		return false;
	}

	// Wagner - 22/03/2007 - Valida estado que pode ser deixado em branco
    if (Form.estado_cobranca.options[Form.estado_cobranca.selectedIndex].value == "")
	{
        alert("O ESTADO é um campo obrigatório !");
        Form.estado_cobranca.focus();
        return false;
	}

    if (Form.pais_cobranca.options[Form.pais_cobranca.selectedIndex].value == "BR")
    {
        var cpf_cob = Form.cpf_cobranca_b1.value + Form.cpf_cobranca_b2.value + Form.cpf_cobranca_b3.value + Form.cpf_cobranca_b4.value;
        
		if (cpf_cob.length == 0)
		{
			//Wagner - 03/08/2007 - Não é obrigatório CPF se vai usar pagamento por depósito ou boleto.
			//Wagner - 16/02/2008 - Deixado obrigatório para emissão de NF.
			if (Form.action == "confirmacao.asp")
			{
				var forma_pagamento = Form.document.getElementsByName('forma_pagamento')[0].value
				//Se não é cartão não precisa CPF //Wagner - 16/02/2008 - Deixado obrigatório para emissão de NF.
				//if (forma_pagamento != "Deposito" && forma_pagamento != "Boleto" && forma_pagamento != "Brasil" && forma_pagamento != "CobreBem")
				//{
					//alert("O CPF é um campo obrigatório para o caso de pagamento com cartões :\r\nVISA / Visa Electron / Itau RedeShop e outros !\r\n\r\nPor favor informe o seu CPF no campo acima.");
					alert("O CPF é um campo obrigatório para poder emitir sua Nota Fiscal de venda e no caso de pagamento com cartões :\r\nVISA / Visa Electron / Itau RedeShop e outros !\r\n\r\nPor favor informe o seu CPF no campo acima.");
					Form.cpf_cobranca_b1.focus();
					return false;
				//}
			}
			else
			{
				alert("Atenção : O CPF é campo obrigatório para poder emitir sua Nota Fiscal de venda e no caso de utilizar pagamento\r\natravés dos cartões : VISA / Visa Electron / Itau RedeShop e outros.");
				Form.cpf_cobranca_b1.focus();
				return false;
			}
		}
		else
		{
			s = limpa_string(cpf_cob);
			if (s.length == 11)
			{
				if (valida_CPF(cpf_cob) == false )
				{
					alert("O CPF não é válido !");
					Form.cpf_cobranca_b1.focus();
					return false;
				}
			}
			else
			{
				alert("O CPF não é válido !");
				Form.cpf_cobranca_b1.focus();
				return false;
			}
		}

		Form.cpf_cobranca.value = cpf_cob;

		var rg_cob = Form.rg_cobranca_b1.value + Form.rg_cobranca_b2.value + Form.rg_cobranca_b3.value + Form.rg_cobranca_b4.value;

		if (rg_cob.length == 0)
		{
			alert("O RG é um campo obrigatório !  O RG é necessário p/ fazer o registro do seu cadastro no nosso banco de dados.");
			Form.rg_cobranca_b1.focus();
			return false;
		}

		if (rg_cob.length == 9)
		{
			Form.rg_cobranca.value = '0' + rg_cob;
		}
		else
		{
			Form.rg_cobranca.value = rg_cob;
		}
	}

	if (Form.logradouro_cobranca.value.length == 0)
	{
		alert("O endereço é um campo obrigatório !");
		Form.logradouro_cobranca.focus();
		return false;
	}
	//Wagner - 29/05/2010 - Altera logradouro que usou ", " ou " - " que serão usados como separadores
	//de número e complemento de endereço para emissão de NFe. Mas sem mostrar erro na alteração para o
	//usuário comprador que está se cadastrando pela primeira vez ou alterando o seu cadastro.
	pos = Form.logradouro_cobranca.value.indexOf(', ')
	strLogradouro = Form.logradouro_cobranca.value
	tam = Form.logradouro_cobranca.value.length
	if ( pos > 0 )
	{
		Form.logradouro_cobranca.value = strLogradouro.substr(0,pos) + ' ' + strLogradouro.substr((pos + 1),tam);
	}
	pos = (Form.logradouro_cobranca.value.indexOf(' - ') + 1)
	strLogradouro = Form.logradouro_cobranca.value
	tam = Form.logradouro_cobranca.value.length
	if ( pos > 0 )
	{
		Form.logradouro_cobranca.value = strLogradouro.substr(0,pos) + ' ' + strLogradouro.substr((pos + 1),tam);
	}

	if (Form.numero_cobranca.value.length == 0)
	{
		alert("Digite o NÚMERO do endereço !");
		Form.numero_cobranca.focus();
		return false;
	}
     
	if (Form.pais_cobranca.options[Form.pais_cobranca.selectedIndex].value == "BR")
	{
		var cep_cob = Form.cep_cobranca_b1.value + Form.cep_cobranca_b2.value;
		if (cep_cob.length == 0)
		{
			alert("O CEP é um campo obrigatório !");
			Form.cep_cobranca_b1.focus();
			return false;
		}
		s = limpa_string(cep_cob);
		if (s.length != 8)
		{
			alert("O CEP deve ter 8 caracteres numericos !");
			Form.cep_cobranca_b1.focus();
			return false;
		}
		Form.cep_cobranca.value = cep_cob;
	}

	if (Form.cidade_cobranca.value.length == 0)
	{
		alert("A cidade é um campo obrigatório !");
		Form.cidade_cobranca.focus();
		return false;
	}

	if (Form.ddd_cobranca.value.length == 0)
	{
		alert("O DDD é um campo obrigatório !");
		Form.ddd_cobranca.focus();
		return false;
	}

	if (Form.telefone_cobranca.value.length == 0)
	{
		alert("O telefone é um campo obrigatório !");
		Form.telefone_cobranca.focus();
		return false;
	}

	Form.data_nascimento_cobranca.value = Form.data_nascimento_cobranca_b1.value + Form.data_nascimento_cobranca_b2.value + Form.data_nascimento_cobranca_b3.value;

	// Dados Entrega

	if (Form.cobranca_diferente.checked==true)
	{
		//Wagner - 14/01/2008 - Não testa mais o campo razaosocial_entrega somente pelo fato de tipcliente DE COBRANCA estar como pessoa jurídica. Além disso desde 15/09/2007 não recebe mais os campos de razao social de entrega e cnpj de entrega entre outros.
		//Todo o bloco de teste de razao social e CNPJ de entrega foram retirados.

		if (Form.nome_entrega.value.length == 0)
		{
			alert("O nome é um campo obrigatório !");
			Form.nome_entrega.focus();
			return false;
		}

		// Wagner - 22/03/2007 - Valida estado que pode ser deixado em branco
		if (Form.estado_entrega.options[Form.estado_entrega.selectedIndex].value == "")
		{
			alert("O ESTADO é um campo obrigatório !");
			Form.estado_entrega.focus();
			return false;
		}

		if (Form.pais_entrega.options[Form.pais_entrega.selectedIndex].value == "BR")
		{
			//Wagner - 15/09/2007 - Não recebe mais os campos de entrega : CPF, RG, data de nascimento, razão social, CNPJ, Telefone e e-mail. Esses campos ficam obrigatórios somente para dados de cobrança.
		    //var cpf_ent = Form.cpf_entrega_b1.value + Form.cpf_entrega_b2.value + Form.cpf_entrega_b3.value + Form.cpf_entrega_b4.value;

		    //if (cpf_ent.length == 0) {
		    //    alert("O CPF é um campo obrigatório !");
		    //    Form.cpf_entrega_b1.focus();
		    //    return false;
		    //}

		    //s = limpa_string(cpf_ent);
		    //if (s.length == 11) {
		    //    if (valida_CPF(cpf_ent) == false ) {
		    //        alert("O CPF não é válido !");
		    //        Form.cpf_entrega_b1.focus();
		    //        return false;
		    //    }
		    //}else{
		    //    alert("O CPF não é válido !");
		    //    Form.cpf_entrega_b1.focus();
		    //    return false;
		    //}

		    //Form.cpf_entrega.value = cpf_ent;

		    //var rg_ent = Form.rg_entrega_b1.value + Form.rg_entrega_b2.value + Form.rg_entrega_b3.value + Form.rg_entrega_b4.value;

		    //if (rg_ent.length == 0) {
		    //    alert("O RG é um campo obrigatório !");
		    //    Form.rg_entrega_b1.focus();
		    //    return false;
		    //}

		    //if (rg_ent.length == 9) {
		    //    Form.rg_entrega.value = '0' + rg_ent;
		    //} else {
		    //    Form.rg_entrega.value = rg_ent;
		    //}

		}

		if (Form.logradouro_entrega.value.length == 0)
		{
			alert("O endereço é um campo obrigatório !");
			Form.logradouro_entrega.focus();
			return false;
		}

		if (Form.numero_entrega.value.length == 0)
		{
			alert("Digite o NÚMERO do endereço de entrega e confira o NOME da pessoa que vai receber !");
			Form.numero_entrega.focus();
			return false;
		}

		if (Form.pais_entrega.options[Form.pais_entrega.selectedIndex].value == "BR")
		{
			var cep_ent = Form.cep_entrega_b1.value + Form.cep_entrega_b2.value;
			if (cep_ent.length == 0)
			{
				alert("O CEP é um campo obrigatório !");
				Form.cep_entrega_b1.focus();
				return false;
			}
			s = limpa_string(cep_ent);
			if (s.length != 8)
			{
				alert("O CEP deve ter 8 caracteres numericos !");
				Form.cep_entrega_b1.focus();
				return false;
			}
			Form.cep_entrega.value = cep_ent;
		}

		if (Form.cidade_entrega.value.length == 0)
		{
			alert("A cidade é um campo obrigatório !");
			Form.cidade_entrega.focus();
			return false;
		}

		//if (Form.telefone_entrega.value.length == 0) {
		//	alert("O telefone é um campo obrigatório !");
		//	Form.telefone_entrega.focus();
		//	return false;
		//}

		//if (Form.ddd_entrega.value.length == 0) {
		//	alert("O DDD é um campo obrigatório !");
		//	Form.ddd_entrega.focus();
		//	return false;
		//}

		//if (Form.email_entrega.value.length == 0) {
		//	alert("O e-mail é um campo obrigatório !");
		//	Form.email_entrega.focus();
		//	return false;
		//}

		//if (Form.email_entrega.value.indexOf('@', 0) == -1 || Form.email_entrega.value.indexOf('.', 0) == -1) {
		//    alert("Por favor, preencha corretamente o campo e-mail."); 
		//    Form.email_entrega.focus();
		//    return false;
		//}
	}
	//Form.data_nascimento_entrega.value = Form.data_nascimento_entrega_b1.value + Form.data_nascimento_entrega_b2.value + Form.data_nascimento_entrega_b3.value;
}
//###################################################################################
//Copiar para ADM_funcoes_pedidos.js se alt.
function verifica_cep(cep_frete)
{
	if (document.Endereco.tipo_acesso.value != "conta")
	{
		if (document.Endereco.cobranca_diferente.checked == true)
		{
			if (cep_frete != document.Endereco.cep_entrega.value)
			{
				resposta = confirm("O CEP informado para cálculo de frete na página do carrinho de compras  (" + cep_frete + ")  é diferente do CEP informado nesta página, no endereço de entrega  (" + document.Endereco.cep_entrega.value + ") .\r\nClicando OK , você retornará para a página do carrinho de compras e deverá clicar no botão  [Calcular_frete]  novamente. Deseja prosseguir?");
				if (resposta == false)
				{
					return false;
				}
				else
				{
					document.frmCarrinho.mode.value='changeItem';
					document.frmCarrinho.cep_frete.value=document.Endereco.cep_entrega.value;
					document.frmCarrinho.submit();
					return false;
				}
			}
		}
		else
		{
			if (cep_frete != document.Endereco.cep_cobranca.value)
			{
				resposta = confirm("O CEP informado para cálculo de frete na página do carrinho de compras  (" + cep_frete + ")  é diferente do CEP informado nesta página, no endereço de cobrança/entrega  (" + document.Endereco.cep_cobranca.value + ") .\r\nClicando OK , você retornará para a página do carrinho de compras e deverá clicar no botão  [Calcular_frete]  novamente. Deseja prosseguir?");
				if (resposta == false)
				{
					return false;
				}
				else
				{
					document.frmCarrinho.mode.value='changeItem';
					document.frmCarrinho.cep_frete.value=document.Endereco.cep_cobranca.value;
					document.frmCarrinho.submit();
					return false;
				}
			}
		}
	}
}
//###################################################################################
function checkTipCad(tipoEnd)
{
	var verificacao;

	if (document.getElementsByName('razaosocial_'+tipoEnd)[0].value != '')
	{
		verificacao = true;
	}
	else
	{
		verificacao = false;
	}

	var tipCadText = document.getElementById('tipCadTextJuridico_'+tipoEnd);
	var tipCadInput = document.getElementById('tipCadInputJuridico_'+tipoEnd);
	    
	if (verificacao == false)
	{
		tipCadText.style.display='none';
		tipCadInput.style.display='none';
		document.getElementsByName('razaosocial_'+tipoEnd)[0].value ='';
		document.getElementsByName('cnpj_'+tipoEnd+'_b1')[0].value ='';
		document.getElementsByName('cnpj_'+tipoEnd+'_b2')[0].value ='';
		document.getElementsByName('cnpj_'+tipoEnd+'_b3')[0].value ='';
		document.getElementsByName('cnpj_'+tipoEnd+'_b4')[0].value ='';
		document.getElementsByName('cnpj_'+tipoEnd+'_b5')[0].value ='';
	}
	else
	{
		tipCadText.style.display='';
		tipCadInput.style.display='';
	} 
}

//###################################################################################
function alteraTipCad()
{

	var tipCadTextCob = document.getElementById('tipCadTextJuridico_cobranca');
	var tipCadInputCob = document.getElementById('tipCadInputJuridico_cobranca');

	//Wagner - 15/09/2007 - Não recebe mais os campos de entrega : CPF, RG, data de nascimento, razão social, CNPJ, Telefone e e-mail. Esses campos ficam obrigatórios somente para dados de cobrança.
	//Tirado de dentro da funcao alteraTipCad (abaixo) as referências aos campos de entrega.
	//var tipCadTextEnt = document.getElementById('tipCadTextJuridico_entrega');
	//var tipCadInputEnt = document.getElementById('tipCadInputJuridico_entrega');

	if (document.Endereco.tipcliente[0].checked == true)
	{
		tipCadTextCob.style.display='none';
		tipCadInputCob.style.display='none';
		//tipCadTextEnt.style.display='none';
		//tipCadInputEnt.style.display='none';
		document.getElementsByName('razaosocial_cobranca')[0].value ='';
		document.getElementsByName('cnpj_cobranca_b1')[0].value ='';
		document.getElementsByName('cnpj_cobranca_b2')[0].value ='';
		document.getElementsByName('cnpj_cobranca_b3')[0].value ='';
		document.getElementsByName('cnpj_cobranca_b4')[0].value ='';
		document.getElementsByName('cnpj_cobranca_b5')[0].value ='';
		//document.getElementsByName('razaosocial_entrega')[0].value ='';
		//document.getElementsByName('cnpj_entrega_b1')[0].value ='';
		//document.getElementsByName('cnpj_entrega_b2')[0].value ='';
		//document.getElementsByName('cnpj_entrega_b3')[0].value ='';
		//document.getElementsByName('cnpj_entrega_b4')[0].value ='';
		//document.getElementsByName('cnpj_entrega_b5')[0].value ='';
	}
	else
	{
		tipCadTextCob.style.display='';
		tipCadInputCob.style.display='';
		//tipCadTextEnt.style.display='';
		//tipCadInputEnt.style.display='';
	} 
}
//###################################################################################
function valida_indique() {

    Form = document.indique;
	
    if (Form.Nome_AmigoIndicador.value.length == 0) {
        alert("O nome é um campo obrigatório !");
        Form.Nome_AmigoIndicador.focus();
        return false;
    }

	//Wagner - 13/07/2007 - Não obrigatório e-mail do indicador, mas se digitar, verifica se está correto.
    //if (Form.Email_AmigoIndicador.value.length > 0)
    //{
	//    if (Form.Email_AmigoIndicador.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicador.value.indexOf('.', 0) == -1)
	//    {
	//		alert("Por favor, preencha corretamente o campo e-mail."); 
	//		Form.Email_AmigoIndicador.focus();
	//		return false;
	//	}
    //}

    if (Form.Nome_AmigoIndicado.value.length == 0) {
        alert("O nome é um campo obrigatório !");
        Form.Nome_AmigoIndicado.focus();
        return false;
    }

    if (Form.Email_AmigoIndicado.value.length == 0) {
		alert("O e-mail é obrigatório !");
		Form.Email_AmigoIndicado.focus();
		return false;
	}
    
    if (Form.Email_AmigoIndicado.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicado.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.Email_AmigoIndicado.focus();
        return false;
    }

	//Wagner - 13/07/2007 - Não obrigatório comentário.
    //if (Form.comentario.value.length == 0) {
	//	alert("O comentário é obrigatório !");
	//	Form.comentario.focus();
	//	return false;
	//}

    return true;

}

//###################################################################################
//Wagner - 10/05/2007 - Função para mostrar o banner flash sem a mensagem "Clique aqui para ativar e usar este controle".
function ShowBanner(FileSWF,Width,Height,Link)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + Width + '" height="' + Height + '">');
	document.write('	<param name="movie" value="' + FileSWF + '?clickTAG=' + Link + '" />');
	document.write('	<param name="quality" value="high" />');
	document.write('	<param name="bgcolor" value="#99BB55" />');
	document.write('	<embed src="' + FileSWF + '" quality="high" width="' + Width + '" height="' + Height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />');
	document.write('</object>');
}
//###################################################################################
// Wagner - 23/06/2007 - Pré-load de imagens da página
function PreLoadImagesPage(page, lang_skin)
{
	path_padrao = "config/imagens_conteudo/padrao/";
	path_template = "config/templates/" + lang_skin + "/";

	//Sempre carrega botões básicos
	preloadImagesPg(path_template + 'menutop1_on.gif',path_template + 'menutop2_on.gif',path_template + 'menutop3_on.gif',path_template + 'menutop4_on.gif',path_template + 'menutop5_on.gif');
	preloadImagesPg(path_template + 'menutop1.gif',path_template + 'menutop2.gif',path_template + 'menutop3.gif',path_template + 'menutop4.gif',path_template + 'menutop5.gif');
	preloadImagesPg(path_padrao + 'botao_categoria.gif');
	preloadImagesPg(path_padrao + 'botao_categoria_hover.gif');
	preloadImagesPg(path_padrao + 'botao_24x22.gif');
	preloadImagesPg(path_padrao + 'botao_24x22_hover.gif');
	preloadImagesPg(path_padrao + 'botao_92x22.gif');
	preloadImagesPg(path_padrao + 'botao_92x22_hover.gif');
	preloadImagesPg(path_padrao + 'botao_120x22_retorna.gif');
	preloadImagesPg(path_padrao + 'botao_120x22_retorna_hover.gif');

	//if (page == 'default' || page == 'produtos')

	if (page == 'produtos_descricao')
	{
		preloadImagesPg(path_padrao + 'botao_120x32_comprar.gif');
		preloadImagesPg(path_padrao + 'botao_120x32_comprar_hover.gif');
		preloadImagesPg(path_padrao + 'botao_120x32_indique.gif');
		preloadImagesPg(path_padrao + 'botao_120x32_indique_hover.gif');
	}
	if (page == 'carrinho')
	{
		preloadImagesPg(path_padrao + 'botao_92x22_correios.gif');
		preloadImagesPg(path_template + 'botao_comprarmais.jpg');
		preloadImagesPg(path_template + 'botao_comprarmais_hover.jpg');
		preloadImagesPg(path_template + 'botao_fecharpedido.jpg');
		preloadImagesPg(path_template + 'botao_fecharpedido_hover.jpg');
		preloadImagesPg(path_template + 'botao_recalcular.jpg');
		preloadImagesPg(path_template + 'botao_recalcular_hover.jpg');
	}
	if (page == 'check_usuario')
	{
		preloadImagesPg(path_template + 'botao_alterarpedido.jpg');
		preloadImagesPg(path_template + 'botao_alterarpedido_hover.jpg');
		preloadImagesPg(path_template + 'botao_gravardados.jpg');
		preloadImagesPg(path_template + 'botao_gravardados_hover.jpg');
	}
	if (page == 'confirmacao')
	{
		preloadImagesPg(path_template + 'botao_alterardados.jpg');
		preloadImagesPg(path_template + 'botao_alterardados_hover.jpg');
		preloadImagesPg(path_template + 'botao_finalizarcompra.jpg');
		preloadImagesPg(path_template + 'botao_finalizarcompra_hover.jpg');
	}
	if (window.location.protocol == "https:")
	{
		preloadImagesPg('htt' + 'ps://support.com' + 'odo.com/uploaded/corn' + 'ertr' + 'ust.gif');
	}
}
function preloadImagesPg()
{ 
	var d=document;
	if(d.images)
	{
		if(!d.p) d.p=new Array();
		var i,j=d.p.length,a=preloadImagesPg.arguments;
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{
			d.p[j]=new Image;
			d.p[j++].src=a[i];
		}
	}
}
//###################################################################################
