/*
	EnterSubmit allows you to cause a form to submit if a user presses enter in a form element
	
	William Svec 12/06
	
	Description:
	
	Put it in the onkeypress handler of a form element like this:
	onkeypress="EnterSubmit(event, form, validator)"
	
	- The 'event' argument is boilerplate -- the first argument should ALWAYS be the literal word 'event'.
	- The 'form' argument is a reference to the form you want to submit.
	- The 'validator' argument is an optional reference to a validation function that should run before
	  submitting the form.  Said function should take no arguments and return false if the validation fails. 
	  If no validator is needed, pass null for this argument.
*/

function EnterSubmit(event, form, validator) {
	var FormIsValid = true;
	
	if(EnterWasPressed(event)) {
		if(validator != null)
			FormIsValid = validator();
				
		if(FormIsValid)
			form.submit();
	} else
		return true;
}


/* Different browsers require different code to determine if enter was pressed */
function EnterWasPressed(event) {
	// Note: Firefox reports its appName as Netscape
	if(navigator.appName == "Netscape") {
		if (event && event.which == 13) {
			return true;
		}
	}
	
	if(navigator.appName == "Microsoft Internet Explorer") {
		if (window.event && window.event.keyCode == 13) {
			return true;
		}
	}
		
	return false;
}



