
/**
* Retrieves the "High Scores" list from the game server.
*/
function getHighScoresList () {
	
	/**
	* GET "OLD SCHOOL" version of leaderboards: Pop4, PopSpin, PopQuiz
	*/
	//var func = Delegate.create ( this, handleHighScoresReady ); 
   
	/**
	* GET "NEW SCHOOL" version of leaderboards: Daily, Monthly, Lifetime
	*/
	var func = Delegate.create ( this, newHandleHighScoresReady ); 
	
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }		
	
  
    getHighScores ( func ); 	  
}

/**
* CALLBACK
* 
* This is called once the "Recent Qualifiers" data comes back from the game server.
*/
function handleHighScoresReady ( data, xml, extraData ) {
	
//alert ( " data: " + data );
	
	 var pop4HighScoresDivId = "pop4HighScores";
	 var popQuizHighScoresDivId = "popQuizHighScores";
	 var popSpinHighScoresDivId = "popSpinHighScores";
	 
	 if ( extraData ) {
		 pop4HighScoresDivId = extraData.pop4DivId;
		 popQuizHighScoresDivId = extraData.popQuizDivId;
		 popSpinHighScoresDivId = extraData.popSpinDivId;
	 }
	
	var popQuizHighScores = data.highScores.getLeaderRecordsForGameType (LeaderRecords.GAME_TYPE_POP_QUIZ);
	var pop4HighScores = data.highScores.getLeaderRecordsForGameType (LeaderRecords.GAME_TYPE_POP_4);
	var popSpinHighScores = data.highScores.getLeaderRecordsForGameType (LeaderRecords.GAME_TYPE_POP_SPIN);
		
		
	 showPopQuizHighScores ( popQuizHighScores.leaderRecords, popQuizHighScoresDivId );
	 showPop4HighScores ( pop4HighScores.leaderRecords, pop4HighScoresDivId );
	 showPopSpinHighScores ( popSpinHighScores.leaderRecords, popSpinHighScoresDivId );
	 
	
	 
	
}

/**
* CALLBACK
* 
* This is called once the "Recent Qualifiers" data comes back from the game server.
*/
function newHandleHighScoresReady ( data, xml, extraData ) {
	
//alert ( " data: " + data );
	
	 var pop4HighScoresDivId = "pop4HighScores";
	 var popQuizHighScoresDivId = "popQuizHighScores";
	 var popSpinHighScoresDivId = "popSpinHighScores";
	 
	 if ( extraData ) {
		 pop4HighScoresDivId = extraData.pop4DivId;
		 popQuizHighScoresDivId = extraData.popQuizDivId;
		 popSpinHighScoresDivId = extraData.popSpinDivId;
	 }
	
	 var dailyHighScores = data.highScores.getLeaderRecordsForScoreType (LeaderRecords.SCORE_TYPE_DAILY);
	 var monthlyHighScores = data.highScores.getLeaderRecordsForScoreType (LeaderRecords.SCORE_TYPE_MONTHLY);
	 var lifetimeHighScores = data.highScores.getLeaderRecordsForScoreType (LeaderRecords.SCORE_TYPE_LIFETIME);
		
	 showDailyHighScores ( dailyHighScores.leaderRecords, popQuizHighScoresDivId );
	 showMonthlyHighScores ( monthlyHighScores.leaderRecords, pop4HighScoresDivId );
	 showLifetimeHighScores ( lifetimeHighScores.leaderRecords, popSpinHighScoresDivId );
	 
	
}


function showPopQuizHighScores ( popQuizHighScores, divId ) {
	
	var popQuizHighScoresDiv = document.getElementById ( divId ); 
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < popQuizHighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = popQuizHighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.score;
		
		
		var winnerNameCell = document.createElement("td");

		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");

		link.setAttribute ( "href", personPageUrl );

		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");

		wonAmountCell.className = "playerScoreCell";

		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   popQuizHighScoresDiv.appendChild(mytable);
	
}

