function YuiDatePicker(formElem,dspObj) {
	
	this.formElem = document.getElementById(formElem);
	this.oParent = formElem;
	this.displayObj = document.getElementById(dspObj);
	this.calendarObj;
	this.over_cal = false;
	this.calDate;
	
	this.init = function() {
		this.calendarObj = new YAHOO.widget.Calendar(this.calendarObj,this.displayObj);
		this.calendarObj.selectEvent.subscribe(this.getFormDate, this.calendarObj, true);
		this.calendarObj.renderEvent.subscribe(this.setupListeners, this.calendarObj, true);
		YAHOO.util.Event.addListener(this.formElem, 'focus', function() { DatePicker[formElem].showCal(); });
		YAHOO.util.Event.addListener(this.formElem, 'blur', function() { DatePicker[formElem].hideCal(); });
		this.calendarObj.render();
	}

	this.setupListeners = function() {
    	YAHOO.util.Event.addListener(dspObj, 'mouseover', function() { DatePicker[formElem].overCal(); });
    	YAHOO.util.Event.addListener(dspObj, 'mouseout', function() { DatePicker[formElem].outCal(); });
	}
	
	this.getFormDate =  function() {
		var calDate = this.getSelectedDates()[0];
        	calDate = (calDate.getMonth() + 1) + '/' + calDate.getDate() + '/' + calDate.getFullYear();
			DatePicker[formElem].setDateField(calDate);
        	DatePicker[formElem].outCal();
        	DatePicker[formElem].hideCal();
		
	}

	this.showCal = function() {
		var xy = YAHOO.util.Dom.getXY(this.formElem);
		var date = YAHOO.util.Dom.get(this.formElem).value;
		if (this.isDate(date)) {
			this.calendarObj.cfg.setProperty('selected', date);
			this.calendarObj.cfg.setProperty('pagedate', new Date(date), true);
			this.calendarObj.render();
		}
		YAHOO.util.Dom.setStyle(this.displayObj, 'display', 'block');
		xy[1] = xy[1] + 20;
		YAHOO.util.Dom.setXY(this.displayObj, xy);
	}
	
	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.hideCal = function() { if (!this.over_cal) {
		var date = YAHOO.util.Dom.get(this.formElem).value;
		this.isDate(date)
		YAHOO.util.Dom.setStyle(this.displayObj, 'display', 'none'); } 
	}
	this.overCal = function() { this.over_cal = true; }
	this.outCal = function() { this.over_cal = false; }
	this.setDateField =  function(sDate) { this.formElem.value = sDate; }
	this.init();

}