function resetBgColor() {

document.getElementById("rango1").style.backgroundColor = "";

document.getElementById("rango2").style.backgroundColor = "";

document.getElementById("rango3").style.backgroundColor = "";

document.getElementById("rango4").style.backgroundColor = "";

document.getElementById("rango5").style.backgroundColor = "";

document.getElementById("rango6").style.backgroundColor = "";

document.getElementById("rango7").style.backgroundColor = "";

document.getElementById("rango8").style.backgroundColor = "";



}

function calcularIMC() {

        var wt = document.bmi.peso.value;

        var ht = document.bmi.estatura.value;



        //If value is not given for weight

        if(wt=="" || isNaN(wt)){

                alert('Ingrese un valor para el Peso. Use el simbolo "." (punto) para numeros decimales.');

		return;

        }

        if(ht==""  || isNaN(ht)) {

                alert('Ingrese un valor para la Estatura. Use el simbolo "." (punto) para  numeros decimales');

		return;

        }



        // Calculo de IMC

        var h = ht/100;

        var imc = Math.round((wt/(h*h))*100)/100;

        document.getElementById('resultado').innerHTML ='<strong>Resultado:</strong> ' + imc;

        // Marcar con color la tabla con el IMC resultante

	resetBgColor();

        if(imc<5){

		document.getElementById("rango1").style.backgroundColor = "red";

        }

        else if(imc >= 5 && imc < 10){

		document.getElementById("rango2").style.backgroundColor = "red";

        }

        else if(imc >= 10 && imc < 18.5){

		document.getElementById("rango3").style.backgroundColor = "yellow";

        }

        else if(imc>18.5 && imc <= 24.9){

		document.getElementById("rango4").style.backgroundColor = "green";

        }

        else if(imc>24.9 && imc <= 29.9){

                document.getElementById("rango5").style.backgroundColor = "yellow";

        }

        else if(imc>29.9 && imc <= 34.9){

                document.getElementById("rango6").style.backgroundColor = "red";

        }

        else if(imc>34.9 && imc <= 39.9){

                document.getElementById("rango7").style.backgroundColor = "red";

        }



        else if(imc>39.9){

		document.getElementById("rango8").style.backgroundColor = "red";

        }

}

