<?xml version="1.0" encoding="UTF-8"?>
<Module> 
<ModulePrefs title="TD Keno v0.3"
		 description="Play single or multi-game Keno (1, 5, 10 or 100 games at a time). Pick 1-10 numbers from 1-80 and try to match against 20 randomly drawn Keno numbers. Session winning game stats and percentage displayed."
             render_inline="optional"
		 height="115"
		 scaling="false" 
             author="TDavid"
		 screenshot="http://www.tdscripts.com/scripts/google/tdkenov03.gif"
             author_email="tdavid+googleapi@gmail.com"
             author_affiliation="tdscripts.com"
             author_location="Puyallup, WA"
/>
<UserPref name="color" display_name="Color" default_value="#FFFFFF"/>
<Content type="html">
<![CDATA[
<!-- /////////////////////// JavaScript Content ///////////////////////////
// TD Keno Copyright 2005 KMR Enterprises All Rights Reserved
// Last Updated: 12/21/2005
////////////////////////////////////////////////////////////////////////// -->

<script language="JavaScript">
// function reference: http://www.ecma-international.org/publications/standards/Ecma-262.htm
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};
 
var nums = [1,2,3,4,5,6,7,8,9,10,
		11,12,13,14,15,16,17,18,19,20,
		21,22,23,24,25,26,27,28,29,30,
		31,32,33,34,35,36,37,38,39,40,
		41,42,43,44,45,46,47,48,49,50,
		51,52,53,54,55,56,57,58,59,60,
		61,62,63,64,65,66,67,68,69,70,
		71,72,73,74,75,76,77,78,79,80];
var chosen = new Array();
var score = 25;
var numgames = 0;
var numwins = 0;
var winpct = 0; // winpercent is numgames / numwins * 100

function pad(number,size) {
    var str = '' + number;
    while (str.length < size)
        str = '0' + str;
    return str;
}

function multiplayKeno__MODULE_ID__(gamestoplay) {
if(chosen.length == 0) {
alert('To play you must choose at least number from 1-80 by entering into the text box and then pressing the green Add button');
return false;
}
var xtime = 0;
	for (ngames=0;ngames<gamestoplay;ngames++) {
		xtime = 1000 * ngames;
  		setTimeout("playKeno__MODULE_ID__()",xtime);
	}
return true;
}

function playKeno__MODULE_ID__() {
  var keno = nums.shuffle();
  var display = "&nbsp;&nbsp;";
  numgames = numgames + 1;
  score = score - 1;
	if(score < 1) {
		score = 25;
	}
  matched = 0;
		for (i=0;i<20;i++) {
			flag = 0;
			for (x=0; x<chosen.length; x++) {
				if (keno[i] == chosen[x]) {
					flag = 1;
					matched++;
				}
			}
			if (flag == 1 ) {
				display = display + "<font color='red'>" + pad(keno[i],2) + "</font> ";
			} else {
	   			display = display + pad(keno[i],2) + " ";
			}
			if (i == 9) { display = display + '<br />&nbsp;&nbsp;' }
		} 
	document.getElementById("keno_game").innerHTML = display;
	if( matched > 0 ) { scoreKeno(matched) }
	document.getElementById("score").innerHTML = "Score: " + score + " Games: " + numgames + " Win: " + numwins + " (" + Math.round((numwins / numgames)*100) + "%)";
	document.getElementById("keno_head").innerHTML = "TD &nbsp; K E N O&nbsp;&nbsp;&nbsp;&nbsp;" + pad(numgames,3);

// end playKeno function 
return true;
}
 
function winner(inVal2, inVal3, message) {
numwins = numwins + 1;
alert(message + "You matched " + inVal2 + " out of " + chosen.length);
return inVal3;
}

function scoreKeno(inVal2) {
	switch (chosen.length) {
	case 1:
		score = score + winner(inVal2,3,'Try more numbers? ');
	break;
	case 2:
		if(inVal2 == 2) {
			score = score + winner(inVal2,12,'Winner! ');
		}
	break;
	case 3:
		if(inVal2 == 3) {
			score = score + winner(inVal2,42,'Cool picks! ');
		}
		else if(inVal2 == 2) {
			score = score + 1;
		}
	break;
	case 4:
		if(inVal2 == 4) {
			score = score + winner(inVal2,120,'Nicely done! ');
		}
		else if(inVal2 == 3) {
			score = score + 3;
		}
		else if(inVal2 == 2) {
			score = score + 1;
		}
	break;
	case 5:
		if(inVal2 == 5) {
			score = score + winner(inVal2,800,'WOW! ');
		}
		else if(inVal2 == 4) {
			score = score + 10;
		}
		else if(inVal2 == 3) {
			score = score + 1;
		}
	break;
	case 6:
		if(inVal2 == 6) {
			score = score + winner(inVal2,1500,'OUTSTANDING!! ');
		}
		else if(inVal2 == 5) {
			score = score + 85;
		}
		else if(inVal2 == 4) {
			score = score + 3;
		}
		else if(inVal2 == 3) {
			score = score + 1;
		}
	break;

	case 7:
		if(inVal2 == 7) {
			score = score + winner(inVal2,8000,'Super Amazing!! ');
		}
		else if(inVal2 == 6) {
			score = score + 400;
		}
		else if(inVal2 == 5) {
			score = score + 20;
		}
		else if(inVal2 == 4) {
			score = score + 1;
		}
	break;
	case 8:
		if(inVal2 == 8) {
			score = score + winner(inVal2,20000,'ASTONISHING!! ');
		}
		else if(inVal2 == 7) {
			score = score + 1500;
		}
		else if(inVal2 == 6) {
			score = score + 75;
		}
		else if(inVal2 == 5) {
			score = score + 5;
		}
		else if(inVal2 == 4) {
			score = score + 1;
		}
	break;
	case 9:
		if(inVal2 == 9) {
			score = score + winner(inVal2,25000,'VERY ASTONISHING!! ');
		}
		else if(inVal2 == 8) {
			score = score + 4000;
		}
		else if(inVal2 == 7) {
			score = score + 350;
		}
		else if(inVal2 == 6) {
			score = score + 40;
		}
		else if(inVal2 == 5) {
			score = score + 3;
		}
	break;
	case 10:
		if(inVal2 == 10) {
			score = score + winner(inVal2,50000,'YOU ARE THE KENO MASTER! ');
		}
		else if(inVal2 == 9) {
			score = score + 8000;
		}
		else if(inVal2 == 8) {
			score = score + 400;
		}
		else if(inVal2 == 7) {
			score = score + 100;
		}
		else if(inVal2 == 6) {
			score = score + 15;
		}
		else if(inVal2 == 5) {
			score = score + 2;
		}
	break;

	}
}

function errorMsg__MODULE_ID__(emsg) {
kenochosen.player_number.value="";
alert(emsg);
}

function validIs__MODULE_ID__(inVal) {
inVal = inVal.replace(/,/g, "");
var n = parseFloat( inVal );
inVal = n;
	if ( (inVal == "") || (inVal < 1) || (inVal > 80) ) {
		errorMsg__MODULE_ID__("Invalid number, must be between 1 and 80");
		return false;
	}

if (chosen.length > 0) {
	for (i=0; i<chosen.length; i++) {
		if (inVal == chosen[i]) {
			errorMsg__MODULE_ID__('You already have selected that number, please select another.');
			return false;
		}
	}
}

if (chosen.length > 9) {
	errorMsg__MODULE_ID__('Maximum of ten numbers allowed already chosen.');
	return false;
}

kenochosen.player_number.value = "";
chosen.push(inVal);
document.getElementById("chosen_picksVVVGOOGLEVVV").innerHTML = "Picks: " + chosen;
}

function clearChosen__MODULE_ID__() {
 chosen.pop(chosen.length)
 document.getElementById("chosen_picksVVVGOOGLEVVV").innerHTML = "Picks: " + chosen;
}
</script>

<!-- ///////////////////////////// HTML Content /////////////////////////// -->
<style type="text/css">
form { margin: 0; padding: 0; }
#keno_head {
	background: black;
	color: red;
	width: 250px;
	font-size: 16px;
	text-align: center;
}
#keno_game {
	background: black;
	color: white;
	width: 250px;
	font-size: 15px;
	text-align: center;
}
#chosen_picksVVVGOOGLEVVV {
	font-size: 14px;
}
#score {
	text-align: right;
	width: 240px;
	font-size: 12px;
}
.kenoin {
	font-family: Arial; 
	font-size: 8pt; 
	color: #FFFFFF; 
	font-weight: bold; 
	background-color: #005F04
}
.kenoclr {
	font-family: Arial; 
	font-size: 8pt; 
	color: #FFFFFF; 
	font-weight: bold; 
	background-color: #FF0000
}
.kenobut {
	font-family: Arial; 
	font-size: 8pt; 
	color: #FFFFFF; 
	font-weight: bold; 
	background-color: #000080
}
</style>
<div id="keno_head">
TD &nbsp; K E N O&nbsp;&nbsp;&nbsp;&nbsp;001
</div>
<div id="keno_game">
Choose up to 10 numbers<br />
from 1-80 and press Play!
</div>
<div id="chosen_picksVVVGOOGLEVVV">
Picks: ???
</div>

<form name="kenochosen">
<input type="text" size="1" name="player_number"> <input class="kenoin" type="button" onClick="validIs__MODULE_ID__(kenochosen.player_number.value);" value="Add">
<input class="kenoclr" type="button" onClick="clearChosen__MODULE_ID__()" value="Clear"> 
<input class="kenobut" type="button" onClick="multiplayKeno__MODULE_ID__(1)" value="Play 1">
<input class="kenobut" type="button" onClick="multiplayKeno__MODULE_ID__(5)" value="5">
<input class="kenobut" type="button" onClick="multiplayKeno__MODULE_ID__(10)" value="10">
<input class="kenobut" type="button" onClick="multiplayKeno__MODULE_ID__(100)" value="100"><br />
</form>

<div id="score">
TD Keno v0.3 by <a href="http://www.tdscripts.com/">TD Scripts</a>
</div>

]]>
</Content>
</Module>