
                function getBrowser()
                {
                        if(navigator.appName.indexOf("Netscape") != -1)
                                //visa_popup = window.open("", "visa_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
                                return 1;
                        else
                                //visa_popup = window.open("", "visa_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=440");

                        return 0;
                        //return true;
                }

function alert_desconto(texto)
{
        alert(text);
}

function para_pg4(verify)
{

        if (confirm("Confirma compra?")) {
                if (document.getElementById('pgto_visa').checked) {
                        document.form.action="index.php?pg=finalizar_compra&pt=3_5&verify="+verify;
                }
                document.form.submit();
        }

}

function para_pg3(cadastro)
{
        if (document.getElementById('nome').value.length == 0) {
            alert('Preencha o campo nome');
        } else if (document.getElementById('cpf').value.length == 0) {
            alert('Preencha o campo CPF');
        } else if (document.getElementById('rg').value.length == 0) {
            alert('Preencha o campo RG');
        } else if (document.getElementById('email').value.length == 0) {
            alert('Preencha o campo e-mail');
        } else if ((cadastro != 1) && (document.getElementById('senha').value.length == 0)) {
            alert('Preencha o campo senha');
        } else if ((cadastro != 1) && (document.getElementById('senha2').value.length == 0)) {
            alert('Preencha o campo de confirmação de senha');
        } else if (document.getElementById('rua').value.length == 0) {
            alert('Preencha o campo rua');
        } else if (document.getElementById('numero').value.length == 0) {
            alert('Preencha o campo nmero');
        } else if (document.getElementById('bairro').value.length == 0) {
            alert('Preencha o campo bairro');
        } else if (document.getElementById('cidade').value.length == 0) {
            alert('Preencha o campo cidade');
        } else if (document.getElementById('estado').value.length == 0) {
            alert('Preencha o campo estado');
        } else if (!document.getElementById('aceito').checked) {
            alert('A compra só pode ser efetuada caso aceite nossos Termos e Condições');
        } else {
            document.form.submit();
        }
}

function para_pg2_2()
{
        if (document.getElementById('email').value.length == 0) {
            alert('Preencha o campo e-mail');
        } else if (document.getElementById('cadastro_s').checked && document.getElementById('senha').value.length == 0) {
            alert('Preencha o campo senha');
        } else {

            document.form.submit();
        }
}

function para_pg2(desconto, valor_desconto, valor_descontado)
{
        if (parseInt(document.getElementById('valor_frete').innerHTML) != 0) {
                document.form.campo_desconto.value=desconto;
                document.form.campo_valor_desconto.value=valor_desconto;
                document.form.campo_valor_descontado.value=valor_descontado;

                document.form.submit();
        } else {
                alert('Digite um CEP válido e calcule o frete!');
        }
}

function calcular()
{
        if ((document.getElementById('cep1').value.length == 5) && (document.getElementById('cep2').value.length == 3)) {

                if (document.getElementById('frete_sedex').checked) {
                        calcularFrete(document.getElementById('cep1').value+document.getElementById('cep2').value);
                } else if (document.getElementById('frete_carta_registrada').checked) {
                        if (parseInt(document.getElementById('n_produtos').innerHTML) <= 10) {
                                calcularFrete2(document.getElementById('cep1').value+document.getElementById('cep2').value);
                        } else {
                                alert('Envios com carta registrada admitem no mínimo compras de 10 itens');
                                document.getElementById('frete_sedex').checked=true;
                        }
                }
        } else {
                alert('CEP invalido!');
                atualizar_frete(0);
                return 0;
        }
}

function trata_cep()
{
        if(document.getElementById('cep1').value.length == 5)
                document.getElementById('cep2').focus();
}

function atualizar_frete(frete)
{
        // atualiza valor frete
        document.getElementById('valor_frete').innerHTML = numero2moeda(frete);

        s = parseFloat(document.getElementById('subtotal').innerHTML.replace('.','').replace(',','.'));
        f = parseFloat(document.getElementById('valor_frete').innerHTML.replace('.','').replace(',','.'));
        d = parseFloat(document.getElementById('valor_desconto').innerHTML.replace('.','').replace(',','.'));

                //VBV
          if (s == parseFloat(1)) {
                        f = parseFloat(0);
                        }

        // atualiza valor total
        document.getElementById('total').innerHTML = numero2moeda(s + f - d);
}

