// JavaScript Document
function detalheProduto(ido) {
    location.href='produto_detalhe.asp?ProdutoID=' + ido
}

function abreJanela(url) 
{
    window.open(url,"x","location=0,status=1,scrollbars=1,width=450,height=250");    
}


//Função do Menu
function Mostra(tagParaMostrar) 
{
    if (tagParaMostrar != null) 
    {
        tagParaMostrar.style.visibility = "visible";
    }
}

//Função do Menu
function Esconde(tagParaEsconder) 
{
    if (tagParaEsconder != null) 
    {
        tagParaEsconder.style.visibility = "hidden";
    }
}

function digitaTexto(obj) {
    obj.value = '';
}

function pedidoProduto(IDO, Valor) {

    var qtde = document.getElementById('Qtde_' + IDO).value;    
    //var pedido = document.getElementById('carrinho').value + '#' + IDO + '|' + qtde + '|' + Valor + '|' + Nome + '|' + Imagem;
    //document.getElementById('carrinho').value = pedido;
    //document.getElementById('pedidoform').submit();
    location.href = 'carrinho.asp?IDO=' + IDO + '&Qtde=' + qtde +'&Valor='+ Valor


}
function pedido() {
    document.getElementById('formPedido').submit();
}

function validaBusca() {
    var categoria = document.getElementById('CategoriaID').value
    var palavra = document.getElementById('Busca').value    
    if (categoria.length == 0 || palavra.length == 0) {
        alert('Preencha todos os campos (Categoria e palavra que gostria de buscar).')
        return false;            
    }
}

function validaNews() {
    var nome = document.getElementById('nome').value
    var email = document.getElementById('email').value
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(email) == false)
    {
        alert('E-mail inválido.')
        return false;
        
    }

    if (nome.length == 0 || email.length == 0) {
        alert('Preencha todos os campos (Nome e E-mail).')
        return false;
    }
}

function remove(ProdutoID) {
    location.href = 'remove.asp?ProdutoID=' + ProdutoID
}


function SomenteNumero(e) {
    var tecla = (window.event) ? event.keyCode : e.which;
    if ((tecla > 47 && tecla < 58)) return true;
    else {
        if (tecla != 8) return false;
        else return true;
    }
}


function formatar_moeda(campo, separador_milhar, separador_decimal, tecla) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

    if (whichCode == 13) return true; // Tecla Enter
    if (whichCode == 8) return true; // Tecla Delete
    key = String.fromCharCode(whichCode); // Pegando o valor digitado
    if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
    len = campo.value.length;
    for (i = 0; i < len; i++)
        if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
    aux = '';
    for (; i < len; i++)
        if (strCheck.indexOf(campo.value.charAt(i)) != -1) aux += campo.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) campo.value = '';
    if (len == 1) campo.value = '0' + separador_decimal + '0' + aux;
    if (len == 2) campo.value = '0' + separador_decimal + aux;

    if (len > 2) {
        aux2 = '';

        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += separador_milhar;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }

        campo.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            campo.value += aux2.charAt(i);
        campo.value += separador_decimal + aux.substr(len - 2, len);
    }

    return false;
}


function selecionaAll() {
    alert(document.getElementById('Para').length)

/*
    for (i = 0; i < document.getElementById('Para').length; i++)
        if (document.getElementById('Para')[i].type == "checkbox")
            document.getElementById('Para')[i].checked = 1
            */
}


function Exclui(ido, pag) {
    var resposta = confirm("Tem certeza que deseja excluir este registro?")
    if (resposta) {
        window.location = pag +'?st=1&id='+ ido
    }

}


function verificaPgto() {
    var st = document.getElementById('pgtoID').value;
    
    if (st == '1') {location.href = 'finalizapedido.asp'} 
    if (st == '2') {location.href = 'finalizapedido.asp'} 
    if (st == '3') {location.href = 'pagseguro.asp'} 
   
}


function selecionePgto(obj) {

    document.getElementById('pgtoID').value = obj.value;
}
