function Limpar(valor, validos) { 
	// retira caracteres invalidos da string 
	var result = ""; 
	var aux; 
	
	for (var i=0; i < valor.length; i++) { 
		aux = validos.indexOf(valor.substring(i, i+1)); 
		if (aux>=0) { 
			result += aux; 
		} 
	} 
	return result; 
} 

//Formata número tipo moeda usando o evento onKeyDown 
function Formata(campo,tammax,teclapres,decimal) { 
	var tecla = teclapres.keyCode; 
	vr = Limpar(campo.value,"0123456789"); 
	tam = vr.length; 
	dec=decimal 
	
	if (tam < tammax && tecla != 8){ 
		tam = vr.length + 1 ; 
	} 
	
	if (tecla == 8 ) { 
		tam = tam - 1 ; 
	} 
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) { 
		if ( tam <= dec ) { 
			campo.value = vr ; 
		} 
		if ( (tam > dec) && (tam <= 5) ) { 
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
		} 
		if ( (tam >= 6) && (tam <= 8) ) { 
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		} 
		if ( (tam >= 9) && (tam <= 11) ) { 
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
		} 
		if ( (tam >= 12) && (tam <= 14) ) { 
			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 - dec, tam ) ; 
		} 
		if ( (tam >= 15) && (tam <= 17) ) { 
			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 ) ;
		} 
	}
}

function Tecla(e) {
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else {
			if (tecla != 8) // backspace
				event.keyCode = 0;
			else
				return true;
		}
}

function submitForum() {
	if (document.comarcaCartorio.forum) {  
		document.comarcaCartorio.forum.selectIndex = -1; 
	}
 	document.comarcaCartorio.submit();
}

function submitOption() {       
	document.comarcaCartorio.submit();   
}

function submitAto() {
	if (document.bolete.ato) {
		document.bolete.ato.selectIndex = -1;
 	}
 	document.bolete.submit();
}

function submitOptionAto() {    
	document.bolete.submit();      
}

function validate() {	
	if (document.comarcaCartorio.comarca.value=="-1" || document.comarcaCartorio.comarca.value ==null) {	
		alert("Selecione a Comarca!!")
		return false	
	}
	if (document.comarcaCartorio.forum.value=="-1" || document.comarcaCartorio.forum.value == null) {	
		alert("Selecione o Cartório!")
		return false	
	}
	if (document.bolete.ato.value=="-1" || document.bolete.ato.value == null) {
		alert("Ato deve ser informado!")
		return false
	}
	if (document.bolete.discriminacao.value=="-1" || document.bolete.discriminacao.value == null) {
	 	alert("Discriminação do ato deve ser informada!")
	   	return false
	}
	if (document.bolete.quantidade.value=="" ||  document.bolete.quantidade.value==null || document.bolete.quantidade.value==0) {	
		alert("Favor preencher a quantidade de atos!" )
		document.bolete.quantidade.focus();
		return false
	} else {	
		for (var i=0;i<document.bolete.quantidade.value.length;i++) {
			proibido = "abcdefghijklmnopqrstuvxzyw;:()<>-+!@$%&*_=§[]ªº^~´`?/°";
			p = document.bolete.quantidade.value.charAt(i);    		
	    	if(proibido.indexOf(p)>-1) {
				alert("O padrão para a quantidade é número vírgula. Ex.: 3.123,55")
				return false
				document.bolete.quantidade.focus();
	    	}
		}
	}
	return true;
}

