function kSubmitForm(theForm,commandType,commandTrigger,command,redirectType,redirectTrigger,redirect,redirectTarget) {
	if (theForm.onsubmit) {
		theForm.onsubmit();
	}
	if (commandType) {
		theForm.kCommandType.value=commandType;
		theForm.kCommand.value=command;
		theForm.kCommandTrigger.value=commandTrigger;
	}
	if (redirectType) {
		theForm.kRedirectType.value=redirectType;
		theForm.kRedirect.value=redirect;
		theForm.kRedirectTrigger.value=redirectTrigger;
		theForm.kRedirectTarget.value=redirectTarget;
	}
	theForm.submit();
	return false;
}

function disableForm(formName) {
	document.body.style.cursor='wait';
	setTimeout('disableFormElements('+formName+')',0);
	return true;
}

function disableFormElements(formName) {
	var theForm = eval(formName);
	for (var j=0; j<theForm.length; j++) {
		theForm.elements[j].style.cursor='wait';
		if (theForm.elements[j].type != undefined) {
			if (theForm.elements[j].type.substring(0,6) == "submit") {
				theForm.elements[j].disabled=1;
			}
		}
	}
}

var KBROWSER_IE 	= 1;
var KBROWSER_MOZILLA 	= 2;
var KBROWSER_UNKNOWN 	= 4;
function KBrowser() {
	var ua = window.navigator.userAgent.toLowerCase();
	if(ua.indexOf("msie") > -1) {
		this.type = KBROWSER_IE;
	} else if(ua.indexOf("gecko") > -1) {
		this.type = KBROWSER_MOZILLA;
	} else {
		this.type = KBROWSER_UNKNOWN;
	}
	this.version = parseInt(window.navigator.appVersion);
	this.isIE = function kIsIE() {return this.type == KBROWSER_IE;};
}

var kNextField;
var kPreviousField;
/**
 * Activated when the user hits tab
 */
function tabTo(nextField) {
	var browser = new KBrowser();
	switch(event.keyCode) {
		case 9 : {
			var e = window.event;
			if(browser.isIE()) {
				if(!e.shiftKey) {
					window.event.returnValue = false;
					nextField.focus();
				}
			} else {
				if(e.modifiers & Event.SHIFT_MASK == 0) {
					kNextField = nextField;
					setTimeout("focusNextTabField();",0);
				}
			}
			break;
		}
	}		
	return false;
}

function focusNextTabField() {
	kNextField.focus();
}

/**
 * Activated when the user hits shift+tab
 */
function tabBackTo(eField) {
	var browser = new KBrowser();
	switch(event.keyCode) {
		case 9 : {
			var e = window.event;
			if(browser.isIE()) {
				if(e.shiftKey) {
					window.event.returnValue = false;
					eField.focus();
				}
			} else {
				if(e.modifiers & Event.SHIFT_MASK) {
					kPreviousField = eField;
					setTimeout("focusPreviousTabField();",0);				
				}
			}
			break;
		}
	}		
	return false;
}

function focusPreviousTabField() {
	kPreviousField.focus();
}

//Most of the Code for kMaxLength functions comes
//from http://www.siteexperts.com/ie5/htc/ts08/page2.asp
//These only work in IE 5,6
function kMaxLengthKeyPress(eField,iLength) {
	//No max length if iLength = 0
	if(iLength == 0) return;
	//This method is actully called before the keypress actually
	//puts a value in the field so see if one more char can be added
	if(eField.value.length+1 <= iLength) return;
	//Stops event from propogating to the field and adding another char
	event.returnValue = false;
}
function kMaxLengthBeforePaste(eField,iLength) { event.returnValue = false; }
function kMaxLengthPaste(eField,iLength) {
	event.returnValue = false;
	//Get the selected text (will be part of the passed in eField)
	var oTR = document.selection.createRange();
	//Calculates how many chars can be inserted into the field
	//taking into account characters replaced in the selection
	var iInsertLength = iLength - eField.value.length + oTR.text.length;
	//Truncates the pasting data based on # chars left
	var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
	//Sets the pasted text in the selected text range
	oTR.text = sData;
}

