function calc()
{
	var wt = document.bmi.wg.value;
	var ht = document.bmi.ht.value;si
	
	var op=document.bmi.opt1.value;
	
	//SI value
	var h = ht/100;
	var si = Math.round((wt/(h*h))*100)/100;
	document.bmi.si.value = si;
	
	//US value
	//var lb = wt*2.2;
	//var ic = ht*0.39;
	//var us = Math.round((703*(lb/(ic * ic)))*100)/100;
	//document.bmi.us.value = us;
	
	//UK value
	//var uk = Math.round((6.35*si)*100)/100;
	//document.bmi.uk.value = uk;
	
	//If value is not given for weight
	if(wt=="")
	{
		alert("Enter the value for weight");
	}

	//If weight is less than 10
	else if(wt<=10)
	{
		document.bmi.si.value = 0;
		//document.bmi.us.value = 0;
		//document.bmi.uk.value = 0;
		alert("Weight should be greater than 10kgs");
	}
	
	//If weight is pounds and less than 22lbs
	else if(op=="pounds" && wt<=22)
	{
		document.bmi.si.value = 0;
		//document.bmi.us.value = 0;
		//document.bmi.uk.value = 0;
		alert("Weight should be greater than 22lbs");
	}
	
	//If given height is less than 33cms
	else if(ht<33)
	{
		document.bmi.si.value = 0;
		//document.bmi.us.value = 0;
		//document.bmi.uk.value = 0;
		alert("Height should be taller than 33cms");
	}
	else if(op=="pounds")
	{
		document.bmi.si.value=Math.round((si/2.2)*100)/100;
		//document.bmi.us.value=Math.round((us/2.2)*100)/100;
		//document.bmi.uk.value=Math.round((uk/2.2)*100)/100;
	}
	var d = "";
	var clr_code="";
	
	if(si<18.5)
	{	    
		document.bmi.desc.value= d + "Under Weight. Your BMI indicating your weight is in the under weight category for the adults of your height. Being under weight may weaken your immune system and put you at greater risk for nutritional deficiency disease and osteoporosis. To achieve healthy weight, embrace healthy eating by choosing a variety of calorie and nutrient rich foods and strength training exercises to promote lean muscle development.Contact VLCC for Consultation.";
		document.bmi.desc.style.color='#ff0000';
		clr_code="ff0000";		
	}
	else if(si>18.5 && si<=24.9)
	{
	   document.bmi.desc.value= d + "Normal. Congratulations! Your healthy weight is well worth the effort. It reduces your risk of developing serious health conditions such as blood pressure, heart disease, stroke and diabities.";
		document.bmi.desc.style.color='#479300';
		clr_code="479300";	
	}
	else if(si>25 && si<=29.9)
	{	
	    document.bmi.desc.value= d + "Over Weight. Your BMI indicating your weight is in the over weight category for the adults of your height. Being over weight may increase the risk of health problems such as high BP, high blood cholestrol, heart disease. Contact VLCC for Consultation.";
		document.bmi.desc.style.color='#ff0000';
		clr_code="ff0000";	
	}
	
         else if(si>30 && si<=34.9)
        {
        
		document.bmi.desc.value=d + "Obese Class I. Your BMI indicating your weight is in the obese category for adults of your height. Consider the benefits of achieving a healthy weight - a reduced risk of health conditions such as high blood pressure, diabetes and heart disease with improved lifestyle and self esteem. Contact VLCC for Consultation.";
		document.bmi.desc.style.color='#ff0000';
		clr_code="ff0000";	
	}
	else if(si>30 && si<=34.9)	
        {
        
	document.bmi.desc.value=d + "Obese Class II. Your BMI indicating your weight is in the obese category for adults of your height. Consider the benefits of achieving a healthy weight - a reduced risk of health conditions such as high blood pressure, diabetes and heart disease with improved lifestyle and self esteem. Contact VLCC for Consultation.";
		document.bmi.desc.style.color='#ff0000';
		clr_code="ff0000";	
	}
       else if(si>40)
        {
        
	document.bmi.desc.value=d + "Obese Class III. Your BMI indicating your weight is in the obese category for adults of your height. Consider the benefits of achieving a healthy weight - a reduced risk of health conditions such as high blood pressure, diabetes and heart disease with improved lifestyle and self esteem. Contact VLCC for Consultation.";
		document.bmi.desc.style.color='#ff0000';
		clr_code="ff0000";	
        }
        
      if(document.bmi.desc.value!="")
       {
         var url='BMI_Calc_result.aspx?cd=' + clr_code;
	document.bmi.action=url;
	document.bmi.submit();        
        }
       
}


function conv(aa)//Height conversion
{
	var ft=0, inc=0, ht=0;
	if(aa==1 || aa==2)
	{
		ft = document.bmi.opt2.value;
		inc = document.bmi.opt3.value;
		var ss = ft*12;
		var tot = ss+parseInt(inc);
       	var val= tot*2.54;
		document.bmi.ht.value = Math.round(val);
	}

	else{
		ht = document.bmi.ht.value;
		if(ht!="")
		{
			var cm=Math.round(ht/2.54);
			var div=parseInt(cm/12);
			var md=cm%12;
			document.bmi.opt2.value=div;
			document.bmi.opt3.value=md;
		}
         }

}


