
function get(id)
{return document.getElementById(id);}
function bindEvent(node,event,context,func,var_args)
{var preventDefault,sendEvent,sendNode,args,fn;var_args=(var_args&&typeof var_args==="object")?var_args:{};preventDefault=var_args.preventDefault!==undefined?var_args.preventDefault:true;sendEvent=var_args.sendEvent!==undefined?var_args.sendEvent:true;sendNode=var_args.sendNode!==undefined?var_args.sendNode:false;args=var_args.args?var_args.args:[];if(typeof node==='string')
{node=get(node);}
if(!node)
{return{node:null,event:null,listener:null};}
fn=function(e)
{var eventArgs;if(preventDefault)
{if(e.preventDefault)
{e.preventDefault();}
else
{e.returnValue=false;}}
eventArgs=[];if(sendEvent)
{eventArgs.push(e);}
if(sendNode)
{eventArgs.push(node);}
return func.apply(context,eventArgs.concat(args));};if(node.addEventListener)
{node.addEventListener(event,fn,false);}
else
{node.attachEvent("on"+event,fn);}
return{node:node,event:event,listener:fn};}
function removeEvent(params)
{if(!params||!params.node)
{return;}
if(params.node.removeEventListener)
{params.node.removeEventListener(params.event,params.listener,false);}
else
{params.node.detachEvent('on'+params.event,params.listener);}}
function externalLinks()
{var anchors,len,i;if(document.getElementsByTagName)
{anchors=document.getElementsByTagName("a");}
if(!anchors)
{return;}
len=anchors.length;for(i=0;i<len;i+=1)
{if(anchors[i].getAttribute("href")&&anchors[i].getAttribute("rel")==="external")
{anchors[i].target="_blank";}}} 
function XcLeagues()
{this.page={};this.current={};this.clubIndex=0;this.clubEnabled=true;this.leagues=[];this.leaguesCount=0;this.years=[];this.yearsCount=0;this.selLeague=null;this.selShow=null;this.selYear=null;this.goButton=null;this.expired="0";this.classValidText="txtBlack";this.classInvalidText="txtLtGray";this.classValidSelect="select120";this.classInvalidSelect="select120Gray";this.expiredFilter="2";this.yearCurrent="0";this.events=[];}
XcLeagues.prototype.init=function(params)
{var form,opts,i,j;this.page={league:params.league.toString(),show:params.show?params.show.toString():'',year:params.year.toString()};this.current={league:this.page.league,show:this.page.show,year:this.page.year};this.clubIndex=params.clubIndex;form=document.forms.leagueForm;if(form)
{opts={sendEvent:false,args:[null]};this.selLeague=form.leagueView;this.events.push(bindEvent(this.selLeague,'change',this,this.changeLeague,opts));this.events.push(bindEvent(this.selLeague,'keyup',this,this.changeLeague,opts));opts={sendEvent:false};if(form.showView)
{this.selShow=form.showView;this.events.push(bindEvent(this.selShow,'change',this,this.changeShow,opts));this.events.push(bindEvent(this.selShow,'keyup',this,this.changeShow,opts));}
else
{this.toggleClub=function(){};}
this.selYear=form.year;this.events.push(bindEvent(this.selYear,'change',this,this.changeYear,opts));this.events.push(bindEvent(this.selYear,'keyup',this,this.changeYear,opts));opts={sendEvent:false,args:[this]};this.goButton=get('bg');this.events.push(bindEvent(this.goButton,'click',params.go.context,params.go.func,opts));if(form.expired&&form.expired.value==="1")
{this.expired=this.expiredFilter;}
this.leaguesCount=params.leagues.length;for(i=0;i<this.leaguesCount;i+=1)
{this.leagues[i]={value:parseInt(params.leagues[i].value,10),start:parseInt(params.leagues[i].start,10),end:parseInt(params.leagues[i].end,10),clubId:params.leagues[i].clubId,missing:params.leagues[i].missing,missingCount:params.leagues[i].missing.length,valid:true};for(j=0;j<this.leagues[i].missingCount;j+=1)
{this.leagues[i].missing[j]=parseInt(this.leagues[i].missing[j],10);}}
this.yearsCount=this.selYear.options.length;for(i=0;i<this.yearsCount;i+=1)
{this.years[i]={value:parseInt(this.selYear.options[i].value,10),valid:true};}
if(this.selYear.options[this.yearsCount-1].value==='all')
{this.years[this.yearsCount-1].value=0;}
this.yearCurrent=params.yearCurrent;this.changeYear();}};XcLeagues.prototype.isValid=function(year,league)
{if(year>=league.start&&year<=league.end)
{if(league.missingCount)
{return!this.inArray(year,league.missing);}
else
{return true;}}
else if(year===0)
{return league.end>league.start;}
else
{return false;}};XcLeagues.prototype.setLeagues=function(year)
{var i;for(i=0;i<this.leaguesCount;i+=1)
{this.leagues[i].valid=this.isValid(year,this.leagues[i]);this.selLeague[i].className=this.leagues[i].valid?this.classValidText:this.classInvalidText;}};XcLeagues.prototype.setYears=function(league)
{var i;for(i=0;i<this.yearsCount;i+=1)
{this.years[i].valid=this.isValid(this.years[i].value,league);this.selYear[i].className=this.years[i].valid?this.classValidText:this.classInvalidText;}};XcLeagues.prototype.changeLeague=function(leagueIndex)
{var year,i;if(leagueIndex!==null)
{this.selLeague.selectedIndex=leagueIndex;this.current.league=this.selLeague[this.selLeague.selectedIndex].value;}
else
{this.current.league=this.selLeague[this.selLeague.selectedIndex].value;if(!this.leagues[this.selLeague.selectedIndex].valid)
{year=this.leagues[this.selLeague.selectedIndex].end;for(i=this.yearsCount-1;i>=0;i-=1)
{if(this.years[i].value&&this.years[i].value===year)
{this.selYear.selectedIndex=i;this.current.year=this.selYear[this.selYear.selectedIndex].value;break;}}
this.setLeagues(year);}}
this.setYears(this.leagues[this.selLeague.selectedIndex]);this.toggleClub();this.toggleGo();};XcLeagues.prototype.changeYear=function()
{var year,i,leagueIndex;this.current.year=this.selYear[this.selYear.selectedIndex].value;year=this.years[this.selYear.selectedIndex].value;leagueIndex=null;if(!this.years[this.selYear.selectedIndex].valid)
{for(i=0;i<this.leaguesCount;i+=1)
{if(this.isValid(year,this.leagues[i]))
{leagueIndex=i;break;}}}
this.setLeagues(year);this.changeLeague(leagueIndex);};XcLeagues.prototype.changeShow=function()
{this.current.show=this.selShow[this.selShow.selectedIndex].value;this.toggleClub();this.toggleGo();};XcLeagues.prototype.toggleClub=function()
{var valid;valid=!this.leagues[this.selLeague.selectedIndex].clubId;this.selShow[this.clubIndex].className=valid?this.classValidText:this.classInvalidText;if(this.selShow.selectedIndex!==this.clubIndex)
{valid=true;}
if((valid&&!this.clubEnabled)||(!valid&&this.clubEnabled))
{this.selShow.className=valid?this.classValidSelect:this.classInvalidSelect;this.clubEnabled=valid;}};XcLeagues.prototype.toggleGo=function()
{if(this.page.league===this.current.league&&this.page.show===this.current.show&&this.page.year===this.current.year)
{this.goButton.disabled=true;}
else
{this.goButton.disabled=(this.selShow&&this.selShow.className===this.classInvalidSelect);}};XcLeagues.prototype.inArray=function(needle,ar)
{var i,len;for(i=0,len=ar.length;i<len;i+=1)
{if(needle===ar[i])
{return true;}}};XcLeagues.prototype.unload=function()
{var i,len;for(i=0,len=this.events.length;i<len;i+=1)
{removeEvent(this.events[i]);}}; 
function XcTables()
{this.xcLeagues=null;this.baseUrl="";this.currentParam="view";this.viewParam="vx";this.events=[];}
XcTables.prototype.init=function(params)
{var opts,i,len,id;params.go={context:this,func:this.showLeague};this.xcLeagues=new XcLeagues();this.xcLeagues.init(params);opts={sendEvent:false};for(i=0,len=params.clubs.length;i<len;i+=1)
{id='cb-'+params.clubs[i].id;opts.args=[params.clubs[i].id,params.clubs[i].name];this.events.push(bindEvent(id,'click',this,this.showClub,opts));}};XcTables.prototype.showLeague=function(xcLeagues)
{var page,qs;if(xcLeagues.current.year===xcLeagues.yearCurrent)
{page=this.currentParam+"-"+xcLeagues.current.league+".html";}
else
{page=xcLeagues.current.year+"-"+xcLeagues.current.league+".html";}
if(xcLeagues.current.show==="1"&&xcLeagues.expired==="0")
{qs="";}
else
{qs="?"+this.viewParam+"="+xcLeagues.current.show;qs+=xcLeagues.expired;}
location.href=this.baseUrl+page+qs;};XcTables.prototype.showClub=function(id,name)
{var block,link;block=document.getElementById("block"+id);link=document.getElementById("cb-"+id);if(block.style.display==="none")
{block.style.display="block";link.className="viewLinkHide";link.title="Hide non-scoring "+name+" pilots";link.firstChild.nodeValue="Hide Other Pilots";}
else
{block.style.display="none";link.className="viewLinkShow";link.title="Show non-scoring "+name+" pilots";link.firstChild.nodeValue="Show Other Pilots";}};XcTables.prototype.unload=function()
{var i,len;for(i=0,len=this.events.length;i<len;i+=1)
{removeEvent(this.events[i]);}
if(this.xcLeagues.unload)
{this.xcLeagues.unload();}};window['App']=new XcTables();
