//# 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 IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}
   
//###################################################################################
function pesquisar_cep(pais,cep, pesofrete) {
var auxservico
var fr = document.frm;
//document.getElementById("listafrete2").innerHTML = '';
proc_form('cep_frete.asp?pais='+pais+'&cep='+cep+'&pesofrete='+pesofrete, 'listafrete', 'frm');
proc_http('lista_meiospagamentos.asp?page=carrinho&valor_produto='+document.getElementById('subtotal_pedidos').innerHTML,'meiospagamentos');
document.getElementById('total_pedidos').innerHTML = document.getElementById('subtotal_pedidos').innerHTML;
document.getElementById('adicional_pedidos').innerHTML = '0,00';

for(a=0;a<fr.elements.length;a++){
	if(fr.elements[a].name == 'opcao'){
		auxservico = fr.elements[a].id;
		auxservico = auxservico.toLowerCase();
		if (auxservico.indexOf('.asp')>0) {
			proc_http('servicos/'+fr.elements[a].id,'valorfrete'+fr.elements[a].value);
		} else {	 
			 document.getElementById('valorfrete'+fr.elements[a].value).innerHTML = auxservico;	 
		}
	}
}

//    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 = 'BR' //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(ValPesqCepALERTcepinvalido);
            document.frm.cep.focus();
        }
    } else {
        executar_pesquisar_cep();
    }
}

//###################################################################################
function executar_pesquisar_cep() {
	// pais
    //var DROPpais = document.frm.paises;
    var pais = 'BR'; //DROPpais.options[DROPpais.selectedIndex].value;
    document.frmEditContact.pais_frete.value = pais;

    // cep
    var cep = document.frm.cep.value.replace("-", "");

    //peso
    var peso = document.frm.pesofrete.value;
    
    pesquisar_cep(pais,cep, peso);
}

