cartelente=0;
tipo=0;
primo=1;
path="";
stime=0;
msgtp=0;
temps="";
function textticker() 
{        
setTimeout("textticker()",250);
if (loaded==1) {document.forms[0].messages.value = "Press Deal to start";temps=""; loaded=2;}
stime=1;//stime++;
	if (stime>=500) 
	{
	stime=-20;
	temps=document.forms[0].messages.value;	
	msgtp++;
	if (msgtp==4) msgtp=1;
	if (msgtp==1)document.forms[0].messages.value = "For only few money you can get the full version";
	if (msgtp==2)document.forms[0].messages.value = "Get the full version for only 29.95$";
	if (msgtp==3)document.forms[0].messages.value = "With only few money the complete version";
	}
if (stime<=-1) return;
if (stime==0) document.forms[0].messages.value =temps;
if (tipo==1 || tipo==2)
{
    if (cartelente>=1) cartelente++;
    if (cartelente==2) document.mcrd0.src = ccrd.src;
    if (cartelente==3) document.mcrd1.src = ccrd.src;
    if (cartelente==4) document.mcrd2.src = ccrd.src;
    if (cartelente==5) document.mcrd3.src = ccrd.src;
    if (cartelente==6) document.mcrd4.src = ccrd.src;
    if (cartelente==7) document.mcrd0.src = card[herhand[0]].src;
    if (cartelente==8) document.mcrd1.src = card[herhand[1]].src;
    if (cartelente==9) document.mcrd2.src = card[herhand[2]].src;
    if (cartelente==10) document.mcrd3.src = card[herhand[3]].src;
    if (cartelente==11) document.mcrd4.src = card[herhand[4]].src;

    if (cartelente>=12) 
	{
		cartelente=20;
		if (tipo==1) compare();
                if (tipo==2) shecallslast();
	}
}

if (tipo==3 || tipo==4)
{
    if (cartelente>=1) cartelente++;
    if (primo==1 && cartelente==2) {
	cartelente=6;
	document.mcrd0.src = ccrd.src;
	document.mcrd1.src = ccrd.src;
	document.mcrd2.src = ccrd.src;
	document.mcrd3.src = ccrd.src;
	document.mcrd4.src = ccrd.src;
	return;
	}
    if (tipo==4 && cartelente==2)
	{
	document.mcrd0.src = ccrd.src;
	document.mcrd1.src = ccrd.src;
	document.mcrd2.src = ccrd.src;
	document.mcrd3.src = ccrd.src;
	document.mcrd4.src = ccrd.src;
	cartelente=6;
	}
    if (cartelente==2) document.mcrd0.src = ccrd.src;
    if (cartelente==3) document.mcrd1.src = ccrd.src;
    if (cartelente==4) document.mcrd2.src = ccrd.src;
    if (cartelente==5) document.mcrd3.src = ccrd.src;
    if (cartelente==6) document.mcrd4.src = ccrd.src;
    if (cartelente==7) document.mcrd0.src = card[myhand[0]].src;
    if (cartelente==8) document.mcrd1.src = card[myhand[1]].src;
    if (cartelente==9) document.mcrd2.src = card[myhand[2]].src;
    if (cartelente==10) document.mcrd3.src = card[myhand[3]].src;
    if (cartelente==11) document.mcrd4.src = card[myhand[4]].src;
    if (cartelente>=12) 
	{
		cartelente=20;
                if (tipo==3) mischia();

		if (tipo==4)
		{
		        analysis(myhand, keepmy);
		        myrank = rank;
		        mydiagnose = diagnose;
		        for (i=0;i<5;i++) keepmy[i]=true;
		        hermove();
			cartelente=0;
		}
	}
}
}

