<!--

var KeepGoing=false;
var QuickPick=false;
var theTicket=new Array();
var guessArray=new Array();
var theCount=0;
var Match51=0;
var Match50=0;
var Match41=0;
var Match40=0;
var Match31=0;
var Match21=0;
var Match30=0;
var Match11=0;
var Match01=0;

var SavingsBalance=0;
var curInterest = 0;
var totInterest = 0;

function GetRandom(theMin,theMax){
var Result=eval(theMin)+Math.floor(Math.random()*eval(1+eval(theMax)))
return Result }

function Lotto(){
var Result=""
do { Result=[GetRandom(1,56),GetRandom(1,56),GetRandom(1,56),GetRandom(1,56),GetRandom(1,56),GetRandom(1,47)];
} while (IsNotTicket(Result))
return Result; }

function Setup(){
 Match51=0;
 Match50=0;
 Match41=0;
 Match40=0;
 Match31=0;
 Match21=0;
 Match30=0;
 Match11=0;
 Match01=0;
 theCount=0;
 theTicket=Lotto();
 guessArray=Lotto();
 ShowTicket("sectTicket",theTicket)
 ShowTicket("pick",guessArray) }

function CountMatches(theFirst,theSecond){
 var NumMatches=0
 if (theFirst[0]==theSecond[0]) NumMatches++;
 if (theFirst[0]==theSecond[1]) NumMatches++;
 if (theFirst[0]==theSecond[2]) NumMatches++;
 if (theFirst[0]==theSecond[3]) NumMatches++;
 if (theFirst[0]==theSecond[4]) NumMatches++;
 if (theFirst[1]==theSecond[1]) NumMatches++;
 if (theFirst[1]==theSecond[2]) NumMatches++;
 if (theFirst[1]==theSecond[3]) NumMatches++;
 if (theFirst[1]==theSecond[4]) NumMatches++;
 if (theFirst[2]==theSecond[2]) NumMatches++;
 if (theFirst[2]==theSecond[3]) NumMatches++;
 if (theFirst[2]==theSecond[4]) NumMatches++;
 if (theFirst[3]==theSecond[3]) NumMatches++;
 if (theFirst[3]==theSecond[4]) NumMatches++;
 if (theFirst[4]==theSecond[4]) NumMatches++;
 return NumMatches; }

function ShowTicket(SectName,theArray) { for (i in theArray){ eval(SectName+i).innerText=theArray[i]; } }

function SetValues() {
 sectMatch51.innerText=Match51;
 sectMatch50.innerText=Match50;
 sectMatch41.innerText=Match41;
 sectMatch40.innerText=Match40;
 sectMatch31.innerText=Match31;
 sectMatch21.innerText=Match21;
 sectMatch30.innerText=Match30;
 sectMatch11.innerText=Match11;
 sectMatch01.innerText=Match01;
 sectPrize50.innerText=Match50*250000;
 sectPrize41.innerText=Match41*10000;
 sectPrize40.innerText=Match40*150;
 sectPrize31.innerText=Match31*150;
 sectPrize21.innerText=Match21*10;
 sectPrize30.innerText=Match30*7;
 sectPrize11.innerText=Match11*3;
 sectPrize01.innerText=Match01*2;

 sectWin.innerText = eval(sectPrize50.innerText) + eval(sectPrize41.innerText)
                   + eval(sectPrize40.innerText) + eval(sectPrize31.innerText)
                   + eval(sectPrize21.innerText) + eval(sectPrize30.innerText)
                   + eval(sectPrize11.innerText) + eval(sectPrize01.innerText);

 sectDifference.innerText=eval(sectWin.innerText)-eval(sectCost.innerText);
 if (sectDifference.innerText<0) sectDifferenceColor.style.color='red';
 else sectDifferenceColor.style.color='black'; }

