/*
JavaScript Bingo For Bingohall.com
Version : 2.0
Author : RevenueGiants (c) 2005
E-mail : affiliates@revenuegiants.com
*/
//image Locations
var topBanner =          new displayImage("http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/topbanner.gif",90,400,"Play to Win");
var bottomBanner =       new displayImage("http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/bottombanner.gif",45,400,"Play to Win");

var startGame =          new displayImage("http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/start.gif",60,234,"Click to Start");
var playAgain =          new displayImage("http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/playagain.gif",60,234,"Try Again");
var winImage =           new displayImage("http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/youwon.gif",60,234,"YOU WIN, click to claim prize");

var cardSelectedImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/cardsel.gif";
var cardWinImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/cardwin.gif";

var topBackgroundImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/topbuttonback.gif";
var ballBackgroundImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/buttonback.gif";
var ballSelected = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/used.gif";
var startButton = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/button.gif";

var bannerURL = "http://www.bingohall.com/adpage2.asp?sourceid=";
var offerURL = "http://www.bingohall.com/adpage2.asp?sourceid=";

// Images for the ball background
var bImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/b.gif"
var iImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/i.gif"
var nImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/n.gif"
var gImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/g.gif"
var oImage = "http://www.revenuegiants.com/js_content/bingohall_bingogame/version2/o.gif"



var sourceId = "";
var bannerSourceId = "";
var winText = "You Win!<br>Click here to Claim Your Free $6 Bonus.";
var numberWords = new Array();

if (document.images){
   image1 = new Image(100, 100);
   image1.src = topBackgroundImage;
   image2 = new Image(100, 100);
   image2.src = ballBackgroundImage;
   image3 = new Image(100, 100);
   image3.src = ballSelected;
   image4 = new Image(100, 100);
   image4.src = startButton;
   image5 = new Image(100, 100);
   image5.src = topBanner.Url;
   image6 = new Image(100, 100);
   image6.src = bottomBanner.Url;
   image7 = new Image(100, 100);
   image7.src = winImage.Url;
   image8 = new Image(100, 100);
   image8.src = startGame.Url;
   image9 = new Image(100, 100);
   image9.src = playAgain.Url;

   imagesel = new Image(100, 100);
   imagesel.src = cardSelectedImage;
   imagewin = new Image(100, 100);
   imagewin.src = cardWinImage;

   imageb = new Image(100, 100);
   imageb.src = bImage;
   imagei = new Image(100, 100);
   imagei.src = iImage;
   imagen = new Image(100, 100);
   imagen.src = nImage;
   imageg = new Image(100, 100);
   imageg.src = gImage;
   imageo = new Image(100, 100);
   imageo.src = oImage;

}
var drawTimer;
var InPlay = new Array();
var TotalBoardNum = 75;
var numberWords = new Array();
var UserNumbers = new Array();
var ComputerNumbers = new Array();


function displayImage(pURL,pHeight,pWidth,pAlt){
   this.Url = pURL;
   this.Height = pHeight;
   this.Width = pWidth;
   this.Alt   = pAlt;
}
function applyTopBannerStyle(pObject){
   if (topBanner.Url != ""){
      if (bannerURL != ""){
         pObject.innerHTML = "<a id ='topBannerLink' href=# onclick='return bannerLink();'><img src='"+topBanner.Url+"' height='"+topBanner.Height+"' width='"+topBanner.Width+"' alt='"+topBanner.Alt+"' border='0' id='topBannerImg'></a>";
      }
      else{
         pObject.innerHTML = "<img src='"+topBanner.Url+"' height='"+topBanner.Height+"' width='"+topBanner.Width+"' alt='"+topBanner.Alt+"' border='0' id='topBannerImg'>";
      }
   }
}
function applyBottomBannerStyle(pObject){
   if (bottomBanner.Url != ""){
      if (bannerURL != ""){
         pObject.innerHTML = "<a id ='topBannerLink' href=# onclick='return bannerLink();'><img src='"+bottomBanner.Url+"' height='"+bottomBanner.Height+"' width='"+bottomBanner.Width+"' alt='"+bottomBanner.Alt+"' border='0' id='bottomBannerImg'></a>";
      }
      else{
         pObject.innerHTML = "<img src='"+bottomBanner.Url+"' height='"+bottomBanner.Height+"' width='"+bottomBanner.Width+"' alt='"+bottomBanner.Alt+"' border='0' id='bottomBannerImg'>";
      }
   }
}

