/**
*
* This function does the following:
* - Sets a field 'NextField' value
* - Installs a handler for when a key is pressed down
* - Installs a handler for when a key is released
*
* @param object form The document form element for the auto jump fields
*
* @param string fieldName The name of the starting field
*
* @param string NextFieldName The name of the field to jump to
*
* @param integer fakeMaxLength The maximum length of the field
*
*/
function autojump(myForm, fieldName, nextFieldName, fakeMaxLength) {

	// var myForm = document.forms[document.forms.length - 1];
	var myField = myForm.elements[fieldName];

	myField.nextField = myForm.elements[nextFieldName];

	if (myField.maxLength == null) {
		myField.maxLength = fakeMaxLength;
	}

	myField.onkeydown = autojump_keyDown;
	myField.onkeyup = autojump_keyUp;

} // End of autojump()

/**
* Handler for when a key is pressed down.  It records the current
* length of the form field.
*
*/
function autojump_keyDown() {
	this.beforeLength = this.value.length;
	downStrokeField = this;
}

/**
* Handler when a key is released.
* If the length has changed, and it's greater than or equal to the maximum
* length of the field, focus on the next field.
*
*/
function autojump_keyUp() {
	if (
		(this == downStrokeField) &&
		(this.value.length > this.beforeLength) &&
		(this.value.length >= this.maxLength)
		) {
		this.nextField.focus();
	}

	downStrokeField = null;

} // End of autojump_keyUp()

