// Global Functions Start
// New Window
function NewWindow(value, width, height)
{
	// Set height and width
	var NewWinHeight=height;
	var NewWinWidth=width;

	// Place the window
	var NewWinPutX=((screen.width/2)- (NewWinWidth/2));
	var NewWinPutY=((screen.height/2)- (NewWinHeight/2));
	//Get what is below onto one line
	TheNewWin=window.open(value, 'newwindow', config='toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no')

	//Get what is above onto one line
	TheNewWin.resizeTo(NewWinWidth,NewWinHeight);
	TheNewWin.moveTo(NewWinPutX,NewWinPutY);
}

function reverseSort(a, b) 
{ 
   if(a > b) 
      return -1 
   if(a < b) 
      return 1 
   return 0 
} 
function getloc()
{
	var locate = window.location
	document.advent.items.value = locate
	var text = document.advent.items.value
	var theleft = text.indexOf("=") + 1; 
	var theright = text.lastIndexOf("&");
	var value = text.substring(theleft, theright);
	return value;
}
function getloc2()
{
	var locate = window.location
	document.advent.items.value = locate
	var text = document.advent.items.value
	var point = text.lastIndexOf("=");
	return(text.substring(point+1,text.length));
}
function swap(value, item_array)
{
	if(value == "ascN")
	{
		for(var i =0;i<item_array.length;i++)
		{
			var a = item_array[i][0];
			item_array[i][0] = item_array[i][3];
			item_array[i][3] = a;
		}
		item_array.sort();
		for(var i =0;i<item_array.length;i++)
		{
			var a = item_array[i][0];
			item_array[i][0] = item_array[i][3];
			item_array[i][3] = a;
		}
/*future project
		for(var i =0;i<item_array.length;i++)
		{
			var b = new Array(); 
			var count = 0;
		}*/
	}
	else
	{
		for(var i =0;i<item_array.length;i++)
		{
			var a = item_array[i][3];item_array[i][3] = item_array[i][0];item_array[i][0] = a;
		}
		item_array.sort(reverseSort);
		for(var i =0;i<item_array.length;i++)
		{
			var a = item_array[i][3];item_array[i][3] = item_array[i][0];item_array[i][0] = a;
		}
	}
}
function sort(value, value2, item_array, html_link)
{
	var sorter = ""
	if(value == "dscA" || value == "dscAoff")
	{
		if(getloc2() == "ascNoff" || getloc2() == "dscNoff")
			sorter += '<a href="'+html_link+'.html?sort=ascA&sort='+getloc2()+'" id="noswap">(a-z sort)</a> ';
		else
			sorter += '<a href="'+html_link+'.html?sort=ascA&sort='+getloc2()+'off" id="noswap">(a-z sort)</a> ';
		if(value != "dscNoff")
			item_array.sort(reverseSort);
	}
	else if(value == "ascA" || value == "ascAoff")
	{
		if(getloc2() == "ascNoff" || getloc2() == "dscNoff")
			sorter += '<a href="'+html_link+'.html?sort=dscA&sort='+getloc2()+'" id="noswap">(z-a sort)</a> ';
		else
			sorter += '<a href="'+html_link+'.html?sort=dscA&sort='+getloc2()+'off" id="noswap">(z-a sort)</a> ';
		if(value != "ascNoff")
			item_array.sort();
	}
	else
	{
		item_array.sort();
		sorter += '<a href="'+html_link+'.html?sort=dscA&sort='+getloc2()+'off" id="noswap">(z-a sort)</a> ';
	}
	if(value2 == "dscN" || value2 == "dscNoff")
	{
		if(getloc() == "ascAoff" || getloc() == "dscAoff")
			sorter += '<a href="'+html_link+'.html?sort='+getloc()+'&sort=ascN" id="noswap">(0-10 sort)</a>';
		else
			sorter += '<a href="'+html_link+'.html?sort='+getloc()+'off&sort=ascN" id="noswap">(0-10 sort)</a>';
		if(value2 != "dscNoff")
			swap(value2, item_array);
	}
	else if(value2 == "ascN" || value2 == "ascNoff")
	{
		if(getloc() == "ascAoff" || getloc() == "dscAoff")
			sorter += '<a href="'+html_link+'.html?sort='+getloc()+'&sort=dscN" id="noswap">(10-0 sort)</a>';
		else
			sorter += '<a href="'+html_link+'.html?sort='+getloc()+'off&sort=dscN" id="noswap">(10-0 sort)</a>';
		if(value2 != "ascNoff")
			swap(value2, item_array);
	}
	else
		sorter += '<a href="'+html_link+'.html?sort='+getloc()+'off&sort=dscN" id="noswap">(10-0 sort)</a>';
	return sorter;
}
function removezero(S){
	if(S < 10)
	{
		S = S.substring(1,S.length)
		S = "&nbsp;"+S;
		return S;
	}
	else 
		return S;
	}
// End Global Functions