function Mascara(objeto, evt, mask) {

var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var Numeros = '0123456789';
var Fixos  = '().-:/ ';
var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

evt = (evt) ? evt : (window.event) ? window.event : "";
var value = objeto.value;
if (evt) {
 var ntecla = (evt.which) ? evt.which : evt.keyCode;
 tecla = Charset.substr(ntecla - 32, 1);
 if (ntecla < 32) return true;

 var tamanho = value.length;
 if (tamanho >= mask.length) return false;

 var pos = mask.substr(tamanho,1);
 while (Fixos.indexOf(pos) != -1) {
  value += pos;
  tamanho = value.length;
  if (tamanho >= mask.length) return false;
  pos = mask.substr(tamanho,1);
 }

 switch (pos) {
   case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   case '*' : objeto.value = value; return true; break;
   default : return false; break;
 }
}
objeto.value = value;
return true;
}

// AS MASCARAS EFETIVAS
function MaskCEP(objeto, evt) {
return Mascara(objeto, evt, '#####-###');
}

function MaskTelefone(objeto, evt) {
return Mascara(objeto, evt, '####-####');
}

function MaskCPF(objeto, evt) {
return Mascara(objeto, evt, '###.###.###-##');
}

function MaskRG(objeto, evt) {
return Mascara(objeto, evt, '##.###.###-#');
}


function MaskCNPJ(objeto, evt) {
return Mascara(objeto, evt, '##.###.###/####-##');
}

function MaskCartao(objeto, evt) {

  var indice = document.cf.bandeiraCard.selectedIndex;
  var Tipo   = document.cf.bandeiraCard.options[indice].value;

  switch(Tipo){
        case "1":
           return Mascara(objeto, evt, '################'); //13, 16
        case "2":
           return Mascara(objeto, evt, '################'); //16
        case "3":
           return Mascara(objeto, evt, '##############');   //14
        case "4":
           return Mascara(objeto, evt, '###############');  //15
        }
}


function MaskData(objeto, evt) {
return Mascara(objeto, evt, '##/##/####');
}


//----------------------------------------------------------------



// TROCA AUTOMATICA ENTRE OS CAMPOS
//----------------------------------------------------------------
//PARA PESSOA FISICA
function maxToquesCPF(){
        if(document.getElementById('cpf').value.length == document.getElementById('cpf').maxLength){
                document.getElementById('rg').focus();
        }
}
function maxToquesRG(){
        if(document.getElementById('rg').value.length == document.getElementById('rg').maxLength){
                document.getElementById('instituicaopf').focus();
        }
}

function maxToquesDataNasc_f(){
        if(document.getElementById('nasc_f').value.length == document.getElementById('nasc_f').maxLength){
                document.getElementById('sexopf').focus();
        }
}

//PARA PESSOA JURIDICA
function maxToquesCPFpj(){
        if(document.getElementById('cpfpj').value.length == document.getElementById('cpfpj').maxLength){
                document.getElementById('nasc_j').focus();
        }
}

function maxToquesCNPJ(){
        if(document.getElementById('cnpj').value.length == document.getElementById('cnpj').maxLength){
                document.getElementById('nomepj').focus();
        }
}

function maxToquesDataNasc_j(){
        if(document.getElementById('nasc_j').value.length == document.getElementById('nasc_j').maxLength){
                document.getElementById('sexopj').focus();
        }
}

function maxToquesCep(){
        if(document.getElementById('cep1').value.length == document.getElementById('cep1').maxLength){
                document.getElementById('cep2').focus();
        }
}

function maxToquesCEP2(){
        if(document.getElementById('cep2').value.length == document.getElementById('cep2').maxLength){
                document.getElementById('tipo_logra').focus();
        }
}
function maxToquesCep3(){
        if(document.getElementById('cep2_1').value.length == document.getElementById('cep2_1').maxLength){
                document.getElementById('cep2_2').focus();
        }
}

function maxToquesCEP4(){
        if(document.getElementById('cep2_2').value.length == document.getElementById('cep2_2').maxLength){
                document.getElementById('tipo_logra2').focus();
        }
}


function maxToquesDDD_FONE(){
        if(document.getElementById('ddd_fone').value.length == document.getElementById('ddd_fone').maxLength){
                document.getElementById('fone').focus();
        }
}