sfondo = new Image();
sfondo.src=path+"p1.gif";
card = new Array;
decksize = 52;
mischiate = decksize * 10;
deck = new Array(decksize);
myhand = new Array(5);
herhand = new Array(5);
keepher = new Array(5);
keepmy = new Array(5);
herrank = 0;
myrank = 0;
rank = 0;
mydiagnose = "no cards yet";
herdiagnose = "no cards yet";
diagnose = "no cards yet";
itook = 0;
hermoney = 0;
mymoney = 0;
ante = 5;
pot = 0;
tobet = 0;
turn = 0;
mode = 0;	
for (i=0;i<13;i++) {
    deck[i] = 1+(i+2)*10;
    deck[i+13] = 2+(i+2)*10;
    deck[i+26] = 3+(i+2)*10;
    deck[i+39] = 4+(i+2)*10;
    card[1+(i+2)*10] = new Image();
    card[1+(i+2)*10].src = path+eval(1+(i+2)*10)+".gif";
    card[2+(i+2)*10] = new Image();
    card[2+(i+2)*10].src = path+eval(2+(i+2)*10)+".gif";

    card[4+(i+2)*10] = new Image();
    card[4+(i+2)*10].src = path+eval(3+(i+2)*10)+".gif";
    card[3+(i+2)*10] = new Image();
    card[3+(i+2)*10].src = path+eval(4+(i+2)*10)+".gif";
}

ccrd = new Image();
ccrd.src = path+"ccard.jpg";
b="tac";
butdeal = new Image();
butdeal.src = path+"deal.gif";
butdone = new Image();
butdone.src = path+"done.gif";
butbet = new Image();
butbet.src = path+"bet.gif";
butstay = new Image();
butstay.src = path+"stay.gif";
butdrop = new Image();
butdrop.src = path+"drop.gif";
butraise = new Image();
butraise.src = path+"raise.gif";
b+="mio";
butcall = new Image();
butcall.src = path+"call.gif";
b+="g";
but5 = new Image();
but5.src = path+"5.gif";
but10 = new Image();
b+="p";
but10.src = path+"10.gif";
but15 = new Image();
but15.src = path+"15.gif";
but20 = new Image();
b+="j";
but20.src = path+"20.gif";
but25 = new Image();
but25.src = path+"25.gif";
nothing = new Image();
nothing.src = path+"nothing.gif";
b+="12345";
imlosing = 1;
partnu=1;
mpartnu=3;

function csoldi() {
    primo=1;
    vlt=0;
    while (hermoney<=0) { 
        if (vlt==0) {document.forms[0].messages.value += " ...Oh no, I lost clothing"; vlt++;}
        partnu +=1;
        if (partnu>=mpartnu) { 
            mode=100;
            document.forms[0].messages.value = "You won! Get the full version now!"; 
        }
        hermoney += cassa;
        document.forms[0].hercash.value = hermoney;
    } 

    while (hermoney>cassa && partnu!=1) { 
        partnu -=1;
        document.forms[0].messages.value = "   I won back clothing";
        hermoney -= cassa;
        document.forms[0].hercash.value = hermoney;
    }

if (partnu==1) tmpmx = mx1;if (partnu==2) tmpmx = mx2;if (partnu==3) tmpmx = mx3;if (partnu==4) tmpmx = mx4;if (partnu>=5) tmpmx = mx5;
if (tmpmx!= extract(frames['mpx'].location.href)) frames['mpx'].location.href = tmpmx;


    while (mymoney<0) {
        imlosing++;
        if (imlosing >= 2) { 
            mode=100; 
            document.forms[0].messages.value = "You lost!   GAME OVER... press Deal"; 
        }
        mymoney += cassa;
        document.forms[0].mycash.value = mymoney;
    } 
}

function cambiamodo(move) {
    if (move=="bet") {
        if (mode==1) mode=3;
        else if (mode==11) mode=13;
        else if (mode==2) mode=4;
        else if (mode==12) mode=14;
    } else if (move=="raise") {
        if (mode==4) mode=5;
        else if (mode==14) mode=15;
        else if (mode==3) mode=4;
        else if (mode==5) mode=6;
        else if (mode==13) mode=14;
        else if (mode==15) mode=16;
    } else if (move=="stay") {
        if (mode==1) mode=2;
        else if (mode==2) mode=0;
        else if (mode==11) mode=12;
        else if (mode==12) mode==18;
    } else if (move=="drop") {
        mode = 0;
    } else if (move=="call") {
        if (mode<10) mode=8;
        else mode=18;
    }
}

function numberorder(a, b) {
    return a - b;
}

