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