var nowMM
var nowYY
var calendar_place = "calendar_place"

monstr = new Array(12);
for(i = 0; i <= 11; i++){
  monstr[i] = new Array(4);      /* ２次元配列作成  */
}
yostr = new Array();
/*----------------*
 * 設定はここから *
 *----------------*/
var clfont     = "sans-serif";  // フォントの種類（全体共通）

var frbgcolor  = "#ccddff";	    // 外枠の背景色
var frborder   = 5;             // 外枠の幅
var monfnsize  = "15pt";        // 月のフォントサイズ
var frfncolor  = "#DEB887";     // 月の文字色
//var frfncolor  = "#ffffff";   // 月の文字色

var inbgcolor  = "#ffffff";     // 日付部の背景色
var yobgcolor  = "#ffffee";     // 曜日部の背景色
var tdbgcolor  = "#ffeeee";     // 本日の背景色
var dwidth     = 40;            // 日付・曜日欄の幅
var dheight    = 20;            // 日付・曜日欄の高さ
var dayfnsize  = "13pt";        // 日付と曜日のフォントサイズ
var dayfncolor = "#999999";     // 平日の文字色（曜日・日付共通）
var kdfncolor  = "#ff9999";     // 日曜・休日の文字色（曜日・日付共通）
var blfncolor  = "#8484ee";     // 土曜の文字色（曜日・日付共通）
var ndstr      = "・";          // 日付なし欄に出す文字
var ndfncolor  = "#cccccc";     // 日付なし欄の文字色

// 月の表示文字
monstr[0][0]  = "January";    //  1月
monstr[1][0]  = "February";   //  2月
monstr[2][0]  = "March";      //  3月
monstr[3][0]  = "April";      //  4月
monstr[4][0]  = "May";        //  5月
monstr[5][0]  = "June";       //  6月
monstr[6][0]  = "July";       //  7月
monstr[7][0]  = "August";     //  8月
monstr[8][0]  = "September";  //  9月
monstr[9][0]  = "October";    // 10月
monstr[10][0] = "November";   // 11月
monstr[11][0] = "December";   // 12月

monstr[0][1]  = "1月";        //  1月
monstr[1][1]  = "2月";        //  2月
monstr[2][1]  = "3月";        //  3月
monstr[3][1]  = "4月";        //  4月
monstr[4][1]  = "5月";        //  5月
monstr[5][1]  = "6月";        //  6月
monstr[6][1]  = "7月";        //  7月
monstr[7][1]  = "8月";        //  8月
monstr[8][1]  = "9月";        //  9月
monstr[9][1]  = "10月";       // 10月
monstr[10][1] = "11月";       // 11月
monstr[11][1] = "12月";       // 12月

monstr[0][2]  = "睦月";       //  1月
monstr[1][2]  = "如月";       //  2月
monstr[2][2]  = "弥生";       //  3月
monstr[3][2]  = "卯月";       //  4月
monstr[4][2]  = "皐月";       //  5月
monstr[5][2]  = "水無月";     //  6月
monstr[6][2]  = "葉月";       //  7月
monstr[7][2]  = "文月";       //  8月
monstr[8][2]  = "長月";       //  9月
monstr[9][2]  = "神無月";     // 10月
monstr[10][2] = "霜月";       // 11月
monstr[11][2] = "師走";       // 12月

monstr[0][3]  = "01";         //  1月
monstr[1][3]  = "02";         //  2月
monstr[2][3]  = "03";         //  3月
monstr[3][3]  = "04";         //  4月
monstr[4][3]  = "05";         //  5月
monstr[5][3]  = "06";         //  6月
monstr[6][3]  = "07";         //  7月
monstr[7][3]  = "08";         //  8月
monstr[8][3]  = "09";         //  9月
monstr[9][3]  = "10";         // 10月
monstr[10][3] = "11";         // 11月
monstr[11][3] = "12";         // 12月

// 曜日の表示文字
yostr[0] = "Sun";  // 日曜
yostr[1] = "Mon";  // 月曜
yostr[2] = "Tue";  // 火曜
yostr[3] = "Wed";  // 水曜
yostr[4] = "Thu";  // 木曜
yostr[5] = "Fri";  // 金曜
yostr[6] = "Sat";  // 土曜

maxday = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

/*----------------*
 * 設定はここまで *
 *----------------*/
