
String.prototype.trim = function() 
{
	// adds a trim function to the string datatype
	// skip leading and trailing whitespace and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}


function checkemail(strTest)
{
	// Checks if an email is the valid type of string
	var strFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return strFilter.test(strTest);
}


function numberfilter(evt) {  
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		status = "This field accepts numbers only."
		return false
	}
	status = ""
	return true
}


function forceUCase(evt)  {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which = String.fromCharCode(evt.which).toUpperCase().charCodeAt(0) : evt.keyCode = String.fromCharCode(evt.keyCode).toUpperCase().charCodeAt(0)

}

function isDate(dateStr) {
	// parse date into variables
	day = dateStr.slice(0,2);
	month = dateStr.slice(2,4); 
	year = dateStr.slice(4);
	if (month < 1 || month > 12) { // check month range
		return false;
	}
	
	if (day < 1 || day > 31) {
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			return false;
		}
	}
	return true; // date is valid
}
