function FtrataBackSpace(dado, decimal, e){

		zeros = Math.pow(10,decimal) 
		decimal = parseInt(decimal);
		NumDig = dado.value;
		TamDig = NumDig.length;
		TamDig--;
		Contador = 0;
	   
	   var whichCode = (window.Event) ? e.which : e.keyCode;
	   
		if (whichCode == 13) return true;  // Enter
		if (whichCode == 0) return true;  // Del

	   if ((TamDig >= 0) && (whichCode == 8)){
			numer = "";
	      for (i = TamDig; (i >= 0); i--){

				if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
					Contador++;
					//alert(NumDig.substr(i, 1) + " Contador = " + Contador+ " numer = '"+ numer+ "' TamDig = " +TamDig + " i = " + i );
					if ((Contador == decimal+1) && ((TamDig -i) < (decimal+2))){
						numer = "."+numer;
	               Contador = 0;
					}
					//else if ((Contador == 3) && (numer.length > decimal)){
					//	numer = "."+numer;
					//	//numer = ""+numer; //não coloca a vírgula para não dar erro no SQL
					//	Contador = 0;
					//}

					numer = NumDig.substr(i, 1)+numer;
				}
			}
			
			zeros = zeros.toString();

			if (numer == zeros.substring(1))
			    numer="";		
			if (numer.length == decimal )
			    numer= "0." + numer;

			dado.value = numer;
		};
	   if ((TamDig >= 0) && (whichCode == 46)){
			//46 = Del
			numer = dado.value;
			if(numer.substr(0,1)== "."){
				numer = numer.substr(1);
				dado.value = numer;
			}
		//	else if(numer.substr(0,1)== ","){
		//		numer = "0" + numer.substr(0);
		//		dado.value = numer;
		//	}

			numer = dado.value;

			if(numer.substr(numer.length-1, 1) == "." ||
					numer.substr(numer.length-1, 1) == ","){

				dado.value = numer.substr(0, numer.length-1);
				return true;
			}
	   }
	}

	
function FmascTempoReal(ConteudoCampo ,decimal, e){

var key = '';
var strCheck = '0123456789.';
var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del

key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

		if (((whichCode) > 47) && ((whichCode) < 58)){
			NumDig = ConteudoCampo.value;
			TamDig = NumDig.length;
	
			if(TamDig == ConteudoCampo.maxLength) return false;
			
			Contador = 0;
			if (TamDig > 1){
				numer = "";
				for (i = TamDig; (i >= 0); i--){
					if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)){
						Contador++;
						//Aumentou o nº de decimais de 2 para 3
						if ((Contador == decimal) && ((TamDig -i) < 4)){
//						if ((Contador == 3) && ((TamDig -i) < 5)){
						//Aumentou o nº de decimais de 3 para 4
						//if ((Contador == 4) && ((TamDig -i) < 6)){
							numer = "."+numer;
		               Contador = 0;
						}
						//Aumentar o valor do Contador na comparação
						//para aumentar o nº de decimais.
//						else if (Contador == 3){
						else if (Contador == 4){
							//numer = ","+numer;
							numer = ""+numer; //retira a vírgula para não dar erro no SQL
		               Contador = 0;
						}
		            numer = NumDig.substr(i, 1)+numer;
					}
				}
		      ConteudoCampo.value = numer;
			};
			return(true)
		}
		else return(false)
	}



//muda a cor da linha
function CCA(CB,N)
{
	if (N == 1)
	//if (CB.checked)
		hL(CB);
	else
		dL(CB);
}

function hL(e){
//while (E.tagName!="TR")
//	{E=E.parentElement;}
//E.className = "LinhaClara";
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		//r.className = "td_lista_a";
		r.className = "LinhaEscura";
	}
    }
}

function dL(e){
//while (E.tagName!="TR")
//	{E=E.parentElement;}
//E.className = "LinhaEscura";
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		//r.className = "td_lista_b";
		r.className = "LinhaRealcada";
	}
    }
}





//var whichCode = (window.Event) ? e.which : e.keyCode;
function Maiuscula(e) {
    if (navigator.appName!='Microsoft Internet Explorer'){
        Key = String.fromCharCode(e.which);
		Key = Key.toUpperCase();
		Key = Key.charCodeAt(0);
		//document.onkeypress = Key;
		}
    else{
   		Key = String.fromCharCode(window.event.keyCode);
		Key = Key.toUpperCase();
		Key = Key.charCodeAt(0);
		event.keyCode = Key;
		}

}





<!-- Begin
function currencyFormat(fld, milSep, decSep, e,Num,Dec) {
//Num é o numero maximo de caracteres no campo
var sep = '';
var key = '';
var i = j = '';
var len = len2 = '';
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
//alert(whichCode);
if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
//len = fld.value.length;
len = Num;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = ''+ decSep + '' + aux;
//joao
if (len == 2 ) fld.value = ''+ decSep + aux;
//if (len == 2 || len == 3 || len == 4 ) fld.value = ''+ decSep + aux;
if (len > 2 && len < (Dec +1) ) fld.value = ''+ decSep + aux;


//joao
//if (len > 2) {
//if (len > 4) {
if (len > Dec) {
aux2 = '';
for (j = 0, i = len - (Dec+1); i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}

fld.value = '';
len2 = aux2.length;
//joao
for (i = len2 - 1; i >= 0; i--)
//for (i = len2 - 3; i >= 0; i--)
//for (i = len2 - (Dec - 1); i >= 0; i--)
fld.value += aux2.charAt(i);
//joao
//fld.value += decSep + aux.substr(len - 2, len);
fld.value += decSep + aux.substr(len - Dec, len);
}
return false;
}


