Index: advpoll-form.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/advpoll-form.js,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 advpoll-form.js
--- advpoll-form.js	4 Sep 2007 15:36:47 -0000	1.1.2.6
+++ advpoll-form.js	8 Sep 2007 18:00:55 -0000
@@ -63,6 +63,64 @@ Drupal.advpoll.updateWriteins = function
   }
 }
 
+Drupal.advpoll.dateTimePickers = function() {
+  var start = $("#edit-settings-startdate").val();
+  var end = $("#edit-settings-enddate").val();
+  var timezone = Drupal.settings.advPoll.timezone;
+  //Date.format = 'yyyy-mm-dd'; // Set date format for datePicker.
+    
+  function setDateTime() {
+    var sD = $("#advpoll-startdate").val();
+    var sT = $("#advpoll-starttime").val();
+    var eD = $("#advpoll-enddate").val();
+    var eT = $("#advpoll-endtime").val();
+    var sDT = (sD ? sD : '') + (sT ? ' ' + sT : '');
+    var eDT = ($("#advpoll-use-end").is(":checked") ? '' : (eD ? eD : '') + (eT ? ' ' + eT : ''));
+    // Only add the timezone to the string if date or time is set.
+    sDT = sDT ? sDT + ' ' + timezone : '';
+    eDT = eDT ? eDT + ' ' + timezone : '';
+    
+    $("#edit-settings-startdate").val(sDT);
+    $("#edit-settings-enddate").val(eDT);
+  }
+  
+  var calendarSettings = {dateFormat: 'YMD-', firstDay: Drupal.settings.advPoll.firstDay, "onSelect": setDateTime, "speed": "", "changeFirstDay": false, "showOtherMonths": true};
+  
+  $("#edit-settings-active input[@type=radio]").click(function() {
+    if (this.value == 2) {
+      setDateTime();
+    }
+    else {
+      // Empty startdate and enddate if "Open" or "Closed" is checked.
+      $("#edit-settings-startdate, #edit-settings-enddate").val("");
+    }
+    // Show or hide date fields depending on which radiobutton is checked.
+    $("#advpoll-dates")[['hide', 'hide', 'show'][this.value]]();
+  });
+  
+  // Insert elements, attach pickers and bind events.
+  $('<input type="text" id="advpoll-startdate" />').insertBefore("#edit-settings-startdate").calendar(calendarSettings);
+  $('<input type="text" id="advpoll-starttime" />').insertBefore("#edit-settings-startdate").timePicker(null, setDateTime);
+  $('<input type="text" id="advpoll-endtime" />').insertBefore("#edit-settings-enddate").timePicker(null, setDateTime);
+  $('<input type="text" id="advpoll-enddate" />').insertBefore("#edit-settings-enddate").calendar(calendarSettings);
+  $("#advpoll-endfields").prepend('<span> to <\/span>');
+  var label = $('<label class="advpoll">Unlimited</label>').appendTo("#advpoll-dates");
+  $('<input type="checkbox" checked="checked" id="advpoll-use-end" class="form-checkbox" />').prependTo(label).click(function() {
+    $("#advpoll-endfields").css("display", ($(this)[0].checked ? "none" : "inline"));
+  });
+  // Set dates and time and also bind change event to support keyboard.
+  $("#advpoll-startdate").change(setDateTime).val(start.match(/\d\d\d\d-\d\d-\d\d/));
+  $("#advpoll-starttime").change(setDateTime).val(start.match(/\d\d:\d\d/));
+  $("#advpoll-enddate").change(setDateTime).val(end.match(/\d\d\d\d-\d\d-\d\d/));
+  $("#advpoll-endtime").change(setDateTime).val(end.match(/\d\d:\d\d/));
+  
+  // If endate is set uncheck "Unlimited"-checkbox and show endate fields.
+  if(end) {
+    $("#advpoll-use-end")[0].checked = false;
+    $("#advpoll-endfields").css("display", "inline");
+  }
+};
+
 Drupal.advpoll.nodeFormAutoAttach = function() {
   // This code is used on the node edit page and the content-type settings page.
 
@@ -107,6 +165,8 @@ Drupal.advpoll.nodeFormAutoAttach = func
     
     return false;
   });
+  // Date and time pickers
+  Drupal.advpoll.dateTimePickers();
 }
 
 // Global Killswitch
