
function redondear(num, dec){ 
    num = parseFloat(num); 
    dec = parseFloat(dec); 
    dec = (!dec ? 2 : dec); 
    return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); 
} 
function replaceChars(entry) {
	out = ","; // reemplazar la coma
	add = "."; // por el punto
	temp = "" + entry;

	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function calcular() {
	if(document.form1.peso.value!="peso en kilos..." && document.form1.altura.value!="altura en metros..." && document.form1.peso.value!="" && document.form1.altura.value!="") {
		altura=replaceChars(document.form1.altura.value);
		imc=document.form1.peso.value/(altura*altura);
		imc_red=redondear(imc,1);
		document.getElementById("resultado").innerHTML="Su <strong>IMC</strong> es "+imc_red+" - <a href='grados.html#resul' class='txt_base'>¿Qu&eacute; significa?</a>";
	}
	else {
		window.alert("Debe introducir el peso en kilos (por ejemplo, 175) y la altura en metros (por ejemplo, 1.80)");
	}
	
}
