function checkLen(o, next) {
	if ( o.value.length == o.size ) next.focus();
	return true;
}

var validateMsg = "";
var validateCount = 0;
var petRadioClicked = false;
var gateRadioClicked = false;

function allReqVars(fs) {
	var msg = "";
	var len = fs.length;

	for ( var i = 0; i < len; i++ ) {
		msg += fs.elements[i].name + ": " + fs.elements[i].value + "\n";
//		msg += eval(fs + ".elements[" + i + "].name") + ": " + eval(fs + ".elements[" + i + "].value") + "\n";
	}
	return msg;
}

function formatPhoneNumber(n) {

	var s = "";

// Get digits from phone number

	for ( var i = 0; i < n.value.length; i++ ) {
		if ( n.value.charAt(i) >= '0' && n.value.charAt(i) <= '9' ) {
			s = s.concat(n.value.charAt(i));
		}
	}

// If 10 digits long, format (npa) nxx-line

	if ( s.length == 10 ) {
/*		n.value = "(" + s.substr(0,3) + ") " + s.substr(3,3) + "-" + s.substr(6); */
		n.value = s.substr(0,3) + "-" + s.substr(3,3) + "-" + s.substr(6);
	}
}

function confirmDelete(name, submitDate) {
	return confirm("Permanently delete record for\n" + name + " dated\n" + submitDate + "?");
}

//
// Set Address and Home Phone Same As Patient
//

function setSameAsPatient(c) {
    var f = c.form;
    if ( c.checked == true ) {
	eval("f." + c.value + "_address.value = f.patient_address.value;");
	eval("f." + c.value + "_city.value = f.patient_city.value;");
	eval("f." + c.value + "_state.value = f.patient_state.value;");
	eval("f." + c.value + "_zip.value = f.patient_zip.value;");
	eval("f." + c.value + "_phone.value = f.patient_phone.value;");
    }
}

//
// Validate Appointment Request Form
//

function validateContactMessage(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.name.value) == "" ) {
		validateMsg = "    Name\n";
		validateCount += 1;
		f.name.focus();
		focusSet = 1;
	}
	if ( trim(f.phone.value) == "" ) {
		validateMsg += "    Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.phone.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.email.value) == "" ) {
		validateMsg += "    E-mail\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.email.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.message.value) == "" ) {
		validateMsg += "    Message\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.message.focus();
			focusSet = 1;
		}
	}


// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate e-mail if provided

	if (trim(f.email.value) != "" ) {
		if (!validateEmail(f.email)) return false;
	}

// Validate phone number if provided

	if (trim(f.phone.value) != "") {
		var phoneDigits = getDigits(f.phone.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The phone number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include your area code.";
			return confirm(msg);
		}
	}
	return true;
}


//
// Validate E-mail Reminders Sign-up
//

function validateReminders(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.first_name.value) == "" ) {
		validateMsg = "    First Name\n";
		validateCount += 1;
		f.form_by.value = "";
		f.first_name.focus();
		focusSet = 1;
	}
	if ( trim(f.last_name.value) == "" ) {
		validateMsg += "    Last Name\n";
		validateCount += 1;
		f.form_by.value = "";
		if ( ! focusSet ) {
			f.last_name.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_date.value) == "" ) {
		validateMsg += "    Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_date.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.e_mail.value) == "" ) {
		validateMsg += "    Reminder E-mail Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.e_mail.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.form_by.value) == "" ) {
		validateMsg += "    Name of Person Signing Up for Patient\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.form_by.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.phone.value) == "" ) {
		validateMsg += "    Phone Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.phone.focus();
			focusSet = 1;
		}
	}
	if ( !f.remind_flu_shot.checked && !f.remind_annual_adult.checked && !f.remind_annual_child.checked ) {
		validateMsg += "    Check at Least One Reminder Box\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.remind_flu_shot.focus();
			focusSet = 1;
		}
	}


// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		f.self_signup.checked = false;
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate select fields

	if (trim(f.birth_date.value) != "" ) {
		if (!validateDate(f.birth_date, "Date of Birth")) return false;
	}

	if (trim(f.e_mail.value) != "" ) {
		if (!validateEmail(f.e_mail)) return false;
	}

// Validate phone numbers provided

	if (trim(f.phone.value) != "") {
		var phoneDigits = getDigits(f.phone.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The Phone Number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include the area code.";
			if ( !confirm(msg) ) {
				f.phone.focus();;
				return false;
			}
		}
	}

	return true;
}

//
// Validate Prescription Refill Request
//

