var SITE = 'http://www.expoentec.edu.br';

function rodaEvento(cont, total){
	
	var	cont = parseInt(cont);	
	var total = total;
	
		
    if (cont < total) {
        $('#player-correr').animate({
            "marginLeft": "-=448px"
        }, "slow");
        
    }
	
	if (cont == total) {
		
		$('#player-correr').animate({
            "marginLeft": "0px"
        }, "slow");
		cont = 0;		
	}
	
    cont++;
    destaque = setTimeout('rodaEvento(' + cont + ',' + total + ');', 2000);
}


$(function(){

    ///////////////////////////////////////////////////////////////////////
    //// Carrocel fotos Eventos Destaque
    total = $('#player-correr .img').size();
    cont = 1;
    
    
    if (total > 1) {
    	setTimeout('rodaEvento(' + cont + ',' + total + ');', 2000);
    }
    
	
    
    $('#avancar').click(function(event){	
		
        if (cont < total) {
            $('#player-correr').animate({
                "marginLeft": "-=448px"
            }, "slow");
            cont++;
        }
    });
    
    
    $('#voltar').click(function(event){		
	
        if (cont != 1) {
            $('#player-correr').animate({
                "marginLeft": "+=448px"
            }, "slow");
            cont--;
        }
    });
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Enviar o Formulario de ouvidoria 
    $('#bt-enviar-newsletter').click(function(event){
    
    
        error = false;
        
        // valida Nome
        if ($('#new-nome').val() == "" || $('#new-nome').val() == "Seu Nome") {
            $('.new-nome').text('Preencha o campo Nome');
            error = true;
        }
        else {
            $('.new-nome').text('');
        }
        
        
        
        // Valida Email
        if ($('#new-email').val() == "" || $('#new-email').val() == "E-mail") {
        
            $('.new-email').text('Preencha o campo E-mail');
            error = true;
        }
        else {
        
            $('.new-email').text('');
            
            if (validaEmail($('#new-email').val()) == false) {
                $('.new-email').text('Preencha o campo E-mail corretamente, e-mail inválido');
                error = true;
            }
        }
        
        
        
        
        if (error == true) {
            return false;
        }
        else {
            dados = $('#form-newsletter').serialize();
            
            $('#carregando2').show();
            $('#form-newsletter fieldset').hide();
            
            
            $.ajax({
                header: {
                    "Content-Type": "text/html;  charset=ISO-8859-1"
                },
                type: "get",
                data: "acao=newsletter&" + dados,
                url: "http://www.expoentec.edu.br/ajax.php",
                dataType: "json",
                success: function(valor){
                    $('#carregando2').html('<p>Cadastro efetuado com successo,Obrigado.<br /> <a href="#" class="mostra-form" title="Mostra formulário">Mostra formulário</a></p>');
                    
                    
                    if (valor.mensagem == "true") {
                        $('#new-nome').val('Seu Nome');
                        $('#new-email').val('E-mail');
                    }
                    else {
                        alert('error');
                        $('#carregando2').html('<p>' + valor.valor + '.<br /> <a href="#" class="mostra-form" title="Mostra formulário">Mostra formulário</a></p>');
                    }
                    
                    $('.mostra-form').live('click', function(event){
                        $('#form-newsletter fieldset').show();
                        $('#carregando2').hide();
                        $('#carregando2').html('<img src="http://www.expoentec.edu.br/template/img/carregando.gif" alt="carregando" />');
                        
                        event.preventDefault(event);
                        return false;
                    });
                    
                    
                    event.preventDefault(event);
                    return false;
                }
            });
        }
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Enviar o Formulario de ouvidoria 
    $('#bt-enviar-interesse').click(function(event){
    
    
        error = false;
        
        // valida Nome
        if ($('#nome').val() == "" || $('#nome').val() == "Insira seu nome (Obrigatório)") {
            $('#nome').parents('.campo').children('.avisso').text('Preencha o campo Nome');
            error = true;
        }
        else {
            $('#nome').parents('.campo').children('.avisso').text('');
        }
        
        
        
        // Valida Email
        if ($('#email').val() == "" || $('#email').val() == "Insira seu e-mail (Obrigatório)") {
        
            $('#email').parents('.campo').children('.avisso').text('Preencha o campo E-mail');
            error = true;
        }
        else {
        
            $('#email').parents('.campo').children('.avisso').text('');
            
            if (validaEmail($('#email').val()) == false) {
                $('#email').parents('.campo').children('.avisso').text('Preencha o campo E-mail corretamente, e-mail inválido');
                error = true;
            }
        }
        
        
        
        
        // valida Assunto
        if ($('#telefone').val() == "" || $('#telefone').val() == "Insira seu telefone (Obrigatório)") {
            $('#telefone').parents('.campo').children('.avisso').text('Insira seu telefone (Obrigatório)');
            error = true;
        }
        else {
            $('#telefone').parents('.campo').children('.avisso').text('');
        }
        
        
        
        
        
        // Valida Comentario		
        if ($('#endereco').val() == "" || $('#endereco').val() == "Insira seu endereço (Obrigatório)") {
            $('#endereco').parents('.campo').children('.avisso').text('Preencha o campo Mensagem');
            error = true;
        }
        else {
            $('#endereco').parents('.campo').children('.avisso').text('');
        }
        
        
        if (error == true) {
            return false;
        }
        else {
            dados = $('#form-comentario').serialize();
            
            $('#carregando').show();
            $('#form-comentario fieldset').hide();
            
            
            $.ajax({
                header: {
                    "Content-Type": "text/html;  charset=ISO-8859-1"
                },
                type: "get",
                data: "acao=interesse&" + dados,
                url: "http://www.expoentec.edu.br/ajax.php",
                dataType: "json",
                success: function(valor){
                    $('#carregando').html('<p class="titulo">Mensagem enviada com successo,Obrigado.<br /> <a href="#" class="mostra-form" title="Mostra formulário">Mostra formulário</a></p>');
                    
                    
                    if (valor.mensagem == "true") {
                        $('#nome').val('Insira seu nome (Obrigatório)');
                        $('#email').val('Insira seu e-mail (Obrigatório)');
                        $('#telefone').val('Insira seu telefone (Obrigatório)');
                        $('#endereco').val('Insira seu endereço (Obrigatório');
                    }
                    
                    $('.mostra-form').live('click', function(event){
                        $('#form-comentario fieldset').show();
                        $('#carregando').hide();
                        $('#carregando').html('<img src="http://www.expoentec.edu.br/template/img/carregando.gif" alt="carregando" />');
                        
                        event.preventDefault(event);
                        return false;
                    });
                    
                    
                    event.preventDefault(event);
                    return false;
                }
            });
        }
        event.preventDefault(event);
        return false;
    });
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Limpa os campos
    // Campos do formulario de contato
    $('.campo-input,#comentario,#txt-busca,#new-email,#new-nome,#pesquisa').focus(function(event){
        valorAntigo = $(this).attr('value');
        
        if (valorAntigo == "Insira seu endereço (Obrigatório)" || valorAntigo == "Insira seu telefone (Obrigatório)" || valorAntigo == "Digite aqui o que deseja pesquisar" || valorAntigo == "E-mail" || valorAntigo == "Seu Nome" || valorAntigo == "Digite o que deseja pesquisar" || valorAntigo == 'Deixe sua mensagem' || valorAntigo == "Insira seu nome (Obrigatório)" || valorAntigo == "Insira seu e-mail (Obrigatório)" || valorAntigo == "Deixe seu comentário" || valorAntigo == 'Insira o assunto da mensagem (Obrigatório)') {
            $(this).attr('value', '');
        }
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            $(this).attr('value', valorAntigo);
        }
        
    });
	
	 $('#op-senha').focus(function(event){
        valorAntigo = $(this).attr('value');
        
      
            $(this).attr('value', '');
      
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            $(this).attr('value', valorAntigo);
        }
        
    });
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Enviar o Formulario de ouvidoria 
    $('#bt-enviar-ouvidoria').click(function(event){
    
    
        error = false;
        
        // valida Nome
        if ($('#nome').val() == "" || $('#nome').val() == "Insira seu nome (Obrigatório)") {
            $('#nome').parents('.campo').children('.avisso').text('Preencha o campo Nome');
            error = true;
        }
        else {
            $('#nome').parents('.campo').children('.avisso').text('');
        }
        
        
        
        // Valida Email
        if ($('#email').val() == "" || $('#email').val() == "Insira seu e-mail (Obrigatório)") {
        
            $('#email').parents('.campo').children('.avisso').text('Preencha o campo E-mail');
            error = true;
        }
        else {
        
            $('#email').parents('.campo').children('.avisso').text('');
            
            if (validaEmail($('#email').val()) == false) {
                $('#email').parents('.campo').children('.avisso').text('Preencha o campo E-mail corretamente, e-mail inválido');
                error = true;
            }
        }
        
        
        
        
        // valida Assunto
        if ($('#assunto').val() == "" || $('#assunto').val() == "Insira o assunto da mensagem (Obrigatório)") {
            $('#assunto').parents('.campo').children('.avisso').text('Preencha o campo Assunto');
            error = true;
        }
        else {
            $('#nome').parents('.campo').children('.avisso').text('');
        }
        
        
        
        
        
        // Valida Comentario		
        if ($('#comentario').val() == "" || $('#comentario').val() == "Deixe sua mensagem") {
            $('#comentario').parents('.campo').children('.avisso').text('Preencha o campo Mensagem');
            error = true;
        }
        else {
            $('#comentario').parents('.campo').children('.avisso').text('');
        }
        
        
        if (error == true) {
            return false;
        }
        else {
            dados = $('#form-comentario').serialize();
            
            $('#carregando').show();
            $('#form-comentario fieldset').hide();
            
            
            $.ajax({
                header: {
                    "Content-Type": "text/html;  charset=ISO-8859-1"
                },
                type: "get",
                data: "acao=mensagem&" + dados,
                url: "http://www.expoentec.edu.br/ajax.php",
                dataType: "json",
                success: function(valor){
                    $('#carregando').html('<p class="titulo">Mensagem enviada com successo,Obrigado.<br /> <a href="#" class="mostra-form" title="Mostra formulário">Mostra formulário</a></p>');
                    
                    
                    if (valor.mensagem == "true") {
                        $('#nome').val('Insira seu nome (Obrigatório)');
                        $('#email').val('Insira seu e-mail (Obrigatório)');
                        $('#assunto').val('Insira o assunto da mensagem (Obrigatório)');
                        $('#comentario').val('Deixe sua mesagem');
                    }
                    
                    $('.mostra-form').live('click', function(event){
                        $('#form-comentario fieldset').show();
                        $('#carregando').hide();
                        $('#carregando').html('<img src="http://www.expoentec.edu.br/template/img/carregando.gif" alt="carregando" />');
                        
                        event.preventDefault(event);
                        return false;
                    });
                    
                    
                    event.preventDefault(event);
                    return false;
                }
            });
        }
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    
    
    
    
    
    
    // botao do calendario	
    $(' #anterior').live('click', function(event){
        $('#cotainer').hide();
        $('#loading').show();
        
        $.ajax({
            header: {
                "Content-Type": "text/html;  charset=ISO-8859-1"
            },
            type: "get",
            data: "acao=anterior",
            url: SITE + "/ajax.php",
            dataType: 'html',
            success: function(valor){
            
                $('#cotainer').html(valor);
                $('#cotainer').show();
                $('#loading').hide();
                return true;
            }
        });
        
        event.preventDefault(event);
        return false;
    });
    
    $('#proximo').live('click', function(event){
        $('#cotainer').hide();
        $('#loading').show();
        $.ajax({
            header: {
                "Content-Type": "text/html;  charset=ISO-8859-1"
            },
            type: "get",
            data: "acao=proximo",
            url: SITE + "/ajax.php",
            dataType: 'html',
            success: function(valor){
            
                $('#cotainer').html(valor);
                $('#cotainer').show();
                $('#loading').hide();
                return true;
            }
        });
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    // Menu Lateral
    $('.menu-item').click(function(event){
        $(this).parents('li').children('.submenu').slideToggle();
        event.preventDefault(event);
    });
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////
    // Houver dos botoes de aumentar o texto
    $('.letra-menor,.letra-maior').mouseover(function(){
        $(this).css({
            'color': '#ffffff',
            'border-color': '#074590',
            'background-color': '#074590'
        });
    }).mouseout(function(){
        $(this).css({
            'color': '#074590',
            'border-color': '#cccccc',
            'background-color': '#FFFFFF'
        });
    })
    
    
    $('.letra-menor').click(function(){
        tamanhoFonte = $('#descricao').css('font-size');
        tamanhoFonte = parseInt(tamanhoFonte);
        
        if (tamanhoFonte > 10) {
            $('#descricao').css('font-size', tamanhoFonte - 2 + 'px');
        }
        
    });
    
    $('.letra-maior').click(function(){
        tamanhoFonte = $('#descricao').css('font-size');
        tamanhoFonte = parseInt(tamanhoFonte);
        
        if (tamanhoFonte < 20) {
            $('#descricao').css('font-size', tamanhoFonte + 2 + 'px');
        }
        
    });
    
    
    
    
    
    
    
    
    
    function validaEmail(mail){
        var er = RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if (er.test(mail) == false) {
            return false;
        }
        
        return true;
    }
    
    
    
    
    
    /////////////////////////////////////////////////////////////////////////////////
    // Target Blanck
    $('.externo').attr('target', '_blanck');
    
    /////////////////////////////////////////////////////////////////////////////////
    // Colorbox das galerias	
    $('a[rel="popup"]').colorbox({
        slideshow: true
    });
    
    $('a.single').colorbox({});
    
    
    
    /*	
     // Rotacao Banner Rodape 170x70
     if ($('.pub-5').size() > 0) {
     setTimeout('rotacionarBanner ("pub-5","b5",500);',2000);
     }
     */
});



/**
 * Rotação do banner
 */
function rotacionarBanner(classe, bt, tempo){

    // Total de banner
    total = $('.' + classe).size() + 1;
    
    // Pegar o id do Banner Atual 
    atual = $('.' + classe + '-hover').attr('id');
    atual = atual.replace(bt + '-', '');
    
    if (atual != total) {
        $('#' + bt + '-' + atual).attr('class', classe).next().attr('class', classe + '-hover');
    }
    else {
        $('#' + bt + '-' + atual).attr('class', classe);
        $('#' + bt + '-1').attr('class', classe + '-hover');
    }
    
    tempoBannerTopoMaior = setTimeout('rotacionarBanner ("' + classe + '","' + bt + '",' + tempo + ');', tempo);
}


/****************************\
 FUNCAO QUE CRIA O OBJETO AJAX
 \****************************/
function criarAjax(){
    var ajax;
    try {
        ajax = new XMLHttpRequest();
    } 
    catch (ee) {
        try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (E) {
                ajax = false;
            }
        }
    }
    
    
    
    return ajax;
}


//Tenta criar o objeto xmlHTTP

try {

    xmlhttp = new XMLHttpRequest();
    
} 
catch (ee) {

    try {
    
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        
    } 
    catch (e) {
    
        try {
        
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            
        } 
        catch (E) {
        
            xmlhttp = false;
            
        }
        
    }
    
}



function enviar_enquete(){



    var pergunta = document.getElementById('votacao').cod_pergunta.value;
    
    
    
    //O voto. Cria uma variÃ¡vel como a opÃ§Ã£o escolhida.
    if (document.getElementById('votacao').escolha1.checked) 
        var voto = 0;
    else 
        if (document.getElementById('votacao').escolha2.checked) 
            var voto = 1;
        else 
            if (document.getElementById('votacao').escolha3.checked) 
                var voto = 2;
            else 
                if (document.getElementById('votacao').escolha4.checked) 
                    var voto = 3;
                else 
                    var voto = "";
    
    if ((voto != 0) && (voto != 1) && (voto != 2) && (voto != 3)) {
        alert("Escolha uma opção para poder votar!")
    }
    else {
        //Abre a conexÃ£o
        xmlhttp.open("GET", "http://www.expoentec.edu.br/votar.php?voto=" + voto + "&per=" + pergunta, true);
        
        //FunÃ§Ã£o para tratamento do retorno
        xmlhttp.onreadystatechange = function(){
        
            if (xmlhttp.readyState == 4) {
            
                //Mostra mensagem
                var mensagem = xmlhttp.responseText;
                mensagem = mensagem.replace(/\+/g, " ");
                mensagem = unescape(mensagem);
                document.getElementById('votacao').innerHTML = mensagem;
            }
        }
        
        //Executa
        xmlhttp.send(null)
    }
    
    return false;
    
    
}

/**
 * Player da Index
 */
function playerIndex(item){

    // Reinalizo o item	
    if (item > $('#player-opcoes li').size()) {
        item = 1;
    }
    
    if (item != 1) {
        // Esconder todas as imagens e mostro a proxima
        $('#player-img').animate({
            "marginLeft": "-=273px"
        }, "slow");
        $('.player-menu').removeClass('hover');
        $('#player-menu-' + item).addClass('hover');
    }
    else {
        $('#player-img').animate({
            "marginLeft": "0px"
        }, "slow");
        $('.player-menu').removeClass('hover');
        $('#player-menu-' + item).addClass('hover');
    }
    
    item++;
    
    
    tempoPlayerIndex = setTimeout('playerIndex (' + item + ');', 8000);
}

/**
 * Botao Anterior
 */
function playerAnterior(){
    atual = $('.player-menu.hover').attr('id');
    atual = atual.replace('player-menu-', '');
    
    if (atual > 1) {
        atual = atual - 1;
        
        clearInterval(tempoPlayerIndex);
        $('#player-img').animate({
            "marginLeft": "+=273px"
        }, "slow");
        $('.player-menu').removeClass('hover');
        $('#player-menu-' + atual).addClass('hover');
        
        atual++;
        tempoPlayerIndex = setTimeout('playerIndex (' + atual + ');', 8000);
    }
    
    return false;
}

/**
 * Botao Proxima
 */
function playerProxima(){
    atual = $('.player-menu.hover').attr('id');
    atual = atual.replace('player-menu-', '');
    
    if (atual < $('#player-opcoes li').size()) {
        atual = parseInt(atual);
        atual++;
        
        clearInterval(tempoPlayerIndex);
        $('#player-img').animate({
            "marginLeft": "-=273px"
        }, "slow");
        $('.player-menu').removeClass('hover');
        $('#player-menu-' + atual).addClass('hover');
        
        atual++;
        tempoPlayerIndex = setTimeout('playerIndex (' + atual + ');', 8000);
    }
    
    return false;
}

/**
 * PLayer Item
 */
function playerItem(){

    //Paro o player
    clearInterval(tempoPlayerIndex);
    
    //Elemento Atual
    atual = $('.player-menu.hover').attr('id');
    atual = atual.replace('player-menu-', '');
    
    //Elemento do Click
    click = $(this).attr('id');
    click = click.replace('player-menu-', '');
    
    // Coloco o item como Hover
    $('.player-menu').removeClass('hover');
    $('#player-menu-' + click).addClass('hover');
    
    // Caso click maior que o atual vai pra frente se naum para traz
    if (click > atual) {
    
        diferenca = click - atual;
        mover = diferenca * 273;
        $('#player-img').animate({
            "marginLeft": "-=" + mover + "px"
        }, "slow");
        
        click++;
        
        tempoPlayerIndex = setTimeout('playerIndex (' + click + ');', 8000);
    }
    else {
    
        diferenca = atual - click;
        mover = diferenca * 273;
        $('#player-img').animate({
            "marginLeft": "+=" + mover + "px"
        }, "slow");
        
        click++;
        tempoPlayerIndex = setTimeout('playerIndex (' + click + ');', 8000);
    }
    
}

function mascaras(valor, id, mascara, evento){
    /////////////////////////////////////////////////////////////////////////////////
    //                             MODELO  DE MÁSCARA                              //
    //onkeyup="mascaras(this.value, this.id, '####.##.##.#######-#/#', event)"//
    /////////////////////////////////////////////////////////////////////////////////
    
    /////////////////////////////////////////////////////////////////////////////////
    //                         MODELO  DE MÁSCARA MONETÁRIA                        //
    //onkeyup="mascaraHellas(this.value, this.id, 'money', event)"                 //
    /////////////////////////////////////////////////////////////////////////////////
    
    
    //inicializa a variavel que vai conter o valor final
    var valorFinal = "";
    
    //verifica o que foi digitada para que seja verificado se é somente números ou não
    var tecla = evento.keyCode;
    
    //manetem o tamanho original do campo sem retirar a máscara
    var valorOriginal = valor;
    
    //inicializa um array com todos os caracteres que serão retirado
    var arrNaoPermitidos = new Array("-", ".", "/", "\\", "|", "(", ")", ":", " ", ",");
    
    //retira qualquer máscatra que já tenho sido colocada
    for (i1 = 0; i1 < valor.length; i1++) {
        for (i2 = 0; i2 < arrNaoPermitidos.length; i2++) {
            if (valor.charAt(i1) == arrNaoPermitidos[i2]) {
                valor = valor.toString().replace(arrNaoPermitidos[i2], "");
            }
        }
    }
    
    //merifica se a máscara é mometária ou uma máscara fixa
    if (mascara == "money") {
        //retira os zeros da frente do valor
        var temZero = true;
        while (temZero == true) {
            if (valor.substring(0, 1) == "0") {
                valor = valor.substring(1, valor.length);
            }
            else {
                temZero = false;
            }
        }
        
        //verifica se foi precionado o backspae
        if (tecla == 8) {
            valor = valor.substring(0, valor.length);
        }
        
        //faz as verificações para a formatação do valor
        if (valor.length == 1) {
            valorFinal = "0,0" + valor;
        }
        else 
            if (valor.length == 2) {
                valorFinal = "0," + valor;
            }
            else 
                if (valor.length == 4 && valor.substr(0, 2) == "00") {
                    valorFinal = "0," + valor.substr(2);
                }
                else 
                    if (valor.length == 4 && valor.substr(0, 1) == "0" && valor.substr(0, 2) != "00") {
                        valorFinal = valor.substr(1, 1) + "," + valor.substr(2);
                    }
                    else 
                        if (valor.length >= 4 || valor.length == 3) {
                            var parteInteira = valor.substr(0, (valor.length - 2));
                            var parteDecimal = valor.substr((valor.length - 2))
                            var inteiro = "";
                            var cont = 1;
                            var milhar = "";
                            
                            for (i = parteInteira.length; i > 0; i--) {
                                if (cont == 4) {
                                    milhar = ".";
                                    cont = 2;
                                }
                                else {
                                    milhar = "";
                                    cont++;
                                }
                                
                                inteiro = parteInteira.substr((i - 1), 1) + milhar + inteiro;
                            }
                            
                            valorFinal = inteiro + "," + parteDecimal;
                        }
                        else {
                            valorFinal = "0,00";
                        }
    }
    else {
        //verifica se foi precionado o backspae
        if (tecla != 8) {
            //verifica se já não ultrapassou o tamanha máximo da máscara
            if (mascara.length >= valorOriginal.length) {
                //loop em cima do valor do campo sem a máscara
                jaTemMascara = false;
                for (i = 0; i < valor.length; i++) {
                    //verifica se a string já recebeu alguma máscara ou não
                    if (jaTemMascara == false) {
                        //verifica se o tipo da entrada de dados tem que ser némerica
                        if (mascara.charAt(i) == "#") {
                            //verifica se foi digitado somente números
                            if (((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16) {
                                //0 = 96 ou 48
                                //1 = 97 ou 49
                                //2 = 98 ou 50
                                //3 = 99 ou 51
                                //4 = 100 ou 52
                                //5 = 101 ou 53
                                //6 = 102 ou 54
                                //7 = 103 ou 55
                                //8 = 104 ou 56
                                //9 = 105 ou 57
                                //tecla == 9 = tab
                                valorFinal = valorFinal + valor.charAt(i);
                            }
                            else//se não foi digitado um número é retirado o caracter da string
                            {
                                valorFinal = valorOriginal.substring(0, valorOriginal.length - 1);
                            }
                        }
                        else 
                            if (mascara.charAt(i) == "@")//verifica se o tipo da entrada é qualquer caracter
                            {
                                valorFinal = valorFinal + valor.charAt(i);
                            }
                            else//se não for quelaquer caracter é algum elemento da máscara
                            {
                                //verifica se o próxima depois da máscara é númerica 
                                if (mascara.charAt(i + 1) == "#") {
                                    //verifica se foi digitado somente números
                                    if (((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16) {
                                        //0 = 96 ou 48
                                        //1 = 97 ou 49
                                        //2 = 98 ou 50
                                        //3 = 99 ou 51
                                        //4 = 100 ou 52
                                        //5 = 101 ou 53
                                        //6 = 102 ou 54
                                        //7 = 103 ou 55
                                        //8 = 104 ou 56
                                        //9 = 105 ou 57
                                        //tecla == 9 = tab
                                        valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
                                        jaTemMascara = jaTemMascara + 1;
                                    }
                                    else//se não foi digitado um número é retirado o caracter da string
                                    {
                                        valorFinal = valorOriginal.substring(0, valorOriginal.length - 1);
                                    }
                                }
                                else// se não é númerico então pode ser qualuqer caracter
                                {
                                    valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
                                    jaTemMascara = jaTemMascara + 1;
                                }
                            }
                    }
                    else//else da verificação da máscara
                    {
                        //verifica se foi digitado somente números
                        if (mascara.charAt(i + jaTemMascara) == "#") {
                            //verifica se foi digitado somente números
                            if (((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16) {
                                //0 = 96 ou 48
                                //1 = 97 ou 49
                                //2 = 98 ou 50
                                //3 = 99 ou 51
                                //4 = 100 ou 52
                                //5 = 101 ou 53
                                //6 = 102 ou 54
                                //7 = 103 ou 55
                                //8 = 104 ou 56
                                //9 = 105 ou 57
                                //tecla == 9 = tab
                                valorFinal = valorFinal + valor.charAt(i);
                            }
                            else//se não foi digitado um número é retirado o caracter da string
                            {
                                valorFinal = valorOriginal.substring(0, valorOriginal.length - 1);
                            }
                        }
                        else 
                            if (mascara.charAt(i + jaTemMascara) == "@")//verifica se o tipo da entrada é qualquer caracter
                            {
                                valorFinal = valorFinal + valor.charAt(i);
                            }
                            else {
                                //verifica se foi digitado somente números
                                if (mascara.charAt(i + jaTemMascara + 1) == "#") {
                                    //verifica se foi digitado somente números
                                    if (((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)) || tecla == 9 || tecla == 16) {
                                        //0 = 96 ou 48
                                        //1 = 97 ou 49
                                        //2 = 98 ou 50
                                        //3 = 99 ou 51
                                        //4 = 100 ou 52
                                        //5 = 101 ou 53
                                        //6 = 102 ou 54
                                        //7 = 103 ou 55
                                        //8 = 104 ou 56
                                        //9 = 105 ou 57
                                        //tecla == 9 = tab
                                        valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
                                        jaTemMascara = jaTemMascara + 1;
                                    }
                                    else//se não foi digitado um número é retirado o caracter da string
                                    {
                                        valorFinal = valorOriginal.substring(0, valorOriginal.length - 1);
                                    }
                                }
                                else// se não é númerico então pode ser qualuqer caracter
                                {
                                    valorFinal = valorFinal + mascara.charAt(i + jaTemMascara) + valor.charAt(i);
                                    jaTemMascara = jaTemMascara + 1;
                                }
                            }
                    }//fim da verificação da máscara	
                }
            }
            else {
                valorFinal = valorOriginal.substring(0, mascara.length);
            }//final da verificação do tamanha máximo da string
        }
        else {
            //valorFinal = valorOriginal.substring(0, valorOriginal.length -1)
            valorFinal = valorOriginal.substring(0, valorOriginal.length);
        }//final da verificação do backspace		
    }
    document.getElementById(id).value = valorFinal;
    
    //faz as verificações para que seja feito o tab automático
    if (mascara != "money") {
    
    }
}

