// Video Poker JavaScript veena

var MaxDraws = 1; // Number of draws per hand
var Rank;
var HighScore=0;
var score=0;

var Payout = [
              ['Royal Flush',       800, 1600, 2400, 3200, 4000],
              ['Four Deuces W/A',   400, 800,  1200, 1600, 2000],
              ['Four Deuces',       200, 400,  600,  800,  1000],
              ['Wild Royal',        25,  50,   75,   100,  125],
              ['Five of a Kind',    20,  40,   60,   80,   100],
              ['Straight Flush',    9,   18,   27,   36,   45],
              ['Four of a Kind',    4,   8,    12,   16,   20],
              ['Full House',        4,   8,    12,   16,   20],
			  ['Flush',             3,   6,    9,    12,   15],
              ['Straight',          1,   2,    3,    4,    5],
              ['Three of a Kind',   1,   2,    3,    4,    5],
			 ];

var MaxBet = Payout[0].length - 1;

var Styles = ["Yellow"];
//var Suites = ['cards_test'];

var Suites = ['Spades','Hearts','Clubs','Diamonds'];
//var CardID = ['','3','3','3','3','W'];
var CardID = ['','A','3','4','5','6','7','8','9','T','J','Q','K','W'];

var Cards = null;

var PayoutTable = document.getElementById('payout');
var CardArea = document.getElementById('cardarea');
var PlayCards = null;
var Deck = null;
var DeckPos = 0;
var InPlay = false;
var Expires = new Date();
Expires.setYear(Expires.getYear() + 1901);
var CookieExpires = '; expires=' + Expires.toGMTString();
var Bank = GetBank();
var Bet = 0;
var holdFlag=0;

InitDeck();         // Initialize the deck
InitStyles();       // Initialize the style
InitCards();        // Initialize the card playing area
InitPayoutTable();  // Initialize the payout table

// Show the card backs (initial display)
ShowCards();

// Start a new hand
DoHand();

function removeElement(id) {
	//alert("removeElement");
	/*var d = document.getElementById(id);
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);*/
	var node = document.getElementById(id);
    node.removeChild(node.childNodes[1]);
}


function removeMsg_remove() 
	{// alert("removeMsg_remove");
	
	Bank = 100;
		document.getElementById('bank').innerHTML = "$100";
		if(document.getElementById("msg_remove"))
			{
				var d = document.getElementsByTagName("body").item(0);
				var olddiv = document.getElementById("msg_remove");
				d.removeChild(olddiv);
			}
		else
			return false;
	}

function AlertmoneyOut()
	{
		    //alert(" in AlertMsg");
			
				var divId="msg_remove";
				if(document.getElementById('displayTextBox'))
	if(document.getElementById('msg_remove'))
	{
		
			var d = document.getElementsByTagName("body").item(0);
			var olddiv = document.getElementById('msg_remove');
			d.removeChild(olddiv);		
	}
			
				var obj=document.createElement('DIV');
		obj.setAttribute("style","position:absolute; align:center;top:250px;left:23px;width:260px;height:130px;z-index:5;background-image:url(images_splash/messageboard.gif);");
				//obj.setAttribute("style","position:absolute; align:center; top:280px; left:22px; width:271;height:140;z-index:5;background-image:url(images_splash/messageboard.gif");
				obj.setAttribute("id",divId);
				obj.setAttribute("class","BoxAlert3");
				document.getElementsByTagName("body").item(0).appendChild(obj);
				document.getElementById(divId).innerHTML="<div><br><div align='center' style='color:black'><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >You have run out of chips!<br>  We are giving you a<br> fresh set of 100 chips.</font></div><div style=\"position:absolute; cursor:pointer; background-image:url(images_splash/ok_2.gif);top:75px;left:95px; width:93px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"removeMsg_remove();\"></div><br></div>";
				return document.getElementById(divId);
				
				
	}
	
	function Alertstand_remove() 
	{
		//alert("Alertstand_remove");
		if(document.getElementById("msg_remove"))
			{
				var d = document.getElementsByTagName("body").item(0);
				var olddiv = document.getElementById("msg_remove");
				d.removeChild(olddiv);
			}
		else
			return false;
	}

function Alertstand()
	{
		   // alert(" in Alertstand");
			
				var divId="msg_remove";
				if(document.getElementById('displayTextBox'))
	if(document.getElementById('msg_remove'))
	{
		
			var d = document.getElementsByTagName("body").item(0);
			var olddiv = document.getElementById('msg_remove');
			d.removeChild(olddiv);		
	}
			
				var obj=document.createElement('DIV');
				obj.setAttribute("style","position:absolute; align:center; top:280px; left:22px; width:256;height:90;z-index:5");
				obj.setAttribute("id",divId);
				obj.setAttribute("class","BoxAlert3");
				document.getElementsByTagName("body").item(0).appendChild(obj);
				document.getElementById(divId).innerHTML="<div><br><div align='center' style='color:black'>You can not stand with less than 5 cards showing.</div><div style=\"position:absolute; cursor:pointer; background-image:url(images_splash/ok.gif);top:40px;left:110px; width:89px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"Alertstand_remove();\"></div><br></div>";
				return document.getElementById(divId);
				
	}


function Alertbox(divId,id)
{
		//alert("Alertbox");
		var obj=document.createElement('DIV');
		obj.setAttribute("style","position:absolute;overflow:hidden; top:5px; left:auto; width:50;height:40;z-index:5;display:block");
		obj.setAttribute("id",divId+"in");
		obj.setAttribute("class","BoxAlert2");
		document.getElementById(id).appendChild(obj);
		document.getElementById(divId+"in").innerHTML="<br><font style='color:#0000FF;text-align:center;outline-color:#F06B1C;outline-style:solid;outline-width:1px;'>HOLD</font>";
		//alert(document.getElementById(id).innerHTML);
		return document.getElementById(divId+"in");
		//holdFlag=1;
}