function validateRxRefill(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.first_name.value) == "" ) {
		validateMsg = "    First Name\n";
		validateCount += 1;
		f.first_name.focus();
		focusSet = 1;
	}
	if ( trim(f.last_name.value) == "" ) {
		validateMsg += "    Last Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.last_name.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_date.value) == "" ) {
		validateMsg += "    Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_date.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_address.value) == "" ) {
		validateMsg += "    Patient Street Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_address.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_city.value) == "" ) {
		validateMsg += "    Patient City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_city.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_state.value) == "" ) {
		validateMsg += "    Patient State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_state.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_zip.value) == "" ) {
		validateMsg += "    Patient Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_zip.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.medication.value) == "" ) {
		validateMsg += "    Name of Medication\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.medication.focus();
			focusSet = 1;
		}
	}
	if ( f.prescriber[0].selected ) {
		validateMsg += "    Prescribing Physician\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.prescriber[0].focus();
			focusSet = 1;
		}
	}
	if ( !f.instructions[0].checked && !f.instructions[1].checked  ) {
		validateMsg += "    Select Pick-up or Call-in\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.instructions[0].focus();
			focusSet = 1;
		}
	}
	if ( f.instructions[1].checked  ) {
	    if ( trim(f.pharmacy_name.value) == "" ) {
		validateMsg += "    Pharmacy Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_name.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_phone.value) == "" ) {
		validateMsg += "    Pharmacy Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_phone.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_address.value) == "" ) {
		validateMsg += "    Pharmacy Street Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_city.value) == "" ) {
		validateMsg += "    Pharmacy City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_city.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_state.value) == "" ) {
		validateMsg += "    Pharmacy State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_state.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_zip.value) == "" ) {
		validateMsg += "    Pharmacy Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_zip.focus();
			focusSet = 1;
		}
	    }
	}
	if ( trim(f.requester_name.value) == "" ) {
		validateMsg += "    Requester Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_name.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_relation.value) == "" ) {
		validateMsg += "    Requester Relationship to Patient\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_relation.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_address.value) == "" ) {
		validateMsg += "    Requester Street Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_address.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_city.value) == "" ) {
		validateMsg += "    Requester City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_city.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_state.value) == "" ) {
		validateMsg += "    Requester State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_state.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_zip.value) == "" ) {
		validateMsg += "    Requester Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_zip.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_home_phone.value) == "" &&  trim(f.requester_cell.value) == "" ) {
		validateMsg += "    Requester Home or Cell Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_home_phone.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester_email.value) == "" ) {
		validateMsg += "    Requester E-mail Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester_email.focus();
			focusSet = 1;
		}
	}


// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate select fields

	if (trim(f.birth_date.value) != "" ) {
		if (!validateDate(f.birth_date, "Date of Birth")) return false;
	}
	if (trim(f.patient_email.value) != "" ) {
		if (!validateEmail(f.patient_email)) return false;
	}
	if (trim(f.patient_zip.value) != "" ) {
		if (!formatZipCode(f.patient_zip)) return false;
	}
	if (trim(f.pharmacy_zip.value) != "" ) {
		if (!formatZipCode(f.pharmacy_zip)) return false;
	}
	if (trim(f.requester_zip.value) != "" ) {
		if (!formatZipCode(f.requester_zip)) return false;
	}
	if (trim(f.requester_email.value) != "" ) {
		if (!validateEmail(f.requester_email)) return false;
	}

// Validate phone numbers provided

	if (trim(f.pharmacy_phone.value) != "") {
		var phoneDigits = getDigits(f.pharmacy_phone.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The Pharmacy Phone Number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include the area code.";
			if ( !confirm(msg) ) {
				f.pharmacy_phone.focus();;
				return false;
			}
		}
	}
	if (trim(f.requester_home_phone.value) != "") {
		var phoneDigits = getDigits(f.requester_home_phone.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The Requester Home Phone Number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include the area code.";
			if ( !confirm(msg) ) {
				f.requester_home_phone.focus();;
				return false;
			}
		}
	}
	if (trim(f.requester_cell.value) != "") {
		var phoneDigits = getDigits(f.requester_cell.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The Requester Cell Phone Number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include the area code.";
			if ( !confirm(msg) ) {
				f.requester_cell.focus();;
				return false;
			}
		}
	}
	return true;

} // validateRxRefill()


//
// Validate Appointment Request Form
//

