
// valida o campo informado em 'id' de acordo com o número
// de caracteres informado em 'lem'. 'isnan' aceita 1 ou 0
// para considerar ou não números no campo
function lemField(id, lem, isnan) {
    var lemField = document.getElementById(id);

    if (isnan == 0 || isNaN(lemField.value) || lemField.value == '') {
        if (lemField.value.length < lem) {
            window.alert('Mínimo de ' + lem + ' caracteres!');
            lemField.focus();
            return false;
        }
    }
    return true;
}

// oculta ou mostra o 'div' informado em 'id'
function showHidden(id) {
    if (document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = 'block';
    } else {
        document.getElementById(id).style.display = 'none';
    }
}

// valida um endereço de email
function isEmail(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;
    }
}

function textCounter(x, y, limit) {
    var txtarea = document.getElementById(x);
    var remtxtarea = document.getElementById(y);
    
    if (txtarea.value.length > limit) {
        txtarea.value = txtarea.value.substring(0, limit);
    } else {
        remtxtarea.value = limit - txtarea.value.length;
    }
}

// limpa o campo informado em 'id' se o seu valor
// for igual ao informado em 'v'
function clearField(id, v) {

    var field = document.getElementById(id);

    if (field.value == v) {
        field.value = '';
    }
}

// adiciona a página atual aos favoritos
function addFavorite(page, title) {
    if (document.all) {
        window.external.AddFavorite(page, title);
    } else {
        window.sidebar.addPanel(title, page, '');
    }
}

