//-----------------------------------------------
//      JavaScriptライブラリィ(SDMLIB.js)
//     
//      作成者     今井芳也
//      更新日　   2008.5.7
//      バージョン SDML1.1
//-----------------------------------------------
//<style>
//<!--
//.mon  { font-size:10pt; } /* 年月の文字サイズ */
//.wday { font-size:10pt; } /* 曜日の文字サイズ */
//.date { font-size:12pt; } /* 日の文字サイズ   */
//-->
//</style>

//  最終更新日表示
function UpDate()
{
document.writeln( document.lastModified );
}

//  日付表示
function DspDate()
{
   youbi  = new Array("(日)","(月)","(火)","(水)","(木)","(金)","(土)");
   myDate = new Date() ;
   theDate  = myDate.getDate() ;
   theDay   = youbi[myDate.getDay()];
   theFyear = myDate.getFullYear() ;
   theYear  = myDate.getYear() ;
   theMonth = myDate.getMonth() + 1 ;
   document.write( theFyear + "年" + theMonth + "月" + theDate + "日 " + theDay ) ;

}

//　日付＋時間（入力ボックスに表示）
function DATETIME() 
{
now = new Date();
year = now.getYear();
month = now.getMonth()+1;
day = now.getDate();
hour = now.getHours();
minute = now.getMinutes();
second = now.getSeconds();
if (year < 1000) { year += 1900 }
if (hour < 10) { hour = '0' + hour }
if (minute < 10) { minute = '0' + minute }
if (second < 10) { second = '0' + second }
document.form.watch.value = year+'年' + month + '月' + day + '日 '
+ hour + ':' + minute + ':' + second;
setTimeout("DATETIME()",1000);
}

//----------------------------------------------------------------
//  年間１２ヶ月カレンダー CalDsp1(num)
//----------------------------------------------------------------
function CalDsp1(num){
var now = new Date();
var year;
var month;
var date;
var dValue = document.getElementById("dValue");

switch(parseInt(num)){
case 0:
year = now.getFullYear();
month = now.getMonth()+1;
date = now.getDate();
break;
case 1:
var backMDate = new Date(parseInt(dValue.innerHTML) - 24*60*60*1000*1);
if(backMDate.getMonth() == now.getMonth() && backMDate.getFullYear() == now.getFullYear()){
year = now.getFullYear();
month = now.getMonth()+1;
date = now.getDate();
}else{
year = backMDate.getFullYear();
month = backMDate.getMonth() + 1;
date = -1;
}
break;
case 2:
var nextMDate = new Date(parseInt(dValue.innerHTML) + 24*60*60*1000*31);
if(nextMDate.getMonth() == now.getMonth() && nextMDate.getFullYear() == now.getFullYear()){
year = now.getFullYear();
month = now.getMonth()+1;
date = now.getDate();
}else{
year = nextMDate.getFullYear();
month = nextMDate.getMonth() + 1;
date = -1;
}
break;
}

dValue.innerHTML = (new Date(year, month-1, 1)).getTime();

var last_date = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var editMsg;
if(month==2){
if(year%4==0){
if((year%100==0) && (year%400!=0)){
}else{
last_date[1] = 29;
}
}
}
editMsg = "";
editMsg += "<TABLE border=0 cellspacing=3><TR><TD colspan='7' align='center'><B><U><FONT size='-1'>" + year + "年" + month + "月</FONT></B></U></TD></TR>\n";
editMsg += "<TR>" + defTD("日","red") + defTD("月","black") + defTD("火","black") + defTD("水","black") + defTD("木","black") + defTD("金","black") + defTD("土","blue") + "</TR>\n";
editMsg += "<TR>";
for(dayIndex=0; dayIndex<(new Date(year,month-1,1)).getDay(); dayIndex++){
editMsg += defTD("&nbsp;","white");
}
for(i=1; i<=last_date[month-1]; i++){
if(i!=1 && dayIndex == 0){
editMsg += "<TR>";
}
if(i==date){
editMsg += defTD(i,"orange");
}else{
switch(dayIndex){
case 0: editMsg += defTD(i,"red"); break;
case 6: editMsg += defTD(i,"blue"); break;
default: editMsg += defTD(i,"black"); break;
}
}
if(dayIndex == 6){
editMsg += "</TR>\n";
}
dayIndex++; dayIndex%=7;
}
if(dayIndex!=7){
editMsg += "</TR>\n";
}
editMsg += "</TABLE>\n";
document.getElementById("CalDsp1").innerHTML = editMsg;
}
function defTD(str, iro){
return "<TD align='center'><B><FONT size='-2' color='" + iro + "'>" + str + "</FONT></B></TD>";
}