function validateAppointment(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.patient.value) == "" ) {
		validateMsg = "    Full Name of Patient\n";
		validateCount += 1;
		f.patient.focus();
		focusSet = 1;
	}
	if ( trim(f.birth_date.value) == "" ) {
		validateMsg += "    Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_date.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.requester.value) == "" ) {
		validateMsg += "    Name of Requester\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.requester.focus();
			focusSet = 1;
		}
	}
	if ( f.relationship.selectedIndex == 0 ) {
		validateMsg += "    Relationship to Patient\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.relationship.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.phone.value) == "" ) {
		validateMsg += "    Phone Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.phone.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.email.value) == "") {
		validateMsg += "    E-mail Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.email.focus();
			focusSet = 1;
		}
	}
	if ( f.appt_type.selectedIndex == 0 ) {
		validateMsg += "    Type of Appointment\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.appt_type.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.date1.value) == "" ) {
		validateMsg += "    Date - 1st Preference\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.date1.focus();
			focusSet = 1;
		}
	}
	if ( f.time1.selectedIndex == 0 ) {
		validateMsg += "    Time - 1st Preference\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.time1.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.date2.value) != "" && f.time2.selectedIndex == 0 ) {
		validateMsg += "    Time - 2nd Preference\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.time2.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.date3.value) != "" && f.time3.selectedIndex == 0 ) {
		validateMsg += "    Time - 3rd Preference\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.time3.focus();
			focusSet = 1;
		}
	}


// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate select fields

	if (trim(f.birth_date.value) != "" ) {
		if (!validateDate(f.birth_date, "Date of Birth")) return false;
	}
	if (trim(f.email.value) != "" ) {
		if (!validateEmail(f.email)) return false;
	}

// Validate phone number if provided

	if (trim(f.phone.value) != "") {
		var phoneDigits = getDigits(f.phone.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The phone number you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include your area code.";
			return confirm(msg);
		}
	}
	return true;

} // validateAppointment()

//
// Parent Address Same as Patient
//

function fatherSameAsPatient(c) {
	if (c.checked == true ) {
		f = c.form;
		f.father_address.value = f.patient_address.value;
		f.father_city.value = f.patient_city.value;
		f.father_state.value = f.patient_state.value;
		f.father_zip.value = f.patient_zip.value;
	}
}

function motherSameAsPatient(c) {
	if (c.checked == true ) {
		f = c.form;
		f.mother_address.value = f.patient_address.value;
		f.mother_city.value = f.patient_city.value;
		f.mother_state.value = f.patient_state.value;
		f.mother_zip.value = f.patient_zip.value;
	}
}

function selfSignUp(f) {
	if (f.self_signup.checked) {
		if (f.first_name.value.length > 0)  f.form_by.value = f.first_name.value;
		if (f.middle_name.value.length > 0) f.form_by.value += ' ' + f.middle_name.value;
		if (f.last_name.value.length > 0)   f.form_by.value += ' ' + f.last_name.value;
		if (f.suffix.value.length > 0)      f.form_by.value += ' ' + f.suffix.value;
		if (f.patient_phone.value.length > 0)      f.form_by_phone.value += ' ' + f.patient_phone.value;
	}
}

//
// Validate Patient Demographic Information Form
//

function validateDemoInfoForm(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.first_name.value) == "" ) {
		validateMsg = "    First Name\n";
		validateCount += 1;
		f.self_signup.checked = false;
		f.first_name.focus();
		focusSet = 1;
	}
	if ( trim(f.last_name.value) == "" ) {
		validateMsg += "    Last Name\n";
		validateCount += 1;
		f.self_signup.checked = false;
		if ( ! focusSet ) {
			f.last_name.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_date.value) == "" ) {
		validateMsg += "    Patient Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_date.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.ssn.value) == "" &&  trim(f.driver_license_number.value) == "" ) {
		validateMsg += "    Patient Social Security Number or Driver License Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.ssn.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.driver_license_number.value) != "" && trim(f.driver_license_state.value) == "" ) {
		validateMsg += "    Driver License Issuing State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.driver_license_state.focus();
			focusSet = 1;
		}
	}
	if ( !f.gender[0].checked && !f.gender[1].checked ) {
		validateMsg += "    Gender\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.gender[0].focus();
			focusSet = 1;
		}
	}
	if ( !f.marital_status[0].checked && !f.marital_status[1].checked &&  !f.marital_status[2].checked && !f.marital_status[3].checked ) {
		validateMsg += "    Marital Status\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.gender[0].focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_address.value) == "" ) {
		validateMsg += "    Patient Street Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_address.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_city.value) == "" ) {
		validateMsg += "    Patient City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_city.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_state.value) == "" ) {
		validateMsg += "    Patient State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_state.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_zip.value) == "" ) {
		validateMsg += "    Patient Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.patient_zip.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.patient_phone.value) == "" ) {
		validateMsg += "    Patient Home Phone Number\n";
		validateCount += 1;
		f.self_signup.checked = false;
		if ( ! focusSet ) {
			f.patient_phone.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.form_by.value) == "" ) {
		validateMsg += "    Name of Person Completing Form for Patient\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.form_by.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.form_by_phone.value) == "" ) {
		validateMsg += "    Phone Number of Person Completing Form for Patient\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.form_by_phone.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.employer_name.value) != "" ) {
	    if ( trim(f.employer_address.value) == "" ) {
		validateMsg += "    Employer Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.employer_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.employer_city.value) == "" ) {
		validateMsg += "    Employer City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.employer_city.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.employer_state.value) == "" ) {
		validateMsg += "    Employer State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.employer_state.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.employer_zip.value) == "" ) {
		validateMsg += "    Employer Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.employer_zip.focus();
			focusSet = 1;
		}
	    }
	}
