//  ========================================================
//  jkl-Calendar2.js ---- ポップアップカレンダー表示クラス
//  Copyright 2005-2006 Kawasaki Yusuke <u-suke [at] kawa.net>
//  Thanks to 2tak <info [at] code-hour.com>
//  http://www.kawa.net/works/js/jkl/calender.html
//  2005/04/06 - 最初のバージョン
//  2005/04/10 - 外部スタイルシートを使用しない、JKL.Opacity はオプション
//  2006/10/22 - typo修正、spliter/min_date/max_dateプロパティ、×ボタン追加
//  2006/10/23 - prototype.js併用時は、Event.observe()でイベント登録
//  2006/10/24 - max_date 範囲バグ修正
//  2006/10/25 - フォームに初期値があれば、カレンダーの初期値に採用する
//  2006/11/15 - MOM Update 週の初めの曜日を変更できるように修正
//  2006/11/23 - MOM Update 今日日付の文字色を指定できるように修正、あと枠線も描画してみる
//  2006/11/30 - MOM Update 選択可能な曜日をプロパティに追加、今日日付と選択不可能な日付の背景色をスタイルに追加
//               カレンダーのz-indexをプロパティに追加
//  2006/12/04 - ksuzu Update 選択可能日がない月には移動できないように変更
//               カレンダーの表示月をクリックすると現在の月に移動できるよう変更
//               閉じるボタンにてカレンダーを閉じたとき、カレンダーの初期表示を戻すよう変更
//  2006/12/30 - MOM IFRAMEのSRC属性にdummy.htmlを挿入
//  2006/12/30 - joao 祝日設定と選択できない日、できる日を設定するため変更
//               フォームに使用せず表示のみの使用に対応させた
//               --表示のみの使用で日がクリックされた後のリンク先を指定できるようにした
//               選択範囲を本日からの相対で何日間という設定をできるようにした
//  2007/02/04 - MOM setDateYMDのバグを修正
//               TDタグのスタイルに背景色を指定するよう修正
//  2007/05/10 - joao 2000年6月5日　フォーマットに対応
//  ========================================================



/***********************************************************
//  （サンプル）ポップアップするカレンダー

  <html>
    <head>
      <script type="text/javascript" src="jkl-Calendar2.js" charset="Shift_JIS"></script>
      <script>
        var cal1 = new JKL.Calendar2("calid","formid","colname");
       </script>
    </head>
    <body>
      <form id="formid" action="">
        <input type="text" name="colname" onClick="cal1.write();" onChange="cal1.getFormValue(); cal1.hide();"><br>
        <div id="calid"></div>
      </form>
    </body>
  </html>

//  （サンプル）フォームに使用せずページに表示させて使用

  <html>
    <head>
      <script type="text/javascript" src="jkl-Calendar2.js" charset="Shift_JIS"></script>
      <script>
        var cal1 = new JKL.Calendar2("calid");
       </script>
    </head>
    <body onload="cal1.write(1);">
        <div id="calid"></div>
    </body>
  </html>

 **********************************************************/

// 親クラス

if ( typeof(JKL) == 'undefined' ) JKL = function() {};

// JKL.Calendar2 コンストラクタの定義

JKL.Calendar2 = function ( eid, fid, valname ) {
    this.eid = eid;
    this.formid = fid;
    this.valname = valname;
    this.__dispelem = null;  // カレンダー表示欄エレメント
    this.__textelem = null;  // テキスト入力欄エレメント
    this.__opaciobj = null;  // JKL.Opacity オブジェクト
    this.style = new JKL.Calendar2.Style();
    return this;
};

// バージョン番号

JKL.Calendar2.VERSION = "0.13";

// デフォルトのプロパティ
// 2007.05.10 joao 2000年6月5日フォーマット(JKL.Calendar2.prototype.spliter = "";)に対応
JKL.Calendar2.prototype.spliter = "";
JKL.Calendar2.prototype.date = null;
JKL.Calendar2.prototype.min_date = null;
JKL.Calendar2.prototype.max_date = null;

// 2006.11.15 MOM 表示開始曜日をプロパティに追加(デフォルトは日曜日=0)
JKL.Calendar2.prototype.start_day = 0;

// 2006.11.23 MOM カレンダー内の日付を枠線で区切るかどうかのプロパティ(デフォルトはtrue)
JKL.Calendar2.prototype.draw_border = true;

