/* vim:set ts=2 sw=2 sts=2 ai si nu et ft=javascript ff=dos:

  Last Change: 04-June-2009 09:40:03.
  Author: Technical team.
  Copyright: (C)Anchor Group K.K.

  URL: http://www.anchor-gr.jp/labo.html
  EMAIL: info@anchor-gr.jp

  Filename: smartcalendar.js
  Charset: utf-8

 ---------------------------------------------------------*/

var smartCalendarVersion = "0.0.2";

Date.prototype.reap = function() { var result = false; var year = this.getFullYear(); if ((year % 4)==0) { if ((year % 100)==0 && (year % 400)!=0) { result = false; }else{ result = true; } } return result; }; Date.prototype.length = function() { var result; switch(this.getMonth()+1) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: result = 31; break; case 2: result = (this.reap() ? 29 : 28); break; case 4: case 6: case 9: case 11: result = 30; break; } return result; }; Date.prototype.prevDate = function() { if (this.getDate() > 1) { this.setDate(this.getDate()-1); }else{ if (this.getMonth() > 1) { this.setMonth(this.getMonth()-1); }else{ this.setFullYear(this.getFullYear()-1); this.setMonth(11); } } }; Date.prototype.nextDate = function() { if (this.getDate() > this.length()) { if (this.getMonth() > 11) { this.setMonth(this.getMonth()+1); }else{ this.setFullYear(this.getFullYear()+1); this.setMonth(0); } }else{ this.setDate(this.getDate()+1); } }; Date.prototype.today = new Date(); Date.prototype.wday = new Array( "Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday"); Date.prototype.getWday = function() { return this.wday[this.getDay()]; }; Date.prototype.jwday = new Array( "日","月","火","水","木","金","土"); Date.prototype.getJWday = function() { return this.jwday[this.getDay()]; }; /* class smartCalendar */ function smartCalendar(year, month) { if (typeof year != "undefined"){ this.d = new Date(year, month-1); }else{ this.d = new Date(); } this.d.setDate(1); /* Methods */ this.make = smartCalendar_make; this.monthly = smartCalendar_monthly; this.display = smartCalendar_display; return this; }; function smartCalendar_monthly(swap) { var buf = new Array(); buf.push('<table class="' + this.prefix + 'table">'); buf.push('<tr><th colspan="7" class="' + this.prefix + 'th_Year">'); buf.push(this.d.getFullYear() + '年'); buf.push((this.d.getMonth()+1) + '月</th></tr>'); buf.push('<tr>'); for (var i=0; i<7; i++) { buf.push('<th class="' + this.prefix + 'th_' + this.d.wday[i] + '">'); buf.push(this.d.jwday[i] + '</th>'); } buf.push('</tr>'); if (this.d.getDay() > 0) { buf.push("<tr>"); for (var i=0; i<this.d.getDay(); i++) { buf.push("<td>　</td>"); } } var end_of_month = this.d.length(); var class_name = new Array(); var today_id = ""; var title = ""; for (var i=0; i<end_of_month; i++) { if (this.d.getFullYear() == this.d.today.getFullYear()) { if (this.d.getMonth() == this.d.today.getMonth()) { if (this.d.getDate() == this.d.today.getDate()) { today_id = ' id="' + this.prefix + 'td_Today" '; } } } class_name.push(this.prefix + 'td_' + this.d.getWday()); for (var v in swap) { var sp = swap[v].split(":"); if (String(this.d.getDate()) == sp[0]) { class_name.push(this.prefix + 'td_' + sp[1]); if ((typeof sp[2] != "undefined") && (sp[2] != "")) { title = ' title="' + sp[2] + '" '; } swap.slice(v,1); break; } } if (this.d.getDay() == 0) buf.push('<tr>'); buf.push('<td class="' + class_name.join(" ") + '"' + title + today_id + '>'); buf.push(this.d.getDate() + '</td>'); if (this.d.getDay() == 6) buf.push('</tr>'); if (this.d.getDate() < end_of_month) this.d.nextDate(); class_name = new Array(); title = ""; today_id = ""; } if (this.d.getDay() < 6) { for (var i=this.d.getDay(); i<6; i++) { buf.push("<td>　</td>"); } buf.push("</tr>"); } buf.push("</table>"); return buf.join(""); }; function smartCalendar_display(id) { document.getElementById(id).innerHTML = this.make(); }; function smartCalendar_make() { var buf = new Array(); for (var n=0; n<this.limit; n++) { var swap_space = this.swap; var swap = new Array(); var str = (String(this.d.getFullYear()) + '\/' + (this.d.getMonth()+1)); for (var k in swap_space) { var reg = new RegExp("^" + str + '\/([0-9]+\:.+)$'); if (swap_space[k].match(reg)) { swap.push(RegExp.$1); swap_space.slice(k,1); } } buf.push(this.monthly(swap)); this.d.nextDate(); } return buf.join(""); }; smartCalendar.prototype.prefix = "Calendar_"; smartCalendar.prototype.limit = 1; smartCalendar.prototype.swap = new Array();