/*
	if ( (f.mother_name.value != "" || f.father_name.value != "" || f.bill_resp_other_name.value != "") && (!f.bill_resp_person[0].checked && !f.bill_resp_person[1].checked && && !f.bill_resp_person[2].checked && !f.bill_resp_person[3].checked) ) {
		validateMsg += "    Billing Responsibility\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_person[0].focus();
			focusSet = 1;
		}
	}
*/
	if ( f.bill_resp_person[0].checked && f.mother_name.value == "" ) {
		validateMsg += "    Mother's Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_name.focus();
			focusSet = 1;
		}
	}
	if ( f.bill_resp_person[1].checked && f.father_name.value == "" ) {
		validateMsg += "    Father's Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_name.focus();
			focusSet = 1;
		}
	}
	if ( f.bill_resp_person[3].checked && f.bill_resp_other_name.value == "" ) {
		validateMsg += "    Name of Other Person Responsible for Billing\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_other_name.focus();
			focusSet = 1;
		}
	}
	if ( f.mother_name.value != "" ) {
	    if ( f.mother_address.value == "" ) {
		validateMsg += "    Mother's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.mother_birthdate.value) == "" ) {
		validateMsg += "    Mother's Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_birthdate.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.mother_ssn.value) == "" &&  trim(f.mother_license_number.value) == "" ) {
		validateMsg += "    Mother's Social Security Number or Driver License Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_ssn.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.mother_license_number.value) != "" && trim(f.mother_license_state.value) == "" ) {
		validateMsg += "    Mother's Driver License Issuing State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_license_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.mother_address.value == "" ) {
		validateMsg += "    Mother's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_address.focus();
			focusSet = 1;
		}
	    }
	    if ( f.mother_city.value == "" ) {
		validateMsg += "    Mother's City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_city.focus();
			focusSet = 1;
		}
	    }
	    if ( f.mother_state.value == "" ) {
		validateMsg += "    Mother's State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.mother_zip.value == "" ) {
		validateMsg += "    Mother's Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_zip.focus();
			focusSet = 1;
		}
	    }
	    if ( f.mother_phone.value == "" ) {
		validateMsg += "    Mother's Home Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.mother_phone.focus();
			focusSet = 1;
		}
	    }
	}
	if ( f.father_name.value != "" ) {
	    if ( f.father_address.value == "" ) {
		validateMsg += "    Father's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.father_birthdate.value) == "" ) {
		validateMsg += "    Father's Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_birthdate.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.father_ssn.value) == "" &&  trim(f.father_license_number.value) == "" ) {
		validateMsg += "    Father's Social Security Number or Driver License Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_ssn.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.father_license_number.value) != "" && trim(f.father_license_state.value) == "" ) {
		validateMsg += "    Father's Driver License Issuing State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_license_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.father_address.value == "" ) {
		validateMsg += "    Father's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_address.focus();
			focusSet = 1;
		}
	    }
	    if ( f.father_city.value == "" ) {
		validateMsg += "    Father's City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_city.focus();
			focusSet = 1;
		}
	    }
	    if ( f.father_state.value == "" ) {
		validateMsg += "    Father's State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.father_zip.value == "" ) {
		validateMsg += "    Father's Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_zip.focus();
			focusSet = 1;
		}
	    }
	    if ( f.father_phone.value == "" ) {
		validateMsg += "    Father's Home Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.father_phone.focus();
			focusSet = 1;
		}
	    }
	}
	if ( f.bill_resp_other_name.value != "" ) {
	    if ( f.bill_resp_address.value == "" ) {
		validateMsg += "    Other Responsible Person's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.bill_resp_birthdate.value) == "" ) {
		validateMsg += "    Other Responsible Person's Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_birthdate.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.bill_resp_ssn.value) == "" &&  trim(f.bill_resp_license_number.value) == "" ) {
		validateMsg += "    Other Responsible Person's Social Security Number or Driver License Number\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_ssn.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.bill_resp_license_number.value) != "" && trim(f.bill_resp_license_state.value) == "" ) {
		validateMsg += "    Other Responsible Person's Driver License Issuing State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_license_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.bill_resp_address.value == "" ) {
		validateMsg += "    Other Responsible Person's Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_address.focus();
			focusSet = 1;
		}
	    }
	    if ( f.bill_resp_city.value == "" ) {
		validateMsg += "    Other Responsible Person's City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_city.focus();
			focusSet = 1;
		}
	    }
	    if ( f.bill_resp_state.value == "" ) {
		validateMsg += "    Other Responsible Person's State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_state.focus();
			focusSet = 1;
		}
	    }
	    if ( f.bill_resp_zip.value == "" ) {
		validateMsg += "    Other Responsible Person's Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_zip.focus();
			focusSet = 1;
		}
	    }
	    if ( f.bill_resp_phone.value == "" ) {
		validateMsg += "    Other Responsible Person's Home Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.bill_resp_phone.focus();
			focusSet = 1;
		}
	    }
	}
	if ( trim(f.emergency_contact.value) == "" ) {
		validateMsg += "    Emergency Contact Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.emergency_contact.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.emergency_main_phone.value) == "" ) {
		validateMsg += "    Emergency Contact Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.emergency_main_phone.focus();
			focusSet = 1;
		}
	}
	if ( !f.no_insurance.checked ) {
	    if ( trim(f.insurance_company.value) == "" ) {
		validateMsg += "    Insurance Company\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.insurance_company.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.insurance_phone.value) == "" ) {
		validateMsg += "    Insurance Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.insurance_phone.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.claims_city.value) == "" ) {
		validateMsg += "    Claims Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.claims_city.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.claims_city.value) == "" ) {
		validateMsg += "    Claims Address City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.claims_city.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.claims_state.value) == "" ) {
		validateMsg += "    Claims Address State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.claims_state.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.claims_zip.value) == "" ) {
		validateMsg += "    Claims Address Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.claims_zip.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.primary_insured_name.value) == "" ) {
		validateMsg += "    Name of Primary Insured\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.primary_insured_name.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.primary_insured_dob.value) == "" ) {
		validateMsg += "    Birth Date of Primary Insured\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.primary_insured_dob.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.policy_number.value) == "" ) {
		validateMsg += "    Insurance Policy Number or ID\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.policy_number.focus();
			focusSet = 1;
		}
	    }
	}
	if ( trim(f.pharmacy_name.value) != "" ) {
	    if ( trim(f.pharmacy_address.value) == "" ) {
		validateMsg += "    Pharmacy Phone\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_phone.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_address.value) == "" ) {
		validateMsg += "    Pharmacy Address\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_address.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_city.value) == "" ) {
		validateMsg += "    Pharmacy City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_city.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_state.value) == "" ) {
		validateMsg += "    Pharmacy State\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_state.focus();
			focusSet = 1;
		}
	    }
	    if ( trim(f.pharmacy_zip.value) == "" ) {
		validateMsg += "    Pharmacy Zip Code\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.pharmacy_zip.focus();
			focusSet = 1;
		}
	    }
	}
	if ( !f.yn_correct_insurance.checked ) {
		validateMsg += "    Check Insurance is Correct\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_correct_insurance.focus();
			focusSet = 1;
		}
	}
	if ( !f.yn_release_info.checked ) {
		validateMsg += "    Check Authorization to Release Medical Info\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_release_info.focus();
			focusSet = 1;
		}
	}
	if ( !f.yn_assign_benefits.checked ) {
		validateMsg += "    Check Assignment of Benefits\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_assign_benefits.focus();
			focusSet = 1;
		}
	}
	if ( !f.yn_my_responsibility.checked ) {
		validateMsg += "    Check Financial Responsibility\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_my_responsibility.focus();
			focusSet = 1;
		}
	}
	if ( !f.yn_authorize_copy.checked ) {
		validateMsg += "    Check Copy of Authorization\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_authorize_copy.focus();
			focusSet = 1;
		}
	}
	if ( !f.yn_review_policies.checked ) {
		validateMsg += "    Check Policies Reviewed\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.yn_review_policies.focus();
			focusSet = 1;
		}
	}
	if ( f.reminder_email.value != "" && (!f.remind_flu_shot.checked && !f.remind_annual_adult.checked && !f.remind_annual_child.checked) ) {
		validateMsg += "    If Reminder E-mail Address is Provided, Check at Least One Reminder Box\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.remind_flu_shot.focus();
			focusSet = 1;
		}
	}	

// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate dates

	if (trim(f.birth_date.value) != "" ) {
		if (!validateDate(f.birth_date, "Patient Birth Date")) return false;
	}
	if (trim(f.father_birthdate.value) != "" ) {
		if (!validateDate(f.father_birthdate, "Father's Birth Date")) return false;
	}
	if (trim(f.mother_birthdate.value) != "" ) {
		if (!validateDate(f.mother_birthdate, "Mother's Birth Date")) return false;
	}

// Validate e-mail addresses if provided

	if (trim(f.patient_email.value) != "" ) {
		if (!validateEmail(f.patient_email)) return false;
	}
	if (trim(f.father_email.value) != "" ) {
		if (!validateEmail(f.father_email)) return false;
	}
	if (trim(f.mother_email.value) != "" ) {
		if (!validateEmail(f.mother_email)) return false;
	}
	if (trim(f.reminder_email.value) != "" ) {
		if (!validateEmail(f.reminder_email)) return false;
	}

// Validate phone number if provided

	if (trim(f.patient_phone.value) != "" ) {
		if (!validatePhone(f.patient_phone)) return false;
	}
	if (trim(f.patient_cell.value) != "" ) {
		if (!validatePhone(f.patient_cell)) return false;
	}
	if (trim(f.father_phone.value) != "" ) {
		if (!validatePhone(f.father_phone)) return false;
	}
	if (trim(f.father_cell.value) != "" ) {
		if (!validatePhone(f.father_cell)) return false;
	}
	if (trim(f.father_work.value) != "" ) {
		if (!validatePhone(f.father_work)) return false;
	}
	if (trim(f.mother_phone.value) != "" ) {
		if (!validatePhone(f.mother_phone)) return false;
	}
	if (trim(f.mother_cell.value) != "" ) {
		if (!validatePhone(f.mother_cell)) return false;
	}
	if (trim(f.mother_work.value) != "" ) {
		if (!validatePhone(f.mother_work)) return false;
	}
	if (trim(f.emergency_phone.value) != "" ) {
		if (!validatePhone(f.emergency_main_phone)) return false;
	}

