function isValidCreditCardNumber(cardNumber, cardType){
    alert(cardNumber);
    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 "mastercard":
                lengthIsValid = (cardNumberLength == 16);
                prefixRegExp = /^5[1-5]/;
                break;
            case "visa":
                lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
                prefixRegExp = /^4/;
                break;
            case "amex":
                lengthIsValid = (cardNumberLength == 15);
                prefixRegExp = /^3(4|7)/;
                break;
            default:
                prefixRegExp = /^$/;
                alert("Card type not found");
        }

        prefixIsValid = prefixRegExp.test(cardNumbersOnly);
        isValid = prefixIsValid && lengthIsValid;
    }
    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("Número do cartão inválido.")
        return false;
    }
}

function atualizaValorInput(id,valor) {
    $(id).value=valor;
}
function atualiza_pagina() {
    window.location.reload()
}

function liberaReceber() {
    //alert('a');
    radio_receber = document.getElementById('entrega_receber').value

    if(radio_receber == "receber") {
        //alert('b');
        for (i in document.getElementsByName("endereco_id")){
            //navego pelas chaves do array como um for
            //document.write('Campo \''+i+'\': ' + testeVar[i] + '<br>');
            alert(document.getElementsByName("endereco_id")[i].disabled);
        }

    }
}

function validaEntrega() {
    entrega = document.getElementsByName('entrega');
    cont = 1;
    if(entrega[1].checked == true) {
        cont = 0;
        enderecos = document.getElementsByName('endereco_id');
        for (i =0; i < enderecos.length; i++){
            if(document.getElementsByName("endereco_id")[i].checked) cont++;
        }
    }
    if(cont == 0) {
        alert("Escolha um endereço para entrega!");
        return false
    }
    return true
}


function validaEndereco() {
    //d = document.cadastro_endereco;
   
    if (document.getElementById("endereco_endereco").value == ""){
        alert("O campo ENDEREÇO deve ser preenchido!");
        document.getElementById("endereco_endereco").focus();
        return false;
    }
    if (document.getElementById("endereco_numero").value == ""){
        alert("O campo NÚMERO deve ser preenchido!");
        document.getElementById("endereco_numero").focus();
        return false;
    }
    if (isNaN(document.getElementById("endereco_numero").value)){
        alert("O campo NÚMERO deve conter apenas números!");
        document.getElementById("endereco_numero").focus();
        return false;
    }
    if (document.getElementById("endereco_bairro").value == ""){
        alert("O campo BAIRRO deve ser preenchido!");
        document.getElementById("endereco_bairro").focus();
        return false;
    }
    if (document.getElementById("endereco_cidade").value == ""){
        alert("O campo CIDADE deve ser preenchido!");
        document.getElementById("endereco_cidade").focus();
        return false;
    }
    if (document.getElementById("endereco_estado_id").value == ""){
        alert("O campo ESTADO deve ser preenchido!");
        document.getElementById("endereco_estado_id").focus();
        return false;
    }
    if (document.getElementById("endereco_cep").value == ""){
        alert("O campo CEP deve ser preenchido!");
        document.getElementById("endereco_cep").focus();
        return false;
    }
    if (document.getElementById("endereco_ddd").value == ""){
        alert("O campo TELEFONE deve ser preenchido!");
        document.getElementById("endereco_ddd").focus();
        return false;
    }
    if (document.getElementById("endereco_telefone").value == ""){
        alert("O campo TELEFONE deve ser preenchido!");
        document.getElementById("endereco_telefone").focus();
        return false;
    }
    //validar telefone(verificacao se contem apenas numeros)
    if (isNaN(document.getElementById("endereco_ddd").value)){
        alert("O campo TELEFONE deve conter apenas números!");
        document.getElementById("endereco_ddd").focus();
        return false;
    }
    if (isNaN(document.getElementById("endereco_telefone").value)){
        alert("O campo TELEFONE deve conter apenas números!");
        document.getElementById("endereco_telefone").focus();
        return false;
    }
    return true;
}