//-----------------------------------------------------
//    年月度指定カレンダー CalDsp2()
//-----------------------------------------------------
function CalDsp2()
{
// カレンダーの枠の色
cal_bd = "white";

// カレンダーの文字色
cal_tx = "white";

// カレンダーの背景色
cal_bg = "black";

// 土曜日の色
sat_col = "blue";

// 日曜日の色
sun_col = "red";

// 本日の文字色
tdy_tx = "black";

// 本日の背景色
tdy_col = "white";

// 過去未来の表示可能年数（10なら10年前から10年後まで）
// 1970年以前の表示がどこまで正確にできるかについては保証しません
noy = 10;

// 月（'１月','２月','３月'...等でも可）
mnname = new Array('1','2','3','4','5','6','7','8','9','10','11','12');

// 曜日（'日','月','火'...等でも可）
wdname = new Array('日','月','火','水','木','金','土');

buffer = document.location.search;
buffer = buffer.replace("?","");
buffer = buffer.split("&");
query = new Array();
for (i in buffer) {
   buf = buffer[i].split("=");
   query[buf[0]] = buf[1];
}

if (query['year'] && query['mon']) {
   y = eval(query['year']);
   m = eval(query['mon']) - 1;
   target = new Date(y,m);
   d = new Date();
   nowyear = d.getYear();
   nowmon = d.getMonth();
   nowdate = d.getDate();
}
else {
   target = new Date();
   nowyear = target.getYear();
   nowmon = target.getMonth();
   nowdate = target.getDate();
}

year = target.getYear();
mon = target.getMonth();
if (nowyear < 1900) nowyear += 1900;
if (year < 1900) year += 1900;

for (i = 28; i <= 31; i++) {
   ldate = new Date(year,mon,i);
   if (ldate.getMonth() == mon) ld = i;
}

fd = new Date(year,mon,1);
fwday = fd.getDay();
ldate = new Date(year,mon,ld);
lwday = ldate.getDay();
day = 1 - fwday;

CAL = "<table><form><td align=center>";
CAL += "<table bgcolor=" + cal_bd + " border=0 cellpadding=0 cellspacing=0><td>";
CAL += "<table border=0 cellspacing=1>";
CAL += "<tr bgcolor=" + cal_bg + "><th colspan=7>";

CAL += "<select name=year class=mon style='color : white;background-color : black;'>";
for (i = nowyear - noy; i <= nowyear + noy; i ++)
   if (i == year) CAL += "<option value=" + i + " selected>" + i;
   else CAL += "<option value=" + i + ">" + i;
CAL += "</select><select name=mon class=mon style='color : white;background-color : black;'>";
for (i = 1; i <= 12; i ++)
   if (i == mon + 1) CAL += "<option value=" + i + " selected>" + mnname[i-1];
   else CAL += "<option value=" + i + ">" + mnname[i-1];
CAL += "</select> <input type=submit value='Set'>";
CAL += "</th></tr>";

CAL += "<tr bgcolor=" + cal_bg + ">";
for (i in wdname) {
   if (i == 0) wdname[i] = wdname[i].fontcolor(sun_col);
   else if (i == 6) wdname[i] = wdname[i].fontcolor(sat_col);
   else wdname[i] = wdname[i].fontcolor(cal_tx);
   CAL += "<td align=center class=wday><tt>" + wdname[i] + "</tt></td>";
}
CAL += "</tr>";

while (day <= ld) {
   CAL += "<tr bgcolor=" + cal_bg + ">";
   for (i = 0; i < 7; i ++) {
      if (day < 1 || day > ld) CAL += "<td><br></td>";
      else {
         if (year == nowyear && mon == nowmon && day == nowdate) {
            CAL += "<td bgcolor=" + tdy_col + " align=right class=date>";
            CAL += String(day).fontcolor(tdy_tx);
         }
         else {
            CAL += "<td align=right class=date>";
            if (i == 0) CAL += String(day).fontcolor(sun_col);
            else if (i == 6) CAL += String(day).fontcolor(sat_col);
            else CAL += String(day).fontcolor(cal_tx);
         }
         CAL += "</td>";
      }
      day ++;
   }
   CAL += "</tr>";
}
CAL += "</table></td></table></td></form></table>";

document.write(CAL);

}

