// 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) {
	if (entry.length==0) return true;

	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;
	}
}

//validates that the entry is in military time format
function isTime(str) {
	var reg = /^(\d{1,2}):(\d{2})?$/;
//with seconds and am/pm (optional) 
//var reg = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var matchArray = str.match(reg);
	if (matchArray == null) {
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];

	if (hour < 0  || hour > 23) {
		return false;
	}
	if (minute<0 || minute > 59) {
		return false;
	}
	return true;
}

//validates that the entry is URL
function isURL(str) {
	var re = /[http:\/\/,www]?(\w+)\.(\w+)(.*)/
	if(!str.match(re)) 
		{return false;}
	else 
		{return true;}
}
	
function RegExpValid(str, template)
{	
	if(!str.match(template)) {
		return false;}
	else {
		return true;}
}

