
// 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, '');
    }
}

// confirmação de delete
function del(str) {
    if (window.confirm(str)) {
        return true;
    } else {
        return false;
    }
}

// Abas
function sel(idaba){
	var aba=document.getElementById(idaba);
	var nAbas="27"; <!-- colocar o número de abas  1-->
	for(var i="1";i<nAbas;i++){
		var id="aba"+i;
		document.getElementById(id).className="unsel";
	}
	aba.className="sel";
	
	for(var u="1";u<nAbas;u++){
		var idt="textaba"+u;
		document.getElementById(idt).className="divunsel";
	}
	var iddiv="text"+idaba;
	document.getElementById(iddiv).className="divsel";
}

// abre uma janela
function popUp(file, args) {
    window.open(file, '', args);
}

// substitui virgula por ponto no campo informado em 'id'
function replaceComa(id) {
    var c = document.getElementById(id).value;
    if (c.indexOf(",") != -1) {
        document.getElementById(id).value = c.replace(",", ".");
    }
}