	var ddName = 'DD';
	var mmName = 'MM';
	var yyName = 'YY';


	function check_form_fert() {
		with (document.mainform) {
			if (!YY.value || !MM.value || !DD.value || !cycle[cycle.selectedIndex].value) {
				alert('Please specify a month, day, year, and cycle.');
				return false;	
			} else {
				if (!valid_date_fert(YY.value, MM.value, DD.value)) {
					alert('Please enter a valid date in the format month, day, year.');
					return false;		
				} else {
					submit();
				}
			}
		}
	}

	function num_in_range(num, start, end) {
		num = parseInt(num);
		if ((num < start) || (num > end) || (isNaN(num))) {
			return false;	
		}
		return true;
	}
	
	function valid_date_fert(year, month, day) {
		month = month.replace(/^0/gi,'');
		month = parseInt(month);
		day = day.replace(/^0/gi,'');
		day = parseInt(day);
		if (!(year && month && day)) {
			return false;
		}

		if (!num_in_range(year, 0, 99)) {
			return false;
		}
		if (!num_in_range(month, 1, 12)) {
			return false;
		}
		
		var end_day;
		
		if (month == 2) {
			end_day = (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
		} else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
			end_day = 30;
		} else {
			end_day = 31;
		}
		if (!num_in_range(day, 1, end_day)) {
			return false;
		}
		return true;
	}	
	
	function DateCalc(arg1, month, day) {
		if (arguments.length == 1) {
			this.jsdate = new Date(arg1);
			this.year = this.jsdate.getFullYear();
			this.month = this.jsdate.getMonth() + 1;
			this.day = this.jsdate.getDate();
		} else {
			this.year = arg1;
			this.month = month;
			this.day = day;
			this.jsdate = new Date(arg1, month - 1, day);
		}
		this.str = this.month + '/' + this.day + '/' + this.year.toString().substr(2,2);
		this.ms = 24 * 60 * 60 * 1000;
		this.add_delta_days = DateCalc_add_delta_days;
	}
	
	function DateCalc_add_delta_days(days) {
		var milliseconds = this.jsdate.valueOf();
		milliseconds += (days * this.ms);
		var newdate = new DateCalc(milliseconds);
		return newdate;
		
	}

function updateIDs(){
	mx_date_LastUTC = new Date();
	monthARR = mx_date_MonthDayList('MLong');
	calOBJ = document.getElementById('calID');
	if (qf[mmName] != null) {
	month = qf[mmName];
	month = month.replace(/^0/gi,'');
	} else {
	month = dateSTR.getMonth()+1;
	}
	if(month<10) month= '0' + month;
	mcore_selectItem(mmName,month,'mainform');
	if (qf[ddName] != null) {
	day = qf[ddName];
	day = day.replace(/^0/gi,'');
	} else {
	day = dateSTR.getDate();
	}
	if(day<10) day = '0' + day;
	mcore_selectItem(ddName,day,'mainform');
	if (qf[yyName] != null) {
	year = qf[yyName];
	year = parseInt(year);
	} else {
	year = dateSTR.getYear();
	}
	if(year<1000) year+=1900;
	year += '';
	mcore_selectItem(yyName,year.substring(2,4),'mainform');
	if (qf['cycle'] != '') {
	cycle = qf['cycle'];
	cycle += '';
	mcore_selectItem('cycle',cycle,'mainform');
	}
}
function returnDate(strDate) {
	toggleDisp('calID','hidden');
	dateSTR = new Date(strDate);
	month = dateSTR.getMonth()+1;
	if(month<10) month= '0' + month;
	mcore_selectItem(mmName,month,'mainform');
	day = dateSTR.getDate();
	if(day<10) day = '0' + day;
	mcore_selectItem(ddName,day,'mainform');
	year = dateSTR.getYear();
	if(year<1000) year+=1900;
	year += '';
	mcore_selectItem(yyName,year.substring(2,4),'mainform');
}

function clearForm(item) {
	item.clear();

}
