  var mydate = new Date();
  var thisYear = mydate.getFullYear();
  var thisMonth = mydate.getMonth() + 1;
  var thisDay = mydate.getDate();
  var nextYear = mydate.getFullYear() + 1;


//*************************************************************************
// Return true if a numberField is all number and nothing else
//(can be a floating point number)
//*************************************************************************
function isDecimalNumbersOnly(numberValue) 
{
	var tempString = numberValue.replace(/[0-9]/gi,'');
	tempString = tempString.replace(/[.]?/,'');
	return (tempString.length == 0);
}


//*************************************************************************
// Return true if a numberField is all numbers and nothing else.
//*************************************************************************
function isNumbersOnly(numberValue) 
{
	var tempString = numberValue.replace(/[0-9]/gi,'');
	return (tempString.length == 0);
}

//*************************************************************************
// Return true if a number in a field is valid
//*************************************************************************
function isNumberValid(message, theField)
{
	if (! (isNumbersOnly(theField.value)))
	{
		errorMessage(theField, message);
		return false;
	}
	return true;
}


//*************************************************************************
// Return true if a number with decimals in a field is valid
//*************************************************************************
function isDecimalValid(message, theField)
{
	if (! (isDecimalNumbersOnly(theField.value)))
	{
		errorMessage(theField, message);
		return false;
	}
	return true;
}


//*************************************************************************
// Return true if a number with dollar signs in a field is valid
//*************************************************************************
function isNumberOrDollarValid(message, theField)
{
	if (!(isNumbersOrDollarSignOnly(theField.value)))
	{
		errorMessage(theField, message);
		return false;
	}
	return true;
}


//*************************************************************************
// Returns an empty message if the day is valid otherwise the
// message returned contains the problem with the value
//*************************************************************************
function isDayValid(dayValue) 
{
	var result = true;
	message = "";
	if (passMandatoryCheck(dayValue) && isNumbersOnly(dayValue)) 
	{
		if ((dayValue < 1) && (dayValue > 31)) 
		{
			return "Day must be between 1 and 31";
		} else {
			return "";
		}
	} else {
		return "Day is not valid";
	}
}


//*************************************************************************
// Returns an empty message if the month is valid otherwise the
// message returned contains the problem with the value
//*************************************************************************
function isMonthValid(monthValue) 
{
	if (passMandatoryCheck(monthValue) && isNumbersOnly(monthValue)) 
	{
		if ((monthValue < 1) || (monthValue > 12)) 
		{
			return "Month must be between 1 and 12";
		} else {
			return "";
		}
	} else {
		return "Month is not valid";
	}
}


//*************************************************************************
// Returns an empty message if the year is valid otherwise the
// message returned contains the problem with the value
//*************************************************************************
function isYearValid(yearValue, lowLimit, highLimit, message) 
{
	if (isNumbersOnly(yearValue.value) && (yearValue.value.length == 4)) 
	{
		if ((yearValue.value < lowLimit) || (yearValue.value > highLimit)) 
		{
			errorMessage(yearValue, message);
			return false;
		}
	} else {
		errorMessage(yearValue, message);
		return false;
	}
	return true;
}


//*************************************************************************
// Returns true if the date entered is before today
//*************************************************************************
function isDateOfBirthBeforeToday(message, dayField, monthField, yearField) 
{
	year = yearField.options[yearField.selectedIndex].value;
	day = dayField.options[dayField.selectedIndex].value;
	month = monthField.options[monthField.selectedIndex].value;

	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);
		
	var dob = new Date(year, month - 1, day, 0, 0, 0, 0);
	

	if (today.getTime() < dob.getTime())
	{
		errorMessageB(dayField, message);
		return false;	
	} else {
		return true;	
	}
}


//*************************************************************************
// Returns true if the date entered is after today
//*************************************************************************
function isDateAfterToday(message, dayField, monthField, yearField) 
{
	year = yearField.options[yearField.selectedIndex].value;
	day = dayField.options[dayField.selectedIndex].value;
	month = monthField.options[monthField.selectedIndex].value;
		
	var myDate = new Date(year, month - 1, day, 0, 0, 0, 0);

	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);

	if (today.getTime() > myDate.getTime())
	{
		errorMessageB(dayField, message);
		return false;
	} else {
		return true;
	}
}