// Request Final Review

	return (confirm("Click OK to submit your Patient General Information Form.\n\n" + "Click Cancel to review or to make changes."));

} // patient demographic form


//
// Validate Patient Medical History Form
//

function validateMedHistoryForm(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( trim(f.first_name.value) == "" ) {
		validateMsg = "    First Name\n";
		validateCount += 1;
		f.first_name.focus();
		focusSet = 1;
	}
	if ( trim(f.last_name.value) == "" ) {
		validateMsg += "    Last Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.last_name.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_date.value) == "" ) {
		validateMsg += "    Date of Birth\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_date.focus();
			focusSet = 1;
		}
	}
	if ( !f.delivery_type[0].checked && !f.delivery_type[1].checked ) {
		validateMsg += "    Delivery Type\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.delivery_type[0].focus();
			focusSet = 1;
		}
	}
	if ( f.delivery_type[1].checked && trim(f.why_caesarian.value) == "" ) {
		validateMsg += "    If Caesarian, Why?\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.why_caesarian.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.gestation_age.value) == "" ) {
		validateMsg += "    Gestational Age\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.gestation_age.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_weight.value) == "" ) {
		validateMsg += "    Birth Weight\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_weight.focus();
			focusSet = 1;
		}
	}
	if ( trim(f.birth_length.value) == "" ) {
		validateMsg += "    Birth Length\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.birth_length.focus();
			focusSet = 1;
		}
	}
	if ( !f.hearing_screen[0].checked && !f.hearing_screen[1].checked && !f.hearing_screen[2].checked ) {
		validateMsg += "    Hearing Screen\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.hearing_screen[0].focus();
			focusSet = 1;
		}
	}
	if ( f.allergy.checked && trim(f.allergy_desc.value) == "" ) {
		validateMsg += "    Specify Allergies\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.allergy_desc.focus();
			focusSet = 1;
		}
	}
	if ( f.dev_delay.checked && trim(f.dev_delay_desc.value) == "" ) {
		validateMsg += "    Specify Developmental Delay\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.dev_delay.focus();
			focusSet = 1;
		}
	}
	if ( f.other_problems.checked && trim(f.other_prob_desc.value) == "" ) {
		validateMsg += "    Specify Other Chronic Problems\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.other_prob_desc.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_diabetes.checked && trim(f.fh_diabetes_who.value) == "" ) {
		validateMsg += "    Diabetes: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_diabetes_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_seizures.checked && trim(f.fh_seizures_who.value) == "" ) {
		validateMsg += "    Seizures: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_seizures_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_asthma.checked && trim(f.fh_asthma_who.value) == "" ) {
		validateMsg += "    Asthma: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_asthma_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_cholesterol.checked && trim(f.fh_chol_who.value) == "" ) {
		validateMsg += "    High Cholesterol: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_chol_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_heart.checked && trim(f.fh_heart_who.value) == "" ) {
		validateMsg += "    Heart Disease: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_heart_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_anemia.checked && trim(f.fh_anemia_who.value) == "" ) {
		validateMsg += "    Anemia: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_anemia_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_hypertension.checked && trim(f.fh_hypert_who.value) == "" ) {
		validateMsg += "    High Blood Pressure: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_hypert_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_cancer.checked && trim(f.fh_cancer_who.value) == "" ) {
		validateMsg += "    Cancer: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_cancer_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_eczema.checked && trim(f.fh_eczema.value) == "" ) {
		validateMsg += "    Eczema: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_eczema.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_allergy.checked && trim(f.fh_allergy_who.value) == "" ) {
		validateMsg += "    Allergies: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_allergy_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_bleeding.checked && trim(f.fh_bleeding_who.value) == "" ) {
		validateMsg += "    Bleeding Disorder: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_bleeding_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_liver.checked && trim(f.fh_liver_who.value) == "" ) {
		validateMsg += "    Liver Disease: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_liver_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_kidney.checked && trim(f.fh_kidney_who.value) == "" ) {
		validateMsg += "    Kidney Disease: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_kidney_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_mental.checked && trim(f.fh_mental_who.value) == "" ) {
		validateMsg += "    Mental Health: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_mental_who.focus();
			focusSet = 1;
		}
	}
	if ( f.fh_other.checked && trim(f.fh_other_who.value) == "" ) {
		validateMsg += "    Other Medical Problems: List Family Members\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.fh_other_who.focus();
			focusSet = 1;
		}
	}

// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Validate dates

	if (trim(f.birth_date.value) != "" ) {
		if (!validateDate(f.birth_date, "Date of Birth")) return false;
	}

// Request Final Review

	return (confirm("Click OK to submit your Patient Medical History Form.\n\n" + "Click Cancel to review or to make changes."));
}

function validatePhone(p, plabel) {
		var phoneDigits = getDigits(p.value);
		var phoneLen = phoneDigits.length;
		if (phoneLen != 10) {
			msg = "The " + plabel + " you provided is\n" +
				phoneLen + " digits long. Is this correct?";
			if (phoneLen < 10)
				msg += "\n\nPlease include your area code.";
			if (!confirm(msg)) {
				p.focus();
				return false;
			}
		}
		return true;
}

function getDigits(str) {

	var digits = new String("");

	for ( var i = 0; i < str.length; i++ ) {
		if ( str.charAt(i) >= '0' && str.charAt(i) <= '9' ) {
			digits = digits.concat(str.charAt(i));
		}
	}
	return digits;
}

// ============================================================
// Function to check if character is whitespace
// ============================================================

function isWhitespace(c) {
    whitespace = " \t\n\r";
    if (whitespace.indexOf(c) < 0) {
	return false;
    }
    return true;
}

// ============================================================
// Function to check if whitespace is embedded in string
// ============================================================

function hasWhitespace(s) {
   var sBuff = trim(s);
   var bLength = sBuff.length;

// Check for embedded whitespace

    for (var sPos = 0; sPos < bLength; sPos++) {
	if (isWhitespace(sBuff.charAt(sPos))) return true;
    }
    return false;
}

// ============================================================
// Function to remove leading and trailing whitespace
// ============================================================

function trim(s) {

   var sBuff = s;
   var sLength = s.length;

// Remove leading whitespace

    for (var sPos = 0; sPos < sLength; sPos++) {
	if (!isWhitespace(s.charAt(sPos))) {
	    sBuff = s.substr(sPos);
	    break;
	}
    }

// Remove trailing whitespace

    var bLength = sBuff.length;
    for (sPos = bLength - 1; sPos >= 0; sPos--) {
	if (isWhitespace(sBuff.charAt(sPos))) {
	    return sBuff.substr(0, (sPos + 1));
	    break;
	}
    }
    return sBuff;
}

