//div id="artistTable"

function getArtists(){
	loadXMLData("_data/getListings.php", "writeData");
}

function writeData() {
	var currentLetter = "";
	var currentColumn = 1;
	var artistsTable = '<table><tr><td>';
	var artistCount = xmlData.firstChild.childNodes.length;
	var thirdCount = Math.round(artistCount / 3);
	var twoThirdsCount = thirdCount * 2;
	
	for(var i = 0; i < artistCount; ++i){
		var name = String(xmlData.firstChild.childNodes[i].firstChild.firstChild.nodeValue);
		var id = xmlData.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
		var first_name = xmlData.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
		var last_name = xmlData.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue;
		
		if(first_name == "") {
			realName = last_name;
			realNameToDisplay = realName;
		}
		else {
			realName = last_name + ", " + first_name;
			realNameToDisplay = first_name + " " + last_name;
		}
			
		var firstCharacter = (realName.substring(0,1)).toUpperCase();
		if((currentColumn == 1) && (i >= thirdCount) && (firstCharacter != currentLetter)){
			artistsTable += '</td><td>';
			currentColumn = 2;
		}
		if((currentColumn == 2) && (i >= twoThirdsCount) && (firstCharacter != currentLetter)){
			artistsTable += '</td><td>';
			currentColumn = 3;
		}
		if(firstCharacter != currentLetter){
			artistsTable += '<h2>' + firstCharacter + '</h2>';
			currentLetter = firstCharacter;
		}
		artistsTable += '<a id="id' + id + '" href="directory.php?showArtist=' + id + '" onClick="showArtist(' + id + '); return false;">' + realNameToDisplay + '</a><br />';
	}
	artistsTable += '</td></tr></table>';
	document.getElementById("artistTable").innerHTML = artistsTable;
	closeXML();
}