function maxToquesFONE(){
        if(document.getElementById('fone').value.length == document.getElementById('fone').maxLength){
                document.getElementById('ddd_cel').focus();
        }
}
function maxToquesDDD_CEL(){
        if(document.getElementById('ddd_cel').value.length == document.getElementById('ddd_cel').maxLength){
                document.getElementById('cel').focus();
        }
}
function maxToquesCEL(){
        if(document.getElementById('cel').value.length == document.getElementById('cel').maxLength){
                document.getElementById('ddd_fax').focus();
        }
}
function maxToquesDDD_FAX(){
        if(document.getElementById('ddd_fax').value.length == document.getElementById('ddd_fax').maxLength){
                document.getElementById('fax').focus();
        }
}
function maxToquesFAX(){
        if(document.getElementById('fax').value.length == document.getElementById('fax').maxLength){
                document.getElementById('ref_entrega').focus();
        }
}


function maxToquesCARCEP1(){
        if(document.getElementById('cep_p1').value.length == document.getElementById('cep_p1').maxLength){
                document.getElementById('cep_p2').focus();
        }
}

//PARA O CARTAO DE CREDITO

function maxToquesNB_CARTAO(){

 if(document.getElementById('txtNumCartao').value.length == document.getElementById('txtNumCartao').maxLength){
                document.getElementById('txtCodSerg').focus();
  }
}

function maxToquesValid_Mes(){
        if(document.getElementById('txtDtValidade_Mes').value.length == document.getElementById('txtDtValidade_Mes').maxLength){
                document.getElementById('txtDtValidade_Ano').focus();
        }

}




//MENU
GroupAtual = "";
function abrefecha(atual,tot){
        if(GroupAtual == "" || GroupAtual != atual){
            //total de categorias
                for(i=1; i<=tot; i++){
                document.getElementById('sub' + i).style.display = 'none';
            }

            document.getElementById('sub'+atual).style.display = 'block';
                GroupAtual = atual;
        } else {
                document.getElementById('sub'+atual).style.display = 'none';
                GroupAtual = "";

        }
}



//PARA AS IMAGENS
function hider()
{
document.all.div1.style.display = 'none';
document.all.div2.style.display = 'block';
}
function unHider()
{
document.all.div1.style.display = 'block';
document.all.div2.style.display = 'none';
}



function showentrega(){
        if(cad.ent.value==1){
                document.getElementById('de').style.display  = 'block';
        }else{
                document.getElementById('de').style.display  = 'none';
        }
}

function soferta()
{
document.getElementById('so').style.display = 'none';
}
function hoferta()
{
document.getElementById('valor0').value = '';
document.getElementById('so').style.display = 'block';
}
function hoferta2()
{
document.getElementById('so').style.display = 'block';
}



function validarecupera()
{
        if (recu.userl.value==""){alert('Por favor, informe o E-mail.'); recu.userl.focus(); return false; }
}

function limpapc(){ fbu.keyword.value=''; }
function limpapc2(){ fbu2.keyword2.value=''; }
function limpanasc_f(){ cad.nasc_f.value=''; }
function limpanasc_j(){ cad.nasc_j.value=''; }
function limpapc1(){ fbu1.sumario.value=''; }

function showpf(){
        document.getElementById('pf').style.display  = 'block';
        document.getElementById('pj').style.display  = 'none';

        document.cad.nomepf.focus();
        //document.cad.emissao[0].checked = true;
        //document.cad.emissao[1].disabled = true;

}
function showpj(){
        document.getElementById('pj').style.display  = 'block';
        document.getElementById('pf').style.display  = 'none';

        document.cad.nomepj.focus();
        //document.cad.emissao[1].checked = true;
       // document.cad.emissao[1].disabled = false;

}


function disable_boleto(){
//document.cf.meio_pgto[1].disabled=true;
document.getElementById('Boleto').disabled=true;
document.getElementById('Cartao').checked=true;
showcartao();
}
function enable_boleto(){
//document.cf.meio_pgto[1].disabled=false;
document.getElementById('Boleto').disabled=false;
document.getElementById('Boleto').checked=true;
hidecartao();
}


function showepj(){
 document.getElementById('epj').style.display  = 'block';
}
function hideepj(){
 document.getElementById('epj').style.display  = 'none';
}

function showcartao(){
 document.getElementById('ct').style.display  = 'block';
}
function hidecartao(){
 document.getElementById('ct').style.display  = 'none';
}






function openwindow(id)
{
   window.open("video.php?idv="+id+"","VídeoABM","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=480,height=360,left=0,top=0");
}




/*
function erv(){ //emissao do recibo de venda

         //se clicar na fisica
         if(cad.tipocad[0].checked==true){
                cad.emissao[0].checked = true;
                cad.emissao[1].disabled = true;

         //se clicar na juridica
         }else if(cad.tipocad[1].checked==true){
                cad.emissao[1].checked = true;
                cad.emissao[1].disabled = false;
         }

}
*/