function validaUsuario() {
    if (document.getElementById("usuario_nome").value == ""){
        alert("O campo NOME COMPLETO deve ser preenchido!");
        document.getElementById("usuario_nome").focus();
        return false;
    }
    
    if (document.getElementById("usuario_login").value == ""){
        alert("O campo LOGIN deve ser preenchido!");
        document.getElementById("usuario_login").focus();
        return false;
    }
    if (document.getElementById("usuario_email").value == ""){
        alert("O campo EMAIL deve ser preenchido!");
        document.getElementById("usuario_email").focus();
        return false;
    }
    if (document.getElementById("usuario_cpf").value == ""){
        alert("O campo CPF deve ser preenchido!");
        document.getElementById("usuario_cpf").focus();
        return false;
    }
    if(!validaCPF('usuario_cpf')) {
        return false;
    }
    if (document.getElementById("usuario_password").value == ""){
        alert("O campo SENHA deve ser preenchido!");
        document.getElementById("usuario_nome").focus();
        return false;
    }
    if (document.getElementById("usuario_password").value.length < 4){
        alert("Sua senha deve ter no mínimo 4 caracteres!");
        document.getElementById("usuario_nome").focus();
        return false;
    }
    if (document.getElementById("usuario_password_confirmation").value == ""){
        alert("O campo CONFIRME A SENHA deve ser preenchido!");
        document.getElementById("usuario_nome").focus();
        return false;
    }
    if (document.getElementById("usuario_password_confirmation").value != document.getElementById("usuario_password").value){
        alert("As senhas digitadas não conferem!");
        document.getElementById("usuario_nome").focus();
        return false;
    }
    if (document.getElementById("usuario_data_nascimento").value == ""){
        alert("O campo DATA DE NASCIMENTO deve ser preenchido!");
        document.getElementById("usuario_cpf").focus();
        return false;
    }
    //validar data de nascimento
    erro=0;
    hoje = new Date();
    anoAtual = hoje.getFullYear();
    barras = document.getElementById("usuario_data_nascimento").value.split("/");
    if (barras.length == 3){
        dia = barras[0];
        mes = barras[1];
        ano = barras[2];
        resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
        if (!resultado) {
            alert("Formato de data invalido!");
            document.getElementById("usuario_data_nascimento").focus();
            return false;
        }
    } else {
        alert("Formato de data invalido!");
        document.getElementById("usuario_data_nascimento").focus();
        return false;
    
    }

    if(!validaEndereco()) {
        return false;
    }
}

function validaAlterarSenha() {
    if (document.getElementById("senha_antiga").value == ""){
        alert("O campo SENHA ATUAL deve ser preenchido!");
        document.getElementById("senha_antiga").focus();
        return false;
    }
    if (document.getElementById("usuario_password").value == ""){
        alert("O campo NOVA SENHA deve ser preenchido!");
        document.getElementById("usuario_password").focus();
        return false;
    }
    if ( (document.getElementById("usuario_password").value.length < 4) || (document.getElementById("usuario_password_confirmation").value.length < 4)){
        alert("Sua NOVA SENHA deve conter 4 ou mais caracteres!");
        document.getElementById("usuario_password").focus();
        return false;
    }
    if (document.getElementById("usuario_password_confirmation").value == ""){
        alert("O campo CONFIRME A SENHA deve ser preenchido!");
        document.getElementById("usuario_password_confirmation").focus();
        return false;
    }
    if ( document.getElementById("usuario_password").value != document.getElementById("usuario_password_confirmation").value){
        alert("A confirmação não bate com a nova senha digitada!");
        document.getElementById("usuario_password_confirmation").focus();
        return false;
    }
    return true;
}

