function Mascara (formato, objeto){
	campo = eval (objeto);
	if (formato=='Altura'){
		separador1 = ',';
		conjunto1 = 1;
		conjunto2 = 2;
		if (campo.value.length == conjunto1){
			campo.value = campo.value + separador1;
		}
	}
}

function V2P(num) {
// Substitui vírgula por ponto
   p = num.lastIndexOf(',');
   if ( p != -1 ) {
	  num = " " + num;
	  temp = "";
	  for (i=1;i<7;i++) {
		 if( num.charAt(i) != ',' ) { temp += num.charAt(i); }
		 else { temp += '.'; } ;
	  }
	  num = parseFloat(temp);
   }
   return ( num );
} 

function CampoNumerico(campo1) {
  campo=campo1.value;
  var i=0; 
  saida=true;
  for (i=0; i<campo.length ; i++) {
	dig = String(campo.substr(i, 1));
	if ((dig == "\*") || (dig == "\\") || (dig == "\^") || (dig == "\$") || (dig == "\?") || (dig == "\+")) {
	  saida = false;
	  break;
	}
	if ("0123456789,.-/".search(dig) == -1) {
	  saida = false;
	  break;
	}
  }
  return(saida);
}

function FormataMoeda(campo,formulario,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = formulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.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 ){ 
			formulario[campo].value = vr ; }
		if ( (tam > 2) && (tam <= 5) ){
			formulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
			formulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
		if ( (tam >= 9) && (tam <= 11) ){
			formulario[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) ){
			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 ) ; }
		if ( (tam >= 15) && (tam <= 17) ){
			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 ) ;}
	}
		
	for (var ct = 0; ct < formulario.elements.length; ct++) {
		if (formulario.elements[ct].name == formulario.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && formulario.elements[ct+1] && formulario.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
}		

function somenteNumeros(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape
		key = e.which;
	}
	if (key!=127 || key!=9 || key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8) || (key == 9)); {
		return false;
	}
}

function calcula() {
   if (document.calculaIMC.TXT_PESO.value == "") { 
	  alert ("Digite o peso");
	  document.calculaIMC.TXT_PESO.focus();
	  return;
   }
   
   if (document.calculaIMC.TXT_ALTURA.value == "") { 
	  alert ("Digite a altura");
	  document.calculaIMC.TXT_ALTURA.focus();
	  return;
   }
   
   Peso = document.calculaIMC.TXT_PESO.value;
   if (Peso <= 0 ) {
	  alert("Peso inválido");
	  document.calculaIMC.TXT_PESO.focus();
	  return;
   }
   
   Altura = document.calculaIMC.TXT_ALTURA.value;
   Altura = V2P(Altura);
   document.calculaIMC.TXT_ALTURA.value = Altura;
   Peso = V2P(Peso);
   document.calculaIMC.TXT_PESO.value = Peso;

   if (Altura <= 0 || Altura > 2.6) {
	  alert("Altura inválida");
	  document.calculaIMC.TXT_ALTURA.focus();
	  return;
   }
   
   var resultado = document.getElementById("spanIMC");
   
   if ((Peso/(Altura*Altura)) <= 18.5) {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Seu peso est&aacute; abaixo da faixa considerada normal.';
   } else if ((Peso/(Altura*Altura)) > 18.5 && (Peso/(Altura*Altura)) < 25) {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Seu peso est&aacute; dentro da faixa considerada normal.';
   } else if ((Peso/(Altura*Altura)) >= 25 && (Peso/(Altura*Altura)) < 30) {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Voc&ecirc; est&aacute; na faixa chamada de "acima do peso".';
   } else if ((Peso/(Altura*Altura)) >= 30 && (Peso/(Altura*Altura)) < 35) {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Voc&ecirc; est&aacute; na faixa chamada de "obesidade leve".';
   } else if ((Peso/(Altura*Altura)) >= 35 && (Peso/(Altura*Altura)) < 40) {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Voc&ecirc; est&aacute; na faixa chamada de "obesidade moderada".';
   } else {
	   resultado.innerHTML = 'O seu IMC &eacute; <strong>'+(Peso/(Altura*Altura)+'').substring(0,5)+'</strong>. Voc&ecirc; est&aacute; na faixa chamada de "obesidade m&oacute;rbida".';
   }
   document.calculaIMC.reset();
   document.calculaIMC.TXT_PESO.focus();
   return;
}