//====================================================================================================
//                                                                                      CPF - CNPJ
//====================================================================================================
//valida numero inteiro com mascara
function mascaraInteiro(){
        if (event.keyCode < 48 || event.keyCode > 57){
                event.returnValue = false;
                return false;
        }
        return true;
}


//valida o CPF Pessoa Fisica
function ValidarCPFPF(Objcpf){
        var ck_cpf = Objcpf.value;
        exp = /\.|\-/g
        ck_cpf = ck_cpf.toString().replace( exp, "" );
        if(!valida_cpf(ck_cpf)){
           alert('C.P.F. inválido, favor verificar!');
           return false;
        }
}

//valida o CPF Pessoa Juridica
function ValidarCPFPJ(Objcpf){
        var ck_cpf = Objcpf.value;
        exp = /\.|\-/g
        ck_cpf = ck_cpf.toString().replace( exp, "" );
        if(!valida_cpf(ck_cpf)){
           alert('C.P.F. inválido, favor verificar!');
           return false;
        }
}


//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
        var ck_cnpj = ObjCnpj.value;
        exp = /\.|\-/g
        ck_cnpj = ck_cnpj.toString().replace( exp, "" );
        ck_cnpj = ck_cnpj.toString().replace( '/', "" );
        if(!valida_cnpj(ck_cnpj)){
           alert('C.N.P.J. inválido, favor verificar!');
           return false;
        }
}



//====================================================================================================
//====================================================================================================


