/**
 * Scrolling Table for PHPMaker 2019
 * @license (C) 2018 e.World Technology Ltd.
 */
ew.SCROLL_TABLE_DELAY=0;ew.scrollableTable=function(elContainer,width,height){var j=jQuery,$container=$("#"+elContainer),tbd=$container.find("table.ew-table")[0],ua=ew.MOBILE_DETECT;if(!ew.IS_MOBILE&&ua.version("MSIE")<8||ew.IS_MOBILE&&ua.mobileGrade()!="A"||!width&&!height||!tbd||!tbd.rows||!$container[0]||!$container.is("div.ew-grid-middle-panel"))return;var isMobile=function(){return ew.IS_MOBILE||!ew.IS_SCREEN_SM_MIN};var getWidth=function(){return isMobile()?"100%":width};var timer,$subContainers=$(),$tbd=$(tbd),$window=$(window),$grid=$container.addClass("ew-scroll-table").closest(".ew-grid").css({display:"block","min-width":0}),$panels=$grid.find(".ew-grid-lower-panel, .ew-grid-upper-panel"),$form=$grid.closest(".ew-form:not(.ew-list-form)"),$detailPages=$grid.closest(".ew-detail-pages").css("display","block"),$tabPane=$grid.closest(".tab-pane"),$tab=$detailPages.find("a[data-toggle=tab][href='#"+$tabPane.attr("id")+"']"),$collapse=$grid.closest(".collapse"),isDetail=!!$form[0],isActive=$tab.hasClass("show")||$collapse.hasClass("show")||!$detailPages[0];var _setWidths=function(){var t=getWidth();$grid.width(isDetail?"100%":t);$panels.innerWidth("100%");$subContainers.width("100%");$container.removeClass("invisible");ew.fixLayoutHeight()};var setWidths=function(){if(isDetail&&!isActive){$tab.on("shown.bs.tab",_setWidths);$collapse.on("shown.bs.collapse",_setWidths)}else{_setWidths()}};var init=function(){if($container.data("ScrollableTable"))return;var yscroll=height,elContainer=$container[0],width=getWidth();if(isDetail&&width)$form.width(width);$(tbd.rows).each(function(){$(this.cells).each(function(){$(this).wrapInner("<div></div>")})});var rowcnt=tbd.tHead.rows.length;var awidth=$(tbd.tHead.rows[rowcnt-1].cells).map(function(){return this.firstChild.offsetWidth}).get();var colcnt=awidth.length;$grid.width(isDetail?"100%":width);$container.width(width?"100%":"").height(height?"100%":"").css("overflowX",width?"auto":"hidden").css("overflowY",height?"auto":"hidden");var xscrolling=width&&elContainer.scrollWidth>elContainer.clientWidth;var yscrolling=height&&elContainer.scrollHeight>elContainer.clientHeight;$container.addClass("invisible").width("").height("").css("overflowX","hidden").css("overflowY","hidden");var tr,thd,$thd;if(yscroll){var $hdContainer=$("<div></div>").width(width||"").addClass("ew-scroll-table-header").appendTo($container);var $pthd=$("<table></table>").attr({border:0,cellSpacing:0,cellPadding:0,width:"100%"});tr=$pthd[0].insertRow(-1);$(tr).addClass("ew-table-header");$thd=$("<table></table>").attr({border:0,cellSpacing:0,cellPadding:0}).addClass("ew-table").appendTo($(tr.insertCell(-1)).css({padding:"0px",border:"0px"}));thd=$thd[0];$hdContainer.append($pthd);$subContainers=$subContainers.add($hdContainer)}var $bdContainer=$("<div></div>").width(width||"").height(height||"").css("overflowX",width?"auto":"hidden").css("overflowY",height?"auto":"hidden").addClass("ew-scroll-table-body").scroll(function(t){if($hdContainer)$hdContainer.scrollLeft(this.scrollLeft)});$container.append($bdContainer);$subContainers=$subContainers.add($bdContainer);$bdContainer.append(tbd);if(yscroll){$(tbd.tHead).clone().appendTo(thd);$(tbd.tHead).hide()}if(awidth&&tbd.rows&&tbd.rows[0]&&tbd.rows[0].cells){var stmt="";for(var i=0;i<colcnt;i++){if(thd&&thd.tHead&&thd.tHead.rows&&thd.tHead.rows[rowcnt-1]&&thd.tHead.rows[rowcnt-1].cells.length==colcnt)stmt+="thd.tHead.rows["+(rowcnt-1)+"].cells["+i+"].firstChild.style.width='"+awidth[i]+"px';";for(var j=0,rcnt=tbd.rows.length;j<rcnt;j++){if(tbd.rows[j].cells.length==colcnt)stmt+="tbd.rows["+j+"].cells["+i+"].firstChild.style.width='"+awidth[i]+"px';"}}if(stmt!="")eval(stmt)}var bdContainer=$bdContainer[0];yscrolling=bdContainer.scrollHeight>bdContainer.clientHeight;xscrolling=bdContainer.scrollWidth>bdContainer.clientWidth;if(yscroll&&yscrolling&&tr){var ohw=bdContainer.offsetWidth-bdContainer.clientWidth;$(tr.insertCell(-1)).addClass("ew-scroll-table-overhang").html($("<div></div>").width(ohw)).width(ohw)}ew.setupTable(-1,tbd);if(yscroll&&tbd.rows&&bdContainer.clientHeight>tbd.offsetHeight){var $rows=$(tbd.rows).filter(":not(."+ew.ITEM_TEMPLATE_CLASSNAME+")");var n=$rows.filter("[data-rowindex=1]").length||$rows.filter("[data-rowindex=0]").length||1;$rows.filter(":gt("+(-1*n-1)+")").find("td."+ew.TABLE_LAST_ROW_CLASSNAME).removeClass(ew.TABLE_LAST_ROW_CLASSNAME).addClass(ew.TABLE_BORDER_BOTTOM_CLASSNAME)}var _resize=function(){clearTimeout(timer);timer=setTimeout(setWidths,250)};$window.resize(_resize);$('[data-widget="pushmenu"]').on("collapsed.lte.pushmenu",_resize).on("shown.lte.pushmenu",_resize);setWidths();$container.data("ScrollableTable",true)};if(isDetail&&!isActive){$tab.on("shown.bs.tab",init);$collapse.on("shown.bs.collapse",init)}else if(ew.SCROLL_TABLE_DELAY>0){$.later(ew.SCROLL_TABLE_DELAY,null,init)}else if(ew.SCROLL_TABLE_DELAY<0){$(init)}else if(ew.SCROLL_TABLE_DELAY==0){init()}};