//traps an enter key press and causes a specified submit button to be pressed
//used onKeyDown()
function KeyDownHandler(e, btn)
{	
	var code;
	
	//mozilla
	if (e.which)
	{
		code = e.which;
	}
		
	//IE
	if (window.event)
	{
		code = e.keyCode;
	}

	// process only the Enter key
	if (code == 13)
	{
		// cancel the default submit
		//alert(code);
		e.returnValue=false;
		e.cancel = true;
		// submit the form by programmatically clicking the specified button
		btn = document.getElementById(btn);
		if (btn != null)
			btn.click();
	}
}

/*---------------------------------------------------------------------------------
//sets focus to a field element
//used onLoad()
---------------------------------------------------------------------------------*/
function setFocus(field)
{
	if (document.getElementById(field) != null)
		document.getElementById(field).focus();
}

/*---------------------------------------------------------------------------------
- enforces max length on a field
- used onKeyUp() of a field
- Example: <input id="test" type="text" onkeyup="return checkSize(this, 250);"/> 
----------------------------------------------------------------------------------*/
function checkSize(field, maxLen) 
{ 
	if (field.value.length > maxLen)
	{
		field.value = field.value.substring(0,maxLen);
		alert('Text can only be ' + maxLen + ' characters long.');
		field.focus();
	}
}