function validaEdicaoUsuario() {
    if (document.getElementById("usuario_nome").value == ""){
        alert("O campo NOME COMPLETO deve ser preenchido!");
        document.getElementById("usuario_nome").focus();
        return false;
    }

    if (document.getElementById("usuario_login").value == ""){
        alert("O campo LOGIN deve ser preenchido!");
        document.getElementById("usuario_login").focus();
        return false;
    }
    if (document.getElementById("usuario_email").value == ""){
        alert("O campo EMAIL deve ser preenchido!");
        document.getElementById("usuario_email").focus();
        return false;
    }
    if (document.getElementById("usuario_cpf").value == ""){
        alert("O campo CPF deve ser preenchido!");
        document.getElementById("usuario_cpf").focus();
        return false;
    }
    if(!validaCPF('usuario_cpf')) {
        return false;
    }
    if (document.getElementById("usuario_data_nascimento").value == ""){
        alert("O campo DATA DE NASCIMENTO deve ser preenchido!");
        document.getElementById("usuario_cpf").focus();
        return false;
    }
    //validar data de nascimento
    erro=0;
    hoje = new Date();
    anoAtual = hoje.getFullYear();
    barras = document.getElementById("usuario_data_nascimento").value.split("/");
    if (barras.length == 3){
        dia = barras[0];
        mes = barras[1];
        ano = barras[2];
        resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
        if (!resultado) {
            alert("Formato de data invalido!");
            document.getElementById("usuario_data_nascimento").focus();
            return false;
        }
    } else {
        alert("Formato de data invalido!");
        document.getElementById("usuario_data_nascimento").focus();
        return false;
    }
}
//no ar sem funfar
function atualiza_quantidade() {
    var tab_precos = document.getElementById("tab_precos");
    if(tab_precos) {
        total = 0;
        linhasIngresso = tab_precos.rows;
        for(var i=0; i < linhasIngresso.length; i++){
            if(linhasIngresso[i].className == 'ingresso') {
                var quantidade = linhasIngresso[i].getElementsByTagName('td')[2].childNodes[0].selectedIndex;
                //var valor = parseFloat(linhasIngresso[i].getElementsByTagName('td')[2].innerHTML.replace('R$ ', ''));
                var valor = parseFloat(linhasIngresso[i].getElementsByTagName('td')[3].innerHTML.replace('R$ ','').replace(',','.'));
                var conveniencia = parseFloat(linhasIngresso[i].getElementsByTagName('td')[4].innerHTML.replace('R$ ','').replace(',','.'));
                //alert (valor);
                //alert (conveniencia);
                var subtotal = linhasIngresso[i].getElementsByTagName('td')[5];
                valor = (quantidade * (valor + conveniencia));
                //valor = quantidade * valor;
                subtotal.innerHTML = ("R$" + valor.toFixed(2)).replace('.',',');
                //subtotal.innerHTML = ("R$" + valor.toFixed(2));
                total += valor
            }
        }
        document.getElementById("valor_total_de_tudo").innerHTML = ("R$ " + total.toFixed(2)).replace('.',',');
    //document.all.valor_total_de_tudo.innerHTML = ("R$ " + total.toFixed(2));
    }
}
//	  var primeira = false;
  
var valorTroca = "";
var textTroca = "";	
var nameTroca = "";	
  
function atual(listaAtual){
    nameTroca = listaAtual.name;
    valorTroca = listaAtual.value;
    textTroca = listaAtual.options[listaAtual.selectedIndex].text;
}
  
function excluiTodas(listaAtual){
    valorAtual = listaAtual.value;
    textAtual = listaAtual.options[listaAtual.selectedIndex].text;
    
    for ( i =0; i < document.forms[1].elements.length; i++) {	
        listaProxima = document.forms[1].elements[i];
        if(listaAtual.name != document.forms[1].elements[i].name && document.forms[1].elements[i].lugar =="true" ){
            exclui(valorAtual , listaProxima);
        }
        if( nameTroca != listaProxima.name && valorTroca != "selecione" && document.forms[1].elements[i].lugar =="true"){
            incluir( valorTroca , textTroca, listaProxima);	
        }
    }
    primeira = true;
}
  
