function raceselect()
{
var myrace=document.getElementById("myrace");
var racenumber=document.getElementById("myrace").selectedIndex;

if(racenumber==0) { horse = new Array();	horse[0]="My Will 9/1";	odds = new Array();	odds[0]=10;	
	horse[1]="Butler's Cabin 9/1";		odds[1]=10;	
	horse[2]="Rambling Minster 9/1";		odds[2]=10;	
	horse[3]="Black Apalachi 14/1";		odds[3]=15;	
	horse[4]="State Of Play 14/1";		odds[4]=15;	
	horse[5]="Parsons Legacy 16/1";		odds[5]=17;	
	horse[6]="Darkness 16/1";		odds[6]=17;	
	horse[7]="Comply Or Die 18/1";		odds[7]=19;	
	horse[8]="Hear The Echo 20/1";		odds[8]=21;	
	horse[9]="Offshore Account 20/1";		odds[9]=21;	
	horse[10]="Kilbeggan Blade 20/1";		odds[10]=21;	
	horse[11]="Big Fella Thanks 22/1";		odds[11]=23;	
	horse[12]="L'Ami 22/1";		odds[12]=23;	
	horse[13]="Irish Invader 22/1";		odds[13]=23;	
	horse[14]="Snowy Morning 28/1";		odds[14]=29;	
	horse[15]="Southern Vic 28/1";		odds[15]=29;	
	horse[16]="Cornish Sett 33/1";		odds[16]=34;	
	horse[17]="Brooklyn Brownie 33/1";		odds[17]=34;	
	horse[18]="Himalayan Trail 33/1";		odds[18]=34;	
	horse[19]="Battlecry 40/1";		odds[19]=41;	
	horse[20]="Can'T Buy Time 40/1";		odds[20]=41;	
	horse[21]="Cloudy Lane 50/1";		odds[21]=51;	
	horse[22]="Silver Birch 50/1";		odds[22]=51;	
	horse[23]="Idle Talk 50/1";		odds[23]=51;	
	horse[24]="Chelsea Harbour 66/1";		odds[24]=67;	
	horse[25]="Knowhere 66/1";		odds[25]=67;	
	horse[26]="Golden Flight 66/1";		odds[26]=67;	
	horse[27]="Ollie Magern 80/1";		odds[27]=81;	
	horse[28]="Mon Mome 80/1";		odds[28]=81;	
	horse[29]="Stan 100/1";		odds[29]=101;	
	horse[30]="Preists Leap 100/1";		odds[30]=101;	
	horse[31]="Eurotrek 100/1";		odds[31]=101;	
	horse[32]="Reveillez 125/1";		odds[32]=126;	
	horse[33]="Zabenz 125/1";		odds[33]=126;	
	horse[34]="Fleet Street 150/1";		odds[34]=151;	
	horse[35]="Musica Bella 150/1";		odds[35]=151;	
	horse[36]="Fundamentalist 200/1";		odds[36]=201;	
	horse[37]="Kelami 200/1";		odds[37]=201;	
	horse[38]="Arteea 300/1";		odds[38]=301;	
	horse[39]="Cerium 500/1";		odds[39]=501;	
				calc()};


function calc()
{

var total = 0;
for(var i = 0; i < odds.length; i++)
{
 total += odds[i];
} 


//odds range
aveodd = Math.floor(total / odds.length);
toppercent= Math.floor((aveodd / 100) * 20);
midpercent= Math.floor((aveodd / 100) * 60);
lowmidpercent = Math.floor((aveodd / 100) * 150);
outsidepercent = Math.floor((aveodd / 100) * 200);

for (t=toppercent; odds.lastIndexOf(t)<odds.length; t++)
{
if(odds.lastIndexOf(t)!=-1)
{
break;
}}
topodd = odds.lastIndexOf(t);

for (m=midpercent; odds.lastIndexOf(m)<odds.length; m++)
{
if(odds.lastIndexOf(m)!=-1)
{
 break;
}}
midodd = odds.lastIndexOf(m);

for (l=lowmidpercent; odds.lastIndexOf(l)<odds.length; l++)
{
if(odds.lastIndexOf(l)!=-1)
{
 break;
}}
lowodd = odds.lastIndexOf(l);
for (o=outsidepercent; odds.lastIndexOf(o)<0; o--)
{
if(odds.lastIndexOf(o)!=-1)
{
 break;
}}
outodd = odds.lastIndexOf(o);
//horse range
horserange = topodd;
horserange2 = midodd;
horserange3 = lowodd;
horserange4 = outodd;
var range = 0;

if (Math.floor(Math.random() * horse.length)<=horserange)
{
	range = horserange
	}
else if (Math.floor(Math.random() * horse.length)>horserange && Math.floor(Math.random() * horse.length)<horserange2)
{	
	if (Math.floor(Math.random() * 2) ==0)
	{
	range = horserange
	}
	else if(Math.floor(Math.random() * 2) ==1)
	{
	range = horserange2
	}
}
else if (Math.floor(Math.random() * horse.length)>=horserange2 && Math.floor(Math.random() * horse.length)<=horserange4)
{
	if (Math.floor(Math.random() * 3) ==0)
	{
	range = horserange
	}
	else if(Math.floor(Math.random() * 3) >=1)
	{
	range = horserange3
	}
	
	
}
else if (Math.floor(Math.random() * horse.length)>=horserange3)
{
	if (Math.floor(Math.random() * 4) ==0)
	{
	range = horserange
	}
	else if(Math.floor(Math.random() * 4) ==1)
	{
	range = horserange2
	}
	else if(Math.floor(Math.random() * 4) >=2)  
	{
	range = horserange4
	}
	
	
}
index = Math.floor(Math.random() * Math.floor(range));
}


document.getElementById("selection").value=horse[index];
}

