(function(){
    //この処理はテキスト解析中に処理されるので、処理中に対象のオブジェクトをコンテナ配置してしまう。
    var container = $("script:last").parents("div:first");
//M0010659 ADD 20110808 HIROYUKI NORO START
    var storeCalenddarData;
//M0010659 ADD 20110808 HIROYUKI NORO END

    $(function(){
        //この処理はテキスト解析後に処理されるので、データ取得処理を行う
        ajaxRequest(getHost() + "/page/calendarview/calendarheaderinfo", {
            "calendarDivId": $(container).find(".calendarDivId").val(),
            "strCalendarId": $(container).find(".strCalendarId").val()
        }, app_headerCallback);
    });

    function DateLinkMapping(date, link){
        this.Date = date;
        this.Link = link;
    }

    var Calendar = {
        settings: {
            firstDayOfWeek: 1,
            baseClass: "calendar",
            curDayClass: "curDay",
            prevMonthCellClass: "prevMonth",
            nextMonthCellClass: "nextMonth",
            curMonthNormalCellClass: "",
            prevNextMonthDaysVisible: true
        },
        containerId: "",
        weekDayNames: [],
        dateLinkMappings: [],
        month:"",
        year:"",
        day:"",
        _setDayFn: function(time){
            this.day=time.value;
        },
        Init: function(weekDayNames, dateLinkMappings, settings) {
            if (!weekDayNames || weekDayNames.length && weekDayNames.length != 7) {
                this.weekDayNames[1] = "月";
                this.weekDayNames[2] = "火";
                this.weekDayNames[3] = "水";
                this.weekDayNames[4] = "木";
                this.weekDayNames[5] = "金";
                this.weekDayNames[6] = "土";
                this.weekDayNames[7] = "日";
            } else {
                this.weekDayNames = weekDayNames;
            }

            if (dateLinkMappings) {
                this.dateLinkMappings = dateLinkMappings;
            }
        },
        RenderCalendar: function(calendarDivId, divId, month, year) {
            var strTime  = "<li class='prev'><a class='prevMonth' title='前の月' value=" + month + "-" + year + " >前の月</a></li>";
                strTime += "<li class='prevnbspID' style=\"display: none;\" ></li>";
                strTime += "<li class='_date' value=" + month + "-" + year + ">" + year + "年" + month + "月</li>";
                strTime += "<li class='next'><a class='nextMonth' title='次の月' value=" + month + "-" + year + ">次の月</a></li>";
                strTime += "<li class='nextnbspID' style=\"display: none;\" ></li>";

            var strDisplay = "";

            if ($(container).find(".hidhead1").val() == "") {
            	strDisplay = "display:none;"
            } else {
            	strDisplay = "";
            }

            var strtab  = "      <li style=\"cursor: pointer;" + strDisplay + "\" class=\"co0_head_1 co0_head_1_a\" ><a>" + $(container).find(".hidhead1").val() + "</a></li>";

            if ($(container).find(".hidhead2").val() == "") {
            	strDisplay = "display:none;"
            } else {
            	strDisplay = "";
            }

            strtab += "      <li style=\"cursor: pointer;" + strDisplay + "\" class=\"co0_head_2 co0_head_2_a\" ><a>" + $(container).find(".hidhead2").val() + "</a></li>";

            if ($(container).find(".hidhead3").val() == "") {
            	strDisplay = "display:none;"
            } else {
            	strDisplay = "";
            }

            strtab += "      <li style=\"cursor: pointer;" + strDisplay + "\" class=\"co0_head_3 co0_head_3_a\" ><a>" + $(container).find(".hidhead3").val() + "</a></li>";

            if ($(container).find(".hidhead4").val() == "") {
            	strDisplay = "display:none;"
            } else {
            	strDisplay = "";
            }

            strtab += "      <li style=\"cursor: pointer;" + strDisplay + "\" class=\"co0_head_4 co0_head_4_a\" ><a>" + $(container).find(".hidhead4").val() + "</a></li>";

            $(container).find(".timeContents").html(strTime);  
            $(container).find(".tabContents").html(strtab);  

            var colHeight = 0;
            var col1H = $(container).find(".co0_head_1").height();
            var col2H = $(container).find(".co0_head_2").height();
            var col3H = $(container).find(".co0_head_3").height();
            var col4H = $(container).find(".co0_head_4").height();

            if (col1H > col2H && col1H > col3H && col1H > col4H) {
            	colHeight = col1H;
            } else if (col2H > col3H && col2H > col4H) {
            	colHeight = col2H;
            } else if (col3H > col4H) {
            	colHeight = col3H;
            } else {
            	colHeight = col4H;
            }

            $(container).find(".co0_head_1").height(colHeight);
            $(container).find(".co0_head_2").height(colHeight);
            $(container).find(".co0_head_3").height(colHeight);
            $(container).find(".co0_head_4").height(colHeight);

            $(container).find(".co0_head_1_a").click(function() {
                changeTab(1, "co0");
            });

            $(container).find(".co0_head_2_a").click(function() {
                changeTab(2, "co0");
            });

            $(container).find(".co0_head_3_a").click(function() {
                changeTab(3, "co0");
            });
            $(container).find(".co0_head_4_a").click(function() {
                changeTab(4, "co0");
            });

            var strWeek="<table><tr>";

            for (var i = 0; i < 7; i++) {
                var day = (i + this.settings.firstDayOfWeek) == 7 ? 7 : (i + this.settings.firstDayOfWeek) % 7;

                if(day==7){//set sunday class=holiday
                    strWeek += "<th class='holiday'><span>", this.weekDayNames[day], "</span></th>"; 
                } else {
                    strWeek += "<th><span>", this.weekDayNames[day], "</span></th>";
                }
            }

            strWeek += "</tr></table>";

            for (i = 0; i < 4; i++) {
                divId = "0"+i; 
                this.month=month;
                this.year=year;
                this.containerId = divId;
                var ht = [];
                ht.push("<table>");
                ht.push(this._RenderTitle(calendarDivId, divId, month, year));
                ht.push(this._RenderBody(calendarDivId, divId, month, year));
                ht.push("</table>");
                $(container).find("." + divId).html(ht.join("")); 
                 
//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659  this._InitEvent(calendarDivId, this.containerId, month, year);
                if(i == 0){
                    this._InitEvent(calendarDivId, this.containerId, month, year, 0);
                }
                else{
                    this._InitEvent(calendarDivId, this.containerId, month, year, 1);
                }
//M0010659 MOD 20110808 HIROYUKI NORO END
            }
        },
        _RenderTitle: function(calendarDivId, divId,month, year) {
            var ht = [];
            ht.push("<tr>");
            
            for (var i = 0; i < 7; i++) {
                var day = (i + this.settings.firstDayOfWeek) == 7 ? 7 : (i + this.settings.firstDayOfWeek) % 7;

                if (day == 7) {//set sunday class=holiday
                    ht.push("<th class='holiday'><span>", this.weekDayNames[day], "</span></th>"); 
                } else {
                    ht.push("<th><span>", this.weekDayNames[day], "</span></th>");
                }
            }

            ht.push("</tr>");
            return ht.join("");
        },
        _RenderBody: function(calendarDivId, divId,month, year) {
            var date = new Date(year, month - 1, 1);
            var day = date.getDay();
            var strMonth;
            var dayOfMonth = 1;
            var daysOfPrevMonth = (7 - this.settings.firstDayOfWeek + day) % 7;
            var totalDays = this._GetTotalDays(month, year);
            var totalDaysOfPrevMonth = this._GetToalDaysOfPrevMonth(month, year);
            var ht = [];
            var curDate;

            for (var i = 0; ; i++) {
                curDate = null;

                if (i % 7 == 0) {//new rows
                    ht.push("<tr>");
                }

                ht.push("<td");

                if (i >= daysOfPrevMonth && dayOfMonth <= totalDays) {//cur Month
                    strMonth = month ;//1
                    curDate = new Date(year, month - 1, dayOfMonth);
                    var toDayNumber =this._BuildCell(curDate);

                    if (Date.parse(new Date().toDateString()) - curDate == 0) {                        
                        if(i % 7 == 6){//today is sunday
                            ht.push(" class='today holiday ");//curDayClass
                        } else {
                            if(HolidayHelper.isHoliday(year,month,toDayNumber)){//today is holiday
                                ht.push(" class='today holiday ");
                            } else if (HolidayHelper.preDayIsHoliday(year, month, toDayNumber) && (i % 7)-1 == 6) {
                                ht.push(" class='today holiday ");//curDayClass
                            } else {
                                if (month==5 && toDayNumber==6 && ((i-2)==-1 || (i-3)==-1)) {
                                    ht.push(" class='today holiday ");//curDayClass
                                } else {
                                    ht.push(" class='today ");//curDayClass
                                }
                            }
                        }
                    } else { 
                        if (i % 7 == 6) {//today is sunday
                            ht.push(" class='holiday ");//curDayClass
                        } else {
                            if (HolidayHelper.isHoliday(year,month,toDayNumber)) {//today is holiday
                                ht.push(" class='holiday ");
                            } else if (HolidayHelper.preDayIsHoliday(year, month, toDayNumber) && (i % 7)-1 == 6) {
                                ht.push(" class='holiday ");//curDayClass
                            } else {
                                if (month==5 && toDayNumber==6 && ((i-2)==-1 || (i-3)==-1)) {
                                    ht.push(" class='holiday ");//curDayClass
                                } else {
                                    ht.push(" class=' ");//curDayClass
                                }
                            }
                        }
                    }

                    dayOfMonth++;
                    ht.push("day_"+divId+strMonth+"_"+this._BuildCell(curDate)+"' value="+this._BuildCell(curDate)+" >");
                    ht.push("<span>" + this._BuildCell(curDate) + "</span>");
                    ht.push("</td>");
                } else if (i < daysOfPrevMonth) {//PrevMonth
                    if (this.settings.prevNextMonthDaysVisible) {
                        var prevMonth = month;
                        var prevYear = year;

                        if (month == 1) {
                            prevMonth = 12;
                            prevYear = prevYear - 1;
                        } else {
                            prevMonth = prevMonth - 1;
                        }

                        strMonth = prevMonth ;//1
                        curDate = new Date(prevYear, prevMonth - 1, totalDaysOfPrevMonth - (daysOfPrevMonth - i - 1));
//                        ht.push(" class='", this.settings.prevMonthCellClass, "'");
                        ht.push("><span>");
                        ht.push("</span></td>");
                    }
                } else {//下月
                    if (this.settings.prevNextMonthDaysVisible) {
                        var nextMonth = month;
                        var nextYear = year;

                        if (month == 12) {
                            nextMonth = 1;
                            nextYear = prevYear + 1;
                        } else {
                            nextMonth = nextMonth + 1;
                        }

                        strMonth = nextMonth ;//1
                        curDate = new Date(nextYear, nextMonth-1, i - dayOfMonth - daysOfPrevMonth + 2);
//                        ht.push(" class='", this.settings.nextMonthCellClass, "'");
                        ht.push("><span>");
                        ht.push("</span></td>");
                    }
                }

                if (i % 7 == 6) {//end of one rows
                    ht.push("</tr>");
                }

                if (i % 7 == 6 && dayOfMonth - 1 >= totalDays) {
                    break;
                }
            }

            return ht.join("");
        },
        _BuildCell: function(curDate) {
            var ht = [];

            if (curDate) {
                for (var j = 0; j < this.dateLinkMappings.length; j++) {
                    if (Date.parse(this.dateLinkMappings[j].Date) - curDate == 0) {
                        ht.push("<a href='", this.dateLinkMappings[j].Link, "'>", curDate.getDate(), "</a>");
                        break;
                    }
                }

                if (j == this.dateLinkMappings.length) {
                    ht.push(curDate.getDate());
                }
            } else {
                ht.push("&nbsp;");
            }

            return ht.join("");
        },
//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659 _InitEvent: function(calendarDivId, divId, month, year) {
        _InitEvent: function(calendarDivId, divId, month, year, storeFlg) {
//M0010659 MOD 20110808 HIROYUKI NORO END
            var date = new Date() ;
            boolMonth = date.getMonth()+1 ;
            boolYear = date.getFullYear() ;
            var bool_prevMonth ;
            var bool_nextMonth ;
            var bool_prevYear = boolYear ;
            var bool_nextYear = boolYear ;

            if (boolMonth == 1) {
                bool_prevMonth = 12;
                bool_prevYear =  bool_prevYear-1;
            } else {
                bool_prevMonth = boolMonth - 1;
            }

            if(boolMonth==12){
                bool_nextMonth = 1;
                bool_nextYear =boolYear+1;
            } else {
                bool_nextMonth = boolMonth+1 ;
            }

            var boolPrVal = bool_prevYear +"-" +bool_prevMonth;
            var boolneVal = bool_nextYear+ "-" +bool_nextMonth;
            var curDate = year+ "-" +month;
            var t = this;

            $(container).find(".prevMonth").css("cursor", "pointer");
            $(container).find(".nextMonth").css("cursor", "pointer");
             
            if(boolPrVal==curDate){
                $(container).find(".prevMonth").css("display", "none");
                $(container).find(".nextMonth").css("display", "block");
//                $(container).find(".prevMonth").attr("display", "none");
//                $(container).find(".prevnbspID").attr("display", "block");
            } else {
                $(container).find(".prevMonth").click(function() {
                    if (month == 1) {
                        month = 12;
                        year = year - 1;
                    } else {
                        month = month - 1;
                    }

                    t.RenderCalendar($(container).find(".calendarDivId").val(), divId, month, year);
//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659 showView($(container).find(".calendarDivId").val(), $(container).find(".strCalendarId").val(), month+"-"+year); 
                    showView($(container).find(".calendarDivId").val(), $(container).find(".strCalendarId").val(), month+"-"+year, storeFlg);
//M0010659 MOD 20110808 HIROYUKI NORO END
                    changeTab($(container).find(".hidTdValue").val(), "co0");
                });
            }
            ;

            if(boolneVal==curDate){
                $(container).find(".nextMonth").css("display", "none");
                $(container).find(".nextnbspID").css("display", "block");
//                $(container).find(".nextMonth").attr("display", "none");
//                $(container).find(".nextnbspID").attr("display", "block");
            } else {
                $(container).find(".nextMonth").click(function() {
                    if (month == 12) {
                        month = 1;
                        year = year + 1;
                    } else {
                        month = month + 1;
                    }

                    t.RenderCalendar($(container).find(".calendarDivId").val(),divId, month, year);
//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659  showView($(container).find(".calendarDivId").val(), $(container).find(".strCalendarId").val(), month+"-"+year);
                    showView($(container).find(".calendarDivId").val(), $(container).find(".strCalendarId").val(), month+"-"+year, storeFlg);
//M0010659 MOD 20110808 HIROYUKI NORO END
                    changeTab($(container).find(".hidTdValue").val(), "co0");
                });
            } 
            ;
        },
        //Compute an appointed month day number
        _GetTotalDays: function(month, year) {
            if (month == 2) {
                if (this._IsLeapYear(year)) {
                    return 29;
                } else {
                    return 28;
                }
            } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                return 30;
            } else {
                return 31;
            }
        },
        _GetToalDaysOfPrevMonth: function(month, year) {
            if (month == 1) {
                month = 12;
                year = year - 1;
            } else {
                month = month - 1;
            }

            return this._GetTotalDays(month, year);
        },
        //IsLeapYear
        _IsLeapYear: function(year) {
            return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
        }
    };

    function setCalendar(calandarDivId, id){
        var date = new Date();
        var mapping = [];
        mapping.push(new DateLinkMapping("3-22-2010", "javascript:alert(1)"));
        mapping.push(new DateLinkMapping("3-23-2010", "javascript:alert(1)"));
        Calendar.Init(null, mapping);
        Calendar.RenderCalendar(calandarDivId, id, date.getMonth() + 1, date.getFullYear());
    }

    function getCalendar(id){ 
        var month=Calendar.month;
        var year=Calendar.year;
        var day=Calendar.day;

        return day+"-"+month+"-"+year;
    }

//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659 function showView(calendarDivId, strCalendarId,strdate){
    function showView(calendarDivId, strCalendarId,strdate, storeFlg){
//M0010659 MOD 20110808 HIROYUKI NORO END
        var strArray =strdate.split("-");
        var strMonth =strArray[0];
        var strYear =strArray[1];

//M0010659 MOD 20110808 HIROYUKI NORO START
        if(storeFlg == 0){
            ajaxRequest(getHost() + "/page/calendarview/calendarplug",
                    {
                        "strCalendarId"   : strCalendarId,
                        "strMonth"        : strMonth,
                        "strYear"         : strYear,
                        "strCalendarDivId":calendarDivId
                    }, cms_colorCallback);
        }
        else{
            cms_colorCallback(storeCalenddarData);
        }
//M0010659 MOD 20110808 HIROYUKI NORO END
    }

    function cms_colorCallback(data){
        var date          = new Date();
        var day           = date.getDate();
        var year          = date.getFullYear();
        var month         = date.getMonth()+1;
        var curday        = year + "-" + month;
        var calendarDivId = data.calendarDivId;

        if (data != null && data != "") {
            if (data.HEADER.TODAYCol[0] != null && data.HEADER.TODAYCol[0] != "" && curday == data.HEADER.TODAYCol[0].YearMonth) {
                for (i = 0; i < 4; i++) {
                    $(container).find(".day_0" + i + "" + month + "_" + day).children("span").css("border-bottom", "1px solid #" + data.HEADER.TODAYCol[0].TODAYCOLOR);
//                    $(container).find(".day_0" + i + "" + month + "_" + day).attr("bgColor", "#" + data.HEADER.TODAYCol[0].TODAYCOLOR);
                }
            }

            if (data.HEADER.ArrColor != "") {
                for (i = 0; i < data.HEADER.ArrColor.length; i++) {
                    if (data.HEADER.ArrColor[i].COLOR_FG_1 == 1) {
                        $(container).find("." + data.HEADER.ArrColor[i].DAYID_1).attr("bgColor", "#" + data.HEADER.ArrColor[i].ACTIVECOLOR_1);
                    } 
                    
                    if (data.HEADER.ArrColor[i].COLOR_FG_2 == 1) {
                        $(container).find("." + data.HEADER.ArrColor[i].DAYID_2).attr("bgColor", "#" + data.HEADER.ArrColor[i].ACTIVECOLOR_2);
                    } 
                    
                    if (data.HEADER.ArrColor[i].COLOR_FG_3 == 1) {
                        $(container).find("." + data.HEADER.ArrColor[i].DAYID_3).attr("bgColor", "#" + data.HEADER.ArrColor[i].ACTIVECOLOR_3);
                    } 
                    
                    if (data.HEADER.ArrColor[i].COLOR_FG_4 == 1) {
                        $(container).find("." + data.HEADER.ArrColor[i].DAYID_4).attr("bgColor", "#" + data.HEADER.ArrColor[i].ACTIVECOLOR_4);
                    }
                
                }
            }
//M0010659 ADD 20110808 HIROYUKI NORO START
            storeCalenddarData = data;
//M0010659 ADD 20110808 HIROYUKI NORO END
        }
    }

    function changeTab (n, tab) {
        var len = 4;

        for (var i = 1; i <= len; i++) {
            var display     = (i == n) ? 'block' : 'none';
            var displayHead = (i == n) ? 'active' : '';

            $(container).find("." + tab + i).attr("display", display);
            $(container).find("." + tab + i).css("display", display);
            
            if (displayHead == 'active') {
                $(container).find("." + tab + "_head_" + i).addClass(displayHead);
            } else {
                $(container).find("." + tab + "_head_" + i).removeClass('active');
            }
        }

        $(container).find(".hidTdValue").val(n);
    };

    function app_headerCallback(data){
        var calendarHeader ;
        var head1     = data.HEADER[0].COLOR_NAME_1 ;
        var head2     = data.HEADER[0].COLOR_NAME_2 ;
        var head3     = data.HEADER[0].COLOR_NAME_3 ;
        var head4     = data.HEADER[0].COLOR_NAME_4 ;
        var bottomVal = data.HEADER[0].GUIDANCE ;
        
        var calendarDivId = data.calendarDivId;
        var strCalendarId = data.calendarId; // 2011.05.23 add

        $(container).find(".hidhead1").val(head1);
        $(container).find(".hidhead2").val(head2);
        $(container).find(".hidhead3").val(head3);
        $(container).find(".hidhead4").val(head4);

        calendarHeader  = "<h2>"+data.HEADER[0].TITLE+"</h2>";
        calendarHeader += "<ul class=\"nv timeContents\"></ul>" ;
        calendarHeader += "<ul class=\"tab tabContents\"></ul>";
        calendarHeader += "<div class=\"contents\">";
        calendarHeader += "<div class=\"co01\">";
        calendarHeader += "<div class=\"00\"></div>";
        calendarHeader += "</div>";
        calendarHeader += "<div class=\"co02\" style=\"display: none;\">";
        calendarHeader += "<div class=\"01\"></div>";
        calendarHeader += "</div>";
        calendarHeader += "<div class=\"co03\" style=\"display: none;\">";
        calendarHeader += "<div class=\"02\"></div>";
        calendarHeader += "</div>";
        calendarHeader += "<div class=\"co04\" style=\"display: none;\">";
        calendarHeader += "<div class=\"03\"></div>";
        calendarHeader += "</div>";

        if (bottomVal != null && bottomVal != "") {
            calendarHeader += "<div>";
            calendarHeader += "<hr><div style=\"margin-bottom:4px;\">" + bottomVal + "</div>";
            calendarHeader += "</div>";
        }

        $(container).find(".contents").html(calendarHeader);

        for (i = 0; i < 4; i++) {
            setCalendar(calendarDivId, "0"+i);
        }
        
        // 表示するタブの一番左になる物を選択状態にさせる
        var tab = 1;
        
        if (head1 == "") {
        	if (head2 != "") {
        		tab = 2;
        	} else if (head3 != "") {
        		tab = 3;
        	} else if (head4 != "") {
        		tab = 4;
        	}
        }

        changeTab(tab, "co0");

        var date   = new Date();
        var year   = date.getFullYear();
        var month  = date.getMonth()+1;
        var curday = month+"-"+year ;

//M0010659 MOD 20110808 HIROYUKI NORO START
//M0010659  showView(calendarDivId, strCalendarId, curday);
        showView(calendarDivId, strCalendarId, curday, 0);
//M0010659 ADD 20110808 HIROYUKI NORO END
    }

    //日付が指定されている祝日
    var DateHoliday = function( month, day ) {
        this.month = month;
        this.day = day;
    };

    DateHoliday.prototype = {
        getHoliday:  function(year) {
            return this.day;
        }
    };

    // ハッピーマンデー
    var MondayHoliday = function( month, week ) {
        this.month = month;
        this.week = week;
        this.wday = 1;
    };

    MondayHoliday.prototype = {
        getHoliday: function(year) {
            var firstWday = new Date(year,this.month-1,1).getDay();

            return 7*(this.week - ( (firstWday <= this.wday) ? 1 : 0 )) + ( this.wday - firstWday ) + 1; // 第this.week this.wday曜日
        }
    };

    // 春分・秋分の日
    var EquinoxHoliday = function( month ) {
        this.month = month;

        if( this.month == 3 ) {
            this.offset = 20.8431;
        } else if ( this.month == 9 ) {
            this.offset = 23.2488;
        } else {
            throw 'Not exists equinox day in '+month;
        }
    };

    EquinoxHoliday.prototype = {
        getHoliday: function(year) {
            return Math.floor(this.offset+0.242194*(year-1980)-Math.floor((year-1980)/4)); // 1980-2099に対応?
        }
    };

    var HolidayHelper = {
        holidayMap: {
            1:  [new DateHoliday( 1, 1 ), new MondayHoliday( 1, 2 )],
            2:  [new DateHoliday( 2, 11 )],
            3:  [new EquinoxHoliday( 3 )],
            4:  [new DateHoliday( 4, 29 )],
            5:  [new DateHoliday( 5, 3 ), new DateHoliday( 5, 4 ), new DateHoliday( 5, 5 )],
            7:  [new MondayHoliday( 7, 3 )], 
            9:  [new MondayHoliday( 9, 3 ), new EquinoxHoliday( 9 )],
            10: [new MondayHoliday( 10, 2 )],
            11: [new DateHoliday( 11, 3 ), new DateHoliday( 11, 23 )],
            12: [new DateHoliday( 12, 23 )]
        },
        // 月をまたがる振替休日や国民の休日(昨日と翌日が国民の祝日である日)が存在しないことを前提とした処理
        getHolidays: function( year, month ) {
            var holidays = this.holidayMap[month];

            if ( !holidays ) {
                return {};
            }

            var dayHash= {}
            var dateArray = []

            for( var i=0, len=holidays.length; i<len; i++ ) {
                var day = holidays[i].getHoliday(year);
                dayHash[ day ] = true;
                dateArray.push( new Date(year,month-1,day) );
            }

            for ( var i=0, len=dateArray.length; i<len; i++ ) {
                var date = dateArray[i];
                var day = date.getDate();

                if ( date.getDay() == 0 ) {
                    var cday = day+1;

                    while( dayHash[cday] ) {  // 振替休日が祝日の場合、翌日へ
                        cday++;
                    }

                    dayHash[ cday ] = true;
                }

                // 国民の休日判定には、振替休日を考慮しない
                if ( dayHash[day+2] && !dayHash[day+1] ) {
                    dayHash[ day+1 ] = true;
                }
            }

            return dayHash;
        },
        isHoliday : function( dateOrYear, month, day ) {
            var year  = day ? dateOrYear : dateOrYear.getFullYear();
            var month = day ? month : dateOrYear.getMonth()+1;
            var day   = day || dateOrYear.getDate();

            return !! this.getHolidays( year, month )[ day ];
        },
        preDayIsHoliday:function(dateOrYear, month, day){
            if (day == 1) {//月初1号
                if (month == 1) {
                    month =12;
                    dateOrYear = dateOrYear-1 ;
                } else {
                    month=month-1;
                }

                if (month == 2) {
                    if (this.bolIsLeapYear(dateOrYear)) {
                        day = 29;
                    } else {
                        day = 28;
                    }
                } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                    day = 30;
                } else {
                    day = 31;
                }
            } else {
                day=day-1;
            }
            //IsLeapYear

            return this.isHoliday(dateOrYear, month, day);
        },
        bolIsLeapYear: function(year) {
            return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
        }
    };
})();

