<!--
//log the number selected
    var intSelected=0;
    var intMaxSelected=6;
    var intTotalNumbers = 49;
	var arrPlayersNumbers = new Array();
	var intPlayersBonus = null;
    var isBonusSelected=false;        //log if the bonus ball has been selected
    var strSelected="selected";       //Define the styles to use
    var strBonus="bonus";             //Define the styles to use

//A Player has clicked on a ball
function pickBall (id) {
    var intStatus = 0;
    var identity = document.getElementById('c' + id);
			
    if (identity.className.indexOf(strSelected) > 0) { 
      if (identity.className.indexOf(strBonus) > 0) { intStatus = 1; }          //selected and bonus
      else { intStatus = 2; }                                                   //selected, but not bonus
	} else { if (identity.className.indexOf(strBonus) > 0) { intStatus = 1; } } //bonus, not selected

    switch (intStatus)
    {
    case 1:     //1. It is currently selected and bonus therefore unselect a bonus Or //2. It is currently bonus, not selected ball therefore unselect a bonusball
	       unselectBonus(id);
      break
    case 2:      //It is currently selected, and it's not bonus 
	       if (intSelected != intMaxSelected) { unselectBall(id); }               //if not all are selected unclick
	       else { 
              //if all are selected check if there is a bonus selected elewhere
              if (isBonusSelected == true) { unselectBall(id); }                  //unselect a ball
              else { selectBonus(id); }                                           //Select a bonus
		   }
      break
    default:      //It is currently not selected, not bonus (A clear square)
    	  if (intSelected != intMaxSelected){ selectBall(id); }		         //Have all the numbers been selected? If not all selected, select a ball

          //Are all numbers selected and the bonus selected elsewhere?
    	  else { 
	          if (isBonusSelected == true) { alert ("all numbers have been selected!"); }
    	      if (isBonusSelected == false) { selectBonus(id); } //Select a bonus
	      }
    }
	
	//Output selection?
	//alert (arrPlayersNumbers);
	
}

//Select a ball only
function selectBall(id){
    var identity = document.getElementById('c' + id);
    identity.className = identity.className + " " + strSelected;  //Add a new class noting it is selected
    intSelected = intSelected + 1;                                //Increment the selection
    constrainLimits();                                            //Make sure we don't exceed limits
}

function constrainLimits(){
    if(intSelected > intMaxSelected){ intSelected = intMaxSelected; } //Don't go above the max allowed
    if(intSelected < 0){ intSelected = 0; }                           //Don't go below the min allowed
}

//Select a ball only
function selectBall(id){
    var identity = document.getElementById('c' + id);
    identity.className = identity.className + " " + strSelected;  //Add a new class noting it is selected
    intSelected = intSelected + 1;                                //Increment the selection
    constrainLimits();                                            //Make sure we don't exceed limits
    arrPlayersNumbers[(intSelected-1)]= id;                       //Log the number picked
	arrPlayersNumbers.sort( numOrdA );                            //Sort the log with the smallest number first
	showSelection("s");
}

//unselect a ball only 
function unselectBall(id){
    var identity = document.getElementById('c' + id);
    identity.className = trim(replace(identity.className, strSelected, ""));  //Return it to its previous class
    intSelected = intSelected - 1;                                            //Reduce the count of selected
    constrainLimits();                                                        //Make sure we don't exceed limits
    removeFromArrPlayersNumbers(id);                                 		  //Remove the number from the log
	showSelection("s");
}

function removeFromArrPlayersNumbers (id) {
    for (j=0;j<= arrPlayersNumbers.length;j++)
    { 
    	if (arrPlayersNumbers[j] == id) { 
    		arrPlayersNumbers.splice(j, 1);
    	 }
    }
}

