function YuiDatePicker(formObj,buttonElem,dspObj,calendarOptions) {

	this.formObj = document.getElementById(formObj);
	this.buttonElem = document.getElementById(buttonElem);
	this.displayObj = document.getElementById(dspObj);
	this.calendarObj;
	this.over_cal = false;
	this._showCal = false;
	this.calDate;

	this.init = function() {
		this.calendarObj = new YAHOO.widget.Calendar(this.calendarObj,this.displayObj,calendarOptions);
		this.calendarObj.selectEvent.subscribe(this.getFormDate, this.calendarObj, true);
		this.calendarObj.showNavEvent.subscribe(this.getFormMonth, this.calendarObj, true);
		YAHOO.util.Event.addListener(this.buttonElem, 'click', function() {DatePicker.toggleCal();});
		this.calendarObj.render();
	}

	this.getFormMonth = function() {

		// get month and year
		var month = parseInt(document.getElementById('CalendarArchives_calendar_nav_month').value)+1;
		var year = document.getElementById('CalendarArchives_calendar_nav_year').value;

		// hide default yahoo calendar functionality
		this.oNavigator.hide();

		// figure out last day of month - how many day links are there?
		var endDay = YAHOO.util.Selector.query('a.selector').length;

		document.getElementById('CalendarStartDate').value = month + "/1/" + year;
		document.getElementById('CalendarEndDate').value = month + "/" + endDay + "/" + year;
		document.getElementById(formObj).submit();

	}

	this.getFormDate =  function() {
		var calDate = this.getSelectedDates()[0];
		calDate = (calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear();
		document.getElementById('CalendarStartDate').value = calDate;
		document.getElementById('CalendarEndDate').value = calDate;
		document.getElementById(formObj).submit();
	}

	this.toggleCal = function() {
		if (!this._showCal) {
			this.showCal();
		} else {
			this.hideCal();
		}
	}

	this.showCal = function() {
		YAHOO.util.Dom.setStyle(this.displayObj, 'display', 'block');
		this._showCal = true;
		document.getElementById('calButtonText').innerHTML = "Hide Calendar";
	}

	this.hideCal = function() {
		YAHOO.util.Dom.setStyle(this.displayObj, 'display', 'none');
		this._showCal = false;
		document.getElementById('calButtonText').innerHTML = "View Calendar";
	}

	this.isDate = function(dateStr) {

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = dateStr.match(datePat);

		if (matchArray == null) { return false; }

		month = matchArray[1]; // p@rse date into variables
		day = matchArray[3];
		year = matchArray[5];

		if (month < 1 || month > 12) { 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; // date is valid
	}

	this.init();

}