//###################################################################################
/*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;
	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.tipo.value == false) {
		alert(MtdPagALERTselpag);
		return false;
	} 

	if (document.pagamento.taxa_envio.value == 0 && !document.carrinho.frete_teste) {
		alert(MtdPagALERTcalcfrete);
		return false;
	} else { 
		if (num_pag == "1") {
			temp = document.pagamento.tipo.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.tipo.value == true) {
					sel = i;
				break;
				}
			}
			temp = document.pagamento.tipo.value;
		}
		// VISA1
		// VISA - VisaNet, 1 - com SSL

		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;
		} else {
			acao = document.pagamento.URL_Autentica_seguro.value + "?acao=login" + "&forma_pagamento=" + metodo_pag;
		}

		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(VldBuscaALERTcampobusca);
		Form.produto.focus();
		return false;
	}

    if (Form.produto.value.length < 2) {
		alert(VldBuscaALERTminbusca);
		Form.produto.focus();
		return false;
	}

    if (!Form.codigo_categoria) {
        alert(VldBuscaALERTexistecatbusca);
        return false;
    }
	
    if (Form.codigo_categoria.value == '') {
		alert(VldBuscaALERTcatbusca);
		Form.codigo_categoria.focus();
		return false;
	}
}


//###################################################################################
function valida_cep() {

	Form = document.carrinho;
	if (Form.cep1.value.length == 0) {
		alert(VldCepALERTcampocep);
		Form.cep1.focus();
		return false;
	}
	if (Form.cep2.value.length == 0) {
		alert(VldCepALERTcampocep);
		Form.cep2.focus();
		return false;
	}
	s = limpa_string(Form.cep1.value);
	if (s.length != 5) {
		alert(VldCepALERTcaractcep);
		Form.cep1.focus();
		return false;
	}
	s = limpa_string(Form.cep2.value);
	if (s.length != 3) {
		alert(VldCepALERTcaractcep);
		Form.cep2.focus();
		return false;
	}
	return true;
}

//###################################################################################
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 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_cadastro(formname,tipoverif,cep_frete,cpfcnpj) {

	var Form;
	Form = formname;

	if (cep_frete == 'SEM FRETE') {
        if (tipoverif == 'CadPedido') {
            if ((valida_endereco(Form,'CadPedido', cpfcnpj) == false) || (valida_password(Form) == false)) {
                return false;
            } else {
				return true
			}
        } else if (tipoverif == 'CadUsuario') {
            if (valida_endereco(Form,'CadUsuario', cpfcnpj) == false) {
                return false;
            } else {
				return true
			}
        }
	} else {
        if ((valida_endereco(Form,'CadPedido', cpfcnpj) == false) || (valida_password(Form) == false)) {
            return false;
        } else {
				return true
		}
    }

}
//###################################################################################
function envia_endereco(cep, cpfcnpj){
	if (valida_cadastro(document.Endereco,'CadPedido',cep, cpfcnpj)==true){
		document.Endereco.submit();
	}	
}
//###################################################################################
function valida_password(Form) {

	if (Form.tipo_login.value == "user_new") {
		if (Form.senha1.value.length == 0 || Form.senha2.value.length == 0) {
			alert(VldPwdALERTcamposenha);
			Form.senha1.focus();
			return false;
		}
		if (Form.senha1.value != Form.senha2.value) {
			alert(VldPwdALERTsenhadif);
			Form.senha1.focus();
			return false;
		}
	}

}

//###################################################################################
function valida_trocapassword(Form) {

	if (Form.senha_atual.value.length == 0) {
		alert(VldTrocaPwdALERTcamposenhaatual);
		Form.senha_atual.focus();
		return false;
	}
	if (Form.nova_senha.value.length == 0 || Form.confirma_senha.value.length == 0) {
		alert(VldTrocaPwdALERTcamposenha);
		Form.nova_senha.focus();
		return false;
	}
	if (Form.nova_senha.value != Form.confirma_senha.value) {
		alert(VldTrocaPwdALERTsenhadif);
		Form.nova_senha.focus();
		return false;
	}

}

//###################################################################################
function valida_faleconosco(Form) {

	if (Form.nome.value.length == 0) {
		alert(VldFaleConALERTcmpnome);
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldFaleConALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldFaleConALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert(VldFaleConALERTcmpassunto);
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert(VldFaleConALERTcmpcomentario);
		Form.comentarios.focus();
		return false;
	}

    return true;

}

//###################################################################################
function valida_newsletter(Form) {

	if (Form.nome.value.length == 0) {
		alert(VldNewsALERTcmpnome);
		Form.nome.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldNewsALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldNewsALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

    return true;

}

//###################################################################################
function valida_endereco(Form,tipoverif,cpfcnpj) {

	var s;

    //Dados Cobrança
    if (valida_dadosCobranca(Form, cpfcnpj) == false) {
        return false;
    }

    //Confirma o tipo de verificação
	if (tipoverif == 'CadPedido') {
        // Dados Entrega
        if (Form.cobranca_diferente.checked==true) {
            if (valida_dadosEntrega(Form, cpfcnpj) == false) {
                return false;
            }
        }
    } else if (tipoverif == 'CadUsuario') {
        // Dados Entrega
        if (valida_dadosEntrega(Form, cpfcnpj) == false) {
            return false;
        }
    }
}

//###################################################################################
function valida_dadosCobranca(Form, cpfcnpj) {

    var s;

	if (Form.tipcliente[1].checked) {

		if (Form.razaosocial_cobranca.value.length == 0) {
			alert(VldEndALERTcmprazaosocial);
			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;

            s = limpa_string(cnpj_cob);
			
			if ((s.length <= 0)&&(cpfcnpj=="SIM")) {
                alert('CNPJ Inválido.');
                Form.cnpj_cobranca_b1.focus();
                return false;
			}
			
			if (s.length > 0) {
				if (s.length == 14) {
					if (valida_CNPJ(cnpj_cob) == false ) {
						alert(VldEndALERTcmpcnpjinc);
						Form.cnpj_cobranca_b1.focus();
						return false;
					}
				} else {
					alert(VldEndALERTcmpcnpjinc);
					Form.cnpj_cobranca_b1.focus();
					return false;
				}
			}

            Form.cnpj_cobranca.value = cnpj_cob;

        }

	} else {

		if (Form.nome_cobranca.value.length == 0) {
			alert(VldEndALERTcmpnome);
        	Form.nome_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;

			s = limpa_string(cpf_cob);
				
			if ((s.length <= 0)&&(cpfcnpj=="SIM")) {
                alert('CPF Inválido.');
                Form.cpf_cobranca_b1.focus();
                return false;
			}
			
				if (s.length > 0) {
					if (s.length == 11) {
						if (valida_CPF(cpf_cob) == false ) {
							alert(VldEndALERTcmpcpfinc);
							Form.cpf_cobranca_b1.focus();
							return false;
						}
					} else {
						alert(VldEndALERTcmpcpfinc);
						Form.cpf_cobranca_b1.focus();
						return false;
					}
				}
	
				Form.cpf_cobranca.value = cpf_cob;
		}
	}
    if (Form.logradouro_cobranca.value.length == 0) {
		alert(VldEndALERTcmpend);
		Form.logradouro_cobranca.focus();
		return false;
	}
     
	if (Form.numero_cobranca.value.length == 0) {
		alert(VldEndALERTcmpnum);
		Form.numero_cobranca.focus();
		return false;
	}
	
	if (Form.bairro_cobranca.value.length == 0) {
		alert('O Bairro é um campo obrigatório');
		Form.bairro_cobranca.focus();
		return false;
	}

     
    if (Form.pais_cobranca.options[Form.pais_cobranca.selectedIndex].value == "BR") {

        var cep_cob = Form.cep_cobranca_b1[0].value + Form.cep_cobranca_b2.value;

        if (cep_cob.length == 0) {
            alert(VldEndALERTcmpcep);
            Form.cep_cobranca_b1[0].focus();
            return false;
        }
         
        s = limpa_string(cep_cob);
        if (s.length != 8) {
            alert(VldEndALERTcmptamcep);
            Form.cep_cobranca_b1[0].focus();
            return false;
        }

        Form.cep_cobranca.value = cep_cob;
     
	} else {
        Form.cep_cobranca.value = Form.cep_cobranca_b1[1].value;
    }

    if (Form.cidade_cobranca.value.length == 0) {
		alert(VldEndALERTcmpcidade);
		Form.cidade_cobranca.focus();
		return false;
	}
	if (Form.estado_cobranca[0].value == '') {
		alert('O Estado é um campo obrigatório');
		Form.estado_cobranca[0].focus();
		return false;
	}

	if (Form.telefone_cobranca.value.length == 0) {
		alert(VldEndALERTcmptel);
		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;

}

//###################################################################################
function valida_dadosEntrega(Form, cpfcnpj) {
    
	var s;

    if (Form.tipcliente[1].checked) {

        if (Form.razaosocial_entrega.value.length == 0) {
            alert(VldEndALERTcmprazaosocial);
            Form.razaosocial_entrega.focus();
            return false;
        }

        if (Form.pais_entrega.options[Form.pais_entrega.selectedIndex].value == "BR") {
            
            var cnpj_ent = Form.cnpj_entrega_b1.value + Form.cnpj_entrega_b2.value + Form.cnpj_entrega_b3.value + Form.cnpj_entrega_b4.value + Form.cnpj_entrega_b5.value;

            s = limpa_string(cnpj_ent);
			
			if ((s.length <= 0)&&(cpfcnpj=="SIM")) {
                alert('CNPJ Inválido.');
                Form.cnpj_entrega_b1.focus();
                return false;
			}

			if (s.length > 0) {
            	if (s.length == 14) {
                	if (valida_CNPJ(cnpj_ent) == false ) {
                    	alert(VldEndALERTcmpcnpjinc);
	                    Form.cnpj_entrega_b1.focus();
    	                return false;
        	        }
            	} else {
					alert(VldEndALERTcmpcnpjinc);
	                Form.cnpj_entrega_b1.focus();
    	            return false;
				}
			}

            Form.cnpj_entrega.value = cnpj_ent;

        }

    } else {

	    if (Form.nome_entrega.value.length == 0) {
    	    alert(VldEndALERTcmpnome);
        	Form.nome_entrega.focus();
	        return false;
    	}

	    if (Form.pais_entrega.options[Form.pais_entrega.selectedIndex].value == "BR") {

    	    var cpf_ent = Form.cpf_entrega_b1.value + Form.cpf_entrega_b2.value + Form.cpf_entrega_b3.value + Form.cpf_entrega_b4.value;		
        		
			Form.cpf_entrega.value = cpf_ent;
				
			s = limpa_string(cpf_ent);
				
			if ((s.length <= 0)&&(cpfcnpj=="SIM")) {
				alert('CPF Inválido.');
				Form.cpf_entrega_b1.focus();
				return false;
			}
	
			if (s.length > 0) {
				if (s.length == 11) {
					if (valida_CPF(cpf_ent) == false ) {
						alert(VldEndALERTcmpcpfinc);
						Form.cpf_entrega_b1.focus();
						return false;
					}
				} else {
					alert(VldEndALERTcmpcpfinc);
					Form.cpf_entrega_b1.focus();
					return false;
				}
			}
	
			Form.cpf_entrega.value = cpf_ent;
		}
	}

    if (Form.logradouro_entrega.value.length == 0) {
        alert(VldEndALERTcmpend);
        Form.logradouro_entrega.focus();
        return false;
    }

    if (Form.numero_entrega.value.length == 0) {
        alert(VldEndALERTcmpnum);
        Form.numero_entrega.focus();
        return false;
    }

	if (Form.bairro_entrega.value.length == 0) {
		alert('O Bairro é um campo obrigatório');
		Form.bairro_entrega.focus();
		return false;
	}


    if (Form.pais_entrega.options[Form.pais_entrega.selectedIndex].value == "BR") {

        var cep_ent = Form.cep_entrega_b1[0].value + Form.cep_entrega_b2.value;

        if (cep_ent.length == 0) {
            alert(VldEndALERTcmpcep);
            Form.cep_entrega_b1[0].focus();
            return false;
        }

        s = limpa_string(cep_ent);
        if (s.length != 8) {
            alert(VldEndALERTcmptamcep);
            Form.cep_entrega_b1[0].focus();
            return false;
        }
        
        Form.cep_entrega.value = cep_ent;

    } else {
        Form.cep_entrega.value = Form.cep_entrega_b1[1].value;
    }

    if (Form.cidade_entrega.value.length == 0) {
        alert(VldEndALERTcmpcidade);
        Form.cidade_entrega.focus();
        return false;
    }
	
	if (Form.estado_entrega[0].value == "") {
        alert('O Estado é um campo obrigatório');
        Form.estado_entrega[0].focus();
        return false;
    }

    if (Form.telefone_entrega.value.length == 0) {
        alert(VldEndALERTcmptel);
        Form.telefone_entrega.focus();
        return false;
    }

//    if (Form.email_entrega.value.indexOf('@', 0) == -1 || Form.email_entrega.value.indexOf('.', 0) == -1) {
//        alert(VldEndALERTcmpemailinc); 
//        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;

}

//###################################################################################
function valida_cartao(Form) {

    var s;

    s = limpa_string(Form.ccn.value);
    if (s.length != 16) {
        alert(VldCartaoALERTcmptamnumcartao);
        Form.ccn.focus();
        return false;
    }
    
    if (Form.ccn.value.length == 0) {
        alert(VldCartaoALERTcmpnumcartao);
        Form.ccn.focus();
        return false;

    }

    if (Form.exp.value.length == 0) {
        alert(VldCartaoALERTcmpdataval);
        Form.exp.focus();
        return false;

    }

    if (Form.cvv2.value.length == 0) {
        alert(VldCartaoALERTcmpcodseg);
        Form.cvv2.focus();
        return false;

    }

    return true;

}

//###################################################################################
function valida_visa() {
	if (valida_endereco() == true) {
		document.Endereco.submit();
	}
	else return;
}

//###################################################################################
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 mostraDadosMenu(pri, lnk) {
  var element = document.getElementById(pri);

  if (element.style.display=='none') {
   element.style.display='';
   window.location = lnk;
  } else {
   element.style.display='none';   
  }

}

//###################################################################################
function mostraentrega() {
	if (document.getElementById("cobranca_diferente").checked == true) {
		document.getElementById("dados_entrega_top").style.display = '';
		document.getElementById("dados_entrega_body").style.display = '';
		document.getElementById("cep_cobranca_b1").disabled = false;
		document.getElementById("cep_cobranca_b2").disabled = false;
		document.getElementById("cep_cobranca_b1").value = document.getElementById("cep_cobranca_aux1").value;
		document.getElementById("cep_cobranca_b2").value = document.getElementById("cep_cobranca_aux2").value;
	
		if (document.getElementById("cep_entrega_b1")){
			document.getElementById("cep_entrega_b1").value = document.getElementById("cep_frete_b1").value;
			document.getElementById("cep_entrega_b2").value = document.getElementById("cep_frete_b2").value;
			document.getElementById("cep_entrega_b1").disabled = true;
			document.getElementById("cep_entrega_b2").disabled = true;
		}
	} else {
		document.getElementById("dados_entrega_body").style.display = 'none';
		document.getElementById("dados_entrega_top").style.display = 'none';
		document.getElementById("cep_cobranca_b1").disabled = true;
		document.getElementById("cep_cobranca_b2").disabled = true;
		document.getElementById("cep_cobranca_b1").value = document.getElementById("cep_frete_b1").value;
		document.getElementById("cep_cobranca_b2").value = document.getElementById("cep_frete_b2").value;
		if (document.getElementById("cep_entrega_b1")){
			document.getElementById("cep_entrega_b1").value = '';
			document.getElementById("cep_entrega_b2").value = '';
			document.getElementById("cep_entrega_b1").disabled = false;
			document.getElementById("cep_entrega_b2").disabled = false;
		}
	}
}

//###################################################################################
function mostraentrega_conta() {
	if (document.getElementById("cobranca_diferente").checked == true) {
		document.getElementById("dados_entrega_top").style.display = '';
		document.getElementById("dados_entrega_body").style.display = '';
	} else {
		document.getElementById("dados_entrega_body").style.display = 'none';
		document.getElementById("dados_entrega_top").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 = RnvPwdALERTreenvsenha;
   } else {
      fr.senha.disabled = false;
      fr.enviar.value = RnvPwdALERTautentusuario;
   }
}

//###################################################################################
function check_login() {
   var fr = document.autent;

   if (fr.user_id.value.length == 0) {
      alert(CkLoginALERTcmpemail);
      fr.user_id.focus();
      return false;
   }

   if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1) {
      alert(CkLoginALERTcmpemailinc); 
      fr.user_id.focus();
      return false;
   }

   if (fr.esquecisenha.checked == false) {
      if (fr.senha.value.length == 0) {
         alert(CkLoginALERTcmpsenha);
         fr.senha.focus();
         return false;
      }
   }
   return true;
}

//###################################################################################
function check_newlogin() {
   var fr = document.new_user;

   if (fr.user_id.value.length == 0) {
      alert(CkNwLoginALERTcmpemail);
      fr.user_id.focus();
      return false;
   }

   if (fr.user_id.value.indexOf('@', 0) == -1 || fr.user_id.value.indexOf('.', 0) == -1) {
      alert(CkNwLoginALERTcmpemailinc); 
      fr.user_id.focus();
      return false;
   }
   return true;
}

//###################################################################################
function alteraTipCad(valor) {
    
    var tipCadTextCob = document.getElementById('tipCadTextJuridico_cobranca');
    var tipCadInputCob = document.getElementById('tipCadInputJuridico_cobranca');
    var tipCadTextEnt = document.getElementById('tipCadTextJuridico_entrega');
    var tipCadInputEnt = document.getElementById('tipCadInputJuridico_entrega');
    var tipCadTextCob2 = document.getElementById('tipCadTextJuridico2_cobranca');
    var tipCadInputCob2 = document.getElementById('tipCadInputJuridico2_cobranca');
    var tipCadTextEnt2 = document.getElementById('tipCadTextJuridico2_entrega');
    var tipCadInputEnt2 = document.getElementById('tipCadInputJuridico2_entrega');
    
	if (valor == 'fisica') {
        tipCadTextCob.style.display='none';
        tipCadInputCob.style.display='none';
        tipCadTextEnt.style.display='none';
		tipCadInputEnt.style.display='none';
        tipCadTextCob2.style.display='none';
        tipCadInputCob2.style.display='none';
        tipCadTextEnt2.style.display='none';
        tipCadInputEnt2.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('inscricaoestadual_cobranca')[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 ='';
//        document.getElementsByName('inscricaoestadual_entrega')[0].value ='';

		document.getElementsByName('nome_cobranca')[0].style.display ='';
        document.getElementsByName('cpf_cobranca_b1')[0].style.display ='';
        document.getElementsByName('cpf_cobranca_b2')[0].style.display ='';
        document.getElementsByName('cpf_cobranca_b3')[0].style.display ='';
        document.getElementsByName('cpf_cobranca_b4')[0].style.display ='';
        document.getElementsByName('rg_cobranca')[0].style.display ='';
        document.getElementsByName('data_nascimento_cobranca_b1')[0].style.display ='';
        document.getElementsByName('data_nascimento_cobranca_b2')[0].style.display ='';
        document.getElementsByName('data_nascimento_cobranca_b3')[0].style.display ='';
        document.getElementById('tipCadTextNome_cobranca').style.display ='';
        document.getElementById('tipCadTextRg_cobranca').style.display ='';
		document.getElementById('tipCadTextDataNasc_cobranca').style.display ='';
		document.getElementById('tipCadTextCpf_cobranca').style.display ='';

// 	    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 ='';
//        document.getElementsByName('inscricaoestadual_entrega')[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 ='';
//        document.getElementsByName('inscricaoestadual_entrega')[0].value ='';

		document.getElementsByName('nome_entrega')[0].style.display ='';
        document.getElementsByName('cpf_entrega_b1')[0].style.display ='';
        document.getElementsByName('cpf_entrega_b2')[0].style.display ='';
        document.getElementsByName('cpf_entrega_b3')[0].style.display ='';
        document.getElementsByName('cpf_entrega_b4')[0].style.display ='';
        document.getElementsByName('rg_entrega')[0].style.display ='';
//        document.getElementsByName('data_nascimento_entrega_b1')[0].style.display ='';
//        document.getElementsByName('data_nascimento_entrega_b2')[0].style.display ='';
//        document.getElementsByName('data_nascimento_entrega_b3')[0].style.display ='';
        document.getElementById('tipCadTextNome_entrega').style.display ='';
        document.getElementById('tipCadTextRg_entrega').style.display ='';
		document.getElementById('tipCadTextDataNasc_entrega').style.display ='';
		document.getElementById('tipCadTextCpf_entrega').style.display ='';
 	} else {
        tipCadTextCob.style.display='';
        tipCadInputCob.style.display='';
        tipCadTextEnt.style.display='';
        tipCadInputEnt.style.display='';
        tipCadTextCob2.style.display='';
        tipCadInputCob2.style.display='';
        tipCadTextEnt2.style.display='';
        tipCadInputEnt2.style.display='';
		
		document.getElementsByName('nome_cobranca')[0].style.display ='none';
        document.getElementsByName('cpf_cobranca_b1')[0].style.display ='none';
        document.getElementsByName('cpf_cobranca_b2')[0].style.display ='none';
        document.getElementsByName('cpf_cobranca_b3')[0].style.display ='none';
        document.getElementsByName('cpf_cobranca_b4')[0].style.display ='none';
        document.getElementsByName('rg_cobranca')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b1')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b2')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b3')[0].style.display ='none';
        document.getElementById('tipCadTextNome_cobranca').style.display ='none';
        document.getElementById('tipCadTextRg_cobranca').style.display ='none';
		document.getElementById('tipCadTextDataNasc_cobranca').style.display ='none';
		document.getElementById('tipCadTextCpf_cobranca').style.display ='none';
		
//		document.getElementsByName('nome_cobranca')[0].value ='';
        document.getElementsByName('cpf_cobranca_b1')[0].value ='';
        document.getElementsByName('cpf_cobranca_b2')[0].value ='';
        document.getElementsByName('cpf_cobranca_b3')[0].value ='';
        document.getElementsByName('cpf_cobranca_b4')[0].value ='';
//        document.getElementsByName('rg_cobranca')[0].value ='';

//		document.getElementsByName('nome_entrega')[0].style.display ='none';
        document.getElementsByName('cpf_entrega_b1')[0].style.display ='none';
        document.getElementsByName('cpf_entrega_b2')[0].style.display ='none';
        document.getElementsByName('cpf_entrega_b3')[0].style.display ='none';
        document.getElementsByName('cpf_entrega_b4')[0].style.display ='none';
//        document.getElementsByName('rg_entrega')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_entrega_b1')[0].style.display ='';
//        document.getElementsByName('data_nascimento_entrega_b2')[0].style.display ='';
//        document.getElementsByName('data_nascimento_entrega_b3')[0].style.display ='';
        document.getElementById('tipCadTextNome_entrega').style.display ='none';
        document.getElementById('tipCadTextRg_entrega').style.display ='none';
		document.getElementById('tipCadTextDataNasc_entrega').style.display ='none';
		document.getElementById('tipCadTextCpf_entrega').style.display ='none';
		
//		document.getElementsByName('nome_entrega')[0].value ='';
        document.getElementsByName('cpf_entrega_b1')[0].value ='';
        document.getElementsByName('cpf_entrega_b2')[0].value ='';
        document.getElementsByName('cpf_entrega_b3')[0].value ='';
        document.getElementsByName('cpf_entrega_b4')[0].value ='';
//        document.getElementsByName('rg_entrega')[0].value ='';
	} 

}

//###################################################################################
function checkTipCad(tipoEnd) {
    
    var verificacao;
	
    if (document.getElementsByName('tipcliente')[1].checked) {
        verificacao = true;
    } else {
        verificacao = false;
    }
	
    var tipCadText = document.getElementById('tipCadTextJuridico_'+tipoEnd);
    var tipCadInput = document.getElementById('tipCadInputJuridico_'+tipoEnd);
    var tipCadText2 = document.getElementById('tipCadTextJuridico2_'+tipoEnd);
    var tipCadInput2 = document.getElementById('tipCadInputJuridico2_'+tipoEnd);
    
    if (verificacao == false) {
        tipCadText.style.display='none';
        tipCadInput.style.display='none';
        tipCadText2.style.display='none';
        tipCadInput2.style.display='none';

		document.getElementsByName('nome_'+tipoEnd)[0].style.display ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b1')[0].style.display ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b2')[0].style.display ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b3')[0].style.display ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b4')[0].style.display ='';
        document.getElementsByName('rg_'+tipoEnd)[0].style.display ='';
       // document.getElementsByName('data_nascimento_'+tipoEnd+'_b1')[0].style.display ='';
        //document.getElementsByName('data_nascimento_'+tipoEnd+'_b2')[0].style.display ='';
        //document.getElementsByName('data_nascimento_'+tipoEnd+'_b3')[0].style.display ='';
        document.getElementById('tipCadTextNome_'+tipoEnd).style.display ='';
        document.getElementById('tipCadTextRg_'+tipoEnd).style.display ='';
		document.getElementById('tipCadTextDataNasc_'+tipoEnd).style.display ='';
		document.getElementById('tipCadTextCpf_'+tipoEnd).style.display ='';

//		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 ='';
//        document.getElementsByName('inscricaoestadual_'+tipoEnd)[0].value ='';
    } else {
        tipCadText.style.display='';
        tipCadInput.style.display='';
        tipCadText2.style.display='';
        tipCadInput2.style.display='';
		
		document.getElementsByName('nome_'+tipoEnd)[0].style.display ='none';
        document.getElementsByName('cpf_'+tipoEnd+'_b1')[0].style.display ='none';
        document.getElementsByName('cpf_'+tipoEnd+'_b2')[0].style.display ='none';
        document.getElementsByName('cpf_'+tipoEnd+'_b3')[0].style.display ='none';
        document.getElementsByName('cpf_'+tipoEnd+'_b4')[0].style.display ='none';
        document.getElementsByName('rg_'+tipoEnd)[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b1')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b2')[0].style.display ='none';
//        document.getElementsByName('data_nascimento_cobranca_b3')[0].style.display ='none';
        document.getElementById('tipCadTextNome_'+tipoEnd).style.display ='none';
        document.getElementById('tipCadTextRg_'+tipoEnd).style.display ='none';
		document.getElementById('tipCadTextDataNasc_'+tipoEnd).style.display ='none';
		document.getElementById('tipCadTextCpf_'+tipoEnd).style.display ='none';
		
        document.getElementsByName('cpf_'+tipoEnd+'_b1')[0].value ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b2')[0].value ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b3')[0].value ='';
        document.getElementsByName('cpf_'+tipoEnd+'_b4')[0].value ='';

    }
}

//###################################################################################
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(VrfCepALERTcepentdif);
                if (resposta == false) {
                    return false;
                } else {
                    document.Endereco.mode.value='changeItem';
                    document.Endereco.cep_frete.value=document.Endereco.cep_entrega.value;
                    document.Endereco.submit();
                    return false;
                }
            }
        } else {
            if (cep_frete != document.Endereco.cep_cobranca.value) {
                alert(cep_frete + '###' + document.Endereco.cep_cobranca.value);
                resposta = confirm(VrfCepALERTcepentcobdif);
                if (resposta == false) {
                    return false;
                } else {
                    document.Endereco.mode.value='changeItem';
                    document.Endereco.cep_frete.value=document.Endereco.cep_cobranca.value;
                    document.Endereco.submit();
                    return false;
                }
            }
        }
    }
}

//###################################################################################
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');
}

//###################################################################################
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 PopUp(theURL,winName,features) 
{
window.open(theURL,winName,features); 
}

//###################################################################################
function check_opcaopag() 
	{
	var fr = document.frm;
	var fr2 = document.OpcaoPag;
	var check = false;
	var check2 = false;
	
	for(a=0;a<fr.elements.length;a++){
		if(fr.elements[a].name == 'opcao'){
			if (fr.elements[a].checked == true) {
				check = true;
				break;
			}
		}
	}

for(a=0;a<fr2.elements.length;a++){
		if(fr2.elements[a].name == 'tipo'){
			if (fr2.elements[a].checked == true) {
				check2 = true;
				break;
			}
		}
	}
	
	if (check == false) {
		alert(CkOpFreteALERTselFrete);
	} else {
		if (check2 == false) {
			alert(CkOpPagALERTselpag);			
		} else {		
			fr2.submit();
		}
	}
}
//###################################################################################
function comprar_mais() 
{
	var fr = document.OpcaoPag;
	fr.action = "autentica.asp?op=comprarmais";
	fr.submit();
}

//###################################################################################
function valida_VisaMoset(Form) {

	if (Form.ccn.value.length == 0) {
		alert(VldMosetALERTcmpnumcartao);
		Form.ccn.focus();
		return false;
	}

    if (Form.email.value.length == 0) {
        alert(VldMosetALERTcmpemail);
        Form.email.focus();
        return false;
    }

    if (Form.email.value.indexOf('@', 0) == -1 || Form.email.value.indexOf('.', 0) == -1) {
        alert(VldMosetALERTcmpemailinc); 
        Form.email.focus();
        return false;
    }

    if (Form.assunto.value.length == 0) {
		alert(VldMosetALERTcmpassunto);
		Form.assunto.focus();
		return false;
	}

    if (Form.comentarios.value.length == 0) {
		alert(VldMosetALERTcmpcomentario);
		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(tip) {
    var fr = document.frmEditContact;
    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 = parseFloat(fr.quantidade_produto[i].value);
            qte_atual = parseFloat(fr.quantidade_atual[i].value);
            qte_maxima = parseFloat(fr.quantidade_maxima[i].value);

//			alert(qte_escolhida + '/' + qte_atual +'/' +qte_maxima );
//			qte_diferenca = qte_escolhida - qte_atual;
//            var qte_tratada; //= String(qte_diferenca);           
//            if (qte_tratada.indexOf('-') == -1) {

//                qte_tratada = qte_escolhida; //Number(qte_tratada);

                if ((qte_escolhida > qte_maxima) && (qte_maxima != 0)) {
                    alert('Não há estoque suficiente para esta quantidade');//AtzCarALERTqtdestoque
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

                if ((qte_escolhida > qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0)) {
                    alert('Não há estoque suficiente para esta quantidade');//AtzCarALERTqtdestoque
                    fr.quantidade_produto[i].focus();
                    liberado = false;
                    break;
                }

//            }

        }
    
    } else {

        qte_escolhida = parseFloat(fr.quantidade_produto.value);
        qte_atual = parseFloat(fr.quantidade_atual.value);
        qte_maxima = parseFloat(fr.quantidade_maxima.value);


//        qte_diferenca = qte_escolhida - qte_atual;
//      var qte_tratada = 0; //= String(qte_diferenca);
        
//        if (qte_tratada.indexOf('-') == -1) {

//            qte_tratada = qte_escolhida; //Number(qte_tratada);

//			alert(qte_escolhida + '/' + qte_atual +'/' +qte_maxima );

            if ((qte_escolhida>qte_maxima) && (qte_maxima != 0)) {
                alert('Não há estoque suficiente para esta quantidade');//AtzCarALERTqtdestoque
                fr.quantidade_produto.focus();
                liberado = false;
            }

            if ((qte_escolhida>qte_maxima) && (qte_maxima == 0) && (qte_tratada != 0)) {
                alert('Não há estoque suficiente para esta quantidaden');//AtzCarALERTqtdestoque
                fr.quantidade_produto.focus();
                liberado = false;
            }

//        }
    }

    if (liberado == true) {
        if (tip == 'frete') {
            valida_pesquisar_cep();
        } else {
            fr.submit();
        }
    }
}

//###################################################################################
function valida_indique() {

    Form = document.indique;
	
    if (Form.Nome_AmigoIndicador.value.length == 0) {
        alert(VldIndALERTcmpnome);
        Form.Nome_AmigoIndicador.focus();
        return false;
    }

    if (Form.Email_AmigoIndicador.value.length == 0) {
		alert(VldIndALERTcmpemail);
		Form.Email_AmigoIndicador.focus();
		return false;
	}

    if (Form.Email_AmigoIndicador.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicador.value.indexOf('.', 0) == -1) {
        alert(VldIndALERTcmpemailinc); 
        Form.Email_AmigoIndicador.focus();
        return false;
    }

    if (Form.Nome_AmigoIndicado.value.length == 0) {
        alert(VldIndALERTcmpnome);
        Form.Nome_AmigoIndicado.focus();
        return false;
    }

    if (Form.Email_AmigoIndicado.value.length == 0) {
		alert(VldIndALERTcmpemail);
		Form.Email_AmigoIndicado.focus();
		return false;
	}
    
    if (Form.Email_AmigoIndicado.value.indexOf('@', 0) == -1 || Form.Email_AmigoIndicado.value.indexOf('.', 0) == -1) {
        alert(VldIndALERTcmpemailinc); 
        Form.Email_AmigoIndicado.focus();
        return false;
    }

    if (Form.comentario.value.length == 0) {
		alert(VldIndALERTcmpcomentario);
		Form.comentario.focus();
		return false;
	}

    return true;

}

//###################################################################################
function travaCepFrete(paises,cep) {

    cep.value = '';
    if (paises == 'BR') {
        cep.maxLength = "8";
	} else {
        cep.maxLength = "100";
    }

}
//###################################################################################
function ajustaCepFrete(paises,cep) {

    if (paises == 'BR') {
        cep.value = cep.value.replace(/[^\d]*/gi,"");
    }

}
//###################################################################################
function ajustaEstadoCadastro(Form,tipo) {

    var pais = document.getElementsByName('pais'+tipo)[0].options[document.getElementsByName('pais'+tipo)[0].selectedIndex].value;

    if (pais == 'BR') {
        document.getElementsByName('display_estado'+tipo)[0].style.display = '';
        document.getElementsByName('estado'+tipo)[0].disabled = false;
        document.getElementsByName('display_estado'+tipo)[1].style.display = 'none';
        document.getElementsByName('estado'+tipo)[1].disabled = true;
    } else {
        document.getElementsByName('display_estado'+tipo)[0].style.display = 'none';
        document.getElementsByName('estado'+tipo)[0].disabled = true;
        document.getElementsByName('display_estado'+tipo)[1].style.display = '';
        document.getElementsByName('estado'+tipo)[1].disabled = false;
    }

}
//###################################################################################
function ajustaCepCadastro(Form,tipo) {

    var pais = document.getElementsByName('pais'+tipo)[0].options[document.getElementsByName('pais'+tipo)[0].selectedIndex].value;

    if (pais == 'BR') {
        document.getElementsByName('display_cep'+tipo)[0].style.display = '';
        document.getElementsByName('cep'+tipo+'_b1')[0].disabled = false;
        document.getElementsByName('cep'+tipo+'_b2')[0].disabled = false;
        
        document.getElementsByName('display_cep'+tipo)[1].style.display = 'none';
        document.getElementsByName('cep'+tipo+'_b1')[1].disabled = true;
    } else {
        document.getElementsByName('display_cep'+tipo)[0].style.display = 'none';
        document.getElementsByName('cep'+tipo+'_b1')[0].disabled = true;
        document.getElementsByName('cep'+tipo+'_b2')[0].disabled = true;
        
        document.getElementsByName('display_cep'+tipo)[1].style.display = '';
        document.getElementsByName('cep'+tipo+'_b1')[1].disabled = false;
    }

}
//###################################################################################