// NEW
function showDailyHighScores ( popQuizHighScores, divId ) {
	
	var popQuizHighScoresDiv = document.getElementById ( divId ); 
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < popQuizHighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = popQuizHighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.dailyScore;
		
		
		var winnerNameCell = document.createElement("td");

		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");

		link.setAttribute ( "href", personPageUrl );

		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");

		wonAmountCell.className = "playerScoreCell";

		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   popQuizHighScoresDiv.appendChild(mytable);
	
}



function showPop4HighScores ( pop4HighScores, divId ) {
	
	var pop4HighScoresDiv = document.getElementById ( divId ); // "pop4HighScores" );
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < pop4HighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = pop4HighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.score;
		
		
		var winnerNameCell = document.createElement("td");

		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");
		link.setAttribute ( "href", personPageUrl );
		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");
		wonAmountCell.className = "playerScoreCell";
		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   pop4HighScoresDiv.appendChild(mytable);
	
}

// NEW
function showMonthlyHighScores ( pop4HighScores, divId ) {
	
	var pop4HighScoresDiv = document.getElementById ( divId ); // "pop4HighScores" );
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < pop4HighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = pop4HighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.monthlyScore;
		
		
		var winnerNameCell = document.createElement("td");

		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");
		link.setAttribute ( "href", personPageUrl );
		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");
		wonAmountCell.className = "playerScoreCell";
		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   pop4HighScoresDiv.appendChild(mytable);
	
}


function showPopSpinHighScores ( popSpinHighScores, divId ) {
	
	var popSpinHighScoresDiv = document.getElementById ( divId ); //"popSpinHighScores" );
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < popSpinHighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = popSpinHighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.score;
		
		
		var winnerNameCell = document.createElement("td");
		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");
		link.setAttribute ( "href", personPageUrl );
		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");
		wonAmountCell.className = "playerScoreCell";
		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   popSpinHighScoresDiv.appendChild(mytable);
	
}

// NEW
function showLifetimeHighScores ( popSpinHighScores, divId ) {
	
	var popSpinHighScoresDiv = document.getElementById ( divId ); //"popSpinHighScores" );
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < popSpinHighScores.length; row++ ) {
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var highScore = popSpinHighScores[row];
		
		var name = highScore.name;
		var personPageUrl = highScore.personPageUrl;
		var score = highScore.lifetimeScore;
		
		
		var winnerNameCell = document.createElement("td");
		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");
		link.setAttribute ( "href", personPageUrl );
		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( name );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");
		wonAmountCell.className = "playerScoreCell";
		var amountTextNode = document.createTextNode ( score );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   popSpinHighScoresDiv.appendChild(mytable);
	
}




/**
* Retrieves the "Recent Qualifiers" list from the game server.
*/
function getQualifiersList () {
   
    var func = Delegate.create ( this, handleQualifiersReady ); 
	
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }		
  
    getQualifiers ( func ); 	  
}

/**
* CALLBACK
* 
* This is called once the "Recent Qualifiers" data comes back from the game server.
*/
function handleQualifiersReady ( data, xml, extraData ) {
   
   var divId = "recentQualifiers";
   
   if ( extraData ) {
	   divId = extraData.divId;
   }
   
   var recentQualifiers = null;
   if ( data.getQualifiersGroupForPrizeType ( QualifiersGroup.WEEKLY_PRIZE_TYPE ) ) {
	   recentQualifiers = data.getQualifiersGroupForPrizeType ( QualifiersGroup.WEEKLY_PRIZE_TYPE ).qualifiers;
   }
   
   if ( recentQualifiers == null ) {
	   return;
   }
   
     /**
	 * Fill the <div> with an unordered list of qualifiers.
	 */
     var recentQualifiersDiv = document.getElementById ( divId );

     var list = document.createElement("ul");
	 recentQualifiersDiv.appendChild (list);

     for(var idx=0; idx < recentQualifiers.length; idx++ ) {
	    var recentQualifier = recentQualifiers[idx];
		
		// Only show 5!!!
		if ( idx >= 5 ) {
			break;
		}
		
	    var item = document.createElement("li");
		list.appendChild(item);
		var link = document.createElement("a");
		link.setAttribute ( "href", recentQualifier.qualifierUrl );
		item.appendChild(link);
		var text = document.createTextNode ( recentQualifier.qualifierName );
		link.appendChild(text);
		
     }   

}


