//SCRIPT FILE CONTAINING FUNCTIONS AND DATA FOR BRISTOL HASH SITE RUN LISTS (c) Martin Wolff 2001/2

function displine(hash,display,stats,call,run,rdate,dateaddnl,venue,hare,gride,gridn,scale,ospref,backcol,printline)
{
if (display.indexOf(hash) < 0 && display != "A")
// display is page calling this function, hash is the one-character code (B,G, K or S) in bh3list.js
{
return;
}
			

var homepage=0; 
	
if (display=="BGKS")
	{
	 homepage	= 1;
	 //var d1		= rdate;
	 var d_start= new Date();
	 d_start.setDate(d_start.getDate()-1);
	 var d_end	= new Date();
	 d_end.setDate(d_end.getDate()+6);
	 rundate	= new Date(parseInt(rdate.substring(6,8),10)+2000,parseInt(rdate.substr(3,5),10)-1,parseInt(rdate.substr(0,2),10));	 
//document.write(d_start+'  '+rundate+'<p>');
   if (rundate <= d_end && rundate >= d_start )
	 {										 
	 var hashname= "";
	 if (hash=="K")
	  {
	  hashname	= "Kennet and Avon HHH";
	  hashlink	= "kahruns.php";
	  }
	 if (hash=="G")
	  {
	  hashname	= "Bristol Greyhound HHH";
	  hashlink	= "bghruns.php";
	  }
	 if (hash=="B")
	  {
	  hashname	= "Bristol HHH";
	  hashlink	= "bh3runs.php";
	  } 
 	 if (hash=="S")
	  {
	  hashname	= "Bogs of Somerset HHH";
	  hashlink	= "bogsruns.php";
	  } 
	  
	 d_days		= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	 d_months 	= new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 
	if (rundate.getDate() == d_start.getDate()+1)
	{
	var d_date = '<span style="color:Blue"><B>Today</B><span>';
	}
	else
	{
	var d_date	= '<b>'+d_days[rundate.getDay()]+'</b>, '+rundate.getDate()+' '+d_months[rundate.getMonth()];	
	}
	if (dateaddnl != "")
	{
	venue = venue +" <b><i>NB: "+dateaddnl+".</i></b>";
	}	
	if (call == "f")
	{
	var m_more = '';
	}	
	else
	{			
	var m_more='~<b>more</b>~';
	}
		 document.write('<tr><td style="font-size:8pt">'+m_hr+''+d_date+', <b>'+hashname+':</b> '+venue+' <a href="'+hashlink+'" target="_top" style="font-size:8pt;color:Red" title="For more details and a location map, click to go to The '+hashname+' Run List page.">'+m_more+' </a></td></tr>');

	m_hr = '<hr size="0" color="a0a0ff">';
	 }	   
	 return;
}
//
if (backcol=="")
{
if (hash=="B")
	{
	backcol="#e5ffe5";
	}
if (hash=="G")
	{
	backcol="#f5f5d5";
	}
if (hash=="K")
	{
	backcol="#e5e5ff";
	}
if (hash=="S")
	{
	backcol="#ffffaa";
	}

}
if (hash=="B")
	{
	hashkey = "BRIS";
	}
if (hash=="G")
	{
	hashkey = "GREY";
	}
if (hash=="K")
	{
	hashkey = "K&amp;A";
	}
if (hash=="S")
	{
	hashkey = "BOGS";
	}
	
printit="0";
if (printline=="")
{
printline=venue;
}
if(call=="p") 
{ 
backcol="#ffffff";
frontcol="#000000";
call="c";
printit="1";
}
if(gride=="")
{
osref=ospref;
} 
else
{
osref=ospref+gride.substring(1,4)+gridn.substring(1,4);
}
now   = new Date();
nyear = now.getYear();
if(nyear<1000) nyear=nyear+1900;
nyear = nyear-2000;
nyear = ((nyear<10) ? "0":"")+nyear;
nmonth= now.getMonth()+1;
nmonth= ((nmonth<10) ? "0":"")+nmonth;
nday  = now.getDate() ;
nday  = ((nday<10) ? "0":"")+nday ;
ndate = nday+'/'+ nmonth +'/'+ nyear;
testnow = nyear+""+nmonth+""+nday;
ntoday  = testnow;

if (stats != "")   // if stats contains a date in the form 091231 list will start from there
	{
	testnow = stats;
	}
testrun = rdate.substring(6,8)+rdate.substring(3,5)+rdate.substring(0,2);

if(printit!="1")
	{
	if(ntoday==testrun && stats=="") rdate='Today';
	}
	else
	{ 
	locn = hare.search("printdisp");
	if (locn >= 0)
	 	{
		locn = locn + 11;
		locnend = hare.search("]");
		hare = hare.substring(locn,locnend);
		}
	}
if(testrun>=testnow && call=="c" || testrun<testnow && (call=="o" || call=="a"))
   {
   document.write('<tr valign="top" bgcolor='+backcol+'>');
/*  if(call=="o")
   {
	document.write('<td valign="top" align="center"><a href="stats/runstat.php?runno='+run+'"  style="color:white; background:red ;font-size:12pt" target="runstat"><b>S</b></a></td>');
	}
*/	
	if (display=="A")
	{
   document.write('<td valign="top" align="center"><strong>'+hashkey+'</strong></td>');
   document.write('<td valign="top" align="center"><strong>'+rdate+'<br>'+dateaddnl+'</strong></td>');
   	}
	else
	{
    //if(call=="o")	

	if (testrun<ntoday && hash=="B")
     {
	 document.write('<td valign="top" ><a href="bh3intro.php?run='+run+'"  style="color:white; background:red ;font-size:8pt" title="Click for list of runners" target="_top"><strong>'+run+'</strong></a></td>');
	 }
	else
	 {
     document.write('<td valign="top"><strong>'+run+'</strong></td>');
   	 }
   document.write('<td valign="top" align="left"><strong>'+rdate+'<br>'+dateaddnl+'</strong></td>');
    }
   if(printit=="1")
   {
   document.write('<td valign="top">'+printline+'</td>');
   document.write('<td valign="top">'+osref+' </td>');
   }
   else
   {
   document.write('<td valign="top">'+venue+'</td>');
   //client=public&gride='+gride+'&gridn='+gridn+'
   document.write('<td valign="top"><a href="http://www.multimap.com/maps/?hloc=|'+osref+'&dp=os" TARGET="_blank" title="Click for Multimap of '+osref+'">'+osref+'</a></td>');
   }
   document.write('<td valign="top">'+hare+'</td>');
   document.write('</tr>');
} 
}

