');
+ $table.append($tr);
+ }
+
+ var $td = $('');
+ $td.data("day", realDay);
+
+ $tr.append($td);
+
+ if (firstWday > i) {/* Before months day */
+ $td.text(beforeMonthLastDay + realDay);
+ $td.addClass('day_another_month');
+ $td.data("dateStr", dateBeforeMonth.getYear() + 1900 + "/" + (dateBeforeMonth.getMonth() + 1) + "/" + (beforeMonthLastDay + realDay));
+ } else if (i < firstWday + lastDay) {/* Now months day */
+ $td.text(realDay);
+ $td.data("dateStr", (date.getYear() + 1900) + "/" + (date.getMonth() + 1) + "/" + realDay);
+ } else {/* Next months day */
+ $td.text(realDay - lastDay);
+ $td.addClass('day_another_month');
+ $td.data("dateStr", dateNextMonth.getYear() + 1900 + "/" + (dateNextMonth.getMonth() + 1) + "/" + (realDay - lastDay));
+ }
+
+ if (i % 7 == 0) {/* Sunday */
+ $td.addClass('wday_sun');
+ } else if (i % 7 == 6) {/* Saturday */
+ $td.addClass('wday_sat');
+ }
+
+ if (realDay == date.getDate()) {/* selected day */
+ $td.addClass('active');
+ }
+
+ if (date.getMonth() == todayDate.getMonth() && realDay == todayDate.getDate()) {/* today */
+ $td.addClass('today');
+ }
+
+ /* Set event-handler to day cell */
+
+ $td.click(function() {
+ if ($(this).hasClass('hover')) {
+ $(this).removeClass('hover');
+ }
+ $(this).addClass('active');
+
+ var $picker = getParentPickerObject($(this));
+ var targetDate = new Date($(this).data("dateStr"));
+ var selectedDate = getPickedDate($picker);
+ draw($picker, {
+ "isAnim": false,
+ "isOutputToInputObject": true
+ }, targetDate.getYear() + 1900, targetDate.getMonth(), targetDate.getDate(), selectedDate.getHours(), selectedDate.getMinutes());
+ });
+
+ $td.hover(function() {
+ if (! $(this).hasClass('active')) {
+ $(this).addClass('hover');
+ }
+ }, function() {
+ if ($(this).hasClass('hover')) {
+ $(this).removeClass('hover');
+ }
+ });
+ }
+
+ /* Timelist ----- */
+ $timelist.children().remove();
+
+ /* Set height to Timelist (Calendar innerHeight - Calendar padding) */
+ $timelist.css("height", $calendar.innerHeight() - 10 + 'px');
+
+ /* Output time cells */
+ for (var hour = 0; hour < 24; hour++) {
+ for (var min = 0; min <= 30; min += 30) {
+ var $o = $('');
+ $o.addClass('timelist_item');
+ $o.text(zpadding(hour) + ":" + zpadding(min));
+
+ $o.data("hour", hour);
+ $o.data("min", min);
+
+ $timelist.append($o);
+
+ if (hour == date.getHours() && min == date.getMinutes()) {/* selected time */
+ $o.addClass('active');
+ timelist_activeTimeCell_offsetTop = $o.offset().top;
+ }
+
+ /* Set event handler to time cell */
+
+ $o.click(function() {
+ if ($(this).hasClass('hover')) {
+ $(this).removeClass('hover');
+ }
+ $(this).addClass('active');
+
+ var $picker = getParentPickerObject($(this));
+ var date = getPickedDate($picker);
+ var hour = $(this).data("hour");
+ var min = $(this).data("min");
+ draw($picker, {
+ "isAnim": false,
+ "isOutputToInputObject": true
+ }, date.getYear() + 1900, date.getMonth(), date.getDate(), hour, min);
+ });
+
+ $o.hover(function() {
+ if (! $(this).hasClass('active')) {
+ $(this).addClass('hover');
+ }
+ }, function() {
+ if ($(this).hasClass('hover')) {
+ $(this).removeClass('hover');
+ }
+ });
+ }
+ }
+
+ /* Scroll the timelist */
+ if(isScroll == true){
+ /* Scroll to new active time-cell position */
+ $timelist.scrollTop(timelist_activeTimeCell_offsetTop - $timelist.offset().top);
+ }else{
+ /* Scroll to position that before redraw. */
+ $timelist.scrollTop(drawBefore_timeList_scrollTop);
+ }
+
+ /* Fade-in animation */
+ if (isAnim == true) {
+ if(changePoint == "calendar"){
+ $calendar.fadeTo("fast", 1.0);
+ }else if(changePoint == "timelist"){
+ $timelist.fadeTo("fast", 1.0);
+ }
+ }
+
+ /* Output to InputForm */
+ if (isOutputToInputObject == true) {
+ outputToInputObject($picker);
+ }
+ };
+
+ var init = function($obj, opt) {
+ /* Container */
+ var $picker = $(' ');
+ $picker.addClass('datepicker')
+ $obj.append($picker);
+
+ /* Set options data to container object */
+ if (opt.inputObjectId != null) {
+ $picker.data("inputObjectId", opt.inputObjectId);
+ }
+ $picker.data("pickerId", PickerObjects.length);
+ $picker.data("dateFormat", opt.dateFormat);
+ $picker.data("locale", opt.locale);
+ $picker.data("animation", opt.animation);
+
+ /* Header */
+ var $header = $(' ');
+ $header.addClass('datepicker_header');
+ $picker.append($header);
+ /* InnerContainer*/
+ var $inner = $(' ');
+ $inner.addClass('datepicker_inner_container');
+ $picker.append($inner);
+ /* Calendar */
+ var $calendar = $(' ');
+ $calendar.addClass('datepicker_calendar');
+ var $table = $(' ');
+ $table.addClass('datepicker_table');
+ $calendar.append($table);
+ $inner.append($calendar);
+ /* Timelist */
+ var $timelist = $('');
+ $timelist.addClass('datepicker_timelist');
+ $inner.append($timelist);
+
+ /* Set event handler to picker */
+ $picker.hover(
+ function(){
+ ActivePickerId = $(this).data("pickerId");
+ },
+ function(){
+ ActivePickerId = -1;
+ }
+ );
+
+ PickerObjects.push($picker);
+
+ draw_date($picker, {
+ "isAnim": true,
+ "isOutputToInputObject": true
+ }, opt.current);
+ };
+
+ /**
+ * Initialize dtpicker
+ */
+ $.fn.dtpicker = function(config) {
+ var date = new Date();
+ var defaults = {
+ "inputObjectId": undefined,
+ "current": date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes(),
+ "dateFormat": "default",
+ "locale": "en",
+ "animation": true
+ };
+
+ var options = $.extend(defaults, config);
+ options.current = getDate(options.current);
+ return this.each(function(i) {
+ init($(this), options);
+ });
+ };
+
+ /**
+ * Initialize dtpicker, append to Text input field
+ * */
+ $.fn.appendDtpicker = function(config) {
+ var date = new Date();
+ var defaults = {
+ "inline": false,
+ "current": date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes(),
+ "dateFormat": "default",
+ "locale": "en",
+ "animation": true
+ }
+ var options = $.extend(defaults, config);
+ return this.each(function(i) {
+
+ /* Add input-field with inputsObjects array */
+ var input = this;
+ var inputObjectId = InputObjects.length;
+ InputObjects.push(input);
+
+ options.inputObjectId = inputObjectId;
+
+ /* Current date */
+ var date, strDate, strTime;
+ if($(input).val() != null && $(input).val() != ""){
+ options.current = $(input).val();
+ }
+
+ /* Make parent-div for picker */
+ var $d = $(' ');
+ if(options.inline == false){
+ /* float mode */
+ $d.css("position","absolute");
+ }
+ $d.insertAfter(input);
+
+ /* Initialize picker */
+
+ var pickerId = PickerObjects.length;
+
+ var $picker_parent = $($d).dtpicker(options); // call dtpicker() method
+
+ var $picker = $picker_parent.children('.datepicker');
+
+ /* Link input-field with picker*/
+ $(input).data('pickerId', pickerId);
+
+ /* Set event handler to input-field */
+
+ $(input).keyup(function() {
+ var $input = $(this);
+ var $picker = $(PickerObjects[$input.data('pickerId')]);
+ if ($input.val() != null && (
+ $input.data('beforeVal') == null ||
+ ( $input.data('beforeVal') != null && $input.data('beforeVal') != $input.val()) )
+ ) { /* beforeValue == null || beforeValue != nowValue */
+ var date = getDate($input.val());
+ if (isNaN(date.getDate()) == false) {/* Valid format... */
+ draw_date($picker, {
+ "isAnim":true,
+ "isOutputToInputObject":false
+ }, date);
+ }
+ }
+ $input.data('beforeVal',$input.val())
+ });
+
+ $(input).change(function(){
+ $(this).trigger('keyup');
+ });
+
+ if(options.inline == true){
+ /* inline mode */
+ $picker.data('isInline',true);
+ }else{
+ /* float mode */
+ $picker.data('isInline',false);
+ $picker_parent.css({
+ "zIndex": 100
+ });
+ $picker.css("width","auto");
+
+ /* Hide this picker */
+ $picker.hide();
+
+ /* Set onClick event handler for input-field */
+ $(input).click(function(){
+ var $input = $(this);
+ var $picker = $(PickerObjects[$input.data('pickerId')]);
+ ActivePickerId = $input.data('pickerId');
+ $picker.show();
+ $picker.parent().css("top", $input.offset().top + $input.outerHeight() + 2 + "px");
+ $picker.parent().css("left", $input.offset().left + "px");
+ });
+ }
+ });
+};
+
+/* Set event handler to Body element, for hide a floated-picker */
+$(function(){
+ $('body').click(function(){
+ for(var i=0;i |