function analysis(hand, keep) {
    color = new Array(5);
    kind = new Array(5);
    for (i=0;i<5;i++) {
        color[i] = hand[i] % 10;
        kind[i] = parseInt(hand[i]/10);
    }
    for (i=0;i<5;i++) keep[i]=false;
    flush = (color[0]==color[1] && color[1]==color[2] && color[2]==color[3] && color[3]==color[4]);
    straight = (kind[4]-kind[3]==1 && kind[3]-kind[2]==1 && kind[2]-kind[1]==1 && kind[1]-kind[0]==1);
    if (straight || flush) { for (i=0;i<5;i++) keep[i]=true; } 
    if (straight && flush) { rank=65000+kind[4]; diagnose="a straight flush"; return; }
    if (straight) { rank=256+kind[4]; diagnose="a straight"; return; }
    if (flush) { rank=510+kind[4]; diagnose="a flush!"; return; }

    four = (kind[0]==kind[1] && kind[1]==kind[2] && kind[2]==kind[3]) ||
           (kind[1]==kind[2] && kind[2]==kind[3] && kind[3]==kind[4]);
    if (four) {
        for (i=0;i<5;i++) keep[i]=true; 
        rank = 4200+kind[3];
        diagnose = "four of a kind";
        return;
    }

    fullhouse = (kind[0]==kind[1] && kind[3]==kind[4] && (kind[1]==kind[2] || kind[2]==kind[3]));
    if (fullhouse) {
        for (i=0;i<5;i++) keep[i]=true; 
        if (kind[1]==kind[2]) rank = 694+kind[1];
        else rank = 694+kind[3];
        diagnose = "a full house";
        return;
    }

    three = false;
    if (kind[0]==kind[1] && kind[1]==kind[2]) {
        three = true;
        keep[0]=true; keep[1]=true; keep[2]=true;
        rank = 100+kind[0];
    }
    if (kind[1]==kind[2] && kind[2]==kind[3]) {
        three = true;
        keep[1]=true; keep[2]=true; keep[3]=true;
        rank = 100+kind[1];
    }
    if (kind[2]==kind[3] && kind[3]==kind[4]) {
        three = true;
        keep[2]=true; keep[3]=true; keep[4]=true;
        rank = 100+kind[2];
    }
    if (three) { diagnose="three of a kind"; return; }

    twopair = false;
    if (kind[0]==kind[1] && kind[2]==kind[3]) {
        twopair = true;
        keep[0]=true; keep[1]=true;
        keep[2]=true; keep[3]=true;
    }
    if (kind[0]==kind[1] && kind[3]==kind[4]) {
        twopair = true;
        keep[0]=true; keep[1]=true;
        keep[3]=true; keep[4]=true;
    }
    if (kind[1]==kind[2] && kind[3]==kind[4]) {
        twopair = true;
        keep[1]=true; keep[2]=true;
        keep[3]=true; keep[4]=true;
    }
    if (twopair) { rank=50+kind[3]; diagnose="two pair"; return; }

    two = false;
    if (kind[0]==kind[1]) { keep[0]=true; keep[1]=true; two=true; rank=20+kind[0]; }
    if (kind[1]==kind[2]) { keep[1]=true; keep[2]=true; two=true; rank=20+kind[1]; }
    if (kind[2]==kind[3]) { keep[2]=true; keep[3]=true; two=true; rank=20+kind[2]; }
    if (kind[3]==kind[4]) { keep[3]=true; keep[4]=true; two=true; rank=20+kind[3]; }
    if (two) { diagnose="a pair"; return; }

    if (kind[4]>10) { 
        if (kind[3]>10) keep[3]=true; 
        keep[4]=true; 
        rank=kind[4]; 
        diagnose="a high card"; 
        return;
    }
    rank=kind[4];
    diagnose = "a low card";
    return;
}

