// 
//	TYGR Productions Interactive Statistics
//	
//	This file contains JavaScript support functions for TYGR Productions' Interactive Statistics.  The code contained herein
//  is NOT in the public domain.  This file is provided for download to personal computers and is only authorized for personal 
//  use in conjuction with TYGR Productions' Interactive Statistics.  Copying or reposting this file in whole or in part on 
//  any web server or other network server, or reusing any portion of the code is not allowed without express written consent 
//  of the author.  Any commercial use is strictly prohibited.
//	
//	Copyright (c) 2005, 2006 by Jon T. Camp.  All rights reserved.
// 
function sortValues(tableData, nIndex, aPointers, aSorted, aValues) 
{
	for (var i = 0; i < aValues.length; i++) 
	{
		var nInsertIndex = aSorted.length;
		
		for (var j = 0; j < aSorted.length; j++) 
		{
			// special cases
			if ((tableData.Table.id == "tableKickingId") && ((tableData.IDs[nIndex] == "fgma") || (tableData.IDs[nIndex] == "patma")))
			{
				// must be int/int
				var aParts1 = aValues[i].split("/");
				var aParts2 = aSorted[j].split("/");
				
				if ((Number(aParts1[0]) < Number(aParts2[0])) || ((Number(aParts1[0]) == Number(aParts2[0])) && (Number(aParts1[1]) > Number(aParts2[1]))))
				{
					nInsertIndex = j;
					break;
				}
			}
			// special cases
			else if (((tableData.Table.id == "tablePassingOffenseId") || (tableData.Table.id == "tablePassingDefenseId")) && (tableData.IDs[nIndex] == "attcmp"))
			{
				// must be int/int
				var aParts1 = aValues[i].split("/");
				var aParts2 = aSorted[j].split("/");
				
				if ((Number(aParts1[1]) < Number(aParts2[1])) || ((Number(aParts1[1]) == Number(aParts2[1])) && (Number(aParts1[0]) > Number(aParts2[0]))))
				{
					nInsertIndex = j;
					break;
				}
			}
			// special cases
			else if ((tableData.Table.id == "tableOtherId") && ((tableData.IDs[nIndex] == "wl") || (tableData.IDs[nIndex] == "sec")))
			{
				// must be int-int
				var aParts1 = aValues[i].split("-");
				var aParts2 = aSorted[j].split("-");
				
				if ((Number(aParts1[0]) < Number(aParts2[0])) || ((Number(aParts1[0]) == Number(aParts2[0])) && (Number(aParts1[1]) > Number(aParts2[1]))))
				{
					nInsertIndex = j;
					break;
				}
			}
			else if (tableData.ByValue[nIndex]) 
			{
				if (Number(aValues[i]) < Number(aSorted[j])) 
				{
					nInsertIndex = j;
					break;
				}
			}
			else 
			{
				if (aValues[i] < aSorted[j]) 
				{
					nInsertIndex = j;
					break;
				}
			}
		}
		
		for (var j = aSorted.length; j > nInsertIndex; j--) 
		{
			aSorted[j] = aSorted[j - 1];
			aPointers[j] = aPointers[j - 1];
		}
		
		aSorted[nInsertIndex] = aValues[i];
		aPointers[nInsertIndex] = tableData.Ptr[i];
	}
	
	if (tableData.Descending[nIndex]) 
	{
		aPointers.reverse();
		aSorted.reverse();
	}
}
