(function(){var k={},n=/'/g,l=zul.db.Datebox=zk.$extends(zul.inp.FormatWidget,{_buttonVisible:!0,_lenient:!0,_strictDate:!1,_selectLevel:"day",_closePopupOnTimezoneChange:!0,$init:function(){this.$supers("$init",arguments);this.afterInit(this.$class._initPopup);this.listen({onChange:this},-1E3)},$define:{buttonVisible:function(a){zul.inp.RoundUtl.buttonVisible(this,a)},format:function(){this._pop&&(this._pop.setFormat(this._format),this._value&&(this._value=this._pop.getTime()));var a=this.getInputNode();
a&&(a.value=this.getText())},constraint:function(a){"string"==typeof a&&"["!=a.charAt(0)?this._cst=new zul.inp.SimpleDateConstraint(a,this):this._cst=a;this._cst&&(this._reVald=!0);this._pop&&(this._pop.setConstraint(this._constraint),this._pop.rerender())},timeZone:function(a){this._timezone=a;this._tm.setTimezone(a);this._setTimeZonesIndex();this._value&&this._value.tz(a);this._pop&&this._pop._fixConstraint();(a=this._cst)&&a instanceof zul.inp.SimpleConstraint&&a.reparseConstraint()},timeZonesReadonly:function(a){var b=
this.$n("dtzones");b&&(b.disabled=a?"disabled":"")},displayedTimeZones:function(a){this._dtzones=a?a.split(","):null},unformater:function(a){eval("Datebox._unformater = "+a)},lenient:null,localizedSymbols:[function(a){return a?(k[a[0]]||(k[a[0]]=a[1]),k[a[0]]):a},function(){this._tm&&(this._tm._localizedSymbols=this._localizedSymbols);this._pop&&this._pop.setLocalizedSymbols(this._localizedSymbols)}],weekOfYear:function(a){this._pop&&this._pop.setWeekOfYear(a)},showTodayLink:function(a){this._pop&&
this._pop.setShowTodayLink(a)},todayLinkLabel:function(a){this._pop&&this._pop.setTodayLinkLabel(a)},strictDate:null,defaultDateTime:null,selectLevel:null,closePopupOnTimezoneChange:null},getIconSclass:function(){return"z-icon-calendar"},inRoundedMold:function(){return!0},_setTimeZonesIndex:function(){var a=this.$n("dtzones");if(a&&this._timezone)for(var b=jq(a).children("option"),c=b.length;c--;)b[c].text==this._timezone&&(a.selectedIndex=c)},onSize:function(){this.isOpen()&&this.$class._reposition(this,
!0)},getTimeFormat:function(){var a=this._format,b=a.indexOf("a"),c=a.indexOf("h"),d=a.indexOf("K"),e=a.indexOf("H"),g=a.indexOf("k"),f=a.indexOf("m");a=a.indexOf("s");f=-1<f?"mm":"";a=-1<a?"ss":"";return(-1<b||c)&&(-1<c||-1<d)?(e=this.$class._prepareTimeFormat(c<d?"KK":"hh",f,a),-1==b?e:-1!=c&&b<c||-1!=d&&b<d?"a "+e:e+" a"):this.$class._prepareTimeFormat(e<g?"kk":-1<e?"HH":"",f,a)},getDateFormat:function(){return this._format.replace(/[(s.S{1,3})ahKHksm]*:?/g,"").trim()},setOpen:function(a,b){if(this.isRealVisible()){var c;
if(c=this._pop)a?c.open(!b):c.close(!b)}},isOpen:function(){return this._pop&&this._pop.isOpen()},setValue:function(a,b){var c=this.getTimeZone();c&&a&&a.tz(c);this.$supers("setValue",arguments)},coerceFromString_:function(a,b){var c=l._unformater,d=this.getTimeZone();if(c&&jq.isFunction(c)&&(c=c(a)))return this._shortcut=a,c;if(a){var e=this._refDate||this._value;c=this.getFormat();a=(new zk.fmt.Calendar).parseDate(a,b||c,!this._lenient,e,this._localizedSymbols,d,this._strictDate);this._refDate=
null;if(!a)return{error:zk.fmt.Text.format(msgzul.DATE_REQUIRED+this.localizedFormat.replace(n,""))};c.match(/[HkKh]/)||(a=(new zk.fmt.Calendar).escapeDSTConflict(a,d));return a}return null},coerceToString_:function(a,b){return a?(new zk.fmt.Calendar).formatDate(a,b||this.getFormat(),this._localizedSymbols):""},doClick_:function(a){this._disabled||(this._readonly&&this._buttonVisible&&this._pop&&!this._pop.isOpen()&&this._pop.open(),this.$supers("doClick_",arguments))},doKeyDown_:function(a){this._doKeyDown(a);
a.stopped||this.$supers("doKeyDown_",arguments)},_doKeyDown:function(a){if(!jq.nodeName(a.domTarget,"option","select")){var b=a.keyCode,c=this._pop.isOpen();!a.shiftKey&&9==b&&a.domTarget==this.$n("real")&&c?(this._pop.focus(),a.stop()):(9==b||zk.webkit&&0==b)&&a.target!=this._tm?c&&this._pop.close():!a.altKey||38!=b&&40!=b?!c||13!=b&&27!=b&&32!=b?18==b||27==b||13==b||112<=b&&123>=b||this._pop.isOpen()&&this._pop.doKeyDown_(a):13==b?this.enterPressed_(a):27==b&&this.escPressed_(a):(c?this._pop.close():
this._pop.open(),b={propagation:!0},11>zk.ie&&(b.dom=!0),a.stop(b))}},enterPressed_:function(a){this._pop.close();this.updateChange_();a.stop()},escPressed_:function(a){this._pop.close();a.stop()},afterKeyDown_:function(a,b){!b&&this._inplace&&jq(this.$n()).toggleClass(this.getInplaceCSS(),13==a.keyCode?null:!1);return this.$supers("afterKeyDown_",arguments)},bind_:function(){this.$supers(l,"bind_",arguments);var a;if(a=this.$n("btn"))this.domListen_(a,zk.android?"onTouchstart":"onClick","_doBtnClick"),
this._inplace&&this.domListen_(a,"onMouseDown","_doBtnMouseDown");zWatch.listen({onSize:this,onScroll:this,onShow:this});this._pop.setFormat(this.getDateFormat())},unbind_:function(){var a;(a=this._pop)&&a.close(!0);if(a=this.$n("btn"))this.domUnlisten_(a,zk.android?"onTouchstart":"onClick","_doBtnClick"),this._inplace&&this.domUnlisten_(a,"onMouseDown","_doBtnMouseDown");zWatch.unlisten({onSize:this,onScroll:this,onShow:this});this.$supers(l,"unbind_",arguments)},_doBtnClick:function(a){this._inplaceIgnore=
!1;this._buttonVisible&&(this._disabled||this.setOpen(!jq(this.$n("pp")).zk.isVisible(),zul.db.DateboxCtrl.isPreservedFocus(this)),a.stop(this._pop&&this._pop._open?{propagation:1}:null))},_doBtnMouseDown:function(){this._inplaceIgnore=!0},_doTimeZoneChange:function(a){a=this.$n("dtzones").value;this.updateChange_();this.fire("onTimeZoneChange",{timezone:a},{toServer:!0},150);this._pop&&this._closePopupOnTimezoneChange&&this._pop.close()},onChange:function(a){a=a.data;var b=this.getInputNode().value;
this._pop&&this._pop.setValue(a.value);!a.value&&b&&this.getFormat()&&"[c"==this._cst&&(a.value=b)},onScroll:function(a){if(this.isOpen()){var b=this._pop;a&&b&&(this.getInputNode()&&zul.inp.InputWidget._isInView(this)?this.$class._reposition(this,!0):b.close())}},onShow:function(){this.__ebox&&(this.setFloating_(!0),this.__ebox.show())},getTimeZoneLabel:function(){return""},redrawpp_:function(a){a.push('<div id="',this.uuid,'-pp" class="',this.$s("popup"),'" style="display:none" role="dialog" aria-labelledby="',
this._pop.uuid,'-title">');for(var b=this.firstChild;b;b=b.nextSibling)b.redraw(a);this._redrawTimezone(a);a.push("</div>")},_redrawTimezone:function(a){var b=this._dtzones;if(b){a.push('<div class="',this.$s("timezone"),'">',this.getTimeZoneLabel(),'<select id="',this.uuid,'-dtzones">');for(var c=0,d=b.length;c<d;c++)a.push('<option value="',b[c],'">',b[c],"</option>");a.push("</select></div>")}},updateChange_:function(){this.isOpen()||this.$supers("updateChange_",arguments)}},{_initPopup:function(){this._pop=
new zul.db.CalendarPop;this._tm=new zul.db.CalendarTime;this.appendChild(this._pop);this.appendChild(this._tm)},_reposition:function(a,b){if(a.$n()){var c=a.$n("pp"),d=a.$n(),e=a.getInputNode();c&&(zk(c).position(d,a.position,{dodgeRef:d}),a._pop.syncShadow(),b||zk(e).focus())}},_prepareTimeFormat:function(a,b,c){var d=[];a&&d.push(a);b&&d.push(b);c&&d.push(c);return d.join(":")}}),m=zul.db.CalendarPop=zk.$extends(zul.db.Calendar,{$init:function(){this.$supers("$init",arguments);this.listen({onChange:this},
-1E3)},setFormat:function(a){this._fmt=a},setLocalizedSymbols:function(a){this._localizedSymbols=a},rerender:function(){this.$supers("rerender",arguments);this.desktop&&this.syncShadow()},close:function(a){var b=this.parent,c=b.$n("pp");if(c&&zk(c).isVisible()){b._inplace&&(b._inplaceIgnore=!1,b._inplaceTimerId=setTimeout(function(){b.desktop&&jq(b.$n()).addClass(b.getInplaceCSS())},b._inplaceTimeout));try{if((zk.ff||zk.safari)&&zk.currentFocus){var d=zk.currentFocus.getInputNode?zk.currentFocus.getInputNode():
zk.currentFocus.$n();jq.nodeName(d,"input")&&jq.isAncestor(c,d)&&jq(d).blur()}}catch(e){zk.debugLog(e.message||e)}this._shadow&&(this._shadow.destroy(),this._shadow=null);c.style.display="none";c.className=b.$s("popup");jq(c).zk.undoVParent();b.setFloating_(!1);a?b.updateChange_():zul.db.DateboxCtrl.isPreservedFocus(this)&&zk(b.getInputNode()).focus();a=b.$s("open");jq(b.$n()).removeClass(a);jq(c).removeClass(a)}},isOpen:function(){return zk(this.parent.$n("pp")).isVisible()},open:function(a){var b=
this.parent,c=b.$n(),d=b.$n("pp");if(c&&d){b._inplace&&(b._inplaceIgnore=!0);b.setFloating_(!0,{node:d});zWatch.fire("onFloatUp",b);var e=this.setTopmost();this._setView(b._selectLevel);var g=b.getZclass();d.className=c.className+" "+d.className;jq(d).removeClass(g);d.style.width="auto";d.style.display="block";d.style.zIndex=0<e?e:1;this.setDomVisible_(d,!0,{visibility:!0});jq(d).zk.makeVParent();d.offsetWidth<c.offsetWidth?d.style.width=c.offsetWidth+"px":(e=jq.innerWidth()-20,e<c.offsetWidth&&(e=
c.offsetWidth),d.offsetWidth>e&&(d.style.width=e));delete b._shortcut;c=b.getTimeFormat();e=b.getTimeZone();(g=b._value||b._defaultDateTime||zUtl.today(c,e))&&this.setValue(g);if(c){var f=b._tm;f.setVisible(!0);f.setFormat(c);f.setValue(g||Dates.newInstance().tz(e));f.onSize()}else b._tm.setVisible(!1);c=b.$s("open");jq(b.$n()).addClass(c);jq(d).addClass(c);b.$class._reposition(b,a)}},syncShadow:function(){this._shadow||(this._shadow=new zk.eff.Shadow(this.parent.$n("pp"),{left:-4,right:4,top:2,bottom:3}));
this._shadow.sync()},onChange:function(a){var b=this.getTime(),c=this.parent,d=c.getTimeFormat(),e=c.getValue(),g=c.getTimeZone(),f=new zk.fmt.Calendar;if(d){var h=c._tm.getValue();d.match(/[HK]/i)&&b.setHours(h.getHours());d.match(/[m]/)&&b.setMinutes(h.getMinutes());d.match(/[s]/)&&b.setSeconds(h.getSeconds());d.match(/[S]/)&&b.setMilliseconds(h.getMilliseconds());d.match(/[HkKh]/)||(b=f.escapeDSTConflict(b,g))}else e&&(b=Dates.newInstance([b.getFullYear(),b.getMonth(),b.getDate(),e.getHours(),
e.getMinutes(),e.getSeconds(),e.getMilliseconds()],g),this.getFormat().match(/[HkKh]/)||(b=f.escapeDSTConflict(b,g)));a.data.shiftView||(c.getInputNode().value=c.coerceToString_(b));this._view==c._selectLevel&&!1!==a.data.shallClose&&(this.close(),a.data.value=b,this.$class._equalDate(b,e)||(c._refDate=b,c.updateChange_()));a.stop()},onFloatUp:function(a){this.isOpen()&&(zUtl.isAncestor(this.parent,a.origin)||this.close(!0))},bind_:function(){this.$supers(m,"bind_",arguments);this._bindTimezoneEvt();
zWatch.listen({onFloatUp:this})},unbind_:function(){zWatch.unlisten({onFloatUp:this});this._unbindfTimezoneEvt();this._shadow&&(this._shadow.destroy(),this._shadow=null);this.$supers(m,"unbind_",arguments)},_bindTimezoneEvt:function(){var a=this.parent,b=a.$n("dtzones");b&&(b.disabled=a.isTimeZonesReadonly()?"disable":"",a.domListen_(b,"onChange","_doTimeZoneChange"),a._setTimeZonesIndex())},_unbindfTimezoneEvt:function(){var a=this.parent,b=a.$n("dtzones");b&&a.domUnlisten_(b,"onChange","_doTimeZoneChange")},
_setView:function(a,b){this.parent.getTimeFormat()&&this.parent._tm.setVisible("day"==a);this.$supers("_setView",arguments);9<zk.ie&&this.syncShadow();zk.ie9_&&b&&zk(this.parent.$n("pp")).redoCSS(500)},doKeyDown_:function(a){this.$supers("doKeyDown_",arguments);27==a.keyCode&&this.parent.escPressed_(a)},animationSpeed_:function(){return zk(this.parent).getAnimationSpeed("_default")},_chooseDate:function(a,b){var c=this.parent._selectLevel;if(a&&!jq(a).hasClass(this.$s("disabled"))){var d=this.getTime();
switch(this._view){case "day":c=this.getTime();this._setTime(null,null!=a._monofs&&0!=a._monofs?d.getMonth()+a._monofs:null,b,!0);a=this.getTime();c.getYear()==a.getYear()&&c.getMonth()==a.getMonth()?this._markCal({sameMonth:!0}):(this.rerender(-1),this.focus());break;case "month":if("month"==c){this._setTime(null,b,1,!0);break}this._setTime(null,b);this._setView("day");break;case "year":if("year"==c){this._setTime(b,0,1,!0);break}this._setTime(b);this._setView("month");break;case "decade":this._setTime(b),
this._setView("year")}}}},{_equalDate:function(a,b){return a==b||a&&b&&a.getTime()==b.getTime()}});zul.db.CalendarTime=zk.$extends(zul.db.Timebox,{$init:function(){this.$supers("$init",arguments);this.listen({onChanging:this},-1E3)},onChanging:function(a){var b=this.parent,c=b.getValue()||b._pop.getValue();c=b.coerceToString_(c,"yyyy/MM/dd ")+a.data.value;var d="yyyy/MM/dd "+b.getTimeFormat();c+=-1<d.indexOf("a")?0>c.indexOf("AM")&&0>c.indexOf("PM")?"AM":"":"";c=b.coerceFromString_(c,d);c instanceof
DateImpl&&(b.getInputNode().value=a.data.value=b.coerceToString_(c),b.fire(a.name,a.data));this._view==b._selectLevel&&!1!==a.data.shallClose&&this.close();a.stop()}});zul.db.DateboxCtrl={isPreservedFocus:function(a){return!0}}})();
