//休日指定（YYYYMMDD形式）
myHoliday = new Array("20081228",
                      "20081229",
                      "20081230",
                      "20090101",
                      "20090102",
                      "20090103",
                      "20090104",
                      "20090105",
                      "20090106",
                      "20090201",
                      "20090301",
                      "20090405",
                      "20090503",
                      "20090607",
                      "20090705",
                      "20090802",
                      "20090813",
                      "20090814",
                      "20090815",
                      "20090816",
                      "20090906",
                      "20091004",
                      "20091101",
                      "20091206",
                      "20091229",
                      "20091230",
                      "20091231",
                      "20100101",
                      "20100102",
                      "20100103",
                      "20100104",
                      "20100105",
                      "20100106",
                      "20100207",
                      "20100307",
                      "20100404",
                      "20100502",
                      "20100606",
                      "20100704",
                      "20100801",
                      "20100905",
                      "20101003",
                      "20101107",
                      "20101205",
                      "20151231"
                      );

var myDate = null;

function writeCalendar(year, month, day) {
    //引数に日付が指定されていない場合は、今日の日付を取得
    if (year == null || month == null || day == null) {
        myDate = new Date();                                   // 今日の日付データ取得
    } else {
        myDate = new Date(year, month, day);
    }

    myWeekTbl = new Array("日","月","火","水","木","金","土"); // 曜日テーブル定義
    myMonthTbl= new Array(31,28,31,30,31,30,31,31,30,31,30,31);// 月テーブル定義
    myYear = myDate.getFullYear();                                 // 下２桁の西暦取得
    myYear = (myYear<2000) ? (1900+myYear) : (myYear);         // ４桁の西暦に変換
    if (((myYear%4)==0 && (myYear%100)!=0) || (myYear%400)==0) // うるう年だったら...
       myMonthTbl[1] = 29;                                     // 　２月を２９日とする
    myMonth = myDate.getMonth();                               // 月を取得(0月～11月)
    myToday = myDate.getDate();                                // 今日の'日'を退避
    myDate.setDate(1);                                         // 日付を'１日'に変えて、
    myWeek = myDate.getDay();                                  // '１日'の曜日を取得
    myTblLine = Math.ceil((myWeek+myMonthTbl[myMonth])/7);     // カレンダーの行数
    myTable   = new Array(7*myTblLine);                        // 表のセル数分定義

    for(i=0; i<7*myTblLine; i++) myTable[i]="　";              // myTableを掃除する
    for(i=0; i<myMonthTbl[myMonth]; i++)myTable[i+myWeek]=i+1; // 日付を埋め込む

    // ***********************
    // *  カレンダーの表示   *
    // ***********************
    var strCal = "";
    strCal = "<p>" + myYear + "年" + (myMonth+1) + "月の営業日カレンダー</p>"
    
    
    var preMonth = new Date(myYear, myMonth-1, 1);
    var nowDate = new Date();
    var nextMonth = new Date(myYear, myMonth+1, 1);
    strCal = strCal + "<div align='center'><p><a href='./index.html' onclick=\"writeCalendar('" + preMonth.getFullYear() + "','" + preMonth.getMonth() + "','1'); return false;\">前月</a>　　　<a href='./index.html' onclick=\"writeCalendar('" + nowDate.getFullYear() + "','" + nowDate.getMonth() + "','1'); return false;\">今月</a>　　　<a href='./index.html' onclick=\"writeCalendar('" + nextMonth.getFullYear() + "','" + nextMonth.getMonth() + "','1'); return false;\">翌月</a></p></div>";
    
    
    strCal = strCal + "<table ";						// 表の作成開始
    strCal = strCal + "bordercolor='#808080' ";
    strCal = strCal + "bordercolordark='#000000' ";
    strCal = strCal + "bordercolorlight='#C0C0C0'>";

    strCal = strCal + "<tr>";							// 曜日見出しセット
    strCal = strCal + "<th class='tdred'>日</th>";
    strCal = strCal + "<th class='tdn'>月</th>";
    strCal = strCal + "<th class='tdn'>火</th>";
    strCal = strCal + "<th class='tdn'>水</th>";
    strCal = strCal + "<th class='tdn'>木</th>";
    strCal = strCal + "<th class='tdn'>金</th>";
    strCal = strCal + "<th class='tdblue'>土</th>";
    strCal = strCal + "</tr>";

    // 日付の書き込み
    for(i=0; i<myTblLine; i++){                                 // 表の「行」のループ
       strCal = strCal + "<tr>";								// 行の開始
       for(j=0; j<7; j++){                                      // 表の「列」のループ
          strCal = strCal + "<td align='center' ";				// 列(セル)の作成
          myDat = myTable[j+(i*7)];                             // 書きこむ内容の取得
          if(j==3 && myDat != "　") {
            strCal = strCal + "bgcolor='#ffb6c1'";				// 水曜のセルの色
          }

          //水曜以外の休日のセルの色設定（水曜を休日指定にしていると表示が崩れる）
          for (k=0; k<myHoliday.length; k++) {
            if (myYear == myHoliday[k].substr(0, 4) &&
                myMonth+1 == myHoliday[k].substr(4, 2) &&
                myDat == myHoliday[k].substr(6, 2)) {
                strCal = strCal + "bgcolor='#ffb6c1'";
            }
          }

          strCal = strCal + ">";								// tdの閉じタグ
          strCal = strCal + myDat;								// 日付セット
          strCal = strCal + "</td>";							// 列(セル)の終わり
       }
       strCal = strCal + "</tr>"								// 行の終わり
    }

    strCal = strCal + "</table>";								// 表の終わり
    strCal = strCal + "<p class='datep'>※<span class='f_tdh'>■</span>は定休日です。<br />定休日：水曜・第1日曜日</p>";

    document.getElementById("cal").innerHTML = strCal;
}



function changeCalendar(param) {
    if (param == "pre") {
        writeCalendar(preMonth);
    } else {
        writeCalendar(nextMonth);
    }
}