// 2006.11.30 MOM 各曜日の選択可否をプロパティに追加(デフォルトは全てtrue)
// 配列の添え字で曜日を指定(0〜6 = 日曜〜土曜)、選択可否をboolean値で代入する、という使い方
JKL.Calendar2.prototype.selectable_days = new Array(false,true,true,false,true,true,true);

// 2006.12.30 joao 祝日判定のため追加しました（選択させない日も月日、年月日のどちらでも設定可能、月日の場合は当該年と解釈）
JKL.Calendar2.prototype.syukuzitsu_days = new Array('1/1','4/29','5/3','5/4','5/5','11/3','11/23','12/23','2007/1/8','2007/2/12','2007/3/21','2007/4/30','2007/7/16','2007/9/17','2007/9/24','2007/10/8','2007/12/24','2008/1/14','2008/2/11','2008/3/20','2008/5/6','2008/7/21','2008/9/15','2008/9/23','2008/10/13','2008/11/24');
// 2006.12.30 joao 祝日を選択させる true; 、祝日をさせない false; 設定のため追加しました
JKL.Calendar2.prototype.syuku_sel_or_nonsel =false;
// 2006.12.30 joao 選択させない日 true; 、させる日 false; 設定のため追加しました
JKL.Calendar2.prototype.sel_or_nonsel =true;
JKL.Calendar2.prototype.non_select_days = new Array('1/2','1/3','12/29','12/30','12/31','8/14','8/15','8/16','8/17');
//2006.12.30 joao 選択範囲の最初の日付を今日から何日後で指定、最終日を最初の日から何日後で指定
// どちらも0なら全ての日を選択可能に（選択可能日付範囲の指定があると範囲を優先）
JKL.Calendar2.prototype.min_day = -30;
JKL.Calendar2.prototype.max_day = 30;
//2006.12.30 joao 表示のみの使用で日がクリックされた後のリンク先を指定
JKL.Calendar2.prototype.url = "";
// joao 表示のみの使用で日がクリックされた後のリンク先のtargetを指定、指定しないと同じ窓に
JKL.Calendar2.prototype.win_name = "";
// joao 表示のみの使用で日がクリックされた後のリンク先のURLに日を引数に付ける 〜.cgi?2007/01/01
// joao URLと引数の間に挿入するテキスト（URLエンコードが必要な場合は変換後のテキストを指定）
JKL.Calendar2.prototype.cgi = "?";

// JKL.Calendar2.Style

JKL.Calendar2.Style = function() {
    return this;
};

// デフォルトのスタイル

JKL.Calendar2.Style.prototype.frame_width        = "180px";      // フレーム横幅
JKL.Calendar2.Style.prototype.frame_color        = "url(total_image/month.jpg)";    // フレーム枠の色
JKL.Calendar2.Style.prototype.font_size          = "11px";       // 文字サイズ
JKL.Calendar2.Style.prototype.day_bgcolor        = "url(total_image/day.jpg)";    // カレンダーの背景色
JKL.Calendar2.Style.prototype.month_color        = "#999999";    // ○年○月部分の背景色
JKL.Calendar2.Style.prototype.month_hover_color  = "#FFFFFF";    // マウスオーバー時の≪≫文字色
JKL.Calendar2.Style.prototype.month_hover_bgcolor= "#666666";   // マウスオーバー時の≪≫背景色
JKL.Calendar2.Style.prototype.weekday_color      = "#000000";    // 月曜〜金曜日セルの文字色
JKL.Calendar2.Style.prototype.saturday_color     = "#000000";    // 土曜日セルの文字色
JKL.Calendar2.Style.prototype.sunday_color       = "#000000";    // 日曜日セルの文字色
JKL.Calendar2.Style.prototype.others_color       = "#999999";    // 他の月の日セルの文字色
JKL.Calendar2.Style.prototype.day_hover_bgcolor  = "#FF3300";    // マウスオーバー時の日セルの背景
JKL.Calendar2.Style.prototype.cursor             = "pointer";    // マウスオーバー時のカーソル形状

// 2006.11.23 MOM 今日日付の文字色をプロパティに追加
JKL.Calendar2.Style.prototype.today_color        = "#CC0000";    // 今日日付セルの文字色
// 2006.11.23 MOM 枠線もつけてみる
JKL.Calendar2.Style.prototype.today_border_color = "#CC0000";    // 今日日付セルの枠線の色
JKL.Calendar2.Style.prototype.others_border_color= "#FFFFFF";    // 他の日セルの枠線の色

