// Copyright (c) 2004-2006 koikikukan All Rights Reserved.
// http://www.koikikukan.com/
// License is granted if and only if this entire
// copyright notice is included. By Yujiro ARAKI.

// Ver1.00en 2006.04.11 for England and Wales.
// Ver1.01en 2006.04.15 fix bug.
// Ver1.02en 2006.04.16 fix bug.
// Ver1.03en 2006.08.03 fix bug.

var currentYear;
var currentMonth;
var currentDay;

function setCurrentDate() {
    data = new Date();
    currentYear = data.getYear();
    currentYear = (currentYear < 2000) ? currentYear + 1900 : currentYear;
    currentMonth = data.getMonth() + 1;
    currentDay = data.getDate();
}

function isToday(year, month, day) {
    if (year == currentYear && parseInt(month,10) == currentMonth && day == currentDay) {
        return true;
    }
    return false;
}

function isSaturday(year, month, day) {
    var week = new Date(year, month - 1, day).getDay();
    if (week == 6) {
        return true;
    }
    return false;
}

function isHoliday(year, month, day) {
    var week = new Date(year, month - 1, day).getDay();
    if (week == 0) {
        return true;
    }
    switch(parseInt(month,10)) {
    case 1:
        if (day == 1) {
            return true;
        }
        if (day == 2 && isSunday(year, month, 1)) {
            return true;
        }
        break;
    case 3:
        if (year == 2008 && (day == 21 || day == 24)) {
            return true;
        }
        break;
    case 4:
        if (year == 2006 && (day == 14 || day == 17)) {
            return true;
        }
        if (year == 2007 && (day == 6 || day == 9)) {
            return true;
        }
        break;
    case 5:
        if (day == (getFirstMonday(year, month))) {
            return true;
        }
        if (day == (getFirstMonday(year, month) + 21) &&
            ((getFirstMonday(year, month) + 28) > 31)) {
            return true;
        }
        if (day == (getFirstMonday(year, month) + 28)) {
            return true;
        }
        break;
    case 8:
        if (day == (getFirstMonday(year, month) + 21) &&
            ((getFirstMonday(year, month) + 28) > 31)) {
            return true;
        }
        if (day == (getFirstMonday(year, month) + 28)) {
            return true;
        }
        break;
    case 12:
        if (day == 25) {
            return true;
        }
        if (day == 26) {
            return true;
        }
        if (day == 27 && (isSaturday(year, month, 25) || isSunday(year, month, 25))) {
            return true;
        }
        if (day == 28 && (isSaturday(year, month, 25) || isSaturday(year, month, 26))) {
            return true;
        }
        break;
    }
    return false;
}

function isSunday(year, month, day) {
    var week = new Date(year, month - 1, day).getDay();
    if (week == 0) {
        return true;
    }
    return false;
}

function getFirstMonday(year, month) {
    var monday;
    for(monday = 1; monday < 8; monday++) {
        if(new Date(year, month - 1, monday).getDay() == 1) {
            break;
        }
    }
    return monday;
}