function formatSSN(ssnInput) {

	var digits = getDigits(ssnInput.value);

	if (digits.length == 0 && ssnInput.length != 0) {
		alert("Please enter a valid Social Security Number.");
		ssnInput.focus();
		return false;
	}

// If 9 digits long, format ###-##-####

	if ( digits.length == 9 ) {
		ssnInput.value = digits.substr(0,3) + "-" + digits.substr(3,2) + "-" + digits.substr(5);
	}
	return true;
}

function formatZipCode(zipInput) {

	var digits = getDigits(zipInput.value);

	if (digits.length == 0 && zipInput.value.length > 0) {
		alert("Please enter a valid US Zip Code.");
		zipInput.focus();
		return false;
	}
	if (digits.length != 0 && digits.length != 5 && digits.length != 9) {
		alert("US Zip Code should be 5 or 9 digits long.");
		zipInput.focus();
		return false;
	}

// If 9 digits long, format #####-####

	if ( digits.length == 9 ) {
		zipInput.value = digits.substr(0,5) + "-" + digits.substr(5);
	}
	return true;
}

function formatPhoneNumber(phoneInput) {

	var s = "";
	var digits = getDigits(phoneInput.value);

	if (digits.length == 0 && phoneInput.value.length > 0) {
		alert("Please enter a valid Phone Number.");
		phoneInput.focus();
		return false;
	}

// Require area code (North American standard)

	if ( digits.length < 10 && digits.length != 0) {
		alert("Please provide area code and phone number");
		phoneInput.focus();
		return false;
	}

// If 10 digits long, format (npa) nxx-line

	if ( digits.length == 10 ) {
		phoneInput.value = digits.substr(0,3) + "-" + digits.substr(3,3) + "-" + digits.substr(6);
	}
	return true;
}

function validateDate(t, tlabel) {
    var dateChars  = "01234567890/";
    var s = trim(t.value);

    if (s.length == 0) return false;
    if (s.length != 10 && s.length != 0) {
	alert("Invalid " + tlabel + " date format:  Use the form mm/dd/yyyy  with no spaces.");
	t.focus();
	return false;
    }
    for (var i = 0; i < s.length; i++) {
	if (dateChars.indexOf(s.charAt(i)) < 0) {
	    alert("Invalid characters in" + tlabel + " date:  Use only digits and slashes in the form mm/dd/yyyy.");
	    t.focus();
	    return false;
	}
    }
    var yr = s.substr(6, 4) - 0;
    var month = s.substr(0, 2) - 0;
    var day  = s.substr(3, 2) - 0;
    if (yr < 1900) {
	alert("Check" + tlabel + " year:  Minimum allowed is 1900.");
	t.focus();
	return false;
    }
    if (month < 1 || month > 12) {
	alert("Invalid" + tlabel + " month: Should be between 01 and 12.");
	t.focus();
	return false;
    }
    switch(month) {
	case  1 : 
	case  3 : 
	case  5 : 
	case  7 : 
	case  8 : 
	case 10 : 
	case 12 : if (day > 0 && day <= 31) return true; break;
	case  4 : 
	case  6 : 
	case  9 : 
	case 11 : if (day > 0 && day <= 30) return true; break;
	default : if ((yr % 4 == 0 && day <= 29) || (yr % 4 != 0 && day <= 28)) return true; break;
    }
    alert("Check" + tlabel + " day " + day + ": Should be between 1 and appropriate End-of-Month (30, 31, 28 or 29).");
    t.focus();
    return false;
}

function validateEmail(emailInput) {
	var email_pattern = /^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]+$/;
	if((result = email_pattern.exec(emailInput.value)) == null) {
		alert("Please check for a valid e-mail address format\nExamples: john@yahoo.com, jane.doe@my-isp.net");
		emailInput.focus();
		return false;
	}
	return true;	
}

/*

<nobr>
handle<span style="font-size:1px;">
</span>&#064;<span style="font-size:1px;">
</span>domain<span style="font-size:1px;">
</span>&#046;<span style="font-size:1px;">
</span>com
</nobr>

OR

<script language="javascript">
<!--
function buildEmail(a, domain, handle) {
	a.href = "mailto:" + handle + "@" + domain;
}
//-->
</script>
<a
href="javascript:void(0)"
onMouseOver="buildEmail(this, 'domain.ext', 'handle');"
class="copyright">
 	<nobr>
	handle<span style="font-size:1px;">
	</span>&#064;<span style="font-size:1px;">
	</span>domain<span style="font-size:1px;">
	</span>&#046;<span style="font-size:1px;">
	</span>ext</nobr>
</a>

<p><img src="imgcounter.php?filename=home&color=000000">
CAVEAT - Verify:
Perms 446 or 447
Path /imgcounter.php, relative or absolute
*/