function calcula_desconto_cliente()
{
        st = parseFloat(document.getElementById('total_geral').innerHTML.replace('.', '').replace(',', '.'));

        n = faixas.length;

        dd = 0;

        for (x = 0; x < n-1; x++) {
                campos = faixas[x].split(',');

                if (st >= parseFloat(campos[0]) && st < parseFloat(campos[1])) {
                        dd = campos[2];
                        break;
                }

        }

        if (document.getElementById('total')) {
                tt = parseInt(document.getElementById('total').innerHTML.replace('.','').replace(',','.') * 100);
        } else {
                tt = 0;
        }

        valor_desc = parseFloat(Math.floor(st*dd) /100);

        total_desc = parseInt(st*100 - parseInt(valor_desc * 100));

        dados_desconto = dd+'__';
        dados_desconto += valor_desc+'__';

        if (parseFloat(document.getElementById('valor_frete'))) {

                dados_desconto += parseFloat(total_desc/100) + parseFloat(document.getElementById('valor_frete').innerHTML.replace('.','').replace(',','.'));
        } else {
                dados_desconto += 0;
        }

        atualizar_desconto(dados_desconto);

}

function atualizar_desconto(dados)
{
        d = dados.split('__');

        d1 = numero2moeda(d[1]);
        d2 = numero2moeda(d[2]);

        if (document.getElementById('desconto')) {
                document.getElementById('desconto').innerHTML = d[0];
                document.getElementById('valor_desconto').innerHTML = d1;

                document.getElementById('total').innerHTML = d2;
        }

        //atualiza no carrinho

        document.getElementById('car_desconto').innerHTML = d[0];
        document.getElementById('car_valor_desconto').innerHTML = d1;

        tg = document.getElementById('total_geral').innerHTML.replace('.','').replace(',','.');
        car_t = parseFloat(tg) - parseFloat(d[1]);

        document.getElementById('car_total').innerHTML = numero2moeda(car_t);
        if (document.getElementById('total')) {
                document.getElementById('total').innerHTML = numero2moeda(car_t);
        }
}

function confirmarLimparCarrinho(url)
{
         if (confirm('Deseja excluir todos os produtos do carrinho?')) {
             window.location.href=url;
         }
}

/* mascara de numeros */

function mascara(o){

    v_obj=o
    v_fun=soNumeros;
    setTimeout("execmascara()",1);
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value);
}

function soNumeros(v){
    return v.replace(/\D/g,"");
}

/* fim mascara de numeros */

function verifica2(campo, saldo)
{
         if (campo.value > saldo) {
            campo.value = 0;
            alert('Saldo Não Suficiente para esta quantidade.');
            return 0;
         }
}

function validaNumero(campo, qtd_multipla, qtd_minima)
{
         if (campo.value == '') campo.value = 0;

         if (campo.value > 0 && campo.value < qtd_minima)
         {
             campo.value = 0;
             alert('Saldo Não Suficiente para esta quantidade.');
             return 0;
         }

         if ((resto = (campo.value % qtd_multipla)) != 0)
         {
               campo.value = parseInt(campo.value) + (parseInt(qtd_multipla) - parseInt(resto));
               alert('Quantidade desse produto deve ser múltipla de '+qtd_multipla);
               return 0;
         }
}

function alteraQtd(campo, qtd_multipla, qtd_minima, saldo) {

        campo.value = parseInt(campo.value) + parseInt(qtd_multipla);

        if (campo.value > saldo) {
            campo.value = 0;
            alert('Saldo Não Suficiente para esta quantidade.');
            return 0;
        }

        if (campo.value > 0 && campo.value < qtd_minima) {
            campo.value = (parseInt(qtd_multipla) > 0) ? qtd_minima : 0;
            return 0;
        }

        if (campo.value < 0) {
                campo.value = parseInt(0);
                return 0;
        }
}

function contabiliza_nocarrinho_aux(id, seq_progrp, seq_subprogrp, prods, grupos)
{
         contabiliza(id);

         soma  = 0;
         for (x in prods) {
              parcial = document.getElementById('total'+prods[x]).innerHTML.replace('.','').replace(',','.');
              soma += parseFloat(parcial);
         }

         document.getElementById('total_'+seq_progrp+'_'+seq_subprogrp).innerHTML = numero2moeda(soma);

         contabiliza_subtotal(grupos);
}

function contabiliza_nocarrinho(id, seq_progrp, seq_subprogrp, prods, grupos)
{

         contabiliza_nocarrinho_aux(id, seq_progrp, seq_subprogrp, prods, grupos);
         contabiliza_total();
}

function contabiliza_nocarrinho2(id, seq_progrp, seq_subprogrp, prods, grupos)
{
         contabiliza_nocarrinho_aux(id, seq_progrp, seq_subprogrp, prods, grupos);
}

function contabiliza_total()
{
         f = document.getElementById('valor_frete').innerHTML.replace('.','').replace(',','.');
         s = document.getElementById('subtotal').innerHTML.replace('.','').replace(',','.');
         d = document.getElementById('valor_desconto').innerHTML.replace('.','').replace(',','.');

         document.getElementById('total').innerHTML = numero2moeda(parseFloat(f) + parseFloat(s) - parseFloat(d));

}