function unit()  //Weight conversion
{
	var pp=document.bmi.opt1.value;
	var ww = document.bmi.wg.value;
	
	//Kilogram to pounds
	if(pp=="pounds")	
	{
		document.bmi.wg.value = Math.round((ww*2.2)*100)/100;
	}

	//Pounds to kilograms
	else
	{
		document.bmi.wg.value=Math.round(ww/2.2);
	}
}



function unitCalorie()
{
    var pp;

    var s= getXXX();
    if(s==0)
    {
     pp = "P";
    }
    else
    {
     pp = "K";
    }
   
	var ww = document.bmi.txtWeight.value;
	
	//Kilogram to pounds
	if(pp=="P")	
	{
		document.bmi.txtWeight.value = Math.round((ww*2.2)*100)/100;
	}

	//Pounds to kilograms
	else
	{
		document.bmi.txtWeight.value=Math.round(ww/2.2);
	}
}

function getXXX()
{
 for (var i=0; i<document.bmi.radio2.length; i++){ 
 if (document.bmi.radio2[i].checked) { return i }
 }
}

function getXX()
{
 for (var i=0; i<document.bmi.radio1.length; i++){ 
 if (document.bmi.radio1[i].checked) { return i }
 }
}


function calCalorie()
{
 
  var pp="";
  var gender= getXX();
  
  
  var memberage=document.getElementById("age").value;        
  var hf=document.getElementById("txtFeet").value;
  var hi=document.getElementById("txtInches").value;
  var w=document.getElementById("txtWeight").value;


//  var memberage=document.bmi.age.value;
//  var hf=document.bmi.txtFeet.value;
//  var hi=document.bmi.txtInches.value;
//  var w=document.bmi.txtWeight.value;
    
  if((memberage=="")||(hf=="")||(w==""))
    {
        if (memberage == "") 
        {
        alert("You have not filled in the age field.");
        return false;
        }
        if (hf == "") 
        {
        alert("You have not filled in the height field.");
        return false;
        }
        if (w == "") 
        {
        alert("You have not filled in the weight field.");
        return false;
        }
    }
    
   if(gender==0)
   {
      var j = 12 * hf; 
      if (hi =="")
      {hi=0;}
      var i =parseFloat(parseInt(j) + parseInt(hi));
      //var reccalories = 1.375 * (66 + (13.7 * (parseFloat(w))) + (2.54 * 5 * i) - (6.8 * (parseFloat(memberage))));
      //var reccalories = 1.375 * (66 + (13.7 * (parseFloat(w))) + (2.54 * 5 * i) - (6.8 * (parseFloat(memberage))));
      
      var reccalories = 66 + (13.7 * (parseFloat(w))) + (2.54 * 5 * i) - (6.8 * (parseFloat(memberage)));     
       
       
      rounded=reccalories*100;rounded = Math.round(rounded);
      strrounded = "" + rounded;len = strrounded.length;
      totalreccalories=(strrounded.substring(0, len - 2) + "." + strrounded.substring(len - 2, len));
   }
   else
   {
      var j = 12 * hf; if (hi =="")
      {hi=0;}
      var i =parseFloat(parseInt(j) + parseInt(hi));
      //var reccalories = 1.375 * (655 + (9.6 * (parseFloat(w))) + (2.54 * 1.8 * (i)) - (4.7 * (parseFloat(memberage))));
      //var reccalories = 1.375 * (655 + (9.6 * (parseFloat(w))) + (2.54 * 1.8 * (i)) - (4.7 * (parseFloat(memberage))));
      
      var reccalories = 655 + (9.6 * (parseFloat(w))) + (2.54 * 1.8 * (i)) - (4.7 * (parseFloat(memberage)));    
      
      
      
      rounded=reccalories*100;rounded = Math.round(rounded);
      strrounded = "" + rounded;len = strrounded.length;
      totalreccalories=(strrounded.substring(0, len - 2) + "." + strrounded.substring(len - 2, len));
   }
   document.getElementById('result').innerHTML="<font color='green'>Your recommended calorie intake daily should be </font><font color='red'>"+Math.round(totalreccalories)+"</font><font color='green'> Calories.</font>";
   document.getElementById('tdresult').style.display= "block";
   document.getElementById('footerad').style.display = "block";
  return false;
}


function fnTab(tblObject)
{
  
  if(tblObject=="tblCalories")
  {
     document.getElementById("tblCalories").style.display='none';
     document.getElementById("tblBMI").style.display='inline';
  }
  if(tblObject=="tblBMI")
  {
     document.getElementById("tblCalories").style.display='inline';
     document.getElementById("tblBMI").style.display='none';
  }
}