function toCalender(yy, mm) {
  var todate = new Date();
  var date = new Date(yy, mm, 1);
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var today = todate.getDate();
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { maxday[1]++; }
  date.setDate(1);
  var yo1 = date.getDay();
  var flag = 0;
  var mmode = 1;
  var daycnt = 1;

  //カレンダーを表示する場所
  var mybody=document.getElementById(calendar_place);
  while (mybody.hasChildNodes())
  {
    mybody.removeChild(mybody.firstChild);
  }

  //カレンダーメインテーブル
  mytable = document.createElement("TABLE");
  mytable.style.backgroundColor = frbgcolor;
  mytable.style.cellpadding = frborder;
  mytable.style.cellspacing = "0";
  mytablebody = document.createElement("TBODY");

  //カレンダー年月表示
  mycurrent_row=document.createElement("TR");

  mycurrent_cell=document.createElement("TD");
  mycurrent_cell.style.textAlign = "center";

  mycurrent_cell_span=document.createElement("SPAN");
  mycurrent_cell_span.style.fontFamily = clfont;
  mycurrent_cell_span.style.fontSize = monfnsize;

  mycurrent_cell_span_font=document.createElement("FONT");
  mycurrent_cell_span_font.style.color = frfncolor;

  mycurrent_cell_span_font_div=document.createElement("DIV");
  mycurrent_cell_span_font_div.id = 0;
  if (mmode == 0) {
    currenttext=document.createTextNode(monstr[month-1][mmode] + ' ' + year);
  } else if (mmode == 1) {
    currenttext=document.createTextNode(year + '年 ' + monstr[month-1][mmode]);
  } else if (mmode == 2) {
    currenttext=document.createTextNode(year + '年 ' + monstr[month-1][mmode]);
  } else {
    currenttext=document.createTextNode(year + ' / ' + monstr[month-1][mmode]);
  }
  mycurrent_cell_span_font_div.appendChild(currenttext);
  mycurrent_cell_span_font.appendChild(mycurrent_cell_span_font_div);
  mycurrent_cell_span.appendChild(mycurrent_cell_span_font);
  mycurrent_cell.appendChild(mycurrent_cell_span);

  //カレンダーメイン表示
  sbtable = document.createElement("TABLE");
  sbtable.style.borderStyle = "none";
  sbtable.style.backgroundColor = inbgcolor;
  sbtable.style.cellpadding = "0";
  sbtable.style.cellspacing = "0";
  sbtablebody = document.createElement("TBODY");

  //カレンダー曜日表示
  sbcurrent_row=document.createElement("TR");
  sbcurrent_row.style.backgroundColor = yobgcolor;

  for (yo = 0; yo < 7; yo++) {

    sbcurrent_cell=document.createElement("TD");
    sbcurrent_cell.style.width = dwidth;
    sbcurrent_cell.style.height = dheight;
    sbcurrent_cell.style.textAlign = "center";

    sbcurrent_cell_span=document.createElement("SPAN");
    sbcurrent_cell_span.style.fontFamily = clfont;
    sbcurrent_cell_span.style.fontSize = dayfnsize;

    sbcurrent_cell_span_font=document.createElement("FONT");
    if (yo == 0) {
      sbcurrent_cell_span_font.style.color = kdfncolor
    }else if (yo < 6) {
      sbcurrent_cell_span_font.style.color = dayfncolor;
    }else {
      sbcurrent_cell_span_font.style.color = blfncolor;
    }

    currenttext=document.createTextNode(yostr[yo]);
    sbcurrent_cell_span_font.appendChild(currenttext);
    sbcurrent_cell_span.appendChild(sbcurrent_cell_span_font);
    sbcurrent_cell.appendChild(sbcurrent_cell_span);
    sbcurrent_row.appendChild(sbcurrent_cell);
  }

  sbtablebody.appendChild(sbcurrent_row);

  while (flag < 2) {
    sbcurrent_row=document.createElement("TR");
    for (yo = 0; yo < 7; yo++) {

      sbcurrent_cell=document.createElement("TD");
      sbcurrent_cell.style.width = dwidth;
      sbcurrent_cell.style.height = dheight;
      sbcurrent_cell.style.textAlign = "center";

      // 1日
      if (flag == 0 && yo1 == yo) { flag = 1; }
      // 日付あり
      if (flag == 1) {
        if (daycnt == today && month - 1 == todate.getMonth() && year == todate.getFullYear()) {
          // 本日の背景設定
          sbcurrent_cell.style.backgroundColor = tdbgcolor;
        }

        sbcurrent_cell_span=document.createElement("SPAN");
        sbcurrent_cell_span.style.fontFamily = clfont;
        sbcurrent_cell_span.style.fontSize = dayfnsize;

        sbcurrent_cell_span_font=document.createElement("FONT");
        if (yo == 0) {
          sbcurrent_cell_span_font.style.color = kdfncolor
        } else if (ktHolidayName(year + "/" + month + "/" + daycnt) != "") {
          sbcurrent_cell_span_font.style.color = kdfncolor
        } else if (yo < 6) {
          sbcurrent_cell_span_font.style.color = dayfncolor
        } else {
          sbcurrent_cell_span_font.style.color = blfncolor
        }
        if (++daycnt > maxday[month - 1]) { flag = 2; }	// 最終日

        sbcurrent_cell_span_font_div=document.createElement("DIV");
        sbcurrent_cell_span_font_div.id = daycnt - 1;
        currenttext=document.createTextNode(daycnt - 1);
        sbcurrent_cell_span_font_div.appendChild(currenttext);
        sbcurrent_cell_span_font.appendChild(sbcurrent_cell_span_font_div);
        sbcurrent_cell_span.appendChild(sbcurrent_cell_span_font);
        sbcurrent_cell.appendChild(sbcurrent_cell_span);

      } else {	// 日付なし
        sbcurrent_cell_span_font=document.createElement("FONT");
        sbcurrent_cell_span_font.style.color = ndfncolor

        currenttext=document.createTextNode(ndstr);
        sbcurrent_cell_span_font.appendChild(currenttext);
        sbcurrent_cell.appendChild(sbcurrent_cell_span_font);

      }
      sbcurrent_row.appendChild(sbcurrent_cell);
    }
    sbtablebody.appendChild(sbcurrent_row);
  }

  sbtable.appendChild(sbtablebody);

  mycurrent_cell.appendChild(sbtable);
  mycurrent_row.appendChild(mycurrent_cell);

  mytablebody.appendChild(mycurrent_row);

  mytable.appendChild(mytablebody);
  mybody.appendChild(mytable);
}

