function ModifyHeightUnit()
{
	var flag
	if (document.BMIForm.heighttype.value=="feet")
		{
 			 document.getElementById("selec").innerHTML='<select size="1" name="height"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>&nbsp;&nbsp;<select size="1" name="inches"><option value="0">0&quot;</option><option value="1">1&quot;</option><option value="2">2&quot;</option><option value="3">3&quot;</option><option value="4">4&quot;</option><option value="5">5&quot;</option><option value="6">6&quot;</option><option value="7">7&quot;</option><option value="8">8&quot;</option><option value="9">9&quot;</option><option value="10">10&quot;</option><option value="11">11&quot;</option></select>'		 
		}
	else
		{
	    document.getElementById("selec").innerHTML ='<input size="5" name="height"/><input type="hidden" value="0" name="inches"/>'
		}
}
				
function ComputeBMI(form, height, weight, inches)
{
	if (document.BMIForm.weight.value=="")
	{
		alert("Enter Weight");
		document.BMIForm.weight.focus();
		return false;
	}
	if (inches=="")
	{ 	
		inches=0
 	}
	htype=document.BMIForm.heighttype.value
	wtype=document.BMIForm.weighttype.value

	if (wtype=='lb')
	{
		weight=weight*0.454
	}

	if (htype=='feet')
	{
  	height=document.BMIForm.height.value
	  inches=document.BMIForm.inches.value
		height=(height * 30) + (inches * 2.54)
	}
 	bmi = (weight / ((height/100)*(height/100)))

	if (bmi < 19)
	{ 
	bmitype = "Underweight"
	}
	if ((bmi >=19) && (bmi < 25))
	{
 	bmitype = "Normal"
  }
	if ((bmi >=25) && (bmi < 30))
	{
	bmitype = "Overweight"
	}
	if (bmi >= 30)
	{
		bmitype = "Obese"
	}

	ybmi = round(bmi,2);
	document.getElementById("s").innerHTML='<br/><font face="arial" size="3"><b>Your BMI is <font color="red">' + ybmi+'</font><br/><br/> You are ' + bmitype +'</b></font>';
	if (bmi >= 25)
	{
		red_weight = round((weight - 25*((height/100)*(height/100))), 2);
		if (wtype=='lb')
		{
			red_weight = round (red_weight * 2.2, 2);
		}
		document.getElementById("s").innerHTML+='<br/><font face="arial" size="3" color="red"><b>Reduce your weight by ' + red_weight + ' ' + wtype + '</b></font>';
	}

	if (bmi < 19)
	{
		incr_weight = round(19*((height/100)*(height/100)) - weight, 2);
		if (wtype=='lb')
		{
			incr_weight = round (incr_weight * 2.2, 2);
		}
		document.getElementById("s").innerHTML+='<font face="arial" size="3" color="red"><b><br/>Increase your weight by ' + incr_weight	+ ' ' + wtype + '</b></font>';	
	}
}

function round(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else { 
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