//----------------------------------------------------------
//    当月カレンダー 休日表示 CalDsp3()
//----------------------------------------------------------
function CalDsp3() {

day = new Date();
kyou = day.getDate(); //今日の日にちを取得
//var week = new Array("<font color=red>(Sun)</font>","(Mon)","(Tue)","(Wed)","(Thu)","(Fri)","<font color=blue>(Sat)</font>");
var week = new Array("<font color=red>(日)</font>","(月)","(火)","(水)","(木)","(金)","<font color=blue>(土)</font>");

my_youbi = day.getDay();
wday = week[my_youbi];

var gyouji = new Array("元旦","成人の日","節分(3日)","建国記念日","雛祭り(3日)","春分の日","みどりの日","憲法記念日","国民の休日","こどもの日","米独立記念日(4日)","七夕(7日)","海の日","敬老の日","秋分の日","体育の日","文化の日","勤労感謝の日","天皇誕生日","クリスマスイヴ(24)","大晦日(31)","","","","")

day.setDate(1); //最初の日にち（１日）にセット
month = day.getMonth() + 1; //月を取得
year = day.getFullYear();　　　　//年を取得
// カレンダー本体
tukidays = new Array(31,28,31,30,31,30,31,31,30,31,30,31); //

// 祝祭日の計算
if(month == 1){holiday1 = 1; holiday2 = 14-(day.getDay()+5)%7; holiday3 = -1} //成人の日
else if(month == 2){holiday1 = 11; holiday2 = -1; holiday3 = -1}
else if(month == 3){
ed = 20.8431 + 0.242194 * (year - 1980) - Math.floor((year - 1980)/4); //春分の日


holiday1 = Math.floor(ed);
holiday2 = -1;
holiday3 = -1;
}
else if(month == 4){holiday1 = 29; holiday2 = -1; holiday3 = -1}
else if(month == 5){holiday1 = 3; holiday2 = 4; holiday3 = 5}
else if(month == 6){holiday1 = -1; holiday2 = -1; holiday3 = -1}
else if(month == 7){holiday1 = 21-(day.getDay()+5)%7; holiday2 = -1; holiday3 = -1}
else if(month == 8){holiday1 = -1; holiday2 = -1; holiday3 = -1}
else if(month == 9){
holiday1 = 21-(day.getDay()+5)%7; holiday2 = -1; holiday3 = -1;//敬老の日
ed = 23.2488 + 0.242194 * (year - 1980) - Math.floor((year - 1980)/4); //秋分の日
holiday2 = Math.floor(ed);
holiday3 = -1
}
else if(month == 10){holiday1 = 14-(day.getDay()+5)%7; holiday2 = -1; holiday3 = -1} //体育の日
else if(month == 11){holiday1 = 3; holiday2 = 23; holiday3 = -1}
else if(month == 12){holiday1 = 23; holiday2 = -1; holiday3 = -1}

// 閏年の計算
if((year%4 == 0) && (year%100 != 0) || (year%400 == 0)) tukidays[1] = 29;

my_day = "";
my_day += "<table border=2 cellspcing=1 cellpadding=1 bgcolor=#ffffff style='font-size:9pt'>";
my_day += "<tr align=center bgcolor=#ffffff><th colspan=7>"+year+"年"+month+"月</th></tr>";
my_day += "<tr align=center><th><font color=\"#ff0000\">日</font></th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th><font color=\"#0000ff\">土</font></th></tr>";


// 日付の書き込み
for(sunday = 1-day.getDay(); sunday <= 31; sunday +=7){
my_day += "<TR align=center>";
for(i = sunday; i < sunday + 7; i++){
if((i > 0) && (i <= tukidays[month-1])){
day.setDate(i);
today = day.getDay();

if(kyou == i) my_day += "<td bgcolor='#98fb98'>"; //　薄緑(#98fb98)
else my_day += "<td>";

if(today == 0){
my_day += "<font color=\"#ff0000\">"+ i +"</font></td>";
}else if((i == holiday1)||(i == holiday2)||(i == holiday3)){
my_day += "<font color=\"#ff0000\">"+ i +"</font></td>";
}else if((today == 1)&&((i-1 == holiday1)||(i-1 == holiday2)||(i-1 == holiday3))){
my_day += "<font color=\"#ff0000\">"+ i +"</font></td>";
}else if(today == 6){
my_day += "<font color=\"#0000ff\">"+ i +"</font></TD>";
}else{
my_day += ""+ i +"</td>";
}

}else{
my_day += "<td></td>";
}
}
my_day += "</TR>";
}
if (month==1){spday=gyouji[0]+"["+holiday1+"日]/"+gyouji[1]+"["+holiday2+"日]<br>"}
if (month==2){spday=gyouji[2]+"/"+gyouji[3]+"["+holiday1+"日]<br>"}
if (month==3){spday=gyouji[4]+"/"+gyouji[5]+"["+holiday1+"日]<br>"}
if (month==4){spday=gyouji[6]+"["+holiday1+"日]<br>"}
if (month==5){spday=gyouji[7]+"["+holiday1+"日]/"+gyouji[9]+"["+holiday3+"日]<br>"+gyouji[8]+"["+holiday2+"日]<br>"}
if (month==6){spday=""}
if (month==7){spday=gyouji[10]+"/"+gyouji[11]+"<br>"+gyouji[12]+"["+holiday1+"日]"}
if (month==8){spday=""}
if (month==9){spday=gyouji[13]+"["+holiday1+"日]/"+gyouji[14]+"["+holiday2+"日]<br>"}
if (month==10){spday=gyouji[15]+"["+holiday1+"日]<br>"}
if (month==11){spday=gyouji[16]+"["+holiday1+"日]/"+gyouji[17]+"["+holiday2+"日]<br>"}
if (month==12){spday=gyouji[18]+"["+holiday1+"日]/"+gyouji[20]+"<br>"+gyouji[19]+"<br>"}


//----(今日は．．．)-------------------------------------------------------------------------------------------------------
if ((kyou==holiday1)||(kyou==holiday2)||(kyou==holiday3)||(my_youbi==0)){
//my_day += "<tr align=center bgcolor=#ffffff><th colspan=7><small>今日は"+month+"月<font color=red>"+kyou+"</font>日"+wday+"です</th></tr>"; // <th>はBold 
my_day += "<tr align=center bgcolor=#ffffff><td colspan=7><small>今日は"+month+"月<font color=red>"+kyou+"</font>日"+wday+"です</td></tr>";

}else{
my_day += "<tr align=center bgcolor=#ffffff><td colspan=7><small>今日は"+month+"月"+kyou+"日"+wday+"です</td></tr>";
}

my_day += "<tr align=center bgcolor=#ffffff><td colspan=7><small><font color=black>"+spday+"</font></td></tr>";
// my_day += "<tr align=center bgcolor=#ffffff><td colspan=7><small><font color=black><a href=./NENCALEN.htm>年間カレンダー表示</a></td></tr>";
my_day += "</TABLE>";
//------------------------------------------------------------------------------------------------------------------------
document.write(my_day);
}

