﻿function aktivN() {
  n = window.document.frm_aktivitaet.art.selectedIndex;
  window.document.frm_aktivitaet.aktiv1.style.display = 'none';
  window.document.frm_aktivitaet.aktiv2.style.display = 'none';
  window.document.frm_aktivitaet.aktiv3.style.display = 'none';
  window.document.frm_aktivitaet.aktiv4.style.display = 'none';
  window.document.frm_aktivitaet.aktiv5.style.display = 'none';
  eval("window.document.frm_aktivitaet.aktiv" + n + ".style.display = 'inline'");
}

function calc_kcal() {
	
	if (window.document.frm_aktivitaet.art.selectedIndex) {
		fakt = eval("window.document.frm_aktivitaet."+ window.document.frm_aktivitaet.art.value +".value");
	}
	else {
		alert("Bitte wählen Sie eine Gruppe aus!");
		fakt = 0;
	}
	
	if ((window.document.frm_aktivitaet.gew.value.length > 0) && (window.document.frm_aktivitaet.dauer.value.length > 0)) {
		gew = window.document.frm_aktivitaet.gew.value
		t = window.document.frm_aktivitaet.dauer.value
		window.document.frm_aktivitaet.res.value = Math.round(gew*fakt*t*0.01);
 	}
	else alert("Bitte geben Sie für Alter und Gewicht gültige Werte ein!");
}

function calc_umsatz(){
			document.getElementById("grundumsatz_ergebnis").value = Math.round(document.getElementById("grundumsatz_faktor").value * document.getElementById("grundumsatz_kg").value)
		}
		
function calc_faustformel(){
		document.getElementById("bedarf_ergebnis").value = Math.round(document.getElementById("bedarf_faktor").value * document.getElementById("gewicht").value)
	}

function calc_karvonen()
 {
  hfmax = parseFloat(document.getElementById("karvonen_hfmax").value);
  hfmin = parseFloat(document.getElementById("karvonen_hfmin").value);
  alter = parseFloat(document.getElementById("karvonen_alter").value);
  faktor = parseFloat(document.getElementById("karvonen_faktor").value);
  
  bmax = (hfmax+220-alter)/2;
  pulsweite = bmax-hfmin;
  
  document.getElementById("karvonen_ergebnis").value = Math.round((pulsweite*faktor)+hfmin);
  document.getElementById("karvonen_test").value = ("hfmax:"+hfmax+"; hfmin:"+hfmin+"; alter:"+alter+"; bmax:"+bmax+"; faktor:"+faktor+"; pulsweite:"+pulsweite);
  //Die Karvonenformel
//(220-Lebensalter-Ruhepuls) x 0,6 – 0,85 + Ruhepuls = Trainingspuls
//Bsp: 220-40 = 180 – 60 = 120 x 72/102 + 60 = 132 bis 162
//Anmerkung: Durch Einbezug des Ruhepuls (morgens vor dem aufstehen messen!) sehr viel genauer als die Pauschal-Formel.
 }

function calc_bmi() {
	groesse = document.getElementById("bmi_groesse").value;
	gewicht = document.getElementById("bmi_gewicht").value;
	alter = document.getElementById("bmi_alter").value;
	bmi = Math.round(gewicht/((groesse/100)*(groesse/100)));
	
	if (alter < 18){
		bmi_auswertung = "Die Body-Mass-Index Berechnung ist für Personen unter 17 Jahren nicht geeignet."
	}
	if ((alter > 17)&& (alter < 25)) {
		korektor = -1;}
	if ((alter > 24)&& (alter < 35)) {
		korektor = 0;}
	if ((alter > 34)&& (alter < 46)) {
		korektor = 1;}
	if ((alter > 45)&& (alter < 55)) {
		korektor = 2;}
	if ((alter > 54)&& (alter < 65)) {
		korektor = 3;}
	if (alter > 64) {
		korektor = 4;
	}
	
	
	
		if (bmi < 17) {
			bmi_auswertung = "Achtung, ihre BMI-Auswertung hat ergeben, dass sie kritisches Untergewicht haben!"
		}
		if ((bmi >=(17 + korektor))&&(bmi<=(20+korektor))) {
			bmi_auswertung = "Ihre persönliche BMI-Auswertung anhand Ihrer Daten hat ergeben, dass sie Untergewichtig sind. "
		}
		if ((bmi >(20 + korektor))&&(bmi<=(25 + korektor))) {
			bmi_auswertung = "Ihre persönliche BMI-Auswertung anhand Ihrer Daten hat ergeben, dass sie Normalgewicht haben. "
		}
		if ((bmi >(25 + korektor))&&(bmi<=(30 + korektor))) {
			bmi_auswertung = "Ihre persönliche BMI-Auswertung anhand Ihrer Daten hat ergeben, dass sie Übergewichtig sind. "
		}
		if ((bmi >(30 + korektor))&&(bmi<=(40 + korektor))) {
			bmi_auswertung = "Ihre persönliche BMI-Auswertung anhand Ihrer Daten hat ergeben, dass sie Übergewichtig sind. "
		}
		if (bmi >(40 + korektor)) {
			bmi_auswertung = "Achtung! Ihre persönliche BMI-Auswertung anhand Ihrer Daten hat ergeben, dass sie starkes Übergewichtig haben! "
		}
		ausgabe = ("Ihr BMI Beträgt: " + bmi + "\n\n" + bmi_auswertung);
		document.getElementById("bmi_ergebnis").value = ausgabe;
	
		
	
}

function calc_wunschgewicht(bmi, groesse, alter) {
	bmi = document.getElementById("wg_bmi").value;
	groesse = document.getElementById("wg_groesse").value;
	document.getElementById("wg_ergebnis").value = Math.round(bmi*((groesse/100)*(groesse/100)));
}

