<!doctype html>
<html>
<head>
<title>Pontoon or Draw Poker or Five Hundred - RJM Programming - March, 2018</title>
<style>
th, td { vertical-align:top; }
</style>
<script type='text/javascript'>
var ourgame=null, ntp='', ibit='', withintricknum=0, needed=6;
var bidarr=["No bid","6 spades","6 clubs","6 diamonds","6 hearts","6 no trumps","7 spades","7 clubs","7 diamonds","7 hearts","7 no trumps","8 spades","Misere","8 clubs","8 diamonds","8 hearts","8 no trumps","9 spades","9 clubs","9 diamonds","9 hearts","9 no trumps","10 spades","10 clubs","10 diamonds","Open Misere","10 hearts","10 no trumps"];
var sidarr=[0, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 250, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500, 500, 520];
var pots=[null];
var bids=[null];
var tricksper=[0,0];
var huh='', gnump=0, how='', lastfr=-1, kittynum=0, tricklist='', trickld='', ftl='', ffr=1, oldt='', upforgrabs=0;
var carddealnum=location.search.split('carddealnum=')[1] ? eval(location.search.split('carddealnum=')[1].split('&')[0]) : 2;
var numplayers=location.search.split('numplayers=')[1] ? eval(location.search.split('numplayers=')[1].split('&')[0]) : 2;
var startwith=location.search.split('startwith=')[1] ? eval(location.search.split('startwith=')[1].split('&')[0]) : 0;
var theplayers=[], origtd='', firstreveal=-1, nextoid='';
var ourpack, ourheap, anarray=[], aniarray=[], trickcnt=-1.1;
var cardsinpack=['TwoOfHearts','TwoOfDiamonds','TwoOfSpades','TwoOfClubs','ThreeOfHearts','ThreeOfDiamonds','ThreeOfSpades','ThreeOfClubs','FourOfHearts','FourOfDiamonds','FourOfSpades','FourOfClubs','FiveOfHearts','FiveOfDiamonds','FiveOfSpades','FiveOfClubs','SixOfHearts','SixOfDiamonds','SixOfSpades','SixOfClubs','SevenOfHearts','SevenOfDiamonds','SevenOfSpades','SevenOfClubs','EightOfHearts','EightOfDiamonds','EightOfSpades','EightOfClubs','NineOfHearts','NineOfDiamonds','NineOfSpades','NineOfClubs','TenOfHearts','TenOfDiamonds','TenOfSpades','TenOfClubs','JackOfHearts','JackOfDiamonds','JackOfSpades','JackOfClubs','QueenOfHearts','QueenOfDiamonds','QueenOfSpades','QueenOfClubs','KingOfHearts','KingOfDiamonds','KingOfSpades','KingOfClubs','AceOfHearts','AceOfDiamonds','AceOfSpades','AceOfClubs'];
var mypictures = new Array("//www.rjmprogramming.com.au/images/02h.gif",
"//www.rjmprogramming.com.au/images/02d.gif",
"//www.rjmprogramming.com.au/images/02s.gif",
"//www.rjmprogramming.com.au/images/02c.gif",
"//www.rjmprogramming.com.au/images/03h.gif",
"//www.rjmprogramming.com.au/images/03d.gif",
"//www.rjmprogramming.com.au/images/03s.gif",
"//www.rjmprogramming.com.au/images/03c.gif",
"//www.rjmprogramming.com.au/images/04h.gif",
"//www.rjmprogramming.com.au/images/04d.gif",
"//www.rjmprogramming.com.au/images/04s.gif",
"//www.rjmprogramming.com.au/images/04c.gif",
"//www.rjmprogramming.com.au/images/05h.gif",
"//www.rjmprogramming.com.au/images/05d.gif",
"//www.rjmprogramming.com.au/images/05s.gif",
"//www.rjmprogramming.com.au/images/05c.gif",
"//www.rjmprogramming.com.au/images/06h.gif",
"//www.rjmprogramming.com.au/images/06d.gif",
"//www.rjmprogramming.com.au/images/06s.gif",
"//www.rjmprogramming.com.au/images/06c.gif",
"//www.rjmprogramming.com.au/images/07h.gif",
"//www.rjmprogramming.com.au/images/07d.gif",
"//www.rjmprogramming.com.au/images/07s.gif",
"//www.rjmprogramming.com.au/images/07c.gif",
"//www.rjmprogramming.com.au/images/08h.gif",
"//www.rjmprogramming.com.au/images/08d.gif",
"//www.rjmprogramming.com.au/images/08s.gif",
"//www.rjmprogramming.com.au/images/08c.gif",
"//www.rjmprogramming.com.au/images/09h.gif",
"//www.rjmprogramming.com.au/images/09d.gif",
"//www.rjmprogramming.com.au/images/09s.gif",
"//www.rjmprogramming.com.au/images/09c.gif",
"//www.rjmprogramming.com.au/images/10h.gif",
"//www.rjmprogramming.com.au/images/10d.gif",
"//www.rjmprogramming.com.au/images/10s.gif",
"//www.rjmprogramming.com.au/images/10c.gif",
"//www.rjmprogramming.com.au/images/11h.gif",
"//www.rjmprogramming.com.au/images/11d.gif",
"//www.rjmprogramming.com.au/images/11s.gif",
"//www.rjmprogramming.com.au/images/11c.gif",
"//www.rjmprogramming.com.au/images/12h.gif",
"//www.rjmprogramming.com.au/images/12d.gif",
"//www.rjmprogramming.com.au/images/12s.gif",
"//www.rjmprogramming.com.au/images/12c.gif",
"//www.rjmprogramming.com.au/images/13h.gif",
"//www.rjmprogramming.com.au/images/13d.gif",
"//www.rjmprogramming.com.au/images/13s.gif",
"//www.rjmprogramming.com.au/images/13c.gif",
"//www.rjmprogramming.com.au/images/01h.gif",
"//www.rjmprogramming.com.au/images/01d.gif",
"//www.rjmprogramming.com.au/images/01s.gif",
"//www.rjmprogramming.com.au/images/01c.gif"
);

function Game(cdn) {
this.game = '';
this.number = cdn;
this.numnobid = 0;
this.trickcnt = 0;
this.trumps = '';
this.GameEnum = {
Pontoon : 2,
Draw_Poker : 5,
Five_Hundred : 10 };

if (cdn == this.GameEnum.Pontoon) {
this.game = 'Pontoon';
} else if (cdn == this.GameEnum.Draw_Poker) {
this.game = 'Draw Poker';
} else if (cdn == this.GameEnum.Five_Hundred) {
this.game = 'Five Hundred';
}

this.GetNumber = function() {
return this.number;
};
this.GetNumberNoBid = function() {
return this.numnobid;
};
this.IncrementNumberNoBid = function() {
this.numnobid++;
};
this.SetNumberNoBid = function(nb) {
this.numnobid=nb;
};

this.GetTrickCount = function() {
return this.trickcnt;
};
this.IncrementTrickCount = function() {
this.trickcnt++;
};
this.SetTrickCount = function(nb) {
this.trickcnt=nb;
};

this.GetTrumps = function() {
return this.trumps;
};
this.SetTrumps = function(nb) {
this.trumps=nb;
};
}

function Pot(one) {
this.total=one;
this.GetTotal = function() {
return this.total;
};
this.SetTotal = function(towhat) {
this.total=towhat;
};
this.AddToTotal = function(what) {
this.total+=what;
};
}

function Bid(from, howmuch) {
this.howmuch = howmuch;
this.from = from;
this.CalculateTotal = function(thepot) {
var found=false, thetot=0;
if (thepot == null) {
if (bids[0] == null) {
return 0;
} else {
for (var iy=0; iy<bids.length; iy++) {
thetot+=bids[iy].GetBid();
}
return thetot;
}
} else {
return thepot.GetTotal();
}
thepot.SetTotal=tow;
};
this.GetBid = function() {
return this.howmuch;
};
this.SetPot = function(thepot, tow) {
var found=false;
if (thepot == null) {
try {
eval("found=(bids[0] instanceof Bid);");
} catch(eee) {
found=false;
}
if (!found) {
thepot=this.from;
}
}
thepot.SetTotal=tow;
};
this.AddToPot = function(thepot, wh) {
var found=false;
if (thepot == null) {
try {
eval("found=(bids[0] instanceof Bid);");
} catch(eee) {
found=false;
}
if (!found) {
thepot=this.from;
}
}
thepot.AddToTotal+=wh;
};
}

