// Routines to display the awards loaded into awards array

function familycup(n) {
	content='<div align="center"><h2>Family Cup Winners</h2><h3>Sheila, Devina, and Dash Gohil</h3>';
	content+='<img src="images/familywinnersdec05.jpg" width="400" height="352" border="0" alt="Sheila, Devina, and Dash Gohil">';
	content+='</div>';
	document.getElementById('results').innerHTML=content;
	highlight(n);
}

function showawards(special, sorttype,t) {
	if (sorttype!='')
	{
		BubbleSort(awards,f,sorttype);
	}
	document.getElementById('results').innerHTML=showDetail(awards,f,special,sorttype);
	highlight(special);
}

function highlight(x) {
	mrow = document.getElementById('menurow');
	tdlist = mrow.getElementsByTagName('td');
	for (i=0;i<tdlist.length;i++) {
		tdlist[i].style.backgroundColor='transparent';
	}
	tdlist[x].style.backgroundColor='#99CCFF';
}

function DetailHead(headname,fieldname,stype, special) {
    var sortdown=1;
    if (stype.charAt(0)=='!')
    {
		sortdown=0;
		stype = stype.substr(1);
    }
    txt='<th align="center"><a href="javascript:showawards('+special+',\'';
    if (stype==fieldname && sortdown)
	{
		txt+='!';
	}
	txt+=fieldname + '\')">'+ headname;
    if (stype==fieldname)
	{
        txt+='<img border="0" src="images/';
        txt+=sortdown ? 'down.gif">' : 'up.gif">';
	}
	txt+='</a></th>';
	return txt;
}


function belt(t) {
	switch (t) {
		case 10: return 'Yellow';
		case 9: return 'Red Stripe';
		case 8: return 'Red';
		case 7: return 'Blue Stripe';
		case 6: return 'Blue';
		case 5: return 'Green Stripe';
		case 4: return 'Green';
		case 3: return 'Brown Stripe';
		case 2: return 'Brown';
		case 1: return 'Black';
		default: return 'Unknon';
	}
}

function cell(t) {
	return '<td align="center">' + t + '</td>';
}

function showDetail(object,length, special, sorttype) {
    t='<center><p align="center">Click heading to sort<br /><table class="resulttable">';
    t+='<thead><tr>';
	t+=DetailHead('Name','firstname',sorttype, special);
	t+=DetailHead('Surname','lastname',sorttype, special);
	t+=DetailHead('Kyu','grade',sorttype, special);
	t+=DetailHead('Belt','grade',sorttype, special);
	t+='</tr></thead><tbody>';
    for (var i=0; i<length; i++)
    {
		if (!object[i].show) continue;
		if (special)
		{
			//alert(i+','+special+','+!object[i].doub);
			if (special=='1')	// double grade
			{
				if (!object[i].doub) continue;
			}
			else
			{
				if (object[i].extra !=special) continue;
			}
		}
		t+='<tr>'+cell(object[i].firstname)+cell(object[i].lastname);
        t+=cell(object[i].grade)+cell(belt(object[i].grade))+'</tr>';
	}

    t+='</tbody></table></center>';
	return t;
}

function BubbleSort(arrayName,length,property) {
    var way='<';
    if (property.charAt(0)=='!')
    {
		way='>';
		property = property.substr(1);
    }
    for (var i=0; i<(length-1); i++)
        for (var j=i+1; j<length; j++)
            if (eval('arrayName[j].' + property + way + 'arrayName[i].' + property)) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
}

