function FormataValor(id,tammax,teclapres) {

	if(window.event) { // Internet Explorer
	 var tecla = teclapres.keyCode; }
	else if(teclapres.which) { // Nestcape / firefox
	 var tecla = teclapres.which;
	}

	if (((tecla) >= 48 ) && ((tecla) <= 57 )) {
		vr = document.getElementById(id).value;
		vr = vr.toString().replace( "/", "" );
		vr = vr.toString().replace( "/", "" );
		vr = vr.toString().replace( ",", "" );
		vr = vr.toString().replace( ".", "" );
		vr = vr.toString().replace( ".", "" );
		vr = vr.toString().replace( ".", "" );
		vr = vr.toString().replace( ".", "" );
		tam = vr.length;

		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 <= 2 ){
		document.getElementById(id).value = vr; }
		if ( (tam > 2) && (tam <= 5) ){
		document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 6) && (tam <= 8) ){
		document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ( (tam >= 9) && (tam <= 11) ){
		document.getElementById(id).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.getElementById(id).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.getElementById(id).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(window.event) { // Internet Explorer
			event.keyCodde = 0}
		else if(event.which) { // Nestcape / firefox
			event.which = null;
		}
		return tecla;
	}


}

function FormataData (campo, teclapres) {
	var campo_value = campo.value;
	var tam_aux = campo.value;
	var tam = tam_aux.length; 

	if(window.event) { // Internet Explorer
	 var tecla = teclapres.keyCode; }
	else if(teclapres.which) { // Nestcape / firefox
	 var tecla = teclapres.which;
	}

	if (((tecla) >= 48 ) && ((tecla) <= 57 )) {
		tecla;
		if ( ( tam == 2 ) || ( tam == 5 ) ) {
			campo.value = campo.value + "/"; 
		} 
	} else {
		if(window.event) { // Internet Explorer
			teclapres.keyCode = 0; }
		else if(teclapres.which) { // Nestcape / firefox
			teclapres.which = null;
		}

	} 
} 

function ConfereValor(objeto) {
	valor = objeto.value;
	if (valor.length <= 2) {
		objeto.value = "0," + valor
	}
}