function Player(fullname) {
this.fullname = fullname;
this.num=theplayers.length;
this.score=0;
this.upforgrabs=0;
this.goes=0;
this.how='';
this.bidwords='';
this.bidranking=-1;
this.chosenottobid=false;
this.madebid=false;
this.cardtotal=0;
this.numtoreject=0;
this.cards = new Array();
this.Bid = function(thepot, what) {
var found=false;
if (thepot == null) {
try {
eval("found=(pots[0] instanceof Pot);");
} catch(eee) {
found=false;
}
if (!found) {
pots[0]=new Pot(what);
thepot=pots[0];
this.madebid=true;
}
} else {
this.madebid=true;
thepot.AddToTotal(what);
}
};
this.GetCharacterBid = function() {
return this.bidwords;
};
this.AtStake = function() {
return this.upforgrabs;
};
this.GetBidRanking = function() {
return this.bidranking;
};
this.SetCharacterBid = function(cb) {
for (var ii=0; ii<bidarr.length; ii++) {
if (cb == bidarr[ii]) this.bidranking=ii;
if (cb == bidarr[ii]) this.upforgrabs=sidarr[ii];
}
this.bidwords=cb;
};
this.SetBidRanking = function(icb) {
for (var ii=0; ii<bidarr.length; ii++) {
if (icb == ii) this.bidwords=bidarr[ii];
if (icb == ii) this.upforgrabs=sidarr[ii];
}
this.bidranking=icb;
};
this.GetScore = function() {
return this.score;
};
this.GetGoes = function() {
return this.goes;
};
this.GetHow = function() {
return this.how;
};
this.SetAsNonBidder = function() {
this.chosenottobid = true;
};
this.SetAsBidder = function() {
this.madebid = true;
};
this.UnsetAsBidder = function() {
this.madebid = false;
this.chosenottobid = false;
};
this.AmBidder = function() {
return this.madebid;
};
this.AmNoBidder = function() {
return this.chosenottobid;
};
this.SetNoBidder = function() {
this.chosenottobid = true;
};
this.GetNumToReject = function() {
return this.numtoreject;
};
this.IncrementNumToReject = function() {
this.numtoreject++;
};
this.SetNumToReject = function(tor) {
this.numtoreject = tor;
};
this.SetTotal = function(theplayer, tow) {
var found=false;
if (thepot == null) {
try {
eval("found=(pots[0] instanceof Pot);");
} catch(eee) {
found=false;
}
if (!found) {
pots[0]=new Pot(tow);
thepot=pots[0];
}
} else {
thepot.SetTotal(tow);
}
};
this.SetFullname = function(fn) {
this.fullname = fn;
};
this.GetFullname = function() {
return this.fullname;
};
this.GetCardTotal = function() {
if (ourgame.GetNumber() == 5) { // Draw Poker
var five=[], fivec='', fived='', numdiff=0, pv=0;
//alert(document.getElementById('mydiv' + eval(1 + this.num)).innerHTML);
var isl=document.getElementById('mydiv' + eval(1 + this.num)).innerHTML.split('img ');
for (var jsl=1; jsl<isl.length; jsl++) {
if (isl[jsl].split('>')[0].indexOf('display:') == -1) {
five.push(isl[jsl].split('/images/')[1].split('.')[0]);
if (fived == '') {
numdiff++;
} else if (fivec.indexOf(isl[jsl].split('/images/')[1].split('.')[0].substring(0,2)) != -1) {
if (eval(fivec.indexOf(isl[jsl].split('/images/')[1].split('.')[0].substring(0,2).replace('01','14'))) > pv) pv=eval(fivec.indexOf(isl[jsl].split('/images/')[1].split('.')[0].substring(0,2).replace('01','14')));
} else {
numdiff++;
}
fivec+=fived + isl[jsl].split('/images/')[1].split('.')[0];
fived=',';
}
}
five.sort();
// Royal flush. A, K, Q, J, 10, all the same suit. ... 100000000
// Four of a kind. All four cards of the same rank. 10000000
// Full house. Three of a kind with a pair. 1000000
// Flush. Any five cards of the same suit, but not in a sequence. 100000
// Straight. ... 10000
// Three of a kind. ... 1000
// Two pair. ... 100
// Pair. 10
// Ace 1

this.cardtotal=0;
if (five.length == 5) {
var allthesamesuit=0, thoak=0, twoak=0, fh=0;
if ((',' + fivec + ',').split('h').length == 6) allthesamesuit=4;
if ((',' + fivec + ',').split('d').length == 6) allthesamesuit=3;
if ((',' + fivec + ',').split('c').length == 6) allthesamesuit=1;
if ((',' + fivec + ',').split('s').length == 6) allthesamesuit=2;

if (five[0].substring(0,2) == five[1].substring(0,2) && five[0].substring(0,2) == five[2].substring(0,2) && five[0].substring(0,2) != five[3].substring(0,2)) {
thoak=Math.floor(eval(eval(five[1].substring(0,2).replace('01','14')) / 1));
if (five[4].substring(0,2) == five[3].substring(0,2)) fh=Math.floor(eval(eval(five[1].substring(0,2)) / 2));
} else if (five[4].substring(0,2) != five[1].substring(0,2) && five[4].substring(0,2) == five[2].substring(0,2) && five[4].substring(0,2) == five[3].substring(0,2)) {
thoak=Math.floor(eval(eval(five[1].substring(0,2).replace('01','14')) / 1));
} else if (five[0].substring(0,2) != five[1].substring(0,2) && five[1].substring(0,2) == five[2].substring(0,2) && five[1].substring(0,2) == five[3].substring(0,2) && five[1].substring(0,2) != five[4].substring(0,2)) {
thoak=Math.floor(eval(eval(five[1].substring(0,2).replace('01','14')) / 1));
} else if (five[1].substring(0,2) != five[2].substring(0,2) && five[2].substring(0,2) == five[3].substring(0,2) && five[2].substring(0,2) == five[4].substring(0,2)) {
thoak=Math.floor(eval(eval(five[1].substring(0,2).replace('01','14')) / 1));
if (five[0].substring(0,2) == five[1].substring(0,2)) fh=Math.floor(eval(eval(five[3].substring(0,2)) / 2));
}

if (allthesamesuit != 0 && five[0].indexOf('01') != -1 && five[1].indexOf('10') != -1 && five[2].indexOf('11') != -1 && five[3].indexOf('12') != -1 && five[4].indexOf('13') != -1) {
this.cardtotal=eval(allthesamesuit * 100000000);
this.how=' for Royal Flush';
} else if (five[0].substring(0,2) == five[1].substring(0,2) && five[0].substring(0,2) == five[2].substring(0,2) && five[0].substring(0,2) == five[3].substring(0,2)) {
this.cardtotal=eval(1 * 10000000);
this.how=' for Four of a Kind';
} else if (five[4].substring(0,2) == five[1].substring(0,2) && five[4].substring(0,2) == five[2].substring(0,2) && five[4].substring(0,2) == five[3].substring(0,2)) {
this.cardtotal=eval(1 * 10000000);
this.how=' for Four of a Kind';
} else if (fh != 0) {
this.cardtotal=eval(fh * 1000000);
this.how=' for Full House';
} else if (allthesamesuit != 0) {
this.cardtotal=eval(allthesamesuit * 100000);
this.how=' for Flush';
} else if (numdiff == 5 && eval(eval(five[4].substring(0,2)) - eval(five[0].substring(0,2))) == 4) {
this.cardtotal=eval(Math.floor(eval(eval(five[4].substring(0,2)) / 2)) * 10000);
this.how=' for Straight';
} else if (numdiff == 5 && eval(eval(five[4].substring(0,2)) - eval(five[1].substring(0,2))) == 3 && eval(eval(five[4].substring(0,2)) - eval(five[0].substring(0,2))) == 12) {
this.cardtotal=eval(7 * 10000);
this.how=' for Straight';
} else if (thoak != 0) {
this.cardtotal=eval(thoak * 500);
this.how=' for Three of a Kind';
} else if (numdiff == 3) {
this.cardtotal=eval(Math.floor(eval(eval(five[4].substring(0,2)) / 2)) * 100);
this.how=' for Two Pairs';
} else if (numdiff == 4) {
this.cardtotal=eval(eval(pv) * 5);
this.how=' for Pair';
} else if (five[0].substring(0,2) == '01') {
this.cardtotal=7;
this.how='';
} else {
this.cardtotal=eval(Math.floor(eval(eval(five[4].substring(0,2)) / 2)) * 1);
this.how='';
}

}
} else {
this.how=' for ' + this.cardtotal;
}
return this.cardtotal;
};
this.SetScore = function(addthis) {
if (addthis != 0) {
var found=false;
if (pots[0] == null) {
try {
eval("found=(bids[0] instanceof Bid);");
} catch(eee) {
found=false;
}
if (found) {
addthis=bids[0].CalculateTotal(pots[0]);
}
} else {
addthis=pots[0].GetTotal();
}
}
this.score+=addthis;
};
this.SetGoes = function(addthis) {
this.goes+=addthis;
document.getElementById('score' + eval(1 + this.num)).innerHTML='Score: ' + this.score + '/' + this.goes;
};
this.SetCardTotal = function(addthis) {
//if (eval('' + addthis) == 0) alert(this.cardtotal);
this.cardtotal+=addthis;
};
this.Reset = function(aheap) {
for (var ju=0; ju<this.cards.length; ju++) {
aheap.Addone(this.cards[ju]);
}
pots=[null];
bids=[null];
this.how='';
this.cardtotal=0;
this.numtoreject=0;
this.cards = new Array();
document.getElementById('td' + eval(1 + this.num)).innerHTML=origtd.replace(/1/g,'' + eval(1 + this.num));
};
}

