define(["dojo/_base/declare","dijit/form/DateTextBox","dojox/widget/Calendar","dojo/date/locale","dijit/form/_FormWidget", "chy/_base/_ValidateMixin",
	"dojo/text!./templates/DropDownBox.html"],function(declare,DateTextBox,Calendar,locale,_FormWidget,_ValidateMixin,template)
{
	return declare("chy.form.DateTextBox", [DateTextBox,_ValidateMixin], {
            ddFormat: {
                selector: 'date',
                datePattern: 'dd-MM-yyyy'
            },
            autoWidth : false,
            dateFormat: "%d-%m-%Y",
            //popupClass: Calendar,
            templateString: template,
            nameAttrSetting: "icon-chevron-down",
            iconClass: "fa fa-calendar",
            //cssClass: "dijitCalendarPopup",
            value: "",
            // prevent parser from trying to convert to Date object
            postMixInProperties: function() { // change value string to Date object
            	//this.popupClass=Calendar;
            	this.autoWidth=false;
            	this.forceWidth=false;
                this.inherited(arguments);
                // convert value to Date object
                //alert(this.value);
                this.value = locale.parse(this.value, this.ddFormat);
            },
            // To write back to the server in Oracle format, override the serialize method:
            serialize: function(dateObject, options) {
            	//alert('serialize');
            	var retVal = locale.format(dateObject, this.ddFormat);
            	var re = new RegExp("/", "g");
                return retVal.replace(re,"-");
            },
			_setValueAttr: function(value,priority,formatted){
				//convert string value to dateobject
				if(typeof value == 'string'){
					value = locale.parse(value, this.ddFormat);
				}
				this.inherited(arguments);
			}
        });
});