function calcIt()
{
//validasi dulu

	if(isNaN(document.getElementById("age").value)||document.getElementById("age").value=="")
	{
		alert("please use number only to input your age");
		document.getElementById("age").focus();
		return false;
	 }
	
	if(isNaN(document.getElementById("height").value)||document.getElementById("height").value=="")
	{
		alert("please use number only to input your height");
		document.getElementById("height").focus();
		return false;
	 }

 	if(isNaN(document.getElementById("weight").value)||document.getElementById("weight").value=="")
	{
		alert("please use number only to input your weight");
		document.getElementById("weight").focus();
		return false;
	 }
//start counting
var bmi;
	if(document.getElementById("height_index").value=="inch")
	{//cek apakah satuan berat adalah kilogram
		if(document.getElementById("weight_index").value=="kg")
		{//error, karena harus menggunakan pounds
			alert("Sorry. If you use inch as your height index, then you must use pounds as your weight index");
			document.getElementById("weight_index").focus();
			return false;
		}
		else
		{//process for male
				bmi=(document.getElementById("weight").value/(document.getElementById("weight").value*document.getElementById("height").value))*703;
		}
	}
	else if((document.getElementById("height_index").value=="m")||(document.getElementById("height_index").value=="cm"))
	{//cek apakah satuan berat adalah kilogram
		if(document.getElementById("weight_index").value=="pounds")
		{//error, karena harus menggunakan pounds
			alert("Sorry. If you use m or cm as your height index, then you must use kilograms as your weight index");
			document.getElementById("weight_index").focus();
			return false;
		}
		else
		{//process 
			//convert cm to meter
			var h;
			if(document.getElementById("height_index").value=="cm")
			{			h=document.getElementById("height").value/100;}
			else
			{			h=document.getElementById("height").value;}
				bmi=document.getElementById("weight").value/(h*h);
		}

	}
var stat;
//tentukan bmi-nya melalui tabel
		if(document.getElementById("age").value<=6)
		{
			if(bmi<=15)
			{stat="underweight";	}
			else if (bmi<=17)
			{stat="median";}
			else if(bmi<=19)
			{stat="overweight";}
			else if(bmi>=20)
			{stat="obese";}		
		}
		else if(document.getElementById("age").value<=11)
		{
			if(bmi<=14)
			{stat="underweight";	}
			else if (bmi<=16)
			{stat="median";}
			else if(bmi<=18)
			{stat="overweight";}
			else if(bmi>=18)
			{stat="obese";}		
		}
		else if(document.getElementById("age").value<=15)
		{
			if(bmi<=16)
			{stat="underweight";	}
			else if (bmi<=18)
			{stat="median";}
			else if(bmi<=22)
			{stat="overweight";}
			else if(bmi>=22)
			{stat="obese";}		
		}
		else //adult
		{	
			if(bmi<=17.5)
			{stat=" <font color=red>Anorexia</font> ";	}
			else if (((document.getElementById("sex").value=="F")&&(bmi<18.5))||((document.getElementById("sex").value=="M")&&(bmi<18.5)))
			{	stat=" <font color=red>Under Weight</font> ";}
			else if (((document.getElementById("sex").value=="F")&&(bmi>=18.5)&&(bmi<=22.9))||((document.getElementById("sex").value=="M")&&(bmi>=18.5)&&(bmi<=22.9)))
			{	stat=" <font color=blue>In normal range</font> ";}
			else if (((document.getElementById("sex").value=="F")&&(bmi>=23.0)&&(bmi<=25.9))||((document.getElementById("sex").value=="M")&&(bmi>=23.0)&&(bmi<=25.9)))
			{	stat=" <font color=blue>Over Weight</font> ";}
			else if (((document.getElementById("sex").value=="F")&&(bmi>=26.0))||((document.getElementById("sex").value=="M")&&(bmi>=26.0)))
			{	stat=" <font color=red>Obese</font> ";}

		}
	document.getElementById("icon").bgColor="#74B71B";
	document.getElementById("message").innerHTML='<b><font color="#737373" size="2">Result</font></b>';
	document.getElementById("message").bgColor="#FFFFFF";
	document.getElementById("bmi").innerHTML='<font size=2 color=black>BMI:'+bmi.toString().slice(0,5)+' ('+stat+')';

}