function AlertMenu()
{
	ShowRank();
	//alert("AlertMenu");
	var divId='textBoxDiv';
	
	if(document.getElementById('displayTextBox'))
	{
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('displayTextBox');
		d.removeChild(olddiv);		
	}
	if(document.getElementById('textBoxDiv'))
	{
		
	var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('textBoxDiv');
		d.removeChild(olddiv);		
	}

		var obj=document.createElement('DIV');
		obj.setAttribute("style","position:absolute; align:center;top:155px;left:23px;width:260px;height:130px;z-index:5;background-image:url(images_splash/messageboard.gif);");
		obj.setAttribute("id",divId);
		obj.setAttribute("class","BoxAlert3");
		document.getElementsByTagName("body").item(0).appendChild(obj);
		document.getElementById(divId).innerHTML="<div  style=\"position:absolute;color:#FFFFFF; cursor:pointer; background-image:url(images_splash/close.gif);top:14px;left:243px; width:93px; height:35px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"RemoveHighMenuBox('"+divId+"');\"></div><br><div align='center' style=\"position:absolute;top:18px;left:40px\"><div align='center' style=\"color:#FFCC66; cursor:pointer; background-image:url(images_splash/playagain.gif);position:absolute; width:93; height:31px; left:50px;padding-top:8; background-repeat:no-repeat;\" onClick=\"removeElementMenue();\";\"></div></div><div align='left' style=\"position:absolute;top:55px;left:161px\"><div align='left' style=\"color:#FFCC66; cursor:pointer; background-image:url(images_splash/highscore.gif);position:absolute; text-align:center; width:93;  height:39; padding-top:8; background-repeat:no-repeat;\" onclick=\"displayTextBox('"+divId+"');\"></div></div><div align='right' style=\"position:absolute;top:55px;left:15px\"><div align='right' style=\"color:#FFCC66; cursor:pointer; background-image:url(images_splash/instructions.gif);position:absolute; width:93; height:39; padding-top:8;text-align:center; background-repeat:no-repeat;\"onclick=\"removeElementinstructions();\";\"></div></div><div align='center' style=\"position:absolute;left:50px;top:95px;\"><div align='center' style=\"color:#FFCC66;text-align:center;cursor:pointer; background-image:url(images_splash/moregames.gif);position:absolute; width:93; height:31px; left:40px;padding-top:8; background-repeat:no-repeat;\" onClick=\"location.href='../fun4iphone.htm'\";\"></div></div>";
		return document.getElementById(divId);
}


function RemoveHighMenuBox(divId)
{
	//alert("RemoveHighMenuBox");
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById(divId);
		d.removeChild(olddiv);
}

function removeMsg() 
	{
		//alert("removeMsg");
		if(document.getElementById("msgID"))
		{
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById("msgID");
		d.removeChild(olddiv);
		cleardiv();
		DoHand();
		}
		else
		return false;
	}

function AlertMsg(msg)
{
	   //alert(" in AlertMsg="+msg);
		
		var divId="msgID";
		var obj=document.createElement('DIV');
		obj.setAttribute("style","opacity:.9; position:absolute; align:center; top:318px; left:22px; width:263px;height:60px;background-image:url(images_splash/small_board.gif);background-repeat:no-repeat;");
		obj.setAttribute("id",divId);
		obj.setAttribute("class","BoxAlert3");
		document.getElementsByTagName("body").item(0).appendChild(obj);
		document.getElementById(divId).innerHTML="<div align='center' >"+msg+"</div><div style=\"position:absolute; cursor:pointer; background-image:url(images_splash/ok.gif);top:40px;left:110px; width:89px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"removeMsg();\"></div><br></div>";

		return document.getElementById(divId);
}



function removeElementMenue(divNum,type) 
{
	//alert("removeElementMenue");
	
			if(document.getElementById('displayTextBox'))
	{
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('displayTextBox');
		d.removeChild(olddiv);		
	}
	if(document.getElementById('ShowScore'))
	{
	var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('ShowScore');
		d.removeChild(olddiv);		
	}
	if(document.getElementById('textBoxDiv'))
	{
	var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('textBoxDiv');
		d.removeChild(olddiv);		
	}	

	//window.open("VideoPoker.html","_parent")
}

										// This function will called when user click on instructions Button when Time up Or Win The game
function removeElementinstructions(divNum,type) 
{
	//alert("removeElementinstructions");
	window.open("instructions.htm","_parent")
}

// Remove On Click of high Score
function removeElementHighScore(divNum,type) 
	{
		//alert("removeElementHighScore");
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
		displayTextBox("textBoxDiv");
	}
	
function displayTextBox(divId)
{
	//alert("In");
	
	
	//alert(Rank+"namr="+divId);
	//alert("displayTextBox");
if(Rank<=10)
{
	//ClearDivs();
	
	if(document.getElementById('textBoxDiv'))
	{
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('textBoxDiv');
		d.removeChild(olddiv);
	}
	
	var obj1=document.createElement('DIV');
		obj1.setAttribute("style","position:absolute; align:center;top:155px;left:23px;width:271px;height:140px;z-index:5;background-image:url(images_splash/messageboard.gif);");
	obj1.setAttribute("id",divId);
	obj1.setAttribute("class","BoxAlert");
	document.getElementsByTagName("body").item(0).appendChild(obj1);
	document.getElementById(divId).innerHTML="<div opacity:.7; style=\"position:absolute;color:#FFFFFF; cursor:pointer; background-image:url(images_splash/close.gif);top:5px;left:260px;width:89px;height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"RemoveHighMenuBox('"+divId+"');\"></div><br><div align=\"center\"><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" ><b>Your Rank is: <span id='ShowRank'>"+Rank+"</b></span><br><b>User Name</b><br></font> </div><br><br><div id=\"textBox\" align=\"center\">&nbsp;<font size=\"4\" style=\"color:#FFFF00;font-family:Verdana, Arial, Helvetica, sans-serif; \" ></font><br><br><div style=\"position:absolute;top:60px;left:60px\"><input id=\"text\" style=\"font-family:Verdana, Arial, Helvetica, sans-serif \" name=\"submitText\" type=\"text\" size=\"20\" maxlength=\"30\"></div><br><div opacity:.7; style=\"position:absolute;color:#000000; cursor:pointer; background-image:url(images_splash/ok_2.gif);top:90px;left:90px; width:139px; height:26px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"ValidateUser('"+divId+"');\"></div>&nbsp;&nbsp;<div opacity:.7; style=\"position:absolute;color:#000000; cursor:pointer; background-image:url(images/go_to.gif);top:75px;left:140px; width:139px; height:26px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"DisplayHighScores();\"></div></div>";
	return document.getElementById(divId);
}
else
{
	if(document.getElementById('textBoxDiv'))
	{
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('textBoxDiv');
		d.removeChild(olddiv);
	}
	
	var obj1=document.createElement('DIV');
		obj1.setAttribute("style","position:absolute; align:center;top:155px;left:23px;width:271px;height:140px;z-index:5;background-image:url(images_splash/messageboard.gif);");
	obj1.setAttribute("id",divId);
	obj1.setAttribute("class","BoxAlert");
	document.getElementsByTagName("body").item(0).appendChild(obj1);
		document.getElementById(divId).innerHTML="<div opacity:.7; style=\"position:absolute;color:#FFFFFF; cursor:pointer; background-image:url(images_splash/close.gif);top:8px;left:235px; width:89px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"RemoveHighMenuBox('"+divId+"');\"></div><br><br><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" ><b>To enter your name  in the<br> high score you must be <br>in the top 10 players.<br><br></font><div align='center' style=\"color:#000000; cursor:pointer; background-image:url(images_splash/ok_2.gif);position:absolute; width:150px; height:31px;top:90px; left:90px;padding-top:40px; background-repeat:no-repeat;\" onclick=\"RemoveHighMenuBox('"+divId+"');\"></div>";
		return document.getElementById(divId);
}
}

	
	function ValidateUser(divNum)
	{
		//alert("in validate=="+document.getElementById("text").value);
    if(document.getElementById("text").value=="")
	{
	AlertMsg_name();
		//alert("Please Enter Your Name");
		document.getElementById("text").focus();
		return false;
	}
		 removeTextBoxElement(divNum)
	}
	
	
		function removeMsg_name() 
	{
		//alert("removeMsg_name");
		if(document.getElementById("msgID"))
			{
				var d = document.getElementsByTagName("body").item(0);
				var olddiv = document.getElementById("msgID");
				d.removeChild(olddiv);
				cleardiv();
				DoHand();
			}
		else
			return false;
	}

