function ShowCalculate()
{
	if(!chkw(document.getElementById("weight").value))
	{
		alert("Please enter a number for your weight.");
		return;
	}
	if(!chkh(document.getElementById("height").value))
		{
			return;
	}
	Compute(document.getElementById("weight").value,document.getElementById("height").value)
	document.getElementById("calculate").style.display="none";
	document.getElementById("calculateagain").style.display="block";
}

function ReCalculate()
{
	if(!chkw(document.getElementById("weight1").value))
	{
		alert("Please enter a number for your weight.");
		return;
	}
	if(!chkh(document.getElementById("height1").value))
		{
			alert("Please enter a number for your height.");
			return;
	}
	Compute(document.getElementById("weight1").value,document.getElementById("height1").value)
}

function Compute(w,h){
	var ht  =new Array();
	ht = h.split("."); 
	var ft = ht[0]*12;
	var tot = ft+parseInt(ht[1]);	
    var val= parseInt(tot)*2.54;
    var totht = Math.round(val);
	//SI value
	var he = totht/100;
	var bmi = Math.round((w/(he*he))*100)/100;	


if(bmi < 18)
{
	
	document.getElementById("ksuggestion").innerHTML	="<div style='background: #dbeaf4; padding: 10px;'><h3>Great! You don't need the challenge just yet!</h3><p>Guess what? Results from the BMI calculator show that you have a low estimated BMI, suggesting that you are below the optimum weight for your height. Sorry, but the Kellogg's Special K 2 Weeks' Challenge is not recommended for you!</p></div>"

}
if(bmi >= 18 && bmi <= 25 )
{
		document.getElementById("ksuggestion").innerHTML	="<div style='background: #eef1cc; padding: 10px;'><h3>Hurray! Your BMI is normal.</h3><p>Results from the BMI calculator show that your BMI falls between 18 to 25. In other words you have the perfect balance between your weight and height. Obviously for a woman as fit as you, Kellogg's Special K 2 Weeks' Challenge is not required. However, you might want to kick-start your day with a bowl of cereal for breakfast and replace your lunch OR dinner with another bowl from time to time to maintain your envious proportions. </p></div>"

}
if( bmi > 25 )
{
	document.getElementById("ksuggestion").innerHTML	="<div style='background: #fbd2d3; padding: 10px;'><h3>This challenge is for you!</h3><p>Ok.  Results from the BMI calculator show that you have an estimated BMI greater than 25. The Kellogg's Special K  2 Weeks' Challenge can help you lose up to 2 1/2 kilos in 2 weeks to help you with the first steps towards a new, healthier you!</p><p style='margin-top: 8px;'><a href='DietPlan.aspx'><img src='image/bmi/take-the-challenge.gif' alt='Take The Challenge' title='Take The Challenge' border='0' /></p></div>"
}

document.getElementById("urbmi").innerHTML  = bmi
document.getElementById("urweight").innerHTML = w+"kgs";
document.getElementById("height1").value = h;
document.getElementById("weight1").value = w;
}

function chkw(w){
   if (isNaN(parseInt(w))){
      return false;
   } else if (w < 0){
  return false;
  }
  else{
  return true;
  }
  }
function chkh(height){
	
    if (height.indexOf('.') == -1) 
    {
    	alert("Please make sure you add decimals for Height \n");
    	return false;
    }
    if (height.length == 0 || !isNumber(height) || !isPositiveNumber(height)) 
    {
      alert("Please enter a valid: Height \n");
      return false;
    }
	return true;
}

function isNumber(n) {
		return !isNaN(Number(n));
	}

	function isPositiveNumber(n) {
		return Number(n) > 0;
	}