/* 
	timetrials.js
	File containing all the Time Trial script files prepared for Shaftesbury CC website
	Created by Questronics Computing Service
 */
var ttLastUpdate = "14/07/2010"
var EventArrayWE = new Array(), EventWE = new Array(), EventArrayEV = new Array()
var today = new Date()
var thisYear = today.getFullYear()
var NamesArray = new Array()
var obj = 'document.Entry'
var parentName = getBase("scc")
parentName = parentName.substr(0,parentName.length-1)
var parentName = eval(getParent())
//alert(parentName.banner.document.f.msg1.value)
//alert(parent.parent.banner.document.f.msg1.value)
var parentName2 = eval(getParent2())
var isEnter = false
var FirstEV10 = new Date("January 01, " + thisYear)
var isEV10= false

function entryForm(event) {
	var pName = getDir() + 'entryforms/'
	if (event == 'pb') { loadEntry('pb'); return }
	var typ = event.substring(0,2).toUpperCase()
	var no = parseInt(event.substr(2)) - 1
	var entryEvent = eval('EventArray' + typ + '[' + no + ']')
	if ((typeof entryEvent == 'undefined') || (entryEvent == null)) {
		if (typ == 'WE') { loadWE(thisYear, true) }
		if (typ == 'EV') { loadEV(thisYear, true) }
		entryEvent = eval('EventArray' + typ + '[' + no + ']')
	}
	if (typ == 'EV') { loadEV(FirstEV10, true) }
	entryEvent = eval('EventArray' + typ + '[' + no + ']')
	switch (typ) {
		case 'OP':
			etitle=entryEvent.title.toUpperCase()
			isRand=(etitle.indexOf('RAND') != -1) 
			isLVRC=(etitle.indexOf('LVRC') != -1) 
			isBCC=((etitle.indexOf('CIRCUIT RACE') != -1) || (etitle.indexOf('GO RACE') != -1))
			isBCR=(etitle.indexOf('ROAD RACE') != -1)
			if (isRand) {
				ecrse = entryEvent.course
				x = ecrse.indexOf("&nbsp;&nbsp;")
				if (x > -1) { ecrse = ecrse.substr(x+12) }
				dat = entryEvent.date
				dist=parseInt(ecrse)
//alert(dat+' : '+dist)
//				loadEntry('AUK'); return 
				loadEntry('AUK',dat+'|'+dist); return 
			}
			if (isLVRC) { 
				loadOpen("LVRC",entryEvent)
//				alert('Sorry, this Entry Form procedure not available.\nPlease use a standard LVRC Entry Form.') 
				return
			}
//			if (isBCC || isBCR) { 
/*
				with (parentName.banner.document.f) {
					if (entryEvent.title.toLowerCase().indexOf('2-day') != -1) {
						msg1.value = typ
						msg2.value = parentName2.changeCase('Shaftesbury Open 2-Day Road Race', 'ucase')
						msg3.value = '9&10 July 2005'
						msg4.value = '£25.00'
						msg5.value = '1/2/3/4/W'
						msg6.value = '09/07/2005'
					} else {
						msg1.value = typ
						msg2.value = parentName2.changeCase(entryEvent.title, 'ucase')
						msg3.value = entryEvent.date
						msg4.value = entryEvent.fee
						msg5.value = entryEvent.cat
						msg6.value = longDate(entryEvent.date,false,false)
					}
				}
				loadEntry('RR', 'DONE')
*/
			if (isBCC) { 
				loadOpen("BCC",entryEvent)
			} else {
				if (isBCR) { 
					loadOpen("BCR",entryEvent)
				} else { 
					loadOpen("CTT",entryEvent)
				}
			}
			break
		case 'EV':
		case 'WE':
//alert(entryEvent.entry)
			if (entryEvent.entry != 'open') { 
				with (parentName.banner.document.f) {
					msg1.value = typ
					msg2.value = entryEvent.title
//					msg3.value = ((typ == 'EV') ? 'Wednesday ' + entryEvent.date : parentName2.longDate(entryEvent.date, true, true)) 
					msg3.value = parentName2.longDate(entryEvent.date, true, true) 
					msg4.value = entryEvent.time
					msg5.value = entryEvent.course
					msg6.value = parentName2.longDate(entryEvent.date,false,false)
				}
				loadEntry(typ)
			} else { 
				loadOpen("CTT",entryEvent)
//				getObj("CTT").style.visibility="visible"
//				alert('You must enter this as an Open Event using the CTT Entry Form.\nSorry, this Entry Form procedure not available on line.')
			}
			break
		default:
			if (entryEvent.entry == 'open') { alert('Sorry, this Entry Form procedure not yet ready.') }
	}
}

var date1 = "april 04, 2001"		//	01 for 2001, 03 for April (Jan = 0), 04 for 4th
var year = 2001

function isPast(startDate, interval) {
	if (isNaN(interval)) { interval = 0 }
	var i, x=0, y, cTime = ""
	var now = new Date()
	var nDay, nMonth, nYear, entryDate 
 	warnDate = now.setTime(new Date().getTime() - (interval *  24 * 3600000))		 // <interval> days back
	if (isEV10) {
		nDay = now.getDay()
		switch (nDay) {
			case 1: interval=0; break;		//	Tuesday
			case 2: interval=-6; break;	//	Wednesday
			case 3: interval=-5; break;
			case 4: interval=-4; break;
			case 5: interval=-3; break;
			case 6: interval=-2; break;
			case 0: interval=-1; break;
		} 
		interval=0
	 	warnDate = now.setTime(new Date().getTime() - (interval *  24 * 3600000))		 // <interval> days back
//alert(startDate+' | '+interval)
//alert(nDay+'  '+interval+'  '+new Date(warnDate))
	}
	x=startDate.indexOf("/")
	cDay=1 * startDate.substr(0, x++)
	y=startDate.indexOf("/", x)
	nMonth = 1 * startDate.substring(x, y++)
	cMonth = Months[nMonth - 1]																				// has to be -1 as arrays start from position 0 (zero)
	cYear=startDate.substr(y)
	if (cYear.indexOf(":") > -1) {
		z=cYear.indexOf(":")
		cTime = cYear.substr(z + 1)
		cYear = cYear.substring(0, z)
	}
	if (cYear.length == 2) { cYear = '20' + cYear }
	entryDate = new Date(cMonth + cDay + ", " + cYear + "  " + cTime)
//	if (isNaN(entryDate)) {
//		alert(startDate.substring(x+1,y)*1 + "  "+nMonth + "  " + x + "  " + y + "  " + cDay + "  " + cMonth + "  " + cYear + "  " + cTime)
//		alert(startDate+'  '+entryDate+'  '+new Date(warnDate)+'  '+(entryDate < warnDate))
//	}
	return (entryDate < warnDate)
}