function AlertMsg_name()
	{
		  //  alert(" in AlertMsg_name");
				//var divId='textBoxDiv';
	var divId="msgID";
	
	if(document.getElementById('msgID'))
	{
		
	var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById('msgID');
		d.removeChild(olddiv);		
	}

				
				var obj=document.createElement('DIV');
				
				obj.setAttribute("style","position:absolute; align:center; top:200px; left:22px; width:256;height:61; background-image:url(images_splash/small_board.gif);background-repeat:no-repeat;");

				obj.setAttribute("id",divId);
				obj.setAttribute("class","BoxAlert3");
				document.getElementsByTagName("body").item(0).appendChild(obj);
				document.getElementById(divId).innerHTML="<br><div align='center';z-index:5; style=\"position:absolute;color:#000000; left:50px;\"><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >Please Enter Your Name</font></div><div opacity:.7; style=\"position:absolute;color:#FFCC66; cursor:pointer; background-image:url(images_splash/ok.gif);top:40px;left:120px; width:93px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"removeMsg_name();\"></div>";
				return document.getElementById(divId);
    }
	
/*	
	function displayTextBox(divId)
	{
		var obj1=document.createElement('DIV');
		//obj.setAttribute("style","position:absolute;overflow:hidden; top:180px; left:95px; width:110;height:85;");
		obj1.setAttribute("style","position:absolute; align:center; top:180px; left:10px; width:280;height:130;z-index:1");
		obj1.setAttribute("id",divId);
		obj1.setAttribute("class","BoxAlert4");
		document.getElementsByTagName("body").item(0).appendChild(obj1);
		//document.getElementById(divId).innerHTML="<br><div align='center' style=\"color:#000000; font-family: Verdana, Arial, Helvetica, sans-serif;border:0px solid #00CC33;\"><div style=\"color:#FFFFFF; cursor:pointer; background-image:url(images/GreenButton.gif); width:89; height:31; padding-top:5; background-repeat:no-repeat;\" onclick=\"removeElement('"+divId+"');\">Play Again</div></div>";
		document.getElementById(divId).innerHTML="<br><div id=\"textBox\" align=\"center\">&nbsp;<font size=\"4\" style=\"color:#fffff;font-family:Verdana, Arial, Helvetica, sans-serif; \" ><strong> Username </strong> </font><br><br><div style=\"position:absolute;top:45px;left:50px\"><input id=\"text\" style=\"font-family:Verdana, Arial, Helvetica, sans-serif \" name=\"submitText\" type=\"text\" size=\"23\" maxlength=\"30\" onBlur=\"return ValidateUser();\"></div><br><div opacity:.4; style=\"position:absolute;color:#000000; cursor:pointer; background-image:url(images_splash/RedButton1.gif);top:75px;left:80px; width:89; height:31; padding-top:5; background-repeat:no-repeat;\" onclick=\"ValidateUser('"+divId+"');\">OK</div></div>";
		document.getElementById("text").focus();
		return document.getElementById(divId);
	}
	*/
	function submitForm(user,HighScore)
	{
		 // alert(" in submitForm");
		var d=document.getElementById("main");
		//alert(d);
		// alert(user+' '+HighScore)
		//d.innerHTML+="<form name=\"highscore\" id=\"highscore\">";
		d.innerHTML+="<input type=\"hidden\" name=\"userName\" id=\"username\" value=\""+user+"\">";
		d.innerHTML+="<input type=\"hidden\" name=\"score\" id=\"score\" value=\""+HighScore+"\">";
		d.innerHTML+="<input type=\"hidden\" name=\"gameId\" id=\"gameId\" value=\"5\">";
		//d.innerHTML+="<\\form>";
		document.main.action = "highScore.php";

		//document.frm.action = "http://58.68.117.35/Game/Golf/highScore.php";
		document.main.submit();
		//return
	}
	function removeTextBoxElement(divNum)   //when the user inputs his/her name and click OK...
	{
		
		//alert(" in removeTextBoxElement");
		
		var user=document.getElementById("text").value;
		//alert(TotalPoints);
		submitForm(user,HighScore);
		
		var d = document.getElementsByTagName("body").item(0);
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);

		//alert(user+' '+TotalPoints)
		//alert(TotalPoints)
		//window.open("highScore.php?userName="+user+"&score="+TotalPoints+"&gameId=2","_parent");
		
	}



function SetBetBank()
{
	//alert("SetBetBank bet");
    SetBank(Bank);
	HighScore=Bank;
    document.getElementById('bank').innerHTML = "$"+Bank;
    document.getElementById('betDiv').innerHTML = "<font color='yellow'><b>$"+Bet+"</b></font>";

	if(Bet==1)
	{

		for(var i=0;i<=10;i++)
		{
	document.getElementById(i+'1').style.background="blue";
		}
	}
	else if(Bet==2)
	{
		for(var j=0;j<=10;j++)
		{
			document.getElementById(j+'1').style.background="black";
			document.getElementById(j+'2').style.background="blue";
		}
	}
	else if(Bet==3){
		for(var j=0;j<=10;j++){
			document.getElementById(j+'1').style.background="black";
			document.getElementById(j+'2').style.background="black";

			document.getElementById(j+'3').style.background="blue";
		}
	}
	else if(Bet==4){
		for(var j=0;j<=10;j++){
			document.getElementById(j+'1').style.background="black";
			
			document.getElementById(j+'2').style.background="black";

			document.getElementById(j+'3').style.background="black";

			document.getElementById(j+'4').style.background="blue";
		}
	}
	else if(Bet==5){
	for(var j=0;j<=10;j++){
			document.getElementById(j+'1').style.background="black";
			
			document.getElementById(j+'2').style.background="black";

			document.getElementById(j+'3').style.background="black";

			document.getElementById(j+'4').style.background="black";

			document.getElementById(j+'5').style.background="blue";
		}
	}
	if(Bet==0){
	for(var j=0;j<=10;j++){
			document.getElementById(j+'1').style.background="black";
			
			document.getElementById(j+'2').style.background="black";

			document.getElementById(j+'3').style.background="black";

			document.getElementById(j+'4').style.background="black";

			document.getElementById(j+'5').style.background="black";
		}
	}
	
}

