//Cálculo del índice de masa corporal


function IMCcalc(IMCform){

	
	
	var peso=document.IMCform.peso.value;	
	var altura=document.IMCform.altura.value;	

	
	if (peso== "" || peso== "0" || peso== "00.00" ) {
				alert("Por favor introduce tu peso.");				
				document.IMCform.peso.focus();				
				return false;
			}
		numList = "1234567890.,";
		for (i = 0;i < peso.length;i++) {
				if (numList.indexOf(peso.substring(i, i + 1)) == -1) {
					alert("Por favor introduce solo números");
					document.IMCform.peso.value = "";
					document.IMCform.peso.focus();
					return false;
				}
			}     
	
	if (altura== "" || altura== "0" || altura== "0.00") {
				alert("Por favor introduce tu altura.");
				document.IMCform.altura.focus();
				return false;
			}
		numList = "1234567890.,";
		for (i = 0;i < altura.length;i++) {
				if (numList.indexOf(altura.substring(i, i + 1)) == -1) {
					alert("Por favor introduce solo números");
					document.IMCform.altura.value = "";
					document.IMCform.altura.focus();
					return false;
				}

	}
			if (peso<20 || peso>350){
			alert("Introduce valores adecuados");
			document.IMCform.peso.value = "";
			document.IMCform.peso.focus();
			return;
			}
			if (altura<0.30 || altura>2.4) {
			alert("Introduce valores adecuados");
			document.IMCform.altura.value = "";
			document.IMCform.altura.focus();
			return;
		}
	
	
	var sexo=document.IMCform.sexo.selectedIndex;
	//alert(sexo)
	var peso=eval(peso);
	var altura=eval(altura);
	
	
	var altcuad=altura*altura;	
	var result1="Delgadez pronunciada";
	var result2="Delgadez";
	var result3="Normalidad";
	var result4="Gordura";
	var result5="Obesidad";
	
	var IMC=peso/altcuad;
	IMC=Math.round(IMC);
	document.IMCform.IMC.value=IMC;
	
	
	if(sexo==0){
			
	
		var intinf= altcuad * 21.5;		
		var intsup= altcuad * 23.5;
		intinf=Math.round(intinf*10)/10;
		intsup=Math.round(intsup*10)/10;
		
		if(IMC<=15){	
		document.IMCform.result.value=result1;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;	
		}
		if(IMC>15 && IMC<20)	{
		document.IMCform.result.value=result2;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;	
		}
		if(IMC>=20 && IMC<25)	{
		document.IMCform.result.value=result3;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
		if(IMC>=25 && IMC<30){
		document.IMCform.result.value=result4;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
		if(IMC>=30) {
		document.IMCform.result.value=result5;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
	}	
	if(sexo==1){
		
		var intinf= altcuad * 20.7;
		var intsup= altcuad * 22.8;
		intinf=Math.round(intinf*10)/10;
		intsup=Math.round(intsup*10)/10;
		

		if(IMC<=13){	
		document.IMCform.result.value=result1;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;	
		}
		if(IMC>13 && IMC<18)	{
		document.IMCform.result.value=result2;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;	
		}
		if(IMC>=18 && IMC<23)	{
		document.IMCform.result.value=result3;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
		if(IMC>=23 && IMC<28){
		document.IMCform.result.value=result4;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
		if(IMC>=28) {
		document.IMCform.result.value=result5;
		document.IMCform.intinf.value=intinf;
		document.IMCform.intsup.value=intsup;
		}
	}	

	
}