function Events(no, date, title, course, time, map, fee, cat, colour) {
	var noEntry = false
	this.no = no
	this.date = date
	this.year = date.substr(6)
	this.title = title
	this.course = course
	noEntry = (time.indexOf("*") >= 0)
	this.time = time.replace("*","")
	this.map = map
	this.fee = fee
	this.cat = cat
	this.colour = ""
	this.disabled=' disabled'		//	added 07/04/10
	if ((colour != null) && (colour != "undefined") && (colour != "")) { this.colour = colour }
	this.organiser = ""
	if (this.colour.substr(0,9).toLowerCase() == "organiser") {
		this.organiser = this.colour.substr(10)
		this.colour = ""
	}
	this.result = false
	if ((fee == null) || (fee == "undefined") || (fee == "")) { this.result = true }
	if (isEnter && !noEntry) {
		chkTime = parseFloat(this.time)
		chkHours = parseInt(this.time)
		chkMins = Math.round((chkTime % 1) * 100)
		if (this.time.toLowerCase().indexOf("pm") > -1) { chkHours += 12 }
		chkDate = date + ":" + chkHours + ':' + chkMins 
//alert(chkDate )
		this.entry = (((title.toUpperCase().indexOf('ECCA') == -1) && (title.toUpperCase().indexOf('OPEN') == -1)) ? 'club' : 'open')
//		this.isnew = parentName2.is_new(date, ((this.entry == 'club') ? 0 : -14))
		this.disabled = ((isPast(chkDate, ((this.entry == 'club') ? (this.title.indexOf("Evening")>-1 ? -6 : 0) : -12))) ? ' disabled' : ' title="Click to complete Event Entry Form"')
		this.marshal = ((isPast(chkDate, 0)) ? ' disabled' : ' title="Click to volunteer for Marshalling Duties"')
	}
	if (noEntry) {
		this.disabled = ' disabled'
		this.marshal = ' disabled'
	}
	if (this.organiser=="none") {
		this.marshal = ' disabled'
	}
}

/* WEEKEND EVENTS */

var EventWE = new Array(), EventArrayWE = new Array()