function AddBet(num)
{
		//alert(" in AddBet");
		// document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:40px; top:3px;  visibility: visible;\"><img src=\"button/bet_white.png\" onClick=\"AddBet(1)\" id=\"Bet\"></div><div style=\"position:absolute; left:110px; top:3px;  visibility: visible;\"><img src=\"button/max_red.png\" onclick=\"AddBet(' + MaxBet + ');DoDeal()\" id=\"Max\"></div>';
         //document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:40px; top:3px;  visibility: visible;\"><img src=\"button/bet_red.png\" onClick=\"AddBet(1)\" id=\"Bet\"></div><div style=\"position:absolute; left:110px; top:3px;  visibility: visible;\"><img src=\"button/max_white.png\" onclick=\"AddBet(' + MaxBet + ');DoDeal()\" id=\"Max\"></div>';

if('1')
	{
		//alert("hieeeee");
		document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:35px; top:3px;  visibility: visible;\"><img src=\"button/bet_red.png\" onClick=\"AddBet(1)\" id=\"Bet\"></div><div style=\"position:absolute; left:100px; top:3px;  visibility: visible;\"><img src=\"button/max_white.png\" onclick=\"AddBet(' + MaxBet + ');DoDeal()\" id=\"Max\"></div>';

	}
else
	{
		//alert("hi");
		 document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:35px; top:3px;  visibility: visible;\"><img src=\"button/bet_white.png\" onClick=\"AddBet(1)\" id=\"Bet\"></div><div style=\"position:absolute; left:100px; top:3px;  visibility: visible;\"><img src=\"button/max_red.png\" onclick=\"AddBet(' + MaxBet + ');DoDeal()\" id=\"Max\"></div>';
	}
//document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:40px; top:3px;  visibility: visible;\"><img src=\"button/bet_red.png\"  id=\"Bet\"></div><div style=\"position:absolute; left:110px; top:3px;  visibility: visible;\"><img src=\"button/max_red.png\"  id=\"Max\"></div>';

    for (bets = 0; bets < num; bets++)
    {
        if ((Bet < MaxBet) && (Bank > 0))
        {
            Bet++;
            Bank--;

            if (Bet == 1)
            {
                document.getElementById('action-deal').innerHTML = '<div style=\"position:absolute; left:170px; top:3px;  visibility: visible;\"><img src=\"button/deal_white.png\" id=\"Deal\" onclick=\"DoDeal()\"></div>';
				
            }
			setCookie1('Bet',Bet,365);
        }
		
    }

    SetBetBank();
  //  setCookie1('Bet',Bet,365);

    if (!((Bet < MaxBet) && (Bank > 0)))
    {
        document.getElementById('action-bet').innerHTML = '<div style=\"position:absolute; left:35px; top:3px;  visibility: visible;\"><img src=\"button/bet_white.png\" id=\"Bet\"></div><div style=\"position:absolute; left:100px; top:3px;  visibility: visible;\"><img src=\"button/max_white.png\" id=\"Max\"></div>';
    }
}

function DoDeal()
{
			//alert("in  DoDeal");
if(Bet>=1)
{
    document.getElementById('action-bet').innerHTML = '';
    document.getElementById('action-deal').innerHTML = '';
    ShuffleDeck();
    DealDraw('DoDealDone(' + MaxDraws + ');');
}
else
{
	alertDraw();
}
}

function DoDealDone(count)
{
				//alert("in  DoDealDone");

	count--;

    document.getElementById('action-bet').innerHTML = '<div style=\"position:absolute; left:60px; top:3px;  visibility: visible;\"><img src=\"button/stand_white.png\" onClick=\"DoStand()\" id=\"Stand\"></div>';
    document.getElementById('action-deal').innerHTML = '<div style=\"position:absolute; left:150px; top:3px;  visibility: visible;\"><img src=\"button/draw_white.png\" onClick=\"DoDraw(' + count + ')\" id=\"Stand\"></div>';
    InPlay = true;
}

function DoStand()
{
					//alert(" in DoStand");

    // You can only stand if you have not thrown out any cards
    for (x=0; x < PlayCards.length; x++)
    {
        if (holdFlag==0)
        {DoDraw1();
			 //Alertstand();
           //alert('You can not stand with less than 5 cards showing.');
            return;
        }
    }
    
}

function DoDraw(count)
{						//alert("in DoDraw");
var cnt=0;
    // You can only draw if you have thrown out a card
    for (x=0; x < PlayCards.length; x++)
    {
        if(PlayCards[x].hold==false)
        {
			//alert("DoDraw =="+ x+ " "+ PlayCards[x].hold);
			 var card = PlayCards[x];
			card.showback= !card.showback;
			ShowCard(card);
         }		
    }
	DoDraw1(count);
	return; 
	
}

function DoDraw1(count)
{
							//alert("in DoDraw1");	
    InPlay = false;
	document.getElementById('action-bet').innerHTML = '';
    document.getElementById('action-deal').innerHTML = '';

	if (count > 0)
	{
		//alert("DoDraw=="+count);
		
		DealDraw('DoDealDone(' + count + ');');
	}
	else
	{
		DealDraw('DoPayout();');
	}
}

function SetPayout(hand)
{
			//alert("in SetPayout");

    Bank += eval(Payout[hand][Bet]);
	AlertMsg('<span id="results" style="color:black;"><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >' + Payout[hand][0] + '<br>Credits Won $' + Payout[hand][Bet] + '</font></span>');
	//document.getElementById('bankarea').innerHTML = '<span id="results" style="color:yellow;">' + Payout[hand][0] + '&nbsp;-&nbsp;Credits Won $' + Payout[hand][Bet] + '</span>';	
	var h=hand;
	var b=Bet;
	var c=+h.toString()+b.toString();
	//alert("hand=="+hand +"bet=="+Bet+"=="+h+b + "====="+c);
	document.getElementById(c).style.backgroundColor="red";
	//document.getElementById(hand).style.color="red";	
	
	
	
}
function SetPayout_start(hand)
{
			//alert("in SetPayout");
   // Bank += Payout[hand][Bet];
	//AlertMsg('<span id="results" style="color:black;"><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >' + Payout[hand][0] + '<br>Credits Won $' + Payout[hand][Bet] + '</font></span>');
	//document.getElementById('bankarea').innerHTML = '<span id="results" style="color:yellow;">' + Payout[hand][0] + '&nbsp;-&nbsp;Credits Won $' + Payout[hand][Bet] + '</span>';	
	var h=hand;
	var b=Bet;
	var c=+h.toString()+b.toString();
	//alert("hand=="+hand +"bet=="+Bet+"=="+h+b + "====="+c);
	document.getElementById(c).style.backgroundColor="red";
	//document.getElementById(hand).style.color="red";		
}