//----カンマ編集--------------------------------------------
function NUMEdit(VAL) {
 var txt_num = '' + VAL;
 if (isNaN(txt_num) || txt_num == "") {
     alert("数字を入力して下さい。");
 }
 else {
   var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
   var curr_val = txt_num.split('.');
   curr_val[0] += '.';
   do {
       curr_val[0] = curr_val[0].replace(rxSplit, '$1,$2');
   }   while (rxSplit.test(curr_val[0]));
   if (curr_val.length > 1) {
       return curr_val.join('');
   }
   else {
       return curr_val[0].split('.')[0];
   }
 }
}


//----------------------------------------------------------
//  ポッアップカレンダー　　2008.9.8　UPDATE
//----------------------------------------------------------

//  ========================================================
//  jkl-calendar.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 - フォームに初期値があれば、カレンダーの初期値に採用する
//  ========================================================

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

  <html>
    <head>
      <script type="text/javascript" src="jkl-opacity.js" charset="Shift_JIS"></script>
      <script type="text/javascript" src="jkl-calendar.js" charset="Shift_JIS"></script>
      <script>
        var cal1 = new JKL.Calendar("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>

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

// 親クラス

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

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

//---------------------------------------------------------
// JKL.Calendar = function ( FLG , eid , fid , valname ) 
// FLG     ---  0 :  範囲チェックなし  1 : 範囲チェックあり
// eid     ---  表示エリア名 DIVのid名
// fid     ---  フォーム名 
// valname ---  入力エリアのValue名
//---------------------------------------------------------
JKL.Calendar = function ( FLG , eid, fid, valname ) {
    this.FLG = FLG;
    this.eid = eid;
    this.formid = fid;
    this.valname = valname;
    this.__dispelem = null;  // カレンダー表示欄エレメント
    this.__textelem = null;  // テキスト入力欄エレメント
    this.__opaciobj = null;  // JKL.Opacity オブジェクト
    this.style = new JKL.Calendar.Style();
    return this;
};

// バージョン番号

JKL.Calendar.VERSION = "0.13";

// デフォルトのプロパティ

JKL.Calendar.prototype.spliter = "/";
JKL.Calendar.prototype.date = null;
JKL.Calendar.prototype.min_date = null;
JKL.Calendar.prototype.max_date = null;

// JKL.Calendar.Style

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

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

JKL.Calendar.Style.prototype.frame_width        = "150px";      // フレーム横幅
JKL.Calendar.Style.prototype.frame_color        = "#009900";    // フレーム枠の色
JKL.Calendar.Style.prototype.font_size          = "12px";       // 文字サイズ
JKL.Calendar.Style.prototype.day_bgcolor        = "#F0F0F0";    // カレンダーの背景色
JKL.Calendar.Style.prototype.month_color        = "#FFFFFF";    // ○年○月部分の背景色
JKL.Calendar.Style.prototype.month_hover_color  = "#009900";    // マウスオーバー時の≪≫文字色
JKL.Calendar.Style.prototype.month_hover_bgcolor = "#FFFFCC";   // マウスオーバー時の≪≫背景色
JKL.Calendar.Style.prototype.weekday_color      = "#009900";    // 月曜〜金曜日セルの文字色
JKL.Calendar.Style.prototype.saturday_color     = "#0040D0";    // 土曜日セルの文字色
JKL.Calendar.Style.prototype.sunday_color       = "#D00000";    // 日曜日セルの文字色
JKL.Calendar.Style.prototype.others_color       = "#999999";    // 他の月の日セルの文字色
JKL.Calendar.Style.prototype.day_hover_bgcolor  = "#FF9933";    // マウスオーバー時の日セルの背景
JKL.Calendar.Style.prototype.cursor             = "pointer";    // マウスオーバー時のカーソル形状

//  メソッド

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

// 日付を初期化する

JKL.Calendar.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.Calendar.prototype.getOpacityObject = function () {
    if ( this.__opaciobj ) return this.__opaciobj;
    var cal = this.getCalendarElement();
    if ( ! JKL.Opacity ) return;
    this.__opaciobj = new JKL.Opacity( cal );
    return this.__opaciobj;
};

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

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

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

JKL.Calendar.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.Calendar.prototype.setDateYMD = function (ymd) {
    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();
        this.date.setFullYear( splt[0] );
        this.date.setMonth( splt[1]-1 );
        this.date.setDate( splt[2] );
    } else {
        ymd = "";
    }
    return ymd;
};

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