//I show/update to the screen the balls the player has selected.
function showSelection (idtype) {

	//HP 28/11/05: Get the values entered and set to a variable selectedNumbers
	var chosenNumber = "";
	var numbers_selected = "" ;
	
	//Clear what is currently shown:
	    for (i=1;i<=intMaxSelected;i++)
	    { 
	    	document.getElementById(idtype + i).innerHTML = '&nbsp;'; 
			document.getElementById(idtype + i).className = 'lotto_ball';
	    	}

	//Display the new values
	    for (i=1;i<=intSelected;i++)
	    {   //if number is less then ten put a '0' infront to keep it nicey formatted 
	    	
	    	if ((arrPlayersNumbers[i-1] < 50 ) && (arrPlayersNumbers[i-1] > 39 )) {
	    		 document.getElementById(idtype + i).className = document.getElementById(idtype + i).className + " " + 'forties';
  		 	}
	    	if ((arrPlayersNumbers[i-1] < 40 ) && (arrPlayersNumbers[i-1] > 29 )) {
	    		 document.getElementById(idtype + i).className = document.getElementById(idtype + i).className + " " + 'thirties';    			
  		 	}
	    	if ((arrPlayersNumbers[i-1] < 30 ) && (arrPlayersNumbers[i-1] > 19 )) {
	    		 document.getElementById(idtype + i).className = document.getElementById(idtype + i).className + " " + 'twenties';
  		 	}
	    	if ((arrPlayersNumbers[i-1] < 20 ) && (arrPlayersNumbers[i-1] > 9 )) {
	    		 document.getElementById(idtype + i).className = document.getElementById(idtype + i).className + " " + 'tens';
  		 	}
	    	if (arrPlayersNumbers[i-1] < 10 ) {
	    		 document.getElementById(idtype + i).innerHTML = '0' + arrPlayersNumbers[i-1]; 
	    		 document.getElementById(idtype + i).className = document.getElementById(idtype + i).className + " " + 'noughts';
  		 	}
	    	else{ document.getElementById(idtype + i).innerHTML = arrPlayersNumbers[i-1];	    	
	    	 }
	    // HP 29.11.2005: Added to identify which numbers to pass 
    	chosenNumber = chosenNumber + ", " + arrPlayersNumbers[i-1];
    	selected_numbers =  trim(chosenNumber);
    	if (i==intMaxSelected) {
    	
    		//HP 29.11.2005: get the bonus number and send it to the form, to be passed to the next page.
	    	// get rid of the leading comma and space
	    	var re = /, /;	
	    	selected_numbers = selected_numbers.replace(re,'');
	    	document.myForm.number_string.value = selected_numbers;
    		// alert (numbers_selected); DEBUGGING
	    	}
	    }
}

//Select a bonus only
function selectBonus(id){
    var identity = document.getElementById('c' + id);                        //Select the stylesheet
    identity.className = identity.className + " " + strBonus;                //Update the stylesheet
    isBonusSelected = true;                                                  //Bonus is selected
	intPlayersBonus = id;                                                    //Set the bonus number
    showSelectionBonus();
}

//Unselect a bonus only
function unselectBonus(id){
    var identity = document.getElementById('c' + id);
    //Check if this one is the selected bonus ball
    if (identity.className.indexOf(strBonus) > 0){
        identity.className = trim(replace(identity.className, strBonus, ""));  //Return it to its previous class
        isBonusSelected = false;                                               //Bonus is no longer selected
        intPlayersBonus = null;                                                //This was the bonus number
		dontshowSelectionBonus();
    }
}

//I show the value on screen if a player is has selected a bonus ball.
function showSelectionBonus () {
    var identity = document.getElementById("sBonus");

	//if number is less then ten put a '0' infront to keep it nicely formatted
	  	if (intPlayersBonus < 10 ) { identity.innerHTML = '0' + intPlayersBonus; }
	   	else{ identity.innerHTML = intPlayersBonus; }	
	
    	identity.className = identity.className + " " + strBonus;                //Update the stylesheet

		//HP 29.11.2005: get the bonus number and send it to the form, to be passed to the next page.
	    var bonus_numbers_selected =  intPlayersBonus;
    	isBonusSelected=true;    	
    	document.myForm.bonus_number.value = bonus_numbers_selected;

    	// alert (bonus_numbers_selected); DEBUGGING
}

//I switch off the value on screen of a player's a bonus ball.
function dontshowSelectionBonus () {
    var identity = document.getElementById("sBonus");
	identity.innerHTML = '&nbsp;';
    if (identity.className.indexOf(strBonus) > 0){
        identity.className = trim(replace(identity.className, strBonus, ""));  //Return it to its previous class
	}
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

function replace(argvalue, x, y) {
  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
   
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }
  return argvalue;
}

function clearAllSelected() {
    //Clear all the selected buttons. Clear the selected grid
	    intSelected=0;
	    isBonusSelected=false;
        intPlayersBonus = null;
        arrPlayersNumbers = new Array();

    //Loop through the grid
	    for (i=1;i<=intTotalNumbers;i++)
	    {   identity = document.getElementById('c' + i);
	        identity.className = replace(identity.className, strSelected, "");      //remove the selected class
	        identity.className = replace(identity.className, strBonus, "");     }   //remove the bonus class

    //Display what has been selected (This should clear everything!)
	    showSelection("s");	        	
    	dontshowSelectionBonus();
}

