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 O CAMPO VALOR COLOCANDO AS VÍRGULA QUANDO FOR PREÇO EM REAIS /////////////////
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 validaBoleto(){
	var nome = document.getElementById('NomeSacado');
	var cpf = document.getElementById('cpf');
	var cidade = document.getElementById('CidadeSacado');
	var valor = document.getElementById('ValorDocumento');
	var erro = '';
	
	if(nome.value == ''){
		erro += 'O campo Nome não foi preenchido!\r\n';
		nome.style.border = '1px solid #ff0000';
	}
	
	if(cpf.value == ''){
		erro += 'O campo CPF não foi preenchido!\r\n';
		cpf.style.border = '1px solid #ff0000';
	}
	
	if(cidade.value == ''){
		erro += 'O campo Cidade não foi preenchido!\r\n';
		cidade.style.border = '1px solid #ff0000';
		
	}	
	
	if(valor.value == ''){
		erro += 'O campo Valor não foi preenchido!\r\n';
		valor.style.border = '1px solid #ff0000';
		
	}
	
	
	if(erro == ''){
		return true;
	}else{
		alert(erro);
		return false;
	}
	
}