function mischia() {

tipo=3;

if (cartelente==0)
{
    for (i=0;i<mischiate;i++) {
        a = Math.floor( Math.random()*decksize );
        b = Math.floor( Math.random()*decksize );
	dummy = deck[a];
	deck[a] = deck[b];
	deck[b] = dummy;
    }
    for (i=0;i<5;i++) {
        
        myhand[i] = deck[i*2];
        herhand[i] = deck[i*2+1];
    }
    herhand.sort(numberorder);
    myhand.sort(numberorder);
    cartelente=1;
}
if (cartelente==20){
    cartelente=0;
    primo=2;
    document.mcrd0.src = card[myhand[0]].src;
    document.mcrd1.src = card[myhand[1]].src;
    document.mcrd2.src = card[myhand[2]].src;
    document.mcrd3.src = card[myhand[3]].src;
    document.mcrd4.src = card[myhand[4]].src;

    analysis(herhand, keepher);
    herrank = rank;
    herdiagnose = diagnose;
    analysis(myhand, keepmy);
    myrank = rank;
    mydiagnose = diagnose;
    for (i=0;i<5;i++) keepmy[i]=true;
    cards = 10;
    itook = 0;
}
}

function cambia() {
    for (i=0;i<5;i++) {
        if (!keepher[i]) { herhand[i]=deck[cards]; cards++; }
    }
    herhand.sort(numberorder);
    analysis(herhand, keepher);
    herrank = rank;
    herdiagnose = diagnose;
}

function clearbuttons() {
    document.button0.src = nothing.src;
    document.button1.src = nothing.src;
    document.button2.src = nothing.src;
    document.button3.src = nothing.src;
    document.button4.src = nothing.src;
}

function compare() {
tipo=1;
if (cartelente==0)
{
	document.forms[0].messages.value = "My cards...";
 	cartelente=1;
}

if (cartelente==20){
    cartelente=0;
    document.mcrd0.src = card[herhand[0]].src;
    document.mcrd1.src = card[herhand[1]].src;
    document.mcrd2.src = card[herhand[2]].src;
    document.mcrd3.src = card[herhand[3]].src;
    document.mcrd4.src = card[herhand[4]].src;
    if (myrank == herrank) {
        i = 0;
        while (myrank==herrank && i<5) {
            myrank += myhand[4-i];
            herrank += herhand[4-i];
            i++;
        }
    }
    if (myrank > herrank) {
        document.forms[0].messages.value = "You win. Your take the pot of "+pot+"!";
        mymoney += pot;
        document.forms[0].mycash.value = mymoney;
        pot = 0;
        document.forms[0].pottxt.value = pot;
    } else if (myrank < herrank) {
        document.forms[0].messages.value = "I have "+herdiagnose+". I take the pot of "+pot+".   Deal again";
        hermoney += pot;
        document.forms[0].hercash.value = hermoney;
        pot = 0;
        document.forms[0].pottxt.value = pot;
    } else {
        document.forms[0].messages.value = "We have exactly the same!  Pot of "+pot+" stays.  Deal again";
    }
    clearbuttons();
    document.button0.src = butdeal.src;
    mode = 0;
    csoldi();
}

}

function shebets(bet) {
    tobet = bet;
    hermoney -= tobet;
    document.forms[0].hercash.value = hermoney;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    document.forms[0].messages.value = "I bet "+tobet+". Pot is now "+pot+". Your move?";
    clearbuttons();
    document.button0.src = butraise.src;
    document.button1.src = butcall.src;
    document.button2.src = butdrop.src;
    cambiamodo("bet");
}

function sheraises(bet) {
    hermoney -= tobet;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    tobet = bet;
    hermoney -= tobet;
    document.forms[0].hercash.value = hermoney;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    document.forms[0].messages.value = "I raise "+tobet+". Pot is now "+pot+". Your move?";
    clearbuttons();
    document.button0.src = butraise.src;
    document.button1.src = butcall.src;
    document.button2.src = butdrop.src;
    cambiamodo("raise");
}

function shecalls() {
    hermoney -= tobet;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    document.forms[0].hercash.value = hermoney;
    document.forms[0].messages.value = "I call. Click on the cards you want to discard then press Done";
    clearbuttons();
    document.button0.src = butdone.src;
    cambiamodo("call");
}

function sheraiseslast(bet) {
    hermoney -= tobet;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    tobet = bet;
    hermoney -= tobet;
    document.forms[0].hercash.value = hermoney;
    pot += tobet;
    document.forms[0].pottxt.value = pot;
    document.forms[0].messages.value = "I raise "+tobet+". Last bet: Call or Drop?";
    clearbuttons();
    document.button1.src = butcall.src;
    document.button2.src = butdrop.src;
    cambiamodo("raise");
}

