var countdownPointer="";var gamesPopped=0;$(document).ready(function(){UpdateGames()});function UpdateGames(){$.ajax({type:"POST",url:"/svc/MiniBingoService.aspx/GetBingoSchedule",data:"{}",contentType:"application/json; charset=utf-8",dataType:"json",success:function(b){$("#MiniBingoContainer").empty();if(b.d==null||b.d.length==0){ShowErrorDivAndReloadIn30Secs();return}$("#servicemessagecontainer").hide();var a=false;$.each(b.d,function(c,d){CreateBingoRow(d,a);a=!a})},error:function(b,a){ShowErrorDivAndReloadIn30Secs()}});gamesPopped=0;resetCountDown()}function CreateBingoRow(b,a){if(b.PlayTime=="January 01, 1 00:00:00"){gamesPopped++;return}var c=$("#BingoRowTemplate").clone();if(a){c.addClass("odd")}c.find("#room").text(b.DisplayName);c.find("#gameName").text(b.GameType);c.find("#price").html("&pound;"+b.TicketValue.toFixed(2));c.find("#prize").html("&pound;"+b.PrizeAmount.toFixed(2));c.find("#gameTime").val(b.PlayTime);c.find("#startBingoGameLink").click(function(){_newWindow(b.GameUri,"")});c.show();$("#MiniBingoContainer").append(c)}function ShowErrorDivAndReloadIn30Secs(){$("#servicemessagecontainer").show()}function MakeGameUriLink(a){return"_newWindow(url,'');"}function resetCountDown(){if(countdownPointer==""){countdownPointer=callCountDown()}else{clearInterval(countdownPointer);countdownPointer=callCountDown()}}function callCountDown(){return setInterval("gameTimeCountDown()",990)}function gameTimeCountDown(){var e=document.getElementById("MiniBingoContainer");if(e==null){return}var c=e.getElementsByTagName("input");var d=e.getElementsByTagName("span");if(c==null||c.length<1){return}for(var a=0;a<c.length;a++){if(c[a].getAttribute("name")=="gameTime"){if(IsDivHidden(d[a])){continue}var b=calDiff(c[a].value);updateDiff(c[a]);if(b=="hide"){hideDiv(d[a])}else{renderTime(d[a],b)}}}}function calDiff(a){var b=new Date(a);return getTimeDifference(b)}function updateDiff(b){if(b==null){return}var a=new Date(b.value);a.setSeconds(a.getSeconds()-1);b.value=a}function getTimeDifference(a){var d=new Date(a);var c=d.getHours();var e=d.getMinutes();var b=d.getSeconds();if(c<1){return minsDiff(e,b)}return hoursDiff(c,e,b)}function minsDiff(b,a){if(b==1&&a>30){return"1 min "+a+" secs"}else{if(b>1){return b+" mins "+a+" secs"}}return"hide"}function hoursDiff(b,c,a){return b+" hours "+c+" mins "+a+" secs"}function hideDiv(b){if(b==null||b.parentNode==null){return}var a=b.parentNode.parentNode;a.style.display="none";CheckIfWeShouldGetMoreGames()}function IsDivHidden(b){if(b==null||b.parentNode==null){return true}var a=b.parentNode.parentNode;return a.style.display=="none"}function CheckIfWeShouldGetMoreGames(){gamesPopped++;if(gamesPopped>20){UpdateGames()}}function renderTime(b,a){if(b==null){return}b.innerHTML=a};