/**
* Retrieves the "Landing Page Hit Games" list from the game server.
*/
function getLandingPageHitGamesList ( landingPageHitGamesReadyHandler ) {
   
    var func = Delegate.create ( this, landingPageHitGamesReadyHandler );  
	
    getLandingPageHitGames ( func );   
}



function getCurrentUserInfo ( userInfoReadyHandler ) {
   
    var func = Delegate.create ( this, userInfoReadyHandler );  
    getUserInfo ( func );   
}




/**
* Retrieves the "Drawing Winners" list from the game server.
*/
function getDrawingWinnersList () {
   
    var func = Delegate.create ( this, handleDrawingWinnersReady );  
	
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }	
  
    getDrawingWinners ( func );   
}

/**
* CALLBACK
* 
* This is called once the "Drawing Winners" data comes back from the game server.
*/
function handleDrawingWinnersReady ( data, xml, extraData ) {
	
	var divId = "drawingWinners";
	
	if ( extraData ) {
		divId = extraData.divId;
	}
	
   var drawingWinners = data.drawingWinners.drawingWinners;
	 

   /**
   * Fill the <div> with a table with a row for each drawing winner.
   */
   var drawingWinnersDiv = document.getElementById ( divId );
	 
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

        // creating all cells
	for(var row=0; row < drawingWinners.length; row++ ) {
		
		// ONLY SHOW FIRST 3!
		if ( row >= 3 ) {
			break;
		}
		
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var drawingWinner = drawingWinners[row];
		
		var winnerName = drawingWinner.winnerName;
		var winnerPersonPageUrl = drawingWinner.winnerPersonPageUrl;
		var dollarsWon = drawingWinner.prizeWon;
		
		
		var winnerNameCell = document.createElement("td");
		//winnerNameCell.setAttribute ( "class", "playerNameLinkCell" );
		winnerNameCell.className = "playerNameLinkCell";
		var link = document.createElement("a");
		//link.setAttribute ( "class", "winnerNameLink" );
		link.setAttribute ( "href", winnerPersonPageUrl );
		link.className = "winnerNameLink";
		winnerNameCell.appendChild(link);
		var text = document.createTextNode ( winnerName );
		link.appendChild(text);
		mycurrent_row.appendChild(winnerNameCell);
		
		
		var wonAmountCell = document.createElement("td");
		//wonAmountCell.setAttribute ( "class", "wonMoneyAmountCell" );
		wonAmountCell.className = "wonMoneyAmountCell";
		var amountText =  dollarsWon;
		var amountTextNode = document.createTextNode ( amountText );
		wonAmountCell.appendChild ( amountTextNode );
		mycurrent_row.appendChild(wonAmountCell);
		
		mytablebody.appendChild(mycurrent_row);
	}

   mytable.appendChild(mytablebody);
   drawingWinnersDiv.appendChild(mytable);
}

function resetPrizesPageAjaxVars () {
}

function getDrawingWinnersListForPrizesPage () {
   
    var func = Delegate.create ( this, handleDrawingWinnersPrizesPageReady );  
	
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }	
  
// DataServiceBackEnd.DUMMY_DATA = true; 
    getDrawingWinners ( func );   
//	DataServiceBackEnd.DUMMY_DATA = false;
}

var m_avatarImageElement = new Array ();
var m_avatarImageLoadedSuccessfully = new Array ();
var m_avatarImageUniqueId = Number(0);

function handleIfImageNotLoaded ( id ) {
//	alert ( " image id: " + id );
//	alert ( " this.m_avatarImageLoadedSuccessfully: " + this.m_avatarImageLoadedSuccessfully );
	if ( m_avatarImageLoadedSuccessfully[id] == false ) {
	   m_avatarImageElement[id].src = "/videocube/site/images/blankAvatar.png";
	}
}

