var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0;
var tempY = 0;


function getMouseXY(e) {
if (IE) { 

tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
//alert(tempX+","+tempY)
}
else { 
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  
document.getElementById('mousex').value = tempX;
document.getElementById('mousey').value = tempY;

return true;
}

// NOTE - MOST OF THE REST OF THIS SCRIPT IS COPYWRITTEN BY (C) SMARTACRE, LLC, 2007 and BEYOND.  
//
// THE EXCEPTIONS ARE
// THE FOLLOWING FUNTIONS : 
//
// LTrim, RTrim, trim, Get_Cookie, Set_Cookie, Delete_Cookie, leadingZero
//
// ALL OTHER FUNCTIONS ARE THE PROPERTY OF SMARTACRE, LLC
//
// TO USE THESE SCRIPTS, IN ALL OR IN PART - 
//
// YOU MUST ASK FOR PERMISSION To USE THEM BY CONTACTING SMARTACRE@SMARTACRE.COM
//
// PLEASE INCLUDE THE TYPE OF APPLICATION YOU ARE PLANNING ON USING THEM IN
//

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}


function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}


function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}


function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function isNull( value ) {

return(value==null);

}


function checkme ( x1 )
{

 var theForm = document.forms["former"];

 theForm.elements['i-'+x1].checked = true;

}

function onloader()

