function abasIndex(event){
    // Tiro o hover da aba e escondo a aba
    $('#op-abas li a').removeClass('current');
    $('.abas-content').hide();
    
    // Coloco o hover e mostro a aba
    $(this).addClass('current');
    $($(this).attr('href')).show();
    
    event.preventDefault();
    return false;
}

$(function(){
	
	
	
	
	$('#menu-publicidade .categoria').toggle(function(event){
		
		$(this).parent().children('ul').slideDown();
		
		event.preventDefault(event);
		return false;
	}, function(event){
		
		$(this).parent().children('ul').slideUp();
		
		event.preventDefault(event);
		return false;
	});
	

    // Campo aviao
    $('.cat-apostila').live('change', function(event){
    
        busca = $(this).val();
        
        if (busca != '') {        
            window.location = 'http://www.mercadodaaviacao.com.br/' + $(this).next().val() + '' + busca + '/';
        }
		else {
			window.location = 'http://www.mercadodaaviacao.com.br/' + $(this).next().val() + '/';
		}
        
    });
    
    // Campo aviao
    $('input:[name="ae_definicao"]').change(function(event){
    
        $('#tipo_aeronave').html('<option>Carregando ..</option>');
        
        $.ajax({
            type: 'post',
            url: 'http://www.mercadodaaviacao.com.br/ajax.php',
            data: {
                'acao': 'aeronave',
                'tipo': $(this).val()
            },
            dataType: 'html',
            success: function(valor){
                $('#tipo_aeronave').html(valor);
                //  $('#baer_modelo').html('<option value="">Selecione Primeiro o tipo de aeronave</option>')
            }
        });
        
        
    });
    //tipo_aeronave
    
    
    
    
    // Campo fabricante
    $('#baer_fabricante').change(function(event){
    
        $('#baer_modelo').html('<option>Carregando ..</option>');
        
        $.ajax({
            type: 'post',
            url: 'http://www.mercadodaaviacao.com.br/ajax.php',
            data: {
                'acao': 'modelo',
                'modelo': $(this).val()
            },
            dataType: 'html',
            success: function(valor){
                $('#baer_modelo').html(valor);
            }
        });
        
        
    });
    
    
    
    $('#usu_tipo1').click(function(){
        $("#pessoa-fisica").show();
        $("#pessoa-juridica").hide();
        $('.error-form').remove();
    });
    
    $('#usu_tipo2').click(function(){
        $("#pessoa-fisica").hide();
        $("#pessoa-juridica").show();
        $('.error-form').remove();
    });
    
    ////////////////////////////////////////////////////////////////////
    // Color Box	
    $('a[rel="popup"]').colorbox({
        slideshow: true
    });
    
    $('a[rel="popup-issuu"]').colorbox({
        slideshow: false
    });
    
    
    $('a[rel="video"]').colorbox({
        iframe: true,
        innerWidth: 425,
        innerHeight: 349
    });
    
    
    
    $('#op-abas a').click(abasIndex);
    
    //efeito hover
    $("#bt-buscar, .box-parceiros-list a img, #bt-new,.bt-veja-mais a img, #bser-busca, #bemp-busca, #bpas-pro, #bpas-volta, .list-planos-bt a img, .bt-form").mouseover(function(){
        $(this).fadeTo("fast", 0.70);
    });
    $("#bt-buscar, .box-parceiros-list a img, #bt-new,.bt-veja-mais a img, #bser-busca, #bemp-busca, #bpas-pro, #bpas-volta, .list-planos-bt a img, .bt-form").mouseout(function(){
        $(this).fadeTo("fast", 1.00);
    });
    
    
    $("#redes-sociais a img, #chat a img").mouseover(function(){
        $(this).fadeTo("fast", 1.00);
    });
    $("#redes-sociais a img, #chat a img").mouseout(function(){
        $(this).fadeTo("fast", 0.70);
    });
    
    
    //limpa os campos
    $("#buscar").focus(function(){
        valorAntigo = $(this).attr('value');
        if (valorAntigo == 'O que você procura?') {
            $('#buscar').val("");
        }
    });
    $("#buscar").blur(function(){
        if ($('#buscar').val() == '') {
            $('#buscar').val('O que você procura?');
        };
            });
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // Color Box	
    $('a[rel="popup"]').colorbox({
        slideshow: true
    });
    
    $('a[rel="exeb"]').colorbox({
        rel: 'nofollow'
    });
    
    ///////////////////////////////////////////////////////////////////////////
    // Links Externos 
    $('.externo').attr('target', '_blanck');
    
    //////////////////////////////////////////
    // mascaras
    $("#usu_nascimento").mask("99/99/9999");
    $("#usu_cpf").mask("99999999999");
	
    
    
    /*-------------------------------------NEWSLETTER-------------------------------------*/
    
    //limpa os campos Newsletter
    $("#new-nome").focus(function(){
        valorAntigo = $(this).attr('value');
        if ((valorAntigo == 'Nome:') || (valorAntigo == 'Nome inválido')) {
            $('#new-nome').val("").css({
                'color': '#0090C6'
            });
        }
    });
    
    $("#new-nome").blur(function(){
        if ($('#new-nome').val() == '') {
            $('#new-nome').val('Nome:');
        };
            });
    
    $("#new-email").focus(function(){
        valorAntigo = $(this).attr('value');
        if ((valorAntigo == 'E-mail:') || (valorAntigo == 'E-mail inválido')) {
            $('#new-email').val("").css({
                'color': '#0090C6'
            });
        }
    });
    
    $("#new-email").blur(function(){
        if ($('#new-email').val() == '') {
            $('#new-email').val('E-mail:');
        };
            });
    
    
    
    //Valida cadastro a newsletter
    $('#bt-new').click(function(event){
        nome = $('#new-nome').val();
        email = $('#new-email').val();
        
        error = false;
        
        $('.error').hide();
        $('#error-geral').hide();
        $('#sucess-geral').hide();
        
        if (nome == '' || nome == 'Nome:' || nome == 'Nome inválido') {
            $('#new-nome').val("Nome inválido").css({
                'color': 'red'
            })
            error = true;
        }
        
        if (email == '' || email == 'E-mail:' || email == 'E-mail inválido' || !validaEmail(email)) {
            $('#new-email').val("E-mail inválido").css({
                'color': 'red'
            })
            error = true;
        }
        
        if (error == false) {
            $.ajax({
                type: 'post',
                url: 'http://www.mercadodaaviacao.com.br/ajax.php',
                data: {
                    'acao': 'neswletter',
                    'email': email,
                    'nome': nome
                },
                dataType: 'json',
                success: function(valor){
                    // cadastro corretamente
                    if (valor.error == true) {
                        $('#bt-new').hide();
                        $('#sucess-geral').html(valor.msg).fadeIn();
                        
                        // Mostra mensagem cadastro Ok
                    
                        //$('#carregandoNew').fadeOut().remove();
                    
                    }
                    else {
                        // Mostra Errors
                        $('#bt-new').hide();
                        $('#error-geral').html(valor.msg).fadeIn();
                        
                        //$('#carregandoNew').fadeOut().remove();
                    }
                }
            });
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    /*
     
     // bt compartilhar pagina Twitter
     $('.bt-comp-oferta-twitter').click(function(event){
     
     link = $(this).parents('.box-oferta').find('.img a ');
     
     titulo = URLEncode(link.attr('title'));
     link = link.attr('href');
     
     url = "http://twitter.com/share?text=" + titulo + "&lang=pt&url=" + link;
     
     window.open(url, 'Compartilhe no Facebook', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
     event.preventDefault(event);
     
     return false;
     });
     
     
     // bt compartilhar pagina Facebook
     $('.bt-comp-oferta-facebook').click(function(event){
     
     link = $(this).parents('.box-oferta').find('.img a ');
     
     link = link.attr('href');
     url = "http://www.facebook.com/sharer.php?u=" + link;
     
     
     window.open(url, 'Compartilhe no Facebook', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
     
     event.preventDefault(event);
     return false;
     });
     
     
     // bt compartilhar pagina Orkut
     $('.bt-comp-oferta-orkut').click(function(event){
     
     
     link = $(this).parents('.box-oferta').find('.img a ');
     
     titulo = URLEncode(link.attr('title'));
     imagem = link.children('img').attr('src');
     link = windolink = link.attr('href');
     link = link;
     texto = document.getElementsByName('description');
     texto = URLEncode(texto[0].content);
     
     url = "http://promote.orkut.com/preview?nt=orkut.com&tt=" + titulo + "&du=" + link + "&cn=" + texto + "&tn=" + imagem;
     
     window.open(url, 'Compartilhe no Orkut', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
     event.preventDefault(event);
     
     return false;
     });
     */
    // bt compartilhar pagina Twitter    
    $('.bt-comp-twitter').click(function(event){
		
    
        titulo = URLEncode(document.title);
        
        link = window.location;
        
        // url = "http://twitter.com/share?text=" + titulo + "&lang=pt&url=" + link;
        
        myWindow = window.open("http://twitter.com/share?text=" + titulo + "&lang=pt&url=" + link, '', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
        
        // window.open(url, 'Compartilhe no Facebook', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
        event.preventDefault(event);
        return false;
    });
    
    
    // bt compartilhar pagina Facebook
    $('.bt-comp-facebook').click(function(event){
        link = window.location;
        
        
        myWindow = window.open("http://www.facebook.com/sharer.php?u=" + link, '', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
        
        
        //window.open(url, 'Compartilhe no Facebook', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
        event.preventDefault(event);
        
        return false;
    });
    
    
    // bt compartilhar pagina Orkut 
    $('.bt-comp-orkut').click(function(event){
    
        titulo = URLEncode(document.title);
        link = window.location;
        texto = document.getElementsByName('description');
        texto = URLEncode(texto[0].content);
        imagem = "http://www.mercadodaaviacao.com.br/theme/img/logo-social.jpg";
        
        //url = "http://promote.orkut.com/preview?nt=orkut.com&tt=" + titulo + "&du=" + link + "&cn=" + texto + "&tn=" + imagem;
        
        myWindow = window.open("http://promote.orkut.com/preview?nt=orkut.com&tt=" + titulo + "&du=" + link + "&cn=" + texto + "&tn=" + imagem, '', 'width=660,height=530,scrollbars=NO,toolbar=no,location=no,directories=no,status=no,menubar=no');
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    ///////////////////////////////////////////////////////////////////  
    // Limpa os campos
    $('#index-email, #new-mail, #ind-nome, #ind-email, #ind-nome-amigo, #ind-email-amigo, #mensagem').focus(function(event){
        valorAntigo = $(this).attr('value');
        
        if (valorAntigo == 'digite seu e-mail' ||
        valorAntigo == 'Insira seu e-mail' ||
        valorAntigo == 'Digite seu nome' ||
        valorAntigo == 'Digite seu e-mail' ||
        valorAntigo == 'Digite o nome do seu amigo(a)' ||
        valorAntigo == 'Digite o e-mail do seu amigo(a)' ||
        valorAntigo == 'Digite sua mensagem') {
        
            $(this).attr('value', '');
        }
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            $(this).attr('value', valorAntigo);
        }
    });
    
    
    //indique
    $('.indique-amigo').click(function(event){
        $('body').prepend('<div id="overlay"></div>');
        
        
        widht = $('body').width();
        height = $('body').height();
        
        $("#overlay").width(widht);
        $("#ovelay").height(height);
        
        $("#overlay").fadeTo(0, 0.8);
        
        wB = parseInt($('#indique').width() / 2);
        wP = parseInt(widht / 2);
        
        $('#indique').css('left', parseInt(wP - wB)).fadeIn();
        
    });
    
    $('#bt-indique').click(function(event){
    
        erro = false;
        $('.erro-msg').remove();
        
        if ($('#ind-nome').val() == '' || $('#ind-nome').val() == 'Digite seu nome') {
            $('#ind-nome').parent().append('<span class="erro-msg" >Informe o seu nome</span>')
            erro = true;
        }
        
        if ($('#ind-email').val() == '' || $('#ind-email').val() == 'Digite seu e-mail') {
            $('#ind-email').parent().append('<span class="erro-msg" >Informe o seu e-mail</span>')
            erro = true;
        }
        else 
            if (!validaEmail($('#ind-email').val())) {
                $('#ind-email').parent().append('<span class="erro-msg" >Informe um e-mail valido</span>')
                erro = true;
            }
        
        
        if ($('#ind-nome-amigo').val() == '' || $('#ind-nome-amigo').val() == 'Digite o nome do seu amigo(a)') {
            $('#ind-nome-amigo').parent().append('<span class="erro-msg" >Informe o nome do seu amigo(a)</span>')
            erro = true;
        }
        
        
        if ($('#ind-email-amigo').val() == '' || $('#ind-email-amigo').val() == 'Digite o e-mail do seu amigo(a)') {
            $('#ind-email-amigo').parent().append('<span class="erro-msg" >Informe o e-mail do seu amigo(a)</span>')
            erro = true;
        }
        else 
            if (!validaEmail($('#ind-email').val())) {
                $('#ind-email-amigo').parent().append('<span class="erro-msg" >Informe um e-mail valido</span>')
                erro = true;
            }
        
        
        if ($('#mensagem').val() == '' || $('#mensagem').val() == 'Digite sua mensagem') {
            $('#mensagem').parent().append('<span class="erro-msg" >Informe a sua mensagem</span>')
            erro = true;
        }
        
        if (erro == false) {
        
        
            $('.botao-enviar').html('<img src="/theme/img/carregando.gif" alt="Carregando" style="float:right" />');
            
            $.ajax({
                type: 'post',
                url: 'http://www.mercadodaaviacao.com.br/ajax.php',
                data: {
                    'acao': 'indique',
                    'nome': $('#ind-nome').val(),
                    'email': $('#ind-email').val(),
                    'mensagem': $('#mensagem').val(),
                    'nome-amigo': $('#ind-nome-amigo').val(),
                    'email-amigo': $('#ind-email-amigo').val()
                },
                dataType: 'json',
                success: function(valor){
                
                    // cadastro corretamente
                    if (valor.mensagem == 'ok') {
                    
                        alert(valor.msg);
                        $('.campo').val('');
                        $('.botao-enviar').html('<input type="submit" value="Enviar" id="bt-indique" />');
                        $('#overlay').remove();
                        $('#indique').fadeOut();
                    }
                    else {
                        alert(valor.mensagem);
                        $('.botao-enviar').html('<input type="submit" value="Enviar" id="bt-indique" />');
                    }
                }
            });
            
        }
        event.preventDefault(event);
        return false;
    });
    
    
    $('#indique .fechar').click(function(event){
    
        $('#overlay').remove();
        $('#indique').fadeOut();
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    // Limpa os campos
    $('#envia-nome, #envia-email, #envia-telefone, #envia-desc').focus(function(event){
        valorAntigo = $(this).attr('value');
        
        if (valorAntigo == 'Digite seu nome' ||
        valorAntigo == 'Digite seu e-mail' ||
        valorAntigo == 'Digite a sua mensagem' ||
        valorAntigo == 'Digite seu telefone') {
        
            $(this).attr('value', '');
        }
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            $(this).attr('value', valorAntigo);
        }
    });
    
    
    
    //enviar mensagem
    $('.contato-venda').click(function(event){
        $('body').prepend('<div id="overlay"></div>');
        
        
        widht = $('body').width();
        height = $('body').height();
        
        $("#overlay").width(widht);
        $("#ovelay").height(height);
        
        $("#overlay").fadeTo(0, 0.8);
        
        wB = parseInt($('#envia-mensagem').width() / 2);
        wP = parseInt(widht / 2);
        
        $('#envia-mensagem').css('left', parseInt(wP - wB)).fadeIn();
		
		/*
		$('#envia-telefone').focus(function(){
			$('#envia-telefone').mask('(99)9999-9999');
		}).blur(function(){
			$('#envia-telefone').unmask();
		});*/
        
    });
    
    $('#bt-envia-mensagem').click(function(event){
    
        erro = false;

        $('.erro-msg').remove();
		
		
        
        if ($('#envia-nome').val() == '' || $('#envia-nome').val() == 'Digite seu nome') {
            $('#envia-nome').parent().append('<span class="erro-msg" >Informe o seu nome</span>')
            erro = true;
        }
        
        if ($('#envia-email').val() == '' || $('#envia-email').val() == 'Digite seu e-mail') {
            $('#envia-email').parent().append('<span class="erro-msg" >Informe o seu e-mail</span>')
            erro = true;
        }
        else 
            if (!validaEmail($('#envia-email').val())) {
                $('#envia-email').parent().append('<span class="erro-msg" >Informe um e-mail valido</span>')
                erro = true;
            }
        
        
        if ($('#envia-telefone').val() == '' || $('#envia-telefone').val() == 'Digite seu telefone') {
            $('#envia-telefone').parent().append('<span class="erro-msg" >Informe o seu Telefone</span>')
            erro = true;
        }
        
        
        if ($('#envia-desc').val() == '') {
            $('#envia-desc').parent().append('<span class="erro-msg" >Informe a sua mensagem</span>')
            erro = true;
        }
        
        if (erro == false) {
        
        
            $('.botao-enviar').html('<img src="/theme/img/carregando.gif" alt="Carregando" style="float:right" />');
            
            $.ajax({
                type: 'post',
                url: 'http://www.mercadodaaviacao.com.br/ajax.php',
                data: {
                    'acao': 'contatovenda',
                    'nome': $('#envia-nome').val(),
                    'email': $('#envia-email').val(),
                    'telefone': $('#envia-telefone').val(),
                    'mensagem': $('#envia-desc').val(),
                    'nome-vendedor': $('#vendedor-nome').val(),
                    'email-vendedor': $('#vendedor-email').val(),
                    'produto': $('#vendedor-produto').val()
                },
                dataType: 'json',
                success: function(valor){
                
                    // cadastro corretamente
                    if (valor.mensagem == 'ok') {
                    
                        alert(valor.msg);
                        $('.campo').val('');
                        $('.botao-enviar').html('<input type="submit" value="Enviar" id="bt-indique" />');
                        $('#overlay').remove();
                        $('#envia-mensagem').fadeOut();
						
                    }
                    else {
                        alert(valor.mensagem);
                        $('.botao-enviar').html('<input type="submit" value="Enviar" id="bt-indique" />');
                    }
                }
            });
            
        }
        event.preventDefault(event);
        return false;
    });
    
    
    $('#envia-mensagem .fechar').click(function(event){
    
        $('#overlay').remove();
        $('#envia-mensagem').fadeOut();
        
        
        event.preventDefault(event);
        return false;
    });
    
    //valida formulario
    $('#usu_enviar').click(function(event){
    
        var error = false;
        var errorList = [];
        
        
        if ($('#usu_tipo1').attr('checked') == true) {
        
            if ($('#usu_nome').val() == '') {
                errorList.push('Preencha o campo Nome');
                error = true;
            }
            if ($('#usu_nascimento').val() == '') {
                errorList.push('Preencha o campo Data de Nascimento');
                error = true;
            }
            if (isCpf($('#usu_cpf').val()) == false) {
                errorList.push('Preencha o campo CPF');
                error = true;
            }
            
        }
        else {
            if ($('#usu_fantasia').val() == '') {
                errorList.push('Preencha o campo Nome Fantasia');
                error = true;
            }
            if ($('#usu_razao_social').val() == '') {
                errorList.push('Preencha o campo Razão social');
                error = true;
            }
            if ($('#usu_pessoa_contato').val() == '') {
                errorList.push('Preencha o campo Pessoa de contato');
                error = true;
            }
            
        }
        
        if (!(validaEmail($('#usu_email').val()))) {
            errorList.push('Preencha o campo com um email válido');
            error = true;
        }
        if ($('#usu_email').val() != $('#usu_emailc').val()) {
            errorList.push('Confirme o email');
            error = true;
        }
        if ($('#estado').val() == '') {
            errorList.push('Preencha o campo Estado');
            error = true;
        }
        if ($('#cidade').val() == '') {
            errorList.push('Preencha o campo Cidade');
            error = true;
        }
        if ($('#usu_endereco').val() == '') {
            errorList.push('Preencha o campo Endereço');
            error = true;
        }
        if ($('#usu_cep').val() == '') {
            errorList.push('Preencha o campo CEP');
            error = true;
        }
        if ($('#usu_telefone').val() == '') {
            errorList.push('Preencha o campo Telefone');
            error = true;
        }
        if ($('#usu_senha').val() == '') {
            errorList.push('Preencha o campo Senha');
            error = true;
        }
        if ($('#usu_senha').val() != $('#usu_senhac').val()) {
            errorList.push('Cofirme a Senha');
            error = true;
        }
        if ($('#usu_aceito_termos').attr('checked') == false) {
            errorList.push('Aceite os Termos');
            error = true;
        }
        
        $('#lista-erros').slideUp().end();
        
        if (error == true) {
        
        
            $('html, body').animate({
                scrollTop: $(".box-meio-head").offset().top
            }, 1100);
            
            errors = '';
            for (i = 0; i < errorList.length; i++) {
                errors += '<li>' + errorList[i] + '</li>';
            }
            
            if (errors) {
                $('#errojs').show();
            }
            
            $('#lista-erros').html('<ul></ul>');
            $('#lista-erros ul').html(errors);
            
            errors = '';
            errorList.length = 0;
            
            $('#lista-erros').slideDown();
            
            event.preventDefault(event);
            return false;
            
        }
        
        
    });
    
    
    
    
    
    
});


function URLEncode(texto){
    var plaintext = retirarAcento(texto);
    
    if (encodeURIComponent()) { // OLD Browser mode
        // The Javascript escape and unescape functions do not correspond
        // with what browsers actually do...
        var SAFECHARS = "0123456789" + // Numeric
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
        "abcdefghijklmnopqrstuvwxyz" +
        "-_.!~*'()"; // RFC2396 Mark characters
        var HEX = "0123456789ABCDEF";
        
        var encoded = "";
        for (var i = 0; i < plaintext.length; i++) {
            var ch = plaintext.charAt(i);
            if (ch == " ") {
                encoded += "+"; // x-www-urlencoded, rather than %20
            }
            else 
                if (SAFECHARS.indexOf(ch) != -1) {
                    encoded += ch;
                }
                else {
                    var charCode = ch.charCodeAt(0);
                    if (charCode > 255) {
                    /*
                     alert( "Unicode Character '"
                     + ch
                     + "' cannot be encoded using standard RFC2396 encoding.\n" +
                     "(URL encoding only supports 8-bit characters.)\n" +
                     "A space (+) will be substituted." );
                     encoded += "+";
                     */
                    }
                    else {
                        encoded += "%";
                        encoded += HEX.charAt((charCode >> 4) & 0xF);
                        encoded += HEX.charAt(charCode & 0xF);
                    }
                }
        } // for
        return encoded;
    }
    else { // Modern browser mode
        return encodeURIComponent(plaintext);
    }
    
    
    return false;
};
function retirarAcento(texto){
    var varString = texto
    var stringAcentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ');
    var stringSemAcento = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');
    
    var i = new Number();
    var j = new Number();
    var cString = new String();
    var varRes = '';
    
    for (i = 0; i < varString.length; i++) {
        cString = varString.substring(i, i + 1);
        for (j = 0; j < stringAcentos.length; j++) {
            if (stringAcentos.substring(j, j + 1) == cString) {
                cString = stringSemAcento.substring(j, j + 1);
            }
        }
        varRes += cString;
    }
    return varRes;
}

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;
}

function getPageScroll(){
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        }
        else 
            if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};

/*
 * Mapa
 */
//function loadMapa(lat, lng, info) {
function loadMapa(lat, lng){
    if (GBrowserIsCompatible()) {
    
        var map2 = new GMap2(document.getElementById("map"));
        
        map2.setCenter(new GLatLng(lat, lng), 15);
        //var customUI = map2.getDefaultUI();
        //customUI.controls.scalecontrol = false;
        //map2.setUI(customUI);
        
        map2.addControl(new GLargeMapControl());
        
        map2.setMapType(G_NORMAL_MAP);
        
        var point = new GPoint(lng, lat);
        var marker = new GMarker(point);
        
        //marker.openInfoWindowHtml(info);
        
        GEvent.addListener(marker, "click", function(overlay, point){
            //marker.openInfoWindowHtml(info);
        });
        
        map2.addOverlay(marker);
    }
}
// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
function URLEncode(texto){
    var plaintext = retirarAcento(texto);
    
    if (encodeURIComponent()) { // OLD Browser mode
        // The Javascript escape and unescape functions do not correspond
        // with what browsers actually do...
        var SAFECHARS = "0123456789" + // Numeric
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
        "abcdefghijklmnopqrstuvwxyz" +
        "-_.!~*'()"; // RFC2396 Mark characters
        var HEX = "0123456789ABCDEF";
        
        var encoded = "";
        for (var i = 0; i < plaintext.length; i++) {
            var ch = plaintext.charAt(i);
            if (ch == " ") {
                encoded += "+"; // x-www-urlencoded, rather than %20
            }
            else 
                if (SAFECHARS.indexOf(ch) != -1) {
                    encoded += ch;
                }
                else {
                    var charCode = ch.charCodeAt(0);
                    if (charCode > 255) {
                    /*
                     alert( "Unicode Character '"
                     + ch
                     + "' cannot be encoded using standard RFC2396 encoding.\n" +
                     "(URL encoding only supports 8-bit characters.)\n" +
                     "A space (+) will be substituted." );
                     encoded += "+";
                     */
                    }
                    else {
                        encoded += "%";
                        encoded += HEX.charAt((charCode >> 4) & 0xF);
                        encoded += HEX.charAt(charCode & 0xF);
                    }
                }
        } // for
        return encoded;
    }
    else { // Modern browser mode
        return encodeURIComponent(plaintext);
    }
    
    
    return false;
};



function retirarAcento(texto){
    var varString = texto
    var stringAcentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ');
    var stringSemAcento = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');
    
    var i = new Number();
    var j = new Number();
    var cString = new String();
    var varRes = '';
    
    for (i = 0; i < varString.length; i++) {
        cString = varString.substring(i, i + 1);
        for (j = 0; j < stringAcentos.length; j++) {
            if (stringAcentos.substring(j, j + 1) == cString) {
                cString = stringSemAcento.substring(j, j + 1);
            }
        }
        varRes += cString;
    }
    return varRes;
}

