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;
}


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 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];
sx='Male';
if (t2a[2]=='F')
{
 sx='Female';
}

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";}

 if (roby == 'bycondo')
{
  tstable = condi;
}
 if (roby == 'bysex')
{
  tstable = sx;
}
 if (roby == 'byage')
{
  tstable = t2a[3]+" year olds";
}
 tfww="Week "+t2a[8];
 if (t2a[8] == 0)
 {
  tfww="N/A"
 }

 if (t2a[8] == weekno)
 {
  tfww="This Week"
 }

 if ((parseInt(t2a[8])+7) == weekno)
 {
  tfww="Last Week"
 }

 if (roby == 'byweek')
{
 tstable=tfww;
 if (tfww=="N/A")
{
 tstable="None Selected"
}
}
//tfww="N/A for now";
//alert(2);
 if ((tstable != lstable) && ((roby =="bystable") || (roby=="byweek")|| (roby=="bycondo")|| (roby=="byage")|| (roby=="bysex"))) 
 {
//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='12';
  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 <= 11; yy++)
{
  var cellLeft = row.insertCell(0);
  xa[0].innerHTML=y+' '+yy;
  xa[0].style.backgroundColor=bg1;
  xa[0].className="TypicalTable";
}
  xa[0].className="smaller";
  xa[0].noWrap=true;
  xa[0].height="25";
  xa[0].noWrap=true;
  xa[2].noWrap=true;
  xa[10].noWrap=true;
  xa[11].noWrap=true;
  xa[0].style.textAlign='center';
  xa[1].style.textAlign='right';
  xa[3].style.textAlign='left';
  xa[4].style.textAlign='right';
  xa[5].style.textAlign='right';
  xa[6].style.textAlign='right';
  xa[7].style.textAlign='right';
  xa[8].style.textAlign='right';
  xa[9].style.textAlign='right';
  xa[3].className="smallrtg";
  for (r=3; r<=11; r++)
  {
   xa[r].className="smaller";
  }



//temp1='<a target=newhoss href="onehoss.asp?lg='+league+'&hossnum='+t2a[0]+'" class="rafi">'+t2a[0]+'</a>';
temp1="<a class=\"rafi\"   onmouseover=\"this.className='rafiover'\" onmouseout=\"this.className='rafi'\" onclick=\"showspan(1,'LHC'); loadframespan('LHC',1,'./prettyhorse.asp?hid="+t2a[0]+"');\" target=\"newwin\">"+t2a[0]+"</a>"
//alert(temp1)
//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=460 id=spanner'+y+' style="position: absolute; display:none; z-index:10;">'
temp1=temp1+'<table width=455 bgcolor=#339933 cellpadding=5 cellspacing=2><tr><td bgcolor=white>'
temp1=temp1+"<b>"+t2a[1]+"</b><br>";
t11s=t2a[9].split("|");
temp1=temp1+t11s[0]+" x "+t11s[1]+" x "+t11s[2]+"<br><br>"
temp1=temp1+"Stable: <b>"+t2a[4]+"</b>"
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+'<br><br></td></tr></table>'
temp1=temp1+'</span>'
 xa[0].innerHTML=""

if (t2a[10] != '')
{
 condia=condi;
 master=document.getElementById('mstab').value;
 subst=t2a[4];
 cc="<a target=nnw class=rafi href='eh1.asp?tfw="+t2a[8]+"&condi="+condia+"&master="+master+"&name="+subst+"&passcode="+t2a[10]+"&hossnum="+t2a[0]+"&idno="+t2a[11]+"'>";
 //cc=cc+"Rafi</a> / ";
 cc=cc+"<a  target=nnw class=rafi href='eh1.asp?whereto=bidbuy&tfw="+t2a[8]+"&mitr="+t2a[14]+"&condi="+condia+"&master="+master+"&name="+subst+"&passcode="+t2a[10]+"&hossnum="+t2a[0]+"&idno="+t2a[11]+"'>";
 cc=cc+"Bid</a> ";
 xa[0].innerHTML=cc;
}

