def date_field(object_name, method, options={})
format = options.delete(:format) ||
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] ||
'%d %b %Y'
if options[:value].is_a?(Date)
options[:value] = options[:value].strftime(format)
end
months = Date::MONTHNAMES[1..12].collect { |m| "'#{m}'" }
months = '[' + months.join(',') + ']'
days = Date::DAYNAMES.collect { |d| "'#{d}'" }
days = '[' + days.join(',') + ']'
options = {:onfocus => "this.select();calendar_open(this,{format:'#{format}',images_dir:'/images',month_names:#{months},day_names:#{days}})",
:onclick => "event.cancelBubble=true;this.select();calendar_open(this,{format:'#{format}',images_dir:'/images',month_names:#{months},day_names:#{days}})",
}.merge(options);
text_field object_name, method, options
end