// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function pad(number) {
	var intNum;
	intNum = parseFloat(number);
	if (intNum < 10) {
		return '0' + intNum.toString();
	}
	else {
		return intNum.toString();
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================

function isEmpty(s)
//
// Check whether string s is empty.
//
{   return ((s == null) || (s.length == 0))
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isMonth (s){
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
//alert('isMonth ' + s);
	var intMonth;

	if (isEmpty(s)){
		return false;
	}
	intMonth = parseInt(s);
	if (isNaN(intMonth)) {
		return false;
	}
	else {
		return (intMonth > 0 && intMonth < 13);
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isDay (s){
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
//
//alert('isDay ' + s);
	var intDay;

	if (isEmpty(s)){
		return false;
	}
	intDay = parseFloat(s);
	if (isNaN(intDay)) {
		return false;
	}
	else {
		return (intDay > 0 && intDay < 32);
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isYear (s){
// 
// isYear returns true if string s is a valid 
// year between 1990 and 2050
//
//alert('isYear ' + s);
	var intYear;

	if (isEmpty(s)){
		return false;
	}
	intYear = parseFloat(s);
	if (isNaN(intYear)) {
		return false;
	}
	else {
		return (intYear > 1989 && intYear < 2051 || intYear >= 0 && intYear < 100);
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function convertYear (s){
// 
// convertYear will return a four digit year
//  from either a two or four digit string.
//
	var intYear;
	var strYear;
	if (isEmpty(s) || s.length==3){
		return null;
	}
	intYear = parseFloat(s);
	if (isNaN(intYear)) {
		return null;
	}
	if (intYear >= 0 && intYear <= 50) {
		intYear = intYear + 2000;
	}
	if (intYear >90 && intYear < 100) {
		intYear = intYear + 1900;
	}
	return (intYear.toString());
}

// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isDate(s){
// 
// isDate will return true if the date is valid for
// formatted MM/DD/YYYY.
//
//alert('isDate ' + s);
	var aryText;
	aryText = s.split('/');
	if (aryText.length == 1 || aryText.length != 3) return false;
	return isMonth(aryText[0]) && isDay(aryText[1]) && isYear(aryText[2]);
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function formatDate(s){
// 
// isDate will return either null or a date
// formatted MM/DD/YYYY.
//
//alert('formatDate ' + s);
	var strText;
	aryText = s.split("/");
	return pad(aryText[0]) + '/' + pad(aryText[1]) + '/' + convertYear(aryText[2]);
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isHour (s){
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
//alert('isHour ' + s);
	var intHour;

	if (isEmpty(s)){
		return false;
	}
	intHour = parseInt(s);
	if (isNaN(intHour)) {
		return false;
	}
	else {
		return (intHour >= 0 && intHour < 24);
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isMinute (s){
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
//alert('isMinute ' + s);
	var intMinute;

	if (isEmpty(s)){
		return false;
	}
	intMinute = parseInt(s);
	if (isNaN(intMinute)) {
		return false;
	}
	else {
		return (intMinute >= 0 && intMinute < 61);
	}
}
// ===================================================================================================================
// ===================================================================================================================
// ===================================================================================================================
function isTime(s){
//
//  This will make sure that the time format is in the HH:MM format
//
//alert('isTime ' + s)
	var aryText;
	aryText=s.split(':');
	if (aryText.length != 2) return false;
	return (isHour(aryText[0]) && isMinute(aryText[1]));

}
