// Every single key press action will call this function. 
function shouldCancelbackspace(e) { 
var key; 
if(e){ 
key = e.which? e.which : e.keyCode; 
if(key == null ¦¦ ( key != 8 && key != 13)){ // return when the key is not backspace key. 
return false; 
} 
}else{ 
return false; 
} 

if (e.srcElement) { // in IE 
tag = e.srcElement.tagName.toUpperCase(); 
type = e.srcElement.type; 
readOnly =e.srcElement.readOnly; 
if( type == null){ // Type is null means the mouse focus on a non-form field. disable backspace button 
return true; 
}else{ 
type = e.srcElement.type.toUpperCase(); 
} 

} else { // in FF 
tag = e.target.nodeName.toUpperCase(); 
type = (e.target.type) ? e.target.type.toUpperCase() : ""; 
} 

// 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 true; 
if( ((tag == 'INPUT' && type == 'RADIO') ¦¦ (tag == 'INPUT' && type == 'CHECKBOX')) 
&& (key == 8 ¦¦ key == 13) ){ 
return true; // the mouse is on the radio button/checkbox, disbale the backspace button 
} 
return false; 
} 

// if we are not in one of the above things, then we want to cancel (true) if backspace 
return (key == 8 ¦¦ key == 13); 
} 

// check the browser type 
if(window.event){ 
document.onkeydown = function() { return !shouldCancelbackspace(event); } 
}else { 
document.onkeypress = function(e) { return !shouldCancelbackspace(e); } 
} 


//****************************************************************************
// Check Date Function
// check date JavaScript function
// if date is valid then function returns true, otherwise returns false
//****************************************************************************
function isDatex(txtDate){
  var objDate;  // date object initialized from the txtDate string
  var mSeconds; // milliseconds from txtDate

	// date length should be 10 characters - no more, no less
  if (txtDate.length != 10) return false;

	// extract day, month and year from the txtDate string
	// expected format is mm/dd/yyyy
	// subtraction will cast variables to integer implicitly
  var day   = txtDate.substring(3,5)  - 0;
  var month = txtDate.substring(0,2)  - 1; // because months in JS start with 0
  var year  = txtDate.substring(6,10) - 0;

	// third and sixth character should be /
	if (txtDate.substring(2,3) != '/') return false;
	if (txtDate.substring(5,6) != '/') return false;

  // test year range
  if (year < 999 || year > 3000) return false;

  // convert txtDate to the milliseconds
  mSeconds = (new Date(year, month, day)).getTime();

  // initialize Date() object from calculated milliseconds
  objDate = new Date();
  objDate.setTime(mSeconds);

  // compare input parameter date and created Date() object
  // if difference exists then date isn't valid
  if (objDate.getFullYear() != year)  return false;
  if (objDate.getMonth()    != month) return false;
  if (objDate.getDate()     != day)   return false;

	// otherwise return true
  return true;
}
