var tF = {
addEvent: function(elm, evType, fn, useCapture) {
// cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
},

ascendDOM: function(e, target) {
// climb up the tree to the supplied tag.
	while (e.nodeName.toLowerCase() != target && e.nodeName.toLowerCase() != 'html')
		e = e.parentNode;
	return (e.nodeName.toLowerCase() == 'html') ? null : e;
},

hl_on: function(e) {
// turn on highlighting
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	var parent_row = tF.ascendDOM(el, 'tr');
	if (parent_row == null) return;
	parent_row.className = parent_row.className.replace(/hi/, 'lo');
},

hl_off: function(e) {
// turn off highlighting
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	var parent_row = tF.ascendDOM(el, 'tr');
	if (parent_row == null) return;
	parent_row.className = parent_row.className.replace(/lo/, 'hi');
},

showtype: function(e) {
// show new section of table
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	tF.clearTeamList();
	var typestatus = [0, 0, 0, 0, 0, 0, 0, 0];
	tF.rowCount = tF.firstDisp = tF.firstSel = tF.lastSel = tF.selTotal = 0;
	var args=el.className.split(" ");
	var divide = 1000;
	if (args.length > 1) {
		var a = args[1];
		typestatus[a] = 1;
		if (args.length > 2) {
			a = args[2];
			typestatus[a] = 1;
			divide = 100;
		}
	} else {
		typestatus = [1, 1, 1, 1, 1, 1, 1, 1];
	}
	for (var i = 0; i < tF.nRows; i++) {
		tF.rowtoggle(i,tF.tab.rows[i].cells[2].firstChild.nodeValue == "Out"?0:typestatus[Math.floor(tF.tab.rows[i].cells[0].firstChild.nodeValue / divide)]);
	}
	tF.selection.nodeValue=el.firstChild.nodeValue;
	tF.showlinks();
},

showclub: function(e) {
// show new section of table
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	var club = el.firstChild.nodeValue.substr(0, 3);
	if ((" " + el.className + " ").indexOf(" sel ") == -1) {
		el.className += " sel";
		tF.teamList[tF.teamList.length] = club;
	} else {
		el.className=el.className.replace(/ sel/, '');
		tF.teamList.splice(tF.teamList.indexOf(club),1);
	}
	tF.teamList.sort();
	tF.rowCount = tF.firstDisp = tF.firstSel = tF.lastSel = tF.selTotal = 0;
	for (var i = 0; i < tF.nRows; i++) {
		tF.rowtoggle(i,tF.teamList.indexOf(tF.tab.rows[i].cells[2].firstChild.nodeValue.substr(0, 3))>-1);
	}
	tF.selection.nodeValue=tF.teamList.join(", ");
	tF.showlinks();
},

rowtoggle: function(i,tog) {
// set display or not
	if (tF.rowCount < tF.pageCount) {
		tF.lastDisp = i;
	}
	if (tog) {
		tF.tab.rows[i].showRow = 1;
		tF.selTotal++;
		if (tF.rowCount < tF.pageCount) {
			tF.tab.rows[i].style.display = "";
			tF.lastSel = tF.rowCount++;
		} else {
			tF.tab.rows[i].style.display = "none";
		}
	} else {
		tF.tab.rows[i].showRow = 0;
		tF.tab.rows[i].style.display = "none";
	}
},

nextprev: function(e) {
// show next/prev section of table
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	var direc = el.firstChild.nodeValue.substr(0,4);
	if (tF.lastSel==tF.selTotal-1&&direc=="Next"||tF.firstSel==0&&direc=="Prev") return;
	for (var i=tF.firstDisp; i<tF.lastDisp+1; i++) {
		if (tF.tab.rows[i].showRow) {
			tF.tab.rows[i].style.display = "none";
		}
	}
	tF.rowCount=0;
	if (direc=="Next") {
		tF.firstDisp=tF.lastDisp+1;
		tF.firstSel=tF.lastSel+1;
		for (var i=tF.firstDisp; i<tF.nRows&&tF.rowCount<tF.pageCount; i++) {
			if (tF.tab.rows[i].showRow) {
				tF.tab.rows[i].style.display = "";
				tF.rowCount++;
			}
			tF.lastDisp=i;
		}
		tF.lastSel=tF.firstSel+tF.rowCount-1;
	} else {
		tF.lastDisp=tF.firstDisp-1;
		tF.lastSel=tF.firstSel-1;
		for (var i=tF.lastDisp; i>=0&&tF.rowCount<tF.pageCount; i--) {
			if (tF.tab.rows[i].showRow) {
				tF.tab.rows[i].style.display = "";
				tF.rowCount++;
			}
			tF.firstDisp=i;
		}
		tF.firstSel=tF.lastSel-tF.rowCount+1;
	}
	tF.showlinks();
},

showall: function() {
// show all of current selection
	if (tF.lastSel+1 < tF.pageCount) return;
	for (var i=0; i<tF.nRows; i++) {
		if (tF.tab.rows[i].showRow) {
			tF.tab.rows[i].style.display = "";
		}
	}
	tF.firstSel=0;
	tF.lastSel=tF.selTotal-1;
	tF.showlinks();
},

showlinks: function() {
// show/hide parts of table footer
	if (tF.selTotal) {
		tF.lcfirst.nodeValue=tF.firstSel+1;
		tF.lclast.nodeValue=tF.lastSel+1;
		if (tF.lastSel+1 == tF.selTotal) {
			document.getElementById("nextlink").style.display = "none";
		} else {
			document.getElementById("nextlink").style.display = "";
		}
		if (tF.firstSel == 0) {
			document.getElementById("prevlink").style.display = "none";
		} else {
			document.getElementById("prevlink").style.display = "";
		}
		if (tF.lastSel+1 == tF.selTotal && tF.firstSel == 0) {
			document.getElementById("showall").style.display = "none";
		} else {
			document.getElementById("showall").style.display = "";
		}
	} else {
		tF.lcfirst.nodeValue=0;
		tF.lclast.nodeValue=0;
		document.getElementById("nextlink").style.display = "none";
		document.getElementById("prevlink").style.display = "none";
		document.getElementById("showall").style.display = "none";
	}
	tF.lctotal.nodeValue=tF.selTotal;
},

clearTeamList: function() {
	tF.teamList = [];
	var all_links = document.getElementsByTagName('a');
	for (var i = 0; i < all_links.length; i++) {
		if ((" " + all_links[i].className + " ").indexOf(" clubtype ") != -1) {
			all_links[i].className=all_links[i].className.replace(/ sel/, '');
		}
	}
},

addListeners: function() {
	if (!document.getElementsByTagName) return;
	var all_cells = document.getElementsByTagName('tr');
	for (var i = 0; i < all_cells.length; i++) {
		tF.addEvent(all_cells[i], 'mouseover', tF.hl_on, false);
		tF.addEvent(all_cells[i], 'mouseout', tF.hl_off, false);
	}
	var all_links = document.getElementsByTagName('a');
	for (var i = 0; i < all_links.length; i++) {
		if ((" " + all_links[i].className + " ").indexOf(" playtype ") != -1) {
			tF.addEvent(all_links[i], 'click', tF.showtype, false);
		}
		if ((" " + all_links[i].className + " ").indexOf(" clubtype ") != -1) {
			tF.addEvent(all_links[i], 'click', tF.showclub, false);
		}
		if ((" " + all_links[i].className + " ").indexOf(" listtype ") != -1) {
			tF.addEvent(all_links[i], 'click', tF.nextprev, false);
		}
		if ((" " + all_links[i].className + " ").indexOf(" showall ") != -1) {
			tF.addEvent(all_links[i], 'click', tF.showall, false);
		}
		if ((" " + all_links[i].className + " ").indexOf(" sort ") != -1) {
			tF.addEvent(all_links[i], 'click', tF.colsort, false);
		}
	}
	tF.tab = document.getElementById("tab");
	tF.nRows = tF.tab.rows.length;
	tF.selTotal = 0;
	for (var i = 0; i < tF.nRows; i++) {
		tF.rowtoggle(i,tF.tab.rows[i].cells[2].firstChild.nodeValue == "Out"?0:1);
	}
	tF.lcfirst = document.getElementById("lcfirst").firstChild;
	tF.lclast = document.getElementById("lclast").firstChild;
	tF.lctotal = document.getElementById("lctotal").firstChild;
	tF.selection = document.getElementById("selection").firstChild;
	tF.selection.nodeValue = "All Players";
	tF.showlinks();
},

colsort: function(e) {
// sort table on a different column
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;

	var tempTab=new Array(tF.nRows);
	var args=el.className.split(" ");
	var col1=args[1];
	if (args[2]==undefined||args[2]==0) {
		tF.asc1 = false;
	} else {
		tF.asc1 = true;
	}
	var col2=args[3];
	if (args[4]==undefined||args[4]==0) {
		tF.asc2 = false;
	} else {
		tF.asc2 = true;
	}
	for (var i=0; i<tF.nRows; i++)
    {
		tempTab[i]=new Array(3);
    	tempTab[i][0]=tF.tab.rows[i];
        tempTab[i][1]=tF.chkdate(tF.tab.rows[i].cells[col1].innerHTML);
		if (col2!=null)
		{
	        tempTab[i][2]=tF.chkdate(tF.tab.rows[i].cells[col2].innerHTML);
		}
    }
	tempTab=tempTab.sort(tF.compare);
	tF.lastSel = tF.firstSel = tF.firstDisp = 0;
    for (var i=0;i<tF.nRows;i++)
    {
		if (tF.lastSel < tF.pageCount) {
			tF.lastDisp = i;
		}
		if (tF.lastSel < tF.pageCount && tempTab[i][0].showRow) {
			tempTab[i][0].style.display = "";
			tF.lastSel++;
		} else {
			tempTab[i][0].style.display = "none";
		}
        tF.tab.appendChild(tempTab[i][0]);
    }
	tF.lastSel--;
	tF.showlinks();
},

compare: function(a, b)
{
	return ((a[1]==b[1]?(tF.asc2?a[2]>b[2]:a[2]<b[2]):(tF.asc1?a[1]>b[1]:a[1]<b[1]))?1:(a[1]==b[1]&&a[2]==b[2])?0:-1);
},

chkdate: function(a)
{
	if (a=="&nbsp;") return(0);
	if (a.charAt(2)=='/'&&a.charAt(5)=='/')
	{
		b=a.split("/");
		return (b[2].concat(b[1],b[0]));
	} else {
		b=parseFloat(a);
		if (isNaN(b))
		{
			return (a);
		} else {
			return (b);
		}
	}
},

firstDisp: 0,
lastDisp: 0,
rowCount: 0,
selCount: 0,
selTotal: 0,
firstSel: 0,
lastSel: 0,
pageCount: 25,
asc1: false,
asc2: false,
teamList: []
}
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;
    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}
tF.addEvent(window, 'load', tF.addListeners, false);