(function(){var q={},p=zul.db.Timebox=zk.$extends(zul.inp.FormatWidget,{_buttonVisible:!0,_format:"HH:mm",_timezoneAbbr:"",$init:function(){this.$supers("$init",arguments);this.$class._updFormat(this,this._format)},$define:{timezoneAbbr:function(a){this.$class._updFormat(this,this._format)},timeZone:function(a){this._value&&this._value.tz(a)},buttonVisible:function(a){zul.inp.RoundUtl.buttonVisible(this,a)},unformater:function(a){eval("Timebox._unformater = "+a)},localizedSymbols:[function(a){return a?
(q[a[0]]||(q[a[0]]=a[1]),q[a[0]]):a}],constraint:function(a){"string"==typeof a&&"["!=a.charAt(0)?this._cst=new zul.inp.SimpleLocalTimeConstraint(a,this):this._cst=a;this._cst&&(this._reVald=!0);this._pop&&(this._pop.setConstraint(this._constraint),this._pop.rerender())}},setTimezone:function(a){this.setTimeZone(a)},getTimezone:function(){return this._timeZone},inRoundedMold:function(){return!0},setFormat:function(a){a=a?a.replace(/'/g,""):a;this.$class._updFormat(this,a);this.$supers("setFormat",
arguments)},setValue:function(a,b){var c=this.getTimeZone();c&&a&&a.tz(c);b&&null===a&&(this._changed=!1);this.$supers("setValue",arguments)},coerceToString_:function(a){if(!this._changed&&!a&&arguments.length)return"";for(var b="",c,e,d,f=0,g=this._fmthdler,h=g.length;f<h;f++)c=g[f],e=c.format(a),b+=e,c.type&&!1!==(d=c.isSingleLength())&&(d+=e.length-1)&&c._doShift(this,d);return b},coerceFromString_:function(a){var b=p._unformater,c=this.getTimeZone();if(b&&jq.isFunction(b)&&(b=b(a)))return this._shortcut=
a,b;if(!a)return null;c=this._value?Dates.newInstance(this._value):zUtl.today(this._format,c);b=[];var e=[],d=0;c.setSeconds(0);c.setMilliseconds(0);for(var f=0,g=this._fmthdler,h=g.length;f<h;f++){var k=g[f];if(3==k.type){var l=!0;var m=k.unformat(c,a,{});k.getText(a).trim().length||d++}else if(k.type){var n=f+1<h&&this.$class._shouldObeyCount(g[f+1].type);b.push(k);e.push(n);k.parse(a,{obeyCount:n});k.getText(a).trim().length||d++}}if(b.length==(l?--d:d))this._changed=!1;else{f=0;for(h=b.length;f<
h;f++)l||6!=b[f].type&&7!=b[f].type||(m=!0),c=b[f].unformat(c,a,{am:m,obeyCount:e[f]});return c}},onSize:function(){var a=this.getInputNode();a&&this._value&&!a.value&&(a.value=this.coerceToString_(this._value))},onHide:zul.inp.Textbox.onHide,validate:zul.inp.Intbox.validate,doClick_:function(a){a.domTarget==this.getInputNode()&&this._doCheckPos();this.$supers("doClick_",arguments)},doKeyPress_:function(a){zk.opera&&9!=a.keyCode?a.stop():this.$supers("doKeyPress_",arguments)},_doBeforeInput:function(a){var b=
this.getInputNode();b.disabled||b.readOnly||p._unformater||(b=a.domEvent.originalEvent.data,/\d/.test(b)&&(this._doType(parseInt(b)),a.stop()))},doKeyDown_:function(a){var b=this.getInputNode();if(!b.disabled&&!b.readOnly){if(!p._unformater){var c=a.keyCode;switch(c){case 48:case 96:case 49:case 97:case 50:case 98:case 51:case 99:case 52:case 100:case 53:case 101:case 54:case 102:case 55:case 103:case 56:case 104:case 57:case 105:this._doType(c-(96<=c?96:48));a.stop();return;case 35:this.lastPos=
b.value.length;return;case 36:this.lastPos=0;return;case 37:0<this.lastPos&&this.lastPos--;return;case 39:this.lastPos<b.value.length&&this.lastPos++;return;case 38:this._doUp();a.stop();return;case 40:this._doDown();a.stop();return;case 46:this._doDel();a.stop();return;case 8:this._doBack();a.stop();return;case 9:break;case 13:case 27:break;case 86:if(9>=zk.ie&&a.ctrlKey){this._updateChanged();break}default:112<=c&&123>=c||a.ctrlKey||a.metaKey||a.altKey||a.shiftKey&&45==c||a.stop()}}this.$supers("doKeyDown_",
arguments)}},doPaste_:function(a){this._updateChanged();this.$supers("doPaste_",arguments)},_updateChanged:function(){var a=this,b=this.getInputNode().value;setTimeout(function(){var c=a.getInputNode();c&&b!=c.value&&(a._changed=!0)},0)},_ondropbtnup:function(a){this.domUnlisten_(document.body,"onZMouseup","_ondropbtnup");this._stopAutoIncProc();this._currentbtn=null},_btnDown:function(a){if(this._buttonVisible&&!this._disabled){this._lastPos=this._getPos();var b=this.$n("btn"),c=this.getInputNode();
zk.dragging||(this._currentbtn&&this._ondropbtnup(a),this.domListen_(document.body,"onZMouseup","_ondropbtnup"),this._currentbtn=b);c.value&&p._unformater&&(c.value=this.coerceToString_(this.coerceFromString_(c.value)));c.value||(c.value=this.coerceToString_());var e=zk(b).revisedOffset();b=a.pageY-e[1]<b.offsetHeight/2;zk.webkit&&zk(c).focus();e=this._getPos();this._lastPos!=e&&zk(c).setSelectionRange(this._lastPos);b?(this._doUp(),this._startAutoIncProc(!0)):(this._doDown(),this._startAutoIncProc(!1));
this._changed=!0;delete this._shortcut;zk.Widget.mimicMouseDown_(this);zk(c).focus();a.stop()}},_btnUp:function(a){!this._buttonVisible||this._disabled||zk.dragging||(zk.opera&&zk(this.getInputNode()).focus(),this._onChanging(),this._stopAutoIncProc(),(11>zk.ie||zk.webkit)&&this._lastPos&&zk(this.getInputNode()).setSelectionRange(this._lastPos,this._lastPos))},_getPos:function(){return zk(this.getInputNode()).getSelectionRange()[0]},_doCheckPos:function(){this.lastPos=this._getPos()},_doUp:function(){this._changed=
!0;this.getTimeHandler().increase(this,1);this._onChanging()},_doDown:function(){this._changed=!0;this.getTimeHandler().increase(this,-1);this._onChanging()},_doBack:function(){this._changed=!0;this.getTimeHandler().deleteTime(this,!0)},_doDel:function(){this._changed=!0;this.getTimeHandler().deleteTime(this,!1)},_doType:function(a){this._changed=!0;this.getTimeHandler().addTime(this,a)},getTimeHandler:function(){var a=zk(this.getInputNode()).getSelectionRange(),b=a[0];a=a[1];for(var c,e=0,d=this._fmthdler,
f=d.length;e<f;e++)if(d[e].type&&d[e].index[0]<=b&&(c=d[e],d[e].index[1]+1>=a))return d[e];return c||this._fmthdler[0]},getNextTimeHandler:function(a){var b=this._fmthdler;a=b.$indexOf(a);for(var c;(c=b[++a])&&(!c.type||3==c.type););return c},_startAutoIncProc:function(a){this.timerId&&clearInterval(this.timerId);var b=this,c=a?"_doUp":"_doDown";this.timerId=setInterval(function(){(11>zk.ie||zk.webkit)&&b._lastPos&&zk(b.getInputNode()).setSelectionRange(b._lastPos,b._lastPos);b[c]()},300);jq(this.$n("btn-"+
(a?"up":"down"))).addClass(this.$s("active"))},_stopAutoIncProc:function(){this.timerId&&clearTimeout(this.timerId);this.currentStep=this.defaultStep;this.timerId=null;jq("."+this.$s("icon"),this.$n("btn")).removeClass(this.$s("active"))},doFocus_:function(a){this.$supers("doFocus_",arguments);var b=this.getInputNode(),c=zk(b).getSelectionRange();b.value||(b.value=p._unformater?"":this.coerceToString_());this._doCheckPos();c[0]!==c[1]&&(zk(b).setSelectionRange(c[0],c[1]),this.lastPos=c[1]);zul.inp.RoundUtl.doFocus_(this)},
doBlur_:function(a){this._value||this._changed||p._unformater||(this.getInputNode().value=this._defRawVal="");this.$supers("doBlur_",arguments);zul.inp.RoundUtl.doBlur_(this)},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(zul.db.Timebox,"bind_",arguments);var a;zk.android&&zk.chrome&&this.domListen_(this.getInputNode(),"onBeforeInput","_doBeforeInput");
(a=this.$n("btn"))&&this.domListen_(a,"onZMouseDown","_btnDown").domListen_(a,"onZMouseUp","_btnUp");zWatch.listen({onSize:this})},unbind_:function(){this.timerId&&(clearTimeout(this.timerId),this.timerId=null);zWatch.unlisten({onSize:this});var a=this.$n("btn");a&&this.domUnlisten_(a,"onZMouseDown","_btnDown").domUnlisten_(a,"onZMouseUp","_btnUp");zk.android&&zk.chrome&&this.domUnlisten_(this.getInputNode(),"onBeforeInput","_doBeforeInput");this._changed=!1;this.$supers(zul.db.Timebox,"unbind_",
arguments)},getBtnUpIconClass_:function(){return"z-icon-angle-up"},getBtnDownIconClass_:function(){return"z-icon-angle-down"}},{_updFormat:function(a,b){for(var c=[],e=a._localizedSymbols?a._localizedSymbols.APM:zk.APM,d=0,f=b.length;d<f;d++){var g=b.charAt(d);switch(g){case "a":c.push(new zul.inp.AMPMHandler([d,d+e[0].length-1],3,a));break;case "K":var h=d,k="K"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourHandler2([h,k],7,a));break;case "h":h=d;k="h"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourHandler([h,
k],6,a));break;case "H":h=d;k="H"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourInDayHandler([h,k],4,a));break;case "k":h=d;k="k"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourInDayHandler2([h,k],5,a));break;case "m":h=d;k="m"==b.charAt(d+1)?++d:d;c.push(new zul.inp.MinuteHandler([h,k],1,a));break;case "s":h=d;k="s"==b.charAt(d+1)?++d:d;c.push(new zul.inp.SecondHandler([h,k],2,a));break;case "z":c.push({index:[d,d],format:function(n){return function(){return n}}(a._timezoneAbbr)});break;default:var l=
"";for(k=h=d;(l+=g)&&++k<f;)if(g=b.charAt(k),-1!="ahKHksmz".indexOf(g)){k--;break}c.push({index:[h,k],format:function(n){return function(){return n}}(l)});d=k}}d=0;for(f=c.length;d<f;d++)if(3==c[d].type){var m=c[d].index[1]-c[d].index[0];if(!m)break}else m&&(c[d].index[0]+=m,c[d].index[1]+=m);a._fmthdler=c},_shouldObeyCount:function(a){switch(a){case 1:case 2:case 4:case 5:case 6:case 7:return!0;default:return!1}}});zul.inp.TimeHandler=zk.$extends(zk.Object,{maxsize:59,minsize:0,digits:2,$init:function(a,
b,c){this.index=a;this.type=b;a[0]==a[1]&&(this.digits=1);this.wgt=c},format:function(a){return"00"},unformat:function(a,b,c){return a},increase:function(a,b){var c=a.getInputNode(),e=this.index[0],d=this.index[1]+1,f=c.value,g=this.getText(f),h=!1!==this.isSingleLength();g=zk.parseInt(h?g:g.replace(/ /g,"0"))+b;var k=this.maxsize+1;if(g<this.minsize){g=this.maxsize;var l=1}else g>=k?(g=this.minsize,l=-1):h&&(l=0<b?10==g?1:0:9==g?-1:0);10>g&&!h&&(g="0"+g);c.value=f.substring(0,e)+g+f.substring(d);
h&&l&&(this._doShift(a,l),d+=l);zk(c).setSelectionRange(e,d)},deleteTime:function(a,b){var c=a.getInputNode(),e=zk(c).getSelectionRange(),d=e[0],f=c.value,g=this.$class._getMaxLen(a);f.length>g&&(f=c.value=f.substr(0,g),e=[Math.min(e[0],g),Math.min(e[1],g)],d=e[0]);if(d!=e[1])c.value=f.substring(0,d)+this.$class._cleanSelectionText(a,this)+f.substring(e[1]);else{var h=a._fmthdler,k=h.$indexOf(this);e=b?-1:1;var l=b?0:1;g=b?1:0;if(d==this.index[l]+l){if(h=h[k+2*e])d=h.index[g]+g+e}else d+=e,h=this;
if(h){var m=h.isSingleLength();c.value=f.substring(0,(g+=d)-1)+(m?"":" ")+f.substring(g);m&&h._doShift(a,m)}m&&!b&&d--}zk(c).setSelectionRange(d,d)},_addNextTime:function(a,b){var c=a.getInputNode(),e;if(e=a.getNextTimeHandler(this)){var d=e.index[0];zk(c).setSelectionRange(d,Math.max(d,zk(c).getSelectionRange()[1]));e.addTime(a,b)}},addTime:function(a,b){var c=a.getInputNode(),e=zk(c).getSelectionRange(),d=c.value,f=e[0],g=this.$class._getMaxLen(a),h=this.isSingleLength();d.length>g&&(d=c.value=
d.substr(0,g),e=[Math.min(e[0],g),Math.min(e[1],g)],f=e[0]);if(f!=g){if(f==this.index[0]){g=this.getText(d).substring(0===h?0:2).trim();var k;g.length||(g="0");zk.parseInt(b+g)>this.maxsize&&(0!==h&&(d=c.value=d.substring(0,f)+(h?"0":"00")+d.substring(f+2),h||f++,zk(c).setSelectionRange(f,Math.max(e[1],f)),e=zk(c).getSelectionRange()),h&&this._doShift(a,h))}else if(f==this.index[1]+1){if(!1!==h&&(g=this.getText(d),(k=zk.parseInt(g+b))<=this.maxsize))if(k&&10>k)f--;else if(k||h)d=c.value=d.substring(0,
f+h)+(h?"":"0")+d.substring(f),k?this._doShift(a,1):(zk(c).setSelectionRange(f,Math.max(e[1],f)),h&&this._doShift(a,h));if(!k||k>this.maxsize){this._addNextTime(a,b);return}}if(f!=e[1]){g=this.$class._cleanSelectionText(a,this);var l;!1!==h&&(l=f-this.index[1])&&this._doShift(a,l);c.value=d.substring(0,f++)+b+g.substring(l?0:1)+d.substring(e[1])}else c.value=d.substring(0,f)+b+d.substring(++f);a.lastPos=f;zk(c).setSelectionRange(f,f)}},getText:function(a,b){var c=this.index[0],e=this.index[1]+1;return!1!==
b?a.substring(c,e):a.substring(c)},_doShift:function(a,b){a=a._fmthdler;var c=a.$indexOf(this),e;for(this.index[1]+=b;e=a[++c];)e.index[0]+=b,e.index[1]+=b},isSingleLength:function(){return 1==this.digits&&this.index[0]-this.index[1]},parse:function(a,b){a=this.getText(a,b.obeyCount);b=/^\s*\d*/.exec(a);(b=b.length?b[0].length-(this.index[1]-this.index[0]+1):0)&&this._doShift(this.wgt,b);return zk.parseInt(a)}},{_getMaxLen:function(a){for(var b=a.getInputNode().value,c=0,e,d=0,f=a._fmthdler,g=f.length;d<
g;d++)a=f[d],c=d==g-1?c+a.format().length:c+(a.type?a.getText(b):a.format()).length,a.type&&(e=a);return 1==e.digits?++c:c},_cleanSelectionText:function(a,b){var c=a.getInputNode(),e=zk(c).getSelectionRange();c=e[0];e=e[1];var d=a._fmthdler,f=d.$indexOf(b),g="",h=!0,k;do{var l=b.index[0];var m=b.index[1]+1;b.type&&(k=b.isSingleLength())&&(b._doShift(a,k),e--);if(m>=e&&b.type){for(l=e-l;0<l--;)g+=" ";break}if(b.type){var n=h?c:l;h=!1}else{for(l-=n;0<l--;)g+=" ";g+=b.format()}}while(b=d[++f]);return g}});
zul.inp.HourInDayHandler=zk.$extends(zul.inp.TimeHandler,{maxsize:23,minsize:0,format:function(a){var b=1==this.digits;return a?(a=a.getHours(),!b&&10>a&&(a="0"+a),a.toString()):b?"0":"00"},unformat:function(a,b,c){a.setHours(this.parse(b,c));return a}});zul.inp.HourInDayHandler2=zk.$extends(zul.inp.TimeHandler,{maxsize:24,minsize:1,format:function(a){return a?(a=a.getHours(),0==a?a="24":2==this.digits&&10>a&&(a="0"+a),a.toString()):"24"},unformat:function(a,b,c){b=this.parse(b,c);b>=this.maxsize&&
(b=0);a.setHours(b);return a}});zul.inp.HourHandler=zk.$extends(zul.inp.TimeHandler,{maxsize:12,minsize:1,format:function(a){return a?(a=a.getHours(),a%=12,0==a?a="12":2==this.digits&&10>a&&(a="0"+a),a.toString()):"12"},unformat:function(a,b,c){b=this.parse(b,c);b>=this.maxsize&&(b=0);a.setHours(c.am?b:b+12);return a}});zul.inp.HourHandler2=zk.$extends(zul.inp.TimeHandler,{maxsize:11,minsize:0,format:function(a){var b=1==this.digits;return a?(a=a.getHours(),a%=12,!b&&10>a&&(a="0"+a),a.toString()):
b?"0":"00"},unformat:function(a,b,c){b=this.parse(b,c);a.setHours(c.am?b:b+12);return a}});zul.inp.MinuteHandler=zk.$extends(zul.inp.TimeHandler,{format:function(a){var b=1==this.digits;return a?(a=a.getMinutes(),!b&&10>a&&(a="0"+a),a.toString()):b?"0":"00"},unformat:function(a,b,c){a.setMinutes(this.parse(b,c));return a}});zul.inp.SecondHandler=zk.$extends(zul.inp.TimeHandler,{format:function(a){var b=1==this.digits;return a?(a=a.getSeconds(),!b&&10>a&&(a="0"+a),a.toString()):b?"0":"00"},unformat:function(a,
b,c){a.setSeconds(this.parse(b,c));return a}});zul.inp.AMPMHandler=zk.$extends(zul.inp.TimeHandler,{format:function(a){var b=this.wgt._localizedSymbols?this.wgt._localizedSymbols.APM:zk.APM;if(!a)return b[0];a=a.getHours();return b[12>a?0:1]},unformat:function(a,b,c){a=this.getText(b).trim();b=this.wgt._localizedSymbols?this.wgt._localizedSymbols.APM:zk.APM;return a.length==b[0].length?b[0]==a:!0},addTime:function(a,b){var c=a.getInputNode(),e=this.index[0],d=this.index[1]+1,f=c.value,g=f.substring(e,
d),h=a._localizedSymbols?a._localizedSymbols.APM:zk.APM;g!=h[0]&&g!=h[1]&&(g=h[0],c.value=f.substring(0,e)+g+f.substring(d));this._addNextTime(a,b)},deleteTime:function(a,b){var c=a.getInputNode(),e=zk(c).getSelectionRange(),d=this.index[0],f=this.index[1]+1,g=c.value;if(e[1]-e[0]>f-d)return this.$supers("deleteTime",arguments);e=[""];for(var h=f-d;0<h;h--)e.push(" ");c.value=g.substring(0,d)+e.join("")+g.substring(f);zk(c).setSelectionRange(d,d)},increase:function(a,b){b=a.getInputNode();var c=this.index[0],
e=this.index[1]+1,d=b.value,f=d.substring(c,e);a=a._localizedSymbols?a._localizedSymbols.APM:zk.APM;f=a[0]==f?a[1]:a[0];b.value=d.substring(0,c)+f+d.substring(e);zk(b).setSelectionRange(c,e)},parse:function(a,b){return this.getText(a).trim()}})})();
