function KTree(n){this.options=n;this.LoadState=[];this.MenuItems=[];this.MenuRootPath="/";this.Initialize()}function KTreeMenuItem(){this.ParentMenuItem=null;this.Level=0;this.Path=null;this.MenuItems=[];this.Tags=new KTreeTags;this.HasChildren=!1;this.IsDepartmentLink=!1}function KTreeTags(){this.Ul=null;this.Li=null;this.SpanExpand=null}function KOnlinePayments(n){this.options=n;var t=this;this.selectedPaymentCode=n.selectedPaymentCode;this.selectedOnlinePaymentCode=n.selectedOnlinePaymentCode;this.getPaymentButtonHtml=function(n){window.kytary.ajax.post(t.options.getPaymentButtonHtmlUrl,{orderNumber:t.options.orderNumber,paymentCode:t.selectedPaymentCode,onlinePaymentCode:t.selectedOnlinePaymentCode},n)};this.payButtonHtml=ko.observable();this.onlinePaymentGroups=ko.utils.arrayMap(n.onlinePaymentGroups,function(n){return new KOnlinePaymentGroup(t,n)});this.bind=function(n){ko.applyBindings(this,n)}}function KOnlinePaymentGroup(n,t){var i=this;this.onlinePayments=n;this.name=t.Name;this.code=t.Code;this.selectedValue=ko.observable();this.selectedValue.subscribe(this.selectedValueChanged,this);this.onlinePaymentTypes=ko.utils.arrayMap(t.OnlinePaymentTypes,function(n){return new KOnlinePaymentItem(i,n)})}function KOnlinePaymentItem(n,t){this.group=n;this.name=ko.observable(t.Name);this.description=t.Description;this.code=t.Code;this.imageUrl=t.ImageUrl;var i=n.code==n.onlinePayments.selectedPaymentCode&&this.code==n.onlinePayments.selectedOnlinePaymentCode;i&&n.selectedValue(i?this:null)}KTree.prototype.Initialize=function(){var t=this,n=$("#"+this.options.objName);this.MenuItems[this.MenuRootPath]=new KTreeMenuItem;this.MenuItems[this.MenuRootPath].Level=0;this.MenuItems[this.MenuRootPath].Path=this.MenuRootPath;this.MenuItems[this.MenuRootPath].Tags.Ul=n;this.InitializeRecursive(this.MenuItems[this.MenuRootPath],n);this.options.currentPath===undefined||this.options.currentPath==""||this.options.currentPath=="/"||this.LoadCurrentPath()};KTree.prototype.InitializeRecursive=function(n,t){var f=$(t).children("li"),r;if(f.length!=0){for(r=0;r<f.length;r++){var s=f[r],u=$(s),e=u.children("ul").first(),o=u.find("a").first(),h=o.attr("data-ch"),c=u.find("span.exp").first(),l=n.Level+1,i=o.attr("href");n.MenuItems[i]=new KTreeMenuItem;n.MenuItems[i].ParentMenuItem=n;n.MenuItems[i].Level=l;n.MenuItems[i].Path=i;n.MenuItems[i].HasChildren=h=="1"?!0:!1;n.MenuItems[i].Tags.Ul=e;n.MenuItems[i].Tags.Li=u;n.MenuItems[i].Tags.SpanExpand=c;this.CreateOnClickHandler(n.MenuItems[i]);this.InitializeRecursive(n.MenuItems[i],e);i==this.options.currentPath&&this.SetTopLevelNodeActive(n.MenuItems[i])}this.LoadState.push(n.Path)}};KTree.prototype.SetTopLevelNodeActive=function(n){for(var t=n;t.Level>1;)t=t.ParentMenuItem;t.Tags.Li.addClass("active")};KTree.prototype.LoadCurrentPath=function(){this.LoadPathRecursive(this.options.currentPath,"/",0)};KTree.prototype.LoadPathRecursive=function(n,t,i){for(var r=this,e=n.split("/"),o="/",s=0,f,u=0;u<e.length;u++)if(e[u]!=""&&(o+=e[u]+"/",s++,s>i))break;f=r.GetMenuItemRecursive(r.MenuItems,t);f!=null&&f.HasChildren&&(jQuery.inArray(t,r.LoadState)==-1?this.GetOddeleniByPath(t,function(u){r.CreateLevel(f,u,!0);r.LoadState.push(f.Path);n!=t&&r.LoadPathRecursive(n,o,i+1)}):n!=t&&r.LoadPathRecursive(n,o,i+1))};KTree.prototype.LoadPath=function(n){var t=this;jQuery.inArray(n,t.LoadState)==-1&&this.GetOddeleniByPath(n,function(i){var r=t.GetMenuItemRecursive(t.MenuItems,n);r!=null&&(t.CreateLevel(r,i,!0),t.LoadState.push(n))})};KTree.prototype.CreateLevel=function(n,t){var y=this,a=n.Tags.Ul,i,u,c,o,l,v,s,h;for($(a).css("display","none"),i=0;i<t.length;i++){var r=t[i].IsDepartmentLink?t[i].Path:n.Path+t[i].Section+"/",e=n.Level+1,f=$("<li"+(t[i].IsDepartmentLink?' class="dep-link"':"")+"><\/li>");a.append(f);e>1&&r==this.options.currentPath&&f.addClass("active");u=null;e>=2&&(t[i].HasChildren?(u=document.createElement("span"),$(u).addClass("icon-left plus").css("cursor","pointer"),f.append($(u))):(c=$('<span class="icon-left none"><\/span>'),c.css("cursor","pointer"),f.append(c)));o=document.createElement("a");f.append($(o));o.innerHTML+=window.kytary.utils.HtmlEncode(t[i].Nazev);o.href=r;l=e>1?null:t[i].IconUrl;l&&(v=$('<img src="'+l+'" alt=""/>'),$(o).append(v.wrap("<span><\/span>")));s=document.createElement("input");s.setAttribute("type","hidden");s.setAttribute("name","hasChildren");s.setAttribute("value",t[i].HasChildren?"1":"0");f.append($(s));e==0&&(u=document.createElement("span"),$(u).addClass("icon-right glyphicon glyphicon-menu-down").css("cursor","pointer"),f.append($(u)));h=$('<ul class="slidedown-menu"><\/ul>');f.append(h);h.hide();n.MenuItems[r]=new KTreeMenuItem;n.MenuItems[r].Level=e;n.MenuItems[r].Path=r;n.MenuItems[r].HasChildren=t[i].HasChildren;n.MenuItems[r].Tags.Ul=h;n.MenuItems[r].Tags.SpanExpand=$(u);n.MenuItems[r].IsDepartmentLink=n.IsDepartmentLink;u!=null&&this.CreateOnClickHandler(n.MenuItems[r])}n.HasChildren&&this.OpenOrClose(n)};KTree.prototype.CreateOnClickHandler=function(n){var t=this;$(n.Tags.SpanExpand).on("click",function(i){window.event?(window.event.returnValue=!1,window.event.cancelBubble=!0):i&&(i.stopPropagation(),i.preventDefault());var r=n.Path;t.LoadPath(r);jQuery.inArray(r,t.LoadState)!=-1&&t.OpenOrClose(n)})};KTree.prototype.OpenOrClose=function(n){if(n.Tags.Ul!=null){var t=n.Tags.Ul;n.Level==1?$(t).css("display")=="none"?($(t).css("display","block"),$(n.Tags.SpanExpand).removeClass("icon-right glyphicon glyphicon-menu-down"),$(n.Tags.SpanExpand).addClass("icon-right glyphicon glyphicon-menu-up")):($(t).css("display","none"),$(n.Tags.SpanExpand).removeClass("icon-right glyphicon glyphicon-menu-up"),$(n.Tags.SpanExpand).addClass("icon-right glyphicon glyphicon-menu-down")):n.Level>=2&&($(t).css("display")=="none"?($(t).css("display","block"),$(n.Tags.SpanExpand).removeClass("icon-left plus"),$(n.Tags.SpanExpand).addClass("icon-left minus")):($(t).css("display","none"),$(n.Tags.SpanExpand).removeClass("icon-left minus"),$(n.Tags.SpanExpand).addClass("icon-left plus")))}};KTree.prototype.GetOddeleniByPath=function(n,t){window.kytary.ajax.post(this.options.dataUrl,{OddeleniPath:n},t)};KTree.prototype.GetMenuItemRecursive=function(n,t){var r=null,i;for(i in n){if(n[i]===undefined)break;else{if(n[i].Path==t){r=n[i];break}n[i].SizeIsNotZero()&&(r=this.GetMenuItemRecursive(n[i].MenuItems,t))}if(r!=null)break}return r};KTreeMenuItem.prototype.SizeIsNotZero=function(){var n=!1,t;for(t in this.MenuItems){n=!0;break}return n};KTreeMenuItem.prototype.Size=function(){var n=0,t;for(t in this.MenuItems)n++;return n};KOnlinePaymentGroup.prototype.selectedValueChanged=function(n){var t=this;this.onlinePayments.selectedPaymentCode=n.group.code;this.onlinePayments.selectedOnlinePaymentCode=n.code;this.onlinePayments.getPaymentButtonHtml(function(n){if(n&&n.length>0){t.onlinePayments.payButtonHtml(n);return}window.kytary.utils.messageBox(window.kytary_resources.Error_OnlineGateCommunication,window.kytary.utils.msgIconAlert)})}