function exclui(valorAtual , listaProxima){
    
    for ( y =0; y < listaProxima.length; y++) {
      
        if ( valorAtual == listaProxima.options[y].value  && valorAtual !="selecione"){
            listaProxima.remove(y);
        }					
    }
}
  
function incluir(valorAtual , textAtual , listaProximo ){
    listaProximo.options[listaProximo.length] = new Option( textAtual, valorAtual, false, false);
}
function mascaraData(campoData){
    var data = campoData.value;
    if (data.length == 2){
        data = data + '/';
        campoData.value = data;
        return true;              
    }
    if (data.length == 5){
        data = data + '/';
        campoData.value = data;
        return true;
    }
}

function mascaraMesAno(campoData){
    var data = campoData.value;
    if (data.length == 2){
        data = data + '/';
        campoData.value = data;
        return true;              
    }
    if (data.length == 7){
        //data = data + '/';
        campoData.value = data;
        return true;
    }
}


function moedaMask(formatar, correcao){
    var valorFormatar = new String(formatar);
    pontos = valorFormatar.length / 3 + 1;
    for(a=0; a < pontos; a++){
        valorFormatar = valorFormatar.replace(",","");
        valorFormatar = valorFormatar.replace(".","");
    }
    if( valorFormatar.length < 15 ){
        var valorFormatado ="";
        if ( isNaN(correcao) ){
            correcao = 0
        };
        if ( !isNaN(valorFormatar) ){
            var virgula = valorFormatar.length - 2 - correcao;
            for (j =0; j < valorFormatar.length; j++){
                if(j == virgula){
                    valorFormatado += "," + valorFormatar.charAt(j);
                }else{
                    if(j == virgula-4 || j == virgula-7 || j == virgula-10 || j == virgula-13){
                        valorFormatado +=  valorFormatar.charAt(j) + ".";
                    }else{
                        valorFormatado += valorFormatar.charAt(j);
                    }//else
                }//else
            }//for
            if ( valorFormatado.charAt(0) == ","){
                valorFormatado = "0" + valorFormatado;
            }
            if ( valorFormatado.charAt(0) == "0"){
                if ( valorFormatado.charAt(1) != ","){
                    valorFormatado = valorFormatado.substr(1);
                }
            }
            return(valorFormatado);
        }
    }//if tamanho do número for menor que 13 algarismos}//moedaMask(valo, casas_decimais);
}//formatar o valor como moeda

function formataMoeda(campo, decimal){
    var valor = campo.value;
    //eval("valor = new String(document.form1." + campo + ".value)");
    var aux2 = moedaMask(valor, decimal);
    if ( aux2 != null ){
        //eval( "document.form1." + campo + ".value = aux2" );
        campo.value = aux2;
    }
    return aux2;
}//formatar um campo

//Esta função substitui vírgula por ponto usado geralmente quando nas funções que montam "Strings" e etc.
function preparaValor (valor){
    var aux ="";
    if (valor.length<=2){
        valor = valor + ",00"
    }
    for (var i=0; i<valor.length; i++){
        if(valor.charAt(i)== ','){
            aux += '.';
        }else{
            if(valor.charAt(i)!= '.'){
                aux += valor.charAt(i);
            }//if
        }//else
    }//for
    return aux;
}//preparaValor






function ordena_por(url, campo) {
    parametros = Form.serialize('filtro_form');
    destino = url + "?ordena=" + campo + "&" + parametros ;
    window.open(destino, '_self');
}

function formatamoney(c) {
    var t = this; if(c == undefined) c = 2;		
    var p, d = (t=t.split("."))[1].substr(0, c);
    for(p = (t=t[0]).length; (p-=3) >= 1;) {
        t = t.substr(0,p) + "." + t.substr(p);
    }
    return t+","+d+Array(c+1-d.length).join(0);
}

