Enable/Disable dates in jQuery Datepicker

//
//Block certain days in jQuery Datepicker
//
//

// Holiday List
var unavailableDates = ["9-3-2012", "14-3-2012", "15-3-2012"];

// Exeptions if some Weekends are Working days
var enableDay = ["3-3-2012", "10-3-2012", "17-3-2012"];

// Weekend Days Sunday = 0 ... Sat =6
var weekend = [0, 6];

function nationalDays(date) {
    // get date
    dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();


    // if Holiday then block it    
    if ($.inArray(dmy, unavailableDates) > -1) {
        return [false, "", "Unavailable"];

    }
    // if Exception then Enable it
    if ($.inArray(dmy, enableDay) > -1) {
        return [true, ""];

    }

    //if Weekend then block it
    if ($.inArray(date.getDay(), weekend) > -1) {
        return [false, "", "Unavailable"];
    }

    return [true, ""];
}

$(function() {
    $("#iDate").datepicker({
        dateFormat: 'dd MM yy',
        beforeShowDay: nationalDays
    });

});

Comments

Popular posts from this blog

Category Name with Products in Cart Page Magento

Safe name of a file by php

Sort Products by popularity count in Magento