// Lotto Picker Script
// copyright Stephen Chapman, 3rd May 2006
// you may copy this script but please keep the copyright notice as well

function randOrd(){return (Math.round(Math.random())-0.5);}function  picks(pick,tot) {var ary = [];for (var i = tot; i > 0; i--) ary.push(i ); ary.sort(randOrd);return ary.slice(0,pick).join(',');}

function stripBlanks(fld) {var result =  "";var c = 0;for (i=0; i < fld.length; i++) {if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}var numb = '0123456789';function isValid(parm,val) {if (parm == "") return true; for (i=0; i<parm.length; i++) {if (val.indexOf(parm.charAt(i),0) == -1) return false;} return true;}function isNumber(parm) {return isValid(parm,numb);}function gen(frm) {var p = stripBlanks(frm.pk.value);var t = stripBlanks(frm.tl.value);if (p == '' || !isNumber(p)) {alert("Number of picks must be numeric");thisform.pk.focus();return false;}if (t == '' || !isNumber(t)) {alert("Total to pick from must be numeric");thisform.tl.focus();return false;}p = parseInt(p); t = parseInt(t);if (t <= p) {alert("Total to pick from must be greater than the number of picks");thisform.tl.focus();return false;}frm.rs.value = picks(p,t);}
                  