


function CalculateBmi(){

	var weightInKilos;
	var weightInPounds;
	
	var heightInCms;
	var heignInInches;
	
	var inputWeight = document.getElementById("WeightAmount");
	var inputWeightUnits = document.getElementById("WeightUnits");
	
	var inputHeight = document.getElementById("HeightAmount");
	var inputHeightUnits = document.getElementById("HeightUnits");
	
	if(!FormValidation(inputWeight, inputHeight)){return;}
	
	
	if(inputWeightUnits.value.toLowerCase() == "kg"){
		
		weightInKilos = inputWeight.value;
		weightInPounds = Math.round(weightInKilos*2.2);
	
	}else{
	
		weightInPounds = inputWeight.value;
		weightInKilos = Math.round(weightInPounds/2.2);
	
	}
	
	if(inputHeightUnits.value.toLowerCase() == "cm"){
	
		heightInCms = inputHeight.value;
		heightInInches = Math.round(inputHeight.value/2.54);
	
	}else{
	
		heightInInches = inputHeight.value;
		heightInCms = Math.round(inputHeight.value*2.54)
	
	}

	var bmi = weightInKilos/eval((heightInCms/100)*(heightInCms/100));
	
	bmi = ((Math.round(bmi*10))/10);
	
	DisplayBmi(bmi);

}




function DisplayBmi(bmi){

	var outputBmiSpan = document.getElementById("OutputBmi");
	
	var bmiResult = bmiCategory(bmi);
	
	var lipotrimRec = "";
	
	if(bmi > 25 && bmi < 30){
		lipotrimRec = "Lipotrim may be<br/>useful to you.";
	}else if (bmi >= 30){
		lipotrimRec = "Lipotrim should be<br/>seriously considered.";
	}
	
	outputBmiSpan.innerHTML = "<a href=\"bmicalculator.htm?bmi=" + bmi + "\" title=\"\">Your BMI is " + bmi + "</a><br/><br/>Your rating is:<br/>" + bmiResult + ".<br/><br/>" + lipotrimRec;

}


function bmiCategory(bmi){

	var bmiCategory = "";

	if(bmi < 20){
		bmiCategory = "Underweight";
	}
	else if(bmi >= 20 && bmi <= 25){
		bmiCategory = "Healthy";
	}
	else if(bmi > 25 && bmi <= 30){
		bmiCategory = "Overweight";
	} 
	else if(bmi > 30 && bmi <= 35){
		bmiCategory = "Obese";
	}
	else if(bmi > 35 && bmi <= 40){
		bmiCategory = "Super Obese ";
	} 
	else if(bmi > 40 && bmi <= 45){
		bmiCategory = "Morbid Obese";
	} 
	else if(bmi > 45 && bmi <= 50){
		bmiCategory = "Super Morbid Obese";
	} 
	else{
		bmiCategory = "Super Super Morbid Obese";
	} 				 
	
	return bmiCategory;

}


function FormValidation(inputWeight, inputHeight){


	var isValid = true;
	
	var weight = inputWeight.value;
	var height = inputHeight.value;
	
	//Check for empty values
	if(weight == "" || height == ""){
		return false;
	}
	
	//Check for non-numeric values

	
	//Check for negative values or silly large values
	
	
	return isValid;



}