function loadWE(nYear, enter) {
	var cText, i = 0
	isEnter = enter
//alert(nYear)
	EventWE = new Array()
	switch (nYear) {
		case 2010:
			EventWE[i] = new Events (i++, '21/03/2010', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html','','',"organiser-Lily Shakespeare" )
			EventWE[i] = new Events (i++, '11/04/2010', 'Hilly 20 Miles', 'E.17', '*10.30 am', 'e17_20.html','','',"organiser-Lily Shakespeare" )
			EventWE[i] = new Events (i++, '25/04/2010', '30 Miles (with 32nd Association)', 'E.1', '9.00 am', 'e1_30.html','','',"organiser-Lily Shakespeare" )
			EventWE[i] = new Events (i++, '13/06/2010', '25 Miles', 'E.11', '9.00 am', 'e11_25.html','','',"organiser-Bruce Robinson" )
			EventWE[i] = new Events (i++, '27/06/2010', '100 Miles (ECCA) (with 32nd Association)', 'E.2c', '5.00 am', '','','',"organiser-none")
// 'e2c_100.html' )
			EventWE[i] = new Events (i++, '03/07/2010', '50 Miles &ldquo;Open&rdquo;', 'E.2c', '2.00 pm', 'e2c_50.html', '8.00', "", "organiser-Simon Ginger")
			EventWE[i] = new Events (i++, '25/07/2010', '30 Miles', 'E.1', '9.30 am', 'e1_30.html','','',"organiser-Ralph Mullan" )
			EventWE[i] = new Events (i++, '01/08/2010', '50 Miles (with 32nd Association)', 'E.1', '8.00 am', 'e1_50.html','','',"organiser-Lily Shakespeare" )
			EventWE[i] = new Events (i++, '21/08/2010', '10 Miles &ldquo;SPOCO&rdquo; Open Event at Hog Hill<br> (counts towards Club Hill Climb Championship)', 'E.101/10', '8.30 am', 'e101_10.html', '7.50', "", "organiser-Ken Pearce")
			EventWE[i] = new Events (i++, '05/09/2010', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html','','',"organiser-Laurence Bellamy" )
			EventWE[i] = new Events (i++, '18/09/2010', 'Len Waters 25 Miles (with 32nd&nbsp;Association)', 'E.1c','3.00 pm', 'e1c_25.html','','',"organiser-Lily Shakespeare")
			EventWE[i] = new Events (i++, '03/10/2010', 'Trophy 10 Miles', 'E.83', '10.30 am', 'e83_10.html','','',"organiser-Lily Shakespeare" )	
//  '', '', 'red' )
			EventWE[i] = new Events (i++, '10/10/2010', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html','','',"organiser-Lily Shakespeare" )
			EventWE[i] = new Events (i++, '16/10/2010', 'Hill Climb (ECCA) (with 32nd Association)', 'E.H/7', '2.00 pm', '', '7.50','', "organiser-George Shakespeare" )
			break
		case 2009:
			EventWE[i] = new Events (i++, '22/03/2009', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html' )
			EventWE[i] = new Events (i++, '12/04/2009', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '19/04/2009', '30 Miles (with 32nd Association)', 'E.1', '9.00 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '10/05/2009', '25 Miles', 'E.11', '9.00 am', 'e11_25.html' )
			EventWE[i] = new Events (i++, '13/06/2009', '50 Miles \"Open\"', 'E.2c', '2.00 pm', 'e2c_50.html' )
			EventWE[i] = new Events (i++, '28/06/2009', '100 Miles (ECCA) (with 32nd Association)', 'E.2c', '5.00 am', '')	// 'e2c_100.html' )
			EventWE[i] = new Events (i++, '12/07/2009', '30 Miles', 'E.1', '9.30 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '02/08/2009', '50 Miles (with 32nd Association)', 'E.1', '7.30 am', 'e1_50.html' )
			EventWE[i] = new Events (i++, '06/09/2009', '25 Miles (with 32nd Association)', 'E.1b', '8.00 am', 'e1b_25.html' )
			EventWE[i] = new Events (i++, '19/09/2009', 'Len Waters 25 Miles (with 32nd&nbsp;Association)', 'E.1c','3.00 pm', 'e1c_25.html')
			EventWE[i] = new Events (i++, '04/10/2009', 'Trophy 10 Miles', 'E.83', '10.30 am', 'e83_10.html' )	//  '', '', 'red' )
			EventWE[i] = new Events (i++, '11/10/2009', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '17/10/2009', 'Hill Climb (ECCA) (with 32nd Association)', 'E.H/7', '2.00 pm', '' )
			break
		case 2008:
			EventWE[i] = new Events (i++, '23/03/2008', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html' )
			EventWE[i] = new Events (i++, '13/04/2008', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '20/04/2008', '30 Miles (with 32nd Association)', 'E.1', '9.00 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '11/05/2008', '25 Miles', 'E.11', '9.00 am', 'e11_25.html' )
			EventWE[i] = new Events (i++, '15/06/2008', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html' )
			EventWE[i] = new Events (i++, '06/07/2008', '100 Miles (ECCA) (with 32nd Association)', 'E.2', '5.00 am', 'e2_100.html' )
			EventWE[i] = new Events (i++, '13/07/2008', '30 Miles', 'E.1', '9.30 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '26/07/2008', '50 Miles \"Open\"', 'E.2c', '2.00 pm', 'e2c_50.html' )
			EventWE[i] = new Events (i++, '03/08/2008', '50 Miles (with 32nd Association)', 'E.1', '7.30 am', 'e1_50.html' )
			EventWE[i] = new Events (i++, '06/09/2008', '25 Miles (with 32nd Association)', 'E.1c', '3.00 pm', 'e1c_25.html' )
			EventWE[i] = new Events (i++, '13/09/2008', 'Len Waters 25 Miles (with 32nd&nbsp;Association)', 'E.1c','3.00 pm', 'e1c_25.html')
			EventWE[i] = new Events (i++, '05/10/2008', 'Trophy 10 Miles', 'E.83', '10.30 am', 'e83_10.html' )	//  '', '', 'red' )
			EventWE[i] = new Events (i++, '12/10/2008', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '18/10/2008', 'Hill Climb (ECCA) (with 32nd Association)', 'E.H/7', '2.00 pm', '' )
			break
		case 2007:
			EventWE[i] = new Events (i++, '25/03/2007', '25 Miles (with 32nd Association)', 'E.1b', '9.00 am', 'e1b_25.html' )
			EventWE[i] = new Events (i++, '15/04/2007', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '22/04/2007', '30 Miles (with 32nd Association)', 'E.1', '8.30 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '13/05/2007', '25 Miles', 'E.11', '9.00 am', 'e11_25.html' )
			EventWE[i] = new Events (i++, '10/06/2007', '50 Miles (with 32nd Association)', 'E.1', '7.30 am', 'e1_50.html' )
			EventWE[i] = new Events (i++, '15/07/2007', '30 Miles', 'E.1', '9.00 am', 'e1_30.html' )
			EventWE[i] = new Events (i++, '29/07/2007', '50 Miles \"Open\"', 'E.2b', '5.30 am', 'e2b_50.html' )
			EventWE[i] = new Events (i++, '05/08/2007', '100 Miles (ECCA) (with 32nd Association)', 'E.2', '5.45 am', 'e2_100.html' )
			EventWE[i] = new Events (i++, '02/09/2007', '25 Miles (with 32nd Association)', 'E.1c', '8.00 am', 'e1c_25.html' )
			EventWE[i] = new Events (i++, '08/09/2007', 'Len Waters 25 Miles (with 32nd&nbsp;Association)', 'E.1c','3.00 pm', 'e1c_25.html')
			EventWE[i] = new Events (i++, '07/10/2007', 'Trophy 10 Miles', 'E.83', '10.30 am', 'e83_10.html' )	//  '', '', 'red' )
			EventWE[i] = new Events (i++, '14/10/2007', 'Hilly 20 Miles', 'E.17', '10.30 am', 'e17_20.html' )
			EventWE[i] = new Events (i++, '20/10/2007', 'Hill Climb (ECCA) (with 32nd Association)', 'E.H/7', '2.00 pm', '' )
			break
	}
	if (enter) { for (i = 0; i < EventWE.length; i++) { EventArrayWE[i] = EventWE[i] } }
}

function writeWE(nYear, typ) {
	var cText = '', enter = false, isProv = false
	switch (typeof typ) {
		case 'boolean':
			enter = typ
			break
		case 'string':
			isProv = (typ.toLowerCase() == 'p')
			enter = true
	}
	loadWE(nYear, enter)
	nCols=((enter) ? 5 : 4)+1
	cText += '<p><a name="' + nYear + '_we"></a>'
		+ '<table align="center" border="2" cellspacing="0" cellpadding="2" bgcolor="#ffffbb" bordercolor="orange" >'
		+ '<colgroup>'
		+ '<col width=22 align="center" /l><col width=170 /><col width=300 /><col span=2 />' 
		+ ((enter) ? '<col align="center" width=45 /><col align="center" width=45 />' : '') 
		+ '</colgroup>'
		+ '<tr><th style="border-right:none"><a href="#back" onclick="goback(); return false">'
		+ '<img src="../images/back_arrow.gif" title="Back to Previous Screen" valign=top align=left></a></th>'
		+ '<th colspan=' + nCols + ' align=center valign=top style="border-left:none; color:green;">'
		+ '<a href="#Top" title="Top of Page">'
		+ '<img src="../images/top_arrow.gif" align=right valign=top></a>' + ((isProv) ? 'Provisional ' :'') + 'Weekend Club Event Dates in ' + nYear 
		+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(click <a href="#' + nYear + '_ot">here</a> for Open Events)</th></tr>'
//		+ '<tr><td colspan=' + nCols+1 + ' class="bar" align=center>'
//		+	'Click on [Marshal] for details on how you can offer to help with the marshalling</td></tr>'
//		+ '<tr><td colspan=' + nCols+1 + ' class="bar"><img src="" height=1></td></tr>'
	notPast = -1
	for (var i = 0; i < EventWE.length; i++) {
		if (!isPast(EventWE[i].date,0)) {
			notPast = i
			i = EventWE.length
		}
	}
	for (z=0; z < 2; z++) {
		if (notPast == -1) {
			z=1
			zFirst=0
			zLast=EventWE.length
		} else {
			if (z==0) {
				zFirst = notPast
				zLast=EventWE.length
			} else {
				zFirst = 0
				zLast=notPast
			}
		}
		if (nYear==thisYear) {
			if (z==1) 
				cText+= '<tr><td colspan=' + (nCols+1) + ' class="bar" style="text-align:center">Events already past</td></tr>'
			else
				cText+= '<tr><td colspan=' + (nCols+1) + ' class="bar" style="text-align:center">'
					+ 'Click on [Marshal] for details on how you can offer to help with the marshalling</td></tr>'
		}
		for (i = zFirst; i < zLast; i++) {
//	for (var i = 0; i < EventWE.length; i++) {
			cText += '<tr><td align="center">'+(i+1)+'</td><td>' + parentName2.longDate(EventWE[i].date, true, false) + '</td><td>' + EventWE[i].title + '</td>'
			if (EventWE[i].map != '') {
				cText += '<td><a href="courses/' + EventWE[i].map + '" target="_self" title="Click for Course Details">' + EventWE[i].course + '</a></td>'
			} else { cText += '<td>' + EventWE[i].course + '</td>' }
			if (EventWE[i].colour != "") {
				cText += '<td align=right style="color:' + EventWE[i].colour + '">' + EventWE[i].time + '</td>'
			} else {
				cText += '<td align=right>' + EventWE[i].time + '</td>'
			}
			if (enter) { 
				cText += 
					'<td><input type=button value="Enter" onclick="entryForm(\'we'+(i+1)+'\')"'+(isProv? 'disabled' : EventArrayWE[i].disabled)+'></td>'
				+ '<td><input type=button value="Marshal" onclick="doMarshal(\'we'+(i+1)+'\')"'+(isProv? 'disabled' : EventArrayWE[i].marshal)+'></td>'
			}
			cText += '</tr>'
		}
	}
	cText += '</table>'
//alert(cText)
	document.write(cText)
}

/* EVENING 10'S */

var EventArrayEV = new Array()
var edate = new Array(), etimes = new Array(), 	ecourse = new Array()
var crse1, crse2
var cMonths = new Array('January','February','March','April','May','June','July','August','September','October','November','December')
var cDays = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')

function loadEV(firstDate, enter) {
	var cMonth, cDay, nDay, nMonth
	var eventDate = new Date(firstDate)
	var nYear = eventDate.getFullYear()
	if (eventDate > FirstEV10) { FirstEV10 = eventDate }
//alert(eventDate)
	switch (nYear) {
		case 2010:
			etimes = new Array(
				'6.45','7.00','7.00','7.15','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.15','7.00','6.45','6.45','6.30'
			)
			ecourse = new Array(
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83',
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83'
			)
			break
		case 2009:
			etimes = new Array(
				'6.45','6.45','7.00','7.00','7.15','7.30','7.30','7.30','7.30','7.30','7.30*','7.30*','7.30','7.30','7.30','7.30','7.30','7.15','7.00','6.45','6.45','6.30'
			)
			ecourse = new Array(
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83',
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83'
			)
			break
		case 2008:
			etimes = new Array(
				'6.45','6.45','7.00','7.00','7.15','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.15','7.00','6.45','6.45','6.30'
			)
/*
			etimes = new Array(
				'6.45','6.45','7.00','7.00','7.15','7.30','7.30','7.30','7.30*','7.30*','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.15','7.00','6.45','6.45','6.30'
			)
*/
			ecourse = new Array(
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83',
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83'
			)
			break
		case 2007:
			etimes = new Array(
				'6.45','6.45','7.00','7.00','7.15','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.30','7.15','7.00','6.45','6.45','6.30','6.30'
			)
			ecourse = new Array(
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83',
				'E83','E83','E83','E83','E83','E83','E83','E83','E83','E83','E83'
			)
			break
	}
	crse2=-1
	crse=""
	isEV10 = true
	for (var i = 0; i < 22; i++) {
		eventDate = new Date(firstDate)
   	eventDate.setTime(eventDate.getTime() + ((7 * i) * 24 * 3600000))			 // i weeks on from first event
		nMonth = eventDate.getMonth() - 0
		nDay = eventDate.getDate() - 0
//alert(nDay)
//		if (nDay <= 9) {nDay= '0'+nDay.toString() }
		edate[i] = cMonths[nMonth] + ' ' + AddSuffix(nDay)
		nMonth = nMonth + 1
		if (nMonth <= 9) {nMonth= '0'+nMonth.toString() }
		cDate = nDay + '/' + nMonth + '/' + nYear
		EventArrayEV[i] = new Events(i, cDate, 'Evening 10 No. ' + (i + 1), ecourse[i], etimes[i] + ' pm')
		if (crse != ecourse[i]) {
			if ((crse != "") && (crse2 == -1)) { 
				crse2 = i 
			}
			crse = ecourse[i]
		}
	}
//alert(crse2)
	isEV10 = false
	return nYear
}

function writeEV(firstDate, typ) {
	var cText = '', enter = false, isProv = false, noEntry = false
	switch (typeof typ) {
		case 'boolean':
			enter = typ
			break
		case 'string':
			isProv = (typ.toLowerCase() == 'p')
			enter = true
	}
	isEnter = enter
//	isEnter = true
	var nYear = loadEV(firstDate, enter)
	cText += '<p><a name="' + nYear + '_10"></a>'
		+ '<table align="center" border="2" cellspacing="0" cellpadding="2" bgcolor="#ffffbb" bordercolor="orange" width=' + ((enter) ? 680 : 620) + '>'
		+ '<colgroup>'
		+ '<col width="22px" align="center"></col><col></col><col span=2 align="center"></col>' 
		+ ((enter) ? '<col align="center" width="45px"></col>' : '') + '<col bgcolor="#d0d0d0"></col>'
		+ '<col width="22px" align="center"></col><col></col><col span=2 align="center"></col>' 
		+ ((enter) ? '<col align="center" width="45px"></col>' : '') + '<col bgcolor="#d0d0d0"></col>'
		+ '<col width="22px" align="center"></col><col></col><col span=2 align="center"></col>' 
		+ ((enter) ? '<col align="center" width="45px"></col>' : '') 
		+ '</colgroup>'
		+ '<tr><th style="border-right:none"><a href="#back" onclick="goback(); return false">'
		+ '<img src="../images/back_arrow.gif" title="Back to Previous Screen" valign=top align=left></a></th>'
		+ '<th colspan=16 style="border-left:none; color:green;"><a href="#Top" title="Top of Page">'
		+ '<img src="../images/top_arrow.gif" align=right valign=top></a>' 
		+ ((isProv) ? 'Provisional ' :'') + 'Wednesday Evening 10 Miles Events in ' + nYear + '</th></tr>'
		+ '<tr><td colspan=22 class="bar"><img src="" height=1></td></tr>'
	for (var i = 0; i < 8; i++) {
		cText += '<tr><td align="center">' + (i + 1) + '</td><td>' + edate[i] + '</td><td>'
		crse = EventArrayEV[i].course
		if ((i == 0) || (i == crse2)) {
			cText += '<a href="courses/' + crse.toLowerCase() + '_10.html" target="_self" title="Click for Course Details">' + crse + '</a>' 
		} else { cText +=  crse }
		noEntry = (etimes[i].indexOf("*") >= 0)
		cText += '</td><td>' + etimes[i].replace("*","") + '</td>'
		if (enter) { 
			cText += '<td><input type=button value="Enter" onclick="entryForm(\'ev' + (i + 1) + '\')"' 
				+ ((isProv || noEntry) ? 'disabled' : EventArrayEV[i].disabled) + '></td>' 
		}
		cText += '<td><br></td><td align="center">' + (i + 9) + '</td><td>' + edate[i + 8] + '</td><td>'
		crse = EventArrayEV[i+8].course
		if ((i+8) == crse2) { 
			cText += '<a href="courses/' + crse.toLowerCase() + '_10.html" target="_self" title="Click for Course Details">' + crse + '</a>' 
		} else { cText +=  crse }
		noEntry = (etimes[i + 8].indexOf("*") >= 0)
		cText += '</td><td>' + etimes[i + 8].replace("*","") + '</td>'
		if (enter) { 
			cText += '<td><input type=button value="Enter" onclick="entryForm(\'ev' + (i + 9) + '\')"' 
				+ ((isProv || noEntry) ? 'disabled' : EventArrayEV[i + 8].disabled) + '></td>' 
		}
		cText += '<td><br></td>'
		if (i == 6) { cText += '<td rowspan=2 colspan=5><br></td>' }
		else if (i < 6) {
			crse = EventArrayEV[i+16].course
			cText += '<td align="center">' + (i + 17) + '</td><td>' + edate[i + 16] + '</td><td>'
			if ((i+16) == crse2) { 
				cText += '<a href="courses/' + crse.toLowerCase() + '_10.html" target="_self" title="Click for Course Details">' + crse + '</a>' 
			} else { cText +=  crse }
			noEntry = (etimes[i + 16].indexOf("*") >= 0)
			cText += '</td><td>' + etimes[i + 16].replace("*","") + '</td>'
			if (enter) { 
				cText += '<td><input type=button value="Enter" onclick="entryForm(\'ev' + (i + 17) + '\')"' 
					+ ((isProv || noEntry) ? 'disabled' : EventArrayEV[i + 16].disabled) + '></td>' 
			}
		}
		cText += '</tr>'
	}
	cText += '</table>'
	document.write(cText)
}

var EventOP = new Array(), EventArrayOP = new Array()

function loadOP(nYear, enter) {
	isEnter = enter
	var cText, i = 0
	EventOP = new Array()
	switch (nYear) {
		case 2010:
			EventOP[i] = new Events(i++, '06/02/2010', '2010 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr> Billericay', '6.00 for<br>6.30 pm', '1','£29.00')
			EventOP[i] = new Events(i++, '06/03/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '441','5.00', '', 'organiser-Richard Parrotte' )
			EventOP[i] = new Events(i++, '06/03/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '150 km On&nbsp;Road', '9.00 am', '001','5.00', '', 'organiser-Richard Parrotte' )
			EventOP[i] = new Events(i++, '06/03/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '10.00 am', '001','5.00', '', 'organiser-Richard Parrotte' )
			EventOP[i] = new Events(i++, '06/03/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;50 km On&nbsp;Road', '11.00 am', '001','5.00', '', 'organiser-Richard Parrotte' )
			EventOP[i] = new Events(i++, '08/05/2010', 'Open Ladies 25 Miles Time Trials', 'E.2/25', '2.00 pm', 'e2_25.html','8.00', "", "organiser-Joe O'Herlihy")
			EventOP[i] = new Events(i++, '08/05/2010', 'Open Middle Markers 25 Miles Time Trials', 'E.2/25', '2.00 pm', 'e2_25.html','8.00', "", "organiser-Joe O'Herlihy")
			EventOP[i] = new Events(i++, '03/07/2010', 'Open 50 Miles Time Trial (including&nbsp;Tandems)', 'E.2c/50', '2.00 pm', 'e2c_50.html','8.00', "", "organiser-Simon Ginger")
			EventOP[i] = new Events(i++, '21/08/2010', 'SPOCO 10 Miles Time Trial', 'E.101/10 - Hog Hill', '8.30 am', 'e101_10.html', '7.50', "", "organiser-Ken Pearce")
			EventOP[i] = new Events(i++, '21/08/2010', 'Youth A/B - BC Circuit Race', 'h_Hog Hill Cycle Circuit', '10.15 am', '919','3.00','Youth A/B', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Youth E - BC Circuit Race', 'Hog Hill', '11.00 am', '010','Free','Youth E', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Youth D - BC Circuit Race', 'Hog Hill', '11.15 am', '010','Free','Youth D', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Youth C - BC Circuit Race', 'Hog Hill', '11.40 am', '010','Free','Youth C', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'LVRC Circuit Races', 'Hog Hill', '12.25 pm', '010','8.00', "", "organiser-Terry Anderson")
			EventOP[i] = new Events(i++, '21/08/2010', 'Novice - BC Go Race', 'Hog Hill', '3.00 pm', '010','5.00','Novice', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Women - BC Circuit Race', 'Hog Hill', '3.45 pm', '010','12.00','W', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Regional A (2/3/4) - BC Circuit Race', 'Hog Hill', '3.45 pm', '010','12.00','A 2/3/4', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '21/08/2010', 'Junior - BC Circuit Race', 'Hog Hill', '3.45 pm', '010','5.00','J', 'organiser-Michael Purvis')
			EventOP[i] = new Events(i++, '19/09/2010', 'Shaftesbury ERRL Road Race', 'Debden-Thaxted', '9.00 am', 'r_debden_thaxted.html','15.00','2/3/4', "organiser-Dan Scott")
			EventOP[i] = new Events(i++, '25/09/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '441','5.00', '', 'organiser-Tim Stout' )
			EventOP[i] = new Events(i++, '25/09/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '160 km On&nbsp;Road', '9.00 am', '001','5.00', '', 'organiser-Tim Stout' )
			EventOP[i] = new Events(i++, '25/09/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '10.00 am', '001','5.00', '', 'organiser-Tim Stout' )
			EventOP[i] = new Events(i++, '25/09/2010', 'Audax/Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;50 km On&nbsp;Road', '11.00 am', '001','5.00', '', 'organiser-Tim Stout' )
//			EventOP[i] = new Events(i++, '05/02/2011', '2011 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr> Billericay', '6.00 for<br>6.30 pm', '1','£30.00')
			break
		case 2009:
//			EventOP[i] = new Events(i++, '07/02/2009', '2009 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr> Billericay', '6.00 for<br>6.30 pm', '1','£28.00')
			EventOP[i] = new Events(i++, '07/03/2009', 'Audax/Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '441','£5.00')
			EventOP[i] = new Events(i++, '07/03/2009', 'Randonn&eacute;es (from Bungalow)', '150 km On&nbsp;Road', '9.00 am', '001','£5.00')
			EventOP[i] = new Events(i++, '07/03/2009', 'Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '10.00 am', '001','£5.00')
			EventOP[i] = new Events(i++, '07/03/2009', 'Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;50 km On&nbsp;Road', '11.00 am', '001','£5.00')
			EventOP[i] = new Events(i++, '09/05/2009', 'Open 10 Miles Time Trial (including&nbsp;Tandems)', 'E.2/10', '2.00 pm', 'e2_10.html')
			EventOP[i] = new Events(i++, '13/06/2009', 'Open 50 Miles Time Trial (including&nbsp;Tandems)', 'E.2c/50', '2.00 pm', 'e2c_50.html')
			EventOP[i] = new Events(i++, '04/07/2009', 'Open Middle Markers & Ladies 25 Miles Time Trials', 'E.2/25', '2.00 pm', 'e2_25.html')
			EventOP[i] = new Events(i++, '22/08/2009', 'SPOCO 10 Miles Time Trial', 'E.101/10 - Hog Hill', '9.00 am','e101_10.html')
			EventOP[i] = new Events(i++, '22/08/2009', 'Shaftesbury LVRC Circuit Race', 'h_Hog Hill Cycle Circuit', '12.25 pm', '515','')
			EventOP[i] = new Events(i++, '22/08/2009', 'Shaftesbury BC Go Races', 'Hog Hill', '11.00 am', '010','','Youth A/B/D')
			EventOP[i] = new Events(i++, '22/08/2009', 'Shaftesbury BC Go Race', 'Hog Hill', '12.30 pm', '010','£6.00','W')
			EventOP[i] = new Events(i++, '22/08/2009', 'Shaftesbury BC Go Race', 'Hog Hill', '1.30 pm', '010','£6.00','4/Novice')
			EventOP[i] = new Events(i++, '22/08/2009', 'Shaftesbury BC Circuit Race', 'Hog Hill', '2.30 pm', '010','£10.00','2/3/4')
			EventOP[i] = new Events(i++, '20/09/2009', 'Shaftesbury ERRL Road Race', 'Debden-Thaxted', '9.00 am', 'r_debden_thaxted.html','£15.00','2/3/4')
			EventOP[i] = new Events(i++, '26/09/2009', 'Audax/Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '441','£5.00')
			EventOP[i] = new Events(i++, '26/09/2009', 'Randonn&eacute;es (from Bungalow)', '160 km On&nbsp;Road', '8.45 am', '001','£5.00')
			EventOP[i] = new Events(i++, '26/09/2009', 'Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '10.00 am', '001','£5.00')
			EventOP[i] = new Events(i++, '26/09/2009', 'Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;50 km On&nbsp;Road', '11.00 am', '001','£5.00')
			EventOP[i] = new Events(i++, '06/02/2010', '2010 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr> Billericay', '6.00 for<br>6.30 pm', '1','£28.00')
			break
		case 2008:
			EventOP[i] = new Events(i++, '26/01/2008', '2008 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr><br>Billericay', '6.00 for<br>6.30 pm', '1','£25.00')
			EventOP[i] = new Events(i++, '08/03/2008', 'Audax/Randonn&eacute;es (from Bungalow)', '160 km On&nbsp;Road', '9.00 am', '331','£4.00')
			EventOP[i] = new Events(i++, '08/03/2008', 'Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '10.00 am', '001','£4.00')
			EventOP[i] = new Events(i++, '08/03/2008', 'Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;50 km On&nbsp;Road', '11.00 am', '001','£4.00')
			EventOP[i] = new Events(i++, '10/05/2008', 'Open 10 Miles Time Trial (including&nbsp;Tandems)', 'E.2/10', '2.00 pm', 'e2_10.html')
			EventOP[i] = new Events(i++, '29/06/2008', 'Shaftesbury ERRL Road Race', 'Thaxted', '9.00 am', '','£15.00','E/1/2/3')
			EventOP[i] = new Events(i++, '26/07/2008', 'Open 50 Miles Time Trial (including&nbsp;Tandems)', 'E.2c/50', '2.00 pm', 'e2c_50.html')
			EventOP[i] = new Events(i++, '16/08/2008', 'Open Middle Markers & Ladies 25 Miles Time Trials', 'E.2/25', '2.00 pm', 'e2_25.html')
			EventOP[i] = new Events(i++, '11/10/2008', 'Audax/Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '221','£4.00')
			EventOP[i] = new Events(i++, '11/10/2008', 'Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '9.30 am', '001','£4.00')
//			EventOP[i] = new Events(i++, '07/02/2009', '2009 Annual Dinner &amp; Prize Presentation', '<nobr>Stock Brook Country Club,</nobr><br>Billericay', '6.00 for<br>6.30 pm', '1','£25.00')
			break
		case 2007:
			EventOP[i] = new Events(i++, '10/02/2007', '2007 Annual Dinner &amp; Prize Presentation', 'Thorndon Banqueting Suite, Furze Hill, Margaretting', '6.00 for<br>6.30 pm', '1','£30.00')
			EventOP[i] = new Events(i++, '10/03/2007', 'Randonn&eacute;es (from Bungalow)', '161 km On&nbsp;Road', '9.00 am', '3','£4.00')
			EventOP[i] = new Events(i++, '10/03/2007', 'Randonn&eacute;es (from Bungalow)', '106 km On&nbsp;Road', '10.00 am', '0','£4.00')
			EventOP[i] = new Events(i++, '10/03/2007', 'Randonn&eacute;es (from Bungalow)', '&nbsp;&nbsp;56 km On&nbsp;Road', '11.00 am', '0','£4.00')
			EventOP[i] = new Events(i++, '20/05/2007', 'Open 10 Miles Time Trial (including&nbsp;Tandems)', 'E.3/10', '9.30 am', 'e3_10.html')
			EventOP[i] = new Events(i++, '29/07/2007', 'Open 50 Miles Time Trial (including&nbsp;Tandems)', 'E.2b/50', '5.30 am', 'e2b_50.html')
			EventOP[i] = new Events(i++, '23/09/2007', 'Heron Cycle Sport/Shaftesbury Open Road Race', 'Dengie', '9.30 am', '','£14.00','E/1/2/3')
			EventOP[i] = new Events(i++, '13/10/2007', 'Randonn&eacute;es (from Bungalow)', '200 km On&nbsp;Road', '8.00 am', '2','£4.00')
			EventOP[i] = new Events(i++, '13/10/2007', 'Randonn&eacute;es (from Bungalow)', '100 km On&nbsp;Road', '9.30 am', '0','£4.00')
			break
	}
	if (enter) { for (i = 0; i < EventOP.length; i++) { EventArrayOP[i] = EventOP[i] } }
}

function writeOP(nYear, typ) {
	var enter = false, isProv = false
	switch (typeof typ) {
		case 'boolean':
			enter = typ
			break
		case 'string':
			isProv = (typ.toLowerCase() == 'p')
	}
	isEnter = enter
	loadOP(nYear, enter)
	var rspan, etitle, x, cText = '', emap, ecat
	nCols = ((enter) ? 5 : 4) + 1
	cText += '<p><a name="' + nYear + '_ot"></a>'
		+ '<table align="center" border="2" cellspacing="0" cellpadding="2" bgcolor="#ffffbb" bordercolor="orange">'	// width=' + ((enter) ? 790 : 730) + '>'
		+ '<colgroup>'
		+ '<col width=24%></col><col width=*%></col><col width=17%></col><col width=10%></col>' 
		+ ((enter) ? '<col span=2 align="center" width=45></col>' : '') 
		+ '</colgroup>'
		+ '<tr><th colspan=' + nCols + ' style="color:green;"><a href="#Top" title="Top of Page"><img src="../images/top_arrow.gif" align=right valign=top></a>' 
		+ ((isProv) ? 'Provisional ' :'') + 'Dates in ' + nYear + ' for Open Events promoted by Shaftesbury CC'
		+ ((nYear <2002) ? ' or&nbsp;32nd&nbsp;Association' : '') + '</th></tr>'
//		+ '<tr><td colspan=6 class="bar"><img src="" height=1></td></tr>'
	notPast = -1
	for (var i = 0; i < EventOP.length; i++) {
		if (!isPast(EventOP[i].date,0)) {
			notPast = i
			i = EventOP.length
		}
	}
	for (z=0; z < 2; z++) {
		if (notPast == -1) {
			z=1
			zFirst=0
			zLast=EventOP.length
		} else {
			if (z==0) {
				zFirst = notPast
				zLast=EventOP.length
			} else {
				zFirst = 0
				zLast=notPast
			}
		}
		if (nYear==thisYear) {
			if (z==1) 
				cText+= '<tr><td colspan=' + nCols + ' class="bar" style="text-align:center">Events already past</td></tr>'
			else
				cText+= '<tr><td colspan=' + nCols + ' class="bar" style="text-align:center">'
					+ 'Click on [Marshal] for details on how you can offer to help with the marshalling</td></tr>'
		}
		for (i = zFirst; i < zLast; i++) {
			ecrse = EventOP[i].course
			emap = EventOP[i].map
//alert(emap+ '  '+isNaN(emap))
			ecat = EventOP[i].cat
			if ((ecat == null) || (ecat == "")) { 
				ecat = '' 
			} else {
				if (ecat.indexOf('(') < 0) { ecat =  ' (' + ecat + ')' }
			}
			rspan = rspan1 = rspan2 = 1
			if ((emap != '') && !isNaN(emap)) { 
				rspan = parseInt(emap.substring(0,1))
				if (emap.length > 1) {
					rspan1 = emap.substr(1,1)
					rspan2 = emap.substr(2,1)
				}
//alert(emap+' : '+rspan+' : '+rspan1+' : '+rspan2)
				emap = ''
			} // else { rspan = 1 }
//		etitle = trim(EventOP[i].title)
			etitle = parentName2.trim(EventOP[i].title)
			x = etitle.indexOf('Bungalow')
			if (x > 0) { etitle = etitle.replace('Bungalow', '<a href="../bungalow.html" title="Click for details on Bungalow">Bungalow</a>') }
			cText += '<tr>'
			if ( rspan != '0') {
				cText += '<td rowspan=' + rspan + '>'
				cText += parentName2.longDate(EventOP[i].date, true, (EventOP[i].year != nYear)) + '</td>'
//				+ '<td rowspan=' + rspan1 + '>' + etitle + ((ecat != '') ? ' ' + ecat  : '') + '</td>\n'
//			cText += longDate(EventOP[i].date, true, false) + '</td><td rowspan=' + rspan + '>' + etitle + ((ecat != '') ? ' (' + ecat + ')' : '') + '</td>'
//			cText += parentName2.longDate(EventOP[i].date, true, false) + '</td><td rowspan=' + rspan + '>' + etitle + ((ecat != '') ? ' (' + ecat + ')' : '') + '</td>\n'
			}
			if ( rspan1 != '0') {
				cText += '<td rowspan=' + rspan1 + '>' + etitle + '</td>\n'
//			cText += '<td rowspan=' + rspan1 + '>' + etitle + ((ecat != '') ? ' ' + ecat  : '') + '</td>\n'
			}
			if ( rspan2 != '0') {
				cText += '<td rowspan=' + rspan2 + '>'
				if (ecrse.substring(0,2) == 'h_') {
					ecrse = ecrse.substr(2)
					locn = 'http://www.streetmap.co.uk/newprint.srf?x=547291&y=191903&z=110&ar=Y&searchp=newprint.srf'
						+ '&mapp=newmap.srf&dn=887&ax=547291&ay=191903&lm=0'
					lText = "<a href=\"javascript:showTarget('" + locn + "', '-nw', 700, 810)\" title='Click Course Details'>" + ecrse + '</a></td>'
//alert(lText)
					cText += lText
//				cText += '<a href="' + locn + '" target="_blank" title="Click for Course Details">' + ecrse + '</a></td>'
				}
				else if (emap != '') {
					if (emap.substring(0,2) == 'r_') {
						cText += '<a href="javascript:loadEntry(\'bcf_maps\', \'' + emap.substr(2) +'\')" title="Click for Course Details">' + EventOP[i].course + '</a></td>'
					}
					else { cText += '<a href="courses/' + emap +'" target="_self" title="Click for Course Details">'+ EventOP[i].course + '</a></td>' }
				} else { cText += EventOP[i].course + '</td>' }
			}
			cText += '<td align=right>' + EventOP[i].time + '</td>\n'
			if (enter) { 
				if (EventOP[i].title.toLowerCase().indexOf('dinner') < 0) {
					cText += '<td class=center><input type=button value="Enter" onclick="entryForm(\'op' + (i+1) + '\')"' + EventArrayOP[i].disabled + '></td>' 
 					+ '<td><input type=button value="Marshal" onclick="doMarshal(\'op' + (i+1) + '\')"' +(isProv ? 'disabled' : EventArrayOP[i].marshal)+'></td>'
				} else { cText += '<td><br></td><td><br></td>' }
			}
			cText += '</tr>'
//alert(cText)
		}
	}
	cText += '</table>'
//alert(cText)
	document.write(cText)
	document.close()
}

function getLastEvent() {
	var i, latestDate
	loadWE(thisYear,false)
	loadOP(thisYear,false)
	thisDate = "april 14, 2010"
	loadEV(thisDate,false)
	Today = new Date
	day = parseInt(Today.getDate()).toString()
	if (day.length<2) { day="0"+day }
	month = parseInt(Today.getMonth()+1).toString()
	if (month.length<2) { month="0"+month }
	myDate="01/01/" + thisYear
	lastEvent = "none"
	OPdate = myDate
	WEdate = myDate
	EVdate = myDate
	for (i = 0; i < EventWE.length; i++) {
		if (isLatest(day,month,EventWE[i].date,myDate)) {
			lastEvent = "WE"
			WEdate = EventWE[i].date
			myDate = WEdate
		}
	}
	for (i = 0; i < EventOP.length; i++) {
//alert(EventOP[i].result)
		if (EventOP[i].result && (isLatest(day,month,EventOP[i].date,myDate))) {
			lastEvent = "OP"
			OPdate = EventOP[i].date
			myDate = OPdate
		}
	}
	for (i = 0; i < EventArrayEV.length; i++) {
	var x=EventArrayEV[i].date.indexOf("/")
	if (x==1) { EventArrayEV[i].date = '0'+EventArrayEV[i].date }
		if (isLatest(day,month,EventArrayEV[i].date,myDate)) {
			lastEvent = "EV"
			EVdate = EventArrayEV[i].date
		}
	}
//alert("we="+WEdate+"  op="+OPdate+"  ev="+EVdate+"  levent="+lastEvent)
	return lastEvent
}

function isLatest(tday,tmonth,event,myDate) {
	var retval = true
	if (event.substr(6,4) == thisYear) {
		eday = event.substr(0,2)
		emonth = event.substr(3,2)
		dday = myDate.substr(0,2)
		dmonth = myDate.substr(3,2)
		if (emonth>tmonth) { retval = false }
		else {
			if (emonth == tmonth) { 
				if (eday>tday) { retval = false }
			}
		}
		if (retval) {
			if (emonth < dmonth ) { retval = false }
			else {
				if (emonth == dmonth ) { 
					if (eday<=dday) { retval = false }
				}
			}
		}
	} else {
		retval = false
	}
	return retval
}

function writeEntryForm(typ,id) {
	var raceform = ((typ=='BC') ? 'BCRoadEntryForm' : 'CTTEntryForm')
	cText='Download '+typ+' <a href="'+raceform+'.doc" target="new2" onmouseover="showInfo('+id+')" '
 		+ 'onmouseout="showInfo('+id+')" title="Click to download entry form" '
		+ 'onclick="showTarget(\'festival/'+raceform+'.doc\',\'yy\',720,'+((typ=='BC') ? 920 : 1000)+'); return false;">Word inter-active Entry Form</a> or '
		+ '<a href="'+raceform+'.pdf" onmouseover="showInfo('+id+')" onmouseout="showInfo('+id+')" title="Click to download entry form" '
		+ 'onclick="showPDFfile(\'festival/'+raceform+'.pdf\',\'pdf\'); return false;">PDF Entry Form</a>'
//alert(cText)
	document.write(cText)
}

var ie = document.all
var dom = document.getElementById
var ns4 = document.layers

function loadOpen(typ,event) {
	var scroll_top, frameWidth, frameHeight, frameLeft, cText, WordForm, PDFForm
	crosshtml = (dom) ? document.getElementById("openform") : ie ? document.all.openform : document.openform
	if (crosshtml == null) { alert("Open Event - No online entry facility"); return }
	crossobj = (dom) ? document.getElementById("openform").style : ie ? document.all.openform.style : document.openform
	hidebox()
	scroll_top = ((ie) ? document.body.scrollTop : window.pageYOffset) + 200
	var w = 630 
	var h = 150 
	var h = 280
	crossobj.width=w
	crossobj.height=h
	frameWidth = (ie) ? document.body.clientWidth : self.innerWidth
	frameLeft = (frameWidth - w) / 2
	frameLeft = 40
	var etitle = event.title
	var ecat = event.cat
	var isYouth = (ecat.indexOf("Youth") != -1)
	var isJunior = (ecat.indexOf("J") != -1)
	var isGo = (etitle.indexOf("Go") != -1)
	var edate = event.date
	var eyear = edate.substr(6)
	eday=edate.substr(0,2)
	if (eday.substring(0,1)=="0") { eday = eday.substr(1) }
	emonth=edate.substr(3,2)
	if (emonth.substring(0,1)=="0") { emonth = emonth.substr(1) }
	emonth=emonth - 1
	var edate = new Date(parseInt(eyear), parseInt(emonth), parseInt(eday))
	eDate=cDays[edate.getDay()]+' '+AddSuffix(edate.getDate())+' '+cMonths[edate.getMonth()]+' '+edate.getFullYear()
	var interval = ((typ=='BCC') ? 7 : ((typ=='LVRC') ? 14 : ((typ=='BCR') ? 21 :((edate.getDay()==6) ? 11 : 12))))
	var cDate = edate.setTime(edate.getTime() - (interval *  24 * 3600000))		 // 7, 11, 12 or 14 days back
	cDate = new Date(cDate)
	cDate=cDays[cDate.getDay()]+' '+AddSuffix(cDate.getDate())+' '+cMonths[cDate.getMonth()]+' '+cDate.getFullYear()
	x=0
	while(isNaN(etitle.substr(x,1)) || etitle.substr(x,1)==" ") {
//alert(etitle.substr(x))
		x++
	}
//alert(x+' '+etitle.length)
	var eid = ((typ!='BCC' && x<etitle.length && !isNaN(etitle.substr(x,1))) ? parseInt(etitle.substr(x))+"_"+eyear+"_" : typ)
//alert(eid)
	if (eid=='BCC' || eid=='BCR') { eid = 'BC' }
//	if (ecat != "") { etitle = etitle + " (" + ecat + ")" }
	if (etitle.indexOf("<br>")>-1) { h +=20 }
	var address = parentName2.getDetails(event.organiser.replace(" ",""))
	if (address.indexOf("<br>")>-1) { h +=10 }
	if (typeof crosshtml.innerHTML != "string") { return }
	PDFForm='<a href="javascript:showPDFfile(\''+eyear+'/'+eid+'EntryForm.pdf\', \'pdf\')" title="Click to download entry form">'
		+'PDF Entry Form</a><p>'
	filBase1 = getBase('tt') + "tt/" + eyear + "/" + eid+'EntryForm.doc'
	filBase1 = filBase1.replace("tt/tt/", "tt/")
	WordForm= '<a href="' + filBase1 + '" target="_blank" title="Right or Left click to download the Entry Form as a Word document">'
		+'Word inter-active Entry Form</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'
	filBase1 = getBase('tt') + "tt/" + eyear + "/" + 'Parental Consent Form.doc'
	filBase1 = filBase1.replace("tt/tt/", "tt/")
	PCForm= '<a href="' + filBase1 + '" target="_blank" title="Right or Left click to download the Parental Consent Form as a Word document">'
		+'Parental Consent Form</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'
	if (typ=="LVRC") { WordForm=""; }
	if (typ=="BCC" || typ=="BCR") { typ = "BC" }
	if (WordForm!="") { h +=20 }
	if (isYouth || isJunior) {
		h += 20
	} else {
		PCForm=""
	}
	cText=
		'<div style="font-family:Comic Sans MS, Arial, sans-serif; font-size:12pt; line-height:120%; padding:0px 5px; color:green; font-weight:500; text-align:center">'
		+'<table width="97%" cellspacing="0" cellpadding="0"><tr>'
		+'<td style="font-family:Comic Sans MS, Arial, sans-serif; font-size:12pt; color:green; text-align:left; line-height:120%;">Event Entry</td>'
		+'<td align="right"><a href="javascript:hidebox()"><img src="../images/close.gif" border="0" width="20px" title="Close" /></a></td>'
		+'</tr></table>'
		+'<div style="font-size:16pt; padding:10px 0px 0px 0px; color:red; font-weight:700; text-align:center">' + etitle + '</div>'
		+'<div style="font-size:14pt; padding-top:5px; color:red; font-weight:700; text-align:center">' + eDate + '</div>'
		+(event.organiser!="" && event.organiser!="none" ? '<p>Organiser: '+event.organiser+'<br>'+address+'</p>' : '')
		+'<p>As this is an Open Event you must enter using a standard ' + typ + ' Entry Form.<br />'
		+'Closing Date is ' + cDate + '.</p>'
		+ WordForm
		+ PCForm
		+ PDFForm
	if (isYouth || isJunior) 
		cText+='<p>Click links to load relevant forms, fill in and send to the Organiser'
	else
		cText+='<p>Click link to load relevant form, fill in and send to the Organiser'
	if (etitle.indexOf('ECCA')<0) {
		if ((event.fee == 0) || (event.fee == "Free"))
			cText += ".<br><span style='line-height:170%;'>Entry in advance is <span style='color:red;'>Free</span> but <span style='color:red;'>Entry on the day is &pound;2.00.</span></span>"
		else {
			cText += "<br>together with a cheque for <span style='color:red;'>&pound;"+event.fee+"</span> made payable to Shaftesbury CC."
			if (typ != "CTT") {
				cText += "<br><span style='line-height:170%;color:red;'>Note: Entry on the day is &pound;"
					+(parseFloat(event.fee)+((isYouth) ? 2 : ((typ=="LVRC") ? 4 : 3)))+ ".00.</span>" 
				h += 10
			}
		}
		h += 10
	}
	if (isYouth)
		cText += '<br>Riders without a BC Annual Licence need to provide a signed Parental Consent Form. '
			+ 'Non-BC members also have to pay a One Day Licence Fee of &pound;1.50.'
	if (isJunior)
		cText += '<br>Riders without a BC Annual Licence need to provide a signed Parental Consent Form '
			+'and may also have to pay a One Day Licence Fee of &pound;2.50 or &pound;5.00.'
	if (isGo)
		cText += '<br>Non-BC members also have to pay a One Day Licence Fee of &pound;5.00.'
	cText	+= '</div>'
	crosshtml.innerHTML = cText
	frameWidth = (ie) ? document.body.clientWidth : self.innerWidth
	frameLeft = (frameWidth - w) / 2
	frameLeft = 40
	with (crossobj) {
		top = scroll_top - h/2
//		top = scroll_top -100
		width=w
		height=h
		left = Math.max(0, frameLeft)
		visibility = (dom || ie) ? "visible" : "show"
	}
}

function doMarshal(event) {
	crosshtml = (dom) ? document.getElementById("openform") : ie ? document.all.openform : document.openform
	if (crosshtml == null) { alert("Open Event - No online entry facility"); return }
	crossobj = (dom) ? document.getElementById("openform").style : ie ? document.all.openform.style : document.openform
	hidebox()
	if (typeof crosshtml.innerHTML != "string") { return }
	var typ = event.substring(0,2).toUpperCase()
	var no = parseInt(event.substr(2)) - 1
	var event = eval('EventArray' + typ + '[' + no + ']')
	var etitle = event.title.replace('&nbsp;',' ')
	var isAudax = (etitle.indexOf("Audax") >= 0)
	var edate = parentName2.longDate(event.date, true, true)
	var etime = event.time
	var ecourse = event.course
	var area = ecourse
	ecourse = ecourse.toLowerCase()
//alert(edate)
	var ecat = event.cat
	if (ecat != "") { etitle = etitle + " (" + ecat + ")" }
	var subj = "Marshalling for " + etitle + ' on ' + edate
	var emailaddress = getDetails(((typ=="WE" ) ? "TTSec" : event.organiser.replace(" ","")),'email')
	var address = getDetails(event.organiser.replace(" ",""))
	var phone = getDetails(event.organiser.replace(" ",""),'phone')
	if (ecourse.indexOf('hog') >= 0) { area = "Hog Hill Cycle Circuit" }
	if (ecourse.substring(0,2) == "e.") {
		if (ecourse.substring(0,3) == "e.h") { area = "Little Baddow/Danbury" }
		c = parseInt(ecourse.substr(2))
		if (c == 2) { area = "Cambridge/Newmarket" }
		if (c == 11) { area = "Blackmore/Ongar/Writtle" }
		if (c == 17) { area = "Passingford Bridge/Toot Hill/Theydon Mount" }
		if (c == 1) { area = "Ugley/Stump Cross/Sawston" }
		if (c == 83) { area = "Mountnessing/Blackmore" }
		if (c == 101) { area = "Hog Hill Cycle Circuit" }
	}
	if (isAudax) { area = "" }
	var scroll_top, frameWidth, frameHeight, frameLeft, cText
	scroll_top = ((ie) ? document.body.scrollTop : window.pageYOffset) + 200
	var w = 600 
	var h = 270
	crossobj.width=w
	crossobj.height=h
	frameWidth = (ie) ? document.body.clientWidth : self.innerWidth
	frameLeft = (frameWidth - w) / 2
	frameLeft = 40
	cText=
		'<div style="font-family:Comic Sans MS, Arial, sans-serif; font-size:12pt; line-height:120%; padding:0px 5px; color:green; font-weight:500; text-align:center">'
		+'<table width="97%" cellspacing="0" cellpadding="0"><tr>'
		+'<td style="font-family:Comic Sans MS, Arial, sans-serif; font-size:12pt; color:green; text-align:left; line-height:120%;">Marshalling</td>'
		+'<td align="right"><a href="javascript:hidebox()"><img src="../images/close.gif" border="0" width="20px" title="Close" /></a></td>'
		+'</tr></table>'
		+'<div style="font-size:16pt; padding:10px 0px; color:red; font-weight:700; text-align:center">' + etitle + '</div>'
		+ '<div style="font-size:14pt; padding:5px 0px; color:red; font-weight:700; text-align:center; line-height:150%;">' + edate + ' &nbsp; Start: ' + etime
		+ ((area != "") ? '<br>Area: ' + area + '</div>' : '</div>')
		+'<p style="text-align:justify">Your offer of help with the marshalling and/or organisation of this event would be much appreciated. '
	if (event.organiser!="") {
		cText += 'Please contact the organiser by post, telephone or email.</p>'
			+'<p>Organiser: ' + event.organiser + '<br>' + address + '<br>'
			+'Phone: '+phone+' &nbsp; Email: '+writeEmail(event.organiser.replace(" ",""),"-email",this,subj)
		}
	cText += '</p></div>'
	crosshtml.innerHTML = cText
	with (crossobj) {
//		top = scroll_top - h
		top = scroll_top -100
		left = Math.max(0, frameLeft)
		visibility = (dom || ie) ? "visible" : "show"
	}
}

function hidebox(){
	crossobj = (dom) ? document.getElementById("openform").style : ie ? document.all.openform.style : document.openform
	crossobj.visibility = "hidden"
}