function Heap() {
this.cardat = 0;
this.cardpile = new Array();
this.Addone = function(onecard) {
this.cardpile.push(onecard);
};
this.Redeal = function(playerarr, numperplayer, apack) {
//for (var ju=0; ju<playerarr.length; ju++) {
// playerarr[ju].Reset(ourheap);
//}
var startat=0;
var howmany=this.cardpile.length;
if (numperplayer > 0) howmany=eval(this.cardat + playerarr.length * numperplayer);
for (var iu=this.cardat; iu<howmany; iu++) {
playerarr[startat].cards.push(this.cardpile[iu]);
playerarr[startat].SetCardTotal(playerarr[startat].cards[eval(-1 + playerarr[startat].cards.length)].ScorePontoon(playerarr[startat].GetCardTotal()));
if (ourgame.GetNumber() == 10) { // Five Hundred
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img onclick="if (analyzetricklist(' + eval(1 + startat) + ',this.src)) { this.style.border=' + "'" + '2px solid red' + "'; intrf(this," + eval(1 + startat) + '); }" style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[iu].GetName()) + '></img>';
} else if (ourgame.GetNumber() == 5) { // Draw Poker
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img onclick="this.style.border=' + "'" + '2px solid red' + "'; intr(" + eval(1 + startat) + ');" style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[iu].GetName()) + '></img>';
} else { // Pontoon
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[iu].GetName()) + '></img>';
}
startat++;
if (startat >= playerarr.length) startat=0;
}
this.cardat=howmany;
};
this.Another = function(apack,playerarr,playernum) {
if (ourgame.GetNumber() == 10) { // Five Hundred
var ite=playerarr[playernum].GetNumToReject();
playerarr[playernum].SetNumToReject(0);
for (var it=0; it<ite; it++) {
playerarr[playernum].cards.push(this.cardpile[this.cardat]);
//playerarr[playernum].SetCardTotal(playerarr[playernum].cards[eval(-1 + playerarr[playernum].cards.length)].ScorePontoon(playerarr[playernum].GetCardTotal()));
document.getElementById('mydiv' + eval(1 + playernum)).innerHTML+='<img onclick="if (analyzetricklist(' + eval(1 + playernum) + ',this.src)) { this.style.border=' + "'" + '2px solid red' + "'; intrf(this," + eval(1 + playernum) + '); }" id=i_' + eval(1 + playernum) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[this.cardat].GetName()) + '></img>';
this.cardat++;
}
//alert(document.getElementById('mydiv' + eval(1 + playernum)).innerHTML);
document.getElementById('ib' + eval(1 + playernum)).value=document.getElementById('ib' + eval(1 + playernum)).value.replace('(click 3 to reject ready for kitty, then click first playing card)','(click next playing card)');
} else if (ourgame.GetNumber() == 5) { // Draw Poker
for (var it=0; it<playerarr[playernum].GetNumToReject(); it++) {
playerarr[playernum].cards.push(this.cardpile[this.cardat]);
//playerarr[playernum].SetCardTotal(playerarr[playernum].cards[eval(-1 + playerarr[playernum].cards.length)].ScorePontoon(playerarr[playernum].GetCardTotal()));
document.getElementById('mydiv' + eval(1 + playernum)).innerHTML+='<img id=i_' + eval(1 + playernum) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[this.cardat].GetName()) + '></img>';
this.cardat++;
}
} else { // Pontoon
playerarr[playernum].cards.push(this.cardpile[this.cardat]);
playerarr[playernum].SetCardTotal(playerarr[playernum].cards[eval(-1 + playerarr[playernum].cards.length)].ScorePontoon(playerarr[playernum].GetCardTotal()));
document.getElementById('mydiv' + eval(1 + playernum)).innerHTML+='<img id=i_' + eval(1 + playernum) + '_' + Math.floor(Math.random() * 123456) + ' src=' + apack.GetNameImageUrl(this.cardpile[this.cardat].GetName()) + '></img>';
this.cardat++;
}
};
}

