
function foco_cadastrado(num) {

     document.autent.acao[num].checked = true;
}

function metodo_login() {

   var i, sel, n;
     var Form = document.autent;
   	 var email = Form.e_mail.value; 
     var BadChars = "*|,\":<>[]{}`\'';()&$#% "; 
     var GoodChars = "@."; 
     var posarroba = email.indexOf ('@',0); 

   for (i=0; i<4; i++) {
         if (document.autent.acao[i].checked == true) {
               sel = i;
               break;
         }
   }
   if (document.autent.e_mail.value.length == 0) {
        document.getElementById('pop').style.display='block';
        document.autent.e_mail.focus();
        return false;
   }

if (email.length < 6) // o email é menor que 6 caracteres 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 
for (n = 0; n < email.length; n++) 
{ 
if (BadChars.indexOf(email.charAt(n)) != -1) // Contém caracteres inválidos, badchars 
{ 
document.getElementById('pop2').style.display='block';  
Form.e_mail.value = ''; 
Form.e_mail.focus(); 
return false; 
} 
} 
for (n=0; n < GoodChars.length; n++) 
{ 
if (email.indexOf(GoodChars.charAt(n)) == -1) // não tem goodchars 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 
if (email.indexOf(GoodChars.charAt(n),0) == 0) // começou com goodchars (. ou @) 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 
if (email.lastIndexOf(GoodChars.charAt(n)) > email.length-3) //existe menos de 2 caracteres depois do ultimo goodchar 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 
} 
if (email.lastIndexOf('@') > email.lastIndexOf('.')) //Não tem ponto depois do arroba 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 

if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1) // . e @ colados 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 
if (email.indexOf ('@',posarroba+1) != -1) // Contém mais de um " @ " 
{ 
document.getElementById('pop2').style.display='block'; 
Form.e_mail.focus(); 
return false; 
} 

   if (document.autent.acao[sel].value == "login_cadastro") {
     if (document.autent.senha.value.length == 0) {
		document.getElementById('pop1').style.display='block';
        document.autent.senha.focus();
        return false;
     }
   }
document.autent.submit;
}

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;
}

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.cep1.value.length != 0 || Form.cep2.value.length != 0) {
           resposta = valida_cep();
       }
       if (resposta == true)
       document.carrinho.submit ();
}

function atualizar_pagamento() {
       var resposta, Form;
       Form = document.pagamento;
		if (Form.taxa_envio.value == 0 && Form.peso.value != "0") {
		document.getElementById('pop1').style.display='block';
		return false;
		} else 
		if (Form.mostrar_aviso.value == "True" && Form.taxa_envio.value != 0) { 
		document.getElementById('pop3').style.display='block';
		return false;
		}
		else   
		if (Form.mostrar_aviso.value == "True") {
		document.getElementById('pop2').style.display='block';
		return false;
		}
}

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 fecha_janela(){
document.getElementById('pop2').style.display='none';
document.pagamento.submit ();
}
