/*
* 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.list.min"],function(){!function(e,t){function a(e,t,a){return a?t.substring(0,e).split(a).length-1:0}function s(e,t,s){return t.split(s)[a(e,t,s)]}function n(e,t,s,n){var r=t.split(n);return r.splice(a(e,t,n),1,s),n&&""!==r[r.length-1]&&r.push(""),r.join(n)}function r(e){var t=e.value.length;T(e,t,t)}var o=window.kendo,i=o.support,l=o._activeElement,c=i.placeholder,u=o.ui,d=o.keys,p=o.data.DataSource,h=u.List,_="aria-disabled",f="aria-readonly",g="k-state-default",v="disabled",m="readonly",y="k-state-focused",C="k-state-selected",b="k-state-disabled",w="k-state-hover",k=".kendoAutoComplete",x="mouseenter"+k+" mouseleave"+k,S=h.caret,T=h.selectText,A=e.proxy,B=h.extend({init:function(t,a){var s,n=this;n.ns=k,a=e.isArray(a)?{dataSource:a}:a,h.fn.init.call(n,t,a),t=n.element,a=n.options,a.placeholder=a.placeholder||t.attr("placeholder"),c&&t.attr("placeholder",a.placeholder),n._wrapper(),n._loader(),n._dataSource(),n._ignoreCase(),t[0].type="text",s=n.wrapper,n._popup(),t.addClass("k-input").on("keydown"+k,A(n._keydown,n)).on("paste"+k,A(n._search,n)).on("focus"+k,function(){n._prev=n._accessor(),n._placeholder(!1),s.addClass(y)}).on("blur"+k,function(){n._change(),n._placeholder(),s.removeClass(y)}).attr({autocomplete:"off",role:"textbox","aria-haspopup":!0}),n._enable(),n._old=n._accessor(),t[0].id&&t.attr("aria-owns",n.ul[0].id),n._aria(),n._placeholder(),o.notify(n)},options:{name:"AutoComplete",enabled:!0,suggest:!1,template:"",dataTextField:"",minLength:1,delay:200,height:200,filter:"startswith",ignoreCase:!0,highlightFirst:!1,separator:null,placeholder:"",animation:{}},_dataSource:function(){var e=this;e.dataSource&&e._refreshHandler?e._unbindDataSource():(e._refreshHandler=A(e.refresh,e),e._progressHandler=A(e._showBusy,e)),e.dataSource=p.create(e.options.dataSource).bind("change",e._refreshHandler).bind("progress",e._progressHandler)},setDataSource:function(e){this.options.dataSource=e,this._dataSource()},events:["open","close","change","select","dataBinding","dataBound"],setOptions:function(e){h.fn.setOptions.call(this,e),this._template(),this._accessors(),this._aria()},_editable:function(e){var t=this,a=t.element,s=t.wrapper.off(k),n=e.readonly,r=e.disable;n||r?(s.addClass(r?b:g).removeClass(r?g:b),a.attr(v,r).attr(m,n).attr(_,r).attr(f,n)):(s.addClass(g).removeClass(b).on(x,t._toggleHover),a.removeAttr(v).removeAttr(m).attr(_,!1).attr(f,!1))},close:function(){var e=this,t=e._current;t&&t.removeClass(C),e.current(null),e.popup.close()},destroy:function(){var e=this;e.element.off(k),e.wrapper.off(k),h.fn.destroy.call(e)},refresh:function(){var a,s=this,n=s.ul[0],r=s.popup,i=s.options,c=s._data(),u=c.length;s.trigger("dataBinding"),n.innerHTML=o.render(s.template,c),s._height(u),r.visible()&&r._position(),u&&(i.highlightFirst&&s.current(e(n.firstChild)),i.suggest&&s.suggest(e(n.firstChild))),s._open&&(s._open=!1,a=u?"open":"close",s._typing&&s.element[0]!==l()&&(a="close"),r[a](),s._typing=t),s._touchScroller&&s._touchScroller.reset(),s._makeUnselectable(),s._hideBusy(),s.trigger("dataBound")},select:function(e){this._select(e)},search:function(e){var t,a=this,n=a.options,r=n.ignoreCase,o=n.separator;e=e||a._accessor(),a._current=null,clearTimeout(a._typing),o&&(e=s(S(a.element[0]),e,o)),t=e.length,t?t>=a.options.minLength&&(a._open=!0,a._filterSource({value:r?e.toLowerCase():e,operator:n.filter,field:n.dataTextField,ignoreCase:r})):a.popup.close()},suggest:function(e){var s,n=this,r=n._last,o=n._accessor(),i=n.element[0],l=S(i),c=n.options.separator,u=o.split(c),p=a(l,o,c),_=l;return r==d.BACKSPACE||r==d.DELETE?(n._last=t,t):(e=e||"","string"!=typeof e&&(s=h.inArray(e[0],n.ul[0]),e=s>-1?n._text(n._data()[s]):""),0>=l&&(l=o.toLowerCase().indexOf(e.toLowerCase())+1),s=o.substring(0,l).lastIndexOf(c),s=s>-1?l-(s+c.length):l,o=u[p].substring(0,s),e&&(s=e.toLowerCase().indexOf(o.toLowerCase()),s>-1&&(e=e.substring(s+o.length),_=l+e.length,o+=e),c&&""!==u[u.length-1]&&u.push("")),u[p]=o,n._accessor(u.join(c||"")),T(i,l,_),t)},value:function(e){return e===t?this._accessor():(this._accessor(e),this._old=e,t)},_accessor:function(e){var a=this,s=a.element[0];return e===t?(e=s.value,s.className.indexOf("k-readonly")>-1?e===a.options.placeholder?"":e:e):(s.value=null===e?"":e,a._placeholder(),t)},_accept:function(e){var t=this;t._focus(e),r(t.element[0])},_keydown:function(t){var a=this,s=a.ul[0],n=t.keyCode,r=a._current,o=a.popup.visible();a._last=n,n===d.DOWN?(o&&a._move(r?r.next():e(s.firstChild)),t.preventDefault()):n===d.UP?(o&&a._move(r?r.prev():e(s.lastChild)),t.preventDefault()):n===d.ENTER||n===d.TAB?(n===d.ENTER&&a.popup.visible()&&t.preventDefault(),a._accept(r)):n===d.ESC?(a.popup.visible()&&t.preventDefault(),a.close()):a._search()},_move:function(e){var t=this;e=e[0]?e:null,t.current(e),t.options.suggest&&t.suggest(e)},_hideBusy:function(){var e=this;clearTimeout(e._busy),e._loading.hide(),e.element.attr("aria-busy",!1),e._busy=null},_showBusy:function(){var e=this;e._busy||(e._busy=setTimeout(function(){e.element.attr("aria-busy",!0),e._loading.show()},100))},_placeholder:function(e){if(!c){var a,s=this,n=s.element,r=s.options.placeholder;if(r){if(a=n.val(),e===t&&(e=!a),e||(r=a!==r?a:""),a===s._old&&!e)return;n.toggleClass("k-readonly",e).val(r)}}},_search:function(){var e=this;clearTimeout(e._typing),e._typing=setTimeout(function(){e._prev!==e._accessor()&&(e._prev=e._accessor(),e.search())},e.options.delay)},_select:function(t){var a,s,r=this,o=r.options.separator,i=r._data();t=e(t),t[0]&&!t.hasClass(C)&&(s=h.inArray(t[0],r.ul[0]),s>-1&&(i=i[s],a=r._text(i),o&&(a=n(S(r.element[0]),r._accessor(),a,o)),r._accessor(a),r.current(t.addClass(C))))},_loader:function(){this._loading=e('').insertAfter(this.element)},_toggleHover:function(t){e(t.currentTarget).toggleClass(w,"mouseenter"===t.type)},_wrapper:function(){var e,t=this,a=t.element,s=a[0];e=a.parent(),e.is("span.k-widget")||(e=a.wrap("").parent()),e.attr("tabindex",-1),e.attr("role","presentation"),e[0].style.cssText=s.style.cssText,a.css({width:"100%",height:s.style.height}),t._focused=t.element,t.wrapper=e.addClass("k-widget k-autocomplete k-header").addClass(s.className)}});u.plugin(B)}(window.kendo.jQuery)});