//                                                                                              VALIDACOES - SITE
//--------------------------------------------------------------------------------------------------------
// Cadastro
function validacad()
{

if (cad.tipocad[0].checked){
        var ck_cpf = cad.cpf.value;
        exp = /\.|\-/g
        ck_cpf = ck_cpf.toString().replace( exp, "" );
        if (cad.nomepf.value=="") {alert('Por favor, informe o Nome.'); cad.nomepf.focus(); return false; }
        if (cad.cpf.value=="")    {alert('Por favor, informe o CPF.'); cad.cpf.focus(); return false; }
        else{if(!valida_cpf(ck_cpf)){alert('C.P.F. inválido, favor verificar!');cad.cpf.focus();cad.cpf.select();return false;
        }}
        if (cad.nasc_f.value=="") {alert('Por favor, informe o Data de Nascimento.'); cad.nasc_f.focus(); return false; }
        else{if(!check_date(cad.nasc_f.value)){limpanasc_f();cad.nasc_f.focus();return false;}}
        if (cad.sexopf.value=="") {alert('Por favor, informe o Gênero.'); cad.sexopf.focus(); return false; }

}else if(cad.tipocad[1].checked){
        var ck_cnpj = cad.cnpj.value;
        var ck_cpf  = cad.cpfpj.value;
        exp = /\.|\-/g
        ck_cnpj = ck_cnpj.toString().replace( exp, "" );
        ck_cnpj = ck_cnpj.toString().replace( '/', "" );
        ck_cpf  = ck_cpf.toString().replace( exp, "" );
        if (cad.empresa.value==""){alert('Por favor, informe a Empresa.'); cad.empresa.focus(); return false; }
        if (cad.cnpj.value=="")   {alert('Por favor, informe o CNPJ.'); cad.cnpj.focus(); return false; }
        else{if(!valida_cnpj(ck_cnpj)){alert('C.N.P.J. inválido, favor verificar!');cad.cnpj.focus();cad.cnpj.select();return false;
        }}
        if (cad.nomepj.value=="") {alert('Por favor, informe o Nome.'); cad.nomepj.focus(); return false; }
        if (cad.cpfpj.value=="")  {alert('Por favor, informe o CPF.'); cad.cpfpj.focus(); return false; }
        else{if(!valida_cpf(ck_cpf)){alert('C.P.F. inválido, favor verificar!');cad.cpfpj.focus();cad.cpfpj.select();return false;
        }}
        if (cad.nasc_j.value=="") {alert('Por favor, informe o Data de Nascimento.'); cad.nasc_j.focus(); return false; }
        else{if(!check_date(cad.nasc_j.value)){limpanasc_j();cad.nasc_j.focus();return false}}
        if (cad.sexopj.value=="") {alert('Por favor, informe o Gênero.'); cad.sexopj.focus(); return false; }
}


//para o endereco
if (cad.cep1.value=="")         {alert('Por favor, informe o CEP.'); cad.cep1.focus(); return false; }
if (cad.cep2.value=="")         {alert('Por favor, informe o restante do CEP.'); cad.cep2.focus(); return false; }
if (cad.tipo_logra.value=="")   {alert('Por favor, informe o Tipo do logradouro.'); cad.tipo_logra.focus(); return false; }
if (cad.logradouro.value=="")   {alert('Por favor, informe o Logradouro.'); cad.logradouro.focus(); return false; }
if (cad.numero.value=="")       {alert('Por favor, informe o Número.'); cad.numero.focus(); return false; }
if (cad.bairro.value=="")       {alert('Por favor, informe o Bairro.'); cad.bairro.focus(); return false; }
if (cad.cidade.value=="")       {alert('Por favor, informe a Cidade.'); cad.cidade.focus(); return false; }
if (cad.estado.value=="")       {alert('Por favor, informe o Estado.'); cad.estado.focus(); return false; }
if (cad.ddd_fone.value=="")     {alert('Por favor, informe o DDD do telefone.'); cad.ddd_fone.focus(); return false; }
if (cad.fone.value=="")         {alert('Por favor, informe o Telefone.'); cad.fone.focus(); return false; }

        //caso o endereco seja diferente para a entrega
        if(cad.ent.value==1){
                if (cad.cep2_1.value=="")       {alert('Por favor, informe o CEP de entrega.'); cad.cep2_1.focus(); return false; }
                if (cad.cep2_2.value=="")       {alert('Por favor, informe o restante do CEP de entrega.'); cad.cep2_2.focus(); return false; }
                if (cad.tipo_logra2.value=="")  {alert('Por favor, informe o Tipo do logradouro de entrega.');cad.tipo_logra2.focus();return false; }
                if (cad.logradouro2.value=="")  {alert('Por favor, informe o Logradouro de entrega.');cad.logradouro2.focus(); return false; }
                if (cad.numero2.value=="")      {alert('Por favor, informe o Número de entrega.'); cad.numero2.focus(); return false; }
                if (cad.bairro2.value=="")      {alert('Por favor, informe o Bairro de entrega.'); cad.bairro2.focus(); return false; }
                if (cad.cidade2.value=="")      {alert('Por favor, informe a Cidade de entrega.'); cad.cidade2.focus(); return false; }
                if (cad.estado2.value=="")      {alert('Por favor, informe o Estado de entrega.'); cad.estado2.focus(); return false; }
        }


if (cad.email.value=="")  {alert('Por favor, informe o E-mail.'); cad.email.focus(); return false; }
if (cad.senha.value=="")  {alert('Por favor, informe a Senha.'); cad.senha.focus(); return false; }
if (cad.senha2.value=="") {alert('Por favor, informe a Confirmação da senha.'); cad.senha2.focus(); return false; }

if (cad.senha.value==cad.senha2.value){
}else{
   alert('Atenção: As senhas devem ser iguais.');
   cad.senha.value="";
   cad.senha2.value="";
   cad.senha.focus();
   return false;
}


}

 //fim da funciton





// Busca
function validabusca(){
        if (fbu.keyword.value==""){
                alert('Por favor, informe a palava chave antes de realizar a busca.');
                fbu.keyword.focus();
                return false;
        }
}

function validabusca_cat(){
        if (fbu_cat.cod_cat.value==""){
                alert('Por favor, informe um produto antes de realizar a busca.');
                fbu_cat.cod_cat.focus();
                return false;
        }
}


// Busca AVANÇADA
function validabuscaav(){ //PALAVRA E SUBCAT
        if (fbu2.keyword2.value==""){
                alert('Por favor, informe a palava chave antes de realizar a busca.');
                fbu2.keyword2.focus();
                return false;
        }
        if (fbu2.cod_subcat.value==""){
                alert('Por favor, informe o Assunto antes de realizar a busca.');
                fbu2.cod_subcat.focus();
                return false;
        }
}

function validabuscasm(){ //Sumário E SUBCAT
        if (fbu1.sumario.value==""){
                alert('Por favor, informe a palava chave antes de realizar a busca.');
                fbu1.sumario.focus();
                return false;
        }
        if (fbu1.cod_subcat.value==""){
                alert('Por favor, informe o Assunto antes de realizar a busca.');
                fbu1.cod_subcat.focus();
                return false;
        }
}





