// Function allows for automatic tabbing between fields for for such things as SSNs
// and telephone numbers; It can be used for multiple forms within a page

// Set isNN to true for NN, false for IE
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

// input is the input object, len is the maxium field length and e is the event 
function AutoTab(input,len, e) {
	// Gets keycode depending on type of browser
	var keyCode = (isNN) ? e.which : e.keyCode; 

	// Gets common incorrect keycodes for type of browser, e.g. shift of number keypad
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();}
	return;}

// Function compares the keystroke (ele) against undesirable keystrokes,
// if found returns true, if not found returns false
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length){
		if(arr[index] == ele)
		found = true;
		else
		index++;}
	return found;}

// Function returns the index of the element within the form
function getIndex(input) {
	var index = -1, i = 0;
	while (i < input.form.length && index == -1){
		if (input.form[i] == input)index = i;
		else i++;}
	return index;}