function wHeight(e1516, e1719, e2024, e2529, e3039, e4049, e5059, e6069){
  this.e1516 = e1516;
  this.e1719 = e1719;
  this.e2024 = e2024;
  this.e2529 = e2529;
  this.e3039 = e3039;
  this.e4049 = e4049;
  this.e5059 = e5059;
  this.e6069 = e6069;
}

//  Sexo/Altura         15/16   17/19   20/24   25/29   30/39   40/49   50/59   60/69
var h153 = new wHeight( 44.90 , 51.70 , 55.70 , 58.40 , 59.70 , 61.10 , 62.00 , 60.70 );
var h154 = new wHeight( 45.60 , 52.10 , 56.20 , 58.90 , 60.30 , 61.60 , 62.50 , 61.20 );
var h155 = new wHeight( 46.30 , 52.60 , 56.70 , 59.50 , 60.80 , 62.20 , 63.10 , 61.70 );
var h156 = new wHeight( 47.20 , 53.20 , 57.20 , 60.00 , 61.30 , 62.70 , 63.60 , 62.20 );
var h157 = new wHeight( 48.10 , 53.70 , 57.80 , 60.50 , 61.90 , 63.20 , 64.10 , 62.80 );
var h158 = new wHeight( 49.00 , 54.30 , 58.40 , 61.20 , 62.50 , 63.90 , 64.70 , 63.30 );
var h159 = new wHeight( 49.90 , 55.10 , 59.10 , 61.90 , 63.20 , 64.60 , 65.20 , 63.90 );
var h160 = new wHeight( 50.80 , 55.80 , 59.90 , 62.60 , 63.90 , 65.30 , 65.80 , 64.40 );
var h161 = new wHeight( 51.70 , 56.50 , 60.60 , 63.10 , 64.70 , 66.00 , 66.50 , 65.10 );
var h162 = new wHeight( 52.60 , 57.20 , 61.30 , 63.70 , 65.40 , 66.70 , 67.20 , 65.80 );
var h163 = new wHeight( 53.50 , 58.00 , 61.90 , 64.20 , 66.10 , 67.50 , 67.90 , 66.60 );
var h164 = new wHeight( 54.50 , 58.70 , 62.50 , 64.80 , 66.80 , 68.20 , 68.60 , 67.30 );
var h165 = new wHeight( 55.30 , 59.40 , 63.00 , 65.30 , 67.50 , 68.90 , 69.40 , 68.00 );
var h166 = new wHeight( 56.10 , 60.10 , 63.50 , 66.00 , 68.20 , 69.60 , 70.00 , 68.70 );
var h167 = new wHeight( 57.00 , 60.80 , 64.10 , 66.70 , 68.90 , 70.30 , 70.80 , 69.40 );
var h168 = new wHeight( 57.90 , 61.60 , 64.60 , 67.60 , 69.70 , 71.10 , 71.50 , 70.20 );
var h169 = new wHeight( 58.80 , 62.20 , 65.10 , 67.90 , 70.40 , 72.00 , 72.40 , 71.10 );
var h170 = new wHeight( 59.70 , 62.90 , 65.70 , 68.40 , 71.10 , 72.90 , 73.30 , 72.00 );
var h171 = new wHeight( 60.60 , 63.60 , 66.40 , 69.10 , 71.80 , 73.60 , 74.10 , 72.70 );
var h172 = new wHeight( 61.50 , 64.30 , 67.10 , 69.80 , 72.50 , 74.30 , 74.80 , 73.40 );
var h173 = new wHeight( 62.40 , 65.10 , 67.80 , 70.50 , 73.20 , 75.00 , 75.50 , 74.20 );
var h174 = new wHeight( 63.30 , 65.80 , 68.50 , 71.20 , 73.90 , 75.80 , 76.20 , 75.10 );
var h175 = new wHeight( 64.20 , 66.50 , 69.20 , 71.90 , 74.70 , 76.50 , 76.90 , 76.00 );
var h176 = new wHeight( 64.90 , 67.20 , 69.60 , 72.60 , 75.50 , 77.30 , 77.60 , 76.90 );
var h177 = new wHeight( 65.70 , 67.90 , 70.60 , 73.40 , 76.40 , 78.20 , 78.70 , 77.80 );
var h178 = new wHeight( 66.40 , 68.60 , 71.40 , 74.10 , 77.30 , 79.10 , 79.60 , 78.70 );
var h179 = new wHeight( 67.10 , 69.30 , 72.10 , 74.80 , 78.00 , 79.80 , 80.50 , 79.50 );
var h180 = new wHeight( 67.80 , 70.10 , 72.80 , 75.50 , 78.70 , 80.50 , 81.30 , 80.40 );
var h181 = new wHeight( 68.50 , 70.90 , 73.60 , 76.30 , 79.50 , 81.30 , 82.20 , 81.30 );
var h182 = new wHeight( 69.20 , 71.80 , 74.50 , 77.20 , 80.40 , 82.20 , 83.10 , 82.20 );
var h183 = new wHeight( 70.00 , 72.70 , 75.40 , 78.10 , 81.30 , 83.10 , 84.00 , 83.10 );
var h184 = new wHeight( 70.90 , 73.40 , 76.10 , 79.00 , 82.00 , 83.80 , 84.70 , 84.00 );
var h185 = new wHeight( 71.70 , 74.10 , 76.80 , 79.90 , 82.70 , 84.50 , 85.40 , 84.90 );
var h186 = new wHeight( 72.60 , 74.80 , 77.50 , 80.80 , 83.50 , 85.30 , 86.20 , 85.80 );
var h187 = new wHeight( 73.50 , 75.50 , 78.20 , 81.70 , 84.40 , 86.20 , 87.10 , 86.70 );
var h188 = new wHeight( 74.40 , 76.20 , 79.00 , 82.60 , 85.30 , 87.10 , 88.00 , 87.60 );
var h189 = new wHeight( 75.30 , 76.90 , 79.70 , 83.30 , 86.20 , 88.00 , 88.90 , 88.50 );
var h190 = new wHeight( 76.20 , 77.70 , 80.40 , 84.00 , 87.10 , 88.90 , 89.80 , 89.40 );
var h191 = new wHeight( 77.10 , 78.40 , 81.00 , 84.70 , 88.10 , 89.90 , 90.80 , 90.30 );
var h192 = new wHeight( 78.00 , 79.10 , 81.50 , 85.40 , 89.20 , 91.00 , 91.90 , 91.40 );
var h193 = new wHeight( 0.00 , 79.80 , 82.10 , 86.20 , 90.20 , 92.00 , 92.90 , 92.50 );
var h194 = new wHeight( 0.00 , 80.50 , 82.60 , 86.90 , 91.30 , 93.10 , 94.00 , 93.60 );
var h195 = new wHeight( 0.00 , 81.20 , 83.20 , 87.60 , 92.40 , 94.20 , 95.10 , 94.60 );