String.prototype.formatCurrency=formatamoney

function demaskvalue(valor, currency){
    /*
     * Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as 
     * casas decimais
     */
    var val2 = '';
    var strCheck = '0123456789';
    var len = valor.length;
    if (len== 0){
        return 0.00;
    }

    if (currency ==true){	
        /* Elimina os zeros à esquerda 
         * a variável  <i> passa a ser a localização do primeiro caractere após os zeros e 
         * val2 contém os caracteres (descontando os zeros à esquerda)
         */
		
        for(var i = 0; i < len; i++)
            if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break;
		
        for(; i < len; i++){
            if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i);
        }

        if(val2.length==0) return "0.00";
        if (val2.length==1)return "0.0" + val2;
        if (val2.length==2)return "0." + val2;
		
        var parte1 = val2.substring(0,val2.length-2);
        var parte2 = val2.substring(val2.length-2);
        var returnvalue = parte1 + "." + parte2;
        return returnvalue;
		
    }
    else{
        /* currency é false: retornamos os valores COM os zeros à esquerda, 
         * sem considerar os últimos 2 algarismos como casas decimais 
         */
        val3 ="";
        for(var k=0; k < len; k++){
            if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k);
        }			
        return val3;
    }
}

function reais(obj,event){

    var whichCode = (window.Event) ? event.which : event.keyCode;
    /*
Executa a formatação após o backspace nos navegadores !document.all
     */
    if (whichCode == 8 && !document.all) {	
        /*
Previne a ação padrão nos navegadores
         */
        if (event.preventDefault){ //standart browsers
            event.preventDefault();
        }else{ // internet explorer
            event.returnValue = false;
        }
        var valor = obj.value;
        var x = valor.substring(0,valor.length-1);
        obj.value= demaskvalue(x,true).formatCurrency();
        return false;
    }
    /*
Executa o Formata Reais e faz o format currency novamente após o backspace
     */
    FormataReais(obj,'.',',',event);
} // end reais


function backspace(obj,event){
    /*
Essa função basicamente altera o  backspace nos input com máscara reais para os navegadores IE e opera.
O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown.
Como o opera suporta o infame document.all, tratamos dele na mesma parte do código.
     */

    var whichCode = (window.Event) ? event.which : event.keyCode;
    if (whichCode == 8 && document.all) {	
        var valor = obj.value;
        var x = valor.substring(0,valor.length-1);
        var y = demaskvalue(x,true).formatCurrency();

        obj.value =""; //necessário para o opera
        obj.value += y;
	
        if (event.preventDefault){ //standart browsers
            event.preventDefault();
        }else{ // internet explorer
            event.returnValue = false;
        }
        return false;

    }// end if		
}// end backspace

function FormataReais(fld, milSep, decSep, e) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;

    //if (whichCode == 8 ) return true; //backspace - estamos tratando disso em outra função no keydown
    if (whichCode == 0 ) return true;
    if (whichCode == 9 ) return true; //tecla tab
    if (whichCode == 13) return true; //tecla enter
    if (whichCode == 16) return true; //shift internet explorer
    if (whichCode == 17) return true; //control no internet explorer
    if (whichCode == 27 ) return true; //tecla esc
    if (whichCode == 34 ) return true; //tecla end
    if (whichCode == 35 ) return true;//tecla end
    if (whichCode == 36 ) return true; //tecla home

    /*
O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script
     */

    if (e.preventDefault){ //standart browsers
        e.preventDefault()
    }else{ // internet explorer
        e.returnValue = false
    }

    var key = String.fromCharCode(whichCode);  // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false;  // Chave inválida

    /*
Concatenamos ao value o keycode de key, se esse for um número
     */
    fld.value += key;

    var len = fld.value.length;
    var bodeaux = demaskvalue(fld.value,true).formatCurrency();
    fld.value=bodeaux;

    /*
Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror.
     */
    if (fld.createTextRange) {
        var range = fld.createTextRange();
        range.collapse(false);
        range.select();
    }
    else if (fld.setSelectionRange) {
        fld.focus();
        var length = fld.value.length;
        fld.setSelectionRange(length, length);
    }
    return false;
}