{

var theForm = document.forms["former"];
var xadd=document.getElementById('populate');
var x=document.getElementById('populate').rows[2].cells;
weekno = theForm.elements['weekno'].value;

t1 = theForm.elements['xcount'].value;
roby = theForm.elements['oby'].value;

lstable = '';
//alert(1);

league=theForm.elements['lg'].value;

if (t1==0)
{
 x1="&nbsp;Sorry.. you have no horses!"
 x[0].innerHTML=x1;
}

if (t1 > 0)
{


// alert(1);

 c1=2;
 for (y=1; y<= t1; y++)
 {
 //alert(c1);

 c1=c1+1;

 t2=theForm.elements['x'+y].value;
 t2a=t2.split("!");
 tstable=t2a[4];
//alert(2);
 if ((tstable != lstable) && (roby =="bystable"))
 {
//alert(3);
  var row = xadd.insertRow(c1);
  var cellLeft = row.insertCell(0);
  var xa=document.getElementById('populate').rows[c1].cells;
  xa[0].innerHTML="&nbsp;<b>"+tstable+"</b>";
  xa[0].style.backgroundColor="#999999";
  xa[0].style.textAlign='left';
  xa[0].colSpan='8';
  c1=c1+1;
 }
//alert(4);
 lstable = tstable;
 // x1=x1+y;
  u=100*y/t1;
  u=u.toFixed(2);
  x[0].innerHTML="Loading "+y+" of "+t1+ " -- ("+(u)+"%)";
  //alert(y);

  var row = xadd.insertRow(c1);
var xa=document.getElementById('populate').rows[c1].cells;
bg1='#ffffff';
if ((y/2) == parseInt(y/2))
{
 bg1="#eeeeee";
}
for (yy=0; yy <= 7; yy++)
{
  var cellLeft = row.insertCell(0);
  xa[0].innerHTML=y+' '+yy;
  xa[0].style.backgroundColor=bg1;
}
  xa[0].style.textAlign='right';
  xa[3].style.textAlign='center';
  xa[7].style.textAlign='center';




temp1='<a target=newhoss href="onehoss.asp?lg='+league+'&hossnum='+t2a[0]+'" class="z9q1">'+t2a[0]+'</a>';

temp1=temp1+'<input type=hidden name="pw-'+y+'" value="'+t2a[10]+'">';
temp1=temp1+'<input type=hidden name="stable-'+y+'" value="'+t2a[4]+'">';
temp1=temp1+'<input type=hidden name="hname-'+y+'" value="'+t2a[1]+'">';

temp1=temp1+'<input type=hidden name="myid-'+y
temp1=temp1+'" value="'+t2a[11]+'">'
temp1=temp1+'<input type="hidden" name="h-'+y+'" '
temp1=temp1+'value="'+t2a[0]+'">'
temp1=temp1+'<span width=160 id=spanner'+y+' style="position: absolute; display:none; z-index:10;">'
temp1=temp1+'<table width=155 bgcolor=#339933 cellpadding=5 cellspacing=2><tr><td bgcolor=white>'
temp1=temp1+"Stable: <b>"+t2a[4]+"</b><br>"
temp1=temp1+t2a[3]+' year old '
sx='Male';
if (t2a[2]=='F')
{
 sx='Female';
}
temp1=temp1+sx;
if (t2a[12] > 0)
{
 temp1=temp1+"<br>Last Raced: "+t2a[12]+"<br>";
jj1=0;

jj1=(weekno-t2a[12])/7;
jj1=parseInt(jj1);
 temp1=temp1+"("+jj1+" weeks ago)"
}

temp1=temp1+'</td></tr></table>'
temp1=temp1+'</span>'
xa[0].innerHTML=temp1;
if (y==1)
{
//alert(temp1)
}

xa[1].innerHTML='<a href="#" onclick="" onmouseover="agelwsex('+y+');"  onmouseout="outagelwsex('+y+');">'+t2a[1]+'</a>';

condi="Ready to Go";
if (t2a[5]=="S") {condi="Sharp";}
if (t2a[5]=="G") {condi="Little Groggy";}
if (t2a[5]=="N") {condi="Needs Rest";}
if (t2a[5]=="L") {condi="Lay Off";}
if (t2a[5]=="I") {condi="Injured";}


xa[2].innerHTML=condi;
xa[3].innerHTML='<input type="checkbox"  id="i-'+y+'" name="i-'+y+'" value="in">';
if (y==1)
{
//alert(xa[3].innerHTML)
}
temp1='<select  id="j-'+y+'" name="j-'+y+'" size=1 onchange="checkme('+y+');">';
temp1=temp1+'<option value="-1" >Jockey Select</option>';

for (z=1; z >= 0; z=z-.1)
{
 z1=z.toFixed(2);
//alert(z1);

 z2=1*t2a[6];

 z2=z2.toFixed(2);
//alert(z2);
 temp1=temp1+'<option value="'+z1+'" ';


// alert(z1+' '+z2)
 if (z1 == z2)
 {
 // alert(temp1)
  temp1=temp1+' selected '
 }
 temp1=temp1+">";
 temp1 = temp1 +z1
if (z==1)
{
 temp1=temp1+" - Lead"
}

if (z< .01)
{
 temp1=temp1+" - Close"
}

 temp1=temp1+"</option>";

}
temp1=temp1+'</select>';

if(y==1)
{
// alert(temp1);
}

xa[4].innerHTML=temp1;


temp1='<select  id="r-'+y+'" name="r-'+y+'" size=1 onchange="checkme('+y+');">';
//temp1=temp1+'<option value="-1" >Jockey Select</option>';


for (z=1; z >= .895; z=z-.01)
{
 z1=z.toFixed(2);
//alert(z1);

 z2=1*t2a[7];

 z2=z2.toFixed(2);
//alert(z2);
 temp1=temp1+'<option value="'+z1+'" ';



 if (z1 == z2)
 {

  temp1=temp1+' selected '
 }
 temp1=temp1+">";
 temp1 = temp1 +z1
if (z==1)
{
 temp1=temp1+" - Max"
}

if (z< .905)
{
 temp1=temp1+" - Min"
}

 temp1=temp1+"</option>";

}
temp1=temp1+'</select>';

if(y==1)
{
// alert(temp1);
}


xa[5].innerHTML=temp1;
tfw=t2a[8];
temp1='<select  id="tw-'+y+'" name="tw-'+y+'" size=1 onchange="checkme('+y+');">';
temp1=temp1+'<option value="0">None Selected</option>'
temp1=temp1+'<option value="'+(weekno-7)+'" '
if ((weekno-7) == tfw)
{
 temp1=temp1+"selected"
}
temp1=temp1+'>Last Week</option>'




z2=0;
weekno=parseInt(weekno);

for (z=weekno; z <= (weekno+(7*26)); z=z+7)
{

 zx=z+"(+"+z2+" wk)";

 if (z==weekno)
{
  zx="This Week";
 }

 z2=z2+1;

 temp1=temp1+'<option value="'+z+'" ';


 if (z == tfw)
 {
  temp1=temp1+' selected ';
 }

 temp1=temp1+">";
 temp1=temp1+zx;
 temp1=temp1+"</option>";
}
temp1=temp1+'</select>';

if (y==1)
{
// alert(z);
}


xa[6].innerHTML=temp1;


temp1='<input type="checkbox"  id="safer-'+y+'" name="safer-'+y+'" ';

if (t2a[9] != '')
{
 temp1=temp1+"checked";
}
temp1=temp1+' value="a" onclick="checkme('+y+');">';
xa[7].innerHTML=temp1;






 }
 var row = xadd.deleteRow(2);

 var row = xadd.insertRow(c1);
 var cellLeft = row.insertCell(0);
 var xa=document.getElementById('populate').rows[c1].cells;
 xa[0].innerHTML='&nbsp;<input type="submit" name="prosser" value="Process changes">';
 xa[0].style.backgroundColor="#999999";
 xa[0].style.textAlign='left';
 xa[0].colSpan='8';
 xa[0].height=50;
 c1=c1+1;
}

}

function agelwsex(z)
{
    b="spanner"+z;
    var spanElm = document.getElementById(b);
    spanElm.style.display="block";
    spanElm.style.position="absolute";
    spanElm.style.visibility="visible";  
    spanElm.style.left="120px";  
}