function cardSort(a,b)
{
				//alert("in cardSort");

    if (a == b)
    {
        return 0;
    }
    if ((a-0) < (b-0))
    {
        return -1
    }
    return 1;
}

function cleardiv(){
	//alert("in cleardiv");
				var ids;
				var mydivs=document.getElementsByTagName("td");
				var cnt=mydivs.length;
						//alert(mydivs.length);
				for (var di=0; di<cnt; di++){
											
				st =mydivs.item(di).id.substr(0,1);	
				//alert("in fun=="+st);
					if(st=='c')
					{
						ids=mydivs.item(di).id;
						//alert("in fun 22=="+ids);
						if(document.getElementById(ids).childNodes.length==2){
						
						removeElement(ids);
						}
					}
					//ids.removeChild(ids.childNodes[1]);
					//var node = document.getElementById(ids);
   					 //node.removeChild(node.childNodes[1]);
				}
								
	
}

function alertDraw_remove()
{
	//alert("alertDraw_remove")
	
		if(document.getElementById("msg_remove"))
			{
				var d = document.getElementsByTagName("body").item(0);
				var olddiv = document.getElementById("msg_remove");
				d.removeChild(olddiv);
			}
		else
			return false;
}


function alertDraw()
	{
		    //alert(" in alertDraw");
			
				var divId="msg_remove";
				if(document.getElementById('displayTextBox'))
	if(document.getElementById('msg_remove'))
	{
		
			var d = document.getElementsByTagName("body").item(0);
			var olddiv = document.getElementById('msg_remove');
			d.removeChild(olddiv);		
	}
			
				var obj=document.createElement('DIV');
		obj.setAttribute("style","position:absolute; align:center; top:315px; left:22px; width:263px;height:60px;background-image:url(images_splash/small_board.gif);background-repeat:no-repeat;");
				obj.setAttribute("id",divId);
				obj.setAttribute("class","BoxAlert3");
				document.getElementsByTagName("body").item(0).appendChild(obj);
				document.getElementById(divId).innerHTML="<br><div align='center'><font size=\"2\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >PLACE YOUR BET</font></div><div style=\"position:absolute;color:#000000; cursor:pointer; background-image:url(images_splash/ok.gif);top:40px;left:110px; width:93px; height:31px; padding-top:8px; background-repeat:no-repeat;\" onclick=\"alertDraw_remove();\"><br></div>";
				return document.getElementById(divId);
	}



function DoHand()
{
	 // alert("in DoHand");
	
	    // Flush the bet and the hand
    Bet = 0;
    FlushHand();

	// If you ran out of money...
	if (Bank < 1)
	{
		AlertmoneyOut();
		//alert('You have run out of chips!  We are giving you a fresh set of 100 chips.');
		//Bank = 100;
	}

    document.getElementById('bankarea').innerHTML = '<span id="bank" style="font-size:14px"></span><span id="bet" style="font-size:14px"></span>';
    document.getElementById('action-bet').innerHTML ='<div style=\"position:absolute; left:35px; top:3px;  visibility: visible;\"><img src=\"button/bet_white.png\" onClick=\"AddBet(1)\" id=\"Bet\"></div><div style=\"position:absolute; left:100px; top:3px;  visibility: visible;\"><img src=\"button/max_white.png\" onclick=\"AddBet(' + MaxBet + ');DoDeal()\" id=\"Max\"></div>';
	document.getElementById('action-deal').innerHTML = '<div style=\"position:absolute; left:170px; top:3px;  visibility: visible;\"><img src=\"button/deal_white.png\" id=\"Deal\"  onClick=\"DoDeal()\"disabled></div>';
    SetBetBank();
}





// Flush out the cards in the hand...
function FlushHand()
{
						//alert("in FlushHand");

    for (x=0; x < PlayCards.length; x++)
    {
        PlayCards[x].showback = true;
		PlayCards[x].hold = false;
        PlayCards[x].face = 0;
        PlayCards[x].suite = 0;
        ShowCard(PlayCards[x]);
    }
}

// Deal new cards into the hand
function DealDraw(nextFunction)
{
							//alert("in DealDraw");

    for (x=0; x < PlayCards.length; x++)
    {
        if (PlayCards[x].showback)
        {
            PlayCards[x].face = Deck[DeckPos].face;
            PlayCards[x].suite = Deck[DeckPos].suite;
            PlayCards[x].showback = false;
            ShowCard(PlayCards[x]);

            DeckPos++;
            if (DeckPos >= Deck.length)
            {
                DeckPos = 0;
            }

            // We did one card, so in a bit do another...
            if (nextFunction == undefined)
            {
                setTimeout('DealDraw();',200);
            }
            else
            {
                setTimeout('DealDraw("' + nextFunction + '");',200);
            }
            return;
        }
    }

    if (nextFunction != undefined)
    {
        setTimeout(nextFunction,200);
    }
}

// Initialize the deck (unshuffled)
function InitDeck()
{
								//alert("in InitDeck");

    Deck = new Array();
    var x = 0;
    for (suite = 0; suite < Suites.length; suite++)
    {
        for (face = 1; face < CardID.length; face++)
        {
            Deck[x] = new Object();
            Deck[x].suite = suite;
            Deck[x].face = face;
			
            x++;
        }
    }
			
}

// This shuffles the deck - or at least tries to
function ShuffleDeck()
{
					//alert("in ShuffleDeck");

    var decksize = Deck.length;
    DeckPos = 0;
    for (loop = 0; loop < 7; loop++)
    {
        for (x = 0; x < decksize; x++)
        {
            var y = Math.floor(Math.random() * decksize);

            if (x != y)
            {
                var t = Deck[x];
                Deck[x] = Deck[y];
                Deck[y] = t;
            }
        }
    }
}

function InitStyles()
{
	//alert("in InitStyles");

    style = GetCookie('CardStyle') - 0;
    if ((style >= Styles.length) || (style < 0))
    {
        style = 0;
    }

    loadCards(style);

   /* var tmp = 'Card&nbsp;Style:&nbsp;<select size=1 onchange="NewStyle(this.value)">';
    for (x=0; x < Styles.length; x++)
    {
        tmp += '<option value=' + x;
        if (x == style)
        {
            tmp += ' selected';
        }
        tmp += '>' + Styles[x] + '</option>';
    }
    tmp += '</select>';
    document.getElementById('styleselect').innerHTML = tmp;*/
}

