function FormataInt() {
	var tecla=window.event.keyCode; 

	if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105 ) || (tecla == 9)) {
		event.returnValue=true;
	} else {
		alert("valido somente numeros");
		event.keyCode=0; 
		event.returnValue=false;
	}
}

function FormataDecimal(campo,teclapres) {
	formatNPlaces(campo,teclapres,2);
}

function FormataDecimal3(campo,teclapres) {
	formatNPlaces(campo,teclapres,3);
}

function FormataDecimal4(campo,teclapres) {
	formatNPlaces(campo,teclapres,4);
}

function formatNPlaces(campo,teclapres,nDec) {
	var tecla = 0;
   if(document.all) { // Internet Explorer
     	tecla = teclapres.keyCode;
   } else if(document.layers) { // Nestcape
   		tecla = teclapres.which;
   } else { // Nestcape
   		tecla = teclapres.keyCode;
   }

	vr = FiltraNumeros(campo.value);
	tam = vr.length;
	vr1 = vr.substr( 0, tam+1 - nDec );
	vr2 = vr.substr( tam+1 - nDec, nDec );
	if ( (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105 ) ){
		if(tam>1) {
			if(getLanguage()=="pt") {
				campo.value = vr1 + ',' + vr2;
			} else {
				campo.value = vr1 + ',' + vr2;
			}
		}
	}
}

function FiltraNumeros(campo) {
	b = 0;
	n = 0;
	s = '';
	x = '';
	for(n=0;n<=15;n++) {
		x = campo.substr(n,1);
		if(b == 0) {
			if(x != '0') {
				b = 1;
			}
		}
		if(b==1) {
			if(x=='0'||x=='1'||x=='2'||x=='3'||x=='4'||x=='5'||x=='6'||x=='7'||x=='8'||x=='9') {
				s = s + x;
			}
		}
	}

	b = 0;
	for(n=0;n<=s.length;n++) {
		x = s.substr(n,1);
		if(x=='1'||x=='2'||x=='3'||x=='4'||x=='5'||x=='6'||x=='7'||x=='8'||x=='9') {
			b = 1;
		}
	}

	if(b==1) {
		tam = s.length;
		for(n=tam;n<2;n++) {
			s = '0' + s;
		}
	} else {
		s = "";
	}

	return s;
}

function getLanguage() { 
	var browser 	= navigator.appName; 
	var versao 		= parseInt(navigator.appVersion); 
	var linguagem 	= ''; 
	var plataforma = navigator.platform;
	
	if (versao >= 4) { 
		if (browser == "Microsoft Internet Explorer") { 
			linguagem = navigator.systemLanguage; 
		} else { 
			if (browser == "Netscape") { 
				linguagem = navigator.language; 
			} 
		} 
	} 
	return linguagem.substring(0,2); 
} 

