var XWiki=(function(g){g.DateTimePicker=Class.create({timeStampClassNamePattern:/^t\d+$/,initialize:function(h,j){this.input=$(h);this.input.writeAttribute("autocomplete","off");var i=this._trigger.bindAsEventListener(this);this.input.observe("focus",i).observe("click",i);this.formatter=new Externals.SimpleDateFormat(j);this.timePickerEnabled=this._isTimePickerEnabled()},_isTimePickerEnabled:function(){var h=this.formatter.format(new Date(1876,1,1,23,59,0,0));return h.indexOf("23")>=0&&h.indexOf("59")>=0},_getDate:function(){if(!this.input._timestamp){var j=$w(this.input.className);this.input._timestamp=new Date().getTime();for(var h=0;h<j.length;h++){if(this.timeStampClassNamePattern.test(j[h])){this.input._timestamp=parseInt(j[h].substring(1))}}}return new Date(this.input._timestamp)},_trigger:function(h){if(!this.input.calendar_date_select&&!this.input.calendar_date_select_closing){new Externals.CalendarDateSelect(this.input,{time:this.timePickerEnabled,date:this._getDate(),clear_button:false,formatter:this,before_close:function(){this.calendar_date_select_closing=true;if(this.calendar_date_select.selection_made){h.element()._timestamp=this.calendar_date_select.selected_date.getTime()}},after_close:function(){this.calendar_date_select_closing=undefined}})}},format:function(h){return this.formatter.format(h)},parse:function(h){return new Date(h)}});function c(i){var j=$(i.getPropertyId("emptyIsToday"));if(j.type=="text"){j.type="checkbox";j.checked=j.value=="1";j.value="1";var h=j.up("dd");h.previous("dt").down("label").insert({top:j});h.remove();j.insert({after:new Element("input",{type:"hidden",value:"0",name:j.name})})}}function b(h){var i=$(h.getPropertyId("dateFormat"));if(i.type=="text"){}}function f(h){h.getViewer().select("input[type=text]").each(function(i){if(i.name.endsWith("_0_"+h.getName())){new g.DateTimePicker(i,$(h.getPropertyId("dateFormat")).value)}})}function e(h){return $("type-"+h.getName()).value=="Date"}function a(h){if(e(h)){c(h);b(h);f(h)}}function d(j,i){if(!j&&(typeof Externals=="undefined"||!Externals.SimpleDateFormat||!Externals.CalendarDateSelect)){i=i||0;if(i<3){typeof console!="undefined"&&console.warn&&console.warn("Cannot initialize DateTimePicker due to missing dependencies. Waiting a bit before trying again.");setTimeout(d.bind(this,j,i+1),100)}else{typeof console!="undefined"&&console.error&&console.error("Failed to initialize DateTimePicker due to missing dependencies: SimpleDateFormat and CalendarDateSelect.")}return}document.observe("xwiki:class:displayField",function(k){a(k.memo.field)});document.observe("xwiki:class:previewField",function(k){var l=k.memo.field;if(e(l)){f(l)}});var h=$("fields");if(h){h.childElements().each(function(k){var l=new g.FormField(k);if(l.getConfig()){a(l)}})}else{$("body").select("input.datetime").each(function(k){new g.DateTimePicker(k,k.title)})}return true}(g.domIsLoaded&&d())||document.observe("xwiki:dom:loaded",d);return g}(XWiki||{}));