function validabuscasub(){ //PALAVRA E SUBCAT
        if (fbu3.cod_subcat.value==""){
                alert('Por favor, informe o Assunto antes de realizar a busca.');
                fbu3.cod_subcat.focus();
                return false;
        }
}
function validabuscaavp(){ //PRECOS
        if (fbu3.valor1.value==""){
                alert('Por favor, informe o menor valor antes de realizar a busca.');
                fbu3.valor1.focus();
                return false;
        }
        if (fbu3.valor2.value==""){
                alert('Por favor, informe o maior valor antes de realizar a busca.');
                fbu3.valor2.focus();
                return false;
        }
}



// Login
function validalogin(l){
        if (l.userl.value==""){alert('Por favor, informe o e-mail para entrar.'); l.userl.focus(); return false; }
        if (l.passl.value==""){alert('Por favor, informe a senha para entrar.'); l.passl.focus(); return false; }
}

// Newsletter
function validanews(){
        /*
        if (n.option[0].checked) {
                if (n.emailnews.value==""){alert('Por favor, informe o e-mail para cadastrar.'); n.emailnews.focus(); return false; }
        }
        if (n.option[1].checked) {
                if (n.emailnews.value==""){alert('Por favor, informe o e-mail para remover.'); n.emailnews.focus(); return false; }
        }
        */
if (fn.emailnews.value==""){alert('Por favor, informe o e-mail para cadastrar.'); fn.emailnews.focus(); return false; }

}



// Contato
function validacont(){
        if (cont.nome.value=="")        {alert('Por favor, informe o Nome.'); cont.nome.focus(); return false; }
        if (cont.ddd_fone.value=="")    {alert('Por favor, informe o DDD do telefone.'); cont.ddd_fone.focus(); return false; }
        if (cont.fone.value=="")        {alert('Por favor, informe o Telefone.'); cont.fone.focus(); return false; }
        if ((cont.email.value=="")||(cont.email.value.indexOf('@', 0)==-1)) {alert('Por favor, informe um E-mail válido!'); cont.email.focus(); return false; }
        if (cont.assunto.value=="")     {alert('Por favor, informe o Assunto.'); cont.assunto.focus(); return false; }
}

