function cal_bmi (lbs, ins) {
	h2 = ins * ins;
	bmi = lbs / h2 * 703;
	f_bmi = Math.floor(bmi);
	diff = bmi - f_bmi;
	diff = diff * 10;
	diff = Math.round(diff);
	if (diff == 10) {
		// Need to bump up the whole thing instead
		f_bmi += 1;
		diff=0;
	}
	bmi=f_bmi+"."+diff;
	return bmi;
}


function compute_es () {

	var f=self.document.forms["bmi_input"];

	// ALTURA

	if (f.hti.value.length<=0) {
		alert ("Debe anotar su altura en centímetros");
		return;
	}

	// PESO

	if (f.wt.value.length<=0) {
		alert ("Debe anotar su peso en kilogramos");
		return;
	}
	self.document.getElementById("imc").style.display="inherit";

	compute ();
}

//----------------------------------------------------------------------------

function compute () {
	var f=self.document.forms["bmi_input"];

	w=f.wt.value;
	u=f.hti.value;
	v=0;// f.htf.value;// SOLO PREGUNTO UNA CIFRA (cms) NO DOS COMO EN LA INGLESA

	// CONVIERTO LOS KILOS Y CENTIMETROS EN LIBRAS, PIES Y PULGADAS

	w=2.2046215*parseInt(w);

	// 1 meter = 39.37007874 inches
	// 1 meter = 3.280839895 feet
	// 1 feet = 12 inches

	u = (39.37007874 * parseInt(u)) / 100 ;
	v=parseInt(u/12);
	u=parseInt(u%12);

	// Format values for the BMI calculation

	if (! chkw(u)) {
		var ii=0;
		u=0;
	} else {
		var ii=parseInt(u);
	}

	var fi=parseInt(v*12);
	var i=fi+ii;

	// Do validation of remaining fields to check for existence of values

	if (! chkw(v)) {
		alert ("Please enter a number for your height.");
		f.htf.focus ();
		return;
	}
	if (! chkw(w)) {
		alert ("Please enter a number for your weight.");
		f.wt.focus ();
		return;
	}

	// Perform the calculation

	f.bmi.value=cal_bmi(w,i);

	var val=f.bmi.value;
	if (val < 18.5) {
		f.resultado.value="Puedes tener algún problema de salud";
	} else {
		if (val >= 18.5 && val <= 24.9) {
			f.resultado.value="Goza de buena salud";
		} else {
			if (val >= 25 && val <= 29.9) {
				f.resultado.value="Tiene sobrepeso";
			} else {
				if (val >= 30 && val <= 40) {
					f.resultado.value="Tiene obesidad leve";
				} else {
					f.resultado.value="Tiene obesidad mórbida";
				}
			}
		}
	}
	f.bmi.focus ();
}

function chkw (w) {
	if (isNaN(parseInt(w))) {
		return false;
	} else if (w < 0) {
		return false;
	} else {
		return true;
	}
}