var josBMI;

var josBMIString;



function mod(div,base) {

	return Math.round(div - (Math.floor(div/base)*base));

}



function calcBmi(josw, josHeightFeetMeter, josHeightInchesCm, josMetric) {

	var UnitTrans = 703;

	if (josMetric > 0)

	UnitTrans = 1;

	 

	var w = josw * 1;

	var HeightFeetInt = josHeightFeetMeter * 1;

	var HeightInchesInt = josHeightInchesCm * 1;

	

	HeightFeetConvert = HeightFeetInt * 12;

	h = HeightFeetConvert + HeightInchesInt;



	if ( !(josMetric) && ((w <= 35) || (w >= 500)  || (h <= 48) || (h >= 120)) ) {

		alert ("Fehler! Bitte eingegebene Daten überprüfen!");

		return false;

	}

	

	hm = josHeightFeetMeter + josHeightInchesCm / 100;	



	if ( (josMetric) && ((w <= 10) || (w >= 400)  || (hm <= 0.9) || (hm >= 3)) ) {

		alert ("Fehler! Bitte eingegebene Daten überprüfen!");

		return false;

	}

	if (josMetric > 0)

	h=josHeightFeetMeter + josHeightInchesCm / 100;

	

	displaybmi = Math.round(((w * UnitTrans) / (h * h))*100)/100; //(Math.round((w * UnitTrans) / (h * h)));

	var rvalue = true;



	if (rvalue) {

	if (HeightInchesInt > 11) {

	reminderinches = mod(HeightInchesInt,12);

	josHeightInchesInt = reminderinches;

	josHeightFeetInt = HeightFeetInt + 

	((HeightInchesInt - reminderinches)/12);

	josBMI = displaybmi;

	}

	if (displaybmi <18.5) 

	josBMIString = "Untergewicht";

	if (displaybmi >=18.5 && displaybmi <=24.99) 

	josBMIString = "Normales Gewicht";

	if (displaybmi >=25 && displaybmi <=29.99) 

	josBMIString = "Übergewicht";

	if (displaybmi >=30 && displaybmi <=34.99) 

	josBMIString = "Starkes Übergewicht";

	if (displaybmi >=35 && displaybmi <=39.99) 

	josBMIString = "Sehr starkes Übergewicht";

	if (displaybmi >=40) 

	josBMIString = "Extremes Übergewicht (Lebensgefährlich!)";

	josBMI = displaybmi; }

	return rvalue;

}



// MM DreamWeaver findObj() Function

function findObj(theObj, theDoc)

{

  var p, i, foundObj;

  

  if(!theDoc) theDoc = document;

  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)

  {

    theDoc = parent.frames[theObj.substring(p+1)].document;

    theObj = theObj.substring(0,p);

  }

  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

  for (i=0; !foundObj && i < theDoc.forms.length; i++) 

    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 

    foundObj = findObj(theObj,theDoc.layers[i].document);

  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  

  return foundObj;

}



function josChange(obj) {

	var objlbfeet = findObj("joslbfeet");

	var objlbinches = findObj("joslbinches");

	var objlbw = findObj("joslbw");



	if (obj.value == "true") {

		objlbfeet.innerHTML = " Meter";

		objlbinches.innerHTML = " Zentimeter";

		objlbw.innerHTML = " Gewicht";

	}

	else {

		objlbfeet.innerHTML = " feet";

		objlbinches.innerHTML = " inches";

		objlbw.innerHTML = " lb";

	}

}



function docalc() {

	var objjosHFM = findObj("josHFM");

	var objjosHIC = findObj("josHIC");

	var objjosw = findObj("josW");

	var objjosUnit = findObj("josUnit");

	var objjosResult = findObj("josResult");

	var x;

	if ( calcBmi(parseInt(objjosw.value), parseInt(objjosHFM.value), parseInt(objjosHIC.value), objjosUnit.value=="true") ) {

		objjosResult.innerHTML = josBMI + " " + josBMIString;

		if (josBMI<17) { josBMI=17; }

		if (josBMI>41) { josBMI=41; }

		x = Math.round((15.6)*parseInt(josBMI) - 252);

		moveInd(x);

	}

}



function moveInd(x) {

	objjosInd = findObj("josind");

	objjosInd.style.left = x + "px";

	objjosInd.style.visibility = "visible";

}
