Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.219
diff -u -r1.219 webform.module
--- webform.module	10 Apr 2010 20:30:01 -0000	1.219
+++ webform.module	11 Apr 2010 05:44:06 -0000
@@ -1354,6 +1354,12 @@
 function webform_client_form($form, $form_state, $node, $submission, $is_draft = FALSE, $filter = TRUE) {
   global $user;
 
+  // Attach necessary JavaScript and CSS.
+  $form['#attached'] = array(
+    'css' => array(drupal_get_path('module', 'webform') . '/css/webform.css'),
+    'js' => array(drupal_get_path('module', 'webform') . '/js/webform.js'),
+  );
+
   // Add a theme function for this form.
   $form['#theme'] = array('webform_form_' . $node->nid, 'webform_form');
 
Index: js/webform-admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/js/webform-admin.js,v
retrieving revision 1.2
diff -u -r1.2 webform-admin.js
--- js/webform-admin.js	10 Apr 2010 22:02:11 -0000	1.2
+++ js/webform-admin.js	11 Apr 2010 05:44:07 -0000
@@ -17,7 +17,7 @@
   Drupal.webform.tableSelectIndentation(context);
 }
 
-Drupal.webform = new Object();
+Drupal.webform = Drupal.webform || {};
 
 Drupal.webform.defaultValues = function(context) {
   var $fields = $('.webform-default-value:not(.error)', context);
Index: components/date.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/date.inc,v
retrieving revision 1.37
diff -u -r1.37 date.inc
--- components/date.inc	26 Mar 2010 00:09:08 -0000	1.37
+++ components/date.inc	11 Apr 2010 05:44:07 -0000
@@ -23,6 +23,7 @@
       'year_start' => '1900',
       'year_end' => '2050',
       'year_textfield' => 0,
+      'datepicker' => 1,
       'description' => '',
     ),
   );
@@ -39,6 +40,10 @@
     'webform_display_date' => array(
       'render element' => 'element',
     ),
+    'webform_calendar' => array(
+      'variables' => array('component' => NULL, 'calendar_classes' => NULL),
+      'template' => 'templates/webform-calendar',
+    ),
   );
 }
 
@@ -66,6 +71,15 @@
     '#access' => variable_get('configurable_timezones', 1),
   );
 
+  $form['display']['datepicker'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable popup calendar'),
+    '#default_value' => $component['extra']['datepicker'],
+    '#description' => t('Enable a JavaScript date picker next to the date field.'),
+    '#weight' => 2,
+    '#parents' => array('extra', 'datepicker'),
+  );
+
   $form['display']['year_textfield'] = array(
     '#type' => 'checkbox',
     '#title' => t('Use a textfield for year'),
@@ -111,12 +125,23 @@
     '#prefix' => '<div class="webform-component webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
     '#suffix' => '</div>',
     '#required' => $component['mandatory'],
+    '#year_start' => $component['extra']['year_start'],
+    '#year_end' => $component['extra']['year_end'],
     '#webform_component' => $component,
     '#process' => array('webform_expand_date'),
     '#theme' => 'webform_date',
     '#element_validate' => array('webform_validate_date'),
   );
 
+  if ($component['extra']['datepicker']) {
+    $element['#datepicker'] = TRUE;
+    $element['#attached'] = array(
+      'library' => array(
+        array('system', 'ui.datepicker'),
+      ),
+    );
+  }
+
   if (isset($value[0]) && $value[0] !== '') {
     $value = webform_date_array($value[0], 'date');
     $element['#default_value'] = $value;
@@ -189,8 +214,8 @@
     $element['year']['#maxlength'] = 4;
     unset($element['year']['#options']);
   }
-  elseif (is_numeric($component['extra']['year_start']) && is_numeric($component['extra']['year_end'])) {
-    $element['year']['#options'] = array('' => t('Year')) + drupal_map_assoc(range($component['extra']['year_start'], $component['extra']['year_end']));
+  elseif (is_numeric($element['#year_start']) && is_numeric($element['#year_end'])) {
+    $element['year']['#options'] = array('' => t('Year')) + drupal_map_assoc(range($element['#year_start'], $element['#year_end']));
   }
 
   return $element;
@@ -202,17 +227,39 @@
 function theme_webform_date($variables) {
   $element = $variables['element'];
 
+  $element['year']['#attributes']['class'] = array('year');
+  $element['month']['#attributes']['class'] = array('month');
+  $element['day']['#attributes']['class'] = array('day');
+
   // Add error classes to all items within the element.
   if (form_get_error($element)) {
-    $element['year']['#attributes']['class'] = array('error');
-    $element['month']['#attributes']['class'] = array('error');
-    $element['day']['#attributes']['class'] = array('error');
+    $element['year']['#attributes']['class'][] = 'error';
+    $element['month']['#attributes']['class'][] = 'error';
+    $element['day']['#attributes']['class'][] = 'error';
+  }
+
+  $class = array('container-inline');
+
+  // Add the JavaScript calendar if available (provided by Date module package).
+  if (!empty($element['#datepicker'])) {
+    $class[] = 'webform-datepicker';
+    $calendar_class = array('webform-calendar');
+    if ($element['#year_start'] && is_numeric($element['#year_start'])) {
+      $calendar_class[] = 'webform-calendar-start-' . $element['#year_start'];
+    }
+    if ($element['#year_start'] && is_numeric($element['#year_end'])) {
+      $calendar_class[] = 'webform-calendar-end-' . $element['#year_end'];
+    }
+
+    $calendar = theme('webform_calendar', array('component' => $element['#webform_component'], 'calendar_classes' => $calendar_class));
   }
 
   $output = '';
-  $output .= '<div class="container-inline">';
+  $output .= '<div class="' . implode(' ', $class) . '">';
   $output .= drupal_render_children($element);
+  $output .= isset($calendar) ? $calendar : '';
   $output .= '</div>';
+
   return $output;
 }
 
@@ -239,10 +286,10 @@
     }
   }
   // Check the date is between allowed years.