function genline(call,run,rdate,dateaddnl,venue,hare,gride,gridn,scale,ospref,backcol,frontcol,testnow)
{
osref=ospref+gride.substring(1,4)+gridn.substring(1,4);
now   = new Date();
nyear = now.getYear();
if(nyear<1000) nyear=nyear+1900;
nyear = nyear-2000;
nyear = ((nyear<10) ? "0":"")+nyear;
nmonth= now.getMonth()+1;
nmonth= ((nmonth<10) ? "0":"")+nmonth ;
nday  = now.getDate() ;
nday  = ((nday<10) ? "0":"")+nday ;
ndate = nday+'/'+ nmonth +'/'+ nyear;
testnow = nyear+nmonth+nday;
testrun = rdate.substring(6,8)+rdate.substring(3,5)+rdate.substring(0,2);
//if(testnow==testrun) rdate='Tonight';

if(testrun>=testnow && call=="c" || testrun<testnow && call=="o")
{
   document.write('<tr valign="top" bgcolor='+backcol+'>');
   document.write('<td valign="top"><strong>'+run+'</strong></td>');
   document.write('<td valign="top"><strong>'+rdate+'<br>'+dateaddnl+'</strong></td>');
   document.write('<td valign="top">'+venue+'</td>');
   document.write('<td valign="top"><a href="http://uk8.multimap.com/map/browse.cgi?GridE='+gride+'&GridN='+gridn+'&scale='+scale+'&place='+osref+'" TARGET="multimap">'+osref+'</a></td>');
   document.write('<td valign="top">'+hare+'</td>');
   document.write('</tr>');
} 
}


function runline(run,rdate,dateaddnl,venue,hare,gride,gridn,scale,ospref,backcol,frontcol,testnow)
{
osref=ospref+gride.substring(1,4)+gridn.substring(1,4);
now   = new Date();
nyear = now.getYear();
if(nyear<1000) nyear=nyear+1900;
nyear = nyear-2000;
nyear = ((nyear<10) ? "0":"")+nyear;
nmonth= now.getMonth()+1;
nmonth= ((nmonth<10) ? "0":"")+nmonth ;
nday  = now.getDate() ;
nday  = ((nday<10) ? "0":"")+nday ;
ndate = nday+'/'+ nmonth +'/'+ nyear;
testnow = nyear+nmonth+nday;
testrun = rdate.substring(6,8)+rdate.substring(3,5)+rdate.substring(0,2);
//if(testnow==testrun) rdate='Today';

if(testrun>=testnow)
{
document.write('<tr valign="top" bgcolor='+backcol+'>');
document.write('<td valign="top"><strong>'+run+'</strong></td>');
document.write('<td valign="top"><strong>'+rdate+'<br>'+dateaddnl+'</strong></td>');
document.write('<td valign="top">'+venue+'</td>');
document.write('<td valign="top"><a href="http://uk8.multimap.com/map/browse.cgi?GridE='+gride+'&GridN='+gridn+'&scale='+scale+'&place='+osref+'" TARGET="multimap">'+osref+'</a></td>');
document.write('<td valign="top">'+hare+'</td>');
document.write('</tr>');
}
}

function splashline(hash,display,m_st,call,textcolor,backcolor,splash,expire,printline)
{  
if (hash.indexOf(display) < 0)
{
return;
}
if(call=="p")
{
textcolor="#000000";
backcolor="#ffffff";
if(printline=="")
{
  printline=splash;
}
splash=printline;
call="c";
}
now   = new Date();
nyear = now.getYear();
if(nyear<1000) nyear=nyear+1900;
nyear = nyear-2000;
nyear = ((nyear<10) ? "0":"")+nyear;
nmonth= now.getMonth()+1;
nmonth= ((nmonth<10) ? "0":"")+nmonth ;
nday  = now.getDate() ;
nday  = ((nday<10) ? "0":"")+nday ;
ndate = nday+'/'+ nmonth +'/'+ nyear;
testnow = nyear+nmonth+nday;
testexp = expire.substring(6,8)+expire.substring(3,5)+expire.substring(0,2);
if(testnow<=testexp && call=="c")
{
document.write('<tr bgcolor="'+backcolor+'">');
document.write('<td valign="top" align="center" colspan="5" style="color:'+textcolor+'">'+splash+'</td>');
document.write('</tr>');
}
}