function bannerLink(){
   document.location.href = bannerURL + bannerSourceId;
   return false;
}

// Apply the Styles for the Winning Link.
function applyWinLinkStyle(){
   var bingoHallBoard = document.getElementById('winlink');
   bingoHallBoard.style.color='#ffffff';
   bingoHallBoard.style.fontSize = "14pt";
   bingoHallBoard.style.fontFamily = "verdana";
   bingoHallBoard.style.fontWeight = "bold";
   bingoHallBoard.style.textAlign='center';
}


function applyCardBingoStyle(pObject){
   pObject.style.fontFamily = "verdana";
   pObject.style.fontSize = "10pt";
   pObject.style.fontWeight = "bold";
   pObject.style.textAlign='center';
   pObject.style.color='#ffffff';
   pObject.style.backgroundColor='#000033';
}
// Apply the Styles for the Title of The Cards.

function applyCardTitleStyle(pObject){
   pObject.style.fontFamily = "verdana";
   pObject.style.fontSize = "10pt";
   pObject.style.fontWeight = "bold";
   pObject.style.textAlign='center';
   pObject.style.color='#4080C7';
   pObject.style.backgroundColor='#F5C40F';
}
// Apply the Styles for the Heading of the Board.
function applyBoardHeadStyle(pObject){
   pObject.style.backgroundImage="url('"+topBackgroundImage+"')";
   pObject.style.backgroundColor='#3856B0';
   pObject.style.color='#ffffff';
   pObject.style.fontFamily = "verdana";
   pObject.style.fontWeight = "bold";
   pObject.style.verticalAlign='bottom';
   pObject.style.textAlign='center';
   pObject.style.fontSize = "10pt";
}
// Apply the Styles for the Cells of the Board.
function applyBoardCellStyle(pObject){
   pObject.style.backgroundImage="url('"+ballBackgroundImage+"')";
   pObject.style.backgroundColor='#3856B0';
   pObject.style.color='#ffffff';
   pObject.style.width='24px';
   pObject.style.height='24px';
   pObject.style.verticalAlign='middle';
   pObject.style.textAlign='center';
   pObject.style.fontWeight = "normal";
   pObject.style.fontSize = "10pt";
}
// Apply the Styles for the cell containing the result text.
function applyOutcomeCellStyle(){
   var bingoHallBoard = document.getElementById('outcomecell');
   bingoHallBoard.style.color='#ffffff';
   bingoHallBoard.style.fontSize = "12pt";
   bingoHallBoard.style.fontFamily = "verdana";
   bingoHallBoard.style.fontWeight = "bold";
   bingoHallBoard.style.textAlign='center';
   bingoHallBoard.style.height='50px';
   bingoHallBoard.style.width='200px';
}