function outagelwsex(z)
{
    b="spanner"+z;
    var spanElm = document.getElementById(b);
    spanElm.style.display="none";
    spanElm.style.visibility="hidden";  
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function loadhorse (condi,pageno)
{

var weekno=document.getElementById('weekno').value;
var lweekno=document.getElementById('LWeek').value;

cme=true;
if (pageno==0)
{
pageno=document.getElementById('onpage').value;
cme=false;
}
document.getElementById('lasttype').value=condi;
//var horsetable=document.getElementById('horsetable');
var hili=document.getElementById('hili');
//alert(2);

var hl1=document.getElementById('hili').rows[0].cells;
hlme=-1;

for (x=0; x<5; x++)
{
 hl1[x].style.backgroundColor="#333333";
}

if (condi=='sharp'){
hlme=0;
lat="S";
}

if (condi=='rtg'){
hlme=1;
lat="R";
}
if (condi=='groggy'){
hlme=2;
lat="G";
}
if (condi=='rest'){
hlme=3;
lat="N";
}
if (condi=='offinj'){
hlme=4;
lat="I";
}


 if (hlme >= 0)
{
 hl1[hlme].style.backgroundColor="#336633";
}

pager1=(pageno-1)*10+1;

x1=0;

zcount=document.getElementById(condi+"count").value;


for (x=pager1; x < (pager1+10); x++)
{
x1=x1+1;
//alert(pager1);
col1='';
col2='';//'&nbsp;';
col3='&nbsp;';
col4='&nbsp;';
col5='&nbsp;';

z1=condi+x;
savepop=z1;

    var ht1=document.getElementById('horsetable').rows[x1+1].cells;
     ht1[3].className=''; 
     ht1[4].className=''; 

if ((document.getElementById(z1) != null)){


var mhoss=document.getElementById(z1).value;

mhossa=mhoss.split("!");
col1='&nbsp;<a class="lookhoss" onmouseover="this.className=\'flyOverlookhoss\'" onmouseout="this.className=\'lookhoss\'" onclick="pophorse(\''+z1+'\');">'+mhossa[1]+'</a>';
//alert(col1);

if (0==(mhossa[8]-lweekno))
{
 col3=col3+"T";
}
else
{
 col3=col3+" ";
}
//alert(mhossa[12]);

l1a = (weekno-mhossa[12]);


if ((13 >= l1a) && (l1a >= 7))
{
 col3=col3+"L";
}
if (6 >= (weekno-mhossa[12])) 
{
 col3=col3+"R";
}

if (l1a >= 14) 
{
 col3=col3+" ";
}


    var lhid=mhossa[0];
    sme=trim('s1-'+trim(lhid));
    sme1=Get_Cookie(sme);

    smea=trim('s2-'+trim(lhid));
    sme2=Get_Cookie(smea);
//alert(sme1+"*"+sme2);

//alert(sme+" "+sme1);
    if (isNull(sme1))
{
sme1='';
}
    if (isNull(sme2))
{
sme2='';
}



    if ((sme1 != '')  && (sme1 != '0'))
    {
//     alert("sme1"+sme1)
     myrid=Get_Cookie(trim("zs1-"+trim(lhid)));
     temp1="";
     temp1='<span width=280 id=z1spanner'+x1+' style="position: absolute; display:none; z-index:10;">';
     temp1=temp1+'<table width=275 bgcolor=#333333 cellpadding=5 cellspacing=1><tr><td bgcolor=white>';
     //temp1=temp1+"Race : <b>"+zzxa[10]+"</b><br>"
     rr1=document.getElementById('r'+myrid).value;
     rrs=rr1.split("!")
temp1a="Track : <b>"+rrs[0]+"</b><bR>"
temp1a=temp1a+"Race Number : <b>"+rrs[10]+"</b><bR>"
if (rrs[9] != '')
{
 temp1a=temp1a+rrs[9]+"<br>"
}
     temp1a=temp1a+rtfig(rrs[1]);
if (rrs[2]!=0)
{
 temp1a=temp1a+"($"+rrs[2]+")"
}

temp1a=temp1a+" "+rrs[3]+"<br>" ;
temp1a=temp1a+rrs[5]+" Furlongs on the "+tfig(rrs[6])+"<br>";
temp1a=temp1a+sexfig(rrs[7])+"<br>";
temp1a=temp1a+"Aprox Purse : $"+rrs[8]
     temp1=temp1+temp1a;
     temp1=temp1+'</td></tr></table>';
     temp1=temp1+'</span>';
     col4=temp1+'<a class=smallerUL href="#"  onmouseover="showspan('+x1+',\'z1\');" onmouseout="hidespan('+x1+',\'z1\');" onclick="assignme(\'\',\''+sme+'\',0)";>X-1</a>';
     ht1[3].className='hossbgpend';     
 //   alert(col4);
    }

    if ((sme2 != '')  && (sme2 != '0'))
    {
     myrid=Get_Cookie(trim("zs2-"+trim(lhid)));
//alert(myrid);
     temp1="";
     temp1='<span width=280 id=z2spanner'+x1+' style="position: absolute; display:none; z-index:10;">';
     temp1=temp1+'<table width=275 bgcolor=#333333 cellpadding=5 cellspacing=1><tr><td bgcolor=white>';
     //temp1=temp1+"Race : <b>"+zzxa[10]+"</b><br>"
     rr1=document.getElementById('r'+myrid).value;
     rrs=rr1.split("!")
temp1a="Track : <b>"+rrs[0]+"</b><bR>"
temp1a=temp1a+"Race Number : <b>"+rrs[10]+"</b><bR>"
if (rrs[9] != '')
{
 temp1a=temp1a+rrs[9]+"<br>"
}
     temp1a=temp1a+rtfig(rrs[1]);
if (rrs[2]!=0)
{
 temp1a=temp1a+"($"+rrs[2]+")"
}

temp1a=temp1a+" "+rrs[3]+"<br>" ;
temp1a=temp1a+rrs[5]+" Furlongs on the "+tfig(rrs[6])+"<br>";
temp1a=temp1a+sexfig(rrs[7])+"<br>";
temp1a=temp1a+"Aprox Purse : $"+rrs[8]
     temp1=temp1+temp1a;
     temp1=temp1+'</td></tr></table>';
     temp1=temp1+'</span>';
     col5=temp1+'<a class=smallerUL href="#"  onmouseover="showspan('+x1+',\'z2\');" onmouseout="hidespan('+x1+',\'z2\');" onclick="assignme(\'\',\''+smea+'\',0);">X-2</a>';
//     col5='<a class=smallerUL href="#" onclick="assignme(\'\',\''+smea+'\',0)";>X-2</a>';
     ht1[4].className='hossbgpend'; 
    }




//col1="0";
//alert(col1);
}

if ((zcount == 0) && (x1==1))
{
 col1="&nbsp;<b>No Horses Listed!</b>"
}

ht1[0].innerHTML=col1;
ht1[1].innerHTML=col2;
ht1[2].innerHTML=col3;
ht1[3].innerHTML=col4;
ht1[4].innerHTML=col5;
//alert(col4);

}
//alert(cme);

if (cme)
{
z1='<select id="onpage" name="onpage" onkeyup=\"this.blur(); this.focus();\" onclick="loadhorse(\''+condi+'\',0);" onchange="loadhorse(\''+condi+'\',0);">';
//alert(z1)
za=1
for(z=1; z<=zcount; z=z+10)
{
z1=z1+'<option value="'+za+'">'+za;
za=za+1;

}
z1=z1+'</select>';
var ht1=document.getElementById('pagerow').rows[0].cells;
ht1[1].innerHTML=z1;


}

}


function pophorse(horse)
{

if (horse == "*")
{
 horse=document.getElementById('lasthorse').value;
}

  var iframez=document.getElementById('iframeable').rows[0].cells;
  var cv1=document.getElementById(horse).value;
  cv2=cv1.split("!");
//cv[0];
  var xa=document.getElementById('horsename').rows[0].cells;
  xa[0].innerHTML="&nbsp;<b>PLEASE WAIT.. POPULATING RACES...</b>";
  setTimeout("postpophorse('"+horse+"')",1);
  ggg="<iframe frameborder=0 width=777 height=675 src='./prettyhorse.asp?hid="+cv2[0]+"'></html>";
  iframez[0].innerHTML=ggg;
}


function pophorseb(x,y)
{
  var xa=document.getElementById('horsename').rows[0].cells;
  xa[0].innerHTML="&nbsp;<b>PLEASE WAIT.. POPULATING RACES... ("+x+" of "+y+")</b>";
//  alert(x);
}


function postpophorse(horse)
{
//  alert(horse);
  document.getElementById("lasthorse").value=horse;

  var xa=document.getElementById('horsename').rows[0].cells;
  thorse=document.getElementById(horse).value;
  tsplit=thorse.split("!");
  document.getElementById('lasthorseid').value=tsplit[0];

  rc=document.getElementById('rcount').value;
  ocount=0;
  goodrace="!"
  otpall="!"
  trvcostall="!"
  fromtrack=tsplit[9];
  fromtrack=fromtrack-parseInt(fromtrack);
  fromtrack=parseInt(fromtrack*100);
  trkmat=document.getElementById('trkmat').value;
  tr1=trkmat.indexOf("^"+fromtrack+"~")
  frt1a=-9999
  frt1b=-9999
  if (tr1 >= 0)
  {
   trs=trkmat.substr(tr1,100);
   trs2=trs.split("~");
   frt1a=trs2[3];
   frt1b=trs2[4];
  } 
//  alert(frt1a+","+frt1b+","+fromtrack)


  for (t=1; t<= rc; t++)
  {

   trace = document.getElementById('r'+t).value;
   trsplit=trace.split("!");
//check order : versus winners (vw), sex (sexer)

   keepme=false;
   c1=document.getElementById('vw').value;
   c2=trsplit[1];
   c3=tsplit[14];
   if ( ((c2.substr(0,1)=='M') && (c3==0)) || ((c2.substr(0,1) != 'M') && ((c1 == 'W') || (c3 > 0))))
   {
    keepme = true;
   }

if (keepme)
{
   keepme=false;
   c1=document.getElementById('sexer').value;
   c2=trsplit[7];
   c3=tsplit[2];
   if ((c2==c3) || ((c1=="A") && (c3=='F')))
   {
    keepme = true;
   }
}


//if (t==2)
//{
// alert(keepme+","+c1+","+c2)
//}


//turf or dirt
if (keepme)
{
keepme=false;
   c1=document.getElementById('trk').value;
   c2=trsplit[6];
   if ((c2 == c1) || (c1 == "A"))
   {
    keepme=true;
   }
}


//my sex
if (keepme)
{
   keepme=false;
//   c1=document.getElementById('sexer').value;
   c2=trsplit[4];
   c3=tsplit[3];
   h1=c2.substr(0,1);
   h2=h1;
   if (c2.indexOf("+") >= 0)
   {
    h2=99;
   }
   c3a=1*c3;

   if ((c3a >= h1) && ((c3a <= h2) || (c2.indexOf(c3) >= 0)))
   {
    keepme=true;
   }
}


//distance
if (keepme)
{
 keepme=false;
 c1=document.getElementById('ldist').value;
 c1a=document.getElementById('hdist').value;   
 c2=trsplit[5];
 c1=parseInt(c1*1000);
 c2=parseInt(c2*1000);
 c1a=parseInt(c1a*1000);
 if (c1 > c1a)
 {
  c1b = c1a;
  c1a = c1;
  c1 = c1b; 
 }

 if ((c2 >= c1) && (c2 <= c1a))
 {
  keepme=true;
 }
} 




//race type
c1=document.getElementById('rtype').value;
c2=trsplit[1];
carryover=c2;

if (keepme) 
{
 keepme=false;
 if ((c1.indexOf('A') >= 0) &&  (((c2.indexOf('M') >=0) && (c2.indexOf('C') == -1)) || (c2.indexOf('A') == 0)))
 {
  keepme=true;
 }
 if ((c1.indexOf('K') >= 0) && ((c2.indexOf('ST') == 0) || (c2.indexOf('G') == 0)))
 {
  keepme=true;
 }
 if ((c1.indexOf('G') >= 0) && (c2.indexOf('G') == 0))
 {
  keepme=true;
 }
 if ((c1.indexOf('C') >=0) && (c2.indexOf('C') >=0))
 {
  keepme=true;
 }
 if ((c1.indexOf('S') >=0) && (c2=='S'))
 {
  c3=tsplit[7];
  keepme=true;
 }
}



if ((keepme) && ((c2=='S') || (c2.indexOf('C') >=0) ))
{
 //keepme=false;
 //C1=from doucument, c2=trackfo
 if (keepme)
 {
  c1a=document.getElementById('ctag').value;
  c2a=trsplit[2];
  c1x=c1a.substr(0,1);
  c1y=c1a.substr(1,2);

  if (c1y.substr(0,1) == ' ')
  {
   c1y=c1y.substr(1,2);
  }
  c1y=c1y*1000;

  c3=1*c3;
  if ((c3 > c2a) || (c3 == 0))
  {
   keepme = false
  }

  if (c1x==">")
  {
   c1y=-c1y;
   c2a=(-1)*c2a;

  }

//if (c2a==125000)
//{
// alert(c1a+"x"+c2a+"x"+c1x+"x"+c1y);
//}

  if (c2a > c1y)
  {
   keepme = false;
  }
  
 }


}

 





if (keepme)
{
keepme = false;
c2=trim(trsplit[3]);
if (c2=='')
{
 keepme = true
}

if (c2 != "")
{
 c2=c2+'    ';
 c2a=c2.substr(0,1);
 if (c2a == '*')
 {
  mycpu=1*tsplit[6];
  checkcpu=1*trim(c2.substr(1,3));
  if ((mycpu <= checkcpu) && (tsplit[13] >= 6))
  {
   keepme=true;
  }
 }


 if (c2a == "(")
 {
  c2b=c2.substr(1,1);
  
  if (c2b=='T')
  {
   lasttrack=tsplit[9];
   thistrack=trsplit[10];
   lta=parseInt(100*(lasttrack-parseInt(lasttrack)));
   tta=parseInt(100*(thistrack-parseInt(thistrack)));
   //alert(lta+","+tta);
   if (lta == tta)
   {
    keepme=true;
   }
  }
 }



 if (c2a == 'N')
 {
  c2b=c2.substr(3,1);
  switch (c2b) {
   case 'L': lfield=14; break;
   case 'X': lfield=15; break;
   case 't': lfield=16; break;
   case 's': lfield=17; break;
   case 'n': lfield=18; break;
   case 'y': lfield=19; break;
   default: lfield=14;
  }
  mywins=tsplit[lfield];
  c2c=c2.substr(2,1);
  if (c2c > mywins)
  {
   keepme=true;
  }
 }
}

}

if (keepme) 
{
 gag1=0;
 keepme=false;
 c1=trsplit[10];
 c1z=parseInt(c1);
 c1a=c1-c1z;
 c1a=parseInt(c1a*100);
 tr1=trkmat.indexOf("^"+c1a+"~")
 //alert(tr1);

 if (tr1 >= 0)
 {
  trs=trkmat.substr(tr1,100);
  trs2=trs.split("~");
  trs2a=trs2[3];
  trs2b=trs2[4];
 } 
 tcosta = 0; tcostb=0;
 if ((frt1a > -9999) && (frt1b > -9999))
 {
  m1=frt1a - trs2a;
  m2=frt1b - trs2b;
  m3=(m1*m1)+(m2*m2);
  m3=Math.sqrt(m3);
  m3=Math.pow(m3,1.5);  
  m3=20+parseInt(m3/10)*10;
  tcosta=m3;
//  tcosta = parseInt((20 + (((m1*m1) + (m2*m2)) ^ 0.5) ^ 1.5) / 10) * 10;
  if(c1a == 3)
  {
//   alert((m1*m1)+","+frt1a+","+frt1b+"-"+trs2a+","+trs2b+"-"+tcosta)
  }



  if (Math.abs(c1a-fromtrack) < .1) 
  {
   tcosta=0;
   tcostb=0;
  }
  gag1 = parseInt(Math.pow(1+ Math.pow(tcosta/200, 1.08),.73)-1);

//parseInt((1 + (tcosta / 200) ^ 1.08) ^ 0.73 - 1)
  if (gag1 >3)
  { 
   gag1=parseInt(3+Math.pow((tcosta-1231)/150,1.5));
  }
  if (fromtrack== 0) 
  {
   gag1=0
   tcosta=0
  }
 }
 tcostb=gag1;
 if (tcostb > 20)
 {
  tcostb=20; gag1=20;
 }

 if ((frt1a >= 200) && (frt1b >= 200))
 {
  gtest=((trs2a >= 200) && (trs2b >= 200));
  if (gtest != true)
  {
   tcosta=10000; tcostb="All"; gag1=99;
  }
 }
  if ((frt1a <= 200) && (frt1b <= 200))
 {
  gtest=((trs2a <= 200) && (trs2b <= 200));
  if (gtest != true)
  {
   tcosta=10000; tcostb="All"; gag1=99;
  }
 }
 if (Math.abs(c1a-fromtrack) < .1) 
 {
  tcosta="--";
 }


 if (carryover.substr(0,1)=='G')
 {
  gag1=0; tcostb="--";
 }

 purse1=trsplit[8].length;

 if ((carryover=='ST') && (purse1 >= 4)) //ultimately make this ALL 100K races and above
 {
  gag1=0; tcostb="--";
 }
 bpcost=1*document.getElementById('bp').value;
 if (bpcost >= gag1)
 {
  keepme = true;
 }

 }
 if (keepme) 
 {
  c1b="!"+c1z+"~"+c1a+"^";
  weather=document.getElementById('weather').value;
  c1c=weather.indexOf(c1b);
  if (c1c >=0)
  {
   c1d=weather.substr(c1c,20);
   c1d1=c1d.split("^");
   c1d2=c1d1[1].split("!");
   c1d3=1*c1d2[0];
   otp=document.getElementById('otp').value;
   otp1=otp.substr(0,1);
   otp=1*trim(otp.substr(1,2));
   otpp=c1d3+"%";
   if (otp1 == ">")
   {
    otp=-otp;
    c1d3=-c1d3;
   }    
   if (otp >= c1d3)
   {
    keepme=true;
   }
  }
 }



 if (keepme)
 {
  ocount=ocount+1;
  goodrace=goodrace+t+"!"; //trsplit[10]
  otpall=otpall+otpp+"!";
  trvcostall=trvcostall+tcosta+"("+tcostb+")!";
 }
}

  document.getElementById('goodracecount').value=ocount;
  document.getElementById('goodrace').value=goodrace;
  document.getElementById('otpall').value=otpall;
  document.getElementById('trvcostall').value=trvcostall;
  listraces(1);
  xa[0].innerHTML="&nbsp;<b>"+tsplit[1]+"</b>";
  z="<select id=\"raceonpage\" onchange='listraces(0);'>"
  z='<select id=\"raceonpage\" onkeyup=\"this.blur(); this.focus();\" onclick="listraces(0);" onchange="listraces(0);">'
  cc2=1
  for (cc=1; cc <=ocount; cc=cc+9)
  {
//   alert(cc);
   z=z+"<option value='"+cc2+"'>"+cc2;
   cc2=cc2+1;
  }
  z=z+"</select>"
  xa[2].innerHTML=z;
}

function listraces(g)
{ 
  ndatex = new Date("July 22, 1998")
  weekDayName = new Array ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
  //alert(g);
  if (g==0)
  {
   g=document.getElementById('raceonpage').value;
  }
  goodrace=document.getElementById('goodrace').value;
  otpall=document.getElementById('otpall').value;
  trvcostall=document.getElementById('trvcostall').value;
  ocount=document.getElementById('goodracecount').value;
  glsplit=goodrace.split("!");
  otpsplit=otpall.split("!");
  trvsplit=trvcostall.split("!");
  oo=0;
  for (t=1+(g-1)*9; t<= (g*9); t++)  
  {
   oo=oo+1;
 // alert(t);
   var xa1=document.getElementById('racetable').rows[oo+1].cells;
   for (hh=0; hh<=10; hh++)
   { 
    for (hh=0; hh<11;hh++)
{
    xa1[hh].innerHTML = "&nbsp;";
    xa1[hh].className = "normaler";
} 
  }


   if (t <= ocount)
   {
    zzx=document.getElementById("r"+glsplit[t]).value;
    zzxa=zzx.split("!");
    surfer="dirter";
    if (zzxa[6] == "T")
    {
     surfer="turfer";
    }
temp1=""

ndatez=parseInt(zzxa[10]);
ndatey = ndatex.getTime();
ndatey = ndatey+(ndatez*3600*1000*24);
ndateya = new Date(ndatey);

nd1=weekDayName[ndateya.getDay()]
//alert(nd1);
nd2=leadingZero(1+ndateya.getMonth())+"/"+leadingZero(ndateya.getDate())+"/"+(ndateya.getYear()+1900)

temp1=temp1+'<span width=480 id=spanner'+oo+' style="position: absolute; display:none; z-index:10;">'
temp1=temp1+'<table width=475 bgcolor=#333333 cellpadding=5 cellspacing=1>'

nameb4="Name : "
temp3=zzxa[9].toLowerCase();
temp2=temp3.indexOf("href");
if (temp2 >= 0 )
{
 temp1=temp1+"<tr>";
 temp1=temp1+"<td bgcolor=#333333 width=\"95%\"><font color=white>&nbsp;<b>(Click the X to close this box)</b></font></td><td bgcolor=white align=center><a onclick='hidespan("+oo+",\"\");'><b>X</b></a></td>";
 temp1=temp1+"</tr>";
 temp3a = /\_parent/gi;
 zzxa[9] = zzxa[9].replace(temp3a,'newwindow');
 if (temp3.indexOf('img src') >= 0)
 {
  nameb4 = '<br>';
 }


}

temp1=temp1+'<tr><td colspan=2 bgcolor=white>'
temp1=temp1+"Date : <b>"+nd2+"</b><br>"
temp1=temp1+"Race : <b>"+zzxa[10]+"</b><br>"
if ((zzxa[2] != "0") && (1==0))
{
temp1=temp1+"Tag : <b>"+zzxa[2]+"</b><br>"
}
if (zzxa[9] != "")
{
temp1=temp1+nameb4+"<b>"+zzxa[9]+"</b><br>"
}
temp1=temp1+'</td></tr>'
temp1=temp1+'</table>'
temp1=temp1+'</span>'


if (zzxa[2] > 0)
{
 zzxa[1]=zzxa[1]+" <a class=smaller>($"+zzxa[2]+")</a>"
}




intozz="\&nbsp;<a class=lrace onmouseover='showspan("+oo+",\"\");' onmouseout='hidespan("+oo+",\"\");'>"+nd1+"</a>"+temp1;

if (zzxa[9].indexOf("href") >= 0 )
{
 intozz = "\&nbsp;<a  class=lrace onmouseover='showspan("+oo+",\"\");'>"+nd1+"</a>"+temp1;
}




    xa1[0].innerHTML = intozz;
    xa1[1].innerHTML = "&nbsp;"+zzxa[0];
    xa1[2].innerHTML = "&nbsp;"+zzxa[1];
    xa1[3].innerHTML = "&nbsp;"+zzxa[3];
    xa1[4].innerHTML = zzxa[4]+"&nbsp;";
    xa1[5].innerHTML = zzxa[5]+"&nbsp;";
    xa1[6].innerHTML = zzxa[7]+"&nbsp;";
    xa1[7].innerHTML = zzxa[8]+"&nbsp;";
    xa1[8].innerHTML = "<a class=smaller>"+otpsplit[t]+"</a>&nbsp;";
    xa1[9].innerHTML = "&nbsp;<a class=smaller>"+trvsplit[t]+"</a>&nbsp;";





for (hh=0;hh <=10; hh++)
{
    xa1[hh].className = surfer;
}


if (zzxa[9].indexOf("RESTRICTED") >= 0 )
{ 
   xa1[0].className = "restrictor";

   xa1[1].className = "restrictor";

   xa1[2].className = "restrictor";
}


//this is where we check for entries already

    mm1=zzxa[10];
    var lhid=document.getElementById('lasthorseid').value;
    sme=trim('s1-'+trim(lhid));
    sme1=Get_Cookie(sme);
    smea=trim('s2-'+trim(lhid));
    sme2=Get_Cookie(smea);
//    alert(sme+" "+sme1);

    if ((sme1 == mm1) || (sme2 == mm1))
    {
     xa1[10].className="flagger";
//   alert(sme1);
    }

    mm2='<a class=smallerUL href="#" onclick="assignme(\''+mm1+'\',\''+sme+'\','+glsplit[t]+')";>1</a>';
    mm2=mm2+' ';
    mm2=mm2+'<a class=smallerUL href="#" onclick="assignme(\''+mm1+'\',\''+smea+'\','+glsplit[t]+')";>2</a>';

if (sme1 == mm1)
{
  mm2='<a class=smallerUL href="#" onclick="assignme(\'\',\''+sme+'\',0)";>X-1</a>';
}

if (sme2 == mm1)
{
    mm2='<a class=smallerUL href="#" onclick="assignme(\'\',\''+smea+'\',0)";>X-2</a>';

}


    xa1[10].innerHTML = mm2+"&nbsp;"; //"??"+"&nbsp;";







   } 
  }

}


function assignme(x,y,z)
{
 //alert(x+","+y+","+z);
 Set_Cookie( y, x, 30, '/', '', '' );
 Set_Cookie( "z"+y, z, 30, '/', '', '' );
 y1=trim(y.substr(3,100));
 x2=document.getElementById('lasttype').value;
 y2=document.getElementById('lasthorseid').value;
 if (y2 != '')
 {
//  alert(y2);
// document.getElementById('lasthorseid').value=y1;
  listraces(0);
 }

 loadhorse(x2,0);
//  
// alert("Set!");
}

function showspan(z,z1)
{
   //alert("OK");
    mousexa = tempX; //document.getElementById('mousex').value;
    mouseya = tempY; //document.getElementById('mousey').value;
   //alert(mousex+","+mousey)
    b=z1+"spanner"+z;
    var spanElm = document.getElementById(b);
//alert(spanElm);
    zzz=140+(z-1)*21;
if ((z1=="z1") || (z1=="z2"))
{
    zzz=90+(z-1)*21;
}
    spanElm.style.display="block";
    spanElm.style.position="absolute";
    spanElm.style.visibility="visible";  
    spanElm.style.left="280px";  
    spanElm.style.top=zzz;
    //alert(zzz)
if (z1=="LH") //Race info
{
 

    zzz=(parseInt(mousexa)-200)+"px";
    zzza=(parseInt(mouseya)+15)+"px";
    spanElm.style.left=zzz;  
    spanElm.style.top=zzza;
//alert(zzza+","+zzz)
}

if ((z1=="LHA") || (z1=="LHX")) //Call Info
{
    zzz=(parseInt(mousexa)-250)+"px";
    zzza=(parseInt(mouseya)-75)+"px";
    spanElm.style.left=zzz;  
    spanElm.style.top=zzza;
}

if ((z1=="LHB") || (z1=="LHXA")) // Jockey
{
    zzz=(parseInt(mousexa)-600)+"px";
    zzza=(parseInt(mouseya)-125)+"px";
    spanElm.style.left=zzz;  
    spanElm.style.top=zzza;

}


if (z1=="LHC") //oldresults
{

    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left="0px";  
    spanElm.style.top=mouseyb+"px";

}


if (z1=="PED")
{

    zz=120+(z-1)*25;
    zzz=zz+"px";
    spanElm.style.left="125px";  
    spanElm.style.top="55px";

}


if ((z1=="LHQ") || (z1=="LHD")) // Track
{
    zzz=(parseInt(mousexa)+15)+"px";
    zzza=(parseInt(mouseya)-15)+"px";
    spanElm.style.left=zzz;  
    spanElm.style.top=zzza;
}


if ((z1=="RH") || (z1=="RHZZ"))
{
    zz=10+(z-1)*25;
    zzz=zz+"px";
    spanElm.style.left="300px";  
    spanElm.style.top=zzz;
}

if ((z1=="RHD1") || (z1=="RHD"))
{
    zz=10+(z-1)*25;
    zzz=zz+"px";
    spanElm.style.left="120px";  
    spanElm.style.top=zzz;
}



if ((z1=="RNK") || (z1=="RNKA"))
{
    zz=105;
    zzz=zz+"px";
    spanElm.style.left="410px";  
    spanElm.style.top=zzz;
}

}

function hidespan(z,z1)
{
    b=z1+"spanner"+z;
    var spanElm = document.getElementById(b);
    spanElm.style.display="none";
    spanElm.style.visibility="hidden";  
}


function loadframespan(a,b,c)
{
  var iframez=document.getElementById(a+"Table"+b).rows[1].cells;
  ggg="<iframe frameborder=0 width=740 height=450 src='"+c+"'></html>";
  iframez[0].innerHTML=ggg;
}

function rtfig(a)
{ 
 b="Starter";
 c="";
 if (a.indexOf("M") == 0)
 {
  c="Maiden ";
  b="Maiden Allowance";
 }
 if (a.indexOf("C") >= 0)
 {
  b=c+"Claim ";
 }
 if (a.indexOf("A") == 0)
 {
  b="Allowance";
 }
 if (a.indexOf("G") == 0)
 {
  b="Grade "+a.substr(1,1);
 }
 if (a.indexOf("ST") == 0)
 {
  b="Stakes";
 }
 return b;

}
function tfig(a)
{
 b="Dirt";
 if (a=="T") {b="Turf";}
 return b;
}

function sexfig(a)
{
 b="Open to all horses";
 if (a=="F") {b="Fillies Only";}
 return b;
}