JKL.Calendar.prototype.getDateYMD = function ( dd ) {
    if ( ! dd ) {
        if ( ! this.date ) this.initDate();
        dd = this.date;
    }
    var mm = "" + (dd.getMonth()+1);
    var aa = "" + dd.getDate();
//    if ( mm.length == 1 ) mm = "" + "0" + mm; // 2008/09/08　UPDATE
//    if ( aa.length == 1 ) aa = "" + "0" + aa; // 2008/09/08  UPDATE

    if ( mm.length == 1 ) mm = "" + " " + mm ; // 2008/09/08　UPDATE
    if ( aa.length == 1 ) aa = "" + " " + aa ; // 2008/09/08  UPDATE

    return dd.getFullYear() + this.spliter + mm + this.spliter + aa;
};

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

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

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

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

    if ( this.FLG == 1 ) {
//----2008-08-29------------------------------------------
//    APL内にCHECK()関数を組み込んである事が条件！

    CHECK() ; 範疇チェック（FormTo等）
  
    }
//--------------------------------------------------------
// 2008-08029    if ( document.formid.start_date != "" ) {

// 2008-08029        document.formid.last_date.focus()  ;
// 2008-08029        document.formid.last_date.select() ;
// 2008-08029   }


};

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

JKL.Calendar.prototype.show = function () {
    this.getCalendarElement().style.display = "";
};

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

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

//  カレンダー表示欄をフェードアウトする

JKL.Calendar.prototype.fadeOut = function (s) {
    if ( JKL.Opacity ) {
        this.getOpacityObject().fadeOut(s);
    } else {
        this.hide();
    }
};

// 月単位で移動する

