// browse_schools.js
// replaced jQuery shortcut '$vj' with $vjvj.  See control/main.php

 $vj(document).ready(function() { //wait for document ready
	schoolsList = $vj.ajax({
		url: proxyURL + 'orgslist?year=' + statYear  + '&qid=' + groupID + '&letter=' + theLetter,
		cache: false,
		success: 
			function(xml) {
				handleTeamsList(xml);
			}
	});
	
	/*  BreadNav Function  */
 	var previousGames = $vj.ajax({
	url: proxyURL + "orgbreadnav?year=" + statYear + '&qid=' + groupID,
	cache: false,
	success: 
		function(xml) {
			handleBreadNavBrowse(xml);
		}
	});
});

function handleTeamsList(doc) {

	 var tbody = document.getElementById("offLeaderboardData");
	 //  Delete all the existing rows.  IMPORTANT!!!
	 while (tbody.rows.length > 0) {     tbody.deleteRow(0);    }
	 var root = doc.documentElement;
	 var nds;
	 var i;
	 var row = 0;
	 var zebra_stripe_class_names = rc
	 var otid = 0;
	 var o = 0;
	 var sn = "";
	 var lt = leadType;
	 var rank = ((parseInt(thisPage) - 1)*20);
	 //  Look for child nodes in the XML
	 if(root.hasChildNodes())  
	 {
		   nds=root.childNodes;
		   //  Look through the child nodes and find nodes named "item"
		   for (var i = 0; i < nds.length; i++)
		   {

			if (nds[i].nodeName == "item")
			{
				//  Look through the children of the nodes named "item" and find what we want
				if(nds[i].hasChildNodes())
				{
					var nm = ""; var tc = "&nbsp;"; var tid = "";
					sNds = nds[i].childNodes;
					for (var j=0;j<sNds.length;j++)
					{
						//alert(sNds[j].nodeName);
						if (sNds[j].nodeName == "name" && sNds[j].hasChildNodes()) nm = sNds[j].firstChild.nodeValue;
						if (sNds[j].nodeName == "oid" && sNds[j].hasChildNodes()) oid = sNds[j].firstChild.nodeValue;
						if (sNds[j].nodeName == "TeamCount" && sNds[j].hasChildNodes()) tc = sNds[j].firstChild.nodeValue;
					}
					newRow = tbody.insertRow(tbody.rows.length);
					qw = row % 2;
					newRow.setAttribute('class', rc[qw] );
					newRow.setAttribute('className', rc[qw])
					if (newRow)
					{
						newCell = newRow.insertCell(0);
						rank++;
						if (nm != "") newCell.innerHTML = '<a href="' + baseURL + 'school.php?yid=' + statYear + '&oid=' + oid + '">' + nm + '</a>';
						else newCell.innerHTML = "&nbsp;";
						newCell = newRow.insertCell(1);
						newCell.innerHTML = tc;
						newCell.style.textAlign = 'center';
					}
					o++;
					row++;
				}
				//1  2  3  4  5  6  7  8 ';
			}
		}
		//-- Set footer
		
		HTML = '<a title="All" href="javascript:browseThis(\'All\');">Browse Teams: </a>&nbsp;';
		var letters = Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
		for ( i = 0; i < 26; ++i) {
			letter = letters[i]
			HTML += '<a href="javascript:browseThis(\'' + letter + '\');">' + letter.toUpperCase()+ '</a>&nbsp;';
		}

		document.getElementById('footerCell').innerHTML = HTML;
		document.getElementById('headerCell').innerHTML = HTML;

		stripe_color = row % 2;
		document.getElementById('footerCell').parentNode.setAttribute('class', zebra_stripe_class_names[stripe_color] );
		document.getElementById('footerCell').parentNode.setAttribute('className', zebra_stripe_class_names[stripe_color])
		document.getElementById('headerCell').parentNode.setAttribute('class', zebra_stripe_class_names[stripe_color] );
		document.getElementById('headerCell').parentNode.setAttribute('className', zebra_stripe_class_names[stripe_color])
		document.getElementById('teamTitle').innerHTML += ': ' + statYear;
		var display_letter = theLetter.toUpperCase();
		document.title = siteTitle + statYear + ' - ' + display_letter;
		document.getElementById('browseBreadNav').innerHTML += display_letter;
	}
}

function browseThis(ltr) {
	var url = baseURL + 'browse.php?yid=' + statYear + '&ltr=' + ltr;
	location.href = url;
}

function sortPageLeaders(sp,pg,key,val)
{
	url = baseURL + sp + "/" + pg + ".php?cid=" + divID + "&lid=" + confID + "&ltype=" + leadType + "&" + key + "=" + val;
	location.href = url;
}




