
// function to possibly override keypress
trapfunction = function(event)
{
	var keynum;
	var browserType;
	if (window.event) // eg. IE
	{
		keynum = window.event.keyCode;
		browserType = "ie";
	}
	else if (event.which) // eg. Firefox
	{
		keynum = event.which;
		browserType = "ff";
	}
	if (keynum == 8) // backspace has code 8
	{
		if (browserType == "ie") { // in IE
			tag = window.event.srcElement.tagName.toUpperCase();
			type = window.event.srcElement.type;
			readOnly = window.event.srcElement.readOnly;
			if ( type == null){ // Type is null means the mouse focus on a non-form field. Disable backspace button
				return false;
			} else {
				type = window.event.srcElement.type.toUpperCase();
			}
		} else { // in FF
			tag = event.target.nodeName.toUpperCase();
			type = (event.target.type) ? event.target.type.toUpperCase() : "";
			readOnly = event.target.readOnly;
		}

		// we don't want to cancel the keypress (ever) if we are in an input/text area
		if ( tag == 'INPUT' || type == 'TEXT' || type == 'TEXTAREA') {
			if(readOnly == true ) // if the field has been dsabled, disbale the back space button
				return false;
			if( ((tag == 'INPUT' && type == 'RADIO') || (tag == 'INPUT' && type == 'CHECKBOX'))) {
				return false; // the mouse is on the radio button/checkbox, disbale the backspace button
			}
			return true;
		}
		return false;
	}
	return true;
}
document.onkeydown = trapfunction; // IE, Firefox, Safari
document.onkeypress = trapfunction; // only Opera needs the backspace nullifying in onkeypress