// Apply the Styles for the ball display.
function applyBallChosenNumberStyle(){
   var bingoHallBoard = document.getElementById('ballNumber');
   bingoHallBoard.style.color='#000000';
   bingoHallBoard.style.fontSize = "18pt";
   bingoHallBoard.style.fontFamily = "verdana";
   bingoHallBoard.style.fontWeight = "bold";
   bingoHallBoard.style.textAlign='center';
   bingoHallBoard.style.verticalAlign='middle';
   bingoHallBoard.style.width = '111px';
   bingoHallBoard.style.height = '111px';

}
// Apply the Styles for the ball text display.
function applyBallChosenTextStyle(){
   var bingoHallBoard = document.getElementById('ballText');
   bingoHallBoard.style.color='#ffffff';
   bingoHallBoard.style.fontSize = "10pt";
   bingoHallBoard.style.fontFamily = "verdana";
   bingoHallBoard.style.fontWeight = "bold";
   bingoHallBoard.style.textAlign='center';
}
function applyCardCellStyle(pObject){
   pObject.style.backgroundImage="url('')";
   pObject.style.backgroundColor='#ffffff';
   pObject.style.color='#000000';
   pObject.style.width='24px';
   pObject.style.height='24px';
   pObject.style.verticalAlign='middle';
   pObject.style.textAlign='center';
   pObject.style.fontWeight = "normal";
   pObject.className = "notsel";
   pObject.style.border = "1px solid #3856B0";
   pObject.style.fontSize = "10pt";
}
function applyCardFoundStyle(pElement){
   pElement.style.backgroundImage="url('"+cardSelectedImage+"')";
   pElement.style.fontWeight = "bold";
   pElement.className = "Selected";
}
function applyCardTableStyle(pObject){
   pObject.style.border = "1px solid white";
}
function InArray(val, arr){
   for( var i = 0; i < arr.length; i++ )
      if ( arr[i] == val ) return i+"";
   return false;
}
function drawboard(pSourceId,pBannerSourceId){
   sourceId = pSourceId;
   bannerSourceId = pBannerSourceId;
   setNumberText();
   document.write("<table id='bingoContainer' border='0'><tr><td colspan=2 id='topBannerCell'></td></tr><tr><td id='boardCell'><table id='bingoHallBoard' cellpadding='0' cellspacing='0' border='0'></table></td><td valign='top' align='center'><table cellpadding='2' cellspacing='0' border='0' style='height:350px;'><tr><td colspan='2' id='numberPick' align='center'><table cellpadding='0' cellspacing='0' border='0'><tr><td align='center'><table cellpadding='0' cellspacing='0' border='0'><tr><td id='ballNumber'></td></tr></table></td></tr><tr><td id='ballText'></td></tr></table></td></tr><tr><td><table id='userPlay' border='0' cellpadding='0' cellspacing='0'></table></td><td><table id='computerPlay' border='0' cellpadding='0' cellspacing='0'></table></td></tr><tr height='80'><td colspan='2' id='outcomecell' valign='middle'></td></tr></table></td></tr><tr><td colspan=2 id='bottomBannerCell'></td></tr></table>");

   var pageObject = document.getElementById('topBannerCell');
   applyTopBannerStyle(pageObject);
   var pageObject = document.getElementById('bottomBannerCell');
   applyBottomBannerStyle(pageObject);

   //set the style of the container.
   var pageObject = document.getElementById('bingoContainer');
   pageObject.style.backgroundColor='#3856B0';
   pageObject.style.color='#ffffff';
   pageObject.style.fontFamily = "verdana";
   pageObject.style.fontSize = "10pt";
   pageObject.style.width = "400px";

   applyBallChosenNumberStyle();
   applyBallChosenTextStyle();
   applyOutcomeCellStyle();


   //put the start button in place
   pageObject = document.getElementById('outcomecell');
   pageObject.innerHTML = "<a href='#' onclick='return newGame()'><img src='"+startGame.Url+"' border='0' height='"+startGame.Height+"' width='"+startGame.Width+"' border='0'></a>";

   pageObject = document.getElementById('userPlay');
   pageObject.style.border="1px solid white";
   pageObject = document.getElementById('computerPlay');
   pageObject.style.border="1px solid white";


   pageObject = document.getElementById('numberPick');
   pageObject.style.height = "80px";

   // get the bingo board
   pageObject = document.getElementById('boardCell');
   pageObject.style.width = "120px";

   pageObject = document.getElementById('bingoHallBoard');
   pageObject.style.border="1px solid black";

   //get the headers
   Row = pageObject.insertRow(0);
   cellValue = Row.insertCell(0);
   applyBoardHeadStyle(cellValue);
   cellValue.innerHTML = "B";
   cellValue = Row.insertCell(1);
   applyBoardHeadStyle(cellValue);
   cellValue.innerHTML = "I";
   cellValue = Row.insertCell(2);
   applyBoardHeadStyle(cellValue);
   cellValue.innerHTML = "N";
   cellValue = Row.insertCell(3);
   applyBoardHeadStyle(cellValue);
   cellValue.innerHTML = "G";
   cellValue = Row.insertCell(4);
   applyBoardHeadStyle(cellValue);
   cellValue.innerHTML = "0";
   //create the rows.
   for (i=1;i<16;i++){
      Row = pageObject.insertRow(i);
      cellValue = Row.insertCell(0);
      ballvalue = i;
      cellValue.innerHTML = ballvalue;
      cellValue.id = "board["+i+"]"

      cellValue = Row.insertCell(1);
      ballvalue = i + 15;
      cellValue.innerHTML = ballvalue;
      cellValue.id = "board["+ballvalue+"]"

      cellValue = Row.insertCell(2);
      ballvalue = i + 30;
      cellValue.innerHTML = ballvalue;
      cellValue.id = "board["+ballvalue+"]"

      cellValue = Row.insertCell(3);
      ballvalue = i + 45;
      cellValue.innerHTML = ballvalue;
      cellValue.id = "board["+ballvalue+"]"

      cellValue = Row.insertCell(4);
      ballvalue = i + 60;
      cellValue.innerHTML = ballvalue;
      cellValue.id = "board["+ballvalue+"]"
   }
   resetBoard();
}