function Pack(names, imageurls, shuffle, startwith) {
if (names.length == 0) {
if (shuffle) {
var sofar=',', ii, jj=0;
if (ourgame.GetNumber() == 10) { // Five Hundred
sofar+='TwoOfHearts,TwoOfDiamonds,TwoOfSpades,TwoOfClubs,ThreeOfHearts,ThreeOfDiamonds,ThreeOfSpades,ThreeOfClubs,FourOfDiamonds,FourOfSpades';
jj=sofar.substring(1).split(',').length;
sofar+=',';
}
var choice=Math.floor(Math.random() * cardsinpack.length);
var firstchoice=choice;
for (ii=0; ii<eval(-jj + cardsinpack.length); ii++) {
while (sofar.indexOf(',' + cardsinpack[choice] + ',') != -1) {
choice=Math.floor(Math.random() * cardsinpack.length);
}
eval("names.push(new " + cardsinpack[choice] + "('" + cardsinpack[choice] + "'));");
imageurls.push(mypictures[choice]);
sofar+=(cardsinpack[choice] + ',');
choice=firstchoice;
}
} else {
for (ii=0; ii<cardsinpack.length; ii++) {
eval("names.push(new " + cardsinpack[ii] + "('" + cardsinpack[ii] + "'));");
imageurls.push(mypictures[ii]);
}
}
}
this.names = names;
this.imageurls = imageurls;
this.startwith = startwith;
this.GetNameImageUrl = function(acardname) {
for (var ip=0; ip<this.names.length; ip++) {
if (acardname == this.names[ip].GetName()) return this.imageurls[ip];
}
return '';
};
this.Deal = function(playerarr, numperplayer) {
var startat=0;
var howmany=this.names.length;
if (numperplayer > 0) howmany=eval(playerarr.length * numperplayer);
for (var iu=0; iu<howmany; iu++) {
playerarr[startat].cards.push(this.names[iu]);
playerarr[startat].SetCardTotal(playerarr[startat].cards[eval(-1 + playerarr[startat].cards.length)].ScorePontoon(playerarr[startat].GetCardTotal()));
if (ourgame.GetNumber() == 10) { // Five Hundred
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img onclick="if (analyzetricklist(' + eval(1 + startat) + ',this.src)) { this.style.border=' + "'" + '2px solid red' + "'; intrf(this," + eval(1 + startat) + '); }" style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + iu + ' src=' + this.imageurls[iu] + '></img>';
} else if (ourgame.GetNumber() == 5) { // Draw Poker
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img onclick="this.style.border=' + "'" + '2px solid red' + "'; intr(" + eval(1 + startat) + ');" style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + iu + ' src=' + this.imageurls[iu] + '></img>';
} else { // Pontoon
document.getElementById('mydiv' + eval(1 + startat)).innerHTML+='<img style=visibility:hidden; id=i_' + eval(1 + startat) + '_' + iu + ' src=' + this.imageurls[iu] + '></img>';
}
startat++;
if (startat >= playerarr.length) startat=0;
}
for (var iiu=howmany; iiu<this.names.length; iiu++) {
ourheap.Addone(this.names[iiu]);
}
};
}

function intrfh(scrutinize,uos,uwho) {
if (ourgame.GetNumber() == 10) { // Five Hundred
if (scrutinize && theplayers[eval(eval(eval(-1 + uwho) % 4) + 0)].GetBidRanking() <= lastfr) {
uos.value='';
alert('Bad bid, try again.');
} else {
if (scrutinize) lastfr=theplayers[eval(eval(eval(-1 + uwho) % 4) + 0)].GetBidRanking();
var ready=false;
nextoid='';
for (var fr=firstreveal; fr<=eval(3 + firstreveal); fr++) {
if (theplayers[eval(eval(eval(-1 + uwho) % 4) + 0)].GetCharacterBid() != "No bid") {
document.getElementById('nobidopt' + eval(eval(eval(-1 + fr) % 4) + 1)).innerHTML="No bid on top of " + theplayers[eval(eval(eval(-1 + uwho) % 4) + 0)].GetFullname() + "'s " + theplayers[eval(eval(eval(-1 + uwho) % 4) + 0)].GetCharacterBid();
}
if (uos.id == 'bidsel' + eval(eval(eval(-1 + fr) % 4) + 1)) {
ready=true;
} else if (ready) {
if (ourgame.GetNumberNoBid() < 3) {
nextoid='bidsel' + eval(eval(eval(-1 + fr) % 4) + 1);
}
ready=false;
}
}
if (nextoid == '' && ready && ourgame.GetNumberNoBid() < 3) {
nextoid='bidsel' + eval(eval(eval(3 + firstreveal) % 4) + 1);
}
if (nextoid != '') {
uos.value='';
uos.style.visibility='hidden';
document.getElementById(nextoid).style.visibility='visible';
document.getElementById(uos.id.replace('bidsel','ib')).click();
setTimeout(atm, 1000);
} else {
uos.style.visibility='hidden';
document.getElementById(uos.id.replace('bidsel','ib')).click();
document.getElementById('information').innerHTML='Rejection ready for Kitty and Leading Card';
reveal(document.getElementById('ib' + eval(eval(eval(3 + firstreveal) % 4) + 1)));
}
}
}
}

function atm() {
alert('Ready for your bid, ' + theplayers[eval(-1 + eval(nextoid.replace('bidsel','')))].GetFullname());
document.getElementById(nextoid.replace('bidsel','ib')).click();
}

function intr(uwho) {
if (ourgame.GetNumber() == 5) { // Draw Poker
theplayers[eval(-1 + uwho)].IncrementNumToReject();
document.getElementById('im' + uwho).style.visibility='visible';
} else if (ourgame.GetNumber() == 10 && ourgame.GetNumberNoBid() > 0) { // Five Hundred
theplayers[eval(-1 + uwho)].IncrementNumToReject();
var ik=ourgame.GetNumberNoBid();
ik--;
ourgame.SetNumberNoBid(ik);
if (ik == 0) {
document.getElementById('im' + uwho).style.visibility='visible';
document.getElementById('im' + uwho).click();
}
}
}

function analyzetricklist(divnum,iv) {
// 1,No bid on top of Player1's 6 spades,07s,10s,10c,09h
if (tricklist.indexOf(',') != -1) {
var myl='', myld='', vsiv=iv.split('/images/')[1].split('.')[0].replace('back01','joker');
var tll=tricklist.replace('back01','joker').split(',');
var playeris=tll[1].replace("No bid on top of ","").replace("'s","").split(" ")[0];
var trumpsare=tll[1].replace("No bid on top of ","").replace("'s","").replace(playeris + " ","").toLowerCase();
if (trumpsare.toLowerCase().indexOf('misere') != -1) {
needed=0;
} else {
needed=eval(trumpsare.split(" ")[0]);
}
var ltrumps=" ", alttrumps=" ";
if (trumpsare.toLowerCase().split(" ").length > 1) {
ltrumps=trumpsare.toLowerCase().split(" ")[1].substring(0,1);
if (ltrumps == 'd') alttrumps='11h';
if (ltrumps == 'h') alttrumps='11d';
if (ltrumps == 'c') alttrumps='11s';
if (ltrumps == 's') alttrumps='11c';
}
var firstlead=tll[2];
var thislead=vsiv; //tll[eval(-1 + tll.length)];
if (thislead.substring(2,3) == 'k' && trumpsare.indexOf('no ') == -1 && trumpsare.indexOf('isere') == -1) firstlead='99' + trumpsare.toLowerCase().split(" ")[1].substring(0,1);
var ili=document.getElementById('mydiv' + divnum).innerHTML.replace('back01','joker').split('<img ');
for (var jli=1; jli<ili.length; jli++) {
if (ili[jli].split('>')[0].indexOf('none') == -1 && ili[jli].split('>')[0].indexOf('hidden') == -1) {
myl+=myld + ili[jli].split('>')[0].split('/images/')[1].split('.')[0];
myld=',';
}
}
//alert('myl=' + myl + ' should contain ' + firstlead + '?');
if (myl.indexOf(firstlead) == -1 && tll.length == 3) {
tricklist=tricklist.replace(',' + firstlead, ',' + thislead);
firstlead=thislead;
}
var ok=false;
if (firstlead != thislead) {
if (firstlead.substring(2,3) == thislead.substring(2,3)) ok = true;
if (myl.indexOf(firstlead.substring(2,3)) != -1) {
if (thislead.substring(2,3) == 'k') ok = true;
if (firstlead.substring(0,2) == '99' && thislead.substring(0,2) == '11' && ((ltrumps.replace('h','d') == 'd' && (firstlead.substring(2,3) == 'd' || firstlead.substring(2,3) == 'h')) || (ltrumps.replace('c','s') == 's' && (firstlead.substring(2,3) == 'c' || firstlead.substring(2,3) == 's')) || (ltrumps.replace('h','d') == 'd' && (firstlead.substring(2,3) == 'h' || firstlead.substring(2,3) == 'd')) || (ltrumps.replace('c','s') == 's' && (firstlead.substring(2,3) == 's' || firstlead.substring(2,3) == 'c')))) ok = true;
if (ltrumps != ' ' && thislead.substring(0,2) == '11' && ((ltrumps.replace('h','d') == 'd' && (firstlead.substring(2,3) == 'd' || firstlead.substring(2,3) == 'h')) || (ltrumps.replace('c','s') == 's' && (firstlead.substring(2,3) == 'c' || firstlead.substring(2,3) == 's')) || (ltrumps.replace('h','d') == 'd' && (firstlead.substring(2,3) == 'h' || firstlead.substring(2,3) == 'd')) || (ltrumps.replace('c','s') == 's' && (firstlead.substring(2,3) == 's' || firstlead.substring(2,3) == 'c')))) ok = true;
if (!ok) alert('You should follow suit.');
if (!ok) return false;
}
}
var anal=(tricklist.replace('back01','joker') + ',' + thislead.replace('back01','joker')).toLowerCase().split(',');
var iprfr=firstreveal, prfr='', ioff=firstreveal;
//alert('anal.length=' + anal.length + ' via ' + (tricklist + ',' + thislead));
var six=6;
if (anal.length >= 6) {
if (anal[2] == anal[3]) six=7;
}
if (anal.length >= six) {
prfr=anal[eval(-4 + anal.length)];
if (prfr == 'joker') return true;
for (var jprfr=eval(-3 + anal.length); jprfr<=eval(-1 + anal.length); jprfr++) {
ioff++;
if (ioff == 5) ioff=1;
if (anal[jprfr] == 'joker') {
prfr=anal[jprfr];
firstreveal=ioff;
return true;
} else if (anal[jprfr] == ('11' + ltrumps)) {
prfr=anal[jprfr];
firstreveal=ioff;
} else if (anal[jprfr] == alttrumps && prfr != ('11' + ltrumps)) {
prfr=anal[jprfr];
firstreveal=ioff;
} else if (prfr == alttrumps) {
if (anal[jprfr] == ('11' + ltrumps)) {
prfr=anal[jprfr];
firstreveal=ioff;
}
} else if (ltrumps != ' ' && prfr.indexOf(ltrumps) == -1 && anal[jprfr].indexOf(ltrumps) != -1) {
prfr=anal[jprfr];
firstreveal=ioff;
} else if (ltrumps != ' ' && prfr.indexOf(ltrumps) != -1 && anal[jprfr].indexOf(ltrumps) != -1 && anal[jprfr].substring(0,2) == '11') {
prfr=anal[jprfr];
firstreveal=ioff;
} else if (ltrumps != ' ' && prfr.indexOf(ltrumps) != -1 && anal[jprfr].indexOf(ltrumps) != -1 && eval(prfr.substring(0,2).replace('01','14').replace('11','15')) < eval(anal[jprfr].substring(0,2).replace('01','14').replace('11','15'))) {
prfr=anal[jprfr];
firstreveal=ioff;
} else if (prfr.indexOf(ltrumps) == -1 && anal[jprfr].indexOf(ltrumps) == -1) {
if (prfr.substring(2,3) == anal[jprfr].substring(2,3) && eval(prfr.substring(0,2).replace('01','14')) < eval(anal[jprfr].substring(0,2).replace('01','14'))) {
prfr=anal[jprfr];
firstreveal=ioff;
}
}
}
//alert('firstreveal=' + firstreveal + ' via ' + tricklist);
}
//alert(tricklist + ' vs ' + iv + ' versus ' + myl);
}
return true;
}

function intrf(uoi,uwho) {
withintricknum=0;
if (ourgame.GetNumber() == 10) { // Five Hundred
if (ourgame.GetNumberNoBid() > 0) {
//document.title='why';
theplayers[eval(-1 + uwho)].IncrementNumToReject();
var ik=ourgame.GetNumberNoBid();
ik--;
ourgame.SetNumberNoBid(ik);
if (ik == 0) {
document.getElementById('im' + uwho).style.visibility='visible';
document.getElementById('im' + uwho).click();
trickcnt=1.1;
trickld=',';
tricklist=firstreveal + trickld + document.getElementById('nobidopt1').innerHTML + trickld + uoi.src.split('/images/')[1].split('.')[0];
ffr=firstreveal;
ftl=tricklist;
//alert('0:' + tricklist);
ourgame.SetTrickCount(0);
document.getElementById('information').innerHTML='Playing Out the Hands';
document.getElementById('tinstructions').innerHTML=theplayers[0].GetFullname() + '/' + theplayers[2].GetFullname() + " " + tricksper[0] + " Tricks " + tricksper[1] + " " + theplayers[1].GetFullname() + '/' + theplayers[3].GetFullname();
document.getElementById('tinstructions').innerHTML+='<hr>';
document.getElementById('tinstructions').innerHTML+='<br>Regarding Trick ' + Math.floor(trickcnt) + ':<br>';
if (document.getElementById('span1').innerHTML.toLowerCase().indexOf('misere') != -1 && upforgrabs == 500) { // open misere
document.getElementById('om').innerHTML=document.getElementById('mydiv' + firstreveal).innerHTML.replace(/\ id\=/g,' data-id=');
}
}
} else {
//document.title='why2';
//alert('Play this ' + uoi.src);
document.getElementById('tinstructions').innerHTML+='<span>' + theplayers[eval(-1 + uwho)].GetFullname() + ' played <img src=' + uoi.src + '></img></span>';
uoi.style.display='none';
withintricknum=eval(('' + trickcnt).split('.')[1]);


if (withintricknum == 1) {
tricklist+=trickld + uoi.src.split('/images/')[1].split('.')[0];
//alert('1:' + tricklist);
trickld=',';
document.getElementById('ib' + eval(eval(eval(-1 + firstreveal) % 4) + 1)).click();
ntp=('Next to play in trick ' + Math.floor(trickcnt) + ' card ' + eval(1 + withintricknum) + ' of 4 is ' + theplayers[eval(eval(eval(0 + firstreveal) % 4) + 0)].GetFullname() );
ibit='ib' + eval(eval(eval(0 + firstreveal) % 4) + 1);
setTimeout(nextc,500);
} else if (withintricknum == 2) {
tricklist+=trickld + uoi.src.split('/images/')[1].split('.')[0];
trickld=',';
document.getElementById('ib' + eval(eval(eval(0 + firstreveal) % 4) + 1)).click();
ntp=('Next to play in trick ' + Math.floor(trickcnt) + ' card ' + eval(1 + withintricknum) + ' of 4 is ' + theplayers[eval(eval(eval(1 + firstreveal) % 4) + 0)].GetFullname() );
ibit='ib' + eval(eval(eval(1 + firstreveal) % 4) + 1);
setTimeout(nextc,500);
} else if (withintricknum == 3) {
tricklist+=trickld + uoi.src.split('/images/')[1].split('.')[0];
trickld=',';
document.getElementById('ib' + eval(eval(eval(1 + firstreveal) % 4) + 1)).click();
ntp=('Next to play in trick ' + Math.floor(trickcnt) + ' card ' + eval(1 + withintricknum) + ' of 4 is ' + theplayers[eval(eval(eval(2 + firstreveal) % 4) + 0)].GetFullname() );
ibit='ib' + eval(eval(eval(2 + firstreveal) % 4) + 1);
setTimeout(nextc,500);
} else if (1 == 1) {
ntp='';
document.getElementById('ib' + eval(eval(eval(2 + firstreveal) % 4) + 1)).click();
//document.getElementById('ib' + eval(eval(eval(2 + firstreveal) % 4) + 1)).click();
//document.title='' + eval(eval(eval(2 + firstreveal) % 4) + 1);
//ntp=('Next to play in trick ' + Math.floor(trickcnt) + ' card ' + eval(1 + withintricknum) + ' of 4 is ' + theplayers[eval(eval(eval(3 + firstreveal) % 4) + 0)].GetFullname() );
//ibit='ib' + eval(eval(eval(3 + firstreveal) % 4) + 1);
setTimeout(nextc,500);
}
}
}
}

function nextc() {
if (ntp != '') {
alert(ntp);
trickcnt=eval('' + Math.floor(trickcnt) + '.' + eval(1 + withintricknum));
document.getElementById(ibit).click();
}
if (withintricknum > 3) {
//alert(tricklist);
//alert('End of trick ' + Math.floor(trickcnt));
ourgame.IncrementTrickCount();
trickcnt=Math.floor(trickcnt);
if (trickcnt == 10) {
document.getElementById('tinstructions').innerHTML=theplayers[0].GetFullname() + '/' + theplayers[2].GetFullname() + " " + tricksper[0] + " Tricks " + tricksper[1] + " " + theplayers[1].GetFullname() + '/' + theplayers[3].GetFullname() + '<hr><br>Regarding Trick ' + Math.floor(trickcnt) + ':';
if ((ffr == 1 || ffr == 3) && (tricksper[0] >= needed || (tricksper[0] == 0 && needed == 0))) {
theplayers[0].SetScore(upforgrabs);
theplayers[0].SetGoes(1);
theplayers[2].SetScore(upforgrabs);
theplayers[2].SetGoes(1);
theplayers[1].SetGoes(1);
theplayers[3].SetGoes(1);
} else if ((ffr == 2 || ffr == 4) && (tricksper[1] >= needed || (tricksper[1] == 0 && needed == 0))) {
theplayers[1].SetScore(upforgrabs);
theplayers[1].SetGoes(1);
theplayers[3].SetScore(upforgrabs);
theplayers[3].SetGoes(1);
theplayers[0].SetGoes(1);
theplayers[2].SetGoes(1);
} else if ((ffr == 1 || ffr == 3) && (tricksper[0] < needed || (tricksper[0] == 0 && needed == 0))) {
theplayers[0].SetScore(-upforgrabs);
theplayers[0].SetGoes(1);
theplayers[2].SetScore(-upforgrabs);
theplayers[2].SetGoes(1);
theplayers[1].SetGoes(1);
theplayers[3].SetGoes(1);
} else if ((ffr == 2 || ffr == 4) && (tricksper[1] < needed || (tricksper[1] == 0 && needed == 0))) {
theplayers[1].SetScore(-upforgrabs);
theplayers[1].SetGoes(1);
theplayers[3].SetScore(-upforgrabs);
theplayers[3].SetGoes(1);
theplayers[0].SetGoes(1);
theplayers[2].SetGoes(1);
}
for (var iop=1; iop<=4; iop++) {
document.getElementById('score' + iop).innerHTML='Score: ' + theplayers[eval(-1 + iop)].GetScore() + '/' + theplayers[eval(-1 + iop)].GetGoes();
}
tricksper=[0,0];
upforgrabs=0;
firstreveal=1;
//alert('Reshuffle');
//ol();
location.href=document.URL.split('&score')[0] + '&score1=' + theplayers[0].GetScore() + '&score2=' + theplayers[1].GetScore() + '&score3=' + theplayers[2].GetScore() + '&score4=' + theplayers[3].GetScore() + '&goes1=' + theplayers[0].GetGoes() + '&goes2=' + theplayers[1].GetGoes() + '&goes3=' + theplayers[2].GetGoes() + '&goes4=' + theplayers[3].GetGoes() + '&name1=' + encodeURIComponent(theplayers[0].GetFullname()) + '&name2=' + encodeURIComponent(theplayers[1].GetFullname()) + '&name3=' + encodeURIComponent(theplayers[2].GetFullname()) + '&name4=' + encodeURIComponent(theplayers[3].GetFullname());
} else {
trickcnt++;
trickcnt=eval('' + trickcnt + '.1');
withintricknum=1;
trickld=',';
tricklist=ftl.replace(ffr + ',', firstreveal + ',');
//alert(firstreveal + ' ... ' + ourgame.GetNumberNoBid() + ' 00:' + tricklist);
if (firstreveal == 1 || firstreveal == 3) {
tricksper[0]++;
} else {
tricksper[1]++;
}
document.getElementById('tinstructions').innerHTML=theplayers[0].GetFullname() + '/' + theplayers[2].GetFullname() + " " + tricksper[0] + " Tricks " + tricksper[1] + " " + theplayers[1].GetFullname() + '/' + theplayers[3].GetFullname() + '<hr><br>Regarding Trick ' + Math.floor(trickcnt) + ':';
//alert('Start of ' + Math.floor(trickcnt));
for (var iu=1; iu<=4; iu++) {
if (iu != firstreveal || 1 == 1) {
if (document.getElementById('ib' + iu).value.indexOf('Reveal ') == -1) {
document.getElementById('ib' + iu).click();
}
}
}
reveal(document.getElementById('ib' + firstreveal));
}
}
}

function Card(name) {
this.name = name;
this.GetName = function() {
return this.name;
};
this.ScorePontoon = function(scoresofar) {
if (this.name.toLowerCase().indexOf('ace') != -1 && scoresofar > 10) {
return 1;
} else if (this.name.toLowerCase().indexOf('ace') != -1) {
return 11;
} else if (this.name.toLowerCase().indexOf('king') != -1) {
return 10;
} else if (this.name.toLowerCase().indexOf('queen') != -1) {
return 10;
} else if (this.name.toLowerCase().indexOf('jack') != -1) {
return 10;
} else if (this.name.toLowerCase().indexOf('ten') != -1) {
return 10;
} else if (this.name.toLowerCase().indexOf('nine') != -1) {
return 9;
} else if (this.name.toLowerCase().indexOf('eight') != -1) {
return 8;
} else if (this.name.toLowerCase().indexOf('seven') != -1) {
return 7;
} else if (this.name.toLowerCase().indexOf('six') != -1) {
return 6;
} else if (this.name.toLowerCase().indexOf('five') != -1) {
return 5;
} else if (this.name.toLowerCase().indexOf('four') != -1) {
return 4;
} else if (this.name.toLowerCase().indexOf('three') != -1) {
return 3;
} else if (this.name.toLowerCase().indexOf('two') != -1) {
return 2;
}
};
this.IsPicture = function() {
if (this.name.toLowerCase().indexOf('ace') != -1) {
return 4;
} else if (this.name.toLowerCase().indexOf('king') != -1) {
return 3;
} else if (this.name.toLowerCase().indexOf('queen') != -1) {
return 2;
} else if (this.name.toLowerCase().indexOf('jack') != -1) {
return 1;
}
return 0;
};
this.IsBlack = function() {
if (this.name.toLowerCase().replace('spades','clubs').indexOf('clubs') != -1) {
return true;
}
return false;
};
this.IsRed = function() {
if (this.name.toLowerCase().replace('hearts','diamonds').indexOf('diamonds') != -1) {
return true;
}
return false;
};
}

function TwoOfHearts(name) {
Card.call(this, name);
}

function TwoOfDiamonds(name) {
Card.call(this, name);
}

function TwoOfSpades(name) {
Card.call(this, name);
}

function TwoOfClubs(name) {
Card.call(this, name);
}

function ThreeOfHearts(name) {
Card.call(this, name);
}

function ThreeOfDiamonds(name) {
Card.call(this, name);
}

function ThreeOfSpades(name) {
Card.call(this, name);
}

function ThreeOfClubs(name) {
Card.call(this, name);
}

function FourOfHearts(name) {
Card.call(this, name);
}

function FourOfDiamonds(name) {
Card.call(this, name);
}

function FourOfSpades(name) {
Card.call(this, name);
}

function FourOfClubs(name) {
Card.call(this, name);
}

function FiveOfHearts(name) {
Card.call(this, name);
}

function FiveOfDiamonds(name) {
Card.call(this, name);
}

function FiveOfSpades(name) {
Card.call(this, name);
}

function FiveOfClubs(name) {
Card.call(this, name);
}

function SixOfHearts(name) {
Card.call(this, name);
}

function SixOfDiamonds(name) {
Card.call(this, name);
}

function SixOfSpades(name) {
Card.call(this, name);
}

function SixOfClubs(name) {
Card.call(this, name);
}

function SevenOfHearts(name) {
Card.call(this, name);
}

function SevenOfDiamonds(name) {
Card.call(this, name);
}

function SevenOfSpades(name) {
Card.call(this, name);
}

function SevenOfClubs(name) {
Card.call(this, name);
}

function EightOfHearts(name) {
Card.call(this, name);
}

function EightOfDiamonds(name) {
Card.call(this, name);
}

function EightOfSpades(name) {
Card.call(this, name);
}

function EightOfClubs(name) {
Card.call(this, name);
}

function NineOfHearts(name) {
Card.call(this, name);
}

function NineOfDiamonds(name) {
Card.call(this, name);
}

function NineOfSpades(name) {
Card.call(this, name);
}

function NineOfClubs(name) {
Card.call(this, name);
}

function TenOfHearts(name) {
Card.call(this, name);
}

function TenOfDiamonds(name) {
Card.call(this, name);
}

function TenOfSpades(name) {
Card.call(this, name);
}

function TenOfClubs(name) {
Card.call(this, name);
}

function JackOfHearts(name) {
Card.call(this, name);
}

function JackOfDiamonds(name) {
Card.call(this, name);
}

function JackOfSpades(name) {
Card.call(this, name);
}

function JackOfClubs(name) {
Card.call(this, name);
}

function QueenOfHearts(name) {
Card.call(this, name);
}

function QueenOfDiamonds(name) {
Card.call(this, name);
}

function QueenOfSpades(name) {
Card.call(this, name);
}

function QueenOfClubs(name) {
Card.call(this, name);
}

function KingOfHearts(name) {
Card.call(this, name);
}

function KingOfDiamonds(name) {
Card.call(this, name);
}

function KingOfSpades(name) {
Card.call(this, name);
}

function KingOfClubs(name) {
Card.call(this, name);
}

function AceOfHearts(name) {
Card.call(this, name);
}

function AceOfDiamonds(name) {
Card.call(this, name);
}

function AceOfSpades(name) {
Card.call(this, name);
}

function AceOfClubs(name) {
Card.call(this, name);
}

function Joker(name) {
Card.call(this, name);
}

function ol() {
if (oldt == '') {
oldt=document.getElementById('mytable').innerHTML;
} else {
document.getElementById('mytable').innerHTML=oldt;
}
if (ourgame == null) ourgame=new Game(carddealnum);
if (ourgame.GetNumber() == 10) {
mypictures.push("//www.rjmprogramming.com.au/images/back01.gif");
cardsinpack.push("Joker");
document.getElementById('information').innerHTML='Bidding';
document.getElementById('myh1').innerHTML=document.getElementById('myh1').innerHTML.replace('Pontoon','Five Hundred');
document.getElementById('mynums').value='+' + numplayers;
document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace('Reveal Cards,','Reveal Cards (ready to make a bid),');
document.getElementById('div2').innerHTML=document.getElementById('div2').innerHTML.replace('Reveal Cards,','Reveal Cards (ready to make a bid),');
} else if (ourgame.GetNumber() == 5) {
document.getElementById('myh1').innerHTML=document.getElementById('myh1').innerHTML.replace('Pontoon','Draw Poker');
document.getElementById('mynums').value='-' + numplayers;
document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace('Reveal Cards,','Reveal Cards (rejectable via click),');
document.getElementById('div2').innerHTML=document.getElementById('div2').innerHTML.replace('Reveal Cards,','Reveal Cards (rejectable via click),');
} else {
document.getElementById('mynums').value='' + numplayers;
}
var startat=0, found=true;
var origth=document.getElementById('th1').innerHTML;
origtd=document.getElementById('td1').innerHTML;
for (var iii=1; iii<=numplayers; iii++) {
if (iii > 2) {
if (ourgame.GetNumber() == 10) {
if (iii == 3) {
document.getElementById('mytable').innerHTML+='<tr id=tr1a><th style=display:inline-cell;>' + origth.replace(/1/g,'' + eval(7 - iii)) + '</th><th></th></tr>';
document.getElementById('mytbody').innerHTML+='<tr id=tr2a><td style=display:inline-cell; id=td' + eval(7 - iii) + '>' + origtd.replace(/1/g,'' + eval(7 - iii)) + '</td><td></td></tr>';
} else {
document.getElementById('tr1a').innerHTML+='<th style=display:inline-cell;>' + origth.replace(/1/g,'' + eval(7 - iii)) + '</th>';
document.getElementById('tr2a').innerHTML+='<td style=display:inline-cell; id=td' + eval(7 - iii) + '>' + origtd.replace(/1/g,'' + eval(7 - iii)) + '</td>';
document.getElementById('td1').style.backgroundColor='lightgreen';
document.getElementById('td3').style.backgroundColor='lightgreen';
document.getElementById('td2').style.backgroundColor='lightblue';
document.getElementById('td4').style.backgroundColor='lightblue';


var score1=location.search.split('score1=')[1] ? eval(location.search.split('score1=')[1].split('&')[0]) : 0;
var score2=location.search.split('score2=')[1] ? eval(location.search.split('score2=')[1].split('&')[0]) : 0;
var score3=location.search.split('score3=')[1] ? eval(location.search.split('score3=')[1].split('&')[0]) : 0;
var score4=location.search.split('score4=')[1] ? eval(location.search.split('score4=')[1].split('&')[0]) : 0;
var goes1=location.search.split('goes1=')[1] ? eval(location.search.split('goes1=')[1].split('&')[0]) : 0;
var goes2=location.search.split('goes2=')[1] ? eval(location.search.split('goes2=')[1].split('&')[0]) : 0;
var goes3=location.search.split('goes3=')[1] ? eval(location.search.split('goes3=')[1].split('&')[0]) : 0;
var goes4=location.search.split('goes4=')[1] ? eval(location.search.split('goes4=')[1].split('&')[0]) : 0;
var name1=location.search.split('name1=')[1] ? decodeURIComponent(location.search.split('name1=')[1].split('&')[0]) : 'Player1';
var name2=location.search.split('name2=')[1] ? decodeURIComponent(location.search.split('name2=')[1].split('&')[0]) : 'Player2';
var name3=location.search.split('name3=')[1] ? decodeURIComponent(location.search.split('name3=')[1].split('&')[0]) : 'Player3';
var name4=location.search.split('name4=')[1] ? decodeURIComponent(location.search.split('name4=')[1].split('&')[0]) : 'Player4';



}
} else {
document.getElementById('tr1').innerHTML+='<th style=display:inline-cell;>' + origth.replace(/1/g,'' + iii) + '</th>';
document.getElementById('tr2').innerHTML+='<td style=display:inline-cell; id=td' + iii + '>' + origtd.replace(/1/g,'' + iii) + '</td>';
}
}
theplayers.push(new Player('Player' + iii));
}


if (ourgame.GetNumber() == 10) {
theplayers[0].SetScore(score1);
theplayers[1].SetScore(score2);
theplayers[2].SetScore(score3);
theplayers[3].SetScore(score4);
theplayers[0].SetGoes(goes1);
theplayers[1].SetGoes(goes2);
theplayers[2].SetGoes(goes3);
theplayers[3].SetGoes(goes4);
theplayers[0].SetFullname(name1);
theplayers[1].SetFullname(name2);
theplayers[2].SetFullname(name3);
theplayers[3].SetFullname(name4);
document.getElementById('score1').innerHTML='Score: ' + score1 + '/' + goes1;
document.getElementById('score2').innerHTML='Score: ' + score2 + '/' + goes2;
document.getElementById('score3').innerHTML='Score: ' + score3 + '/' + goes3;
document.getElementById('score4').innerHTML='Score: ' + score4 + '/' + goes4;
document.getElementById('dname1').innerHTML=name1;
document.getElementById('dname2').innerHTML=name2;
document.getElementById('dname3').innerHTML=name3;
document.getElementById('dname4').innerHTML=name4;
}


ourpack=new Pack(anarray,aniarray,true,startwith);
ourheap=new Heap();
ourpack.Deal(theplayers,carddealnum); // for pontoon vs 0);

for (var iiii=0; iiii<numplayers; iiii++) {
theplayers[iiii].SetCardTotal(0);
}

}

function bidfor(nump, islast) {
var hm=null,ca, iiii;
if (!islast) {
if (pots[0] == null) {
hm=prompt(theplayers[eval(0 + nump)].GetFullname() + ", what's your bid?", "1");
} else if ("we_like_verb_bid" == "we_like_verb_bid" || 1 == 1) {
if (theplayers[eval(0 + nump)].AmBidder() == false && theplayers[eval(0 + nump)].AmNoBidder() == false) {
ca=confirm(theplayers[eval(0 + nump)].GetFullname() + ", do you agree to see the earlier bid of " + eval(pots[0].GetTotal() / numplayers) + "?");
if (ca == true) {
theplayers[eval(0 + nump)].SetAsBidder();
} else {
theplayers[eval(0 + nump)].SetAsNonBidder();
}
}
}
} else if ("we_like_verb_bid" == "we_like_verb_bid" || 1 == 1) {
if (pots[0]) {

var ims=document.getElementsByTagName('img');
for (var ifw=0; ifw<ims.length; ifw++) {
ims[ifw].style.visibility='hidden';
}


for (iiii=0; iiii<numplayers; iiii++) {
if (theplayers[iiii].AmBidder() == false && theplayers[iiii].AmNoBidder() == false) {
ca=confirm(theplayers[iiii].GetFullname() + ", do you agree to see the earlier bid of " + eval(pots[0].GetTotal() / numplayers) + "?");
if (ca == true) {
theplayers[iiii].SetAsBidder();
} else {
theplayers[iiii].SetAsNonBidder();
}
}
}
}
}
if (hm != null) {
if ("we_like_verb_bid" == "we_like_verb_bid") { // Player "verb" bidding approach
theplayers[eval(0 + nump)].Bid(pots[0], eval(eval('' + hm) * numplayers));
theplayers[eval(0 + nump)].SetAsBidder();
//alert('' + nump + ' is ' + theplayers[nump].AmBidder());
} else { // Bid "noun" bidding approach
if (bids.length == 1) {
if (bids[0] == null) {
bids[0] = new Bid(theplayers[eval(0 + nump)].GetFullname(), eval('' + hm));
} else {
bids[0] = new Bid(theplayers[eval(0 + nump)].GetFullname(), eval('' + hm));
}
theplayers[eval(0 + nump)].SetAsBidder();
} else {
bids.push(new Bid(theplayers[eval(0 + nump)].GetFullname(), eval('' + hm)));
theplayers[eval(0 + nump)].SetAsBidder();
}
if (!pots[0]) pots[0] = new Pot(eval(eval('' + hm) * numplayers));
}
}
}

function lockedin(nump) {
gnump=nump;
if (document.getElementById('tinstructions').innerHTML.indexOf(theplayers[nump].GetFullname() + ' is locked in.') == -1) {
document.getElementById('tinstructions').innerHTML+=theplayers[nump].GetFullname() + ' is locked in.';
document.getElementById('mydiv' + eval(1 + nump)).style.display='none';
if (document.getElementById('tinstructions').innerHTML.split('<br>').length < numplayers) {
document.getElementById('tinstructions').innerHTML+='<br>';
} else {
var ims=document.getElementsByTagName('img');
for (ifw=0; ifw<ims.length; ifw++) {
ims[ifw].style.visibility='hidden';
}
setTimeout(postlockedin,500);
}
}
}

function postlockedin() {
var nump=gnump;
var ifw;

var ims=document.getElementsByTagName('img');
for (ifw=0; ifw<ims.length; ifw++) {
ims[ifw].style.visibility='hidden';
}
bidfor(nump,true);
for (ifw=0; ifw<ims.length; ifw++) {
ims[ifw].style.visibility='visible';
}
huh='No winners on this round.', huhd='';
var winner=-1, winningscore=-1;
for (var iiii=0; iiii<numplayers; iiii++) {
document.getElementById('mydiv' + eval(1 + iiii)).style.display='block';
if (theplayers[iiii].GetCardTotal() > 21) {
theplayers[iiii].SetCardTotal(-999);
}
}
for (var iii=0; iii<numplayers; iii++) {
if (theplayers[iii].GetCardTotal() >= winningscore) {
huh='Congratulations' + theplayers[iii].GetHow() + ' to';
winningscore=theplayers[iii].GetCardTotal();
}
}
for (var ii=0; ii<numplayers; ii++) {
if (theplayers[ii].GetCardTotal() == winningscore) {
if (theplayers[ii].AmBidder() == true || !pots[0]) {
huh+=huhd + ' ' + theplayers[ii].GetFullname();
huhd=',';
theplayers[ii].SetScore(1);
} else {
huh+=huhd + ' ' + theplayers[ii].GetFullname() + " (except that you did not join the bidding)";
huhd=',';
theplayers[ii].SetScore(0);
}
}
}
for (var i=0; i<numplayers; i++) {
theplayers[i].SetGoes(1);
}
if (1 == 1) {
setTimeout(andthen,2000);
} else {
alert(huh);
for (var i=0; i<numplayers; i++) {
theplayers[i].Reset(ourheap);
}
document.getElementById('tinstructions').innerHTML='';
ourheap.Redeal(theplayers,carddealnum,ourpack); // for pontoon vs 0);
}
}

function andprethen() {
var nump=gnump;
}

function andthen() {
var nump=gnump;
alert(huh);
for (var i=0; i<numplayers; i++) {
theplayers[i].Reset(ourheap);
theplayers[i].UnsetAsBidder();
}
document.getElementById('tinstructions').innerHTML='';
ourheap.Redeal(theplayers,carddealnum,ourpack); // for pontoon vs 0);
}

function reveal(iwhat) {
var cfw=iwhat.id.replace('ib','');
var ifw,fw='i_' + iwhat.id.replace('ib','') + '_';
var iwhatid='' + iwhat.id;
var ims=document.getElementsByTagName('img');
if (iwhat.value.indexOf('Reveal') != -1) {
for (ifw=0; ifw<ims.length; ifw++) {
if (ims[ifw].id.indexOf(fw) != -1) ims[ifw].style.visibility='visible';
}
if (ourgame.GetNumber() == 10 && ourgame.GetNumberNoBid() == 3) { // Five Hundred
//alert(cfw);
firstreveal=eval(cfw);
for (var ih=1; ih<=4; ih++) {
if (ih == firstreveal) {
document.getElementById('div' + iwhat.id.replace('ib','')).innerHTML=document.getElementById('div' + iwhat.id.replace('ib','')).innerHTML.replace('(ready to make a bid)','(click 3 to reject ready for kitty, then click first playing card)');
document.getElementById('div' + iwhat.id.replace('ib','')).innerHTML+='<input id=im' + iwhat.id.replace('ib','') + ' onclick="hidethese(' + iwhat.id.replace('ib','') + ',this); for (var iyt=0; iyt<3; iyt++) { ourheap.Another(ourpack,theplayers,' + eval(-1 + eval(iwhat.id.replace('ib',''))) + '); }" value="Minus Three" type=button style=background-color:yellow;visibility:hidden;></input> <span id=span' + iwhat.id.replace('ib','') + '>' + document.getElementById("nobidopt1").innerHTML.replace('No bid on top of ','') + '</span> <span id=status' + iwhat.id.replace('ib','') + '></span>';
} else {
iwhatid='' + ih;
document.getElementById('div' + iwhatid.replace('ib','')).innerHTML=document.getElementById('div' + iwhatid.replace('ib','')).innerHTML.replace('(ready to make a bid)','(click next playing card)');
document.getElementById('div' + iwhatid.replace('ib','')).innerHTML+=' <span id=span' + iwhatid.replace('ib','') + '>' + document.getElementById("nobidopt1").innerHTML.replace('No bid on top of ','') + '</span> <span id=status' + iwhatid.replace('ib','') + '></span>';
}
}
} else if (ourgame.GetNumber() == 5) { // Draw Poker
document.getElementById('div' + iwhat.id.replace('ib','')).innerHTML+='<input id=im' + iwhat.id.replace('ib','') + ' onclick="hidethese(' + iwhat.id.replace('ib','') + ',this); ourheap.Another(ourpack,theplayers,' + eval(-1 + eval(iwhat.id.replace('ib',''))) + ');" value=Minus type=button style=background-color:yellow;visibility:hidden;></input> <input onclick=bidfor(' + eval(-1 + eval(iwhat.id.replace('ib',''))) + ',false); value=Bid type=button style=background-color:yellow;></input> <input onclick=lockedin(' + eval(-1 + eval(iwhat.id.replace('ib',''))) + '); value=Finished type=button style=background-color:yellow;></input>';
} else if (ourgame.GetNumber() == 2) { // Pontoon
document.getElementById('div' + iwhat.id.replace('ib','')).innerHTML+='<input onclick=ourheap.Another(ourpack,theplayers,' + eval(-1 + eval(iwhat.id.replace('ib',''))) + '); value=Add type=button style=background-color:yellow;></input> <input onclick=bidfor(' + eval(-1 + eval(iwhat.id.replace('ib',''))) + ',false); value=Bid type=button style=background-color:yellow;></input> <input onclick=lockedin(' + eval(-1 + eval(iwhat.id.replace('ib',''))) + '); value=Finished type=button style=background-color:yellow;></input>';
}
document.getElementById('ib' + cfw).value=document.getElementById('ib' + cfw).value.replace('Reveal','Hide');
//alert(document.getElementById('ib' + cfw).value);
if (ourgame.GetNumberNoBid() != 3 && ourgame.GetNumber() == 10 && firstreveal < 0) { // Five Hundred
firstreveal=eval(cfw);
//hm=prompt(theplayers[eval(-1 + firstreveal)].GetFullname() + ", what's your bid?", "1");
document.getElementById('tinstructions').innerHTML='';
var vi='';
for (var fr=firstreveal; fr<=eval(3 + firstreveal); fr++) {
document.getElementById('tinstructions').innerHTML+='<select' + vi + ' id=bidsel' + eval(eval(eval(-1 + fr) % 4) + 1) + ' onchange="if (this.value.length == 0) { this.id=this.id; } else if (this.value == ' + "'" + 'No bid' + "'" + ') { theplayers[' + eval(eval(-1 + fr) % 4) + "].SetCharacterBid(this.value); intrfh(false,this," + eval(eval(eval(-1 + fr) % 4) + 1) + "); ourgame.IncrementNumberNoBid(); } else { theplayers[" + eval(eval(-1 + fr) % 4) + "].SetCharacterBid(this.value); upforgrabs=theplayers[" + eval(eval(-1 + fr) % 4) + "].AtStake(); intrfh(true,this," + eval(eval(eval(-1 + fr) % 4) + 1) + "); ourgame.SetNumberNoBid(0); }" + '"><option value="">' + theplayers[eval(eval(-1 + fr) % 4)].GetFullname() + ", what's your bid?" + '</option><option id=nobidopt' + eval(eval(eval(-1 + fr) % 4) + 1) + ' value="No bid">No bid</option><option value="6 spades">6 spades</option><option value="6 clubs">6 clubs</option><option value="6 diamonds">6 diamonds</option><option value="6 hearts">6 hearts</option><option value="6 no trumps">6 no trumps</option><option value="7 spades">7 spades</option><option value="7 clubs">7 clubs</option><option value="7 diamonds">7 diamonds</option><option value="7 hearts">7 hearts</option><option value="7 no trumps">7 no trumps</option><option value="8 spades">8 spades</option><option value="Misere">Misere</option><option value="8 clubs">8 clubs</option><option value="8 diamonds">8 diamonds</option><option value="8 hearts">8 hearts</option><option value="8 no trumps">8 no trumps</option><option value="9 spades">9 spades</option><option value="9 clubs">9 clubs</option><option value="9 diamonds">9 diamonds</option><option value="9 hearts">9 hearts</option><option value="9 no trumps">9 no trumps</option><option value="10 spades">10 spades</option><option value="10 clubs">10 clubs</option><option value="10 diamonds">10 diamonds</option><option value="Open Misere">Open Misere</option><option value="10 hearts">10 hearts</option><option value="10 no trumps">10 no trumps</option></select><br>';
vi=' style=visibility:hidden;';
}
} //else if (ourgame.GetNumber() == 10) {
//ourgame.SetNumberNoBid(0);
//}

} else {
for (ifw=0; ifw<ims.length; ifw++) {
if (ims[ifw].id.indexOf(fw) != -1) ims[ifw].style.visibility='hidden';
}
iwhat.value=iwhat.value.replace('Hide','Reveal');
}
}

function hidethese(ibv,ibo) {
document.getElementById('mydiv' + ibv).innerHTML=document.getElementById('mydiv' + ibv).innerHTML.replace(/border\:/g,'display:none;border:');
ibo.style.display='none';
}

function changen(od) {
var cfw=od.id.replace('dname','');
theplayers[eval(-1 + eval('' + cfw))].SetFullname(od.innerHTML);
}
</script>
</head>
<body onload="ol();">
<h1 id=myh1>Pontoon Card Game <select id=mynums onchange=" if (this.value.indexOf('+') != -1) { location.href=document.URL.split('#')[0].split('?')[0] + '?carddealnum=10&numplayers=' + this.value.replace('+',''); } else if (this.value < 0) { location.href=document.URL.split('#')[0].split('?')[0] + '?carddealnum=5&numplayers=' + this.value.replace('-',''); } else { location.href=document.URL.split('#')[0].split('?')[0] + '?carddealnum=2&numplayers=' + this.value; }"><option value=2>for 2 (Pontoon)</option><option value=-2>for 2 (Draw Poker)</option><option value=3>for 3 (Pontoon)</option><option value=-3>for 3 (Draw Poker)</option><option value="+4">for 4 (Five Hundred)</option><option value=4>for 4 (Pontoon)</option><option value=-4>for 4 (Draw Poker)</option><option value=5>for 5 (Pontoon)</option><option value=-5>for 5 (Draw Poker)</option><option value=6>for 6 (Pontoon)</option><option value=-6>for 6 (Draw Poker)</option><option value=7>for 7 (Pontoon)</option><option value=-7>for 7 (Draw Poker)</option><option value=8>for 8 (Pontoon)</option><option value=-8>for 8 (Draw Poker)</option><option value=9>for 9 (Pontoon)</option><option value=-9>for 9 (Draw Poker)</option></select></h1>
<h3>RJM Programming - March, 2018</h3><br>
<div id=om></div>
<table id=mytable style='width:100%' border=50>
<thead id=mythead>
<tr id=tr1><th id=th1><div onblur=changen(this); id=dname1 contenteditable=true>Player1</div> <div id=score1>Score: 0/0</div></th><th id=information style=vertical-align:top;>Information</th><th><div onblur=changen(this); id=dname2 contenteditable=true>Player2</div> <div id=score2>Score: 0/0</div></th></tr>
</thead>
<tbody id=mytbody>
<tr id=tr2><td id=td1>
<div id=div1><input type=button onclick=reveal(this); id=ib1 value='Reveal Cards, out of view' style=background-color:yellow;></input></div>
<div id='mydiv1' style='float:left;'></div>
</td><td id=tinstructions style=vertical-align:top;></td><td id=td2>
<div id=div2><input type=button onclick=reveal(this); id=ib2 value='Reveal Cards, out of view' style=background-color:yellow;></input></div>
<div id='mydiv2' style='float:left;'></div>
</td></tr>
</tbody>
</table>
</body>
</html>