(function(){var p={},n=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?
(p[a[0]]||(p[a[0]]=a[1]),p[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,h=this._fmthdler,g=h.length;f<g;f++)c=h[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=n._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,h=this._fmthdler,g=h.length;f<g;f++){var k=h[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 q=f+1<g&&this.$class._shouldObeyCount(h[f+1].type);b.push(k);e.push(q);k.parse(a,{obeyCount:q});k.getText(a).trim().length||d++}}if(b.length==(l?--d:d))this._changed=!1;else{f=0;for(g=b.length;f<
g;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)},doKeyDown_:function(a){var b=
this.getInputNode();if(!b.disabled&&!b.readOnly){if(!n._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&&n._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(inp).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);this.$n();var b=this.getInputNode(),c=zk(b).getSelectionRange();b.value||(b.value=n._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||n._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;(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");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 h=b.charAt(d);switch(h){case "a":c.push(new zul.inp.AMPMHandler([d,d+e[0].length-1],3,a));break;case "K":var g=d,k="K"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourHandler2([g,
k],7,a));break;case "h":g=d;k="h"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourHandler([g,k],6,a));break;case "H":g=d;k="H"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourInDayHandler([g,k],4,a));break;case "k":g=d;k="k"==b.charAt(d+1)?++d:d;c.push(new zul.inp.HourInDayHandler2([g,k],5,a));break;case "m":g=d;k="m"==b.charAt(d+1)?++d:d;c.push(new zul.inp.MinuteHandler([g,k],1,a));break;case "s":g=d;k="s"==b.charAt(d+1)?++d:d;c.push(new zul.inp.SecondHandler([g,k],2,a));break;case "z":c.push({index:[d,
d],format:function(a){return function(){return a}}(a._timezoneAbbr)});break;default:var l="";for(k=g=d;(l+=h)&&++k<f;)if(h=b.charAt(k),-1!="ahKHksmz".indexOf(h)){k--;break}c.push({index:[g,k],format:function(a){return function(){return a}}(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,h=this.getText(f),g=!1!==this.isSingleLength();h=zk.parseInt(g?h:h.replace(/ /g,"0"))+b;var k=this.maxsize+1;if(h<this.minsize){h=this.maxsize;var l=1}else h>=k?(h=this.minsize,l=-1):g&&
(l=0<b?10==h?1:0:9==h?-1:0);10>h&&!g&&(h="0"+h);c.value=f.substring(0,e)+h+f.substring(d);g&&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,h=this.$class._getMaxLen(a);f.length>h&&(f=c.value=f.substr(0,h),e=[Math.min(e[0],h),Math.min(e[1],h)],d=e[0]);if(d!=e[1])c.value=f.substring(0,d)+this.$class._cleanSelectionText(a,this)+f.substring(e[1]);else{var g=a._fmthdler,k=g.$indexOf(this);e=b?-1:1;
var l=b?0:1;h=b?1:0;if(d==this.index[l]+l){if(g=g[k+2*e])d=g.index[h]+h+e}else d+=e,g=this;if(g){var m=g.isSingleLength();c.value=f.substring(0,(h+=d)-1)+(m?"":" ")+f.substring(h);m&&g._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],h=this.$class._getMaxLen(a),g=this.isSingleLength();d.length>h&&(d=c.value=d.substr(0,h),e=[Math.min(e[0],h),Math.min(e[1],h)],f=e[0]);if(f!=h){if(f==this.index[0]){var k=this.getText(d).substring(0===g?0:2).trim();k.length||(k="0");zk.parseInt(b+k)>this.maxsize&&(0!==g&&(d=c.value=d.substring(0,f)+(g?"0":"00")+d.substring(f+2),g||f++,zk(c).setSelectionRange(f,Math.max(e[1],f)),e=zk(c).getSelectionRange()),g&&this._doShift(a,g))}else if(f==this.index[1]+1){if(!1!==g&&(k=this.getText(d),
(k=zk.parseInt(k+b))<=this.maxsize))if(k&&10>k)f--;else if(k||g)d=c.value=d.substring(0,f+g)+(g?"":"0")+d.substring(f),k?this._doShift(a,1):(zk(c).setSelectionRange(f,Math.max(e[1],f)),g&&this._doShift(a,g));if(!k||k>this.maxsize){this._addNextTime(a,b);return}}if(f!=e[1]){k=this.$class._cleanSelectionText(a,this);var l;!1!==g&&(l=f-this.index[1])&&this._doShift(a,l);c.value=d.substring(0,f++)+b+k.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,h=f.length;d<h;d++)a=f[d],c=d==h-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),h="",g=!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--;)h+=" ";break}if(b.type){var n=g?c:l;g=!1}else{for(l-=
n;0<l--;)h+=" ";h+=b.format()}}while(b=d[++f]);return h}});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,h=f.substring(e,d),g=a._localizedSymbols?a._localizedSymbols.APM:zk.APM;h!=g[0]&&h!=g[1]&&(h=g[0],c.value=f.substring(0,e)+h+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,h=c.value;if(e[1]-e[0]>f-d)return this.$supers("deleteTime",arguments);e=[""];for(var g=f-d;0<g;g--)e.push(" ");c.value=h.substring(0,d)+e.join("")+h.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()}})})();