// FINALIZAR
function validacf(){

        //Emissão do Pedido
        if(cf.tipo_emissao[1].checked){
                if (cf.e_empresa.value==""){alert('Por favor, informe a Empresa.');
                                            cf.e_empresa.focus();
                                            return false; }
                if (cf.e_cnpj.value=="")   {alert('Por favor, informe o C.N.P.J.');
                                            cf.e_cnpj.focus();
                                            return false; }
                //Verifica CNPJ
                var ck_cnpj = cf.e_cnpj.value;
                exp = /\.|\-/g
                ck_cnpj = ck_cnpj.toString().replace( exp, "" );
                ck_cnpj = ck_cnpj.toString().replace( '/', "" );
                if(!valida_cnpj(ck_cnpj)){
                   alert('C.N.P.J. inválido, favor verificar!');
                   cf.e_cnpj.focus();
                   cf.e_cnpj.select();
                   return false;
                }
                return true;
        }
    // Validar Cartão
    if(cf.meio_pgto[1].checked){
      // Para as datas
       var DataAtual = new Date();
       var Ano       = parseInt(document.cf.txtDtValidade_Ano.value);
       var AnoAtual  = DataAtual.getFullYear();
       var AnoLimite = AnoAtual+5;
       var Mes       = parseInt(document.cf.txtDtValidade_Mes.value,10);
       var MesAtual  = DataAtual.getMonth()+1;
       var indice    = document.cf.bandeiraCard.selectedIndex;


       //Validar Titular

      if (cf.txtTitular.value==""){alert('Por favor, informe o Nome do Titular');
                                   cf.txtTitular.focus();
                                   return false; }

      if (cf.txtCnpjCpf.value==""){alert('É obrigatório o preechimento do C.P.F. ou C.N.P.J.');
                                 cf.txtCnpjCpf.focus();
                                 return false;
                                 }
      if(cf.tipo[0].checked){
                               var ck_cpf = cf.txtCnpjCpf.value;
                               exp = /\.|\-/g
                               ck_cpf = ck_cpf.toString().replace( exp, "" );
                               if(!valida_cpf(ck_cpf)){
                                   alert('C.P.F. inválido, favor verificar!');
                                   cf.txtCnpjCpf.focus();
                                   cf.txtCnpjCpf.select();
                                   return false;
                                }
      }else{
                               var ck_cnpj = cf.txtCnpjCpf.value;
                               exp = /\.|\-/g
                               ck_cnpj = ck_cnpj.toString().replace( exp, "" );
                               if(!valida_cnpj(ck_cnpj)){
                                   alert('C.N.P.J. inválido, favor verificar!');
                                   cf.txtCnpjCpf.focus();
                                   cf.txtCnpjCpf.select();
                                   return false;
                               }
      }

      if (cf.txtNumCartao.value==""){alert('Por favor, informe o Número do Cartão de Crédito');
                                     cf.txtNumCartao.focus();
                                     return false;}

      if (!isValidCreditCardNumber(cf.txtNumCartao.value)){
                                     cf.txtNumCartao.focus();
                                     return false;}


      if (cf.txtCodSerg.value==""){alert('Por favor, informe o Código de Segurança');
                                 cf.txtCodSerg.focus();
                                 return false;}

      if ((document.cf.bandeiraCard.options[indice].value=="1") || (document.cf.bandeiraCard.options[indice].value=="2") || (document.cf.bandeiraCard.options[indice].value=="3")){
           if (cf.txtCodSerg.value.length!=3){alert('Código de Segurança das Operadoras Visa, MasterCard ou Diners deve ter 3 digítos');
                                             cf.txtCodSerg.focus();
                                             return false;}
                                             }
      if (document.cf.bandeiraCard.options[indice].value=="4"){
           if (cf.txtCodSerg.value.length!=4){alert('Código de Segurança da Operadora Amex deve ter 4 digítos');
                                             cf.txtCodSerg.focus();
                                             return false;}
                                             }

      //Checar datas

      if (cf.txtDtValidade_Mes.value==""){alert('Por favor, informe o mês da validade do Cartão');
                                         cf.txtDtValidade_Mes.focus();
                                         return false;
                                         }else{
                                               if (Mes<1 || Mes>12){alert('O Mês informado não é válido, informe corretamente');
                                                                    cf.txtDtValidade_Mes.focus();
                                                                    return false;}

                                         }

      if (cf.txtDtValidade_Ano.value==""){alert('Por favor, informe o ano da validade do Cartão');
                                         cf.txtDtValidade_Ano.focus();
                                         return false;
                                         }else{

                                              if (Ano==AnoAtual && Mes<MesAtual){alert('A data de validade está expirada');
                                                                                 cf.txtDtValidade_Mes.focus();
                                                                                 cf.txtDtValidade_Mes.select();
                                                                                 return false;}
                                              if (Ano<AnoAtual || Ano>AnoLimite){alert('O ano informado não é válido, informe corretamente');

                                                                            cf.txtDtValidade_Ano.focus();
                                                                            cf.txtDtValidade_Ano.select();
                                                                            return false;}

                                         }
      }


}


//var url = url + "?url=" + document.location
//        var NS = (document.layers) ? true : false;
//        var IE = (document.all) ? true : false;

function openform(id)
{
   window.open("recomendar.php?idv="+id+"","ABM","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=310,left=0,top=0");
}
/*
if(NS) {
        window.open("recomendar.php?idv="+id+"","ABM-Recomendar","scrollbars=no,menubar=no,personalbar=no,width=500,height=310,screenX=0,screenY=0");

        window.open("video.php?idv="+id+"","VídeoABM","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=480,height=360,left=0,top=0");



} else {
        window.open(url,"","scrollbars=no,menubar=no,personalbar=no,width=500,height=312,left=0,top=0");
}
*/

//seta o tipo cnpj ou cpf no campo
function setTipo(tipo){
  var input = document.getElementById("cnpjCpf");
  switch(tipo){
    case "cnpj":
      input.setAttribute("onkeypress","return MaskCNPJ(this,event)"); //firefox
      input.onkeypress = function(event){//IE
            return MaskCNPJ(this,event);
       }
    break;
    case "cpf":
       input.setAttribute("onkeypress","return MaskCPF(this,event)"); //firefox
       input.onkeypress = function(event){//IE
            return MaskCPF(this,event);
       }
    break;
  }
}

function valida_cpf(cpf)
     {
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      }

function valida_cnpj(cnpj)
      {
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      }




function check_date(date) {
   var err = 0
   string = date
   var valid = "0123456789/"
   var ok = "yes";
   var temp;
   for (var i=0; i< string.length; i++) {
     temp = "" + string.substring(i, i+1);
     if (valid.indexOf(temp) == "-1") err = 1;
   }
   if (string.length != 10) err=1
   b = string.substring(3, 5) // month
   c = string.substring(2, 3) // '/'
   d = string.substring(0, 2) // day
   e = string.substring(5, 6) // '/'
   f = string.substring(6, 10)// year
   if (b<1 || b>12) err = 1
   if (c != '/') err = 1
   if (d<1 || d>31) err = 1
   if (e != '/') err = 1
   if (f<1850 || f>2050) err = 1
   if (b==4 || b==6 || b==9 || b==11){
     if (d==31) err=1
   }
   if (b==2){
     var g=parseInt(f/4)
     if (isNaN(g)) {
         err=1
     }
     if (d>29) err=1
     if (d==29 && ((f/4)!=parseInt(f/4))) err=1
   }
   if (err==1) {
        alert("Data inválida");

    return false;
   }
   else {
    return true;
   }
}

