// Checks for the following valid date formats:
// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
function isValidDate(dateStr) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) 
	{
		alert(dateStr + " Date is not in a valid format. Please ensure the date is entered in the format of dd/mm/yyyy.")
		return false;
	}
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) // check month range
	{ 
		alert("Month must be between 1 and 12. Please ensure the date is entered in the format of dd/mm/yyyy.");
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days! Please ensure the date is entered in the format of dd/mm/yyyy.")
		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)) 
		{
			alert("February " + year + " doesn't have " + day + " days! Please ensure the date is entered in the format of dd/mm/yyyy.");
			return false;
		}
	}
	return true;
}

// Check time is ok
function isValidTime(timeStr)
{
	var timePat = /^(\d{1,2})(:)(\d{1,2})$/; 
	var matchArray = timeStr.match(timePat); // is the format ok?

	if (matchArray == null || matchArray[1] > 23 || matchArray[3] > 59)
	{
		alert("Time is invalid enter in form 00:00, i.e. 14:30");
		return false;
	}
	return true;
}

// Check email address is valid
function isEmail(eml)
{
	if (eml.value.indexOf("@") + "" != "-1" &&
		eml.value.indexOf(".") + "" != "-1" &&
		eml.value != "")
	return true;
	else return false;
}
// Validate Integers
function isValidInteger(num)
{
	var len=num.length
	var digits="0123456789"

	for(i=0; i<len; i++)
	{if (digits.indexOf(num.charAt(i))<0)
	{return false;
	break;}
	}
	return true;
}