// 2006.11.30 MOM 今日日付の背景色を忘れてたので追加してみる
JKL.Calendar2.Style.prototype.today_bgcolor      = "url(total_image/today.gif) ";    // 今日日付セルの背景色
// 2006.11.30 MOM 選択不可能な日付の背景色を追加
JKL.Calendar2.Style.prototype.unselectable_day_bgcolor = "#BBBBBB";    // 選択不可能な日付の背景色

//  メソッド

JKL.Calendar2.Style.prototype.set = function(key,val) { this[key] = val; }
JKL.Calendar2.Style.prototype.get = function(key) { return this[key]; }
JKL.Calendar2.prototype.setStyle = function(key,val) { this.style.set(key,val); };
JKL.Calendar2.prototype.getStyle = function(key) { return this.style.get(key); };

// 日付を初期化する

JKL.Calendar2.prototype.initDate = function ( dd ) {
    if ( ! dd ) dd = new Date();
    var year = dd.getFullYear();
    var mon  = dd.getMonth();
    var date = dd.getDate();
    this.date = new Date( year, mon, date );
    this.getFormValue();
    return this.date;
}

// 透明度設定のオブジェクトを返す

JKL.Calendar2.prototype.getOpacityObject = function () {
    if ( this.__opaciobj ) return this.__opaciobj;
    var cal = this.getCalendar2Element();
    if ( ! JKL.Opacity ) return;
    this.__opaciobj = new JKL.Opacity( cal );
    return this.__opaciobj;
};

// カレンダー表示欄のエレメントを返す

JKL.Calendar2.prototype.getCalendar2Element = function () {
    if ( this.__dispelem ) return this.__dispelem;
    this.__dispelem = document.getElementById( this.eid )
    return this.__dispelem;
};

// テキスト入力欄のエレメントを返す

JKL.Calendar2.prototype.getFormElement = function () {
    if ( this.__textelem ) return this.__textelem;
    var frmelms = document.getElementById( this.formid );
    if ( ! frmelms ) return;
    for( var i=0; i < frmelms.elements.length; i++ ) {
        if ( frmelms.elements[i].name == this.valname ) {
            this.__textelem = frmelms.elements[i];
        }
    }
    return this.__textelem;
};

// オブジェクトに日付を記憶する（YYYY/MM/DD形式で指定する）

JKL.Calendar2.prototype.setDateYMD = function (ymd) {
// 2007.05.10 joao 2000年6月5日フォーマットに対応
	if(this.spliter==""){
		var splt = new Array(3);
		if(ymd.match(/(\d+)[^\d]+(\d+)[^\d]+(\d+)/)){
			splt[0]=RegExp.$1; splt[1]=RegExp.$2; splt[2]=RegExp.$3;
		}
		else{return ""}
	}
	else{var splt = ymd.split( this.spliter )}
    if ( splt[0]-0 > 0 &&
         splt[1]-0 >= 1 && splt[1]-0 <= 12 &&       // bug fix 2006/03/03 thanks to ucb
         splt[2]-0 >= 1 && splt[2]-0 <= 31 ) {
        if ( ! this.date ) this.initDate();
/* 2007.02.04 MOM 画面表示時、既に日付がセットされている場合に発生するバグを修正
            this.date.setFullYear( splt[0] );
            this.date.setMonth( splt[1]-1 );
            this.date.setDate( splt[2] );
*/
            this.date.setDate( splt[2] );
            this.date.setMonth( splt[1]-1 );
            this.date.setFullYear( splt[0] );
    } else {
        ymd = "";
    }
    return ymd;
};

// オブジェクトから日付を取り出す（YYYY/MM/DD形式で返る）
// 引数に Date オブジェクトの指定があれば、
// オブジェクトは無視して、引数の日付を使用する（単なるfprint機能）

JKL.Calendar2.prototype.getDateYMD = function ( dd ) {
    if ( ! dd ) {
        if ( ! this.date ) this.initDate();
        dd = this.date;
    }
    var mm = "" + (dd.getMonth()+1);
    var aa = "" + dd.getDate();
// 2007.05.10 joao 2000年6月5日フォーマットに対応
	if(this.spliter==""){return dd.getFullYear() + '年' + mm + '月' + aa + '日'}
	else{
		if ( mm.length == 1 ) mm = "" + "0" + mm;
		if ( aa.length == 1 ) aa = "" + "0" + aa;
		return dd.getFullYear() + this.spliter + mm + this.spliter + aa;
	}
};

// テキスト入力欄の値を返す（ついでにオブジェクトも更新する）

