// JavaScript Document
var lotto_size = 5; // # of numbers in the lottery NOT plus bonus
var num_max = 59; // lotto scope 1 to x
var repeat_num = 0; // 1 = yes; 0 = no; Can numbers repeat? 
 
var bonus_num = 39; //bonus ball scope 1 to x; 0 if none
var bonus_incl = 1; // 1 = yes; 0 = no; Is the bonus ball a separate draw?
 
 
 
 
// don't change values below *****
var print_bonus = "";
var picks = new Array (lotto_size);
var time_num = 0;
 
function pick_numbers(){
    
	picks = [];
	var i;
	var x = -1;
	for (i = 0; i < lotto_size; i++)
	{
		do{
			pick = rand(num_max);
			pick = pad(pick, 2);
			
			if(repeat_num == 0){
			x = picks.join().indexOf(pick);
			}
		}while(x != -1);
		
		picks[i] = pick;
	     
	}
	
	if(bonus_num != 0){
	bonusPick();
	swapTextBonus(print_bonus);
	}
 
swapText(picks.join(" "));
 
}
 
function bonusPick(){
 
    if(bonus_incl == 0){ //If the bonus ball cannot match a number in the regular pick
        var x = -1;
        do{
        var bonus_pick = pad(rand(bonus_num),2);
        x = picks.join().indexOf(bonus_pick);
        }while(x != -1);
    }else{
    var bonus_pick = pad(rand(bonus_num),2);
    }
 
print_bonus = bonus_pick;
}
 
 
function start_loop(){
time_num = 0;
looping();
}	
 
function looping(){
if(time_num == 0){
pick_numbers()
window.setTimeout('looping()',75);
}
 
}
 
function stop_loop(){
time_num = 1;
}	
 
function QuickPick(){
time_num = 1;
pick_numbers();
 
}
 
function AddPick(){
 
var crlf = "\r" + "\n"; // CR and LF to append
picks.sort(function(a,b){return a - b});
var pick = picks.join(" ");
var sw = document.WindowForm.snw.value; // Window
var bon = "";
 
if(pick >= 0)
return;
 
if(bonus_num != 0){
var bon = " (" + print_bonus + ")";
document.WindowForm.snw.value= sw + pick + bon + crlf;
}else
document.WindowForm.snw.value= sw + pick + crlf;
 
}
 
function pad(number, length) {
   
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
   
    return str;
 
}
 
function swapText(txtMsg){
 
// FF fix
if (navigator.userAgent.indexOf('Firefox') !=-1)
{
dynamiccontentNS6("msg",txtMsg);
}else
msg.firstChild.data = txtMsg;
 
}
 
function swapTextBonus(txtMsg){
 
// FF fix
if (navigator.userAgent.indexOf('Firefox') !=-1)
{
dynamiccontentNS6("bonusball",txtMsg);
}else
bonusball.firstChild.data = txtMsg;
 
}
 
// Function for FF fix
function dynamiccontentNS6(elementid,content){
if (document.getElementById && !document.all){
rng = document.createRange();
el = document.getElementById(elementid);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}
}
 
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
 
 
function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