//*************************************************************************
// Returns true if the date entered is after today (with no day field passed)
//*************************************************************************
function isShortDateBeforeToday(message, monthField, yearField) 
{
	year = yearField.options[yearField.selectedIndex].value;
	month = monthField.options[monthField.selectedIndex].value;

	if (year <= thisYear)
	{
		if ((month) < thisMonth)		
		{
			errorMessageB(monthField, message);
			return true;	
		} else {
			return false;	
		}
	}

}


//*************************************************************************
// Returns true if the date entered is after today
//*************************************************************************
function areDatesInOrder(message, dayField1, monthField1, yearField1, dayField2, monthField2, yearField2) 
{
	year1 = yearField1.options[yearField1.selectedIndex].value;
	month1 = monthField1.options[monthField1.selectedIndex].value;
	day1 = dayField1.options[dayField1.selectedIndex].value;

	year2 = yearField2.options[yearField2.selectedIndex].value;
	month2 = monthField2.options[monthField2.selectedIndex].value;
	day2 = dayField2.options[dayField2.selectedIndex].value;

	var date1 = new Date(year1, month1 - 1, day1, 0, 0, 0);	
	var date2 = new Date(year2, month2 - 1, day2, 0, 0, 0);

	if (date2.getTime() < date1.getTime())
	{
		errorMessageB(dayField2, message);
		return false;	
	} else {
		return true;	
	}
}


//*************************************************************************
// Returns true if the date is valid
//*************************************************************************
function validDate(message, dayField, monthField, yearField)
{   
	year = yearField.options[yearField.selectedIndex].value;
	month = monthField.options[monthField.selectedIndex].value;
	day = dayField.options[dayField.selectedIndex].value;

	//alert(day+' / '+month+' / '+year);

	// create a date and if values are not equal then we are not using valid dates
 	var testDate = new Date(99, 11, 31);
 
	testDate.setFullYear(year);
	testDate.setDate(day);
	testDate.setMonth(month - 1);

	//alert(testDate);

	if (!((testDate.getDate() == day) && (testDate.getMonth() == (month - 1)))) 
	{ 
		errorMessageB(dayField, message);
		return false;
	} else {
		return true;
	}
}

//*************************************************************************
// Returns true if the date entered is after today
//
// Parameters:
// 
// message     Error message to be displayed if function fails
// day         The numeric value of the day (1..31)
// month       The numeric value of the month (1..12)
// year        The numeric value of the year (1900..2000)
// focusField  The field that browser focus will be return to  
//
//*************************************************************************
function isDOBByValueBeforeToday(message, day, month, year, focusField) 
{
	//year = yearField.options[yearField.selectedIndex].value;
	//day = dayField.options[dayField.selectedIndex].value;
	//month = monthField.options[monthField.selectedIndex].value;

	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
		
	var dob = new Date(year, month - 1, day, 0, 0, 0);

	if (today.getTime() < dob.getTime())
	{
		errorMessageB(focusField, message);
		return false;	
	} else {
		return true;	
	}
}


//*************************************************************************
// Return a section of a date string
//*************************************************************************
function dateSection(theString, section, seperator)
{
	dateString = 0;
	x = theString.indexOf(seperator, 0);
	y = theString.indexOf(seperator, x + 1);

	if (y == -1) (y = theString.length)
	
	if (section == 'one')
	{
		dateString = theString.substring(0, x);
	}
	else if (section == 'two')
	{
		dateString = theString.substring(x + 1, y);
	}
	else if (section == 'three')
	{
		dateString = theString.substring(y, theString.length);	
	}
	
	return dateString	
}


//*************************************************************************
// Return the age, when passed the day, month and year or birth.
//*************************************************************************
function personsAge(dobDay, dobMonth, dobYear)
{
	var age = thisYear - dobYear;

	if (thisMonth < dobMonth){
		age = age - 1;}
		
	if (thisMonth == dobMonth){
		if (thisDay < dobDay){
			age = age - 1;}}
			
	return age;
	
}
























