var Webropol=Webropol||{};Webropol.Shared=Webropol.Shared||{};Webropol.Shared.Common={stopEvent:function(n,t){var i=n||window.event;return i.cancelBubble=!0,i.returnValue=!1,i.stopPropagation&&n.stopPropagation(),t&&i.stopImmediatePropagation&&n.stopImmediatePropagation(),i.preventDefault&&n.preventDefault(),!1},getFocusableItemsSelector:function(){return'input:visible:not(:disabled), button:visible:not(:disabled), textarea:visible:not(:disabled), select:visible:not(:disabled), a:visible:not([disabled]):not(.disabled), [contenteditable="true"]:visiblediv[tabindex="0"]:visible'},getFocusableItems:function(n){for(var u,f=Webropol.Shared.Common.getFocusableItemsSelector(),i=n.find(f),r=[],t=0;t<i.length;t++)u=i[t],$(u).css("visibility")=="hidden"&&r.push(t);return i.filter(function(n){return $.inArray(n,r)==-1})},focusOnActivePopup:function(n,t){document.activeElement&&document.activeElement.blur();var i=null;t?(i=Webropol.Shared.Common.getFocusableItems(n.find(".modal-footer")).last(),i.length==0&&(i=Webropol.Shared.Common.getFocusableItems(n.find(".modal-body")).first())):(i=Webropol.Shared.Common.getFocusableItems(n.find(".modal-body")).first(),i.length==0&&(i=Webropol.Shared.Common.getFocusableItems(n.find(".modal-footer")).last()));i.length==0&&(i=Webropol.Shared.Common.getFocusableItems(n.find(".modal-header")).first());i.length>0&&i.focus()},isIe:function(){var n=window.navigator.userAgent,t=n.indexOf("MSIE ");return t>0||!!navigator.userAgent.match(/Trident.*rv\:11\./)},getIEVersion:function(){var t=-1,n;if(navigator.appName=="Microsoft Internet Explorer")n=new RegExp("MSIE (\\d+\\.\\d+)");else if(navigator.appName=="Netscape")n=new RegExp("Trident/.*?rv:(\\d+\\.\\d+)");else return t;return n.test(navigator.userAgent)?parseInt(new Number(RegExp.$1),10):t},addIeSpecificCssIfNeeded:function(n){var i="ieSpecificCss",r,t;this.isIe()&&!document.getElementById(i)&&(r=document.getElementsByTagName("head")[0],t=document.createElement("link"),t.id=i,t.rel="stylesheet",t.type="text/css",t.href=n,t.media="all",r.appendChild(t))}};Webropol=Webropol||{};Webropol.Shared=Webropol.Shared||{};Webropol.Shared.TabulationManager=function(n){var t=this,i=$.extend({},{handleMainAreaTabNavigation:!1,scrollAnimateTime:200,getFocusableElementCallback:null,scrollTopCalcCallback:null,beforeFocusCallback:null},n),u=!1,r=!1;this.init=function(){u||($(document).ready(function(){$(document).keydown(function(n){n.keyCode==9&&t.handleFocusOnActivePopup(n)});$("body").on("keydown",":focus",t.tabHandler);$("body").on("mousedown","a[disabled], a.disabled",function(n){Webropol.Shared.Common.stopEvent(n,!0)})}),u=!0)};this.setOptions=function(n){$.extend(i,n)};this.getFocusLimiter=function(){return $("[data-focus-limiter]:visible:last")};this.handleFocusOnActivePopup=function(n,i){return(i=i||t.getFocusLimiter(),i.length>0)?(Webropol.Shared.Common.focusOnActivePopup(i,n.shiftKey),Webropol.Shared.Common.stopEvent(n,!0),!0):!1};this.tabHandler=function(n){var a,u,v,e,c,s,y,l,h,p;if(n.keyCode==9){if(r){Webropol.Shared.Common.stopEvent(n,!0);return}var o=n.target,f=t.getFocusLimiter(),w=Webropol.Shared.Common.getFocusableItemsSelector();(document.activeElement==undefined||f.length>0&&f.find(document.activeElement).length==0||!$(document.activeElement).is(w))&&(a=t.handleFocusOnActivePopup(n,f),a)||(f.length!=0||i.handleMainAreaTabNavigation)&&(u=t.getCurrentTabGroup(o),u!=null)&&(v=n.shiftKey,v?t.isFirstInTabGroup(o,u)?(s=t.getPreviousTabGroupInfo(u,f),s!=null&&(y=s.tg,e=t.getFocusableItems(y),e.length>0&&t.handlePreviousElementFocus(n,e.last(),s.isCyclicJump))):(c=t.getPreviousFocusableItemInContainer(o,u),c!=null&&t.handlePreviousElementFocus(n,c,!1)):t.isLastInTabGroup(o,u)?(h=t.getNextTabGroupInfo(u,f),h!=null&&(p=h.tg,e=t.getFocusableItems(p),e.length>0&&t.handleNextElementFocus(n,e.first(),h.isCyclicJump))):(l=t.getNextFocusableItemInContainer(o,u),l!=null&&t.handleNextElementFocus(n,l,!1)))}};this.handleElementFocus=function(n,u,f,e){var o=u,c=!1,a,s,h,l;typeof i.getFocusableElementCallback=="function"&&(a=i.getFocusableElementCallback(u,f),c=a.needsToScroll,o=a.$elementToFocus);s=t.getScrollableContainer(o);c=c||!t.isVisibleOnScreen(o,s);c?(typeof i.scrollTopCalcCallback=="function"?(h=i.scrollTopCalcCallback(o,f),h==null&&(h=t.calculateScrollTopDefault(o,f,s))):h=t.calculateScrollTopDefault(o,f,s),$(s).attr("data-tab-in-progress","true"),setTimeout(function(){$(s).removeAttr("data-tab-in-progress")},i.scrollAnimateTime+100),r=!0,$(s).animate({scrollTop:h+"px"},i.scrollAnimateTime,"swing",function(){t.focusElement($(n.target),o,f);r=!1})):(t.focusElement($(n.target),o,f),f&&e&&(l=$("#scrollup-btn"),l.length>0&&(r=!0,setTimeout(function(){l.is(":visible")&&l.find(">a").focus();r=!1},200))));Webropol.Shared.Common.stopEvent(n,!0)};this.focusElement=function(n,t,r){typeof i.beforeFocusCallback=="function"&&i.beforeFocusCallback(n,r);t.focus()};this.handlePreviousElementFocus=function(n,i,r){t.handleElementFocus(n,i,!0,r)};this.handleNextElementFocus=function(n,i,r){t.handleElementFocus(n,i,!1,r)};this.getScrollableContainer=function(n){var t=$(n).closest(".ui-layout-container .scrollable");return t.length>0?t[0]:window};this.calculateScrollTopDefault=function(n,t,i){return t?$(i).scrollTop()-($(i).offset().top-n.offset().top+($(i).height()-n.height())):$(i).scrollTop()+(n.offset().top-$(i).offset().top)};this.isVisibleOnScreen=function(n,t){if(t==window)return!0;var i=$(t).offset().top,u=i+$(t).height(),r=n.offset().top,f=r+n.height();return r>=i&&f<=u};this.getCurrentTabGroup=function(n){var t=$(n).parents("[data-tab-group]:first");return t.length>0?t:null};this.getFocusableItems=function(n){var t=Webropol.Shared.Common.getFocusableItems(n);return $($.grep(t,function(n){return $(n).parents(".skip-focus").length==0}))};this.isFirstInTabGroup=function(n,i){var r=t.getFocusableItems(i);return r.length==0?!1:r.first()[0]==n};this.isLastInTabGroup=function(n,i){var r=t.getFocusableItems(i);return r.length==0?!1:r.last()[0]==n};this.getPreviousFocusableItemInContainer=function(n,i){for(var u=t.getFocusableItems(i),r=0;r<u.length;r++)if(u[r]==n)return r==0?null:$(u[r-1]);return null};this.getNextFocusableItemInContainer=function(n,i){for(var u=t.getFocusableItems(i),r=0;r<u.length;r++)if(u[r]==n)return r==u.length-1?null:$(u[r+1]);return null};this.getTargetTabGroupInfoInternal=function(n,t,i){function l(n){for(var t,r,i=0;i<n.length-1;i++)for(t=0;t<n.length-i-1;t++)v(n[t],n[t+1])&&(r=n[t],n[t]=n[t+1],n[t+1]=r)}function a(n,t){var i,r,u,f=/(\.0)+[^\.]*$/;for(n=(n+"").replace(f,"").split("."),t=(t+"").replace(f,"").split("."),u=Math.min(n.length,t.length),i=0;i<u;i++)if(r=parseInt(n[i],10)-parseInt(t[i],10),r!==0)return r;return n.length-t.length}function v(n,t){return a(n,t)>0}var e=n.attr("data-tab-group"),s=i.length>0?i.find("[data-tab-group]:visible"):$("[data-tab-group]:visible"),r;if(s.length<2&&i.length==0)return null;r=[];s.each(function(){r.push($(this).attr("data-tab-group"))});l(r);var h=r[0],c=r[r.length-1],u,f,o=!1;return t?e==h?(f=c,o=!0):(u=$.inArray(e,r),f=u==-1?r[r.length-1]:r[u-1]):e==c?(f=h,o=!0):(u=$.inArray(e,r),f=u==-1?r[0]:r[u+1]),{tg:i.length>0?i.find('[data-tab-group="'+f+'"]'):$('[data-tab-group="'+f+'"]'),isCyclicJump:o}};this.getTargetTabGroupInfo=function(n,i,r){for(var u,f=n,e;;){if(u=t.getTargetTabGroupInfoInternal(f,i,r),u==null)break;if(f=u.tg,f==n)break;if(e=t.getFocusableItems(f),e.length>0)break}return u};this.getPreviousTabGroupInfo=function(n,i){return t.getTargetTabGroupInfo(n,!0,i)};this.getNextTabGroupInfo=function(n,i){return t.getTargetTabGroupInfo(n,!1,i)}}