/* Work around the fact that, when form.submit() is called from JavaScript, it
 * doesn't call onsubmit()
 */
function submitFormIfValid(form) {

	if (form.onsubmit) {
		if (form.onsubmit()) {
			if (form.fireEvent) {
				form.fireEvent('onsubmit');
			}
			form.submit();
		}
	}
	else {
		if (form.fireEvent) {
			form.fireEvent('onsubmit');
		}
		form.submit();
	}
}
