var count=8;
// function to add mutiple custom met

ischanged = 0;
ishchanged = 0;

function add()
{
	count++;
	document.getElementById('tr'+count).style.display = '';
}
function calcchangeM()
{
	document.getElementById('imperial_row').style.display='none';
	document.getElementById('metric_row').style.display='';


	ischanged=1;
	document.getElementById('weight_unit').value=1;
	document.getElementById('height_unit').value=1;
	document.getElementById('wuspan').innerHTML='In Kilogram';
	document.getElementById('spanhu').innerHTML='In Centimetre';
	calc();
	
}

function calcchangeI()
{
	document.getElementById('metric_row').style.display='none';
	document.getElementById('imperial_row').style.display='';
ischanged=1;
	
	document.getElementById('weight_unit').value=2;
	document.getElementById('height_unit').value=2;
	document.getElementById('wuspan').innerHTML='In Pound';
	document.getElementById('spanhu').innerHTML='In Inches';
	calc();
}

function calc()
{

	
	var age = document.getElementById("age").value; // fetch age from textbox
	var height = document.getElementById("height").value; // fetch height from textbox
	var weight = document.getElementById("weight").value; // fetch weight from textbox
	
	// to convert in pound if pound selected
	if(ischanged==1)
	{
		if(document.getElementById("weight_unit").value==2)
		{
			weight = weight * 22.0462262;
			document.getElementById("weight").value = (Math.round(weight)/10);
		}
		else
		{
			weight = weight / 0.220462262;
			document.getElementById("weight").value = (Math.round(weight)/10);
			weight = weight / 10;
		}
		ischanged=0;
	}
	
	if(document.getElementById("weight_unit").value==2)
	{
		weight = document.getElementById("weight").value / 2.20462262;
		
	}
	
	if(document.getElementById("height_unit").value==2)
	{
		var height2,height3;
		if(document.getElementById("height2").value=="")
			height2="0";
		else
			height2=document.getElementById("height2").value;
		if(document.getElementById("height3").value=="")
			height3="0";
		else
			height3=document.getElementById("height3").value;
			
		
		height = Math.round(height2*12);
		height = eval(height + '+' + +height3)
		height = Math.round(height * 2.54); 
		
		document.getElementById("height").value = Math.round(height);
		document.getElementById("height").style.display = 'none';
		document.getElementById("heights").style.display = '';
		
	}
	else
	{
		
		if(document.getElementById("height").value=="")
			height="0";
			

		var heightTemp = height * 0.393700787; 
		heightTemp=Math.round(heightTemp);

		document.getElementById("height2").value = Math.floor(heightTemp / 12);
		document.getElementById("height3").value = heightTemp % 12;	
		
		document.getElementById("height").style.display = '';
		document.getElementById("heights").style.display = 'none';
		
	}
	
	if(height==0)
	{
		return true;
	}
	
	var heightM = height/100;
	
	var BMI; // variable declation
	
	
	
	
	// returning
	if(weight=="" || height=="")
		return true;
	
	BMI = (weight / (heightM * heightM)); // calculating BMI
	
	BMI = BMI*10;
	BMI = Math.round(BMI); // rounding BMI
	BMI = BMI / 10;
	document.getElementById("BMIValue").innerHTML = BMI;
	
	

	
	
}


function runwalk() {
	  
	  var minutes2 = document.getElementById("minutes2").value;
	  var seconds2 = document.getElementById("seconds2").value;
	  var time2;
	  var votwomax3;
	  
	  if(minutes2=='')
	  {
		  	alert("Enter Minute");
	  	return false;
	  }

		
	  if(seconds2 =='')
	  {
		 alert("Enter Second");
	  	return false;
	  }

	  minutes2 = minutes2.trim();
	  seconds2 = seconds2.trim();
	  
	  minutes2 = Number(minutes2);
	  seconds2 = Number(seconds2);
	  time2 = Number(time2);
	  votwomax3 = Number(votwomax3);
	  
		 
	  
	  time2 = minutes2 + seconds2/60;
		
	  votwomax3 = Math.round((483/time2) + 3.5);
	  
	  document.getElementById("outputdisplay3").innerHTML = "Your estimated VO2max is " + votwomax3 + " ml/kg/min.";
	  
	  }
