	//=========================================================================
	// Check if the value of an input field is a valid date.
	//=========================================================================
	function IsValidDate(sValue) {
	var MONTH_NAME = new Array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	var expDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/
	var iDay, iMonth, iYear;
	var hReturnInfo = new ReturnInfo(0, '', 0);

		//Fromat the date properly.
		sValue = FormatDate(sValue);

		//Check that the date was entered in the proper format.
		if (!expDate.test(sValue)) {
			hReturnInfo.ReturnCode = 1;
			hReturnInfo.ErrorDescription = 'Please enter a date in this format MM/DD/YYYY (for example: 12/13/1976).';
		}               


		if (hReturnInfo.ReturnCode == 0) {
			//Split the date string into day, month and year.
			iMonth = sValue.substring(0, sValue.indexOf('/'));
			iDay = sValue.substring(sValue.indexOf('/')+1, sValue.indexOf('/',3));
			iYear = sValue.substring(sValue.indexOf('/',3)+1, sValue.length);
				
			if ((iMonth < 1) || (iMonth > 12)) {
				hReturnInfo.ReturnCode = 2;
				hReturnInfo.ErrorDescription = 'Please enter a month between 1 and 12.';
			}
		}


		//Check that the day ranges between 1 and 31.		
		if (hReturnInfo.ReturnCode == 0) 
			if ((iDay < 1) || (iDay > 31)) {
				hReturnInfo.ReturnCode = 3;
				hReturnInfo.ErrorDescription = 'Please enter a day between 1 and 31.';
			}


		//Check that the day is 30 or less for the 4,6,9 and 11 months.
		if (hReturnInfo.ReturnCode == 0) 
			if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30)) {
				hReturnInfo.ReturnCode = 4;
				hReturnInfo.ErrorDescription = MONTH_NAME[iMonth] + ' is a 30 days long month.';
			}


		//Check that the day is 29 or less for a february in a leap year
		//and 28 or less in a non leap year.  
		if (hReturnInfo.ReturnCode == 0) 
			if (iMonth == 2) {
				if (IsLeapYear(iYear)) {
					if (iDay > 29) {
						hReturnInfo.ReturnCode = 5;
						hReturnInfo.ErrorDescription = 'February is 29 days long in a leap year.';
					}
				}
				else {
					if (iDay > 28) {
						hReturnInfo.ReturnCode = 5;
						hReturnInfo.ErrorDescription = 'February is 28 days long in a non leap year.';
					}
				}
			}
		

		//Check that the year is in logical range.
		if (hReturnInfo.ReturnCode == 0) 
			if ((iYear < 1000) || (iYear > 2500)) {
				hReturnInfo.ReturnCode = 6;
				hReturnInfo.ErrorDescription = 'Please enter a logical year.';
			}	
							
		return hReturnInfo;
	}
	



	//=========================================================================
	// Comparing to input fields that contain dates according to a specified
	// condition.
	//
	// Return Codes:
	//    0: The dates comply with comparison.
	//    1 to 6: See IsValidDate() above.
	//    9: The dates do not comply with comparison.
	//=========================================================================
	function CompareDates(sValue1, sValue2, sCondition) {
	var sDay1, sMonth1, sYear1, sDay2, sMonth2, sYear2;
	var bCompareSuccessful = true;
	var hReturnInfo = new ReturnInfo(0, '', 0);

		//Check that the first date is valid.
		hReturnInfo = IsValidDate(sValue1);
		hReturnInfo.ErrorField = 1; 
		
		if (hReturnInfo.ReturnCode == 0) {
			//Fromat the date properly.
			sValue1 = FormatDate(sValue1);

			//Split the first date string into day, month and year.
			sMonth1 = '0' + sValue1.substring(0, sValue1.indexOf('/'));
			sDay1 = '0' + sValue1.substring(sValue1.indexOf('/')+1, sValue1.indexOf('/',3));
			sYear1 = sValue1.substring(sValue1.indexOf('/',3)+1, sValue1.length);
		
			//Compiling the date as a number in order to enable comparison.
			sValue1 = sYear1 + sMonth1.substring(sMonth1.length-2, sMonth1.length) + sDay1.substring(sDay1.length-2, sDay1.length)
			
			//Check that the second date is valid.
			hReturnInfo = IsValidDate(sValue2);
			hReturnInfo.ErrorField = 2; 
		}

		if (hReturnInfo.ReturnCode == 0) {
			//Fromat the date properly.
			sValue2 = FormatDate(sValue2);

			//Split the second date string into day, month and year.
			sMonth2 = '0' + sValue2.substring(0, sValue2.indexOf('/'));
			sDay2 = '0' + sValue2.substring(sValue2.indexOf('/')+1, sValue2.indexOf('/',3));
			sYear2 = sValue2.substring(sValue2.indexOf('/',3)+1, sValue2.length);

			//Compiling the date as a number in order to enable comparison.
			sValue2 = sYear2 + sMonth2.substring(sMonth2.length-2, sMonth2.length) + sDay2.substring(sDay2.length-2, sDay2.length)

			//Comparing the dates according to the specified condition.
			switch (sCondition) {
			case 'LT':
				bCompareSuccessful = (Number(sValue1) < Number(sValue2));
				break;

			case 'LE':
				bCompareSuccessful = (Number(sValue1) <= Number(sValue2));
				break;

			case 'EQ':
				bCompareSuccessful = (Number(sValue1) == Number(sValue2));
				break;

			case 'GE':
				bCompareSuccessful = (Number(sValue1) >= Number(sValue2));
				break;

			case 'GT':
				bCompareSuccessful = (Number(sValue1) > Number(sValue2));
				break;
		
			default:
				bCompareSuccessful = false;
			}
			
			
			if (!bCompareSuccessful) {
				hReturnInfo.ReturnCode = 9;
				hReturnInfo.ErrorDescription = '';
				hReturnInfo.ErrorField = 0;
			}
		}

		return hReturnInfo;
	}



	//=========================================================================
	// Check if a certain year is a leap year.
	//=========================================================================
	function IsLeapYear(iYear) {
		if ((iYear % 4) == 0) 
			if ((iYear % 100) == 0)
				return ((iYear % 400) == 0)
			else
				return true;
		else
			return false;
	}



	//=========================================================================
	// Format a date in a proper form. ie. MM/DD/YYYY
	//=========================================================================
	function FormatDate(sDate) {
	var expReplace = /\-|\./g
	var sYear;
	
		sDate = sDate.replace(expReplace, '/');

		sYear = sDate.substring(sDate.indexOf('/',3)+1, sDate.length);
		if (sYear.length == 2)
			sYear = '20' + sYear;
			
		sDate = sDate.substring(0, sDate.indexOf('/',3)+1) + sYear;
	
		return sDate;
	}