JKL.Calendar2.prototype.getFormValue = function () {
    var form1 = this.getFormElement();
    if ( ! form1 ) return "";
    var date1 = this.setDateYMD( form1.value );
    return date1;
};

// フォーム入力欄に指定した値を書き込む

JKL.Calendar2.prototype.setFormValue = function (ymd) {
    if ( ! ymd ) ymd = this.getDateYMD();   // 無指定時はオブジェクトから？
    var form1 = this.getFormElement();
    if ( form1 ) form1.value = ymd;
};

//  カレンダー表示欄を表示する

JKL.Calendar2.prototype.show = function () {
    this.getCalendar2Element().style.display = "";
};

//  カレンダー表示欄を即座に隠す

JKL.Calendar2.prototype.hide = function () {
    this.getCalendar2Element().style.display = "none";
};

//  カレンダー表示欄をフェードアウトする
//  2006/12/30 joao 表示のみの使用に対応
JKL.Calendar2.prototype.fadeOut = function (s,only_disp) {
	if(only_disp){return}

    if ( JKL.Opacity ) {
        this.getOpacityObject().fadeOut(s);
    } else {
        this.hide();
    }
};

// 月単位で移動する
//  2006/12/30 joao 表示のみの使用に対応
JKL.Calendar2.prototype.moveMonth = function ( mon ,only_disp) {

    // 前へ移動
    if ( ! this.date ) this.initDate();
    for( ; mon<0; mon++ ) {
        this.date.setDate(1);   // 毎月1日の1日前は必ず前の月
        this.date.setTime( this.date.getTime() - (24*3600*1000) );
    }
    // 後へ移動
    for( ; mon>0; mon-- ) {
        this.date.setDate(1);   // 毎月1日の32日後は必ず次の月
        this.date.setTime( this.date.getTime() + (24*3600*1000)*32 );
    }
    this.date.setDate(1);       // 当月の1日に戻す

//  2006/12/30 joao 表示のみの使用に対応
    this.write(only_disp);    // 描画する
};

// イベントを登録する

JKL.Calendar2.prototype.addEvent = function ( elem, ev, func ) {
//  prototype.js があれば利用する(IEメモリリーク回避)
    if ( window.Event && Event.observe ) {
        Event.observe( elem, ev, func, false );
    } else {
        elem["on"+ev] = func;
    }
}