function setImageSuccessfullyLoaded (id) {
	m_avatarImageLoadedSuccessfully[id] = true;
	//alert ( "SET IMAGE SUCCESSFUL: " + id + " m_avatarImageLoadedSuccessfully[id]: " + m_avatarImageLoadedSuccessfully[id] );
}

function showCurrentDrawingWinner ( currentDrawingWinnerContents, drawingWinner, winnerTypeLabel ) {
	
		var winnerName = drawingWinner.winnerName;
		var winnerId = drawingWinner.winnerId; //176273; //drawingWinner.winnerId; 
		var winnerPersonPageUrl = drawingWinner.winnerPersonPageUrl;
		var dollarsWon = drawingWinner.prizeWon;
		
		var currentDrawingWinner = document.createElement ( "div" );
		currentDrawingWinnerContents.appendChild(currentDrawingWinner);
		
		currentDrawingWinner.className = "currentDrawingWinner";
		currentDrawingWinner.setAttribute ( "class", "currentDrawingWinner" );
		
		var avatarImage = document.createElement("img");
		m_avatarImageUniqueId = m_avatarImageUniqueId + 1;
		m_avatarImageLoadedSuccessfully [m_avatarImageUniqueId] = false;
		m_avatarImageElement [m_avatarImageUniqueId] = avatarImage;
		avatarImage.setAttribute ( "src", "/videocube/imageserver.htm?file=" + winnerId + "_avatar.jpg&avatarType=player" );
		//avatarImage.setAttribute ( "onload", "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")" );
		var evalStr = "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")";
		avatarImage.onload = function () {
			eval ( evalStr );
		}
		setTimeout ( "handleIfImageNotLoaded(" + m_avatarImageUniqueId + ")" , 2000 );
		currentDrawingWinner.appendChild(avatarImage);
		
		var divWithText = document.createElement("div");
		currentDrawingWinner.appendChild (divWithText);
		
		var pWithLink = document.createElement("p");
		divWithText.appendChild(pWithLink);
		
		var winnerLink = document.createElement("a");
		winnerLink.innerHTML = winnerName;
		winnerLink.setAttribute ( "href", "/videocube/member.htm?mid=" + winnerId );
		pWithLink.appendChild(winnerLink);
		
		var pWithMessage = document.createElement("p");
		pWithMessage.innerHTML = winnerTypeLabel; //"Top Question Winner (" + dollarsWon + ")";
		divWithText.appendChild(pWithMessage);
	
}

function handleDrawingWinnersPrizesPageReady ( data, xml, extraData ) {

	var divId = "drawingWinners";
	
	if ( extraData ) {
		divId = extraData.divId;
	}
	
	var availablePastPodSlots = 10;
	var availableCurrentPodSlots = 5;
   
   
    var currentDrawingWinnerContents = document.getElementById ( "currentDrawingWinnerContents" );
	
	if ( data.getDrawingWinnersByType ("all") ) {
	   var dailyDrawingWinners = data.getDrawingWinnersByType ("all").drawingWinners;

	   if ( dailyDrawingWinners.length > 0 ) {
	      var drawingWinner = dailyDrawingWinners[0];
		  var displayNum = availableCurrentPodSlots;
		  if (dailyDrawingWinners.length < displayNum)
		  {
			  displayNum = dailyDrawingWinners.length;
		  }

          for ( var idx = 0; idx <  displayNum; idx++ ) {
              var winner = dailyDrawingWinners[idx];
				addRecentWinnersToPrizesPage ( "currentDrawingWinnerContents", winner);
				
          }

		  if (dailyDrawingWinners.length > displayNum)
		  {
			  for (var idx = displayNum; idx < dailyDrawingWinners.length; idx++ )
			  {
				  var winner = dailyDrawingWinners[idx];
				  if (availablePastPodSlots > 0)
				  {	
						addPastWinnerToPrizesPage ( "pastWinnersPodContents", winner );
						availablePastPodSlots--;
				  }
			  }
		  }
	   }
	}
	

}




