function envia_contato()
{

if (document.correio.nome.value == '')
{
alert('Por favor informe seu nome!');
document.correio.nome.focus()
return false;
}


if (document.correio.email.value == '')
{
alert('Por favor preencha o e-mail!');
document.correio.email.focus()
return false;
}

if (document.correio.email.value.indexOf('@', 0) == -1 || document.correio.email.value.indexOf('.', 0) == -1)
{
alert("Por Favor Digite um E-mail Válido!");
document.correio.email.focus();
return false;
}

if (document.correio.assunto.value == '')
{
alert('Por favor informe o assunto!');
document.correio.email.focus()
return false;
}

else
{document.correio.submit();}

}


function envia_form()
{

if (document.indique.nome_fwd.value == '')
{
alert('Por favor informe seu nome!');
document.indique.nome_fwd.focus()
return false;
}

if (document.indique.amigo_fwd.value == '')
{
alert('Por favor informe o nome do seu amigo!');
document.indique.amigo_fwd.focus()
return false;
}

if (document.indique.mail_fwd.value == '')
{
alert('Por favor informe o e-mail do seu amigo!');
document.indique.mail_fwd.focus()
return false;
}

if (document.indique.mail_fwd.value.indexOf('@', 0) == -1 || document.indique.mail_fwd.value.indexOf('.', 0) == -1)
{
alert("Por Favor Digite um E-mail Válido!");
document.indique.mail_fwd.focus();
return false;
}

else
{document.indique.submit();}

}




function envia(){
var usuario = document.restrito.login.value
var usuLength = document.restrito.login.value.length
var senha = document.restrito.senha.value
var senhaLength = document.restrito.senha.value.length
if(usuario==""){
alert("Campo 'LOGIN' deve ser preenchido");
document.restrito.login.focus()
return false
	}
if(senha==""){
alert("Campo 'SENHA' deve ser preechido");
document.restrito.senha.focus()
return false
	}
}



function validar_form()
{
    if (document.cliente.inp_nome.value == "")
    {alert('Campo NOME precisa ser preenchido!');
    document.cliente.inp_nome.focus();
    return false;}

    if (document.cliente.inp_cgcecpf.value == "")
    {alert('Campo CPF ou CGC precisa ser preenchido!');
    document.cliente.inp_cgcecpf.focus();
    return false;}

    if (document.cliente.inp_senha1.value == "")
    {alert('Campo SENHA precisa ser preenchido!');
    document.cliente.inp_senha1.focus();
    return false;}

    if (document.cliente.inp_senha2.value == "")
    {alert('Campo confirmação da SENHA precisa ser preenchido!');
    document.cliente.inp_senha2.focus();
    return false;}

    if (document.cliente.inp_senha1.value != document.cliente.inp_senha2.value)
    {alert('Campo SENHA não está igual a CONFIRMAÇÃO, por favor redigite!');
    document.cliente.inp_senha2.focus();
    return false;}

    if (document.cliente.inp_endereco.value == "")
    {alert('Campo ENDEREÇO precisa ser preenchido!');
    document.cliente.inp_endereco.focus();
    return false;}

    if (document.cliente.inp_numero.value == "")
    {alert('Campo NÚMERO precisa ser preenchido!');
    document.cliente.inp_numero.focus();
    return false;}

    if (document.cliente.inp_bairro.value == "")
    {alert('Campo BAIRRO precisa ser preenchido!');
    document.cliente.inp_bairro.focus();
    return false;}

    if (document.cliente.inp_cidade.value == "")
    {alert('Campo CIDADE precisa ser preenchido!');
    document.cliente.inp_cidade.focus();
    return false;}

    if (document.cliente.inp_cep.value == "")
    {alert('Campo CEP precisa ser preenchido!');
    document.cliente.inp_cep.focus();
    return false;}
   
    if (document.cliente.referencia.value == "")
    {alert('Campo BAIRRO DE REFERÊNCIA precisa ser preenchido!');
    document.cliente.inp_cep2.focus();
    return false;}

    
    if (document.cliente.inp_ddd_res.value == "")
    {alert('Campo DDD precisa ser preenchido!');
    document.cliente.inp_ddd_res.focus();
    return false;}

    if (document.cliente.inp_telefone.value == "")
    {alert('Campo TELEFONE precisa ser preenchido!');
    document.cliente.inp_telefone.focus();
    return false;}

    if (document.cliente.inp_email.value == "")
    {alert('Campo E-MAIL precisa ser preenchido!');
    document.cliente.inp_email.focus();
    return false;}


    if (document.cliente.inp_email.value.indexOf('@', 0) == -1 || document.cliente.inp_email.value.indexOf('.', 0) == -1)
    { alert("E-mail invalido!");
    document.cliente.inp_email.focus()
    }

    else
    {document.cliente.submit();}
}