function NewStyle(style)
{
		//alert("in NewStyle");

    SetCookie('CardStyle',style);
    loadCards(style);
    ShowCards();
}

function OverCell(e)
{
			//alert("OverCell");

    if (InPlay)
    {
        e.style.backgroundColor = "yellow";
    }
}

function DownCell(e)
{
				//alert("DownCell");

    if (InPlay)
    {
        e.style.backgroundColor = "red";
    }
}

function UpCell(e)
{
					//alert("UpCell");

    if (InPlay)
    {
        e.style.backgroundColor = "yellow";
    }
}

function OutCell(e)
{
						//alert("OutCell");

    e.style.backgroundColor = "transparent";
}

function InitCards()
{
							//alert("in InitCards");

    var tmp = '<table cellspacing=0><tr>';
    for (x = 0; x < 5; x++)
    {
        tmp += '<td  width="50" id="c'+x+'" onmouseover="OverCell(this)" onmousedown="DownCell(this); CardClick(' + x + ')" onmouseup="UpCell(this)" onmouseout="OutCell(this)">';
        tmp += '<img id="card-' + x + '" src="blank.gif" />';
        tmp += '</td>';
    }
    tmp += '</tr></table>';
    CardArea.innerHTML = tmp;

    PlayCards = new Array();
    for (x=0; x<5; x++)
    {
        PlayCards[x] = document.getElementById('card-' + x);
    }

    FlushHand();
}

function ShowCard(card)
{
								//alert("ShowCard");
    card.src = ((card.showback) ? Cards[0][0].src : Cards[card.suite][card.face].src);
}

function CardClick(e)
{
	//alert("in CardClick");

	if (InPlay)
    {
        var card = PlayCards[e];
		
		
		card.hold=!card.hold;
		if(card.hold){
			//alert("CardClick=="+ e);
			Alertbox("hold"+e,"c"+ e );
		}
		else{
			removeElement("c"+ e);
		}
		
    }
}

function ShowCards()
{
										//alert("in ShowCards");
    for (i = 0; i < PlayCards.length; i++)
    {
        ShowCard(PlayCards[i]);
    }
}

function loadCards(style)
{
											//alert("in loadCards");
    var base = Styles[style] + '/';
    var back = new Image();
    back.src=base + 'back.gif';
    Cards = new Array();

    for (suite = 0; suite < Suites.length; suite++)
    {
        Cards[suite] = new Array();
        for (card = 0; card < CardID.length; card++)
        {
            if (CardID[card] == '')
            {
                Cards[suite][card] = back;
            }
            else
            {
                Cards[suite][card] = new Image();
                Cards[suite][card].src = base + Suites[suite] + '/' + CardID[card] + '.gif';
            }
       
	   }
	   //SetPayout_start(1)
    }
	
}


function DoPayout()
{
	 //alert("DoPayout");
    // Calculate any payout and display the results (updating the bank/etc
   var cards = new Array();
    var flushFlag = true;
	
   // var flushFlag1 = true;
	//var flushFlag2 = true;
 //   PlayCards.sort(cardSort);
	//alert(PlayCards);

	for (i in PlayCards)
	{
	//alert(PlayCards[i].face);
	}
	var tmp_place;
	for (x = 0; x < PlayCards.length; x++)
    {
		if(PlayCards[x].face!=13)
		{
			tmp_place=x;
			x=8
		}
	}
    for (x = 0; x < PlayCards.length; x++)
    {
		if(PlayCards[x].face!=13)
		{
			//alert(PlayCards[x].face);
        flushFlag = flushFlag && (PlayCards[tmp_place].suite == PlayCards[x].suite);
		}
        cards[x] = PlayCards[x].face;
		
    }
	
	
	if(flushFlag==true)
	{
		
		//alert("flushFlag=="+flushFlag);
	}
    cards.sort(cardSort);   // Sort the cards just to make things easier...
  //alert(cards);


// First, lets see if we have a Royal FLUSH
    if ((cards[0] == 1) &&
        (cards[1] == 9) &&
        (cards[2] == 10) &&
        (cards[3] == 11) &&
        (cards[4] == 12))
	
    {
		
        if (flushFlag)
        {
            SetPayout(0);   // 0 = royal flush
        }
      else
        {
            SetPayout(9);   // Just a straight
        }
    }
//==============================================================================================================================================
    else if (
			((cards[0] == 1) && (cards[1] == 13) && (cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13))
			
			)
    {
        SetPayout(1);   // four dueces with ace
    }
//==============================================================================================================================================
	    else if (
			((cards[1] == 13) && (cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13))
			
			)
    {
        SetPayout(2);   // four dueces
    }

//==============================================================================================================================================
	   else if (
				
						(
						((cards[0] == 1) &&	(cards[1] ==10) &&	(cards[2] == 11) &&	(cards[3] == 12) &&	(cards[4] ==13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] == 11) &&	(cards[3] == 12) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] == 10) &&	(cards[3] == 12) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] == 10) &&	(cards[3] == 11) &&	(cards[4] == 13)) ||
						((cards[0] == 9) &&	(cards[1] == 10) &&	(cards[2] == 11) &&	(cards[3] == 12) &&	(cards[4] == 13)) ||
						
						((cards[0] == 1) &&	(cards[1] == 11) &&	(cards[2] ==12) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 10) &&	(cards[2] == 12) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 10) &&	(cards[2] == 11) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 10) &&(cards[1] ==11) &&	(cards[2] == 12) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] ==12) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] == 11) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 9) &&	(cards[1] == 11) &&	(cards[2] == 12) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 9) &&	(cards[2] == 11) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						
						
						
						((cards[0] == 1) &&	(cards[1] == 12) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 11) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 11) &&(cards[1] == 12) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&	(cards[1] == 10) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 10) &&(cards[1] == 12) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 1) &&(cards[1] == 9) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 9) &&	(cards[1] == 12) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 9) &&(cards[1] == 10) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 10) &&(cards[1] == 11) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 13)) ||
						((cards[0] == 9) &&	(cards[1] == 11) &&	(cards[2] == 13) &&	(cards[3] == 13) &&	(cards[4] == 113)) 
						
						)
				
				)
				
	
    {
        if (flushFlag)
        {
            SetPayout(3);   // 0 = wild royal flush
        }
	    else
        {
            SetPayout(9);   // Just a straight
        }

	}	    
