function checkAllValidDate(frmThis, sSYearName, sSMonthName, sSDayName, sSHourName, sSMinName, sEYearName, sEMonthName, sEDayName, sEHourName, sEMinName)
{
	var oObj, iYear, iMonth, iDay, iHour, iMinute;

	iYear = getDateValue(frmThis, sSYearName, 1);
	iMonth = getDateValue(frmThis, sSMonthName, 2);
	iDay = getDateValue(frmThis, sSDayName, 3);

	if(!checkValidDate(iDay, iMonth, iYear))
		return false;

	iYear = getDateValue(frmThis, sEYearName, 1);
	iMonth = getDateValue(frmThis, sEMonthName, 2);
	iDay = getDateValue(frmThis, sEDayName, 3);

	if(!checkValidDate(iDay, iMonth, iYear))
		return false;
	
	return true;
}

function checkNotLater(frmThis, sSYearName, sSMonthName, sSDayName, sSHourName, sSMinName, sEYearName, sEMonthName, sEDayName, sEHourName, sEMinName)
{
	var oStart, oEnd;

	oStart = getDateObj(frmThis, sSYearName, sSMonthName, sSDayName, sSHourName, sSMinName);
	oEnd = getDateObj(frmThis, sEYearName, sEMonthName, sEDayName, sEHourName, sEMinName);

	if(!checkDatePeriod(oStart, oEnd))
		return false;

	return true;
}

function getDateValue(frmThis, sName, iType)
{
	var iValue, oObj;

	if (sName != "")
	{
		oObj =  eval("frmThis." + sName);
		iValue = parseInt(oObj.options[oObj.selectedIndex].value);
	}	
	else
	{
		var oDate = new Date();

		switch(iType)
		{
			case 1:
				iValue = oDate.getYear();
				break;
			case 2:
				iValue = oDate.getMonth() + 1;
				break;
			case 3:
				iValue = oDate.getDate();
				break;
			default:
				iValue = 0;
				break;
		}
	}

	return iValue;
}

function getDateObj(frmThis, sYearName, sMonthName, sDayName, sHourName, sMinName)
{
	var oObj, iYear, iMonth, iDay, iHour, iMinute;
	
	iYear = getDateValue(frmThis, sYearName, 1);
	iMonth = getDateValue(frmThis, sMonthName, 2);
	iDay = getDateValue(frmThis, sDayName, 3);
	iHour = getDateValue(frmThis, sHourName, 0);
	iMinute = getDateValue(frmThis, sMinName, 0);

	oObj = changeToDateObj(iYear, iMonth, iDay, iHour, iMinute);
	return oObj;
}

function changeToDateObj(iYear, iMonth, iDay, iHour, iMinute)
{
	var oDate = new Date(iYear, iMonth - 1, iDay, iHour, iMinute);
	return oDate;
}

function checkDatePeriod(oStart, oEnd)
{
	if(oEnd < oStart)
	{
		alert("The end date must be later than the start date.");
		return false;
	}

	return true;
}

function IsValidYear(fldNum)
{
	var strNumber = "+-0123456789."

	var strNum = Trim(fldNum.value);
	//alert (strNum);
	var i;
	for (i = 0; i < strNum.length; i++)
	{
		if (strNumber.indexOf(strNum.charAt(i)) < 0)
		{
			alert('Please enter a valid number for ' + fldNum.name + '!');
			fldNum.focus();
			return false;
		}
	}
	if (strNum < 1900 || strNum > 2010) {
		alert("Please enter correct year");
		return false;
	}
	return true;
}

function fIsValidDate(dateStr) {
	var g_sDateFormat = "dd/mm/yyyy";
	if (dateStr != "")
	{
		var matchArray;
		
		var re = /, /g;
		dateStr = dateStr.replace(re, "/");
		re = / /g;
		dateStr = dateStr.replace(re, "/");
		re = /-/g;
		dateStr = dateStr.replace(re, "/");
	
		matchArray = dateStr.split("/");
		if (matchArray == null || matchArray.length != 3) {
			alert("Please input a valid date format: " + g_sDateFormat);
			return false;
		}

		var month, day, year;
		if (g_sDateFormat == "dd/mm/yyyy")
		{
			year = matchArray[2];
			month = matchArray[1];
			day = matchArray[0];
		}

		if (year < 1900 || year > 2010) {
			alert("Please enter correct year");
			return false;
		}
		if (month < 1 || month > 12) { // check month range
			alert("Month must be between 1 and 12.");
			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!")
			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!");
				return false;
		   }
		}

		return true;
	}

	return false;  // date is valid
}

function checkValidDate(iDay, iMonth, iYear)
{
	if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay==31) 
	{
		if (iMonth==4)
		{
			alert("April doesn't have 31 days.");
			return false;
		}
		else if (iMonth==6)
		{
			alert("June doesn't have 31 days.");
			return false;
		}
		else if (iMonth==9)
		{
			alert("September doesn't have 31 days.");
			return false;
		}
		else if (iMonth==11)
		{
			alert("November doesn't have 31 days.");
			return false;
		}
	}

	if (iMonth == 2) { // check for february 29th
		var isleap = (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0));
		if (iDay > 29 || (iDay == 29 && !isleap)) {
			alert("February " + iYear + " doesn't have " + iDay + " days.");
			return false;
	   }
	}

	return true;
}