//  Sexo/Altura         15/16   17/19   20/24   25/29   30/39   40/49   50/59   60/69
var m148 = new wHeight( 44.40 , 45.30 , 46.60 , 48.90 , 52.40 , 55.60 , 56.90 , 57.80 );
var m149 = new wHeight( 44.90 , 45.80 , 47.20 , 49.40 , 52.80 , 55.90 , 57.30 , 58.20 );
var m150 = new wHeight( 45.40 , 46.30 , 47.70 , 50.00 , 53.10 , 56.30 , 57.70 , 58.60 );
var m151 = new wHeight( 46.00 , 46.90 , 48.20 , 50.50 , 53.70 , 56.90 , 58.20 , 58.90 );
var m152 = new wHeight( 46.50 , 47.40 , 48.80 , 51.00 , 54.20 , 57.40 , 58.80 , 59.30 );
var m153 = new wHeight( 47.10 , 48.10 , 49.40 , 51.60 , 54.80 , 57.90 , 59.30 , 59.80 );
var m154 = new wHeight( 47.90 , 48.80 , 50.10 , 52.10 , 55.30 , 58.50 , 59.80 , 60.30 );
var m155 = new wHeight( 48.60 , 49.40 , 50.80 , 52.60 , 55.80 , 59.00 , 60.40 , 60.80 );
var m156 = new wHeight( 49.30 , 50.20 , 51.30 , 53.20 , 56.30 , 59.50 , 60.90 , 61.30 );
var m157 = new wHeight( 50.00 , 50.90 , 51.90 , 53.70 , 56.90 , 60.00 , 61.40 , 61.90 );
var m158 = new wHeight( 50.60 , 51.50 , 52.40 , 54.30 , 57.40 , 60.60 , 62.10 , 62.50 );
var m159 = new wHeight( 51.10 , 52.10 , 53.00 , 54.80 , 58.00 , 61.10 , 62.50 , 63.20 );
var m160 = new wHeight( 51.70 , 52.60 , 53.50 , 53.00 , 58.50 , 61.70 , 63.50 , 63.90 );
var m161 = new wHeight( 52.20 , 52.20 , 54.00 , 53.50 , 59.00 , 62.40 , 64.20 , 64.70 );
var m162 = new wHeight( 82.80 , 54.00 , 54.60 , 56.50 , 59.60 , 63.10 , 64.90 , 65.40 );
var m163 = new wHeight( 53.40 , 54.80 , 55.20 , 57.00 , 60.10 , 63.80 , 65.70 , 66.10 );
var m164 = new wHeight( 54.10 , 55.50 , 55.90 , 57.70 , 60.70 , 64.30 , 66.40 , 66.80 );
var m165 = new wHeight( 54.80 , 56.20 , 56.60 , 58.50 , 61.20 , 64.80 , 67.10 , 67.50 );
var m166 = new wHeight( 55.50 , 56.70 , 57.30 , 59.20 , 61.90 , 65.60 , 67.80 , 68.20 );
var m167 = new wHeight( 56.20 , 57.30 , 58.10 , 59.90 , 62.60 , 66.20 , 68.50 , 68.90 );
var m168 = new wHeight( 56.90 , 57.80 , 58.70 , 60.50 , 63.20 , 66.90 , 69.20 , 69.70 );
var m169 = new wHeight( 57.40 , 58.30 , 59.20 , 61.10 , 63.80 , 67.60 , 69.90 , 70.40 );
var m170 = new wHeight( 58.00 , 58.90 , 59.80 , 61.60 , 64.30 , 68.40 , 70.60 , 71.10 );
var m171 = new wHeight( 58.60 , 59.60 , 60.50 , 62.30 , 65.00 , 69.10 , 71.30 , 71.80 );
var m172 = new wHeight( 59.40 , 60.30 , 61.20 , 63.00 , 65.70 , 69.80 , 72.10 , 72.50 );
var m173 = new wHeight( 60.10 , 61.00 , 61.90 , 63.70 , 66.40 , 70.50 , 72.50 , 73.20 );
var m174 = new wHeight( 60.80 , 61.70 , 62.60 , 64.40 , 67.10 , 71.20 , 73.50 , 73.90 );
var m175 = new wHeight( 61.50 , 62.40 , 63.30 , 65.10 , 67.90 , 71.90 , 74.20 , 74.70 );
var m176 = new wHeight( 62.20 , 63.10 , 64.00 , 65.80 , 68.60 , 72.80 , 75.10 , 75.40 );
var m177 = new wHeight( 62.90 , 63.80 , 64.70 , 66.60 , 69.30 , 73.70 , 75.90 , 76.10 );
var m178 = new wHeight( 63.60 , 64.60 , 65.50 , 67.30 , 70.00 , 74.60 , 76.80 , 76.80 );
var m179 = new wHeight( 65.50 , 65.50 , 66.40 , 68.20 , 70.90 , 75.50 , 77.70 , 0.00 );
var m180 = new wHeight( 0.00 , 66.40 , 67.30 , 69.10 , 71.80 , 76.40 , 78.80 , 0.00 );
var m181 = new wHeight( 0.00 , 67.30 , 68.20 , 70.00 , 72.70 , 77.20 , 79.60 , 0.00 );
var m182 = new wHeight( 0.00 , 68.20 , 69.10 , 70.90 , 73.60 , 78.10 , 80.70 , 0.00 );
var m183 = new wHeight( 0.00 , 69.10 , 70.00 , 71.80 , 74.50 , 79.00 , 81.80 , 0.00 );
var m184 = new wHeight( 0.00 , 70.00 , 70.90 , 72.70 , 75.40 , 79.90 , 82.90 , 0.00 );
var m185 = new wHeight( 0.00 , 70.90 , 71.80 , 73.60 , 76.30 , 80.80 , 83.90 , 0.00 );