//==============================================================================================================================================
	else if (
			((cards[0] == cards[1]) && (cards[1] == cards[2]) && (cards[2] == cards[3]) &&(cards[4] == 13)) ||
			((cards[0] == cards[1]) && (cards[1] == cards[2]) && (cards[3] == 13) && (cards[4] == 13)) ||
			((cards[0] == cards[1]) && (cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13)) 
			)
			
    {
        SetPayout(4);   // five of a kind
    }
	
//==============================================================================================================================================
		/*else if((cards[0] != cards[1]) && (cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13))
					 {
						 if (flushFlag)
						 {
							SetPayout(5);   //  STRAIGHT flush
					     }
				}*/

//==============================================================================================================================================
	else if (
			 ((cards[0] == 1) &&  (cards[1] == 2) &&  (cards[2] == 3) && (cards[3] == 4) && (cards[4] == 5))||
			 ((cards[0] == 1) &&  (cards[1] == (cards[2]-1)) &&  (cards[2] == (cards[3]-2)) && (cards[4] == 13))||
			 ((cards[0] == 1) &&  (cards[1] == (cards[2]-2)) &&  (cards[2] == (cards[3]-1)) && (cards[4] == 13))||
			 ((cards[0] == (cards[1]-2)) &&  (cards[1] == (cards[2]-2)) &&  (cards[2] == (cards[3]-1)) && (cards[4] == 13))

			 
			 )
	{
		AlertMsg('<span id="results" style="color:black;"><font size=\"3\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >Bust</font></span>');
	}

	
   else if (
			 	( (cards[0] == 1) &&  (cards[1] == 9) &&  (cards[2] == 10) && (cards[3] == 11) && (cards[4] == 12))||
				( (cards[0] == (cards[1]-1)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-1)) && (cards[3] == (cards[4]-1)) ) ||
				( (cards[0] == (cards[1]-1)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-2)) && (cards[4] == 13) ) ||
				( (cards[0] == (cards[1]-1)) && (cards[1] == (cards[2]-2)) && (cards[2] == (cards[3]-1)) && (cards[4] == 13) ) ||
				( (cards[0] == (cards[1]-2)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-1)) && (cards[4] == 13) ) ||
				( (cards[0] == (cards[1]-1)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-1)) && (cards[4] == 13) ) ||
				( (cards[0] == (cards[1]-2)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-1)) && (cards[4] == 13) ) ||
				( (cards[0] == (cards[1]-1)) && (cards[1] == (cards[2]-1)) && (cards[2] == (cards[3]-1)) && (cards[4] == 13) ) ||
				( (cards[0] == 1) &&  (cards[1] == 9)  &&   (cards[2] == 10) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 1) &&  (cards[1] == 9)  &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 1) &&  (cards[1] == 11) &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 10)&&  (cards[1] == 11) &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 9) &&  (cards[1] == 11) &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 9) &&  (cards[1] == 10) &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 9) &&  (cards[1] == 10) &&   (cards[2] == 11) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
			/*( (cards[0] == 1) &&  (cards[1] == 10) &&   (cards[2] == 12) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||*/
			/*( (cards[0] == 1) &&  (cards[1] == 10) &&   (cards[2] == 11) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||*/
			/*( (cards[0] == 1) &&  (cards[1] == 9)  &&   (cards[2] == 11) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||*/
				
				( (cards[0] == 1) &&  (cards[1] == 2) &&  (cards[2] == 4) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 1) &&  (cards[1] == 2) &&  (cards[2] == 3) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 1) &&  (cards[1] == 3) &&  (cards[2] == 5) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
			    ( (cards[0] == 1) &&  (cards[1] == 2) &&  (cards[2] == 3) &&   (cards[2] == 4) &&  (cards[4] == 13)  ) ||				
				( (cards[0] == 1) &&  (cards[1] == 2) &&  (cards[2] == 3) &&   (cards[3] == 4) &&  (cards[4] == 13)  ) ||
					
			/*( (cards[0] == 1) &&  (cards[1] == 9) &&  (cards[2] == 11) &&  (cards[3] == 12) && (cards[4] == 13)  ) ||*/
			/*( (cards[0] == 1) &&  (cards[1] == 9) &&  (cards[2] == 10) &&  (cards[3] == 11) && (cards[4] == 13)  ) ||*/
			/*( (cards[0] == 1) &&  (cards[1] == 9) &&  (cards[2] == 10) &&  (cards[3] == 12) && (cards[4] == 13)  ) ||*/
				
				
				
				( (cards[0] == 1) &&  (cards[1] == 10)&&  (cards[2] == 11) &&  (cards[3] == 12) && (cards[4] == 13)  ) ||
				( (cards[0] == 1) &&  (cards[1] == 10)&&  (cards[2] == 11) &&  (cards[3] ==12) &&  (cards[4] == 13)  ) ||
				
				( (cards[0] == (cards[1]-1)) &&  (cards[1] == (cards[2]-1)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				( (cards[0] == (cards[1]-1)) &&  (cards[1] == (cards[2]-3)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				( (cards[0] == (cards[1]-3)) &&  (cards[1] == (cards[2]-1)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				( (cards[0] == (cards[1]-2)) &&  (cards[1] == (cards[2]-2)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				( (cards[0] == (cards[1]-2)) &&  (cards[1] == (cards[2]-1)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				( (cards[0] == (cards[1]-3)) &&  (cards[1] == (cards[2]-2)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				
				( (cards[0] == (cards[1]-1)) &&  (cards[1] == (cards[2]-2)) &&  (cards[3] == 13) && (cards[4] == 13)) ||
				
				( (cards[0] == 7) &&  (cards[1] == 9) &&   (cards[2] == 10) &&  (cards[3] == 13) && (cards[4] == 13)  ) ||
				
				( (cards[0] == 5) &&  (cards[1] == 6) &&   (cards[2] == 9) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 4) &&  (cards[1] == 6) &&   (cards[2] == 7) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 3) &&  (cards[1] == 4) &&   (cards[2] == 12) &&  (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 6) &&  (cards[1] == 7) &&   (cards[2] == 8) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 3) &&  (cards[1] == 5) &&   (cards[2] == 6) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
			    ( (cards[0] == 2) &&  (cards[1] == 3) &&   (cards[2] == 6) &&   (cards[3] == 13) && (cards[4] == 13)  ) ||
				( (cards[0] == 6) &&  (cards[1] == 8) &&   (cards[2] == 9) &&   (cards[3] == 10) && (cards[4] == 13)  ) ||
				
				
				
				( (cards[0] == 7) &&  (cards[1] == 9) &&   (cards[2] == 10) &&  (cards[3] == 11) && (cards[4] == 13)  ) ||
				
				( (cards[0] == 1) &&  (cards[1] == (cards[2]-1)) &&  (cards[2] == (cards[3]-2)) && (cards[4] == 13))||
				( ((cards[0] == (cards[1]-1)) || (cards[0] == (cards[1]-2)) ) && (cards[4] == 13) && ( (cards[1] == (cards[2]-1) ) || (cards[1] == (cards[2]-2)) ) && (cards[2] == (cards[3]-1) ) ) ||
				( ((cards[0] == (cards[1]-1))  ) && (cards[4] == 13) && (cards[1] == (cards[2]-1) ) && ( (cards[2] == (cards[3]-1) ) || (cards[2] == (cards[3]-2))) )
			)	
	 {
        if (flushFlag)
        {
            SetPayout(5);   //  STRAIGHT flush
        }
        else
        {
            SetPayout(9);   // Just a straight
        }
    }
//==============================================================================================================================================
    else if (flushFlag)
    {
		//alert("in---"+flushFlag)
        SetPayout(8);   // Just a flush
    }
	
//==============================================================================================================================================

else if (
			 ((cards[1] == cards[2]) && (cards[1] == cards[3]) && ((cards[1] == cards[4]) || (cards[1] == cards[0]))) ||
			 ((cards[0] == cards[1]) && ((cards[0] == cards[3]) || (cards[0] == cards[4]) ) && ((cards[3] == 13) || (cards[4] == 13) )) ||
			 ((cards[0] == cards[1] ) && (cards[0] == cards[2] ) && (cards[4] == 13)) || 
			 ((cards[1] == cards[2] ) && (cards[1] == cards[3] ) && (cards[4] == 13)) || 
			 ((cards[1] == cards[2]) && ((cards[3] == 13) && (cards[4] == 13) ))||
			 ((cards[0] == cards[1]) && ((cards[3] == 13) && (cards[4] == 13) ))||
			  (((cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13)))||
			 (((cards[0] != cards[1]) &&(cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13)))
			 
			)
    {
        SetPayout(6);   // Four of a kind
    }
//==============================================================================================================================================
  
else if (
			 ((cards[0] == cards[1]) && (cards[3] == cards[4]) && ((cards[2] == cards[1]) || (cards[2] == cards[3])) ) ||
			 ((cards[0] == cards[1]) && (cards[3] == 13) && (cards[2] == 13) &&(cards[4] == 13)) ||
			 ((cards[0] == cards[1]) &&  (cards[0] == cards[2]) && ( (cards[3] == 13) && (cards[4] ==13)  )   ) ||
			 ((cards[0] == cards[1]) &&  (cards[2] == cards[3]) && ( cards[4] ==13)  )  ||
			 ((cards[0] == cards[1] ) && ((cards[2] == 13) && (cards[3] == 13) && (cards[4] == 13)))
			 )
		
    {
        SetPayout(7);   // Full House
    }
	
//==============================================================================================================================================
	
else if (
			 ((cards[0] == cards[1]) && (cards[1] == cards[2])) || ((cards[1] == cards[2]) && (cards[2] == cards[3])) || ( (cards[2] == cards[3] ) && (cards[3] == cards[4] ) ) ||
			((cards[0] == cards[1]) && (cards[4] == 13)) || ((cards[1] == cards[2]) && (cards[4] == 13)) || (cards[0] == cards[3] && cards[4] == 13)  || (cards[2] == cards[3] && cards[4] == 13) || (cards[3] == cards[4] && (cards[3] == 13 || cards[4] == 13) )
			 
		)
			
   {
        SetPayout(10);   // Three of a kind
    }
//==============================================================================================================================================
    else
    {
       AlertMsg('<span id="results" style="color:black;"><font size=\"3\" style=\"color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif; \" >Bust</font></span>');
			 // document.getElementById('bankarea').innerHTML = '<span id="results">Bust</span>';

    }

//setTimeout("DoHand()",3000);
 document.getElementById('action-deal').innerHTML = '<div style=\"position:absolute; left:40px; top:3px;  visibility: hidden;\"><img src=\"button/nexthand_white.png\" onClick=\"DoHand();cleardiv()\" id=\"Next Hand\"></div>';
 /*Bet = 0;
    

	// If you ran out of money...
	if (Bank < 1)
	{
		alert('You have run out of chips!  We are giving you a fresh set of 100 chips.');
		Bank = 100;
	}
 document.getElementById('action-bet').innerHTML = '<input type=button value="Bet" onclick="AddBet(1)" /><input type=button value="Max" onclick="AddBet(' + MaxBet + ')" />';
    document.getElementById('action-deal').innerHTML = '<input type=button value="Deal" onclick="callfun()" />';*/
}
function callfun(){
	//alert(" in callfun ");
	
FlushHand();
	DoDeal()	
}

function InitPayoutTable()
{
	//alert(" in InitPayoutTable ");
var tmp = '<table cellspacing=0 border=1 bordercolor=white ><tr> <th>Payout Table</th>';
    for (cols = 1; cols < Payout[0].length; cols++)
    {
        tmp += '<th >' + cols + '</th>';
    }
    tmp += '</tr> ';

    for (rows = 0; rows < Payout.length; rows++)
    {
        tmp += '<tr >';
        tmp += '<th id='+rows+'  >' + Payout[rows][0] + '</th>';
        for (cols=1; cols<Payout[rows].length; cols++)
        {
			
            tmp += '<td id='+rows+cols+'>' + Payout[rows][cols] + '</td>';
        }
        tmp += '</tr>';
    }
    tmp += '</table>';
    PayoutTable.innerHTML = tmp;
}


function GetBank()
{
														//alert("in GetBank");

    var t = GetCookie('Bank');
    if ((t - 0) < 1)
    {
        t = 100;
        SetBank(t);
    }
    return(t);
}

function SetBank(money)
{
		
		//Bank=100;
		//alert("SetBank");
 SetCookie('Bank',money);
}

function GetCookie(name)
{
																//alert("GetCookie");

    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            var endstr = document.cookie.indexOf (";", j);
            if (endstr == -1)
            {
                endstr = document.cookie.length;
            }
            return unescape(document.cookie.substring(j, endstr));
        }

        i = document.cookie.indexOf(" ", i) + 1;

        if (i == 0)
        {
            return null;
        }
    }
    return null;
}

function SetCookie(name, value)
{
																	//alert("SetCookie");

    document.cookie = name + '=' + escape(value) + CookieExpires;
}



function setCookie1(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie1(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}



function checkCookie1()
{
	//alert("checkCookie1 bet"+Bet);
Bet=getCookie1('Bet');
//alert(Bet);
if (Bet!=null && Bet!="")
  {
	  //added
//  alert('Welcome again '+Bet+'!');
 document.getElementById('betDiv').innerHTML = "<font color='yellow'><b>$"+Bet+"</b></font>";
 }
 else
 Bet=0;
}


