// JavaScript Document



window.onload = function () {
	// Navigation
	
	// Home
	document.getElementById('navi_index').onmouseover = function () {
		onNaviColor('navi_index', 'index.php');
	}
	document.getElementById('navi_index').onmouseout = function () {
		offNaviColor('navi_index', 'index.php');
	}
	document.getElementById('navi_index').onclick = function () {
		window.location.href = 'index.php';
	}
	
	// BMI
	if(document.getElementById('subnavi_bmi')) {
		document.getElementById('subnavi_bmi').onmouseover = function () {
			onNaviColor('subnavi_bmi', 'bodymassindex_bmi.php');
		}
		document.getElementById('subnavi_bmi').onmouseout = function () {
			offNaviColor('subnavi_bmi', 'bodymassindex_bmi.php');
		}
		document.getElementById('subnavi_bmi').onclick = function () {
			window.location.href = 'bodymassindex_bmi.php';
		}
	}
	
	// Menues
	document.getElementById('navi_menues').onmouseover = function () {
		onNaviColor('navi_menues', 'unsere_menues.php');
	}
	document.getElementById('navi_menues').onmouseout = function () {
		offNaviColor('navi_menues', 'unsere_menues.php');
	}
	document.getElementById('navi_menues').onclick = function () {
		window.location.href = 'unsere_menues.php';
	}
	if(document.getElementById('subnavi_diese_woche')) {
		document.getElementById('subnavi_diese_woche').onmouseover = function () {
			onNaviColor('subnavi_diese_woche', 'speisekarte1.php');
		}
		document.getElementById('subnavi_diese_woche').onmouseout = function () {
			offNaviColor('subnavi_diese_woche', 'speisekarte1.php');
		}
		document.getElementById('subnavi_diese_woche').onclick = function () {
			window.location.href = 'speisekarte1.php';
		}
	}
	if(document.getElementById('subnavi_naechste_woche')) {
		document.getElementById('subnavi_naechste_woche').onmouseover = function () {
			onNaviColor('subnavi_naechste_woche', 'speisekarte2.php');
		}
		document.getElementById('subnavi_naechste_woche').onmouseout = function () {
			offNaviColor('subnavi_naechste_woche', 'speisekarte2.php');
		}
		document.getElementById('subnavi_naechste_woche').onclick = function () {
			window.location.href = 'speisekarte2.php';
		}
	}
	if(document.getElementById('subnavi_preise')) {
		document.getElementById('subnavi_preise').onmouseover = function () {
			onNaviColor('subnavi_preise', 'preise.php');
		}
		document.getElementById('subnavi_preise').onmouseout = function () {
			offNaviColor('subnavi_preise', 'preise.php');
		}
		document.getElementById('subnavi_preise').onclick = function () {
			window.location.href = 'preise.php';
		}
	}
	
	// Bestellung
	document.getElementById('navi_bestellung').onmouseover = function () {
		onNaviColor('navi_bestellung', 'bestellen.php');
	}
	document.getElementById('navi_bestellung').onmouseout = function () {
		offNaviColor('navi_bestellung', 'bestellen.php');
	}
	document.getElementById('navi_bestellung').onclick = function () {
		window.location.href = 'bestellen.php';
	}
	if(document.getElementById('subnavi_testen')) {
		document.getElementById('subnavi_testen').onmouseover = function () {
			onNaviColor('subnavi_testen', '');
		}
		document.getElementById('subnavi_testen').onmouseout = function () {
			offNaviColor('subnavi_testen', '');
		}
		document.getElementById('subnavi_testen').innerHTML = '<a style="padding-left: 10px;" href="javascript:void(0)">Bodyfriend testen</a>';
		document.getElementById('subnavi_testen').onclick = function () {
			window.location.href = 'http://bodyfriend.mittagspause.org/anmeldung.php';
			//window.open('http://bodyfriend.mittagspause.org/anmeldung.php', '_blank', '');
		}
	}
	if(document.getElementById('subnavi_neukunde')) {
		document.getElementById('subnavi_neukunde').onmouseover = function () {
			onNaviColor('subnavi_neukunde', '');
		}
		document.getElementById('subnavi_neukunde').onmouseout = function () {
			offNaviColor('subnavi_neukunde', '');
		}
		document.getElementById('subnavi_neukunde').innerHTML = '<a style="padding-left: 10px;" href="javascript:void(0)">Neukunde</a>';
		document.getElementById('subnavi_neukunde').onclick = function () {
			window.location.href = 'http://bodyfriend.mittagspause.org/anmeldung.php';
			//window.open('http://bodyfriend.mittagspause.org/anmeldung.php', '_blank', '');
		}
	}
	if(document.getElementById('subnavi_bestellsystem')) {
		document.getElementById('subnavi_bestellsystem').onmouseover = function () {
			onNaviColor('subnavi_bestellsystem', '');
		}
		document.getElementById('subnavi_bestellsystem').onmouseout = function () {
			offNaviColor('subnavi_bestellsystem', '');
		}
		document.getElementById('subnavi_bestellsystem').innerHTML = '<a style="padding-left: 10px;" href="javascript:void(0)">zum Bestellsystem</a>';
		document.getElementById('subnavi_bestellsystem').onclick = function () {
			window.location.href = 'http://bodyfriend.mittagspause.org/';
			//window.open('http://bodyfriend.mittagspause.org/', '_blank', '');
		}
	}
	if(document.getElementById('subnavi_insbuero')) {
		document.getElementById('subnavi_insbuero').onmouseover = function () {
			onNaviColor('subnavi_insbuero', '');
		}
		document.getElementById('subnavi_insbuero').onmouseout = function () {
			offNaviColor('subnavi_insbuero', '');
		}
		document.getElementById('subnavi_insbuero').innerHTML = '<a style="padding-left: 10px;" href="javascript:void(0)">f&uuml;r Firmenkunden</a>';
		document.getElementById('subnavi_insbuero').onclick = function () {
			//window.location.href = 'http://www.mittagspause.org/';
			window.open('http://www.mittagspause.org/', '_blank', '');
		}
	}
	
	// so funktioniert's
	document.getElementById('navi_so_funktioniert').onmouseover = function () {
		onNaviColor('navi_so_funktioniert', 'so_funktioniert_es.php');
	}
	document.getElementById('navi_so_funktioniert').onmouseout = function () {
		offNaviColor('navi_so_funktioniert', 'so_funktioniert_es.php');
	}
	document.getElementById('navi_so_funktioniert').onclick = function () {
		window.location.href = 'so_funktioniert_es.php';
	}
	
	// Philosophie
	document.getElementById('navi_philosophie').onmouseover = function () {
		onNaviColor('navi_philosophie', 'philosophie.php');
	}
	document.getElementById('navi_philosophie').onmouseout = function () {
		offNaviColor('navi_philosophie', 'philosophie.php');
	}
	document.getElementById('navi_philosophie').onclick = function () {
		window.location.href = 'philosophie.php';
	}
	if(document.getElementById('subnavi_team')) {
		document.getElementById('subnavi_team').onmouseover = function () {
			onNaviColor('subnavi_team', 'team.php');
		}
		document.getElementById('subnavi_team').onmouseout = function () {
			offNaviColor('subnavi_team', 'team.php');
		}
		document.getElementById('subnavi_team').onclick = function () {
			window.location.href = 'team.php';
		}
	}
	if(document.getElementById('subnavi_partner')) {
		document.getElementById('subnavi_partner').onmouseover = function () {
			onNaviColor('subnavi_partner', 'partner.php');
		}
		document.getElementById('subnavi_partner').onmouseout = function () {
			offNaviColor('subnavi_partner', 'partner.php');
		}
		document.getElementById('subnavi_partner').onclick = function () {
			window.location.href = 'partner.php';
		}
	}
	
	// Presse
	document.getElementById('navi_presse').onmouseover = function () {
		onNaviColor('navi_presse', 'presse.php');
	}
	document.getElementById('navi_presse').onmouseout = function () {
		offNaviColor('navi_presse', 'presse.php');
	}
	document.getElementById('navi_presse').onclick = function () {
		window.location.href = 'presse.php';
	}
	if(document.getElementById('subnavi_referenzen')) {
		document.getElementById('subnavi_referenzen').onmouseover = function () {
			onNaviColor('subnavi_referenzen', 'referenzen.php');
		}
		document.getElementById('subnavi_referenzen').onmouseout = function () {
			offNaviColor('subnavi_referenzen', 'referenzen.php');
		}
		document.getElementById('subnavi_referenzen').onclick = function () {
			window.location.href = 'referenzen.php';
		}
	}
	
	// Kontakt
	document.getElementById('navi_kontakt').onmouseover = function () {
		onNaviColor('navi_kontakt', 'kontakt.php');
	}
	document.getElementById('navi_kontakt').onmouseout = function () {
		offNaviColor('navi_kontakt', 'kontakt.php');
	}
	document.getElementById('navi_kontakt').onclick = function () {
		window.location.href = 'kontakt.php';
	}
}


