// JScript source code
// validates that the field value string has one or more characters in it
function isNotEmpty(str) {
    var re = /.+/;
    if(!str.match(re)) {return false;} else {return true;}
}
   
//validates that the entry is a positive or negative number
function isNumber(str) {
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) {return false;}
    return true;
}
   
// validates that the entry is 16 characters long when
// input field's maxlength attribute is set to 16
function isLen(str, maxlength) {
	var re = new RegExp('\\b.{'+maxlength+'}\\b',"ig");
    if (!str.match(re)) {return false;} else {return true;}
}
   
// validates that the entry is formatted as an email address
function isEMailAddr(str) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {return false;} else {return true;}
}

function isDate(entry, dateformat) {
	var dt=parsedate(entry, dateformat);
	if (!dt) {return false}
    var testDate = new Date(dt.year, dt.month-1, dt.day);
	if (testDate.getDate() == dt.day) {
		if (testDate.getMonth() + 1 == dt.month) {
			if (testDate.getFullYear() == dt.year) {
                    return true;
			} 
		} 
     } 
	 return false

}
//parse the string dt and return object with properties: day, month, year
//date format is one of the follow string: 
//
function parsedate(dt, dateformat) {
	var reg = /\b(\d{1,2})[\/-](\d{1,2})[\/-](\d{2,4})\b/;
	var mat=reg.exec(dt);
	if (!mat) {return false;}
	if (mat.length!=4) {return false}

	var d=new Object();
	d.year=parseInt(mat[3]);
	
	if (d.year<100) {
		if (d.year>50) {d.year=1900+d.year} else {d.year=2000+d.year}
	}
	
	switch (dateformat) {
		case "MM\/DD\/YYYY" :
			d.day=mat[2]; d.month=mat[1];
			return d;
			break;
		case "MM\/DD\/YY" :
			d.day=mat[2]; d.month=mat[1];
			return d;
			break;
		case "MM-DD-YYYY" :
			d.day=mat[2]; d.month=mat[1];
			return d;
			break;
		case "MM-DD-YY" :
			d.day=mat[2]; d.month=mat[1];
			return d;
			break;
		case "DD\/MM\/YYYY" :
			d.day=mat[1]; d.month=mat[2];
			return d;
			break;
		case "DD\/MM\/YY" :
			d.day=mat[1]; d.month=mat[2];
			return d;
			break;
		case "DD-MM-YYYY" :
			d.day=mat[1]; d.month=mat[2];
			return d;
			break;
		case "DD-MM-YY" :
			d.day=mat[1]; d.month=mat[2];
			return d;
			break;
		default :
			d.day=mat[1]; d.month=mat[2];
			return d;
	}			
	
}


