/**
 * jCalendar 0.5
 * Some code based on jQuery Date Picker (http://kelvinluck.com/assets/jquery/datePicker/)
 * Copyright (c) 2007 Theodore Serbinski (http://tedserbinski.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 */
jQuery.jcalendar = function() { var months = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; var days = ['日', '月', '火', '水', '木', '金', '土']; var navLinks = {p:'前月', n:'次月', t:'t'}; var _firstDayOfWeek; var _firstDate; var _lastDate; var _selectedDate; var _drawCalendar = function(dateIn, a, day, month, year) { var today = new Date(); var d; if (dateIn == undefined) { d = new Date(today.getFullYear(), today.getMonth(), 1); year.val(today.getFullYear()); month.val(today.getMonth()+1); day.val(today.getDate());}
else { d = dateIn; d.setDate(1);}
if ((d.getMonth() < _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear()) || d.getFullYear() < _firstDate.getFullYear()) { d = new Date(_firstDate.getFullYear(), _firstDate.getMonth(), 1);}
else if ((d.getMonth() > _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear()) || d.getFullYear() > _lastDate.getFullYear()) { d = new Date(_lastDate.getFullYear(), _lastDate.getMonth(), 1);}
var firstMonth = true; var firstDate = _firstDate.getDate(); if (!(d.getMonth() == _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear())) { firstMonth = false; var lastMonth = d.getMonth() == 0 ? new Date(d.getFullYear()-1, 11, 1) : new Date(d.getFullYear(), d.getMonth()-1, 1); var prevLink = jQuery('<a href="" class="link-prev">&lsaquo;'+ navLinks.p +'</a>').click(function() { jQuery.jcalendar.changeMonth(lastMonth, this, day, month, year); return false;});}
var finalMonth = true; var lastDate = _lastDate.getDate(); if (!(d.getMonth() == _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear())) { finalMonth = false; var nextMonth = new Date(d.getFullYear(), d.getMonth()+1, 1); var nextLink = jQuery('<a href="" class="link-next">'+ navLinks.n +'&rsaquo;</a>').click(function() { jQuery.jcalendar.changeMonth(nextMonth, this, day, month, year); return false;});}
year.val(d.getFullYear()); month.val(d.getMonth()+1); var headRow = jQuery("<tr></tr>"); for (var i=_firstDayOfWeek; i<_firstDayOfWeek+7; i++) { var weekday = i%7; var wordday = days[weekday]; headRow.append('<th scope="col" abbr="'+ wordday +'" title="'+ wordday +'" class="'+ (weekday == 0 ? 'sunday' : (weekday == 6 ? 'saturday' : 'weekday')) +'">'+ wordday +'</th>');}
headRow = jQuery("<thead></thead>").append(headRow); var tBody = jQuery("<tbody></tbody>"); var lastDay = (new Date(d.getFullYear(), d.getMonth()+1, 0)).getDate(); var curDay = _firstDayOfWeek - d.getDay(); if (curDay > 0) curDay -= 7; var todayDate = today.getDate(); var thisMonth = d.getMonth() == today.getMonth() && d.getFullYear() == today.getFullYear(); do { var thisRow = jQuery("<tr></tr>"); for (var i=0; i<7; i++) { var weekday = (_firstDayOfWeek + i) % 7; var atts = {'class': (weekday == 0 ? 'sunday ' : (weekday == 6 ? 'saturday ' : 'weekday '))}; if (curDay < 0 || curDay >= lastDay) { dayStr = ' ';}
else if (firstMonth && curDay < firstDate-1) { dayStr = curDay+1; atts['class'] += 'inactive';}
else if (finalMonth && curDay > lastDate-1) { dayStr = curDay+1; atts['class'] += 'inactive';}
else { d.setDate(curDay+1); linkDay = "0" + (curDay+1); linkDay = linkDay.substring(linkDay.length-2,linkDay.length); linkMonth = "0" + (d.getMonth()+1); linkMonth = linkMonth.substring(linkMonth.length-2,linkMonth.length); linkDate = d.getFullYear() + linkMonth + linkDay; chk_diaryDate = 'blogDate.d'+linkDate; if(eval(chk_diaryDate)) { dayStrA = '<a href="/blog/'+ linkDate +'/">'+ (curDay+1) +'</a>';}else{ dayStrA = '<span>' + (curDay+1) + '</span>';}
dayStr = jQuery(dayStrA); if (day.val() == d.getDate() && !_selectedDate) { _selectedDate = dayStr; _selectedDate.addClass('selected');}
}
if (thisMonth && curDay+1 == todayDate) { atts['class'] += 'today';}
thisRow.append(jQuery("<td></td>").attr(atts).append(dayStr)); curDay++;}
tBody.append(thisRow);} while (curDay < lastDay); jQuery('div.jcalendar').html('<div class="jcalendar-links"></div><table cellspacing="1"></table>'); jQuery('div.jcalendar table').append(headRow, tBody); jQuery('div.jcalendar > div.jcalendar-links').append(prevLink,'　<span id="now_ym">' + year.val() + '年' + month.val() + '月</span>　', nextLink);}; return { show: function(a, day, month, year) { _firstDate = a._startDate; _lastDate = a._endDate; _firstDayOfWeek = a._firstDayOfWeek; var selected; if (year.val() > 0 && month.val() > 0 && day.val() > 0) { selected = new Date(year.val(), month.val()-1, day.val());}
else { selected = null;}
_drawCalendar(selected, a, day, month, year);}, changeMonth: function(d, e, day, month, year) { _drawCalendar(d, e, day, month, year);}, setLanguageStrings: function(aDays, aMonths, aNavLinks) { days = aDays; months = aMonths; navLinks = aNavLinks;}, setDateWindow: function(i, w, year) { if (w == undefined) w = {}; if (w.startDate == undefined) { i._startDate = new Date($(year).find('option:eq(1)').val(), 0, 1);}
else { dateParts = w.startDate.split('-'); i._startDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));}
if (w.endDate == undefined) { i._endDate = new Date($(year).find('option:last').val(), 11, 1);}
else { dateParts = w.endDate.split('-'); i._endDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));}
i._firstDayOfWeek = w.firstDayOfWeek == undefined ? 0 : w.firstDayOfWeek;}
};}(); jQuery.fn.jcalendar = function(a) { this.each(function() { var day = $(this).find('input.jcalendar-select-day'); var month = $(this).find('input.jcalendar-select-month'); var year = $(this).find('input.jcalendar-select-year'); $('div.jcalendar-selects').after('<div class="jcalendar"></div>'); jQuery.jcalendar.setDateWindow(this, a, year); jQuery.jcalendar.show(this, day, month, year);}); return this;}; $(document).ready(function() { $('#calender').jcalendar();}); 