function entra_cad()
{
document.getElementById('ck_usu').style.display = 'block';
}

function valida_precad(){
   if (chk.CnpjCpf_chk.value==""){alert('É obrigatório o preechimento do C.P.F. ou C.N.P.J.');
                                 chk.CnpjCpf_chk.focus();
                                 return false;
                                }


    if(chk.tipo_chk[0].checked){
                               var ck_cpf = chk.CnpjCpf_chk.value;
                               exp = /\.|\-/g
                               ck_cpf = ck_cpf.toString().replace( exp, "" );
                               if(!valida_cpf(ck_cpf)){
                                   alert('C.P.F. inválido, favor verificar!');
                                   chk.CnpjCpf_chk.focus();
                                   chk.CnpjCpf_chk.select();
                                   return false;
                                }
    }else{
                               var ck_cnpj = chk.CnpjCpf_chk.value;
                               exp = /\.|\-/g
                               ck_cnpj = ck_cnpj.toString().replace( exp, "" );
                               ck_cnpj = ck_cnpj.toString().replace( '/', "" );
                               if(!valida_cnpj(ck_cnpj)){
                                   alert('C.N.P.J. inválido, favor verificar!');
                                   chk.CnpjCpf_chk.focus();
                                   chk.CnpjCpf_chk.select();
                                   return false;
                               }
     }
}
function ValidarCpo(objCpo)
{
if (objCpo.Value==""){alert('É obrigatório o preechimento do campo.');
                      objCpo.focus();
                      return false;
                     }
}

function ChecarDados() {
        with(document.cad) {
                if (senha.value == "") {
                        alert("É obrigatório o preechimento da senha!");
                        senha.focus();
                        return false; }
                 if (senha2.value == "") {
                        alert("É obrigatório o preechimento da confirmação da senha!");
                        senha2.focus();
                        return false;
                }
                        submit();
        }
}




function isValidCreditCardNumber(cardNumber){

    var indice   = document.cf.bandeiraCard.selectedIndex;
    var cardType = document.cf.bandeiraCard.options[indice].value;

    var isValid  = false;
    var ccCheckRegExp = /[^\d ]/;
    isValid = !ccCheckRegExp.test(cardNumber);
    if (isValid){
        var cardNumbersOnly = cardNumber.replace(/ /g,"");
        var cardNumberLength = cardNumbersOnly.length;
        var lengthIsValid = false;
        var prefixIsValid = false;
        var prefixRegExp;
    switch(cardType){
       case "1":
            lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
            prefixRegExp = /^4/;
        break;
        case "2":
            lengthIsValid = (cardNumberLength == 16);
            prefixRegExp = /^5[1-5]/;
        break;
        case "3":
            lengthIsValid = (cardNumberLength == 14);
            prefixRegExp = /^3[68]/;
        break;
        case "4":
            lengthIsValid = (cardNumberLength == 15);
            prefixRegExp = /^3(4|7)/;
        break;
        default:
            prefixRegExp = /^$/;

    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;

    if (!isValid){
           alert("Tipo de cartão inexistente");
           return false;
    }

    }
    if (isValid){
        var numberProduct;
        var numberProductDigitIndex;
        var checkSumTotal = 0;
        for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
            checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
            digitCounter--;
            numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
            for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++){
                checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
            }
        }
        isValid = (checkSumTotal % 10 == 0);
        if (!isValid){
           alert('Cartão inválido!');
           return false;
        }
    }

    return isValid;
}