function shecallslast() {
tipo=2;
if (cartelente==0)
{
	document.forms[0].messages.value = "I call. My cards...";
 	cartelente=1;
}

if (cartelente==20){
    cartelente=0;
    hermoney -= tobet;
    pot += tobet;
    document.forms[0].pottxt.value = pot;


    document.forms[0].hercash.value = hermoney;

    if (myrank>herrank) {
        document.forms[0].messages.value = "You win, you take the pot of "+pot+"! Deal again";
        mymoney += pot;
        document.forms[0].mycash.value = mymoney;
    } else {
        document.forms[0].messages.value = "I win, I have "+herdiagnose+". I take the pot of  "+pot+". Deal again";
        hermoney += pot;
        document.forms[0].hercash.value = hermoney;
     }
     clearbuttons();
     document.button0.src = butdeal.src;
     pot = 0;
     document.forms[0].pottxt.value = pot;
     mode = 0;
     csoldi();
}
}

function shedrops() {
    mymoney += pot;
    document.forms[0].mycash.value = mymoney;
    document.forms[0].messages.value = "I Drop.  Pot of "+pot+" is yours. Deal again";
    pot = 0;
    document.forms[0].pottxt.value = pot;
    clearbuttons();
    document.button0.src = butdeal.src;
    mode = 0;
    csoldi();
}

function hermove() {
    if (mode==1) {
        return;
    }
    if (mode==2) {
        if (herrank>20) {
            shebets(5 * Math.floor(1+Math.random()*3));
        } else {
            if (Math.floor(Math.random()*3)==0) {
                shebets(5 * Math.floor(1+Math.random()*3));
            } else {
                document.forms[0].messages.value = "We both stay. Pot is "+pot+". Deal again";
                clearbuttons();
                document.button0.src = butdeal.src;
                mode = 0;
            }
        }
        return;
    }
    if (mode==3) {
        if (herrank>33) {
            sheraises(5 * Math.floor(1+Math.random()*3));
        } else if (herrank>29) {
            if (Math.floor(Math.random()*3)!=0) {
                sheraises(5 * Math.floor(1+Math.random()*2));
            } else {
                shecalls();
            }
        } else if (herrank>20) {
            if (Math.floor(Math.random()*4)==0) {
                sheraises(5 * Math.floor(1+Math.random()*2));
            } else {
                shecalls();
            }
        } else {
            if (Math.floor(Math.random()*tobet)<5) {
                shecalls();
            } else {
                mymoney += pot;
                document.forms[0].mycash.value = mymoney;
                document.forms[0].messages.value = "I Drop.  Pot of "+pot+" is yours. Deal again";
                pot = 0;
                document.forms[0].pottxt.value = pot;
                clearbuttons();
                document.button0.src = butdeal.src;
                mode = 0;
                csoldi();
            }
        }
        return;
    }
    if (mode==4) {
        return;
    }
    if (mode==5) {
        if (herrank>33) {
            sheraiseslast(5 * Math.floor(1+Math.random()*3));
        } else if (herrank>29) {
            if (Math.floor(Math.random()*3)!=0) {
                sheraiseslast(5 * Math.floor(1+Math.random()*2));
            } else {
                shecalls();
            }
        } else if (herrank>20) {
            if (Math.floor(Math.random()*4)==0) {
                sheraiseslast(5 * Math.floor(1+Math.random()*2));
            } else {
                shecalls();
            }
        } else {
            if (Math.floor(Math.random()*tobet)<5) {
                shecalls();
            } else {
                mymoney += pot;
                document.forms[0].mycash.value = mymoney;
                document.forms[0].messages.value = "I Drop.   Pot of "+pot+" is yours. Deal again";
                pot = 0;
                document.forms[0].pottxt.value = pot;
                clearbuttons();
                document.button0.src = butdeal.src;
                mode = 0;
                csoldi();
            }
        }
        return;
    }
    if (mode==6) {
        return;
    }
    if (mode==8) {	
        cambiate = 0;
        for (i=0;i<5;i++) {
            if (!keepher[i]) { herhand[i]=deck[cards]; cards++; cambiate++; }
        }
        herhand.sort(numberorder);
        analysis(herhand, keepher);
        herrank = rank;
        herdiagnose = diagnose;
        document.forms[0].messages.value = "I took "+cambiate+" cards. Your move?";
        document.button0.src = butbet.src;
        document.button1.src = butstay.src;
        document.button2.src = butdrop.src;
        mode = 11;
        return;
    }
    if (mode==11) {
        return;
    }
    if (mode==12) {
        if (herrank>30) {
            shebets(5 * Math.floor(1+Math.random()*3));
        } else {
            if (Math.floor(Math.random()*(6-itook))==0) {
                shebets(5 * Math.floor(2+Math.random()*2));
            } else {
                compare();
            }
        }
        return;
    }
    if (mode==13) {
        if (herrank>33) {
            sheraises(5 * Math.floor(1+Math.random()*itook));
        } else if (herrank>29) {
            if (Math.floor(Math.random()*(5-itook))==0) {
                sheraises(5 * Math.floor(1+Math.random()*itook));
            } else {
                if (Math.floor(Math.random()*tobet)<5) shecallslast();
                else shedrops();
            }
        } else if (herrank>20) {
            if (Math.floor(Math.random()*5)==0) {
                sheraises(5 * Math.floor(1+Math.random()*2));
            } else {
                if (Math.floor(Math.random()*tobet)<5) shecallslast();
                else shedrops();
            }
        } else {
            if (Math.floor(Math.random()*tobet)<5) {
                shecallslast();
            } else {
                shedrops();
            }
        }
        return;
    }
    if (mode==14) {
        return;
    }
    if (mode==15) {
        if (herrank>60) {
            sheraiseslast(5 * Math.floor(1+Math.random()*itook));
        } else if (herrank>33) {
            if (Math.floor(Math.random()*(5-itook))==0) {
                sheraiseslast(5 * Math.floor(1+Math.random()*itook));
            } else {
                if (Math.floor(Math.random()*tobet)<5) shecallslast();
                else shedrops();
            }
        } else if (herrank>29) {
            if (Math.floor(Math.random()*8)==0) {
                sheraiseslast(5 * Math.floor(1+Math.random()*2));
            } else {
                if (Math.floor(Math.random()*tobet)<5) shecallslast();
                else shedrops();
            }
        } else {
            if (Math.floor(Math.random()*tobet)<3) {
                shecallslast();
            } else {
                shedrops();
            }
        }
        return;
    }
    if (mode==16) {
        return;
    }
    if (mode==18) {
        compare();
        return;
    }
}