var retorno;
var mpg_popup;
window.name="loja";
function fabrewin(){
    if(navigator.appName.indexOf("Netscape") != -1)
        mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
    else
        mpg_popup = window.open("", "mpg_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 true;
}

function tipoPagamento() {
    if(document.getElementById('parcelas').value == -1){
        document.getElementById('bt_finalizar').disabled=false
        alert("Selecione uma meio de pagamento.");
        return false;
    }
    else {
        return true;
    }
}

function tipoIngresso(){
    if( (document.getElementById('valor_total_de_tudo').innerHTML == "R$ 0,00") || (document.getElementById('valor_total_de_tudo').innerHTML == "")){
        alert("Nenhum ingresso selecionado.")
        return false;
    }
    else {
        return true;
    }
  
}

function relatorioDetalhado(){
    if(document.getElementById("resumido_false").checked){
        if( (document.getElementById("de_data").value.length <= 0) || (document.getElementById("ate_data").value.length <= 0) ){
            alert("preencha as datas!");
            return false;
        }
    }
}

function validaCPF(obj){
    var cpf = document.getElementById(obj).value;
    var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
    if(!filtro.test(cpf)){
        window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    cpf = remove(cpf, ".");
    cpf = remove(cpf, "-");
    if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
        cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
        cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
        cpf == "88888888888" || cpf == "99999999999"){
        window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    soma = 0;
    for(i = 0; i < 9; i++)
        soma += parseInt(cpf.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
        resto = 0;
    if(resto != parseInt(cpf.charAt(9))){
        window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    soma = 0;
    for(i = 0; i < 10; i ++)
        soma += parseInt(cpf.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if(resto == 10 || resto == 11)
        resto = 0;
    if(resto != parseInt(cpf.charAt(10))){
        window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    return true;
}

function remove(str, sub) {
    i = str.indexOf(sub);
    r = "";
    if (i == -1) return str;
    r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
    return r;
}


function mascaraCPF(){
    var cpf = document.getElementById("usuario_cpf").value;
    if (cpf.length == 3){
        cpf = cpf + '.';
        document.getElementById("usuario_cpf").value = cpf;
        return true;              
    }
    if (cpf.length == 7){
        cpf = cpf + '.';
        document.getElementById("usuario_cpf").value = cpf;
        return true;
    }
    if (cpf.length == 11){
        cpf = cpf + '-';
        document.getElementById("usuario_cpf").value = cpf;
        return true;
    }
}

function mascaraCpfRecebedor(){
    var cpf = document.getElementById("recebedor_cpf").value;
    if (cpf.length == 3){
        cpf = cpf + '.';
        document.getElementById("recebedor_cpf").value = cpf;
        return true;
    }
    if (cpf.length == 7){
        cpf = cpf + '.';
        document.getElementById("recebedor_cpf").value = cpf;
        return true;
    }
    if (cpf.length == 11){
        cpf = cpf + '-';
        document.getElementById("recebedor_cpf").value = cpf;
        return true;
    }
}


function mascaraCEP(){
    var cep = document.getElementById("usuario_cep").value;
    if (cep.length == 5){
        cep = cep + '-';
        document.getElementById("usuario_cep").value = cep;
        return true;              
    } 
}

function mascaraCEPEndereco(){
    var cep = document.getElementById("endereco_cep").value;
    if (cep.length == 5){
        cep = cep + '-';
        document.getElementById("endereco_cep").value = cep;
        return true;
    }
}

function validaData(){
    if( (document.getElementById("de_data").value.length < 7) || (document.getElementById("ate_data").value.length < 7) ){
        alert("Data inválida, digite conforme o exemplo: 04/2008");
        return false;
    }
}