//************************************************************************************************************************
// Fucao para validar email.
//************************************************************************************************************************
function chkEmail(msg) {

  var e = cad.email;
  if (e.value == null){
    alert(msg);
    e.focus();
    return (false);}
  //tirando os espaços vazios no endereço
  for (x = 1; x < e.value.length; x ++)
     { e.value= e.value.replace(' ', '')}

  var emailStr
  emailStr = e.value;
  var emailPat=/^(.+)@(.+)$/
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  var validChars="\[^\\s" + specialChars + "\]"
  var quotedUser="(\"[^\"]*\")"
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  var atom=validChars + '+'
  var word="(" + atom + "|" + quotedUser + ")"
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  var matchArray = emailStr.match(emailPat)
  if (matchArray==null){
    alert('O email informado não é válido.');
    e.value="";
    e.focus();
    return (false);}

  var user=matchArray[1]
  var domain=matchArray[2]
  if (user.match(userPat)==null){
    alert("O seu Nome de usuário parece não ser válido.");
    e.value="";
    e.focus();
    return (false);}

  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null){
  for (var i=1;i<=4;i++){
  if (IPArray[i]>255){
    alert('O endereço do IP parece não ser válido!');
    e.value="";
    e.focus();
    return (false);}
  }
  return true;}

  var domainArray=domain.match(domainPat)
  if (domainArray==null){
    alert('O domínio parece não ser válido !');
    e.value="";
    e.focus();
    return (false);}

  var atomPat=new RegExp(atom,"g")
  var domArr=domain.match(atomPat)
  if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3){
    alert('O endereço deve conter três letras de domínio, ou duas letras do país.');
    e.value="";
    e.focus();
    return (false);}

  if (domArr.length<2){
    var errStr="Este endereço não está encontrando o seu provedor!"
    alert(errStr);
    e.value="";
    e.focus();
    return (false);}

return true;
}



/*
 You may copy this code as long as you have this comment in header and distributed MyCreditCard_ReadMe.txt file with it.
 Copyright: Dusko Vuksanovic
 You can find many usable scripts at: http://burza.exocrew.com/myweb
*/
function ccValidate(ccNumber){
//Based on algorithm: http://www.beachnet.com/~hstiles/cardtype.html
    var digits = '';
    var number = ccNumber;
    var digitPosRight=0;
    for (var ccDigit=1;ccDigit<=number.length;ccDigit++) {
         digitPosRight++;
         var digitPos = number.length - ccDigit;
         digits = (digitPosRight % 2 == 0)
         ? ((number.charAt(digitPos)/1) * 2) + digits
         : number.charAt(digitPos) + digits;
    }
    digitPosRight=0;
    for (var ccDigit=0;ccDigit<digits.length;ccDigit++) {
         digitPosRight += (digits.charAt(ccDigit)/1);
    }
    return ((digitPosRight % 10 == 0) || ((number.length == 15) && ((number.substr(0, 4) == '2014') || (number.substr(0, 4) == '2149'))));
}

function ccFindType(ccNumber) {
//Based on algorithm: http://www.beachnet.com/~hstiles/cardtype.html
    var arrCCNames = new Array ('MasterCard' //     0
                              , 'Visa' //     1
                              , 'Amex' //     2
                              , 'Diners Club' //      3
                              , 'Discover' // 4
                              , 'enRoute' //  5
                              , 'JCB' //      6
                               );
    switch (ccNumber.length) {
           case 13 : switch (ccNumber.charAt(0)) {
                            case '4' : return arrCCNames[1];
                                       break;
                     }
           case 14 : switch (ccNumber.substr(0, 2)) {
                            case '36' :
                            case '38' : return arrCCNames[3];
                                        break;
                     }
    switch (ccNumber.substr(0, 3)) {
           case '300' :
           case '301' :
           case '302' :
           case '303' :
           case '304' :
           case '305' : return arrCCNames[3];
                        break;
    }
           break;
           case 15 : switch (ccNumber.substr(0, 2)) {
                            case '34' :
                            case '37' : return arrCCNames[2];
                                        break;
                     }
                     switch (ccNumber.substr(0, 4)) {
                            case '2014' :
                            case '2149' : return arrCCNames[5];
                                          break;
                            case '2131' :
                            case '1800' : return arrCCNames[6];
                                          break;
                     }
           break;
           case 16 : switch (ccNumber.charAt(0)) {
                            case '3' : return arrCCNames[6];
                                       break;
                            case '4' : return arrCCNames[1];
                                       break;
                     }
                     switch (ccNumber.substr(0, 2)) {
                            case '51' :
                            case '52' :
                            case '53' :
                            case '54' :
                            case '55' : return arrCCNames[0];
                                        break;
                     }
                     switch (ccNumber.substr(0, 4)) {
                            case '6011' : return arrCCNames[4];
                                          break;
                     }
           break;
                                }
                                return '';
    }

//onClick="if (ccValidate(ccNumber.value)) ccType.value=ccFindType(ccNumber.value); else ccType.value='<INVALID CARD>'; return false;">