function press0() {
if (stime<=-1) return;
if (cartelente>=1) return;
    if (mode == 100) { document.forms[0].messages.value = "Game Over.";inizializza()}
    if (document.button0.src==butdeal.src) {
        mischia();
        mymoney -= ante;
        hermoney -= ante; 
        pot += 2 * ante;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        document.forms[0].hercash.value = hermoney;
        document.forms[0].messages.value = "We both ante "+ante+".   Pot is "+pot+". Your move?";
        mode = 1; 
        document.button0.src = butbet.src;
        document.button1.src = butstay.src;
        document.button2.src = butdrop.src;
        return;
    }
    if (document.button0.src==butbet.src) {
        cambiamodo("bet");
        document.forms[0].messages.value = "How much do you want to bet?";
        document.button0.src = but5.src;
        document.button1.src = but10.src;
        document.button2.src = but15.src;
        document.button3.src = but20.src;
        document.button4.src = but25.src;
        return;
    }
    if (document.button0.src==butraise.src) {
        cambiamodo("raise");
        mymoney -= tobet;
        pot += tobet;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        document.forms[0].messages.value = "You pay "+tobet+".  How much do you raise?";
        document.button0.src = but5.src;
        document.button1.src = but10.src;
        document.button2.src = but15.src;
        document.button3.src = but20.src;
        document.button4.src = but25.src;
        return;
    }
    if (document.button0.src == but5.src) {
        tobet = 5;
        mymoney -= 5;
        pot += 5;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        clearbuttons();
        hermove();
        return;
    }
    if (document.button0.src == butdone.src) {
        for (i=0;i<5;i++) {
            if (!keepmy[i]) { myhand[i] = deck[cards]; cards++; }
        }
        myhand.sort(numberorder);

	tipo=4;
	cartelente=1;
	document.forms[0].messages.value = "Your cards...";
        return;
    }
}

