function checkNum(thisChar) {
	if((thisChar != '0') &&
	(thisChar != '1') &&
	(thisChar != '2') &&
	(thisChar != '3') &&
	(thisChar != '4') &&
	(thisChar != '5') &&
	(thisChar != '6') &&
	(thisChar != '7') &&
	(thisChar != '8') &&
	(thisChar != '9')) {
	return false;
	}
	else {
	return true;
	}
}

function checkValue(thisString) {
var isNum = true;
var stringLen = thisString.length;
	if(stringLen == 0) {
	isNum = false;
	}
	else {
		for(count = 0; count < stringLen; count++) {
			if(!(checkNum(thisString.charAt(count)))) {
			isNum = false;
			break;
			}
		}
	}
	return isNum;
}



function calculateBodyFat() {
form = document.bfi;
weight = form.Weight.value;
waist = form.Waist.value;
wrist = form.Wrist.value;
hips = form.Hips.value;
forearm = form.Forearm.value;
isFemale = 0;
bodyfat = 0;
	if(form.Gender[1].checked) {
	isFemale = 1;
	}
formInvalid = 0;
field1 = '';
field2 = '';
field3 = '';
field4 = '';
field5 = '';
	if(!(checkValue(weight))) {
	field1 = 'weight in pounds, ';
	formInvalid = 1;
	}
	if(!(checkValue(waist))) {
	field2 = 'waist size, ';
	formInvalid = 1;
	}
	if(!(checkValue(wrist)) && isFemale) {
	field3 = 'wrist circumference, ';
	formInvalid = 1;
	}
	if(!(checkValue(hips)) && isFemale) {
	field4 = 'hips circumference, ';
	formInvalid = 1;
	}
	if(!(checkValue(forearm)) && isFemale) {
	field5 = 'forearm circumference, ';
	formInvalid = 1;
	}
	if(formInvalid) {
	message = 'Please enter the following required information: ' + field1 + field2 + field3 + field4 + field5;
	message = message.substring(0, (message.length - 2)) + '.';
	alert(message);
	}
	else {
		if(isFemale) {
		bodyfat = ( (weight - ( ( ( ((weight * 0.732) + 8.987) + (wrist / 3.14) ) - (waist * 0.157) ) - (hips * 0.249) ) + (forearm * 0.434) ) * 100) / weight;
		}
		else {
		bodyfat = ((weight - (((weight * 1.082) + 94.42) - (waist * 4.15))) * 100) / weight;
		}
		if(!(isFemale)) {
		form.Wrist.value = '';
		form.Hips.value = '';
		form.Forearm.value = '';
		}
		form.BodyFat.value = Math.floor(bodyfat);
	}
}
