/* specbmi.js -- computes body mass index -- March 27, 2005
   form object has controls for:
   w is input control for weight (in pounds),
   h is input control for time (in inches),
   mw is output control for weight in kilos,
   mh is output control for height in metres,
   bmi is output control for finished computation.
   created by john russell, ve3ll@rac.ca */
/* checked with jslint 2006 05 29 */

function roundoff(x,y){
	scale=Math.pow(10,y);
	return Math.round(x*scale)/scale;
	}

function clrForm(formObj){
w=document.getElementById(formObj+'w');
h=document.getElementById(formObj+'h');
mw=document.getElementById(formObj+'mw');
mh=document.getElementById(formObj+'mh');
bmi=document.getElementById(formObj+'bmi');
w.value=" ";
h.value=" ";
mw.value=" ";
mh.value=" ";
bmi.value=" ";
	}

function clrFormM(formObj){
w=document.getElementById(formObj+'Stone');
h=document.getElementById(formObj+'Feet');
mw=document.getElementById(formObj+'Pounds');
mh=document.getElementById(formObj+'Inch');
bmi=document.getElementById(formObj+'bmiM');
Stone.value=" ";
Feet.value=" ";
Pounds.value=" ";
Inch.value=" ";
bmiM.value=" ";
	}

function bodymass(formObj){ // validate before math
Stone=document.getElementById('calcStone');
Feet=document.getElementById('calcFeet');
bmiM=document.getElementById('calcbmi');
weightStone=Stone.value;


weight=weightStone;

heightFeet=Feet.value;

height=heightFeet;

if (weight.length<1){
	alert("You must set weight!!!");
	Stone.focus();return;
	}
if (isNaN(weight)===true){
	alert("Weight must be a number!!!");
	Stone.focus();return;
	}
if (weight<25){
   alert("Weight must be greater than 25 Pounds!!!");
   Stone.focus();
   return;
   }
if (height.length<1){
	alert("You must set height!!!");
	Feet.focus();
	return;
	}
if (isNaN(height)===true){
	alert("Height must be a number!!!");
	Feet.focus();
	return;
	}
if (height<24){
   alert("Height must be greater than 24 inches!!!");
   Feet.focus();
   return;
   }
height=(height*1)/100;
metricbmi=(weight/(height * height));
bmiM=roundoff(metricbmi,2);
document.getElementById('calcbmi').innerHTML=bmiM;

}

function bodymassM(formObj){ // validate before math

Stone=document.getElementById('calcStone');
Feet=document.getElementById('calcFeet');
Pounds=document.getElementById('calcPounds');
Inch=document.getElementById('calcInch');
bmiM=document.getElementById('calcbmi');
weightStone=Stone.value;

weightPounds=Pounds.value;
weightPounds2=weightPounds*1;
weightStone2=weightStone*14;
weight=(weightPounds *1 ) + (weightStone2 *1);

heightFeet=Feet.value;
heightInch=Inch.value;
heightInch2=heightInch*1;
heightFeet2=heightFeet*12;
height=(heightFeet2*1) + (heightInch2*1);
if (weight.length<1){
	alert("You must set weight!!!");
	Stone.focus();return;
	}
if (isNaN(weight)===true){
	alert("Weight must be a number!!!");
	Stone.focus();return;
	}
if (weight<25){
   alert("Weight must be greater than 25 Pounds!!!");
   Stone.focus();
   return;
   }
if (height.length<1){
	alert("You must set height!!!");
	Feet.focus();
	return;
	}
if (isNaN(height)===true){
	alert("Height must be a number!!!");
	Feet.focus();
	return;
	}
if (height<24){
   alert("Height must be greater than 24 inches!!!");
   Feet.focus();
   return;
   }
metricw=weight/2.2046;
metrich=height*2.54/100;
metricbmi=((weight*703)/(height * height));
bmiM=roundoff(metricbmi,2);
document.getElementById('calcbmi').innerHTML=bmiM;
}
function bmichange()
{

	d=document.getElementById('BMIlink').title;

if(d=="1"){

	document.getElementById('BMIlink').onclick=bodymass;
	document.getElementById('BMIlink').title='2';
	document.getElementById('bmiBox').style.background='url(images/BMI2.png) center no-repeat';
		document.getElementById('buttonstofill').innerHTML='<input name="" id="calcFeet" type="text" style="margin-left:66px;" /><div class="clear"></div><div class="bimsectiongap"></div> <input name="" id="calcStone" type="text" style="margin-left:66px;" />';
	
	}
else if(d=="2"){

	document.getElementById('BMIlink').onclick=bodymassM;
	document.getElementById('BMIlink').title='1';
	document.getElementById('bmiBox').style.background='url(images/BMI.png) center no-repeat';
document.getElementById('buttonstofill').innerHTML='<input name="" id="calcFeet" type="text" style="margin-left:26px;" /><input name="" id="calcInch" type="text" style="margin-left:34px;" /> <div class="clear"></div><div class="bimsectiongap"></div> <input name="" id="calcStone" type="text" style="margin-left:26px;" /><input name="" id="calcPounds" type="text" style="margin-left:34px;" />';
	
	}
}

function eggs(){ alert('hi');}