/**
* Retrieves the top "Submitted Questions" list from the game server.
*/
function getSubmitQuestionWinnerListForPrizesPage () {
   
   var func = Delegate.create ( this, handleSubmitQuestionWinnerListForPrizesPageReady ); 
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }
   
 //DataServiceBackEnd.DUMMY_DATA = true;
    getSubmitQuestionWinner ( func ); // handleSubmitQuestionWinnerReady );
//DataServiceBackEnd.DUMMY_DATA = false;
}


function handleSubmitQuestionWinnerListForPrizesPageReady ( data, xml, extraData ) {
	
	// alert ( "EXTRA DATA: " + extraData );
	
	//alert ( "EXTRA DATA: " + extraData.divId );
	 
	 var pastWinnersDivId = "winningQuestion";
	 if ( extraData ) {
		 pastWinnersDivId = extraData.pastWinnersDivId;
	 }
	 
	 var currentQuestionWinnerId = extraData.currentQuestionWinnerId;
	 
	// alert ( " divId: " + divId );

     //alert ( "XML RESPONSE: " + xml );
	 
    // alert ( "DATA: " + data );
	  
     var winningQuestions = data.winningQuestions.winningQuestions;
	 
	// alert ( " winningQuestions.length: " + winningQuestions.length );
     /**
	 * Fill the <div> with an unordered list of qualifiers.
	 */	 
     for(var idx=0; idx < winningQuestions.length; idx++ ) {
	    var winningQuestion = winningQuestions[idx];
		
		if ( idx == 0 ) {
			addCurrentQuestionWinnerToPrizesPage ( currentQuestionWinnerId, winningQuestion );
			// alert ( "question of the week" );
		   //displayQuestionOfTheWeek ( winningQuestion, divId );
		   //break;
		} else {
			
			addPastWinnerToPrizesPage (pastWinnersDivId,winningQuestion);
		}
		
     }
	 
}

function addCurrentQuestionWinnerToPrizesPage ( currentQuestionWinnerId, winningQuestion ) {

    var currentQuestionWinnerDiv = document.getElementById ( currentQuestionWinnerId );
	
	var winnerId = winningQuestion.winnerId;
	var avatarImage = document.createElement("img");
	m_avatarImageUniqueId = m_avatarImageUniqueId + 1;
	m_avatarImageLoadedSuccessfully [m_avatarImageUniqueId] = false;
	m_avatarImageElement [m_avatarImageUniqueId] = avatarImage;	
	avatarImage.setAttribute ( "src", "/videocube/imageserver.htm?file=" + winnerId + "_avatar.jpg&avatarType=player" );
	//avatarImage.setAttribute ( "onload", "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")" );
	var evalStr = "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")";
	avatarImage.onload = function () {
	    eval ( evalStr );
	}
	setTimeout ( "handleIfImageNotLoaded(" + m_avatarImageUniqueId + ")" , 2000 );
	
	currentQuestionWinnerDiv.appendChild(avatarImage);
	
	var divWithText = document.createElement("div");
	currentQuestionWinnerDiv.appendChild (divWithText);
	
	var pWithLink = document.createElement("p");
	divWithText.appendChild(pWithLink);
	
	var winnerLink = document.createElement("a");
	winnerLink.innerHTML = winningQuestion.winnerName;
	winnerLink.setAttribute ( "href", "/videocube/member.htm?mid=" + winningQuestion.winnerId );
	pWithLink.appendChild(winnerLink);
	
	var span = document.createElement("span"); 
	span.innerHTML = "won $250 for this month's top submitted question:";
	pWithLink.appendChild(span);
	
    var pWithQuestion = document.createElement("p");
	var questionLink = document.createElement("a");
	questionLink.innerHTML = winningQuestion.questionText;
	questionLink.setAttribute ( "href", winningQuestion.questionPreviewUrl );
	pWithQuestion.appendChild(questionLink);	
	divWithText.appendChild(pWithQuestion);

}