// für alle Navigationspunkte
function onNaviColor(id, myfilename) {
	var pos = document.URL.lastIndexOf('/'); // letzter Slash vor dem Dateinamen
	var filename = document.URL.substr(pos+1, document.URL.length);
	if(filename != myfilename) {
		var dasTag = document.getElementById(id);
		dasTag.childNodes[0].style.color = '#a00d41';
		dasTag.style.backgroundColor = '#CBE6B3';
	}
}
function offNaviColor(id, myfilename) {
	var pos = document.URL.lastIndexOf('/'); // letzter Slash vor dem Dateinamen
	var filename = document.URL.substr(pos+1, document.URL.length);
	if(filename != myfilename) {
		var dasTag = document.getElementById(id);
		dasTag.childNodes[0].style.color = '#898885';
		dasTag.style.backgroundColor = '#FFF';
	}
}


// BMI
function myBMI() {
	
	var cm = Number(document.bmiForm.cm.value);
	var kg = Number(document.bmiForm.kg.value.replace(/,/, '.'));
	
	try {
		var bmi = kg / (cm * cm) * 10000;
		if(isNaN(bmi)) throw('Fehler bei der Eingabe!');
		
		var text = 'Ihr BMI beträgt '+bmi.toFixed(1)+' ';
		switch(true) {
			case bmi < 16: text += ' (= starkes Untergewicht).'; break;
			case bmi <= 17: text += ' (= mäßiges Untergewicht).'; break;
			case bmi <= 18.5: text += ' (= leichtes Untergewicht).'; break;
			case bmi <= 25: text += ' (= Normalgewicht).'; break;
			case bmi <= 30: text += ' (= Präadipositas).'; break;
			case bmi <= 35: text += ' (= Adipositas Grad I).'; break;
			case bmi <= 40: text += ' (= Adipositas Grad II).'; break;
			default: text += ' (= Adipositas Grad III).';
		}
		document.getElementById('bmiAuswertung').innerHTML = text;
		
		// Pfeilchen in der Grafik
		var josind = document.getElementById('josind');
		josind.style.display = 'block';
				
		var pos_josind = Math.round((15.6)*parseInt(bmi) - 252);
		if(pos_josind <= 9) pos_josind = 9; // minimale linke Position = 9px
		if(pos_josind >= 385) pos_josind = 385; // maximale rechte Position = 385px
		josind.style.left = pos_josind+"px";
	}
	catch (e) {
		alert(e);
	}
	
	return false;
}