function press1() {
if (stime<=-1) return;
if (cartelente>=1) return;
    if (document.button1.src == butstay.src) {
        clearbuttons();
        cambiamodo("stay");
        hermove();
        return;
    }
    if (document.button1.src == butcall.src) {
        mymoney -= tobet;
        pot += tobet;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        cambiamodo("call");
        if (mode==8) {
            clearbuttons();
            document.button0.src = butdone.src;
            document.forms[0].messages.value = "Click on the cards you want to discard then press Done";
        } else if (mode==18) {
            compare();
        }
        return;
    }
    if (document.button1.src == but10.src) {	
        tobet = 10;
        mymoney -= 10;
        pot += 10;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        clearbuttons();
        hermove();
        return;
    }
}

function press2() {
if (stime<=-1) return;
if (cartelente>=1) return;
    if (document.button2.src == butdrop.src) {
        hermoney += pot;
        tobet = 0;
        document.forms[0].hercash.value = hermoney;
        document.forms[0].messages.value = "You drop, so I take the pot, of "+pot+". Deal again";
        clearbuttons();
        document.mcrd0.src = ccrd.src;
        document.mcrd1.src = ccrd.src;
        document.mcrd2.src = ccrd.src;
        document.mcrd3.src = ccrd.src;
        document.mcrd4.src = ccrd.src;
        document.button0.src = butdeal.src;
        cambiamodo("drop");
	primo=1;
        pot = 0;
        document.forms[0].pottxt.value = pot;
        csoldi();
        return;
    }
    if (document.button2.src == but15.src) {
        tobet = 15;
        mymoney -= 15;
        pot += 15;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        clearbuttons();
        hermove();
        return;
    }
}

function press3() {
if (stime<=-1) return;
if (cartelente>=1) return;
    if (document.button3.src == but20.src) {
        tobet = 20;
        mymoney -= 20;
        pot += 20;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        clearbuttons();
        hermove();
        return;
    }
}

function press4() {
if (stime<=-1) return;
if (cartelente>=1) return;
    if (document.button4.src == but25.src) {
        tobet = 25;
        mymoney -= 25;
        pot += 25;
        document.forms[0].pottxt.value = pot;
        document.forms[0].mycash.value = mymoney;
        clearbuttons();
        hermove();
        return;
    }
}

function scambia(nr) {
    if (mode != 8) return;
    if (keepmy[nr]) {
        keepmy[nr]=false;
        if (nr==0) document.mcrd0.src = ccrd.src;
        if (nr==1) document.mcrd1.src = ccrd.src;
        if (nr==2) document.mcrd2.src = ccrd.src;
        if (nr==3) document.mcrd3.src = ccrd.src;
        if (nr==4) document.mcrd4.src = ccrd.src;
        itook++;
    }
    else {
        keepmy[nr]=true;
        if (nr==0) document.mcrd0.src = card[myhand[0]].src;
        if (nr==1) document.mcrd1.src = card[myhand[1]].src;
        if (nr==2) document.mcrd2.src = card[myhand[2]].src;
        if (nr==3) document.mcrd3.src = card[myhand[3]].src;
        if (nr==4) document.mcrd4.src = card[myhand[4]].src;
        itook--;
    }
}

function extract(what) {
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
    else
        answer = what.substring(what.lastIndexOf('\\')+1,what.length);
    return(answer);
}


function inizializza(){
	document.forms[0].messages.value="Please wait for the graphics..."
	cassa=100;
        hermoney = cassa;
        mymoney = cassa;
	document.forms[0].hercash.value = hermoney;
	document.forms[0].mycash.value = mymoney;
	document.forms[0].pottxt.value = pot;
	cartelente=0;
	frames['mpx'].location.href=mx1; 
	herrank = 0;
	myrank = 0;
	rank = 0;
	mydiagnose = "no cards yet";
	herdiagnose = "no cards yet";
	diagnose = "no cards yet";
	itook = 0;
	ante = 5;
	pot = 0;
	tobet = 0;
	turn = 0;
	mode = 0;	
}