//adquirir
function comprasAdquirir(id, cat, frete) {
   if (frete == null) frete = '';
   if (document.getElementById('idLocalEntrega') != null) var localEntrega = document.getElementById('idLocalEntrega').value;
   else var localEntrega = 'P';
   if (id && cat)
      window.location = '../loja_virtual/?acao=coAd&id='+id+'&categoria='+cat+'&frete='+frete+'&localEntrega='+localEntrega+"#carrinhoCompra";
   else
      window.location = '../loja_virtual/?acao=co&frete='+frete+'&localEntrega='+localEntrega+"#carrinhoCompra";
}
//adicionar a carrinho de compra
function comprasAdicionarLista(id, cat, div) {
   if (id && cat && div) {
      ElementClassChange(div, 'adicionadoLista');
      refreshPage('./produto_carrinho.php?id='+id+'&categoria='+cat, div);
      //recontar numero
      refreshPage('./minha_lista.php', "idMinhaListaResultado");
   }
}

function comprasRemover(id, cat, frete){
   var qtd = 0;
   if (document.getElementById('idLocalEntrega') != null) var localEntrega = document.getElementById('idLocalEntrega').value;
   else var localEntrega = 'P';
   if (document.getElementById('idQtd'+id) != null) {
      qtd = parseInt(document.getElementById('idQtd'+id).value) - 1;
   }
   if (id && cat) {
      //remover item
      window.location = '../loja_virtual/?acao=ex&id='+id+'&categoria='+cat+'&frete='+frete+'&localEntrega='+localEntrega+"#carrinhoCompra";
   } 
      
}

function comprasQuantidade(id, cat, frete, qtd){
   if (document.getElementById('idLocalEntrega') != null) var localEntrega = document.getElementById('idLocalEntrega').value;
   else var localEntrega = 'P';
   if (id&&cat) {
      ElementShowHidden('idLoading', 1);
      window.location = '../loja_virtual/?acao=alQt&id='+id+'&categoria='+cat+'&frete='+frete+'&localEntrega='+localEntrega+'&qtd='+qtd+"#carrinhoCompra";
   }
}

function calcularFrete(doc) {
   if (doc == null || doc.value == '') {
      alert('Preencher campo CEP');
      doc.focus();
   } else {
      window.location = '../loja_virtual/?acao=caFrete&cep='+doc.value;
   }
}

function compraListaValidacao(op){
   doc = document.getElementById('idLista').getElementsByTagName('li');
   if (op != null) {
      for (var i=0; i<4; i++) {
         if (i!=op) {
            doc[i].className = '';
            document.getElementById('idListaResultado').getElementsByTagName('div')[i].style.display = 'none';
         } else {
            doc[i].className = 'selected';
            document.getElementById('idListaResultado').getElementsByTagName('div')[i].style.display = 'block';
         }
      }
   }
}

function validacaoProdutoFrete(op) {
   for (var i = 1; i<=2; i++) {
      if (i == op) {
         ElementClassChange('idFreteValor'+i, 'text_moeda normal');
      } else {
         ElementClearValue('idFreteValor'+i);
         ElementClassChange('idFreteValor'+i, 'text_moeda disable');
      }
   }
}

function validacaoRerecionarProdutoLogin() {
   window.location = '../loja_virtual/?acao=lg';
}

function validacaoProdutoFreteCorreio() {
   var checkFrete = 0;
   var localEntrega = 'P';
   //verificar cep
   if (document.getElementById('idProdutoCep').value == '' || document.getElementById('idProdutoCep').value == '-') {
      alert('Não há cadastro de CEP. Atualize seu cadastro.');
      return false;
   }
   //verificar local de entrega
   if (document.getElementById('idFieldsetLocalEntrega') != null) {
      for (var i = 0; i< document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input').length ; i++) {
         if (document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].type == 'radio' && document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].checked == true) {
            localEntrega = document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].value;
            break;
         }
      }
   }
   //verificar frete selecionado
   for (var i = 1; i<= 2; i++) {
      if (document.getElementById('idProdutoFrete'+i) != null && document.getElementById('idProdutoFrete'+i).checked == true) {
         checkFrete = i;   
         break;
      }
   }
   if (checkFrete == 0) {
      alert('Escolha a opção de envio');
      return false;
   }
   window.location = '../loja_virtual/?acao=veFr&frete='+checkFrete+'&localEntrega='+localEntrega+'#localEntrega';
}

function validacaoLocalEntrega() {
   var checkFrete = 0;
   var localEntrega = 'P';
   //verificar local de entrega
   if (document.getElementById('idFieldsetLocalEntrega') != null) {
      for (var i = 0; i< document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input').length ; i++) {
         if (document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].type == 'radio' && document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].checked == true) {
            localEntrega = document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].value;
            break;
         }
      }
   }
   //verificar frete selecionado
   for (var i = 1; i<= 2; i++) {
      if (document.getElementById('idProdutoFrete'+i) != null && document.getElementById('idProdutoFrete'+i).checked == true) {
         checkFrete = i;   
         break;
      }
   }
   window.location = '../loja_virtual/?acao=veFr&frete='+checkFrete+'&localEntrega='+localEntrega+'#localEntrega';
}

