else entries[j][i]['header'] = 'Round '..j
end
else
entries[j][i]['header'] = 'Lower round '..j
end
end  
return headerCell(tbl,j,i,entry_colspan)
end  
if entries[j][i]['ctype']=='team' then
if byes[j][entries[j][i]['headerindex']] and isBlankEntry(j,i) then
return blankCell(tbl,j,i,2,entry_colspan)
end
if hide[j][entries[j][i]['headerindex']] then
return blankCell(tbl,j,i,2,entry_colspan)
end  
local legs = teamLegs(j,i)
local team_colspan  
team_colspan = maxlegs[j]-legs+1
if aggregate and legs==1 and maxlegs[j]>1 then
team_colspan=team_colspan+1
end
if maxlegs[j]==0 then
team_colspan=team_colspan+1
end  
if seeds then
if showSeeds(j,i)==true then
teamCell(tbl,'seed',j,i)
else
team_colspan=team_colspan+1
end
end
teamCell(tbl,'team',j,i,nil,team_colspan)
for l=1,legs do
teamCell(tbl,'score',j,i,l)
end
if aggregate and legs>1 then
teamCell(tbl,'score',j,i,'agg')
end
end  
if entries[j][i]['ctype']=='text' then
blankCell(tbl,j,i,2,entry_colspan,entries[j][i]['text'])
end  
if entries[j][i]['ctype']=='group' then
local colspan=0
for m=j,entries[j][i]['colspan']+j-1 do
colspan=colspan+maxlegs[m]+2
if not seeds then colspan=colspan-1 end
if (aggregate and maxlegs[m]>1) or maxlegs[m]==0 then
colspan=colspan+1
end
end
colspan = colspan+2*(entries[j][i]['colspan']-1)
blankCell(tbl,j,i,2,colspan,entries[j][i]['group'],'')
end  
if entries[j][i]['ctype']=='line' then
tbl:tag('td')
:attr('rowspan',2)
:attr('colspan',entry_colspan)
:css('-bottom',' solid black')
:wikitext(entries[j][i]['text'])
end
end  
local function isRoundHidden(j,i,headerindex)
if notempty(entries[j][i]['pheader']) then
hide[j][entries[j][i]['headerindex']] = false
end
local row = i+1
repeat
if not isBlankEntry(j,row) then
hide[j][entries[j][i]['headerindex']] = false
end
row = row+1
until (entries[j][row]~=nil and entries[j][row]['ctype']=='header') or row>r
end  
local function paramNames(cname,j,i,l)
local rname = {
{'RD'..j, bargs('RD'..j..'-altname') or 'RD'..j},
{'RD'..j..toChar(entries[j][i]['headerindex']),bargs('RD'..j..toChar(entries[j][i]['headerindex'])..'-altname') or 'RD'..j..toChar(entries[j][i]['headerindex'])}
}
local name = {cname, bargs(cname..'-altname') or cname}
local index = {entries[j][i]['index'], entries[j][i]['altindex']}
local result = {}
if cname=='header' then
if entries[j][i]['headerindex']==1 then
for k=1,2 do
table.insert(result,bargs(rname[1][3-k]) or '')
table.insert(result,bargs(rname[2][3-k]) or '')
end
else
for k=1,2 do
table.insert(result,bargs(rname[2][3-k]) or '')
end
end
elseif cname=='pheader' then
if entries[j][i]['headerindex']==1 then
for k=1,2 do
table.insert(result,pargs[rname[1][3-k]] or '')
table.insert(result,pargs[rname[2][3-k]] or '')
end
else
for k=1,2 do
table.insert(result,pargs[rname[2][3-k]] or '')
end
end
elseif cname=='score' then
for m=1,2 do for k=1,2 do
if l==1 then
table.insert(result,bargs(rname[3-m][3-k]..'-'..name[1]..index[3-m]) or bargs(rname[3-m][3-k]..'-'..name[1]..'0'..index[3-m]) or '')
end
table.insert(result,bargs(rname[3-m][3-k]..'-'..name[1]..index[3-m]..'-'..l) or bargs(rname[3-m][3-k]..'-'..name[1]..'0'..index[3-m]..'-'..l) or '')
end end
elseif cname=='shade' then
for k=1,2 do
if entries[j][i]['headerindex']==1 then
table.insert(result,bargs(rname[1][3-k]..'-'..name[1]) or '')
else
table.insert(result,bargs(rname[2][3-k]..'-'..name[1]) or '')
end
end
table.insert(result,bargs('RD-shade'))
table.insert(result,'#F2F2F2')
elseif cname=='text' then
for n=1,2 do for m=1,2 do for k=1,2 do
table.insert(result,bargs(rname[3-m][3-k]..'-'..name[3-n]..index[3-m]) or bargs(rname[3-m][3-k]..'-'..name[3-n]..'0'..index[3-m]) or '')
end end end
else
for m=1,2 do for k=1,2 do
table.insert(result,bargs(rname[3-m][3-k]..'-'..name[1]..index[3-m]) or bargs(rname[3-m][3-k]..'-'..name[1]..'0'..index[3-m]) or '')
end end
end
for k=1,#result do
if notempty(result[k]) then
return result[k]
end
end
return ''
end  
local function indexedParams(j)
for i=1,r do
if entries[j][i]~=nil then
if entries[j][i]['ctype']=='team' then
local legs = rlegs[j]
if forceseeds then
entries[j][i]['seed'] = bargs(masterindex) or ''
masterindex = masterindex+1
end
entries[j][i]['team'] = bargs(tostring(masterindex)) or ''
masterindex = masterindex+1
entries[j][i]['legs'] = paramNames('legs',j,i)
entries[j][i]['score'] = {}
entries[j][i]['weight'] = 'normal'
entries[j][i]['score']['weight'] = {}
if notempty(entries[j][i]['legs']) then
legs = tonumber(entries[j][i]['legs'])
end
for l=1,legs do
entries[j][i]['score'][l] = bargs(tostring(masterindex)) or ''
masterindex = masterindex+1
entries[j][i]['score']['weight'][l] = 'normal'
end
if aggregate and legs>1 then
entries[j][i]['score']['agg'] = bargs(masterindex) or ''
masterindex = masterindex+1
entries[j][i]['score']['weight']['agg'] = 'normal'
end
end
if entries[j][i]['ctype']=='header' then
entries[j][i]['header'] = paramNames('header',j,i)
entries[j][i]['pheader'] = paramNames('pheader',j,i)
entries[j][i]['shade'] = paramNames('shade',j,i)
end
if entries[j][i]['ctype']=='text' then
entries[j][i]['text'] = bargs(tostring(masterindex)) or ''
masterindex = masterindex+1
end
if entries[j][i]['ctype']=='group' then
entries[j][i]['group'] = bargs(tostring(masterindex)) or ''
masterindex = masterindex+1
end
if entries[j][i]['ctype'] == 'line' and entries[j][i]['hastext']==true then
entries[j][i]['text'] = bargs(masterindex) or ''
masterindex = masterindex+1
end
end
end
end  
local function assignParams
masterindex = 1
local maxcol = 1
local byerows = 1
local hiderows = 1
for j=minc,c do
rlegs[j] = tonumber(bargs('RD'..j..'-legs')) or tonumber(bargs('legs')) or 1
if notempty(bargs('RD'..j..'-legs')) or bargs('legs') then autolegs = false end
if paramstyle == 'numbered' then
indexedParams(j)
else
for i=1,r do
if entries[j][i]~=nil then
if entries[j][i]['ctype']=='team' then
local legs = rlegs[j]
entries[j][i]['seed'] = paramNames('seed',j,i)
entries[j][i]['team'] = paramNames('team',j,i)
entries[j][i]['legs'] = paramNames('legs',j,i)
entries[j][i]['score'] = {}
entries[j][i]['weight'] = 'normal'
entries[j][i]['score']['weight'] = {}
if notempty(entries[j][i]['legs']) then
legs = tonumber(entries[j][i]['legs'])
end
if autolegs then
local l=1
repeat
entries[j][i]['score'][l] = paramNames('score',j,i,l)
entries[j][i]['score']['weight'][l] = 'normal'
l=l+1
until isempty(paramNames('score',j,i,l))
legs = l-1
else
for l=1,legs do
entries[j][i]['score'][l] = paramNames('score',j,i,l)
entries[j][i]['score']['weight'][l] = 'normal'
end
end
if aggregate and legs>1 then
entries[j][i]['score']['agg'] = paramNames('score',j,i,'agg')
entries[j][i]['score']['weight']['agg'] = 'normal'
end
end
if entries[j][i]['ctype']=='header' then
entries[j][i]['header'] = paramNames('header',j,i)
entries[j][i]['pheader'] = paramNames('pheader',j,i)
entries[j][i]['shade'] = paramNames('shade',j,i)
end
if entries[j][i]['ctype']=='text' then
entries[j][i]['text'] = paramNames('text',j,i)
end
if entries[j][i]['ctype']=='group' then
entries[j][i]['group'] = paramNames('group',j,i)
end
if entries[j][i]['ctype'] == 'line' and entries[j][i]['hastext']==true then
entries[j][i]['text'] = paramNames('text',j,i)
end
end
if autocol and not isBlankEntry(j,i) then
maxcol = math.max(maxcol,j)
end
end
end
for i=1,r do
if entries[j][i]~=nil and entries[j][i]['ctype']=='header' then
isRoundHidden(j,i)
end
if entries[j][i]~=nil and not hide[j][entries[j][i]['headerindex']] then
if not byes[j][entries[j][i]['headerindex']] or (byes[j][entries[j][i]['headerindex']] and not isBlankEntry(j,i)) then
byerows = math.max(byerows,i)
end
end
end
end
for j=minc,c do
for k=1,headerindex[j] do
if byes[j][k] or hide[j][k] then
r=byerows+1
end
end
end
if autocol then
c = maxcol
end
end  
local function getHide(j,headerindex)
hide[j] = {}
for k=1,headerindex[j] do
if bargs('RD'..j..toChar(k)..'-hide')=='yes' or bargs('RD'..j..toChar(k)..'-hide')=='y' then
hide[j][k]=true
end
end
end  
local function getByes(j,headerindex)
byes[j] = {}
for k=1,headerindex[j] do