function calcAE(){
	var age = document.getElementById("age").value;
	var weight = document.getElementById("weight").value;
	if (document.getElementById("male").checked == true){var gender = document.getElementById("male").value}else{var gender = document.getElementById("female").value}
	var heartRate = document.getElementById("heartrate").value;
	var minutes = document.getElementById("minutes").value;
	var seconds = document.getElementById("seconds").value;

	var error = ''
	var check = false;

	if (age == ''){error += "Age cannot be blank.\n";check=true;}
	if (weight == ''){error += "Weight cannot be blank.\n";check=true;}
	if (heartRate == ''){error += "Heart rate cannot be blank.\n";check=true;}
	if (minutes == ''){error += "Time cannot be blank.\n";check=true;}

	if(isNaN(age) == true && age != ''){error += "Age must be a number.\n";check=true;}
	if(isNaN(weight) == true && weight != ''){error += "Weight must be a number.\n";check=true;}
	if(isNaN(heartRate) == true && heartRate != ''){error += "Heart rate must be a number.\n";check=true;}
	if(isNaN(minutes) == true && minutes != ''){error += "Minutes must be a number.\n";check=true;}
	if(isNaN(seconds) == true && seconds != ''){error += "Seconds must be a number.\n";check=true;}

	if ((age > 120 || age < 20) && age != ''){error += "Age must be in the range 5-120.\n";check=true;}
	if ((weight > 600 || weight) < 50 && weight != ''){error += "Weight must be in the range 50-600.\n";check=true;}
	if ((heartRate > 300 || heartRate) < 30 && heartRate != ''){error += "Heart rate must be in the range 30-300.\n";check=true;}
	if ((minutes > 59 || age < 1) && minutes != ''){error += "Minutes must be in the range 1-59.\n";check=true;}
	if ((seconds > 59 || seconds < 1) && seconds != ''){error += "Seconds must be in the range 1-59.\n";check=true;}

	var rating = 0;
	if (check == false){
		var time = (parseFloat(minutes) + (seconds / 60))
		var vo2max = Math.abs((132.853 - (0.1692 * (weight * 0.45359237)) - (0.3877 * age) + (6.315 * gender) - (3.2649 * time) - (0.1565 * heartRate)))
		var vo2max = Math.round(vo2max * 10)/10
		var met = Math.round(vo2max / 3.5 * 10)/10

		document.getElementById('ac').innerHTML =  vo2max + ' ml/kg/min';
		document.getElementById('mets').innerHTML = met + ' METs';

		if (gender == 1){ //male
			if (age > 19 && age < 30){
				if (vo2max < 37.1){rating = 1;}
				if (vo2max > 37 && vo2max < 44.3){rating = 2;}
				if (vo2max > 44.3){rating = 3;}
			}
			else if (age > 29 && age < 40){
				if (vo2max < 35.3){rating = 1;}
				if (vo2max > 35.2 && vo2max < 42.5){rating = 2;}
				if (vo2max > 42.4){rating = 3;}
			}
			else if (age > 39 && age < 50){
				if (vo2max < 33){rating = 1;}
				if (vo2max > 32.9 && vo2max < 40){rating = 2;}
				if (vo2max > 39.9){rating = 3;}
			}
			else if (age > 49 && age < 60){
				if (vo2max < 31.4){rating = 1;}
				if (vo2max > 31.3 && vo2max < 39.4){rating = 2;}
				if (vo2max > 42.4){rating = 3;}
			}
			else if (age > 59){
				if (vo2max < 28.3){rating = 1;}
				if (vo2max > 28.2 && vo2max < 36.2){rating = 2;}
				if (vo2max > 36.1){rating = 3;}
			}
		}
		else { //female
			if (age > 19 && age < 30){
				if (vo2max < 30.6){rating = 1;}
				if (vo2max > 30.5 && vo2max < 36.7){rating = 2;}
				if (vo2max > 36.6){rating = 3;}
			}
			else if (age > 29 && age < 40){
				if (vo2max < 28.7){rating = 1;}
				if (vo2max > 28.6 && vo2max < 34.7){rating = 2;}
				if (vo2max > 34.6){rating = 3;}
			}
			else if (age > 39 && age < 50){
				if (vo2max < 26.5){rating = 1;}
				if (vo2max > 26.4 && vo2max < 32.4){rating = 2;}
				if (vo2max > 32.3){rating = 3;}
			}
			else if (age > 49 && age < 60){
				if (vo2max < 25.1){rating = 1;}
				if (vo2max > 25 && vo2max < 31.4){rating = 2;}
				if (vo2max > 31.3){rating = 3;}
			}
			else if (age > 59){
				if (vo2max < 21.9){rating = 1;}
				if (vo2max > 21.8 && vo2max < 28.3){rating = 2;}
				if (vo2max > 28.2){rating = 3;}
			}
		}

		document.getElementById('rating').innerHTML = '';
		if (rating == 1){document.getElementById('rating').innerHTML = 'Low fitness (High Risk)';}
		if (rating == 2){document.getElementById('rating').innerHTML = 'Moderate fitness (Average Risk)';}
		if (rating == 3){document.getElementById('rating').innerHTML = 'High fitness (Low Risk)';}

		document.getElementById('ratingInfo').style.visibility ='visible'
	}
	else {alert (error)}
}