JKL.Calendar.prototype.moveMonth = function ( mon ) {
    // 前へ移動
    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日に戻す
    this.write();    // 描画する
};

// イベントを登録する

JKL.Calendar.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;
    }
}

// カレンダーを描画する

JKL.Calendar.prototype.write = function () {
    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();

    // 選択可能な日付範囲
    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)
    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 = "";
    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 = "";
    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 = "";
    days_td_style += 'font-size: '+this.style.font_size+'; ';
    days_td_style += 'padding: 1px; ';
    days_td_style += 'text-align: center; ';
    days_td_style += 'font-weight: bold;';

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

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

    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>';
    src1 += '<td style="'+month_td_style+'">'+(year)+'年 '+(mon+1)+'月</td>';
    src1 += '<td id="__'+this.eid+'_btn_close" title="閉じる" style="'+month_td_style+'">×</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>';
    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.saturday_color+'; '+week_td_style+'">土</td>';
    src1 += '<td style="color: '+this.style.sunday_color+'; '+week_td_style+'">日</td>';
    src1 += "</tr></table>\n";
    src1 += '<table border="0" cellpadding="0" cellspacing="0" style="'+days_table_style+'">';

    var curutc;
    if ( form1 && form1.value ) {
        var splt = form1.value.split(this.spliter);
        if ( splt[0] > 0 && splt[2] > 0 ) {
            var curdd = new Date( splt[0]-0, splt[1]-1, splt[2]-0 );
            curutc = curdd.getTime();                           // フォーム上の当日
        }
    }

    for ( var i=0; i<list.length; i++ ) {
        var dd = list[i];
        var ww = dd.getDay();
        var mm = dd.getMonth();
        if ( ww == 1 ) {
            src1 += "<tr>";                                     // 月曜日の前に行頭
        }
        var cc = days_td_style;
        if ( mon == mm ) {
            if ( ww == 0 ) {
                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+";";        // 前月末と翌月初の日付
        }
        var utc = dd.getTime();
        if (( min && min > utc ) || ( max && max < utc )) {
            cc += days_unselectable;
        }
        if ( utc == curutc ) {                                  // フォーム上の当日
            cc += "background: "+this.style.day_hover_bgcolor+";";
        }

        var ss = this.getDateYMD(dd);
        var tt = dd.getDate();
        src1 += '<td style="'+cc+'" title='+ss+' id="__'+this.eid+'_td_'+ss+'">'+tt+'</td>';
        if ( ww == 7 ) {
            src1 += "</tr>\n";                                  // 土曜日の後に行末
        }
    }
    src1 += "</table>\n";

    // カレンダーを書き換える
    var cal1 = this.getCalendarElement();
    if ( ! cal1 ) return;
    cal1.style.width = this.style.frame_width;
    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);
        src.style.background = __this.style.day_bgcolor;
    };
    var day_onclick = function (ev) {
        var src = get_src(ev);
        var srcday = src.id.substr(src.id.length-10);
        __this.setFormValue( srcday );
        __this.fadeOut( 1.0 );
    };

    // 前の月へボタン
    var tdprev = document.getElementById( "__"+this.eid+"_btn_prev" );
    tdprev.style.cursor = this.style.cursor;
    this.addEvent( tdprev, "mouseover", month_onmouseover );
    this.addEvent( tdprev, "mouseout", month_onmouseout );
    this.addEvent( tdprev, "click", function(){ __this.moveMonth( -1 ); });

    // 閉じるボタン
    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 );
    this.addEvent( tdclose, "click", function(){ __this.hide(); });

    // 次の月へボタン
    var tdnext = document.getElementById( "__"+this.eid+"_btn_next" );
    tdnext.style.cursor = this.style.cursor;
    this.addEvent( tdnext, "mouseover", month_onmouseover );
    this.addEvent( tdnext, "mouseout", month_onmouseout );
    this.addEvent( tdnext, "click", function(){ __this.moveMonth( +1 ); });

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

        var utc = dd.getTime();
        if ( min && min > utc ) continue;           // 昔過ぎる
        if ( max && max < utc ) continue;           // 未来過ぎる
        if ( utc == curutc ) continue;              // フォーム上の当日

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

        cc.style.cursor = this.style.cursor;
        this.addEvent( cc, "mouseover", day_onmouseover );
        this.addEvent( cc, "mouseout", day_onmouseout );
        this.addEvent( cc, "click", day_onclick );
    }

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

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

