//	Function leapYear calculates whether a given year is a leap year, returning true if it 
//	is, else false
function leapYear(iYear){
	if (iYear % 100 == 0){
		if (iYear % 400 == 0){
			return true;
		}
	}
	else{
		if ((iYear % 4) == 0){
			return true;
		}
	}
	return false;
}

//	Function daysInMonth calculates the number of days in a given month & year
function daysInMonth(iMonth, iYear){
	var iDaysInMonth;
	if (iMonth==2){
		if(leapYear(iYear)){
			iDaysInMonth = 29;
		}
		else{
			iDaysInMonth = 28;
		}
	}
	else{
		if(iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11){
			iDaysInMonth = 30;
		}
		else{
			iDaysInMonth = 31;
		}
	}
	return iDaysInMonth;
}

//	Function isDate calculates whether the value in a particular field is valid
//	Returns true if date is valid, else returns false
function isDate(oField){
	var sDate = new String(oField.value);
	var sMatchPattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (!sDate.match(sMatchPattern)){
		return false;
	}
	var iStringPos2 = sDate.lastIndexOf("/");
	iStringPos2 = iStringPos2 + 1;
	var iYear = Number(sDate.substr(iStringPos2, 4));
	var dNow = new Date();
	var iCurYear = dNow.getYear();
	var iStringPos1 = sDate.indexOf("/") + 1;
	var iStringLength = ((iStringPos2 - 1) - iStringPos1);
	var iMonth = Number(sDate.substr(iStringPos1, iStringLength));
	var iDay = Number(sDate.substr(0,iStringPos1 - 1));
	if(iMonth >= 13){
		return false;
	}
	if(iDay > daysInMonth(iMonth, iYear)){
		return false;		
	}
	return true;
}

//	Function isNumber calculates whether the value of the relevant field is a number.
function isNumber(oField){
	return(!isNaN(oField.value));
}

//	Function isFilled calculates whether the relevant field contains any input.
function isFilled(oField){
	return(oField.value.length >= 1);
}