function contabiliza_subtotal(grupos)
{
         soma = 0;
         for (x in grupos) {
              parcial = document.getElementById('total_'+grupos[x]).innerHTML.replace('.','').replace(',','.');
              soma += parseFloat(parcial);
         }

         document.getElementById('subtotal').innerHTML = numero2moeda(soma);
}

function contabiliza(id)
{
        preco = document.getElementById('preco'+id).innerHTML.replace('.','').replace(',','.');
        qtd = document.getElementById('qtd'+id).value;

        tot = parseFloat(preco) * parseFloat(qtd);

        js_carrinho[id] = parseFloat(tot);

        total_carrinho = 0;
        n_produtos = 0;
        // informacoes exibidas no carrinho
        for (x in js_carrinho)
        {
             total_x = js_carrinho[x];
             if (total_x != 0) {
                 total_carrinho += js_carrinho[x];
                 n_produtos++;
             }
        }

        document.getElementById('total_geral').innerHTML = numero2moeda(total_carrinho);
        document.getElementById('n_produtos').innerHTML = n_produtos;

        tot = (tot) ? numero2moeda(parseFloat(tot)) : numero2moeda(parseFloat(0));

        document.getElementById('total'+id).innerHTML = tot;

        //InserirProduto(id, qtd);
        document.getElementById('i').src = 'insere_produto_carrinho.php?dado0='+id+'&dado1='+qtd+'&dado2='+preco;
}

function numero2moeda(num) {
         num = num.toString().replace(/\$|\,/g,'');

         if(isNaN(num))
            num = "0";

         sign = (num == (num = Math.abs(num)));
         num = Math.floor(num*100+0.50000000001);
         cents = num%100;
         num = Math.floor(num/100).toString();

         if(cents<10)
            cents = "0" + cents;

         for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
             num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));

         return (((sign)?'':'-') + num + ',' + cents);
}

function LimpaCarrinhoVisivel()
{
        document.getElementById('total_geral').innerHTML = numero2moeda(0);
        document.getElementById('n_produtos').innerHTML = 0;
}

function ShowCepPopup()
{
         window.open('http://www.correios.com.br/servicos/cep/cep_loc_log.cfm');
}

function createToolTip(id, img_g)
{
         var t = new ToolTip(document.getElementById(id), "<img src="+img_g+" />", "tooltip", true);
}

/*function createToolTip(sequencias, img_grd)
{

         s = sequencias.split(',');
         img = img_grd.split(',');

         for (x in s) {
              var t = new ToolTip(document.getElementById('imagem_'+s[x]), "<img src=\""+img[x]+"\" />", "tooltip", true);
         }
}

function createToolTip_subprogrp(img_grd)
{
         var t = new ToolTip(document.getElementById('subprogrp'), "<img src=\""+img_grd+"\" />", "tooltip", true);
}

function createToolTip_subprogrp2(id, img_grd)
{
         var t = new ToolTip(document.getElementById(id), "<img src=\""+img_grd+"\" />", "tooltip", true);
} */

/*
**************************************
* Event Listener Function v1.4       *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

//<![CDATA[
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/dhtml/tooltip [v1.1]

//========================================================
// REQUIRES http://www.jsfromhell.com/geral/event-listener
//========================================================

ToolTip = function(o, t, c, f){
        var i, $ = this;
        $.s = ($.o = document.createElement("div")).style;
        $.s.display = "none", $.s.position = "absolute", $.o.className = c, $.t = t, $.f = f;
        for(i in {mouseout: 0, mouseover: 0, mousemove: 0})
                addEvent(o, i, function(e){$[e.type](e);});
};
with({p: ToolTip.prototype}){
        p.update = function(e){
                var w = window, b = document.body;
                this.s.top = e.clientY + (w.scrollY || b.scrollTop || b.parentNode.scrollTop || 0) + "px",
                this.s.left = e.clientX + (w.scrollX || b.scrollLeft || b.parentNode.scrollLeft || 0)+ "px";
        }
        p.mouseout = function(){
                this.s.display = "none";
        };
        p.mouseover = function(e){
                this.s.display = "block", document.body.appendChild(this.o).innerHTML = this.t,
                e.stopPropagation(), this.update(e);
        };
        p.mousemove = function(e){
                this.f && this.update(e);
        };
}
//]]>

function habilita_parcelas() {
         document.getElementById('box_parcelas').style.display='block';
}

function desabilita_parcelas() {
         document.getElementById('box_parcelas').style.display='none';
}