function validacaoProdutoLogin(email, senha, div, acao) {
   if (div == null || div == '') div = 'idLoginGeral';
   if (acao == null) acao = '';
   if (email.value == '' || email.value == null) {
      alert('Campo E-mail inválido');
      email.focus();
      return false;
   }
   if (senha.value == '' || senha.value == null) {
      alert('Campo Senha inválido');
      senha.focus();
      return false;
   }
   refreshPage('../geral/login_geral.php?email='+email.value+'&senha='+senha.value+'&bt_login=1&acao='+acao, div);
}
//exibir formulario para opiniao
function validacaoProdutoOpiniao(id, categoria, acao) {
   var doc              = document.getElementById('idProdutoOpiniao').getElementsByTagName('input');
   var doc2             = document.getElementById('idDepoimento');
   var notaCheck        = '';
   var notaCheckValor   = '';
   if (id && categoria) {
      //valor repassado
      if (acao == 'ad') {
         //adicionar
         for (var i=0; i<doc.length; i++) {
            if (doc[i].checked == true) {
               notaCheck = true;
               notaCheckValor = doc[i].value;
            }
         }
         if (notaCheck == '') {
            //nota nao verificado
            alert("Favor selecione nota.");
            return false;
         }
         if (doc2.value.length == 0) {
            alert("Favor preencher o campo depoimento.");
            return false;
         } else {
            var depoimento = doc2.value;
         }
         refreshPage('../loja_virtual/produto_opiniao.php?acao='+acao+'&id='+id+'&categoria='+categoria+'&nota='+notaCheckValor+'&depoimento='+depoimento, 'idProdutoOpiniao', 'slide');
      } else {
         refreshPage('../loja_virtual/produto_opiniao.php?acao='+acao+'&id='+id+'&categoria='+categoria, 'idProdutoOpiniao', 'slide');
      }
   }
}

function validacaoCompraBotao(op, urlReturn) {
   if (urlReturn == null) urlReturn = '';
   switch(op) {
      case 'cc':
         //cancelar compra
         if (confirm('Deseja cancelar compra?')) {
            window.location='../loja_virtual/?acao=cc';
         }
      break;
      case 'lg':
         //precisa se logar
         alert('Para finalizar sua compra é necessário ter cadastro no site. Você será direcionado para página de login.');
         window.location='../loja_virtual/?acao=lg&paginaRedirecionar='+urlReturn;
      break;
      case 'coFi':
         //compra final
         //verificar cpf/cnpj
         if (document.getElementById('idCpfCnpjCheck').value == '0') {
            if ((document.getElementById('idCPF1').value.length == 0 || document.getElementById('idCPF2').value.length == 0) && (document.getElementById('idCNPJ1').value.length == 0 || document.getElementById('idCNPJ1').value.length ==0 || document.getElementById('idCNPJ2').value.length == 0)) {
               alert('Necessário preencher campo CPF ou CNPJ para compra na loja virtual');
               return false;
            }
         }
         //verificar local de entrega
         if (document.getElementById('idFieldsetLocalEntrega') != null) {
            var localEntrega = '';
            for (var i = 0; i< document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input').length ; i++) {
               if (document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].type == 'radio' && document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].checked == true) {
                  localEntrega = document.getElementById('idFieldsetLocalEntrega').getElementsByTagName('input')[i].value;
                  break;
               }
            }
            if (localEntrega == '') {
               alert('Escolha o local de entrega');
               return false;
            }
         }
         //frete
         if (document.getElementById('idCheckFrete').value != '1') {
            alert('Escolha a opção de envio');
            return false;
         } else {
            document.formProdutoFinal.action='?acao=coFi';
            document.formProdutoFinal.submit();
         }
      break;
      case 'ca':
         window.location='../cadastros/?paginaRedirecionar='+urlReturn;
      break;
      case 'coMs':
         //comprar mais
         window.location='../loja_virtual/?acao=li';
      break;
      case 'alValeDesconto':
         document.formProdutoFinal.action='?acao=co#valeDesconto';
         document.formProdutoFinal.submit();
      break;
      case 'exValeDesconto':
         window.location='../loja_virtual/?acao=exValeDesconto#valeDesconto';
      break;
   }
   return true;
}

function reimprimirBoleto(id) {
   window.location='../loja_virtual/?acao=reBo&idCompra='+id;
}

function consultaPedido() {
   document.formItauShoplineConsultaPedido.target = 'SHOPLINE';
   document.formItauShoplineConsultaPedido.submit();
}

function carregaShoplinePage(time) {
   if (time == null) time = 5000;
   setTimeout("carregaShoplinePageTimer()", time);
}


function carregaShoplinePageTimer() {
   window.open('.', 'SHOPLINE', 'toolbar=yes,menubar=yes,resizable=yes,status=no,scrollbars=yes,width=675,height=485');
   document.formItauShopline.target = 'SHOPLINE';
   document.formItauShopline.submit();
}


function colorirPalestrante(num) {
   if (num != null) {
      var doc = document.getElementById('idUlPalestranteLista').getElementsByTagName('li');
      if (doc != null && doc.length >= 1) {
         for (var i=0; i<doc.length; i++) {
            if (doc[i].getElementsByTagName('a')[0] != null)
               if (i == num) {
                  doc[i].getElementsByTagName('a')[0].className = 'texto_negrito';
               } else {
                  doc[i].getElementsByTagName('a')[0].className = '';
               }
         }
      }
   }
}