function duplica()
{

if (document.cliente.chk_copia.checked)
{
//alert('1');
document.cliente.inp_endereco2.value = document.cliente.inp_endereco.value ;
document.cliente.inp_numero2.value = document.cliente.inp_numero.value;
document.cliente.inp_complemento2.value = document.cliente.inp_complemento.value ;
document.cliente.inp_bairro2.value = document.cliente.inp_bairro.value ;
document.cliente.inp_cidade2.value = document.cliente.inp_cidade.value ;
document.cliente.inp_estado2.value = document.cliente.inp_estado.value ;
document.cliente.inp_cep2.value = document.cliente.inp_cep.value ;
}
else
{
//alert('2');
document.cliente.inp_endereco2.value = ""; 
document.cliente.inp_numero2.value = ""; 
document.cliente.inp_complemento2.value = ""; 
document.cliente.inp_bairro2.value = ""; 
document.cliente.inp_cidade2.value = ""; 
document.cliente.inp_estado2.value = ""; 
document.cliente.inp_cep2.value = ""; 
}

}



//Inicia Formatação e Verificação de CGC e CPF


function limpa_cgc_formatado(informado)
{
  var aux = informado
  var val_informado = "" + aux;
  var tamanho = val_informado.length
  var contador = 0
  var montagem = ""
  var pedaco = ""

  while (contador <= tamanho)
    {

      pedaco = val_informado.substring(contador-1,contador)
      if (pedaco==".")  pedaco=""
      if (pedaco=="/")  pedaco=""
      if (pedaco=="-")  pedaco=""
      if (pedaco==" ")  pedaco=""

      montagem = montagem + pedaco
      contador = contador+1

    }

   return montagem
}

function formata_cgc(informado)
{
  var aux = informado
  var val_informado = "" + aux;
  var tamanho = val_informado.length
  var contador = 0
  var montagem = ""
  var pedaco = ""

//  alert(tamanho);

  if ((tamanho!=11) && (tamanho!=14))
    {
      alert("Tamanho do campo tem que ser 11 caracteres(CPF) ou 14 caracteres(CGC)!");
      montagem = "";
      return montagem
    }

  if (tamanho==11)
    {
    // monta mascara para CPF
    montagem = val_informado.substring(0,3)+"."+val_informado.substring(3,6)+"."+val_informado.substring(6,9)+"-"+val_informado.substring(9,11)
    }

  if (tamanho==14)
    {
    // monta mascara para CGC
    montagem = val_informado.substring(0,2)+"."+val_informado.substring(2,5)+"."+val_informado.substring(5,8)+"/"+val_informado.substring(8,12)+"-"+val_informado.substring(12,14)
    }

   return montagem
}

function Valida_Doc()
{
var valor = limpa_cgc_formatado(document.cliente.inp_cgcecpf.value);
  if (valor == "")
   {
     return false;
   }
  if ((valor.length != 14) && (valor.length != 11))
   {
        alert("Campo tem que possuir 11 digitos para CPF ou 14 para CGC");
        document.cliente.inp_cgcecpf.focus();
        document.cliente.inp_cgcecpf.select();
     return false;
   }
  //validacao de pessoa juridica
  if (valor.length == 14)
  {
    if (! ValidaCGC(valor))
       {
          alert("Digito de Controle do CGC Inválido");
          document.cliente.inp_cgcecpf.value = formata_cgc(valor);
          document.cliente.inp_cgcecpf.focus();
          document.cliente.inp_cgcecpf.select();
        };
    else
       {
          document.cliente.inp_cgcecpf.value = formata_cgc(valor);
        };
  }
  //validacao de pessoa fisica
  if (valor.length == 11)
  {
    if (! ValidaCPF(valor))
       {
          alert("Digito de Controle do CPF Inválido");
         document.cliente.inp_cgcecpf.value = formata_cgc(valor);
          document.cliente.inp_cgcecpf.focus();
          document.cliente.inp_cgcecpf.select();
        };
    else
       {
          document.cliente.inp_cgcecpf.value = formata_cgc(valor);
        };
  }
}


//Fim formatação e validação do CGC e CPF


function concordo()
{

if (document.FORMULARIO.agree[0].checked)
{
document.FORMULARIO.submit();
}
else
{
//location.href = 'mail_ok.asp?msg=NCAD2';
alert('Para poder se cadastrar, é necessário a\naceitação dos termos e condições de uso.');
}


}


function controle()
{
document.FORMULARIO.action="add_carrinho.asp?rec=2";
document.FORMULARIO.submit();
}


function copia()
{

if (document.FORMULARIO.chk_copia.checked)
{
//alert('1');
document.FORMULARIO.inp_endereco2.value = document.FORMULARIO.inp_endereco.value ;
document.FORMULARIO.inp_numero2.value = document.FORMULARIO.inp_numero.value;
document.FORMULARIO.inp_complemento2.value = document.FORMULARIO.inp_complemento.value ;
document.FORMULARIO.inp_bairro2.value = document.FORMULARIO.inp_bairro.value ;
document.FORMULARIO.inp_cidade2.value = document.FORMULARIO.inp_cidade.value ;
document.FORMULARIO.inp_estado2.value = document.FORMULARIO.inp_estado.value ;
document.FORMULARIO.inp_cep2.value = document.FORMULARIO.inp_cep.value ;
}
else
{
//alert('2');
document.FORMULARIO.inp_endereco2.value = ""; 
document.FORMULARIO.inp_numero2.value = ""; 
document.FORMULARIO.inp_complemento2.value = ""; 
document.FORMULARIO.inp_bairro2.value = ""; 
document.FORMULARIO.inp_cidade2.value = ""; 
document.FORMULARIO.inp_estado2.value = ""; 
document.FORMULARIO.inp_cep2.value = ""; 
}

}




