var DataGrid={search:function(sid){var s=page.nodes[sid];var e=Dom.getElement(sid+".search");DataGrid.getItems(s,{nameFilter:e.value,startIndex:"0"})},searchName:function(sid,value){var s=page.nodes[sid];var e=Dom.getElement(sid+".search");e.value=value;DataGrid.getItems(s,{nameFilter:e.value,startIndex:"0"})},sortResults:function(sid,sortOrder){var s=page.nodes[sid];if(s.sortOrder==sortOrder)s.sortDescending=!s.sortDescending;DataGrid.getItems(s,{sortOrder:sortOrder})},showFirstPage:function(sid){var s=page.nodes[sid];DataGrid.getItems(s,{startIndex:"0"})},showPreviousPage:function(sid){var s=page.nodes[sid];DataGrid.getItems(s,{startIndex:s.startIndex-s.pageSize})},showNextPage:function(sid){var s=page.nodes[sid];DataGrid.getItems(s,{startIndex:s.startIndex+s.pageSize})},showLastPage:function(sid){var s=page.nodes[sid];DataGrid.getItems(s,{startIndex:s.count-s.pageSize})},selectAll:function(sid){var t=DataGrid;t.selectDisplayed(sid);var s=page.nodes[sid];s.selectAll=true;t.updateSelectedTitles(s)},selectNone:function(sid){var t=DataGrid;var s=page.nodes[sid];if(s){s.selectAll=false;var count=Array.getLength(s.items);for(var i=0;i<count;i++){var id=s.nodeId+".selected."+i;var e=Dom.getElement(id);if(e){e.checked=false;Dom.removeClass(Dom.getParentByTag(e,"TR"),"dg-selected")}}t.updateSelectedTitles(s)}},selectDisplayed:function(sid){var t=DataGrid;var s=page.nodes[sid];if(s){s.selectAll=false;var count=Array.getLength(s.items);for(var i=0;i<count;i++){var id=s.nodeId+".selected."+i;var e=Dom.getElement(id);if(e){e.checked=true;Dom.addClass(Dom.getParentByTag(e,"TR"),"dg-selected")}}t.updateSelectedTitles(s)}},renderSearchBar:function(w,s){var t=DataGrid;w("<div class='section-padding dg-form'>");w("<table style='width: 100%;'>");w("<tr><td nowrap>");w("<form class='section-padding dg-form' onsubmit='DataGrid.search(",s.nodeId,");return false;'>","<input id='"+s.nodeId+".search' name='search'",Html.attribute("value",s.nameFilter)," style='width: 200px;' />"," &nbsp;<input class=inputButtonWide type=submit value='Search' />");w("</form></td>","<td class=font-sys align=center width=100%>");t._1(w,s,"","All");w("&nbsp; &nbsp;|");var sl=s.letters;if(sl){for(var i=0;i<26;i++){w("&nbsp; &nbsp;");var ch=String.fromCharCode(65+i);if(sl.charAt(i)=="1"){t._1(w,s,ch+"*",ch)}else{w("<span style='color:#aaa;'>",ch,"</span>")}}}w("</td></tr></table>");w("</div>")},_1:function(w,s,value,label){if(!label)label=value;if(!value&&!s.nameFilter||s.nameFilter==value){w(label)}else{w("<a href='' onclick='DataGrid.searchName(",s.nodeId,",\"",value,"\"); return false;'>",label,"</a>")}},renderNavBar:function(w,s){var t=DataGrid;var m=s.module;var start=s.startIndex;var count=Array.getLength(s.items);var total=s.count||0;var label=m.itemName;var sid=s.nodeId;w("<div style='margin: 10px 6px;'>");w("<table class='font-sys' style='width:100%;'>");w("<tr><td style='width: 200px;'>");t._3(w,s);w("</td><td id='",sid,".title' align=center><b>");if(count<total){w((start+1).toN0()+" - "+(start+count).toN0()+" of "+total.toCount(label))}else{w(total.toCount(label))}if(s.nameFilter)w(" for &quot;"+s.nameFilter+"&quot;");w("</b></td><td style='width: 200px;' align=right>");var allowPrev=s.startIndex>0;var allowNext=s.startIndex+Array.getLength(s.items)<s.count;if(allowPrev||allowNext){t._0(w,"‹‹&nbsp;First&nbsp;",allowPrev,"DataGrid.showFirstPage("+sid+")","First Page");t._0(w,"‹&nbsp;Previous",allowPrev,"DataGrid.showPreviousPage("+sid+")","Previous Page");w("&nbsp;&nbsp;&nbsp;");t._0(w,"Next&nbsp;›&nbsp;",allowNext,"DataGrid.showNextPage("+sid+")","Next Page");t._0(w,"Last&nbsp;››",allowNext,"DataGrid.showLastPage("+sid+")","Last Page")}w("</td></tr>");w("</table></div>")},_3:function(w,s){var m=s.module;if(U.owner){var layouts=m.dataGrid.ownerLayouts;if(layouts&&layouts.length>1){var lid=s.lid||m.defaultLayout;for(var i=0;i<layouts.length;i++){if(i>0)w(" | ");var layout=layouts[i];var layoutObj=m.layouts[layout];var layoutTitle=(layoutObj&&layoutObj.title)?layoutObj.title:layout;if(lid==layout){w(layoutTitle)}else{w("<a href='' onclick='Section.setLayout(",s.nodeId,",\"",layout,"\",true);return false;'>",layoutTitle,"</a>")}}}}},_0:function(w,label,enabled,onclick,tooltip){var tipAttr=(tooltip)?" title='"+tooltip+"'":"";w((enabled?"<a href='' onclick='"+onclick+";return false;'"+tipAttr+" >":"<span"+tipAttr+" >"),label,(enabled?"</a>":"</span>"))},renderSortLink:function(w,s,sortOrder,label){var title="Sort by "+label;if(s.sortOrder==sortOrder){if(s.sortDescending){label+=" &#x25bc;"}else{label+=" &#x25b2;";title+=" (Descending)"}}w("<a href=''",Html.attribute("title",title)," onclick='DataGrid.sortResults(",s.nodeId,",\"",sortOrder,"\");return false;'>",label,"</a>")},renderSelectionCheckbox:function(w,s,index,item){if(U.owner){var id=s.nodeId+".selected."+index;w("<input type=checkbox id='",id,"'",(item?Html.attribute("n:nodeId",item.nodeId):"")," onclick='DataGrid._2(",s.nodeId,",\"",id,"\");' />")}},renderEmptyList:function(w,s,items,cols){if(!items||!items.length){var m=s.module;w("<tr><td colspan='",cols,"' class='bc-highlight' style='padding:10px;'>No "+m.itemsName,(s.nameFilter?" for &quot;"+s.nameFilter+"&quot;":""),"</td></tr>")}},renderFooter:function(w,s){DataGrid.renderNavBar(w,s)},formatSelectionTitle:function(s,count){var sid=s.nodeId;var m=s.module;var dispCount=Array.getLength(s.items);var allCount=s.count||0;var itemName=m.itemName.toLowerCase();var itemsName=m.itemsName.toLowerCase();var title=count.toCount(itemName);if(s.selectAll){if(s.nameFilter){title+=" for &quot;"+s.nameFilter+"&quot;"}else{title="All "+title}}title="<b>"+title+"</b> selected.   Select: ";var delim="";if(count>0){title+="<a class=showLink href='' onclick='DataGrid.selectNone("+sid+"); return false;'>none</a>";delim=", "}if(dispCount!=allCount&&count!=dispCount){title+=delim+"<a class=showLink href='' onclick='DataGrid.selectDisplayed("+sid+"); return false;'>"+dispCount.toN0()+" displayed "+itemsName+"</a>";delim=", "}if(count!=allCount){title+=delim+"<a class=showLink href='' onclick='DataGrid.selectAll("+sid+"); return false;'>"+(s.nameFilter?allCount.toCount(itemName)+" for &quot;"+s.nameFilter+"&quot;":"all "+allCount.toCount(itemName))+"</a>"}return title},showSelectionBar:function(s,show){var e=Dom.getParentByTag(Dom.getElement(s.nodeId+".selectionTitleHeader"),"TABLE");if(show){Dom.addClass(e,"dg-selection")}else{Dom.removeClass(e,"dg-selection")}},updateSelectedTitles:function(s){var t=DataGrid;var sid=s.nodeId;var count=(s.selectAll?s.count:t.getSelected(sid).length);t.showSelectionBar(s,count>0);var html=t.formatSelectionTitle(s,count);Dom.setHtml(Dom.getElement(sid+".selectionTitleHeader"),html);Dom.setHtml(Dom.getElement(sid+".selectionTitleFooter"),html);var e=Dom.getElement(sid+".selected.-1");if(e)e.checked=count>=Array.getLength(s.items);e=Dom.getParentByTag(e,"TABLE");if(s.selectAll){Dom.addClass(e,"dg-selectAll")}else{Dom.removeClass(e,"dg-selectAll")}},getSelected:function(sid){var a=[];var s=page.nodes[sid];if(s){var count=Array.getLength(s.items);for(var i=0;i<count;i++){var id=s.nodeId+".selected."+i;var e=Dom.getElement(id);if(e&&e.checked){var itemId=Dom.getAttribute(e,"n:nodeId");if(itemId){var item=page.nodes[itemId];if(item)a.push(item)}}}}return a},getSelectionInfo:function(s){var m=s.module;var g=m.dataGrid;var args={};var message;var itemName=m.itemName.toLowerCase();var itemsName=m.itemsName.toLowerCase();var count=0;if(s.selectAll){count=s.count;if(s.nameFilter){message="all "+count.toCount(itemName)+" for \""+s.nameFilter+"\"";args={mode:"all",count:count,nameFilter:s.nameFilter}}else{message="all "+count.toCount(itemName);args={mode:"all",count:count}}}else{var md=m.dataGrid;var a=DataGrid.getSelected(s.nodeId);count=a.length;if(count==1){message=md.getSelectionTitle(a[0])}else{message="the "+count.toN0()+" selected "+itemsName}var names="";var itemId=md.itemId;for(var i=0;i<count;i++){if(names.length)names+=",";names+=a[i][itemId]}args={mode:"selection",names:names}}args.website=s.website;return{message:message,count:count,args:args}},getItems:function(s,options){if(s){Dom.setHtml(s.nodeId+".title","Loading...");var args={website:s.website,section:s.nodeId,startIndex:s.startIndex,nameFilter:s.nameFilter,sortOrder:s.sortOrder,sortDescending:s.sortDescending,layout:s.lid};Object.extend(args,options);var state={sid:s.nodeId};C.beginExec(s.module.dataGrid.getCommand,args,DataGrid._4,state)}},_4:function(response,state){var s=page.nodes[state.sid];if(s&&!response.error){var result=response.result;if(result&&result.section){ContentItem.initItems(s,result.section.items);Object.extend(s,result.section);Section.refreshContentHtml(s);var e=Dom.getElement(s.nodeId+".search");Dom.setInputFocus(e)}}},_2:function(sid,id){var t=DataGrid;var s=page.nodes[sid];s.selectAll=false;var e=Dom.getElement(id);if(e){if(id.endsWith(".-1")){if(e.checked){t.selectDisplayed(sid)}else{t.selectNone(sid)}}else{var tr=Dom.getParentByTag(e,"TR");if(tr){if(e.checked){Dom.addClass(tr,"dg-selected")}else{Dom.removeClass(tr,"dg-selected")}Dom.addClass(Dom.getParentByTag(tr,"TABLE"),"dg-selection");t.updateSelectedTitles(s)}}}}};function DataRowWriter(w,item){this.w=w;this.item=item;this.count=0};Object.extend(DataRowWriter.prototype,{writeCell:function(fields){var w=this.w;var item=this.item;if(this.count){w("<td class='dg-lb'>")}else{w("<td>")}var v;var first=true;for(var i=0;i<arguments.length;i++){var field=arguments[i];if(field){if(field.getValue){v=field.getValue(item)}else{v=item[field.name]}if(v){if(first){first=false}else{w("<br/>")}w(v)}}}w("</td>");this.count++}});