function IsNotTicket(theArray){
 var NotTicket=true;
 if (theArray[0]!=theArray[1] && theArray[0]!=theArray[2] && theArray[0]!=theArray[3] && theArray[0]!=theArray[4] &&
     theArray[1]!=theArray[2] && theArray[1]!=theArray[3] && theArray[1]!=theArray[4] &&
     theArray[2]!=theArray[3] && theArray[2]!=theArray[4] && theArray[3]!=theArray[4]) NotTicket=false;
 return NotTicket; }
 
function FindMatch() {
FormatNumeric(yourtickets);
FormatNumeric(yourinterest);

if (eval(yourtickets.value)==0 || yourtickets.value=="") yourtickets.value=1; 
if (eval(yourinterest.value)==0 || yourinterest.value=="") yourinterest.value=1; 
if (checkQuickPick.checked) QuickPick=true;
else QuickPick=false;

if (QuickPick) { guessArray=Lotto(); }
else { guessArray = [pick0.value, pick1.value, pick2.value, pick3.value, pick4.value, pick5.value]; }

if (IsNotTicket(guessArray)) { PeanutGallery.innerText="Invalid Ticket"; PeanutGallery.style.color="red"; }
else {
PeanutGallery.innerText=""; PeanutGallery.style.color="black";
theTicket=Lotto();
if (CountMatches(guessArray,theTicket)==5 &&
    guessArray[5]==theTicket[5]) { KeepGoing=false; Match51++; }
else {
 if (CountMatches(guessArray,theTicket)==5) { Match50++; }
 if (CountMatches(guessArray,theTicket)==4) { Match40++; }
 if (CountMatches(guessArray,theTicket)==3) { Match30++; }
 if (CountMatches(guessArray,theTicket)==4 && guessArray[5]==theTicket[5]) { Match41++; }
 if (CountMatches(guessArray,theTicket)==3 && guessArray[5]==theTicket[5]) { Match31++; }
 if (CountMatches(guessArray,theTicket)==2 && guessArray[5]==theTicket[5]) { Match21++; }
 if (CountMatches(guessArray,theTicket)==1 && guessArray[5]==theTicket[5]) { Match11++; }
 if (CountMatches(guessArray,theTicket)==0 && guessArray[5]==theTicket[5]) { Match01++; }
}

theCount++;
ShowTicket("sectTicket",theTicket)
ShowTicket("pick",guessArray)
sectCost.innerText=theCount;
sectTimes.innerText=theCount;
sectSaved.innerText=theCount;

sectWeeks.innerText=Math.round(theCount/eval(yourtickets.value));
sectMonths.innerText=Math.floor(eval(sectWeeks.innerText)/4);
sectYears.innerText=Math.floor(eval(sectWeeks.innerText)/52);

SavingsBalance++;
if (theCount%(eval(yourtickets.value)*4)==0) { curInterest = SavingsBalance*(eval(yourinterest.value)/1200);
                     SavingsBalance = eval(eval(SavingsBalance)+eval(curInterest));
                     totInterest = eval(eval(totInterest)+eval(curInterest));
                     sectInterest.innerText=FormatCash(totInterest); }
sectBalance.innerText=FormatCash(SavingsBalance);


SetValues();

if (KeepGoing) setTimeout('FindMatch()',1); }}


function FormatNumeric(Field){
var numbers="0123456789";
var character=""
var temp=""
temp=Field.value
if(temp.length>1) {
  for(j=0;j<temp.length;j++) {
     character=temp.substring(j,j+1);
     if(numbers.indexOf(character)==-1) while(Field.value.indexOf(character)!=-1) Field.value=Field.value.replace(character,'');} }
else {if(numbers.indexOf(temp)==-1) Field.value=Field.value.replace(temp,'');}
}

function FormatCash(theValue){
var tempValue = ""+Math.round(theValue*100)/100;
if (tempValue.indexOf(".")==-1) tempValue=tempValue+".00"
else { 
  var tempchange = tempValue.substr(tempValue.indexOf(".")+1,tempValue.length);
  if (tempchange.length==1) tempValue=tempValue+"0"; }

return tempValue; }



-->