-  if ($element['year']['#value'] !== '' && is_numeric($component['extra']['year_start']) && is_numeric($component['extra']['year_end'])) {
+  if ($element['year']['#value'] !== '' && is_numeric($element['#year_start']) && is_numeric($element['#year_end'])) {
     // Allow years to be in reverse order.
-    $start = $component['extra']['year_start'] < $component['extra']['year_end'] ? $component['extra']['year_start'] : $component['extra']['year_end'];
-    $end   = $component['extra']['year_start'] > $component['extra']['year_end'] ? $component['extra']['year_start'] : $component['extra']['year_end'];
+    $start = $element['#year_start'] < $element['#year_end'] ? $element['#year_start'] : $element['#year_end'];
+    $end   = $element['#year_start'] > $element['#year_end'] ? $element['#year_start'] : $element['#year_end'];
     if ($element['year']['#value'] < $start || $element['year']['#value'] > $end) {
       form_error($element['year'], t('The entered date needs to be between the years @start and @end.', array('@start' => $start, '@end' => $end)));
       return;
Index: templates/webform-calendar.tpl.php
===================================================================
RCS file: templates/webform-calendar.tpl.php
diff -N templates/webform-calendar.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ templates/webform-calendar.tpl.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,9 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Theme the button for the date component date popup.
+ */
+?>
+<input type="image" src="<?php print base_path() . drupal_get_path('module', 'webform') . '/images/calendar.png'; ?>" class="<?php print implode(' ', $calendar_classes); ?>" title="<?php print t('Open popup calendar'); ?>" />
Index: js/webform.js
===================================================================
RCS file: js/webform.js
diff -N js/webform.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ js/webform.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,61 @@
+// $Id$
+
+/**
+ * JavaScript behaviors for the front-end display of webforms.
+ */
+
+(function ($) {
+
+Drupal.behaviors.webform = Drupal.behaviors.webform || {};
+
+Drupal.behaviors.webform.attach = function(context) {
+  // Calendar datepicker behavior.
+  Drupal.webform.datepicker(context);
+};
+
+Drupal.webform = Drupal.webform || {};
+
+Drupal.webform.datepicker = function(context) {
+  $('div.webform-datepicker').each(function() {
+    var $webformDatepicker = $(this);
+    var $calendar = $webformDatepicker.find('input.webform-calendar');
+    var startYear = $calendar[0].className.replace(/.*webform-calendar-start-(\d+).*/, '$1');
+    var endYear = $calendar[0].className.replace(/.*webform-calendar-end-(\d+).*/, '$1');
+
+    // Set up the jQuery datepicker element.
+    $calendar.datepicker({
+      dateFormat: 'yy-mm-dd',
+      yearRange: startYear + ':' + endYear,
+      onSelect: function(dateText, inst) {
+        var date = dateText.split('-');
+        $webformDatepicker.find('select.year, input.year').val(+date[0]);
+        $webformDatepicker.find('select.month').val(+date[1]);
+        $webformDatepicker.find('select.day').val(+date[2]);
+      },
+      beforeShow: function(input, inst) {
+        // Get the select list values.
+        var year = $webformDatepicker.find('select.year, input.year').val();
+        var month = $webformDatepicker.find('select.month').val();
+        var day = $webformDatepicker.find('select.day').val();
+
+        // If empty, default to the current year/month/day in the popup.
+        var today = new Date();
+        year = year ? year : today.getFullYear();
+        month = month ? month : today.getMonth() + 1;
+        day = day ? day : today.getDate();
+
+        // jQuery UI Datepicker will read the input field and base its date off
+        // of that, even though in our case the input field is a button.
+        $(input).val(year + '-' + month + '-' + day);
+      }
+    });
+
+    // Prevent the calendar button from submitting the form.
+    $calendar.click(function(event) {
+      $(this).focus();
+      event.preventDefault();
+    });
+  });
+}
+
+})(jQuery);
Index: css/webform.css
===================================================================
RCS file: css/webform.css
diff -N css/webform.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ css/webform.css	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,10 @@
+/* $Id$ */
+
+/**
+ * Front-end styling for the display of webforms.
+ */
+
+input.webform-calendar {
+  padding: 3px;
+  vertical-align: top;
+}
