// $Id$
/**
* Attaches the calendar behavior to all required fields
*/
Drupal.behaviors.date_popup_time_dropdown = function (context) {
for (var id in Drupal.settings.datePopup) {
var datePopup = Drupal.settings.datePopup[id];
if (datePopup.func == 'timeEntry') {
$('#' + id).parent().attr('style', 'display:none');
// Compute default values.
var def_hours = datePopup.settings.show24Hours ? '00' : '12';
var def_mins = '00';
var def_secs = '00';
var def_ampm = 'AM';
var current = $('#' + id).val();
if (current.length) {
def_hours = current.substr(0, 2);
def_mins = current.substr(3, 2);
if (datePopup.settings.showSeconds) {
def_secs = current.substr(6, 2);
}
if (!datePopup.settings.show24Hours) {
def_ampm = current.substr(current.length - 2, 2);
}
}
// Generate the dropdowns.
// Hours
var hours = '';
// Minutes
var mins = '';
// Seconds
var secs = '';
if (datePopup.settings.showSeconds) {
secs = '';
}
// AM / PM
var ampm = '';
if (!datePopup.settings.show24Hours) {
ampm = '';
}
var dropdowns = 'at ' + hours + mins + secs + ampm;
$('#' + id).parent().after(dropdowns);
// Update real time field on dropdown change.
$('#' + id + '-hours, #' + id + '-mins, #' + id + '-secs, #' + id + '-ampm').bind('change', id, function(e) {
var id = e.data;
var time = $('#' + id + '-hours option:selected').val();
time += ':' + $('#' + id + '-mins option:selected').val();
if ($('#' + id + '-secs').length != 0) {
time += ':' + $('#' + id + '-secs option:selected').val();
}
if ($('#' + id + '-ampm').length != 0) {
time += $('#' + id + '-ampm option:selected').val();
}
$('#' + id).val(time);
});
}
}
};