// Versão: 1.3 - 02/09/2008
function fn_valida(field,universo,find,replace) {
var ck = 0;
var typed = field.value.charAt(field.value.length-1);
if (typed == find) ck = 1;
for (var i=0; i<universo.length; i++) {
if (typed == universo.charAt(i)) var ck = 1;
}
if (ck == 0) field.value = field.value.substring(0,field.value.length-1);
if (find && field.value.indexOf(find) >= 0) {
field.value = field.value.replace(find, replace);
}
}
function formatnum(valor, dec) {
if (!dec) dec = 2;
var z = 10;
for (var i=1; i<dec; i++) var z = z*10;
valor = Math.round(valor*z)/z + "";
var pos = valor.indexOf(".")
if (pos < 0) {
valor += ".0"
for (var i=1; i<dec; i++) valor += "0";
} else {
var end = dec - valor.length + pos
for (var i=0; i<=end; i++) valor += "0";
}
return valor
}
function formathour(val) {
val = Math.round(val*100)/100;
var comp = Math.round((val-Math.floor(val))*60)
return "" + Math.floor(val) + ":" + (comp < 10 ? "0" : "") + comp;
}
function ckdata(dia,mes,ano) {
if (dia == "" || mes == "" || ano == "") {
return false;
} else {
if (!cknum(dia) || !cknum(mes) || !cknum(ano)) {
return false;
} else if (ano < 1900) {
return false;
} else {
tammes = new Array()
tammes[1] = 31
tammes[2] = (ano%4==0?29:28)
tammes[3] = 31
tammes[4] = 30
tammes[5] = 31
tammes[6] = 30
tammes[7] = 31
tammes[8] = 31
tammes[9] = 30
tammes[10] = 31
tammes[11] = 30
tammes[12] = 31
if (Math.round(mes) > 12 || Math.round(dia) > tammes[Math.round(mes)]) {
return false;
} else {
return true;
}
}
}
}
function cknum (valor) {
universo = "1234567890";
tamvalor = valor.length;
tamuniverso = universo.length;
flag = (valor == "" ? 0 : 1);
for (var i=0; i<tamvalor; i++) {
ck = 0;
for (var j=0;j<tamuniverso;j++) {
if (valor.charAt(i) == universo.charAt(j)) ck = 1;
}
if (ck == 0) flag = 0;
}
return flag;
}
function fn_comparadata(dia_ini,mes_ini,ano_ini,dia_fim,mes_fim,ano_fim) {
if (!cknum(dia_ini) ||
!cknum(mes_ini) ||
!cknum(ano_ini) ||
!cknum(dia_fim) ||
!cknum(mes_fim) ||
!cknum(ano_fim))
return false
else if (Math.round(ano_fim) < Math.round(ano_ini))
return false
else if (Math.round(ano_fim) == Math.round(ano_ini) && Math.round(mes_fim) < Math.round(mes_ini))
return false
else if (Math.round(ano_fim) == Math.round(ano_ini) && Math.round(mes_fim) == Math.round(mes_ini) && Math.round(dia_fim) <= Math.round(dia_ini))
return false
else
return true
}
//
function recvalue(thisfield) {
tempvalue = thisfield.value
}
function gotofield(form,thisfield) {
if (tempvalue != thisfield.value &&
thisfield.maxLength == thisfield.value.length &&
(thisfield.value.substring(thisfield.size-1, thisfield.size) == 1 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 2 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 3 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 4 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 5 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 6 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 7 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 8 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 9 ||
thisfield.value.substring(thisfield.size-1, thisfield.size) == 0)) {
var ck = 0;
for (var i=0; i<form.length; i++) {
if (form[i].name == thisfield.name || ck == 1) {
ck = 1;
if (i+1<form.length) {
if (form[i+1].type != "hidden" && !form[i+1].disabled) {
form[i+1].focus();
if (form[i+1].type == "text") form[i+1].select();
break;
}
}
}
}
}
tempvalue = thisfield.value
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
function fn_get_radio_value(ix) {
var val = "";
obj = eval("document.formulario."+ix);
for (var j=0; j<obj.length; j++) {
if (obj[j].checked) {
val = obj[j].value;
break;
}
}
return val;
}
|