// JavaScript Document
function displayOpeningTimes(theFeed){
	document.getElementById("FriendshipLounge").innerHTML = theFeed["Friendship"];
		document.getElementById("SunshineLounge").innerHTML = theFeed["Sunshine"];
	document.getElementById("SpeedBingoLounge").innerHTML = theFeed["Speed Bingo"];
	document.getElementById("HarmonyLounge").innerHTML = theFeed["Harmony"];

}

function displayWinnerFeed(theFeed,theDiv){
	
	var targetDiv = document.getElementById(theDiv);
	//alert("should display winners now");
	var preparedTable = '<table id="winnersTable" cellpadding="0" cellspacing="0" border="0"><tr class="winnersTableHeader"><td class="winnersLeftHeader"></td><td><p>Ganador</p></td><td><p>Premio</p></td><td><p>Juego</p></td><td class="winnersRightHeader"></td></tr>';
	//Checks if length of gamename is greater than 21 and adds ...
	for($i=0;$i<theFeed.length;$i++){
		if(theFeed[$i][4].length>21){
			
				var gameName = theFeed[$i][4].substring(0,21) + "...";
				
			}else{
				
				gameName = theFeed[$i][4];
				
			}
			
			
	//alert(theFeed[$i][0]);	
	preparedTable += '<tr class="winnerTD"><td class="winnersLeftBorder"></td><td><p>'+theFeed[$i][0]+'</p></td><td><p>&#8364;'+theFeed[$i][2]+'</p></td><td><p>'+gameName+'</p></td><td class="winnersRightBorder"></td></tr>';
		
	}
	preparedTable += '<tr class="winnersFooter"><td class="winnersLeftFooter"></td><td colspan="3"></td><td class="winnersRightFooter"></td></tr></table>';
	targetDiv.innerHTML = preparedTable;
	
}

function displayRoomFeed(theFeed,theDiv){
	
	var targetDiv = document.getElementById(theDiv);
	
	var preparedTable;
	
	preparedTable = '<table id="winnersTable" cellpadding="0" cellspacing="0" border="0"><tr class="winnersTableHeader"><td class="winnersLeftHeader"></td><td width="80"><p>Start time</p></td><td width="45"><p>Price</p></td><td width="80"><p>Game type</p></td><td><p>Game name</p></td><td class="winnersRightHeader"></td></tr>';
	
	for($i=0;$i<theFeed.length;$i++){
			
			var theTime = theFeed[$i][0].split(" ");
			//alert(theTime);
			theTime = theTime[1].substring(theTime[1].length-8,theTime[1].length-3);
			//alert(theTime);
			if(theTime.substring(0,2)>12){
			
				theTime += " PM";
				
			}else{
				
				theTime += " AM";
				
			}
			//alert(theTime);
			preparedTable +='<tr class="winnerTD"><td class="winnersLeftBorder"></td><td><p>'+theTime+'</p></td><td><p>'+theFeed[$i][1]+'p</p></td><td><p>'+theFeed[$i][2]+'</p></td><td><p>'+theFeed[$i][3]+'</p></td><td class="winnersRightBorder"></td></tr>';
	
		}
		if(theFeed.length==0){
				
	preparedTable+= '<tr class="winnerTD"><td class="winnersLeftBorder"></td><td colspan="4"><p>Schedule currently unavailable.</p></td><td class="winnersRightBorder"></td></tr>';
		
	}
		preparedTable += '<tr class="winnersFooter"><td class="winnersLeftFooter"></td><td colspan="4"></td><td class="winnersRightFooter"></td></tr></table>';
		targetDiv.innerHTML = preparedTable;
		
	
	
}

function bingoFeedObj(){
	
		
	this.retrieveFeed = function(type,params,targetDiv){
		
		//alert("doin something");
	

		var http = getXmlHttpObject();
	
	var params = "type="+type+"&params="+params+"&targetDiv="+targetDiv;
	http.open("POST", "../includes/bingoFeed.php", true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.send(params);

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {

	//	alert(http.responseText);
			
			//get array and insert data into target div
			
			//return response;
			
			//CHECK WHAT TYPE OF FEED AND RUN APPROPIATE DISPLAY FUNCTION
			
			if(type=="room"){
				eval(http.responseText);
			displayRoomFeed(response,targetDiv);
			}else if(type=="winners"){
				eval(http.responseText);
				displayWinnerFeed(response,targetDiv);
			}else if(type=="openingTimes"){
				eval(http.responseText);
				//return http.responseText;
				displayOpeningTimes(response);	
			}else if(type=="jackpots"){
			
				document.getElementById(targetDiv).innerHTML = http.responseText;
			  	$("#jackpotContainer").cycle({delay:4000,speed:1000});
				
			}else if(type=="totalJackpot"){
			
				document.getElementById(targetDiv).innerHTML = http.responseText;
			  	$(".totalJackpot").cycle({delay:2000,speed:1000});
				
			}
			
	
		}
	}


	}
	
	
	
}




