I am trying to modify a JS file that we use at my company for our B2C sales site. Our guy that we had doing this left, and I wanted to see if I could get this squared away before having to hire somebody. I'm not sure if this is something that is standard, or if this required code is specific to a) GoDaddy.com (where we host our site) or b) the guy who developed it.
The bit of code I'm needing to modify deals with blocking out certain order days. Currently, our system is blocking out Sundays and Mondays. We need to include Saturdays, too.
Code:
$(function() {
$("#datepicker").datepicker({
buttonImage: 'images/calendar.png',
showOn: 'both',
buttonImageOnly: true,
buttonText: 'Select date',
beforeShow: function() {
window.setTimeout(hideWeekends, 10);
},
onChangeMonthYear: function() {
window.setTimeout(hideWeekends, 10);
}
});
//form validation
$('form[name=cart_quantity]').submit(function() {
date = $('#datepicker').val();
if (!date) {
alert('Please enter arrival date');
$('#datepicker').focus();
return false;
}
comments = $('textarea[name=comments]').val();
if (!comments) {
alert('Please enter your gift message');
$('textarea[name=comments]').focus();
return false;
}
});
});
function hideWeekends() {
$('.ui-datepicker-week-end:first-child').each(function() {
//disable Sundays
text = $(this).text();
$(this)
.removeAttr('onclick')
.empty()
.html(text)
.css('text-align', 'right');
//disable mondays
monday = $(this).next();
text = monday.text();
monday
.removeAttr('onclick')
.empty()
.html(text)
.css('text-align', 'right');
});
//disable invalid dates
month = $('.ui-datepicker-month').text();
months = new Array('January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December');
for (x in months) {
if (months[x] == month) {
month_num = x;
break;
}
}
year = $('.ui-datepicker-year').text();
$('.ui-datepicker td[onclick]').each(function() {
day = $(this).text();
date_str = month_num + '/' + day + '/' + year;
// BLOCK OUT DATES HERE
if (!isValidDate(date_str) || date_str == '0/1/2012') {
text = $(this).text();
$(this)
.removeAttr('onclick')
.empty()
.html(text)
.css('text-align', 'right');
}
});
}
function isValidDate(date_str) {
myArray = date_str.split('/');
myDate = new Date();
time_now = myDate.getTime() / 1000;
arrival_time = Date.UTC(myArray[2],myArray[0],myArray[1]) / 1000 + 8 * 3600; //correction for PDT
//if (arrival_time - time_now < 43200) { //arrival required in less than 12hrs
if (arrival_time - time_now < 48600) { //arrival required in less than 13hrs
return false;
}
else
return true;
}
The portion I'm referring to starts near the middle, below "function hideWeekends".
Bookmarks