if (typeof AWP == 'undefined') AWP = {};
AWP.DatePicker = function(config) {
	AWP.DatePicker.superclass.constructor.call(this, config);
};

Ext.extend(AWP.DatePicker, Ext.DatePicker, {
	handler : function(dp, date) {
		var input = document.getElementById(this.id);
		input.value = date.format('Y-m-d'); 
		
		AWP.DatePicker.show(this.id);
	}
});

AWP.calendars = {};
AWP.DatePicker.show = function(id) {
	if (!AWP.calendars[id]) {
		var input = document.getElementById(id);
		
		var c = document.createElement('div');
		c.style.position = 'absolute';
		c.style.zIndex = 10000;
		Ext.fly(c).alignTo(input);
		
		document.body.insertBefore(c, null);
		AWP.calendars[id] = new AWP.DatePicker({
			id: id,
			renderTo: c,
			format: "Y-m-d"
		});
	} else {
		AWP.calendars[id].destroy();
		delete AWP.calendars[id];
	}
}
