// Check for answering to mandatory questions.
function gpq_validate(f) {
	var error_msg = '';
	var focus_this = null;

	// These questions are mandatory.
	if (!radio_chosen(f.q30)) {
		error_msg += '"Male or female?"\n';
		if (focus_this == null) focus_this = f.q30[0];
	}
	if (!radio_chosen(f.q12)) {
		error_msg += '"How would you describe yourself?"\n';
		if (focus_this == null) focus_this = f.q12[0];
	}
	if (!radio_chosen(f.q14)) {
		error_msg += '"How long have you been participating in clinical trials?"\n';
		if (focus_this == null) focus_this = f.q14[0];
	}
	if (!radio_chosen(f.q27)) {
		error_msg += '"Would you be willing to discuss your experiences on film?"\n';
		if (focus_this == null) focus_this = f.q27[0];
	}
	if (!radio_chosen(f.q28)) {
		error_msg += '"May we add you to our production mailing list?"\n';
		if (focus_this == null) focus_this = f.q28[0];
	}
	if (!radio_chosen(f.q29)) {
		error_msg += '"Would you like to participate in a guinea pig yahoo group or blog?"\n';
		if (focus_this == null) focus_this = f.q29[0];
	}

	// Form is incomplete.
	if (error_msg.length > 0) {
		// Remove the last line break.
		error_msg = error_msg.substring(0, error_msg.length - 1);
		// Notify what's missing.
		if (error_msg.indexOf("\n") > -1) {
			error_msg = 'Please provide an answer to these questions:\n' + error_msg;
		} else {
			error_msg = 'Please provide an answer to the question:\n' + error_msg; 
		}
		alert(error_msg);
		// Select the first missing item.
		focus_this.focus();
		// Scroll the window up so the question is visible.
		window.scrollBy(0, -80);
		// Cancel the form submission.
		return false;
	}

	// Otherwise, the form is complete and ready to submit.
	return true;

}      

function radio_chosen(radio_set) {
    for (var i = 0; i < radio_set.length; i++) {
        if (radio_set[i].checked) return true;
    }
	return false;
}
