function numerosVerificar(event)
{
    var intCodigo = event.keyCode  ? event.keyCode  :
                    event.charCode ? event.charCode :
                    event.which    ? event.which    : void 0;
    
    if((intCodigo >= 48) && (intCodigo <= 57))
        return true;
    else
        return false;
}

function alterarCesta(intOrdem, intProduto)
{
    intQuantidade = document.getElementById("txtQuantidade" + intOrdem).value;
    document.location.href = "produtos_alterar.php?id=" + intProduto + "&qtd=" + intQuantidade;
}

function atualizarFrete()
{
    if(document.frmCesta.cboFrete.value == "0")
    {
        hide("sedex");
        hide("encomenda_normal");
        document.getElementById("blnProsseguir").value = "0";
        document.getElementById("objValorFrete").innerHTML = "";
        document.getElementById("objValorTotal").innerHTML = "";
    }
    else if(document.frmCesta.cboFrete.value == "1")
    {
        hide("sedex");
        show("encomenda_normal");
        document.getElementById("blnProsseguir").value = "0";
        document.getElementById("objValorFrete").innerHTML = "";
        document.getElementById("objValorTotal").innerHTML = "";
    }
    else if(document.frmCesta.cboFrete.value == "2")
    {
        hide("encomenda_normal");
        show("sedex");
        document.getElementById("blnProsseguir").value = "0";
        document.getElementById("objValorFrete").innerHTML = "";
        document.getElementById("objValorTotal").innerHTML = "";
    }
}

function calcularEncomendaNormal($strIdentificador)
{
    if(document.frmCesta.cboEncomendaNormalEstado.value == "")
    {
        alert("Selecione corretamente o Local de Entrega.");
    }
    else
    {
        xajax_calcularFreteEncomendaNormal(document.frmCesta.cboEncomendaNormalEstado.value, $strIdentificador);
    }
}

function calcularSedex($strIdentificador)
{
    if(document.frmCesta.cboSedexEstado.value == "")
    {
        alert("Selecione corretamente o Local de Entrega.");
    }
    else
    {
        xajax_calcularFreteSedex(document.frmCesta.cboSedexEstado.value, $strIdentificador);
    }
}

function frete_calculado($fltValor, $fltValorFormatado)
{
    document.getElementById("blnProsseguir").value = "1";
    document.getElementById("objValorFrete").innerHTML = "R$ " + $fltValor;
    //total_calculado($fltValorFormatado);
    total_calculado($fltValor);
}

function frete_erro(strErro)
{
    document.getElementById("blnProsseguir").value = "0";
    document.getElementById("objValorFrete").innerHTML = "";
    document.getElementById("objValorTotal").innerHTML = "";
    alert("Erro ao calcular o Frete: " + strErro + ".");
}

function showhide(id)
{
    if(document.getElementById)
    {
        obj = document.getElementById(id);
        if(obj.style.display == "none")
        {
            obj.style.display = "";
        }
        else
        {
            obj.style.display = "none";
        }
    }
}

function show(id)
{
    if(document.getElementById)
    {
        obj = document.getElementById(id);
        obj.style.display = "";
    }
}

function hide(id)
{
    if(document.getElementById)
    {
        obj = document.getElementById(id);
        obj.style.display = "none";
    }
}

function roundNumber(rnum)
{
    return Math.round(rnum*Math.pow(10,2))/Math.pow(10,2);
}

function float2moeda(num)
{
    x = 0;
    
    if(num<0)
    {
        num = Math.abs(num);
        x = 1;
    }
    
    if(isNaN(num)) num = "0";
    
    cents = Math.floor((num*100+0.5)%100);
    
    num = Math.floor((num*100+0.5)/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));
    
    ret = num + ',' + cents;
    
    if (x == 1) ret = ' - ' + ret;
    
    return ret;
}

function moeda2float(moeda)
{
    moeda = moeda.replace(".","");
    moeda = moeda.replace(",",".");
    return parseFloat(moeda);
}