function resetBoard(){
   //clear all the balls back to unselected
   for (i=1;i<=TotalBoardNum;i++){
     ball = document.getElementById("board["+i+"]");
     applyBoardCellStyle(ball);
   }
   var userCard = document.getElementById('userPlay');
   var computerCard = document.getElementById('computerPlay');

   //now populate the user title
   Row = userCard.insertRow(0);
   cellValue = Row.insertCell(0);
   cellValue.colSpan = 5;
   cellValue.innerHTML = 'Your Card';
   applyCardTitleStyle(cellValue);

   Row = userCard.insertRow(1);
   cellValue = Row.insertCell(0);
   cellValue.innerHTML = "B";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(1);
   cellValue.innerHTML = "I";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(2);
   cellValue.innerHTML = "N";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(3);
   cellValue.innerHTML = "G";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(4);
   cellValue.innerHTML = "O";
   applyCardBingoStyle(cellValue);

   //now populate the computer title
   Row = computerCard.insertRow(0);
   cellValue = Row.insertCell(0);
   cellValue.colSpan = 5;
   cellValue.innerHTML = 'Computer Card';
   applyCardTitleStyle(cellValue);

   Row = computerCard.insertRow(1);
   cellValue = Row.insertCell(0);
   cellValue.innerHTML = "B";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(1);
   cellValue.innerHTML = "I";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(2);
   cellValue.innerHTML = "N";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(3);
   cellValue.innerHTML = "G";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(4);
   cellValue.innerHTML = "O";
   applyCardBingoStyle(cellValue);

   var currentId = 0;
   for (i=0;i<5;i++){
      Row = userCard.insertRow(i+2);
      for (y=0;y<5;y++){
         cellValue = Row.insertCell(y);
         cellValue.innerHTML = "&nbsp;";
         cellValue.id = "uCard_"+currentId;
         applyCardCellStyle(cellValue);
         currentId ++;
      }
   }
   var currentId = 0;
   for (i=0;i<5;i++){
      Row = computerCard.insertRow(i+2);
      for (y=0;y<5;y++){
         cellValue = Row.insertCell(y);
         cellValue.innerHTML = "&nbsp;";
         cellValue.id = "cCard_"+currentId;
         applyCardCellStyle(cellValue);
         currentId ++;
         var pIndex = i*5+y+1;
      }
   }
}
function newGame(){
   window.clearInterval(drawTimer);
   document.getElementById('ballNumber').innerHTML = "Starting";
   document.getElementById('ballText').innerHTML = "Please Wait";
   document.getElementById('outcomecell').innerHTML = "";

   resetBoard();

   InPlay = new Array();

   //clear the user and computer selection
   var userCard = document.getElementById('userPlay');
   var computerCard = document.getElementById('computerPlay');

   //clear the cards
   numRows = userCard.rows.length;
   for (i=0; i < numRows; i++) {
      userCard.deleteRow(0);
   }
   numRows = computerCard.rows.length;
   for (i=0; i < numRows; i++) {
      computerCard.deleteRow(0);
   }

   //populate the user and computer cards
   //create the user card
   var idx;
   for (i=0;i<5;i++){
      for (j=0;j<5;j++){
         var base = (j*15)+1;
         curN = parseInt(Math.random()*15)+base;
         while (InArray(curN, UserNumbers) ) {
            curN = parseInt(Math.random()*15)+base;
         }
         idx =(i*5)+j;
         UserNumbers[idx] = curN;
      }
   }


   //create the computer card
   var idx;
   for (i=0;i<5;i++){
      for (j=0;j<5;j++){
         var base = (j*15)+1;
         curN = parseInt(Math.random()*15)+base;
         while (InArray(curN, ComputerNumbers) ) {
            curN = parseInt(Math.random()*15)+base;
         }
         idx =(i*5)+j;
         ComputerNumbers[idx] = curN;
      }
   }

   //now populate the user title
   Row = userCard.insertRow(0);
   cellValue = Row.insertCell(0);
   cellValue.colSpan = 5;
   cellValue.innerHTML = 'Your Card';
   applyCardTitleStyle(cellValue);


   Row = userCard.insertRow(1);
   cellValue = Row.insertCell(0);
   cellValue.innerHTML = "B";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(1);
   cellValue.innerHTML = "I";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(2);
   cellValue.innerHTML = "N";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(3);
   cellValue.innerHTML = "G";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(4);
   cellValue.innerHTML = "O";
   applyCardBingoStyle(cellValue);





   //now populate the computer title
   Row = computerCard.insertRow(0);
   cellValue = Row.insertCell(0);
   cellValue.colSpan = 5;
   cellValue.innerHTML = 'Computer Card';
   applyCardTitleStyle(cellValue);


   Row = computerCard.insertRow(1);
   cellValue = Row.insertCell(0);
   cellValue.innerHTML = "B";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(1);
   cellValue.innerHTML = "I";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(2);
   cellValue.innerHTML = "N";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(3);
   cellValue.innerHTML = "G";
   applyCardBingoStyle(cellValue);
   cellValue = Row.insertCell(4);
   cellValue.innerHTML = "O";
   applyCardBingoStyle(cellValue);




   var currentId = 0;
   for (i=0;i<5;i++){
      Row = userCard.insertRow(i+2);
      for (y=0;y<5;y++){
         cellValue = Row.insertCell(y);
         cellValue.innerHTML = UserNumbers[currentId];
         cellValue.id = "uCard_"+currentId;
         applyCardCellStyle(cellValue);
         currentId ++;
      }
   }

   var currentId = 0;
   for (i=0;i<5;i++){
      Row = computerCard.insertRow(i+2);
      for (y=0;y<5;y++){
         cellValue = Row.insertCell(y);
         cellValue.innerHTML = ComputerNumbers[currentId];
         cellValue.id = "cCard_"+currentId;
         applyCardCellStyle(cellValue);
         currentId ++;
         var pIndex = i*5+y+1;
      }
   }


   //start the number picker
   drawTimer = window.setTimeout(pickNumber,3000);

   return false;
}
function setBallBackgroundImage(pColumn){
   if (pColumn == "B"){
      document.getElementById('ballNumber').style.backgroundImage="url('"+bImage+"')";
   }
   if (pColumn == "I"){
      document.getElementById('ballNumber').style.backgroundImage="url('"+iImage+"')";
   }
   if (pColumn == "N"){
      document.getElementById('ballNumber').style.backgroundImage="url('"+nImage+"')";
   }
   if (pColumn == "G"){
      document.getElementById('ballNumber').style.backgroundImage="url('"+gImage+"')";
   }
   if (pColumn == "O"){
      document.getElementById('ballNumber').style.backgroundImage="url('"+oImage+"')";
   }

}
function pickNumber(){
   if (InPlay.length >= TotalBoardNum){
      //clear the timer

      return false;
   }

   curN = parseInt(Math.random()*75)+1;

   while ( (InPlay.length < TotalBoardNum) && InArray(curN, InPlay) ){
      curN = parseInt(Math.random()*75)+1;
   }
   InPlay[ InPlay.length ] = curN;

   var ColumnTitle = "B";
   //get the Letter asscociated with the pick
   if (curN > 15) ColumnTitle = "I";
   if (curN > 30) ColumnTitle = "N";
   if (curN > 45) ColumnTitle = "G";
   if (curN > 60) ColumnTitle = "O";


   //set the background image based on the ColumnTitle value
   setBallBackgroundImage(ColumnTitle);


   document.getElementById("ballNumber").innerHTML = ColumnTitle +"<br>"+curN;
   document.getElementById("ballText").innerHTML = numberWords[curN];

   if (selectOne(curN)){
      drawTimer = window.setTimeout(pickNumber,1500);
   }
}
function selectOne(pNo){
   //see if this number is in either the computer or the user card?

   ball = document.getElementById("board["+pNo+"]");
   ball.style.backgroundImage="url('"+ballSelected+"')";
   ball.style.fontWeight = "bold";

   var foundLoc = InArray(pNo, UserNumbers);
   if (foundLoc){
      //find and hilite the number
      var cardFound = document.getElementById("uCard_"+foundLoc);
      applyCardFoundStyle(cardFound);
   }
   foundLoc = InArray(pNo, ComputerNumbers);
   if (foundLoc){
      var cardFound = document.getElementById("cCard_"+foundLoc);
      applyCardFoundStyle(cardFound);
   }


   //see if we have any winners.
   var i, j, k, uret, cret, cardIdx, cardCheck, userWinCells, computerWinCells;
   // check by lines
   for (i=0;i<5;i++){
      uret = true;
      cret = true;
      userWinCells = new Array();
      computerWinCells = new Array();
      for (j=0;j<5;j++){
         cardIdx = i*5+j;
         cardCheck = document.getElementById("uCard_"+cardIdx);
         userWinCells.push(cardCheck);
         if (cardCheck.className != "Selected"){
            uret = false;
         }
         cardCheck = document.getElementById("cCard_"+cardIdx);
         computerWinCells.push(cardCheck);
         if (cardCheck.className != "Selected"){
            cret = false;
         }
      }
      if ( uret ){
         return userWin(userWinCells);
      }
      if ( cret ){
         return computerWin(computerWinCells);
      }
   }
   //check by cols
   for (i=0;i<5;i++){
      uret = true;
      cret = true;
      userWinCells = new Array();
      computerWinCells = new Array();
      for (j=0;j<5;j++){
         cardIdx = i+5*j;
         cardCheck = document.getElementById("uCard_"+cardIdx);
         userWinCells.push(cardCheck);
         if (cardCheck.className != "Selected"){
            uret = false;
         }
         cardCheck = document.getElementById("cCard_"+cardIdx);
         computerWinCells.push(cardCheck);
         if (cardCheck.className != "Selected"){
            cret = false;
         }
      }
      if ( uret ){
         return userWin(userWinCells);
      }
      if ( cret ){
         return computerWin(computerWinCells);
      }
   }


   //check major diagonal
   uret = true;
   cret = true;
   userWinCells = new Array();
   computerWinCells = new Array();
   for (i=0;i<5;i++){
      cardIdx = i*5+i;
      cardCheck = document.getElementById("uCard_"+cardIdx);
      userWinCells.push(cardCheck);
      if (cardCheck.className != "Selected"){
         uret = false;
      }
      cardCheck = document.getElementById("cCard_"+cardIdx);
      computerWinCells.push(cardCheck);
      if (cardCheck.className != "Selected"){
         cret = false;
      }
   }

   if ( uret ){
      return userWin(userWinCells);
   }
   if ( cret ){
      return computerWin(computerWinCells);
   }

   //check minor diagonal
   uret = true;
   cret = true;
   userWinCells = new Array();
   computerWinCells = new Array();
   for (i=5;i>0;i--){
      cardIdx = i*5-i;
      cardCheck = document.getElementById("uCard_"+cardIdx);
      userWinCells.push(cardCheck);
      if (cardCheck.className != "Selected"){
         uret = false;
      }
      cardCheck = document.getElementById("cCard_"+cardIdx);
      computerWinCells.push(cardCheck);
      if (cardCheck.className != "Selected"){
         cret = false;
      }
   }
   if ( uret ){
      return userWin(userWinCells);
   }
   if ( cret ){
      return computerWin(computerWinCells);
   }
   return true;

}
function userWin(winCells){
   for (i=0;i<winCells.length;i++){
      winCells[i].style.backgroundImage="url('"+cardWinImage+"')";
   }
   document.getElementById('outcomecell').innerHTML = "<a id='winlink' href='"+offerURL+sourceId+"'><img src='"+winImage.Url+"' border='0' height='"+winImage.Height+"' width='"+winImage.Width+"' border='0'></a>";
   applyWinLinkStyle();
   return false;
}
function computerWin(winCells){
   for (i=0;i<winCells.length;i++){
      winCells[i].style.backgroundImage="url('"+cardWinImage+"')";
   }
   document.getElementById('outcomecell').innerHTML = "<a href='#' onclick='return newGame()'><img src='"+playAgain.Url+"' border='0' height='"+playAgain.Height+"' width='"+playAgain.Width+"' border='0'></a>";
   return false;
}