// カレンダーを描画する
//  2006/12/30 joao 表示のみの使用に対応
JKL.Calendar2.prototype.write = function ( only_disp ) {

//  2006/12/30 joao  表示のみの使用で日がクリックされた後のリンク先のURLに対応
	var g_url=this.url;
	var g_win_name=this.win_name;
	var g_cgi=this.cgi;

    var date = new Date();
    if ( ! this.date ) this.initDate();
    date.setTime( this.date.getTime() );

    var year = date.getFullYear();          // 指定年
    var mon  = date.getMonth();             // 指定月
    var today = date.getDate();             // 指定日
    var form1 = this.getFormElement();

    // 選択可能な日付範囲
//  2006/12/30 joao 今日から何日間を選択範囲にするかを設定
	if((this.min_day+this.max_day)>0){
		var dt= new Date((new Date()).getTime()+86400000*(this.min_day));
		this.min_date=new Date(dt.getFullYear(), dt.getMonth(),dt.getDate());
		this.max_day=this.max_day+this.min_day-1;
		var dt= new Date((new Date()).getTime()+86400000*(this.max_day));
		this.max_date=new Date(dt.getFullYear(), dt.getMonth(),dt.getDate());
	}

    var min;
    if ( this.min_date ) {
        var tmp = new Date( this.min_date.getFullYear(), 
            this.min_date.getMonth(), this.min_date.getDate() );
        min = tmp.getTime();
    }
	var max;
    if ( this.max_date ) {
        var tmp = new Date( this.max_date.getFullYear(), 
            this.max_date.getMonth(), this.max_date.getDate() );
        max = tmp.getTime();
    }

    // 直前の月曜日まで戻す
    date.setDate(1);                        // 1日に戻す
    var wday = date.getDay();               // 曜日 日曜(0)〜土曜(6)

// 2006.11.15 MOM 表示開始曜日を可変にしたので、ロジックちょっといじりますよ
    if ( wday != this.start_day ) {
        date.setTime( date.getTime() - (24*3600*1000)*((wday-this.start_day+7)%7) );
    }
/*
    if ( wday != 1 ) {
        if ( wday == 0 ) wday = 7;
        date.setTime( date.getTime() - (24*3600*1000)*(wday-1) );
    }
*/

    // 最大で7日×6週間＝42日分のループ
    var list = new Array();
    for( var i=0; i<42; i++ ) {
        var tmp = new Date();
        tmp.setTime( date.getTime() + (24*3600*1000)*i );
        if ( i && i%7==0 && tmp.getMonth() != mon ) break;
        list[list.length] = tmp;
    }

    // スタイルシートを生成する
    var month_table_style = 'width: 100%; ';
    month_table_style += 'background: '+this.style.frame_color+'; ';
    month_table_style += 'border: 1px solid '+this.style.frame_color+';';

    var week_table_style = 'width: 100%; ';
    week_table_style += 'background: '+this.style.day_bgcolor+'; ';
    week_table_style += 'border-left: 1px solid '+this.style.frame_color+'; ';
    week_table_style += 'border-right: 1px solid '+this.style.frame_color+'; ';

    var days_table_style = 'width: 100%; ';
    days_table_style += 'background: '+this.style.day_bgcolor+'; ';
    days_table_style += 'border: 1px solid '+this.style.frame_color+'; ';

    var month_td_style = "";
// 2007.02.04 MOM TDタグも背景色のスタイルを明示的に指定する
    month_td_style += 'background: '+this.style.frame_color+'; ';
    month_td_style += 'font-size: '+this.style.font_size+'; ';
    month_td_style += 'color: '+this.style.month_color+'; ';
    month_td_style += 'padding: 4px 0px 2px 0px; ';
    month_td_style += 'text-align: center; ';
    month_td_style += 'font-weight: bold;';

    var week_td_style = "";
// 2007.02.04 MOM TDタグも背景色のスタイルを明示的に指定する
    week_td_style += 'background: '+this.style.day_bgcolor+'; ';
    week_td_style += 'font-size: '+this.style.font_size+'; ';
    week_td_style += 'padding: 2px 0px 2px 0px; ';
    week_td_style += 'font-weight: bold;';
    week_td_style += 'text-align: center;';

    var days_td_style = "";
// 2007.02.04 MOM TDタグも背景色のスタイルを明示的に指定する
    days_td_style += 'background: '+this.style.day_bgcolor+'; ';
    days_td_style += 'font-size: '+this.style.font_size+'; ';
    days_td_style += 'padding: 2px; ';
    days_td_style += 'text-align: center; ';
    days_td_style += 'font-weight: bold;';

    var days_unselectable = "font-weight: normal;";

    // HTMLソースを生成する
    var src1 = "";

//2006.12.30 joao 祝日判定、選択させない日設定のため追加しました
    var syukuzitsu = new Object();
    for(i in this.syukuzitsu_days){
		if(this.syukuzitsu_days[i].length>5){syukuzitsu[this.syukuzitsu_days[i]]=true}
		else{syukuzitsu[year+"/"+this.syukuzitsu_days[i]]=true}
    }
    var non_select = new Object();
    for(i in this.non_select_days){
		if(this.non_select_days[i].length>5){non_select[this.non_select_days[i]]=true}
		else{non_select[year+"/"+this.non_select_days[i]]=true}
    }

    src1 += '<table border="0" cellpadding="0" cellspacing="0" style="'+month_table_style+'"><tr>';
    src1 += '<td id="__'+this.eid+'_btn_prev" title="前の月へ" style="'+month_td_style+'">≪</td>';
    src1 += '<td style="'+month_td_style+'">&nbsp;</td>';
// 2006.12.04 ksuzu 表示月をクリックすると現在の月に移動
    src1 += '<td id="__'+this.eid+'_btn_today" style="'+month_td_style+'">'+(year)+'年 '+(mon+1)+'月</td>';
//    src1 += '<td style="'+month_td_style+'">'+(year)+'年 '+(mon+1)+'月</td>';
//  2006/12/30 joao 表示のみの使用に対応
    src1 += '<td id="__'+this.eid+'_btn_close" title="" style="'+month_td_style+'">';
	if(!only_disp){src1+=''}
	src1 += '</td>';

    src1 += '<td id="__'+this.eid+'_btn_next" title="次の月へ" style="'+month_td_style+'">≫</td>';
    src1 += "</tr></table>\n";
    src1 += '<table border="0" cellpadding="0" cellspacing="0" style="'+week_table_style+'"><tr>';

// 2006.11.15 MOM 表示開始曜日start_dayから順に一週間分表示する
    for(var i = this.start_day; i < this.start_day + 7; i++){
        var _wday = i%7;
        if(_wday == 0){
             src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">日</td>';
        }else if(_wday == 1){
             src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">月</td>';
        }else{
             src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">';
            if(_wday == 6)        src1 += '土</td>';
            else if(_wday == 2)    src1 += '火</td>';
            else if(_wday == 3)    src1 += '水</td>';
            else if(_wday == 4)    src1 += '木</td>';
            else if(_wday == 5)    src1 += '金</td>';
        }
    }
/*
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">月</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">火</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">水</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">木</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">金</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">土</td>';
    src1 += '<td style="color: '+this.style.weekday_color+'; '+week_td_style+'">日</td>';
*/

    src1 += "</tr></table>\n";
    src1 += '<table border="0" cellpadding="0" cellspacing="0" style="'+days_table_style+'">';

    var curutc;
// 2007.05.10 joao 2000年6月5日フォーマットに対応
    if ( form1 && form1.value ) {
		if(this.spliter==""){
			var splt = new Array(3);
			if(form1.value.match(/(\d+)[^\d]+(\d+)[^\d]+(\d+)/)){
				splt[0]=RegExp.$1; splt[1]=RegExp.$2; splt[2]=RegExp.$3;
			}
		}
		else{var splt = form1.value.split(this.spliter)}
        if ( splt[0]-0 > 0 && splt[2]-0 > 0 ) {
            var curdd = new Date( splt[0]-0, splt[1]-1, splt[2]-0 );
            curutc = curdd.getTime();                           // フォーム上の当日
        }
    }

//2006.11.23 MOM 今日日付を取得し、時分秒を切り捨てる
    var realdd = new Date();
    var realutc = (new Date(realdd.getFullYear(),realdd.getMonth(),realdd.getDate())).getTime();

    for ( var i=0; i<list.length; i++ ) {
        var dd = list[i];
        var ww = dd.getDay();
        var mm = dd.getMonth();

        if ( ww == this.start_day ) {
            src1 += "<tr>";                                     // 表示開始曜日の前に行頭
        }
/*
        if ( ww == 1 ) {
            src1 += "<tr>";                                     // 月曜日の前に行頭
        }
*/

        var cc = days_td_style;
        var utc = dd.getTime();

//2006.12.30 joao 祝日判定のため上にもってきました
		var tt = dd.getDate();
//2006.12.30 joao 祝日判定のため追加
		var jos=year+"/"+(mm+1)+"/"+tt;

        if ( mon == mm ) {
//2006.11.23 MOM 最初に今日日付かどうかをチェックする
//※当月でない場合にも色変えると選択できそうに見えて紛らわしいので、当月かつ今日日付の場合のみ色を変える
            if ( utc == realutc ){
                cc += "color: "+this.style.today_color+";";     // 今日日付
            }
//2006.12.30 joao 祝日判定のため追加
			if ( ww == 0 || syukuzitsu[jos]) {
                cc += "color: "+this.style.sunday_color+";";    // 当月の日曜日
            } else if ( ww == 6 ) {
                cc += "color: "+this.style.saturday_color+";";  // 当月の土曜日
            } else {
                cc += "color: "+this.style.weekday_color+";";   // 当月の平日
            }
        } else {
            cc += "color: "+this.style.others_color+";";        // 前月末と翌月初の日付
        }

//2006.11.23 MOM utcの変数宣言を↑に移動
//      var utc = dd.getTime();

// 2006.11.30 MOM 選択可能な曜日指定の条件追加
// 2006.12.30 joao 選択させない日 true; 、させる日 false; 設定のため追加しました
		if (( min && min > utc ) || ( max && max < utc ) || (!this.sel_or_nonsel && non_select[jos]==undefined) || (!this.syuku_sel_or_nonsel && syukuzitsu[jos]!=undefined)){cc += days_unselectable}
		else{
			if (this.sel_or_nonsel){
				if(!this.selectable_days[dd.getDay()] || non_select[jos]){cc += days_unselectable}
			}
		}

        if ( utc == curutc ) {                                  // フォーム上の当日
            cc += "background: "+this.style.day_hover_bgcolor+";";
        }
// 2006.11.30 MOM 今日日付の背景色
//        else if ( mon == mm && utc == realutc ) {
//            cc += "background: "+this.style.today_bgcolor+";";
//        }
// 2006.11.30 MOM 選択不可能な日付の背景色
// 2006.12.30 joao 選択させない日 true; 、させる日 false; 設定のため追加しました
		else if (( min && min > utc ) || ( max && max < utc ) || (!this.sel_or_nonsel && non_select[jos]==undefined) || (!this.syuku_sel_or_nonsel && syukuzitsu[jos]!=undefined)){cc += 'background: '+this.style.unselectable_day_bgcolor+';'}
		else{
			if (this.sel_or_nonsel){
				if(!this.selectable_days[dd.getDay()] || non_select[jos]){cc += 'background: '+this.style.unselectable_day_bgcolor+';'}
			}
		}

//2006.11.23 MOM 枠線描画を追加
        if ( this.draw_border ){
            if ( mon == mm && utc == realutc ){
                cc += "border:solid 1px "+this.style.today_border_color+";";    // 当月かつ今日日付
            } else {
                cc += "border:solid 1px "+this.style.others_border_color+";";    // その他
            }
        }

        var ss = this.getDateYMD(dd);
//2006.12.30 joao 祝日判定のため↑にもっていきました
//        var tt = dd.getDate();

        src1 += '<td style="'+cc+'" title='+ss+' id="__'+this.eid+'_td_'+ss+'">'+tt+'</td>';

        if ( ww == (this.start_day+6)%7 ) {
            src1 += "</tr>\n";                                  // 表示開始曜日の１つ手前で行末
        }
/*
        if ( ww == 7 ) {
            src1 += "</tr>\n";                                  // 土曜日の後に行末
        }
*/
    }
    src1 += "</table>\n";

    src1 += '</div>\n';

    // カレンダーを書き換える
    var cal1 = this.getCalendar2Element();
    if ( ! cal1 ) return;
    cal1.style.width = this.style.frame_width;

//  2006/12/30 joao 表示のみの使用に対応
	if(only_disp){cal1.style.position = ""}
    else{cal1.style.position = "absolute"}

    cal1.innerHTML = src1;


    // イベントを登録する
    var __this = this;
    var get_src = function (ev) {
        ev  = ev || window.event;
        var src = ev.target || ev.srcElement;
        return src;
    };
    var month_onmouseover = function (ev) {
        var src = get_src(ev);
        src.style.color = __this.style.month_hover_color;
        src.style.background = __this.style.month_hover_bgcolor;
    };
    var month_onmouseout = function (ev) {
        var src = get_src(ev);
        src.style.color = __this.style.month_color;
        src.style.background = __this.style.frame_color;
    };
    var day_onmouseover = function (ev) {
        var src = get_src(ev);
        src.style.background = __this.style.day_hover_bgcolor;
    };
    var day_onmouseout = function (ev) {
        var src = get_src(ev);
// 2006.11.30 MOM 当月かつ今日日付であれば、今日日付用の背景色を適用
        var today = new Date();
        if( today.getMonth() == __this.date.getMonth() && src.id == '__'+__this.eid+'_td_'+__this.getDateYMD(today) ){
            src.style.background = __this.style.today_bgcolor;
        }else{
            src.style.background = __this.style.day_bgcolor;
        }
    };
    var day_onclick = function (ev) {
        var src = get_src(ev);
		var srcday = src.id.match(/\d\d\d\d/);
        srcday = RegExp.lastMatch+RegExp.rightContext;
        __this.setFormValue( srcday );

//  2006/12/30 joao  表示のみの使用で日がクリックされた後のリンク先のURLに対応
		if(only_disp && g_url != ""){
			if(g_cgi != ""){g_url+=g_cgi+srcday}
			if(g_win_name != ""){window.open(g_url,g_win_name)}
			else{location.href=g_url}
		}
//  2006/12/30 joao 表示のみの使用に対応
        __this.fadeOut( 1.0 ,only_disp);
    };

//
// 2006.12.04 ksuzu 選択できない月へのリンクは作成しない
//
    // 前の月へボタン
    var tdprev = document.getElementById( "__"+this.eid+"_btn_prev" );
    //前の月の最終日
    var tmpDate = new Date(year,mon,1);
    tmpDate.setTime( tmpDate.getTime() - (24*3600*1000) );
    //選択可能な日がある？
    if ( !min || this.min_date <= tmpDate ){
        tdprev.style.cursor = this.style.cursor;
        this.addEvent( tdprev, "mouseover", month_onmouseover );
        this.addEvent( tdprev, "mouseout", month_onmouseout );
//  2006/12/30 joao 表示のみの使用に対応
        this.addEvent( tdprev, "click", function(){ __this.moveMonth( -1 ,only_disp); });
    }
    //選択不可能
    else{
        tdprev.title = "前の月は選択できません";
    }
/*
    tdprev.style.cursor = this.style.cursor;
    this.addEvent( tdprev, "mouseover", month_onmouseover );
    this.addEvent( tdprev, "mouseout", month_onmouseout );
//  2006/12/30 joao 表示のみの使用に対応
    this.addEvent( tdprev, "click", function(){ __this.moveMonth( -1 ,only_disp); });
2006.12.04 ksuzu */

//
// 2006.12.04 ksuzu 表示月をクリックすると現在の月に移動
//
    var nMov = (realdd.getFullYear() - year) * 12 + (realdd.getMonth() - mon);
    if ( nMov != 0 ){
        // 現在の月へボタン
        var tdtoday = document.getElementById( "__"+this.eid+"_btn_today" );
        tdtoday.style.cursor = this.style.cursor;
        tdtoday.title = "現在の月へ";
        this.addEvent( tdtoday, "mouseover", month_onmouseover );
        this.addEvent( tdtoday, "mouseout", month_onmouseout );
//  2006/12/30 joao 表示のみの使用に対応
        this.addEvent( tdtoday, "click", function(){ __this.moveMonth( nMov ,only_disp); });
    }

    // 閉じるボタン
    var tdclose = document.getElementById( "__"+this.eid+"_btn_close" );
    tdclose.style.cursor = this.style.cursor;
    this.addEvent( tdclose, "mouseover", month_onmouseover );
    this.addEvent( tdclose, "mouseout", month_onmouseout );

//
// 2006.12.04 ksuzu カレンダーの初期表示を戻す
//
    this.addEvent( tdclose, "click", function(){ __this.getFormValue(); __this.hide(); });
//    this.addEvent( tdclose, "click", function(){ __this.hide(); });

//
// 2006.12.04 ksuzu 選択できない月へのリンクは作成しない
//
    // 次の月へボタン
    var tdnext = document.getElementById( "__"+this.eid+"_btn_next" );
    //次の月の初日
    var tmpDate = new Date(year,mon,1);
    tmpDate.setTime( tmpDate.getTime() + (24*3600*1000)*32 );
    tmpDate.setDate(1);
    //選択可能な日がある？
    if ( !max || this.max_date >= tmpDate ){
        tdnext.style.cursor = this.style.cursor;
        this.addEvent( tdnext, "mouseover", month_onmouseover );
        this.addEvent( tdnext, "mouseout", month_onmouseout );
//  2006/12/30 joao 表示のみの使用に対応
        this.addEvent( tdnext, "click", function(){ __this.moveMonth( +1 ,only_disp); });
    }
    //選択不可能
    else{
        tdnext.title = "次の月は選択できません";
    }
/*
    tdnext.style.cursor = this.style.cursor;
    this.addEvent( tdnext, "mouseover", month_onmouseover );
    this.addEvent( tdnext, "mouseout", month_onmouseout );
//  2006/12/30 joao 表示のみの使用に対応
    this.addEvent( tdnext, "click", function(){ __this.moveMonth( +1 ,only_disp); });
2006.12.04 ksuzu */

    // セルごとのイベントを登録する
    for ( var i=0; i<list.length; i++ ) {
        var dd = list[i];
        if ( mon != dd.getMonth() ) continue;       // 今月のセルにのみ設定する

        var utc = dd.getTime();
//2006.12.30 joao 選択させない日設定のため追加しました
		var tt = dd.getDate();

        if ( min && min > utc ) continue;           // 昔過ぎる
        if ( max && max < utc ) continue;           // 未来過ぎる
        if ( utc == curutc ) continue;              // フォーム上の当日
// 2006.11.30 MOM 選択可能な曜日指定対応
//2006.12.30 joao 選択させない日設定のためMOMさんに便乗
        var ss = this.getDateYMD(dd);
		var sl = ss.substring(0,4)+"/"+(mon+1)+"/"+tt;
		if(!this.sel_or_nonsel && non_select[sl]==undefined){continue}
		else if (syukuzitsu[sl]!=undefined && !this.syuku_sel_or_nonsel){continue}
		else if (this.sel_or_nonsel){
			if(!this.selectable_days[dd.getDay()] || non_select[sl]){continue}
		}

        var cc = document.getElementById( "__"+this.eid+"_td_"+ss );
        if ( ! cc ) continue;

    }

    // 表示する
    this.show();
};

// 旧バージョン互換（typo）
JKL.Calendar2.prototype.getCalenderElement = JKL.Calendar2.prototype.getCalendar2Element;
JKL.Calender = JKL.Calendar2;

