function successHandler(o){

	function makeTable(){
      var tb = document.getElementById('liveLeaderboard');
  	  var root = o.responseXML.documentElement; 
  	  var aPlayers = root.getElementsByTagName('Player');	
      
      function makePlayerRow(i) {
      	  // Crawl the XML for all of the data
          var sLastName = aPlayers[i].getAttribute('Lname');
      	  var sFirstName = aPlayers[i].getAttribute('Fname');
          var sStartPos = aPlayers[i].getAttribute('StrPos');
          var sCurPos = aPlayers[i].getAttribute('CurPos');
          var sScore = aPlayers[i].getAttribute('TournParRel');
					var sTotal = aPlayers[i].getAttribute('TournStrk');
					var aRounds = aPlayers[i].getElementsByTagName('Rnd');
			
    			// Declare unplayed rounds
    			var sNotPlayed = '-';
    			var sRoundOne = sNotPlayed;
    			var sRoundTwo = sNotPlayed;
    			var sRoundThree = sNotPlayed;
    			var sRoundFour = sNotPlayed;
    			
    			var j = aRounds.length;
    
    			switch (j) {
                 case 1 :
        				 		if (!aRounds[0].getAttribute('Stroke')) {
        				 				break;
        						}
        						else {
        								sRoundOne = aRounds[0].getAttribute('Stroke');
        								break;
        						}
                 case 2 :
                    if (!aRounds[1].getAttribute('Stroke')) {
                        sRoundOne = aRounds[0].getAttribute('Stroke');
                        break;
        						}
        						else {
        								sRoundOne = aRounds[0].getAttribute('Stroke');
        								sRoundTwo = aRounds[1].getAttribute('Stroke');
                        break;
        						}					
                 case 3 :
        				 		if (!aRounds[2].getAttribute('Stroke')) {
                        sRoundOne = aRounds[0].getAttribute('Stroke');
        								sRoundTwo = aRounds[1].getAttribute('Stroke');
                        break;
        						}
        						else {
        								sRoundOne = aRounds[0].getAttribute('Stroke');
        								sRoundTwo = aRounds[1].getAttribute('Stroke');
        								sRoundThree = aRounds[2].getAttribute('Stroke');
                        break;
        						}										
                 case 4 :
        				 		if (!aRounds[3].getAttribute('Stroke')) {
        								sRoundOne = aRounds[0].getAttribute('Stroke');
        								sRoundTwo = aRounds[1].getAttribute('Stroke');
        								sRoundThree = aRounds[2].getAttribute('Stroke');
        								break;
        						}
        						else {
                        sRoundOne = aRounds[0].getAttribute('Stroke');
        								sRoundTwo = aRounds[1].getAttribute('Stroke');
        								sRoundThree = aRounds[2].getAttribute('Stroke');
        								sRoundFour = aRounds[3].getAttribute('Stroke');
                        break;
        						}
                 default :
                    break;
              }
          
          // Create the text that will go in each table cell
          var tdPos = document.createTextNode(sCurPos);
          var tdStartPos = document.createTextNode(sStartPos);
          var tdName = document.createTextNode(sFirstName +' '+ sLastName);
          var tdScore = document.createTextNode(sScore);
          var tdRoundOne = document.createTextNode(sRoundOne);
          var tdRoundTwo = document.createTextNode(sRoundTwo);
          var tdRoundThree = document.createTextNode(sRoundThree);
          var tdRoundFour = document.createTextNode(sRoundFour);
          //var tdMoney = document.createTextNode(sMoney);
          var tdTotal = document.createTextNode(sTotal);  
            
    	  	// Create the tr and td elements
          var tr=document.createElement('tr');  	
          var tdOne=document.createElement('td');
          var tdTwo=document.createElement('td');
          var tdThree=document.createElement('td');
          var tdFour=document.createElement('td');
          var tdFive=document.createElement('td');
          var tdSix=document.createElement('td');
          var tdSeven=document.createElement('td');
          var tdEight=document.createElement('td');
          var tdNine=document.createElement('td');
          //var tdTen=document.createElement('td');
    
          // Stripe alternating rows
          switch (i) {
               case 1 :
                  YAHOO.util.Dom.addClass(tr,'even');
                  break;
               case 3 :
                  YAHOO.util.Dom.addClass(tr,'even');
                  break;
               case 5 :
                  YAHOO.util.Dom.addClass(tr,'even');
                  break;
               case 7 :
                  YAHOO.util.Dom.addClass(tr,'even');
                  break;
               case 9 :
                  YAHOO.util.Dom.addClass(tr,'even');
                  break;
               default :
                  break;
          } 
          
          // Put the text nodes in the table cells; add any styling
          tdOne.appendChild(tdPos);
          YAHOO.util.Dom.addClass(tdOne,'first');
          tdTwo.appendChild(tdStartPos);
          tdThree.appendChild(tdName); 
          tdFour.appendChild(tdScore);
          tdFive.appendChild(tdRoundOne);
          tdSix.appendChild(tdRoundTwo);
          tdSeven.appendChild(tdRoundThree);
          tdEight.appendChild(tdRoundFour);
          tdNine.appendChild(tdTotal);
					YAHOO.util.Dom.addClass(tdNine,'last');
          //tdTen.appendChild(tdMoney);     
          
          // Put the cells into the row
          tr.appendChild(tdOne);
          tr.appendChild(tdTwo); 
          tr.appendChild(tdThree); 
          tr.appendChild(tdFour);
          tr.appendChild(tdFive);
          tr.appendChild(tdSix);
          tr.appendChild(tdSeven);
          tr.appendChild(tdEight);
          tr.appendChild(tdNine);
          //tr.appendChild(tdTen);
          
          // Put the row into the tbody
          tb.appendChild(tr); 						
          
       }
       
       // Repeat row creation for all Top 10 players
       for(i=0; i<10; i++) {
       		makePlayerRow(i)
       }
    }
		makeTable();  
}

/*
 *
 * This is a simple failure handler that will display
 * the HTTP status code and status message if the resource
 * returns a non-2xx code.
 *
 */
function failureHandler(o){
  	var errorMessage = function() {
      	var tb = document.getElementById('liveLeaderboard');
        var tr=document.createElement('tr');  	
        var td=document.createElement('td');
        var sErrorText = 'Unable to contact scoring feed.';
        var tdText = document.createTextNode(sErrorText);
        td.appendChild(tdText);
        tr.appendChild(td);
        tb.appendChild(tr);
    };
}

var oCallback = {
  	success: successHandler,
  	failure: failureHandler
}

function getModule(){
  	//sUrl is the the URL of the request
  	var sUrl = 'leaderboard.php';
    //var sUrl = 'leaderboard_2007.xml'
  
  	// Initiate the HTTP GET request.
  	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, oCallback);
}

function updateModule(){
	// destroy table
	var tb = document.getElementById('liveLeaderboard');
	var tbl = tb.parentNode;
			if (tbl.rows.length > 1) {
					var l = 1;
					while (l < tbl.rows.length) {
    					tbl.deleteRow(1);
					}
			}
	
  	//sUrl is the the URL of the request
  	var sUrl = 'leaderboard.php';
    //var sUrl = 'leaderboard_2007.xml';
  
  	// Initiate the HTTP GET request.
  	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, oCallback);
}

function makeLeaderboard() {
		getModule();
		
		var iDelay = 5;
		
		setInterval('updateModule()',iDelay * 60000);
}