var firstErrorField = '';

function checkForm(form) {
	var alertText = '';
	firstErrorField = '';
	
	if (!form.name_of_baby.value) {
		alertText += "Please enter the baby's name.\n";
		checkFirstErrorField('name_of_baby');
	}
	if (!form.parents.value) {
		alertText += "Please enter the parents' names.\n";
		checkFirstErrorField('parents');
	}
	if (!form.date_of_birth.value) {
		alertText += "Please enter the date of birth.\n";
		checkFirstErrorField('date_of_birth');
	}	
	if (form.parents_town.selectedIndex < 1) {
		alertText += "Please select the parents' town.\n";
		checkFirstErrorField('parents_town');
	}
	if (!form.birth_facility.value) {
		alertText += "Please enter the name of hospital or birth facility.\n";
		checkFirstErrorField('birth_facility');
	}
	if (!form.contact_name.value) {
		alertText += "Please enter your name.\n";
		checkFirstErrorField('contact_name');
	}
	if (!form.contact_phone.value) {
		alertText += "Please enter a phone number where we can contact you.\n";
		checkFirstErrorField('contact_phone');
	}
	if (!form.contact_email.value) {
		alertText += "Please enter your email address.\n";
		checkFirstErrorField('contact_email');
	}
	else {
		if (!(emailCheck(form.contact_email.value))) {
			alertText += "Please enter a valid email address.\n";
			checkFirstErrorField('contact_email');
		}
	}

	if (!form.captchaCode.value) {
		alertText += "To help prevent spam posts, please type the characters you see in the graphic.";
		checkFirstErrorField('captchaCode');
	}
	else if (form.captchaCode.value != captcha) {
		alertText += "The security code you typed in is incorrect.";
		checkFirstErrorField('captchaCode');
	}
	
	if (alertText != '') {
		alert(alertText);
		form[firstErrorField].focus();
		if (firstErrorField != 'parents_town') {
			form[firstErrorField].select();
		}
		return false;
	}
	else {
		form.submit();
	}
}
