/*
* Kendo UI Beta v2013.2.716 (http://kendoui.com)
* Copyright 2013 Telerik AD. All rights reserved.
*
* Kendo UI Beta license terms available at
* http://www.kendoui.com/purchase/license-agreement/kendo-ui-beta.aspx
*/
("function"==typeof define&&define.amd?define:function(e,t){return t()})(["./kendo.data.min","./kendo.popup.min"],function(){!function(e,t){function n(t,a){t.filters&&(t.filters=e.grep(t.filters,function(e){return n(e,a),e.filters?e.filters.length:e.field!=a}))}var a=window.kendo,i=a.ui,r=i.Widget,o=a.keys,l=a.support,s=a.htmlEncode,u=a._activeElement,d="id",c="li",f="change",_="character",p="k-state-focused",h="k-state-hover",v="k-loading",m="open",g="close",b="select",x="selected",S="progress",y="requestEnd",w="width",C=e.extend,k=e.proxy,F=l.browser,I=F.msie&&F.version<9,T=/"/g,D={ComboBox:"DropDownList",DropDownList:"ComboBox"},H=r.extend({init:function(t,n){var a,i=this,o=i.ns;r.fn.init.call(i,t,n),t=i.element,i._isSelect=t.is(b),i._template(),i.ul=e('
').css({overflow:l.kineticScrollNeeded?"":"auto"}).on("mouseenter"+o,c,function(){e(this).addClass(h)}).on("mouseleave"+o,c,function(){e(this).removeClass(h)}).on("click"+o,c,k(i._click,i)).attr({tabIndex:-1,role:"listbox","aria-hidden":!0}),i.list=e("").append(i.ul).on("mousedown"+o,function(e){e.preventDefault()}),a=t.attr(d),a&&(i.list.attr(d,a+"-list"),i.ul.attr(d,a+"_listbox"),i._optionID=a+"_option_selected"),i._accessors(),i._initValue()},options:{valuePrimitive:!1},setOptions:function(e){r.fn.setOptions.call(this,e),e&&e.enable!==t&&(e.enabled=e.enable)},focus:function(){this._focused.focus()},readonly:function(e){this._editable({readonly:e===t?!0:e,disable:!1})},enable:function(e){this._editable({readonly:!1,disable:!(e=e===t?!0:e)})},_filterSource:function(e){var t=this,a=t.options,i=t.dataSource,r=i.filter()||{};n(r,a.dataTextField),e&&(r=r.filters||[],r.push(e)),i.filter(r)},_initValue:function(){var e=this,t=e.options.value;t?e.element.val(t):t=e.element.val(),e._old=t},_ignoreCase:function(){var e,t=this,n=t.dataSource.reader.model;n&&n.fields&&(e=n.fields[t.options.dataTextField],e&&e.type&&"string"!==e.type&&(t.options.ignoreCase=!1))},items:function(){return this.ul[0].children},current:function(e){var n=this,a=n._optionID;return e===t?n._current:(n._current&&(n._current.removeClass(p).removeAttr("aria-selected").removeAttr(d),n._focused.removeAttr("aria-activedescendant")),e&&(e.addClass(p),n._scroll(e),a&&(e.attr("id",a),n._focused.attr("aria-activedescendant",a))),n._current=e,t)},destroy:function(){var e=this,t=e.ns;r.fn.destroy.call(e),e._unbindDataSource(),e.ul.off(t),e.list.off(t),e.popup.destroy(),e._form&&e._form.off("reset",e._resetHandler)},dataItem:function(e){var n=this;return e===t&&(e=n.selectedIndex),n._data()[e]},_accessors:function(){var e=this,t=e.element,n=e.options,i=a.getter,r=t.attr(a.attr("text-field")),o=t.attr(a.attr("value-field"));r&&(n.dataTextField=r),o&&(n.dataValueField=o),e._text=i(n.dataTextField),e._value=i(n.dataValueField)},_aria:function(e){var n=this,a=n.options,i=n._focused;a.suggest!==t&&i.attr("aria-autocomplete",a.suggest?"both":"list"),e=e?e+" "+n.ul[0].id:n.ul[0].id,i.attr("aria-owns",e),n.ul.attr("aria-live",a.filter&&"none"!==a.filter?"polite":"off")},_blur:function(){var e=this;e._change(),e.close()},_change:function(){var e,n=this,a=n.selectedIndex,i=n.options.value,r=n.value();n._isSelect&&!n._bound&&i&&(r=i),r!==n._old?e=!0:a!==t&&a!==n._oldIndex&&(e=!0),e&&(n._old=r,n._oldIndex=a,n.trigger(f),n.element.trigger(f))},_click:function(t){t.isDefaultPrevented()||this._accept(e(t.currentTarget))},_data:function(){return this.dataSource.view()},_enable:function(){var e=this,n=e.options,a=e.element.is("[disabled]");n.enable!==t&&(n.enabled=n.enable),!n.enabled||a?e.enable(!1):e.readonly(e.element.is("[readonly]"))},_focus:function(e){var n=this;return n.popup.visible()&&e&&n.trigger(b,{item:e})?(n.close(),t):(n._select(e),n._triggerCascade(),n._blur(),t)},_index:function(e){var t,n,a=this,i=a._data();for(t=0,n=i.length;n>t;t++)if(a._dataValue(i[t])==e)return t;return-1},_dataValue:function(e){var n=this._value(e);return n===t&&(n=this._text(e)),n},_height:function(e){if(e){var t=this,n=t.list,a=t.popup.visible(),i=t.options.height;n=n.add(n.parent(".k-animation-container")).show().height(t.ul[0].scrollHeight>i?i:"auto"),a||n.hide()}},_adjustListWidth:function(){var e,t,n=this.list,a=n[0].style.width,i=this.wrapper;if(n.data(w)||!a)return e=window.getComputedStyle?window.getComputedStyle(i[0],null):0,t=e?parseFloat(e.width):i.outerWidth(),e&&(F.mozilla||F.msie)&&(t+=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight)+parseFloat(e.borderLeftWidth)+parseFloat(e.borderRightWidth)),a=t-(n.outerWidth()-n.width()),n.css({fontFamily:i.css("font-family"),width:a}).data(w,a),!0},_popup:function(){var e=this,t=e.list,n=e._focused,r=e.options,o=e.wrapper;e.popup=new i.Popup(t,C({},r.popup,{anchor:o,open:function(t){e._adjustListWidth(),e.trigger(m)?t.preventDefault():(n.attr("aria-expanded",!0),e.ul.attr("aria-hidden",!1))},close:function(t){e.trigger(g)?t.preventDefault():(n.attr("aria-expanded",!1),e.ul.attr("aria-hidden",!0))},animation:r.animation,isRtl:l.isRtl(o)})),e.popup.one(m,function(){e._height(e._data().length)}),e._touchScroller=a.touchScroller(e.popup.element)},_makeUnselectable:function(){I&&this.list.find("*").attr("unselectable","on")},_toggleHover:function(t){e(t.currentTarget).toggleClass(h,"mouseenter"===t.type)},_toggle:function(e){var n=this;e=e!==t?e:!n.popup.visible(),l.touch||n._focused[0]===u()||n._focused.focus(),n[e?m:g]()},_scroll:function(e){if(e){e[0]&&(e=e[0]);var t=this.ul[0],n=e.offsetTop,a=e.offsetHeight,i=t.scrollTop,r=t.clientHeight,o=n+a;t.scrollTop=i>n?n:o>i+r?o-r:i}},_template:function(){var e=this,t=e.options,n=t.template,i=t.dataSource;e._isSelect&&e.element[0].length&&(i||(t.dataTextField=t.dataTextField||"text",t.dataValueField=t.dataValueField||"value")),n?(n=a.template(n),e.template=function(e){return''+n(e)+""}):e.template=a.template('${'+a.expr(t.dataTextField,"data")+"}",{useWithBlock:!1})},_triggerCascade:function(){var e=this,t=e.value();(!e._bound&&t||e._old!==t)&&e.trigger("cascade")},_unbindDataSource:function(){var e=this;e.dataSource.unbind(f,e._refreshHandler).unbind(S,e._progressHandler).unbind(y,e._requestEndHandler).unbind("error",e._errorHandler)}});C(H,{caret:function(e){var t,n=e.ownerDocument.selection;return t=n?Math.abs(n.createRange().moveStart(_,-e.value.length)):e.selectionStart},selectText:function(e,t,n){try{if(e.createTextRange){e.focus();var a=e.createTextRange();a.collapse(!0),a.moveStart(_,t),a.moveEnd(_,n-t),a.select()}else e.setSelectionRange(t,n)}catch(i){}},inArray:function(e,t){var n,a,i=t.children;if(!e||e.parentNode!==t)return-1;for(n=0,a=i.length;a>n;n++)if(e===i[n])return n;return-1}}),a.ui.List=H,i.Select=H.extend({init:function(e,t){H.fn.init.call(this,e,t),this._initial=this.element.val()},setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.options.autoBind&&this.dataSource.fetch()},close:function(){this.popup.close()},select:function(e){var n=this;return e===t?n.selectedIndex:(n._select(e),n._triggerCascade(),n._old=n._accessor(),n._oldIndex=n.selectedIndex,t)},_accessor:function(e,n){var a,i=this.element[0],r=this._isSelect,o=i.selectedIndex;return e===t?(r?o>-1&&(a=i.options[o],a&&(e=a.value)):e=i.value,e):(r?(o>-1&&i.options[o].removeAttribute(x),i.selectedIndex=n,a=i.options[n],a&&a.setAttribute(x,x)):i.value=e,t)},_hideBusy:function(){var e=this;clearTimeout(e._busy),e._arrow.removeClass(v),e._focused.attr("aria-busy",!1),e._busy=null},_showBusy:function(){var e=this;e._request=!0,e._busy||(e._busy=setTimeout(function(){e._focused.attr("aria-busy",!0),e._arrow.addClass(v)},100))},_requestEnd:function(){this._request=!1},_dataSource:function(){var t,n=this,i=n.element,r=n.options,o=r.dataSource||{};o=e.isArray(o)?{data:o}:o,n._isSelect&&(t=i[0].selectedIndex,t>-1&&(r.index=t),o.select=i,o.fields=[{field:r.dataTextField},{field:r.dataValueField}]),n.dataSource&&n._refreshHandler?n._unbindDataSource():(n._refreshHandler=k(n.refresh,n),n._progressHandler=k(n._showBusy,n),n._requestEndHandler=k(n._requestEnd,n),n._errorHandler=k(n._hideBusy,n)),n.dataSource=a.data.DataSource.create(o).bind(f,n._refreshHandler).bind(S,n._progressHandler).bind(y,n._requestEndHandler).bind("error",n._errorHandler)},_get:function(t){var n,a,i=this,r=i._data();if("function"==typeof t)for(n=0,a=r.length;a>n;n++)if(t(r[n])){t=n;break}if("number"==typeof t){if(0>t)return e();t=e(i.ul[0].children[t])}return t&&t.nodeType&&(t=e(t)),t},_move:function(e){var t,n,a=this,i=e.keyCode,r=a.ul[0],l=a.popup.visible()?"_select":"_accept",s=a._current,u=i===o.DOWN;if(i===o.UP||u){if(e.altKey)a.toggle(u);else{if(t=r.firstChild,!t&&!a._accessor()&&"filter"!==a._state)return a.dataSource.one(f,function(){a._move(e)}),a._filterSource(),e.preventDefault(),!0;u?(!s||-1===a.selectedIndex&&!a.value()&&s[0]===t?s=t:(s=s[0].nextSibling,s||t!==r.lastChild||(s=t)),a[l](s)):(s=s?s[0].previousSibling:r.lastChild,s||t!==r.lastChild||(s=t),a[l](s))}e.preventDefault(),n=!0}else i===o.ENTER||i===o.TAB?(a.popup.visible()&&e.preventDefault(),a._accept(s),n=!0):i===o.ESC&&(a.popup.visible()&&e.preventDefault(),a.close(),n=!0);return n},_selectItem:function(e){var t=this,n=t.options,a=t.selectedIndex;e=t._selectedValue||n.value||t._accessor(),e?t.value(e):(!t._bound||a>-1)&&(t._bound||(a=n.index),t.select(a))},_fetchItems:function(e){var n=this,a=n.ul[0].firstChild;return n._request?!0:n._fetch||a?t:n.options.cascadeFrom?!a:(n.dataSource.one(f,function(){n.value(e),n._fetch=!1}),n._fetch=!0,n.dataSource.fetch(),!0)},_options:function(e,n){var a,i,r,o,l=this,u=l.element,d=u[0].selectedIndex,c=e.length,f="",_=0;for(n&&(f=n,d+=1,_=1);c>_;_++)a="",f+=a;u.html(f),u[0].selectedIndex=-1===d?0:d},_reset:function(){var t=this,n=t.element,a=n.attr("form"),i=a?e("#"+a):n.closest("form");i[0]&&(t._resetHandler=function(){setTimeout(function(){t.value(t._initial)})},t._form=i.on("reset",t._resetHandler))},_cascade:function(){var t,a,i,r,o,l=this,s=l.options,u=s.cascadeFrom;if(u){if(l._selectedValue=s.value||l._accessor(),a=e("#"+u),t=a.data("kendo"+s.name),t||(t=a.data("kendo"+D[s.name])),!t)return;s.autoBind=!1,r=t.options.dataValueField,o=function(){var e=l._selectedValue||l.value();e?(l.value(e),l.dataSource.view()[0]&&-1!==l.selectedIndex||l._clearSelection(t,!0)):l.select(s.index),l.enable(),l._triggerCascade()},i=function(){var e,a,i=t.dataItem(),s=i?t._value(i):null;s||0===s?(e=l.dataSource.filter()||{},n(e,r),a=e.filters||[],a.push({field:r,operator:"eq",value:s}),l.dataSource.one(f,o).filter(a)):(l.enable(!1),l._clearSelection(t),l._triggerCascade())},t.bind("cascade",function(){i()}),t._bound?i():t.value()||l.enable(!1)}}})}(window.kendo.jQuery)});