function addRecentWinnersToPrizesPage (pastWinnersDivId,winningQuestion ) {
	
//	alert("In addRecentWinnersToPrizesPage, pastWinnersDivId= " + pastWinnersDivId);

    var pastWinnersDiv = document.getElementById ( pastWinnersDivId );

//    alert("Pass 1");

 //   var space = document.createElement("&nbsp;");
//	pastWinnersDiv.appendChild(space);

//    var tdSection = document.createElement("td");
//    pastWinnersDiv.appendChild(tdSection);

	var questionWinnerDiv = document.createElement("div");
	questionWinnerDiv.setAttribute ( "class", "currentDrawingWinner" );
	questionWinnerDiv.className = "currentDrawingWinner";
	pastWinnersDiv.appendChild(questionWinnerDiv);
	


	var winnerId = winningQuestion.winnerId;
	var avatarImage = document.createElement("img");
	m_avatarImageUniqueId = m_avatarImageUniqueId + 1;
	m_avatarImageLoadedSuccessfully [m_avatarImageUniqueId] = false;
	m_avatarImageElement [m_avatarImageUniqueId] = avatarImage;		
	avatarImage.setAttribute ( "src", "/videocube/imageserver.htm?file=" + winnerId + "_avatar.jpg&avatarType=player" );
	//avatarImage.setAttribute ( "onload", "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")" );
	var evalStr = "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")";
	avatarImage.onload = function () {
	    eval ( evalStr );
	}
	setTimeout ( "handleIfImageNotLoaded(" + m_avatarImageUniqueId + ")" , 2000 );
	
	questionWinnerDiv.appendChild(avatarImage);
	
	var divWithText = document.createElement("div");
	questionWinnerDiv.appendChild (divWithText);
	
	var pWithLink = document.createElement("p");
	divWithText.appendChild(pWithLink);
	
	var winnerLink = document.createElement("a");
	winnerLink.innerHTML = winningQuestion.winnerName;
	winnerLink.setAttribute ( "href", "/videocube/member.htm?mid=" + winningQuestion.winnerId );
	pWithLink.appendChild(winnerLink);
	
	var pWithMessage = document.createElement("p");
	//pWithMessage.innerHTML = winTypeLabel; // "Top Question Winner ($250)";
	pWithMessage.innerHTML = winningQuestion.prizeType + " Drawing Winner";
	divWithText.appendChild(pWithMessage);


}


function addPastWinnerToPrizesPage (pastWinnersDivId,winningQuestion, winTypeLabel ) {
	
    var pastWinnersDiv = document.getElementById ( pastWinnersDivId );

	var questionWinnerDiv = document.createElement("div");
	questionWinnerDiv.setAttribute ( "class", "questionWinner" );
	questionWinnerDiv.className = "questionWinner";
	pastWinnersDiv.appendChild(questionWinnerDiv);
	
	var winnerId = winningQuestion.winnerId;
	var avatarImage = document.createElement("img");
	m_avatarImageUniqueId = m_avatarImageUniqueId + 1;
	m_avatarImageLoadedSuccessfully [m_avatarImageUniqueId] = false;
	m_avatarImageElement [m_avatarImageUniqueId] = avatarImage;		
	avatarImage.setAttribute ( "src", "/videocube/imageserver.htm?file=" + winnerId + "_avatar.jpg&avatarType=player" );
	//avatarImage.setAttribute ( "onload", "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")" );
	var evalStr = "setImageSuccessfullyLoaded(" + m_avatarImageUniqueId + ")";
	avatarImage.onload = function () {
	    eval ( evalStr );
	}
	setTimeout ( "handleIfImageNotLoaded(" + m_avatarImageUniqueId + ")" , 2000 );
	
	questionWinnerDiv.appendChild(avatarImage);
	
	var divWithText = document.createElement("div");
	questionWinnerDiv.appendChild (divWithText);
	
	var pWithLink = document.createElement("p");
	divWithText.appendChild(pWithLink);
	
	var winnerLink = document.createElement("a");
	winnerLink.innerHTML = winningQuestion.winnerName;
	winnerLink.setAttribute ( "href", "/videocube/member.htm?mid=" + winningQuestion.winnerId );
	pWithLink.appendChild(winnerLink);
	
	var pWithMessage = document.createElement("p");
	pWithMessage.innerHTML = winningQuestion.prizeType + " Drawing Winner";
	divWithText.appendChild(pWithMessage);
}