function getLuckyDip() {
    //Create a random selection for the player.
	    //Clear anything currently selected so we have a blank field to play with.
    		clearAllSelected();

    //Get an array of random numbers
    var arrLotteryNumbers = new Array(intMaxSelected-1);
    arrLotteryNumbers = getRandomNumbers();
							    
    //Update the grid with this selection
	    for (k=0; k<=(intMaxSelected-1); k++) 
			{ pickBall(arrLotteryNumbers[k]); }
		pickBall(get_random_Lotto_number());                //Get a bonus number
}

//I select the player's luckly numbers:
function pickLucky(num1,num2,num3,num4,num5,num6,num7) {
	   // alert(num4); DEBUGGING
	    clearAllSelected();   //Clear anything currently selected so we have a blank field to play with.
		pickBall(num1);       //Pick the normal numbers
		pickBall(num2);                
		pickBall(num3);                
		pickBall(num4);                
		pickBall(num5);                
		pickBall(num6);                
		pickBall(num7);       //Get a bonus number
	
}



//I take the currently selected numbers and make them the lucky numbers
function resetLuckyNumers() {
	//Check if the tickbox is selected //Check if all the numbers are selected
    if ((document.getElementById("makeLuckyNumbersCheckbox").checked == true) && (isBonusSelected == true) && (intSelected == intMaxSelected)) {
		showSelection("lucky");  											//Reset the numbers
		if (intPlayersBonus < 10) {
	    	document.getElementById("luckybonus").innerHTML = "0" + intPlayersBonus;  //Reset the bonus
		}
		else{
	    	document.getElementById("luckybonus").innerHTML = intPlayersBonus;  //Reset the bonus
		}
		document.getElementById("luckybonus").className = 'lotto_bball_lucky';
		
		//HP 06.12.2005: Added the if() so that it checks if pickLuckyNumbers exists before it tries to use the pickLucky function. It won't exist if they don't already have lucky numbers
		if (document.getElementById("pickLuckyNumbers")) {
			//Reset the lucky numbers if someone picks them again.
			// document.getElementById("pickLuckyNumbers").onclick = "pickLucky(" + arrPlayersNumbers + "," + intPlayersBonus + ");";
			document.getElementById("pickLuckyNumbers").onclick = new Function("pickLucky(" + arrPlayersNumbers + "," + intPlayersBonus + ");");
		}
	}
}


//I get a set of random numbers
function getRandomNumbers(){
    var arrLotteryNumbers = new Array(intMaxSelected-1);
    for (i=0;i<=(intMaxSelected-1);i++)
    {
        arrLotteryNumbers[i] 
		intRanNum = get_random_Lotto_number();
        for (j=0; j <= (intMaxSelected-1); j)
       {
         if (intRanNum == arrLotteryNumbers[j])
         {
            intRanNum = get_random_Lotto_number();
            j=0;
         }
         j++;
       }
       arrLotteryNumbers[i]=intRanNum;
    }
    arrLotteryNumbers.sort( numOrdA );   //Sort it numerically
    return arrLotteryNumbers;
}

function numOrdA(a, b){ return (a-b); }

function get_random_Lotto_number(){
    //I create a random lottery number.
    //NOTE: ran num will be between 0 and intTotalNumbers-1, so we add one to the final value will give us the right range.
    var ranNum= Math.round(1+Math.random()*(intTotalNumbers-1));
    return ranNum;
}


// HP 04.12.2005: I submit the players numbers
function go(str)
{
	if (emailCheck(document.myForm.player_emailaddress.value))
	{
		if (intMaxSelected == 6 && isBonusSelected ==true )
		  {document.myForm.country.value = str; document.myForm.submit();}
		else
		  {alert("You must select 6 numbers and a Bonus number.");}
	}
}

// HP 05.12.2005: I answer  yes to a question on play page
function goincorrect (str)
{
	if (emailCheck(document.myForm.player_emailaddress.value))
	{
		if (intMaxSelected == 6 && isBonusSelected ==true)
		  {document.myForm.country.value = str; 
		  document.myForm.adquesanswer.value = "incorrect";
		  document.myForm.submit();}
		else
		  {alert("You must select 6 numbers and a Bonus number.");}
	}

}

// HP 05.12.2005: I answer no to a question on play page
function gocorrectinactive (str)
{
	if (emailCheck(document.myForm.player_emailaddress.value))
	{
		if (intMaxSelected == 6 && isBonusSelected ==true)
		  {document.myForm.country.value = str; 
		  document.myForm.adquesanswer.value = "correct";
		  document.myForm.submit();}
		else
		  {alert("You must select 6 numbers and a Bonus number.");}
	}

}

//-->