xa[1].innerHTML=temp1;
if (y==1)
{
//alert(temp1)
}

xa[2].innerHTML='<a class=rafi href="#" onclick="" onmouseover="agelwsex('+y+');"  onmouseout="outagelwsex('+y+');">'+t2a[1]+'</a>';
xa[4].innerHTML=t2a[3]+"&nbsp;";
xa[3].innerHTML=sx;
t2as=t2a[6].split("|");
xa[10].innerHTML=condi;
xa[5].innerHTML=t2as[0]+"&nbsp;";
xa[6].innerHTML=t2as[1]+"&nbsp;";
xa[7].innerHTML=t2as[2]+"&nbsp;";
xa[8].innerHTML=t2as[3]+"&nbsp;";
xa[9].innerHTML=t2a[7]+"&nbsp;";
xa[11].innerHTML=tfww;

z2=0;
weekno=parseInt(weekno);

}
 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='12';
// 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="200px";  
}

function outagelwsex(z)
{
    b="spanner"+z;
    var spanElm = document.getElementById(b);
    spanElm.style.display="none";
    spanElm.style.visibility="hidden";  
}

function showspan(z,z1)
{
    mousexa = tempX; //document.getElementById('mousex').value;
    mouseya = tempY; //document.getElementById('mousey').value;
    b=z1+"spanner"+z;
    var spanElm = document.getElementById(b);

    spanElm.style.display="block";
    spanElm.style.position="absolute";
    spanElm.style.visibility="visible";  


if (z1=="LHC") //oldresults
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left="5px";  
    spanElm.style.top=(mouseya+5)+"px"; //+"px";
}

if (z1=="Silks") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa-100)+"px"; //+"px";
    spanElm.style.top=(mouseya+15)+"px"; //+"px";
}

if (z1=="SName") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa-100)+"px"; //+"px";
    spanElm.style.top=(mouseya+15)+"px"; //+"px";
}


if (z1=="GName") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa-100)+"px"; //+"px";
    spanElm.style.top=(mouseya+15)+"px"; //+"px";
}
if (z1=="note") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa+15)+"px"; //+"px";
    spanElm.style.top=(mouseya+15)+"px"; //+"px";
}

if (z1=="pic") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa-250)+"px"; //+"px";
    spanElm.style.top=(mouseya+15)+"px"; //+"px";
}

if (z1=="remover") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa+30)+"px"; //+"px";
    spanElm.style.top=(mouseya-120)+"px"; //+"px";
}

if (z1=="masterremover") 
{
    zz=120+(z-1)*25;
    zzz=zz+"px";
    mouseyb=5+parseInt((mouseya-220)/220)*220;
    spanElm.style.left=(mousexa+30)+"px"; //+"px";
    spanElm.style.top=(mouseya-140)+"px"; //+"px";
}

}

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=780 height=600 src='"+c+"'></html>";
  iframez[0].innerHTML=ggg;

}

function popremover(a,b)
{
 var x=document.getElementById('removertable').rows[0].cells;
 x[0].innerHTML='Stable : <b>'+a+'</b>';
 document.getElementById('remover').value = a;
 document.getElementById('removerauth').value = b;
 b="masterremoverspanner1";
 var spanElm = document.getElementById(b);
 spanElm.style.display="none";
 spanElm.style.visibility="hidden"; 
}

function popmasterremover(a,b)
{
 var x=document.getElementById('masterremovertable').rows[0].cells;
 x[0].innerHTML='Stable : <b>'+a+'</b>';
 document.getElementById('masterremover').value = a;
 document.getElementById('masterremoverauth').value = b;

 b="removerspanner1";
 var spanElm = document.getElementById(b);
 spanElm.style.display="none";
 spanElm.style.visibility="hidden"; 
// alert(document.getElementById('masterremoverauth').value);
 //alert(1)
}