Index: advpoll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/advpoll.module,v
retrieving revision 1.21.2.62
diff -u -p -r1.21.2.62 advpoll.module
--- advpoll.module	4 Sep 2007 16:21:39 -0000	1.21.2.62
+++ advpoll.module	8 Sep 2007 18:05:46 -0000
@@ -130,8 +130,14 @@ function advpoll_form($node, $form_value
   // Only add javascript once, even if _form is called multiple times.
   static $add_js;
   if (!$add_js) {
+    // Get the current timezone which is passed to the JavaScript.
+    $timezone = format_date(0, 'custom', 'O');
     // Pass translatable strings
-    drupal_add_js(array('advPoll' => array('remove' => t('Remove'), 'addChoice' => t('Add choice'), 'noLimit' => t('No limit'))), 'setting');
+    drupal_add_js(array('advPoll' => array('remove' => t('Remove'), 'addChoice' => t('Add choice'), 'noLimit' => t('No limit'), 'timezone' => $timezone, 'firsDay' => variable_get('date_first_day', 0))), 'setting');
+    
+    drupal_add_js(drupal_get_path('module', 'advpoll') .'/datetimepicker/datetimepicker.js', 'module');
+    drupal_add_css(drupal_get_path('module', 'advpoll') .'/datetimepicker/datetimepicker.css', 'module');
+    
     drupal_add_js(drupal_get_path('module', 'advpoll') .'/advpoll-form.js', 'module');
     drupal_add_css(drupal_get_path('module', 'advpoll') .'/advpoll.css', 'module');
     $add_js = true;
@@ -257,14 +263,7 @@ function advpoll_form($node, $form_value
       '#description' => t('Voting algorithm to use to calculate the winner.'),
     );
   }
-  
-  $form['settings']['close'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Close poll'),
-    '#description' => t('When a poll is closed users may no longer vote on it.'),
-    '#default_value' => isset($node->active) ? !$node->active : 0,
-  );
-
+ 
   $default_startdate = '';
   $default_enddate = '';
   $time = format_date(time(), 'custom', 'Y-m-d H:i:s O');
@@ -273,10 +272,25 @@ function advpoll_form($node, $form_value
     $default_startdate = $time;
     $default_enddate = format_date(time() + variable_get('advpoll_runtime_'. $type->type, ''), 'custom', 'Y-m-d H:i:s O');
   }
-  
+ $default_active = isset($node->active) ? $node->active : 1;
+ // Set "Define duration" as default if any date is defined.
+ if ($default_startdate || $default_enddate || $node->startdate || $node->enddate) {
+   $default_active = 2;
+ }
+ 
+ $form['settings']['active'] = array(
+    '#prefix' => '<div id="edit-settings-active">', // Used by date and time picker.
+    '#type' => 'radios',
+    '#title' => t('Status'),
+    '#default_value' => $default_active,
+    '#options' => array(1 => t('Open'), 0 => t('Closed'), 2 => t('Define duration')),
+    '#description' => t('When a poll is closed, visitors can no longer vote for it.'),
+    '#suffix' => '</div>',
+  );
   $form['settings']['startdate'] = array(
+    '#prefix' => '<div id="advpoll-dates">', // Used by date and time picker.
     '#type' => 'textfield',
-    '#title' => t('Starting date'),
+    '#title' => t('Open at'),
     '#description' => t('The date that the poll opens. Format: %time. Leave blank if you want the poll to open now.', array('%time' => $time)),
     '#size' => 25,
     '#maxlength' => 25,
@@ -284,12 +298,14 @@ function advpoll_form($node, $form_value
   );
   
   $form['settings']['enddate'] = array(
+    '#prefix' => '<div id="advpoll-endfields">', // Used by date and time picker.
     '#type' => 'textfield',
-    '#title' => t('Ending date'),
+    '#title' => t('Close at'),
     '#description' => t('The date that the poll closes. Format: %time. Leave blank if you do not want the poll to close automatically.', array('%time' => $time)),
     '#size' => 25,
     '#maxlength' => 25,
     '#default_value' => $node->enddate ? format_date($node->enddate, 'custom', 'Y-m-d H:i:s O') : $default_enddate,
+    '#suffix' => '</div></div>',
   );
   
   // Settings available for users with 'administer polls' permission.
@@ -929,7 +945,7 @@ function advpoll_cancel_form($nid) {
  */
 function advpoll_update($node) {
 
-  db_query("UPDATE {advpoll} SET active = %d, maxchoices = %d, algorithm = '%s', uselist = %d, showvotes = %d, startdate = '%s', enddate = '%s', writeins = %d, show_writeins = %d WHERE nid = %d", !$node->settings['close'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $node->settings['startdate'] ? strtotime($node->settings['startdate']) : 0, $node->settings['enddate'] ? strtotime($node->settings['enddate']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->nid);
+  db_query("UPDATE {advpoll} SET active = %d, maxchoices = %d, algorithm = '%s', uselist = %d, showvotes = %d, startdate = '%s', enddate = '%s', writeins = %d, show_writeins = %d WHERE nid = %d", $node->settings['active'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['uselist'], $node->settings['showvotes'], $node->settings['startdate'] ? strtotime($node->settings['startdate']) : 0, $node->settings['enddate'] ? strtotime($node->settings['enddate']) : 0, $node->settings['writeins'], $node->settings['show_writeins'], $node->nid);
 
   _advpoll_insert_choices($node->nid);
   votingapi_recalculate_results('advpoll', $node->nid);
@@ -1001,7 +1017,7 @@ function _advpoll_get_mode($node_type) {
  */
 function advpoll_insert($node) {
   $mode = _advpoll_get_mode($node->type);
-  db_query("INSERT INTO {advpoll} (nid, mode, uselist, active, maxchoices, algorithm, showvotes, startdate, enddate, writeins, show_writeins) VALUES (%d, '%s', %d, %d, %d, '%s', %d, '%s', '%s', %d, %d)", $node->nid, $mode, $node->settings['uselist'], !$node->settings['close'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['showvotes'], $node->settings['startdate'] ? strtotime($node->settings['startdate']) : 0, $node->settings['enddate'] ? strtotime($node->settings['enddate']) : 0, $node->settings['writeins'], $node->settings['show_writeins']);
+  db_query("INSERT INTO {advpoll} (nid, mode, uselist, active, maxchoices, algorithm, showvotes, startdate, enddate, writeins, show_writeins) VALUES (%d, '%s', %d, %d, %d, '%s', %d, '%s', '%s', %d, %d)", $node->nid, $mode, $node->settings['uselist'], $node->settings['active'], $node->settings['maxchoices'], $node->settings['algorithm'], $node->settings['showvotes'], $node->settings['startdate'] ? strtotime($node->settings['startdate']) : 0, $node->settings['enddate'] ? strtotime($node->settings['enddate']) : 0, $node->settings['writeins'], $node->settings['show_writeins']);
 
   // Insert the choices
   _advpoll_insert_choices($node->nid);
Index: datetimepicker/datetimepicker.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/datetimepicker/Attic/datetimepicker.css,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 datetimepicker.css
--- datetimepicker/datetimepicker.css	4 Sep 2007 07:24:33 -0000	1.1.2.1
+++ datetimepicker/datetimepicker.css	8 Sep 2007 18:01:11 -0000
@@ -190,3 +190,52 @@ div.time-picker li.selected {
   background: #027ac6;
   color: #fff;
 }
+
+/*-------- AdvPoll specific styles -----------*/
+#calendar_div td, #calendar_div th {
+  padding:0;
+}
+#calendar_div table {
+  margin:0;
+}
+
+.calendar_control {
+  display:none;
+}
+
+div.time-picker {
+  margin-top: 1.5em;
+}
+#advpoll-starttime, #advpoll-endtime {
+  width:4em;
+}
+#advpoll-startdate, #advpoll-enddate {
+  width:7em;
+}
+#advpoll-startdate {
+  margin-right:0.2em;
+}
+#advpoll-enddate {
+  margin-left:0.2em;
+}
+html.js #edit-settings-startdate, html.js #edit-settings-enddate, html.js #advpoll-dates .description, html.js #advpoll-endfields {
+  display:none;
+}
+html.js #advpoll-dates .form-item, html.js #advpoll-dates label{    
+  display:inline;
+}
+html.js #advpoll-dates .form-item {    
+  display:relative;
+}
+html.js #advpoll-dates label{    
+  position:absolute;
+  margin-top:-1.6em;
+}
+html.js #advpoll-dates {
+  margin:2.5em 0 1.5em 0;
+}
+html.js #advpoll-dates label.advpoll {
+  margin-top:0;
+  position:relative;
+}
+
