function KeyPressHandler(e)
{
	// is it IE?
	if (window.event)
	{
		if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
		{
			event.returnValue = false;
			event.cancel = true;
			return false;
		}
	}
	// or something else?
	else
	{
		if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit')
		{
			e.returnValue = false;
			e.cancel = true;
			e.preventDefault();
			return false;
		}
	}
	return true;
}

function SelectLastRadio(radioGroup)
{
	var iLast = radioGroup.length - 1;
	radioGroup[iLast].checked = true;
}

function MoveOnMaxLength(e, txtBox, nextId)
{
	e = e || window.event;
	var key = e.keyCode || e.which;
	var nextElement = document.getElementById(nextId);
	

	var maxLength = txtBox.maxLength;
	if (maxLength && maxLength < 1)
		maxLength = 250000;

	if (key == 13)
	{
		nextElement.focus();
		return false;
	}
	if (txtBox.value.length >= maxLength)
	{
		if ((key >= 16 && key <=18) || (key >= 35 && key <= 40) || key == 8 || key == 46 || key == 20 || key == 9 || key == undefined)
		{
			// ignore shift, ctrl, alt, arrows, backspace, delete, caps
			return true;
		}
		if (key == 32)
		{
			nextElement.focus();
			return false;
		}
		var iSpace = txtBox.value.lastIndexOf(" ");
		if (iSpace > 0)
		{
			var line1 = txtBox.value.substring(0, iSpace);
			var line2 = txtBox.value.substring(iSpace+1);
			txtBox.value = line1;
			nextElement.focus();
			nextElement.value = line2;
		}
		else
		{
			nextElement.focus();
		}
		return true;		
	}		
} 

function WarnOnMaxLength(e, txtBox)
{
	e = e || window.event;
	key = e.keyCode || e.which;

	var maxLength = txtBox.maxLength;
	if (maxLength && maxLength < 1)
		maxLength = 250000;

	if (txtBox.value.length >= maxLength)
	{
		if ((key >= 16 && key <=18) || (key >= 37 && key <= 40) || key == 8 || key == 46 || key == 20 || key == undefined)
		{
			// ignore shift, ctrl, alt, arrows, backspace, delete, caps
			return true;
		}
		else
		{
			alert('Maximum length reached!');
			return false;
		}
	}
}