// To Do
// build discard system.

var pto = new Array()

function Entry(Index,Score)
	{
    this.INDEX = parseInt(Index);
    this.SCORE = Score;
	}

function createPTO()
	{
	for(a=1;a<pti.length;a++)
		{
		pilotTotal=0;
		te = pti[a].split(",");
		rc = te.length - 7;
			for(b=(te.length-rc);b<te.length;b++)
				{
				pilotTotal = pilotTotal + parseInt(te[b]);
				}
				pilotTotal = pilotTotal + parseInt(te[1]);
				pto[pto.length++] = new Entry(a,pilotTotal);
		}
		pto.sort(sortByScore);
		var oStr = "<table border='1' width='100%' cellspacing='0'>"
		thisHeader = pti[0].split(",");
		oStr = oStr + "<tr>";
		oStr = oStr + "<td class='body'><b>Position</b></td>";
		oStr = oStr + "<td class='body'><b>"+thisHeader[0]+"</b></td>";
		oStr = oStr + "<td class='body' align='center'><b>"+thisHeader[2]+"</b></td>";
		oStr = oStr + "<td class='body' align='center'><b>"+thisHeader[1]+"</b></td>";
		oStr = oStr + "<td class='body'><b>Competitor</b></td>";
		oStr = oStr + "<td class='body' align='center'><b>"+thisHeader[5]+"</b></td>";
		oStr = oStr + "<td class='body' align='center'><b>"+thisHeader[6]+"</b></td>";
		for(c=7;c<thisHeader.length;c++)
				{
				oStr = oStr + "<td class='body' align='center'><b>"+thisHeader[c]+"</b></td>";
				}
			oStr = oStr + "</tr>";
		for(d=0;d<pto.length;d++)
			{
				thisItem = parseInt(pto[d].INDEX);
				thisEntry = pti[thisItem].split(",");
				oStr = oStr + "<tr>";
				oStr = oStr + "<td class='body'>"+(d+1)+"</td>";
				oStr = oStr + "<td class='body'>"+thisEntry[0]+"</td>";
				oStr = oStr + "<td class='body' align='center'>"+pto[d].SCORE+"</td>";
				oStr = oStr + "<td class='body' align='center'>"+thisEntry[1]+"</td>";
				oStr = oStr + "<td class='body'>"+thisEntry[4]+thisEntry[3]+"</td>";
				oStr = oStr + "<td class='body' align='center'>"+thisEntry[5]+"</td>";
				oStr = oStr + "<td class='body' align='center'>"+thisEntry[6]+"</td>";
				for(e=7;e<thisEntry.length;e++)
					{
					oStr = oStr + "<td class='body' align='center'>"+thisEntry[e]+"</td>";
					}
				oStr = oStr + "</tr>";
			}
			oStr = oStr + "</table>";
		document.getElementById('list').innerHTML = "<center><font face='arial' color='#FFFFFF' size='5'><b>"+thisSeries+"</b></font><p>"+ oStr + "<p><font face='arial' size='1' color='#FFFFFF'>NO UNAUTHORISED REPRODUCTION OF THESE RESULTS IS PERMITTED. WRITTEN PERMISSION MUST BE OBTAINED FROM THE PARAKART ASSOCIATION.<p>&copy; 2003-2008 Time-IT!</font></center>";
	}
function sortByScore(a, b)
	{
	var x = a.SCORE;
	var y = b.SCORE;
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
	}