/**
* Retrieves the top "Submitted Questions" list from the game server.
*/
function getSubmitQuestionWinnerList () {
   
   var func = Delegate.create ( this, handleSubmitQuestionWinnerReady ); // trythis ); // handleSubmitQuestionWinnerReady );
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }
   
  // alert ( " func.extraData: " + func.extraData );
  
    getSubmitQuestionWinner ( func ); // handleSubmitQuestionWinnerReady );
}

/**
* This function displays the "question of the week" in its own <div>.
*/
function displayQuestionOfTheWeek ( winningQuestion, divId ) {

   var winningQuestionDiv = document.getElementById ( divId );

	var link = document.createElement("a");
	link.setAttribute ( "href", winningQuestion.questionPreviewUrl );
	link.style.color = "#FFCC00";
	winningQuestionDiv.appendChild(link);
	
	var pMain = document.createElement("p");
	pMain.setAttribute ( "id", "winningQuestionQuestion" );
	pMain.style.color = "#FFCC00";
	link.appendChild(pMain);
	
	var text = document.createTextNode ( winningQuestion.questionText );
	pMain.appendChild(text);
   

	
    var pCongratsMessage = document.createElement("p");
	pCongratsMessage.setAttribute ( "id", "congratsToQuestionWinner" );
	
	
	var messageSpan1 = document.createElement("span");
	messageSpan1.innerHTML = "Congratulations to ";
	
	var winnerLink = document.createElement("a");
	winnerLink.style.fontWeight = "bold";
	winnerLink.style.color = "#ffffff";
	winnerLink.innerHTML = winningQuestion.winnerName;
//	winnerLink.setAttribute ( "href", "/videocube/member.htm?mid=139" );
	
	
	var messageSpan3 = document.createElement("span");
	messageSpan3.innerHTML = "&nbsp;on winning $250 for submitting this question!";
	
	
	var winnerImage = document.createElement("img");
	winnerImage.setAttribute ( "src", "site/images/art.jpg" );
	winnerImage.width = 56;
	winnerImage.height = 70;
	winnerImage.className = "floatLeftImage";
	winnerImage.style.paddingRight = "20px";
	winningQuestionDiv.appendChild(winnerImage);	
	
	pCongratsMessage.appendChild(messageSpan1);
	pCongratsMessage.appendChild(winnerLink);
	pCongratsMessage.appendChild(messageSpan3);
	//pCongratsMessage.className = "floatParagraphLeft";
	/*pCongratsMessage.style.width = "300px";*/
	winningQuestionDiv.appendChild(pCongratsMessage);
	
	


	
	/*
	var winnerImage = document.createElement("img");
	winnerImage.setAttribute ( "src", "site/images/art.jpg" );
	winnerImage.width = 30;
	winnerImage.height = 34;
	pCongratsMessage.appendChild(winnerImage);
	*/
	
	//var link = document.createElement("a");
	//var message = "Congratulations to " + winningQuestion.winnerName + " on winning $250 for submitting this question!";
	//var textCongrats = document.createTextNode ( message );
    //pCongratsMessage.appendChild ( textCongrats );
  
}

/**
* CALLBACK
* 
* This is called once the "Submitted Questions" data comes back from the game server.
*/
function handleSubmitQuestionWinnerReady ( data, xml, extraData ) {
	
	//alert ( "EXTRA DATA: " + extraData.divId );
	 
	 var divId = "winningQuestion";
	 if ( extraData ) {
		 divId = extraData.divId;
	 }

     //alert ( "XML RESPONSE: " + xml );
	 
    // alert ( "DATA: " + data );
	  
     var winningQuestions = data.winningQuestions.winningQuestions;
	 
     /**
	 * Fill the <div> with an unordered list of qualifiers.
	 */	 
     for(var idx=0; idx < winningQuestions.length; idx++ ) {
	    var winningQuestion = winningQuestions[idx];
		
		if ( idx == 0 ) {
		   displayQuestionOfTheWeek ( winningQuestion, divId );
		   break;
		}
		
     }
	 
}


