/**

  $Id: jshelpers.js,v 1.1 2002/08/19 14:23:53 swhatmor Exp $

*/

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function swapField(whichField,maxLength,e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var keyFilter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	curValue = whichField.value;
	if(curValue.length >= maxLength && !containsElement(keyFilter,keyCode)) {
		curValue = curValue.slice(0, maxLength);
		newField = whichField.form[(getIndex(whichField)+1) % whichField.form.length];
		newField.focus();
	}
	return true;
}

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 getIndex(whichField) {
	var index = -1, i = 0, found = false;
	while (i < whichField.form.length && index == -1)
	if (whichField.form[i] == whichField)index = i;
	else i++;
	return index;
}

function handleKey(field, event, next) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if (keyCode == 9) {
		field.form.elements[next].focus();
		return false;
	} else if (keyCode == 13) {
		field.blur();
		field.focus();
		return false;
	} else {
		return true;
	}
}

function openWindow(theURL, theName, theWidth, theHeight) {
	popup = window.open(theURL,theName,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + theWidth + ',height=' + theHeight);
}