function setNumberText(){
   numberWords[1]="Kelly's Eye";
   numberWords[2]="One Little Duck";
   numberWords[3]="Cup of Tea";
   numberWords[4]="Knock at the Door";
   numberWords[5]="Man Alive";
   numberWords[6]="Tom Mix";
   numberWords[7]="Lucky 7";
   numberWords[8]="Garden Gate";
   numberWords[9]="Doctors Orders";
   numberWords[10]="Tony's Den";
   numberWords[11]="Legs Eleven";
   numberWords[12]="One Dozen";
   numberWords[13]="Unlucky for Some";
   numberWords[14]="Valentines Day";
   numberWords[15]="Young and Keen";
   numberWords[16]="Sweet Sixteen";
   numberWords[17]="Dancing Queen";
   numberWords[18]="Coming of Age";
   numberWords[19]="Goodbye Teens";
   numberWords[20]="One Score";
   numberWords[21]="Key of the Door";
   numberWords[22]="Two Little Ducks";
   numberWords[23]="Thee and Me";
   numberWords[24]="Two Dozen";
   numberWords[25]="Duck and Dive";
   numberWords[26]="Pick and Mix";
   numberWords[27]="Gateway to Heaven";
   numberWords[28]="Over Weight";
   numberWords[29]="Rise and Shine";
   numberWords[30]="Dirty Gertie";
   numberWords[31]="Get up and Run";
   numberWords[32]="Buckle my Shoe";
   numberWords[33]="Dirty Knee";
   numberWords[34]="Ask for More";
   numberWords[35]="Jump and Jive";
   numberWords[36]="Three Dozen";
   numberWords[37]="More than Eleven";
   numberWords[38]="Christmas Cake";
   numberWords[39]="Steps";
   numberWords[40]="Naughty Forty";
   numberWords[41]="Time for Fun";
   numberWords[42]="Winnie the Pooh";
   numberWords[43]="Down on your Knees";
   numberWords[44]="Droopy Drawers";
   numberWords[45]="Halfway There";
   numberWords[46]="Up to Tricks";
   numberWords[47]="Four and Seven";
   numberWords[48]="Four Dozen";
   numberWords[49]="PC";
   numberWords[50]="Half a Century";
   numberWords[51]="Tweak of the Thumb";
   numberWords[52]="Danny La Rue";
   numberWords[53]="Stuck in the Tree";
   numberWords[54]="Clean the Floor";
   numberWords[55]="Snakes Alive";
   numberWords[56]="Was she worth it";
   numberWords[57]="Heinz Varieties";
   numberWords[58]="Make them Wait";
   numberWords[59]="Brighton Line";
   numberWords[60]="Five Dozen";
   numberWords[61]="Bakers Bun";
   numberWords[62]="Turn on the Screw";
   numberWords[63]="Tickle Me 63";
   numberWords[64]="Red Raw";
   numberWords[65]="Old Age Pension";
   numberWords[66]="Clickety Click";
   numberWords[67]="Made in Heaven";
   numberWords[68]="Saving Grace";
   numberWords[69]="Either Way Up";
   numberWords[70]="Three Score & Ten";
   numberWords[71]="Bang on the Drum";
   numberWords[72]="Six Dozen";
   numberWords[73]="Queen B";
   numberWords[74]="Candy Store";
   numberWords[75]="Strive & Strive";
}
document.write('</style>');
document.write('<table border=0 cellspacing=1 cellpadding=3>');
document.write('<tr><td align=center class=mojo_header><img src="http://www.bngohall.com/cgi-bin/bhl_game.cgi" height=0 width=0 border=0></td></tr>');
document.write('</table>');