/**
* Retrieves the top "HIT Questions" list from the game server.
*/
function getHitQuestionList () {
   
   var func = Delegate.create ( this, handleHitQuestionsReady ); // trythis ); // handleSubmitQuestionWinnerReady );
  
   func.extraData = null;
   if ( arguments.length > 0 ) {
	   func.extraData = arguments[0];
   }
   
    getHitQuestions ( func ); // handleSubmitQuestionWinnerReady );
}

/**
* CALLBACK
* 
* This is called once the "HIT Questions" data comes back from the game server.
*/
function handleHitQuestionsReady ( data, xml, extraData ) {
	
	var divId = "hitQuestions";
	
	if ( extraData ) {
		divId = extraData.divId;
	}
	
     var hitQuestions = data.hitQuestions.hitQuestions;
	 
     /**
	 * Fill the <div> with an unordered list of qualifiers.
	 */	 
     var hitQuestionsDiv = document.getElementById ( divId ); // "hitQuestions" );
	 
     var list = document.createElement("ul");
	 hitQuestionsDiv.appendChild (list);
	 
	 
     for(var idx=0; idx < hitQuestions.length; idx++ ) {
	    var hitQuestion = hitQuestions[idx];
		
	    var item = document.createElement("li");
		list.appendChild(item);
		var link = document.createElement("a");
		link.setAttribute ( "href", hitQuestion.questionPreviewUrl );
		item.appendChild(link);
		var text = document.createTextNode ( hitQuestion.questionText );
		link.appendChild(text);
		
     }
	 
	
}


/**
* Retrieves the top "HIT Questions" list from the game server.
*/
function getHitGamesInfoList () {
   
   var func = Delegate.create ( this, handleHitGamesInfoReady ); // trythis ); // handleSubmitQuestionWinnerReady );
  
    getHitGameInfo ( func ); // handleSubmitQuestionWinnerReady );
}

/**
* CALLBACK
* 
* This is called once the "HIT Questions" data comes back from the game server.
*/
function handleHitGamesInfoReady ( data, xml ) {
	//alert ( "XML: " + xml );
	
	// alert ( "data: " +  data );
	
	var hitGamesXMLDumpDiv = document.getElementById ( "hitGamesXMLDump" );
	var textNode = document.createTextNode ( xml );
	hitGamesXMLDumpDiv.appendChild ( textNode );
	
	
	var hitGamesListDiv = document.getElementById ( "hitGamesList" );
	
   mytable     = document.createElement("table");
   mytable.setAttribute ( "cellspacing", "0" );
   mytablebody =  document.createElement("tbody");

    var hitGameGroups = data.hitGameGroups.hitGameGroups;
	
        // creating all cells
	for(var row=0; row < hitGameGroups.length; row++ ) {
		
		
		// creates a <tr> element
		mycurrent_row = document.createElement("tr");

		var hitGameGroup = hitGameGroups[row];
		
		
		var hitGameGroupName = hitGameGroup.title;
		
	
		
		var hitGroupNameCell = document.createElement("td");
		
		var text = document.createTextNode ( hitGameGroupName );
		hitGroupNameCell.appendChild(text);
		mycurrent_row.appendChild(hitGroupNameCell);
		mytablebody.appendChild(mycurrent_row);
		
		var hitGames = hitGameGroup.hitGames;
		
		for ( var innerRow = 0; innerRow < hitGames.length; innerRow++ ) {
			var hitGame = hitGames[innerRow];
			var innerTableRow = document.createElement("tr");
			var blankCell = document.createElement("td");
			innerTableRow.appendChild(blankCell);
			var hitGameNameCell = document.createElement("td");
			innerTableRow.appendChild(hitGameNameCell);
			var hitGameName = document.createTextNode ( hitGame.name );
			hitGameNameCell.appendChild(hitGameName);
			mytablebody.appendChild(innerTableRow);
		}
		
	}

   mytable.appendChild(mytablebody);
   hitGamesListDiv.appendChild(mytable);
	
	
	
}