function close_shop()
{
    if (verifica())
    {
    document.FORMULARIO.action = "confere_carrinho.asp";	
    document.FORMULARIO.submit();
    }
}

function card()
{
    document.FORMULARIO.credit.value = "1"; 
}


function verifica()
{
soma = 0;

if (document.FORMULARIO.linhas.value = 0)
{ alert('Não existem itens em seu carrinho!');
return false;	}
else
{ soma = soma + 1; }

if (document.FORMULARIO.frete.value = 0)
{ alert('Informe o BAIRRO DE REFERÊNCIA para entrega!');
document.FORMULARIO.referencia.focus();
return false;	}
else
{ soma = soma + 1; }

if ((document.FORMULARIO.pagamento[0].checked == false) && (document.FORMULARIO.pagamento[1].checked == false))
{ alert('Informe o campo FORMA DE PAGAMENTO!');
document.FORMULARIO.pagamento[0].focus();
return false;	}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_entrega.value == "")
{alert('Informe o campo NOME DE ENTREGA!');
document.FORMULARIO.inp_entrega.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.dt_entrega.value == "")
{alert('Informe o campo DATA DE ENTREGA!');
document.FORMULARIO.dt_entrega.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.periodo.value == "")
{alert('Informe o campo PERÍODO DE ENTREGA!');
document.FORMULARIO.inp_entrega.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_endereco2.value == "")
{alert('Informe o campo ENDEREÇO DE ENTREGA!');
document.FORMULARIO.inp_endereco2.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_numero2.value == "")
{alert('Informe o campo NÚMERO DE ENTREGA!');
document.FORMULARIO.inp_numero2.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_bairro2.value == "")
{alert('Informe o campo BAIRRO DE ENTREGA!');
document.FORMULARIO.inp_bairro2.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_cidade2.value == "")
{alert('Informe o campo CIDADE DE ENTREGA!');
document.FORMULARIO.inp_cidade2.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_estado2.value == "")
{alert('Informe o campo ESTADO DE ENTREGA!');
document.FORMULARIO.inp_estado2.focus();
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.inp_cep2.value == "")
{alert('Informe o campo CEP DE ENTREGA!');
document.FORMULARIO.inp_cep2.focus();
return false;}
else
{ soma = soma + 1; }

return true;

}


function finaliza()
{
    if (verifica2())
    {
    document.FORMULARIO.action = "fecha_carrinho.asp"; 
    document.FORMULARIO.submit();
    }
}


function verifica2()
{
soma = 0;

if (document.FORMULARIO.pagamento.value == "C" && document.FORMULARIO.credit.value == 0){

if (document.FORMULARIO.credit.value == 0)
{ alert('Selecione o Cartão para Pagamento!');
return false;}
else
{ soma = soma + 1; }

if (document.FORMULARIO.cd_credito.value == "")
{ alert('Informe o NÚMERO DO CARTÃO!');
document.FORMULARIO.cd_credito.focus();
return false;	}
{ soma = soma + 1; }

if (document.FORMULARIO.cd_segura.value == "")
{ alert('Informe o CÓDIGO DE SEGURANÇA DO CARTÃO!');
document.FORMULARIO.cd_segura.focus();
return false;	}
{ soma = soma + 1; }

if (document.FORMULARIO.no_pessoa.value == "")
{ alert('Informe o NOME IMPRESSO NO CARTÃO!');
document.FORMULARIO.no_pessoa.focus();
return false;	}
{ soma = soma + 1; }

if (document.FORMULARIO.nm_mesvalid.value == "")
{ alert('Informe o MÊS DE VENCIMENTO DO CARTÃO!');
document.FORMULARIO.nm_mesvalid.focus();
return false;	}
{ soma = soma + 1; }

if (document.FORMULARIO.nm_anovalid.value == "")
{ alert('Informe o ANO DE VENCIMENTO DO CARTÃO!');
document.FORMULARIO.nm_anovalid.focus();
return false;	}
{ soma = soma + 1; }

}

return true;
}



function altera()
{
history.back(-1);
}

function abre_cep1()
{
window.open('form_busca_cep1.asp','_janela','width=630; height=430; top=80; left=30; resizable=0; toolbar=0; location=0; scrollbars=1');
}

function abre_cep2()
{
window.open('form_busca_cep2.asp','_janela','width=630; height=430; top=80; left=30; resizable=0; toolbar=0; location=0; scrollbars=1');
}

function abre_cep3()
{
window.open('form_busca_cep3.asp','_janela','width=630; height=430; top=80; left=30; resizable=0; toolbar=0; location=0; scrollbars=1');
}