function formata(num) {
//onBlur="this.value=formatCurrency(this.value);
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}



function numer(e) {//acieta tambem o ponto
var key = '';
var strCheck = '0123456789.';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function numero(e) {//nao aceita ponto
var key = '';
var strCheck = '0123456789';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function virgula(e) {//nao aceita ponto
var key = '';
var strCheck = '0123456789,.';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}


function numerodot(obj,e) {
var ponto = ".";
var comma = ",";
var campo = obj.value;
var key = '';
var strCheck = '0123456789.,';
var whichCode = (window.Event) ? e.which : e.keyCode;
//alert(whichCode);''
if (whichCode == 13) return true;  // Enter
if (whichCode == 8) return true;  // BackSpace
if (whichCode == 0) return true;  // Del

key = String.fromCharCode(whichCode);  // Get key value from key code

if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

	if(key == "." || key == ","){
		for(i=0; i<campo.length;i++){
			if (ponto.indexOf(campo.charAt(i)) != -1 || comma.indexOf(campo.charAt(i)) != -1) // Contém ponto 
			{
			//alert("O campo ja tem ponto!");
			return false;
			}
		}
	}
	
	if(key == ","){
		for(i=0; i<campo.length;i++){
			if (ponto.indexOf(campo.charAt(i)) != -1) // Contém ponto 
			{
			//alert("O campo ja tem ponto!");
			return false;
			}
		}
	}

	valor = obj.value;
	frm = obj.form.name;
	cmp = obj.name;
	out = ","; // replace this
	add = "."; // with this
	temp = "" + valor; // temporary holder
	
	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	eval("document."+frm+"."+cmp+".value ='"+temp+"'");
	
}


function formatamoeda( num ) 
{ 
   //var prefix = "R$"; 
   var prefix = ""; 
   var suffix = ""; 

   if ( num < 0 ) 
   { 
       prefix = "($"; 
       suffix = ")"; 
       num = - num; 
   } 
       var temp = Math.round( num * 100.0 ); // convert to pennies! 
       if ( temp < 10 ) return prefix + "0.0" + temp + suffix; 
       if ( temp < 100 ) return prefix + "0." + temp + suffix; 
       temp = prefix + temp; // convert to string! 
       return temp.substring(0,temp.length-2) + "." + temp.substring(temp.length-2) + suffix; 
} 

//arendonda numeros
function arredonda(number,X) {

//por chaves
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

//transforma o digitado em maiuscula
function UppCase(Letra)
{
Letra.value=Letra.value.toUpperCase();
}


function formatando(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+//','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-')  + num + '.' + cents);
}


function mascComp(objeto){
	if (objeto.value.indexOf("/") == -1 && objeto.value.length > 7){ objeto.value = ""; }
	if (objeto.value.length == 2){
		objeto.value += "/";
	}
}
function pop_combo(nome_form,tabela,campo_visivel,campo_hidden,idtab,desctab)
{
	window.open("../pop/combo.asp?tab="+tabela+"&visivel="+campo_visivel+"&nform="+nome_form+"&hidden="+campo_hidden+"&idtab="+idtab+"&desctab="+desctab,"via", "toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=yes,menubar=no, top=200, left=350, width=350 ,height=150");
}
function pop_dependente(nome_form,tabela,campo_visivel,campo_hidden,idtab,desctab,depende,condicao)
{
	depend=eval("parent.document."+nome_form+"."+depende+".value")
	window.open("../pop/combo.asp?tab="+tabela+"&visivel="+campo_visivel+"&nform="+nome_form+"&hidden="+campo_hidden+"&idtab="+idtab+"&desctab="+desctab+"&dep="+depend+"&cond="+condicao,"via", "toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=yes,menubar=no, top=200, left=350, width=350 ,height=150");
}
function ColorEditor(e)
{
		var leftPos = (screen.availWidth-420) / 2
		var topPos = (screen.availHeight-400) / 2
		window.open('../includes/editor.asp?nmcampo='+e,'','width=420,height=370,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
}
function letra(letra)
{
	document.forms[1].letra.value = letra;
	document.forms[1].submit();
}

function CCA(CB,N)
{
	if (N == 1)
		hL(CB);
	else
		dL(CB);
}

function hL(e)
{
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) 
		{r = e.parentNode.parentNode;}
	else 
		if (e.parentElement && e.parentElement.parentElement) 
			{r = e.parentElement.parentElement;}

	if (r)
		{r.className = "LinhaEscura";}
}

function dL(e)
{
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) 
		{r = e.parentNode.parentNode;}
	else 
		if (e.parentElement && e.parentElement.parentElement) 
			{r = e.parentElement.parentElement;}

	if (r)
		{r.className = "LinhaClara";}
}




//***************************************************************************************
//FUNCAO PARA MASCARAR CAMPOS MES/ANO
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onkeypress="return mascComp(this, event)" onblur="validComp(this)" 

function mascCEP(objeto, e){
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // BackSpace
	if (whichCode == 0) return true;  // Del
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1){ 
		return false;  // Not a valid key		
		}
		else{
			if (objeto.value.indexOf("/") == -1 && objeto.value.length > 9){ objeto.value = ""; }
			if (objeto.value.length == 5){
			objeto.value += "-";
		}
	}
}



//***************************************************************************************
//FUNCAO PARA MASCARAR CAMPOS MES/ANO
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onkeypress="return mascComp(this, event)" onblur="validComp(this)" 

function mascComp(objeto, e){
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // BackSpace
	if (whichCode == 0) return true;  // Del
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1){ 
		return false;  // Not a valid key		
		}
		else{
			if (objeto.value.indexOf("/") == -1 && objeto.value.length > 7){ objeto.value = ""; }
			if (objeto.value.length == 2){
			objeto.value += "/";
		}
	}
}
//funcao para formatar valor
function FormataValor(campo, teclapres) {
//	var vr = document.formulario[campo].value;
	var vr = campo.value;
	var tecla = teclapres.keyCode;
	if ( tecla == 8 || tecla == 46 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		vr = vr.replace(/\./g, "" );
		vr = vr.replace(/,/g, "" );
		tam = vr.length;
			if ( tam <= 2 ){ 
				//document.formulario[campo].value = vr ;
				campo.value = vr;
				}
			if ( (tam > 2) && (tam <= 5) ){
				//document.formulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
				campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
				}
			if ( (tam >= 6) && (tam <= 8) ){
				//document.formulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				}
			if ( (tam >= 9) && (tam <= 11) ){
				//document.formulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				}
			if ( (tam >= 12) && (tam <= 14) ){
				//document.formulario[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
				}
			if ( (tam >= 15) && (tam <= 17) ){
				//document.formulario[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
				campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
				}
		}
	else {
		if (tecla!=37 && tecla!=39){
			//document.formulario[campo].value = caracterinvalido(vr);
			campo.value = caracterinvalido(vr);
			}
		}
	}
	function caracterinvalido (strCampo)
		{
		nTamanho = strCampo.length;
		szCampo = "";
		for (i= nTamanho-1;i>=0;i--)
			{
			if (verDigito (strCampo.charAt(i)))
				{
				szCampo = strCampo.charAt (i) + szCampo;
				}
			}
		return szCampo;
		}
	function verDigito(c)
		{ return ((c >= "0") && (c <= "9") || (c == ".") || (c == ","))}	
//***************************************************************************************
//FUNCAO PARA VALIDAR CAMPOS MES/ANO 
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onblur="validComp(this)" 

function validComp(Campo){
	var mes, ano

	numer = Campo.value;
		
	if(numer != ""){
		if(numer.length < 7 && numer.length >= 1){
			alert("Mês/Ano inválido!");
			Campo.value = "";
			Campo.focus();
			return false;
		}
	
		if(numer.length == 7){
			
			mes = parseFloat(numer.substring(0,2));
			ano = parseFloat(numer.substring(3,7));
	
			if(mes < 1 || mes > 12 || ano < 1900){
				alert("Mês/Ano inválido!");
				Campo.value = "";
				Campo.focus();
				return false;
			}
	
		}
		return true;
	}
	

}

//***************************************************************************************
//FUNCAO TRIM SEMELHANTE A DO VBSCRIPT 
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

var campo ='';
var alerta ='';

//***************************************************************************************
//FUNCAO PARA VALIDAR CAMPOS MES/ANO 
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onsubmit return valida(this)" 

function valida(obj){	
formulario = obj.name;

var campos=campo.split(',');
var alertas=alerta.split(',');

	for(i=0; i<campos.length-1; i++){
		var valor = eval('document.'+formulario+'.'+campos[i]+'.value');
		if(trim(valor) == ""){
			alert(alertas[i]+' é obrigatório!');
			eval('document.'+formulario+'.'+campos[i]+'.focus()');
			return false	;
		}
	}
}


//***************************************************************************************
//FUNCAO PARA LIMITAR DIGITACAO EM UM TEXTAREA
/* 
 * @author: Sérgio Chaves - Mestra Informática 2003 
*/
//onkeyup="max(this,10)" onkeypress="max(this,10)"

function max(txarea, tam) 
{ 

    total = tam; 
    tam = txarea.value.length; 
    str=""; 
    str=str+tam; 
     
    Digitado.innerHTML = str; 
    Restante.innerHTML = total - str; 

    if (tam > total){          
       aux = txarea.value; 
       txarea.value = aux.substring(0,total); 
       Digitado.innerHTML = total 
       Restante.innerHTML = 0 
   } 

} 


function confirmaExclusao(){
if (confirm("Confirma Exclusão ?"))
	return true;
else
	return false;
}
