﻿/* Manipula campo texto do WebMail */
function fc_ajustaCampoWebMail(obj) {
    $('txtMailPassword').style.display = 'block';
    $('txtMailPassword').focus(); 
    obj.style.display = 'none';
}

/* Verifica acesso ao WebEmail */
function fc_VerificaAcessoWebmail() {
    //document.xfrmwebmail.username.value = document.xfrmwebmail.usernameMask.value;
    //document.xfrmwebmail.password.value = document.xfrmwebmail.passwordMask.value;

    if (document.xfrmwebmail.username.value == '') {
        alert("E-mail inválido.")
        return false;
    }else if (document.xfrmwebmail.password.value == '') {
        alert('Informe a senha.')
        return false;
    }

    //document.xfrmwebmail.usernameMask.value = '';
    //document.xfrmwebmail.passwordMask.value = '';
    
    return true;
}

/* Mostra a layer de dica ad opção de acesso do Webmail */
function mostrarHelpWebmail(e, idg) {
    if (idg == null) return;

    if (!e) {
        if (window.event) {
            //Internet Explorer
            e = window.event;
        }
        else {
            //total failure, we have no way of referencing the event
            return;
        }
    }

    // tratamento da DIV
    var obj = document.getElementById('popup_' + idg);

    obj.style.zIndex = 999;
    obj.style.left = (e.clientX - 100) + document.body.scrollLeft;
    obj.style.top = (e.clientY + 15) + document.body.scrollTop;

    obj.style.display = 'block';
}

function esconderHelpWebmail(idg) {
    var obj2 = document.getElementById('popup_' + idg)
    obj2.style.display = 'none';
}

/* Função utilizada no evento onkeyup de caixas de texto */
function OnlyNumbers() {
    k = event.keyCode
    //backspace - tab - shift
    if (k == 8 || k == 9 || k == 16) {
        event.returnValue = true
        return
    }
    //0-9 alfa
    if (k >= 48 && k <= 57) {
        event.returnValue = true
        return
    }
    //0-9 num
    if (k >= 96 && k <= 105) {
        event.returnValue = true
        return
    }
    //setas
    if (k >= 37 && k <= 40) {
        event.returnValue = true
        return
    }
    //delete
    if (k == 46) {
        event.returnValue = true
        return
    }
    event.returnValue = false
}

/* Teste de consistência do formulário de busca rápida */
function VerificaAcessoRapido() {
    if ($('frmAutenticacao').id_acesso.value != '7') {
        if ($('frmAutenticacao').id_acesso.value == '2') {
            if ($('frmAutenticacao').mail_aasp.value == '') {
                alert("E-mail inválido.")
                return false;
            }
        } else {
            if ($('frmAutenticacao').matricula_aasp.value == '') {
                alert('Informe o número AASP.')
                return false;
            }
        }

        if ($('frmAutenticacao').senha.value == '') {
            alert('Informe a senha.')
            return false;
        }
    }
    return true;
}
/*****************************************************/
function ValidaEmail(email) {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

    if (filter.test(email))
        return true
    else { return false }

}
/*****************************************************/
var win = null;
function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var settings = 'height=' + h + ',';

    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += 'scrollbars=' + scroll + ',';
    settings += 'resizable=no';
    win = window.open(mypage, myname, settings);

    if (parseInt(navigator.appVersion) >= 4)
    { win.window.focus(); }
}
/*****************************************************/
function AtribuiValorRadio(campo, valor) {
    var aux;
    aux = eval('document.FilieAASP.' + campo);
    aux.value = valor;
}

/******************************************************/

function fc_VerificaRepeticao(str) {
    var vm_retorno = true;
    for (j = 0; j < str.length - 1; j++) {
        if (str.charAt(j) == str.charAt(j + 1))
            vm_retorno = true;
        else {
            vm_retorno = false;
            break;
        }
    }
    return vm_retorno;
}

/* Valida a Busca do Site */
function VerificaBuscaSite() {
    if (trim($('frmBuscaSite').termo.value) == '') {
        alert('Por favor, digite um termo para a busca.');
        return false;
        } else {
            return true;
            }
}

/* Remove os espaços em branco antes e após o texto informado. */
function trim(texto) {
    return texto.replace(/^\s*/, "").replace(/\s*$/, "");
}

/* Mudar opção do Acesso rápido */
function mudaOpcaoAR(opcao) {
    var direction = "";
    var num = opcao;
    if (num == "1") direction = "boletins/";
    if (num == "2") direction = "tribunais/competencias/ct_consultalogra.asp";
    if (num == "3") direction = "tribunais/custas/tabelas_custas/guia_aasp.asp";
    if (num == "4") direction = "servicos/guia_enderecos/index_guia.asp";
    if (num == "5") direction = "servicos/jucesp/sa_jucesp.asp";
    if (num == "6") { direction = window.location = "http://webmail.aasp.org.br/atmail.pl"; return; }
    if (num == "7") direction = "servicos/cobranca/infocobranca.asp";
    if (num == "8") direction = "servicos/cobranca/infocobranca.asp";
    if (num == "9") direction = "informacoes/economicas/indecon.asp";
    if (num == "10") direction = "login/rs_index.asp";
    if (num == "11") direction = "recortes/historico.asp";
    if (num == "12") direction = "servicos/index.asp";
    window.location = app_url + direction;
}