$(function() {
$('#dropOffDate').datepicker({
minDate: 0, //today
maxDate: 730, //two years from today
beforeShowDay: enableDaysOfWeek,
onSelect: function() {
updateTimes();
}
});
$('#dropOffDate').change(function() {
updateTimes();
});
if($('#pickUpDate').length) {
$('#pickUpDate').change(function() {
updateTimes();
});
}
if($('#extraDays').length) {
$('#extraDays').change(function() {
updateTimes();
});
}
if($('#dropOffTimeWarning').length) {
$('#dropOffTimeWarning').tooltip({
position: { my: "right+78 bottom-19", at: "right bottom" },
open: function( event, ui ) { //auto hide after timeout
setTimeout(function(){
$('#dropOffTimeWarning').tooltip('close');
}, 3000);
}
});
}
if($('#pickUpDayWarning').length) {
$('#pickUpDayWarning').tooltip({
position: { my: "right-2 top+19", at: "right top" },
open: function( event, ui ) { //auto hide after timeout
setTimeout(function(){
$('#pickUpDayWarning').tooltip('close');
}, 3000);
}
});
}
if($('#pickUpTimeWarning').length) {
$('#pickUpTimeWarning').tooltip({
position: { my: "right+71 top+19", at: "right top" },
open: function( event, ui ) { //auto hide after timeout
setTimeout(function(){
$('#pickUpTimeWarning').tooltip('close');
}, 3000);
}
});
}
var mil_times = new Array;
var ampm_times = new Array;
var dropoff = new Array;
var pickup = new Array;
mil_times[0] = '06:00:00';
ampm_times[0] = '6:00am';
mil_times[1] = '06:30:00';
ampm_times[1] = '6:30am';
mil_times[2] = '07:00:00';
ampm_times[2] = '7:00am';
mil_times[3] = '07:30:00';
ampm_times[3] = '7:30am';
mil_times[4] = '08:00:00';
ampm_times[4] = '8:00am';
mil_times[5] = '08:30:00';
ampm_times[5] = '8:30am';
mil_times[6] = '09:00:00';
ampm_times[6] = '9:00am';
mil_times[7] = '09:30:00';
ampm_times[7] = '9:30am';
mil_times[8] = '10:00:00';
ampm_times[8] = '10:00am';
mil_times[9] = '10:30:00';
ampm_times[9] = '10:30am';
mil_times[10] = '11:00:00';
ampm_times[10] = '11:00am';
mil_times[11] = '11:30:00';
ampm_times[11] = '11:30am';
mil_times[12] = '12:00:00';
ampm_times[12] = '12:00pm';
mil_times[13] = '12:30:00';
ampm_times[13] = '12:30pm';
mil_times[14] = '13:00:00';
ampm_times[14] = '1:00pm';
mil_times[15] = '13:30:00';
ampm_times[15] = '1:30pm';
mil_times[16] = '14:00:00';
ampm_times[16] = '2:00pm';
mil_times[17] = '14:30:00';
ampm_times[17] = '2:30pm';
mil_times[18] = '15:00:00';
ampm_times[18] = '3:00pm';
mil_times[19] = '15:30:00';
ampm_times[19] = '3:30pm';
mil_times[20] = '16:00:00';
ampm_times[20] = '4:00pm';
mil_times[21] = '16:30:00';
ampm_times[21] = '4:30pm';
mil_times[22] = '17:00:00';
ampm_times[22] = '5:00pm';
mil_times[23] = '17:30:00';
ampm_times[23] = '5:30pm';
mil_times[24] = '18:00:00';
ampm_times[24] = '6:00pm';
mil_times[25] = '18:30:00';
ampm_times[25] = '6:30pm';
mil_times[26] = '19:00:00';
ampm_times[26] = '7:00pm';
mil_times[27] = '19:30:00';
ampm_times[27] = '7:30pm';
mil_times[28] = '20:00:00';
ampm_times[28] = '8:00pm';
mil_times[29] = '20:30:00';
ampm_times[29] = '8:30pm';
mil_times[30] = '21:00:00';
ampm_times[30] = '9:00pm';
mil_times[31] = '21:30:00';
ampm_times[31] = '9:30pm';
mil_times[32] = '22:00:00';
ampm_times[32] = '10:00pm';
mil_times[33] = '22:30:00';
ampm_times[33] = '10:30pm';
mil_times[34] = '23:00:00';
ampm_times[34] = '11:00pm';
mil_times[35] = '23:30:00';
ampm_times[35] = '11:30pm';
dropoff[0] = new Array;
pickup[0] = new Array;
dropoff[0]['start'] = '08:00:00';
dropoff[0]['end'] = '12:00:00';
pickup[0]['open'] = 9;
pickup[0]['start'] = '16:00:00';
pickup[0]['end'] = '20:00:00';
dropoff[1] = new Array;
pickup[1] = new Array;
dropoff[1]['start'] = '08:00:00';
dropoff[1]['end'] = '16:00:00';
pickup[1]['open'] = 21;
pickup[1]['start'] = '10:00:00';
pickup[1]['end'] = '20:00:00';
dropoff[2] = new Array;
pickup[2] = new Array;
dropoff[2]['start'] = '08:00:00';
dropoff[2]['end'] = '16:00:00';
pickup[2]['open'] = 21;
pickup[2]['start'] = '10:00:00';
pickup[2]['end'] = '20:00:00';
dropoff[3] = new Array;
pickup[3] = new Array;
dropoff[3]['start'] = '08:00:00';
dropoff[3]['end'] = '16:00:00';
pickup[3]['open'] = 21;
pickup[3]['start'] = '10:00:00';
pickup[3]['end'] = '20:00:00';
dropoff[4] = new Array;
pickup[4] = new Array;
dropoff[4]['start'] = '08:00:00';
dropoff[4]['end'] = '16:00:00';
pickup[4]['open'] = 21;
pickup[4]['start'] = '10:00:00';
pickup[4]['end'] = '20:00:00';
dropoff[5] = new Array;
pickup[5] = new Array;
dropoff[5]['start'] = '08:00:00';
dropoff[5]['end'] = '12:00:00';
pickup[5]['open'] = 9;
pickup[5]['start'] = '16:00:00';
pickup[5]['end'] = '20:00:00';
dropoff[6] = new Array;
pickup[6] = new Array;
dropoff[6]['start'] = '08:00:00';
dropoff[6]['end'] = '12:00:00';
pickup[6]['open'] = 9;
pickup[6]['start'] = '16:00:00';
pickup[6]['end'] = '20:00:00';
//enables/disables specific days of week (sun-fri) based on config vars
function enableDaysOfWeek(date) {
var day = date.getDay(); //date was passed as a date object
if(day == 0 || day == 1 || day == 2 || day == 3 || day == 4 || day == 5 || day == 6)
return [true, '']; //open for biz
else return [false, '', 'Sorry, we\'re closed']; //biz closed
}
//updates the rental time and return times select boxes based on rental date and return date
function updateTimes() {
if($('#dropOffDate').val() == 'mm/dd/yyyy' || $('#dropOffDate').val() == '') //cant calculate if date not set
return false;
var sd = $('#dropOffDate').val();
var m = parseInt(sd.substr(0,2));
var d = parseInt(sd.substr(3,2));
var y = parseInt(sd.substr(6,4));
var start_date = new Date(y, m-1, d, 0, 0, 0, 0); //drop-off date
var start_day = start_date.getDay(); //drop-off day
if($('#extraDays').length) {
var days_to_add = parseInt($('#extraDays').val());
var end_date = new Date(y, m-1, d, 0, 0, 0, 0);
end_date.setDate(end_date.getDate() + days_to_add); //pick-up date
var end_day = end_date.getDay(); //pick-up day
}
else if($('#pickUpDate').length) {
if($('#pickUpDate').val() == 'mm/dd/yyyy' || $('#pickUpDate').val() == '') //cant calculate if date not set
return false;
sd = $('#pickUpDate').val();
m = parseInt(sd.substr(0,2));
d = parseInt(sd.substr(3,2));
y = parseInt(sd.substr(6,4));
var end_date = new Date(y, m-1, d, 0, 0, 0, 0); //pick-up date
var end_day = end_date.getDay(); //pick-up day
}
//check validity of select dropOffTime options and current selection and update if necessary
if(dropoff[start_day]['start'] == $("#dropOffTime option:eq(1)").val() && dropoff[start_day]['end'] == $("#dropOffTime option:last").val()) {
//alert("dropoff start and end time is same");
//do nothing
} else {
//alert("dropoff start time or end time is different\nstart 1:"+dropoff[start_day]['start']+"\nstart 2:"+$("#dropOffTime option:eq(1)").val()+"\nend 1:"+dropoff[start_day]['end']+"\nend 2:"+$("#dropOffTime option:last").val());
//save current selection, clear out existing range and input new range, reselect original if exists and if not notify
var curr_dropoff_selection = $("#dropOffTime").val();
$('#dropOffTime').empty(); //empty current list
$('#dropOffTime').append(''+"\n");
//repopulate with new values
var opts = '';
for(var i=0; i= mil_times[i])
opts += ''+"\n";
else if(1 == 0)
opts += ''+"\n";
}
$('#dropOffTime').append(opts);
var curr_exists = false;
$('#dropOffTime option').each(function(){
if (this.value == curr_dropoff_selection) {
curr_exists = true;
return false;
}
});
if(curr_exists)
$('#dropOffTime').val(curr_dropoff_selection);
else
if($('#dropOffTimeWarning').length) $('#dropOffTimeWarning').tooltip('open');
}
//if applicable, check validity of select extraDays options and current selection and update if necessary
if($('#extraDays').length) {
var curr_extra_days_selection = $("#extraDays").val();
$('#extraDays').empty(); //empty current list
$('#extraDays').append(''+"\n");
var day = 0;
var opts = '';
for(var i=1; i<=10; i++) {
//start_day is what we'll be calculating from
day = (start_day + i) % 7;
if(pickup[day]['open'] > 0) //option available
opts += ''+"\n";
else if(1 == 0)
opts += ''+"\n";
}
$('#extraDays').append(opts);
var curr_exists = false;
$('#extraDays option').each(function(){
if (this.value == curr_extra_days_selection) {
curr_exists = true;
return false;
}
});
if(curr_exists)
$('#extraDays').val(curr_extra_days_selection);
else {
if($('#pickUpDayWarning').length) $('#pickUpDayWarning').tooltip('open');
//because the extraDays value directly effects the pickUpTime range of values we have to recalculate the new valid
//pickUpTime range based on our changes to extraDays, to do this we will recall this function and exit out the
//current iteration of it to prevent incorrect pickUpTime range from displaying
updateTimes();
return;
}
}
//check validity of select pickUpTime options and current selection and update if necessary
if(pickup[end_day]['start'] == $("#pickUpTime option:eq(1)").val() && pickup[end_day]['end'] == $("#pickUpTime option:last").val()) {
//alert("pickup start and end time is same");
//do nothing
} else {
//alert("pickup start time or end time is different\nstart 1:"+pickup[end_day]['start']+"\nstart 2:"+$("#pickUpTime option:eq(1)").val()+"\nend 1:"+pickup[end_day]['end']+"\nend 2:"+$("#pickUpTime option:last").val());
//save current selection, clear out existing range and input new range, reselect original if exists and if not notify
var curr_pickup_selection = $("#pickUpTime").val();
$('#pickUpTime').empty(); //empty current list
$('#pickUpTime').append(''+"\n");
//repopulate with new values
var opts = '';
for(var i=0; i= mil_times[i])
opts += ''+"\n";
else if(1 == 0)
opts += ''+"\n";
}
$('#pickUpTime').append(opts);
var curr_exists = false;
$('#pickUpTime option').each(function(){
if (this.value == curr_pickup_selection) {
curr_exists = true;
return false;
}
});
if(curr_exists)
$('#pickUpTime').val(curr_pickup_selection);
else
if($('#pickUpTimeWarning').length) $('#pickUpTimeWarning').tooltip('open');
}
}
//onload refresh time selects with correct data if date exists to prevent too wide a range from displaying
updateTimes();
});