// CALCULADORAS
function Calcula(tipo,f) {
	switch (tipo) {
		case 'IMC': //indice de masa corporal
			Estatura=f.estatura.value;
			if (Estatura=='') {
				alert("La estatura no puede ser vacía.");
				f.estatura.focus();
				return;
			} else {
				if (isNaN(Estatura)) {
					alert("La estatura ha de ser numérica.");
					f.estatura.focus();
					return;
				}
			}
			Estatura = parseFloat(f.estatura.value, 10);
			if (f.mestatura.selectedIndex==1) Estatura = Estatura * 2.54;
			if ((Estatura<50) || (Estatura>300)) {
				alert("Por favor, ingresa un valor real de estatura.");
				f.estatura.focus();
				return;
			}
			
			Peso=f.peso.value;
			if (Peso=='') {
				alert("El peso no puede ser vacío.");
				f.peso.focus();
				return;
			} else {
				if (isNaN(Peso)) {
					alert("El peso ha de ser numérico.");
					f.peso.focus();
					return;
				}
			}
			Peso = parseFloat(f.peso.value, 10);
			if (f.mpeso.selectedIndex==1) Peso = Peso * 0.4536;
			if ((Peso<1) || (Peso>400)) {
				alert("Por favor, ingresa un valor real de peso.");
				f.peso.focus();
				return;
			}
			
			h = Estatura / 100;
			Index = Math.round(Peso /(h*h));
			f.resultado.value = Index;
			f.resultado.focus();
		break;
		case 'PI': //peso ideal
			if (f.sexo.selectedIndex==0){
				var gender = 'h';
				var li = 153;
				var ls = 195;
			} else {
				var gender = 'm';
				var li = 148;
				var ls = 185;
			}
			result = 0;
			altura = f.altura[f.altura.selectedIndex].value;
			if (altura >= li && altura <= ls) {tabulado = true;} else {tabulado = false;}
			if (tabulado) { 
				 result = eval(gender + altura + '.' + f.edad[f.edad.selectedIndex].value);
			}
			if (result == 0) {
				f.resultado.value = '';
				alert('Los valores ingresados no son válidos.'); }
			else {
				f.resultado.value = eval(gender + altura + '.' + f.edad[f.edad.selectedIndex].value); 
			}
			f.resultado.focus();
		break;
		case 'CALO': //calorias gastadas
			if ((!f.sexo[0].checked) && (!f.sexo[1].checked)) {
				alert("Elige un sexo.");
				return;
			}

			cEdad=f.edad.value;
			if (cEdad=='') {
				alert("La edad no puede ser vacía.");
				f.edad.focus();
				return;
			} else {
				if (isNaN(cEdad)) {
					alert("La edad ha de ser numérica.");
					f.edad.focus();
					return;
				}
			}
			if ((cEdad<1) || (cEdad>200)) {
				alert("Por favor, ingresa un valor real de edad.");
				f.edad.focus();
				return;
			}

			cPeso=f.peso.value;
			if (cPeso=='') {
				alert("El peso no puede ser vacío.");
				f.peso.focus();
				return;
			} else {
				if (isNaN(cPeso)) {
					alert("El peso ha de ser numérico.");
					f.peso.focus();
					return;
				}
			}
			if ((cPeso<1) || (cPeso>400)) {
				alert("Por favor, ingresa un valor real de peso.");
				f.peso.focus();
				return;
			}

			cAltura=f.altura.value;
			if (cAltura=='') {
				alert("La altura no puede ser vacía");
				f.altura.focus();
				return;
			} else {
				if (isNaN(cAltura)) {
					alert("La altura ha de ser numérica");
					f.altura.focus();
					return;
				}
			}
			if ((cAltura<50) || (cAltura>300)) {
				alert("Por favor, ingresa un valor real de altura.");
				f.altura.focus();
				return;
			}
			
			mbhombre=66.5+(13.8*eval(f.peso.value))+(5*eval(f.altura.value))-(6.8*eval(f.edad.value));
			mbmujer=655.1+(9.6*eval(f.peso.value))+(1.8*eval(f.altura.value))-(4.7*eval(f.edad.value));
			Sexo = (f.sexo[0].checked) ? eval(f.sexo[0].value) : eval(f.sexo[1].value);
			Actividad = f.actividad.options[f.actividad.selectedIndex].value;
			Reduccion = (eval(f.edad.value)<40)?(0):(eval(f.edad.value)>=40&&eval(f.edad.value)<=49)?(0.05):(eval(f.edad.value)>=50&&eval(f.edad.value)<=59)?(0.1):(eval(f.edad.value)>=60&&eval(f.edad.value)<=79)?(0.2):(0.3);
			rmb = (Sexo==1)?eval(mbmujer):eval(mbhombre);		//(*)Metabolismo Basal (kcal) :
			rge = (eval(rmb)*Actividad)+(eval(rmb)*0.1)-eval(Reduccion)*((eval(rmb)*Actividad)+(eval(rmb)*0.1));
			f.resultado0.value=eval(rmb);		//(*) Metabolismo Basal (kcal) :
			index=f.resultado0.value.indexOf(".");
			if (index!=-1) {
				f.resultado0.value=f.resultado0.value.substring(0,index+2);
			}
			f.resultado1.value=(eval(rmb)*Actividad)+(eval(rmb)*0.1)-eval(Reduccion)*((eval(rmb)*Actividad)+(eval(rmb)*0.1));		//Gasto Energético (kcal) :
			index=f.resultado1.value.indexOf(".");
			if (index!=-1) {
				f.resultado1.value=f.resultado1.value.substring(0,index+2);
			}

/*
	f.mbhombre.value=66.5+(13.8*eval(f.p3_peso.value))+(5*eval(f.p4_altura.value))-(6.8*eval(f.p2_edad.value));		//cte1
	f.mbmujer.value=655.1+(9.6*eval(f.p3_peso.value))+(1.8*eval(f.p4_altura.value))-(4.7*eval(f.p2_edad.value));		//cte2
	if(f.p1_1sexo[0].checked){var p1_1sexo=eval(f.p1_1sexo[0].value);}	if(f.p1_1sexo[1].checked){var p1_1sexo=eval(f.p1_1sexo[1].value);}var p5_actividad=f.p5_actividad.options[f.p5_actividad.selectedIndex].value;	f.reduccion.value=(eval(f.p2_edad.value)<40)?(0):(eval(f.p2_edad.value)>=40&&eval(f.p2_edad.value)<=49)?(0.05):(eval(f.p2_edad.value)>=50&&eval(f.p2_edad.value)<=59)?(0.1):(eval(f.p2_edad.value)>=60&&eval(f.p2_edad.value)<=79)?(0.2):(0.3);		//cte3
	f.rge.value=(eval(f.rmb.value)*p5_actividad)+(eval(f.rmb.value)*0.1)-eval(f.reduccion.value)*((eval(f.rmb.value)*p5_actividad)+(eval(f.rmb.value)*0.1));		//cte4
	f.rmb.value=(p1_1sexo==1)?eval(f.mbmujer.value):eval(f.mbhombre.value);		//(*)Metabolismo Basal (kcal) :
	f.Result0.value=eval(f.rmb.value);		//(*) Metabolismo Basal (kcal) :
	index=f.Result0.value.indexOf(".");
	if(index!=-1){
 f.Result0.value=f.Result0.value.substring(0,index+2);
}
	f.Result1.value=(eval(f.rmb.value)*p5_actividad)+(eval(f.rmb.value)*0.1)-eval(f.reduccion.value)*((eval(f.rmb.value)*p5_actividad)+(eval(f.rmb.value)*0.1));		//Gasto Energético (kcal) :
	index=f.Result1.value.indexOf(".");
	if(index!=-1){
 f.Result1.value=f.Result1.value.substring(0,index+2);
}
*/


		break;
		default:
			return;
		break;
	}
}
