var xmlDoc;	
var xmlObj;
var aDados = new Array();;
function getXMLList()
{
	xml = new ServerRequest();
	xml.onComplete = function(responseText,responseXML)
	{
		xmlDoc = responseXML;

		var xmlObj = xmlDoc.getElementsByTagName('atletas')[0];
  	
		for (var x=0,i=0;i<xmlObj.childNodes.length;i++)
		{
			// No NS/Mozilla é necessário ignorar os espaços em branco
			if (xmlObj.childNodes[i].nodeType != 1) continue;
  	
  		aDados[x] = new Array();
  		aDados[x]['nome'] = xmlObj.childNodes[i].attributes[0].value;
  		aDados[x]['arquivo'] = xmlObj.childNodes[i].attributes[4].value;
  		aDados[x]['ano'] = xmlObj.childNodes[i].attributes[5].value;
			x++;
		}

		setTimeout(function() { parseResults(1, "a","b","c"); },500);
	}
	xml.submit("/tenis/gestor/quemequem_lista.xml");
}	

function parseResults(_char)
{
	$("blocoAlfa").style.height = $("corpo").style.height = $("col-esquerda").style.height = $("col-direita").style.height = $("col-centro").style.height = "90em";
	doMenu(arguments[0]);

	if(!arguments[2]) return;
	else 
	{
		if(!arguments[3]) arguments[3] = "";
		
		for (var i=1;i<arguments.length;i++){
			showResults(i,arguments[i]);
		}
	}

	
	$("blocoAlfa").style.height = $("corpo").style.height = $("col-esquerda").style.height = $("col-centro").style.height = $("col-direita").style.height= "auto";
	if (typeof(setHeight) != "undefined")
		setHeight('corpo','col-esquerda','col-centro','col-direita','blocoAlfa');
		
		
	setHeight('corpo','col-esquerda','col-centro','col-direita');
}

function doMenu(_num)
{
	for(i=1;i<=9;i++)
		$("m"+i).className = "";
	
	$("m"+_num).className = "selecao";
}

function showResults(_bloco, _char)
{
	if (_char == "") { $("bloco"+_bloco).innerHTML = ""; return; }
	
	
	var HTML = '<ul>';
	HTML += '<h3>'+_char.toUpperCase()+'</h3>';
	for (var i=0;i<aDados.length;i++)
	{
		if (_char.toLowerCase() == aDados[i]['nome'].toLowerCase().substr(0,1))
			HTML += '<li><a href="atleta.jhtm?ano='+aDados[i]['ano']+'&nome='+aDados[i]['arquivo']+'">'+aDados[i]['nome']+'</a>';
	}
	HTML += '</ul>';
	
	$("bloco"+_bloco).innerHTML = HTML;	
	setHeight('corpo','col-esquerda','col-centro','col-direita');
}

getXMLList();