// homepage.js

if (parent.is_new('31/10/yyyy',1)) { document.write('<script type="text/javascript" src="'+getDir()+'scripts/JSFX_Halloween.js"></script>') }
if (screen800) { document.write('<link rel="stylesheet" href="'+getDir()+'scc800.css" media="screen" type="text/css">') }
else { document.write('<link rel="stylesheet" href="'+getDir()+'scc.css" media="screen" type="text/css">') }
if (just) { document.write('<link rel="stylesheet" href="'+getDir()+'scc_just.css" media="screen" type="text/css">') }

function readProfile() {
	if (screen.availWidth <= 800) {
		if (((visits > 2) && (profileArray[2].indexOf('no') != -1)) || (visits%20 == 0)) {
			cText = "The optimum screen size for the Shaftesbury CC website is 1024 x 768.\n\nYou may like to adjust your display characteristics"
			modalWindow(cText,"alert",450,175)
			profileArray[2] = 'yes'
		}
	}
/*
//	if (((visits == 5) || ((voteVisits != 0) && (voteVisits%10 == 0))) && (profileArray[3].indexOf('no') != -1)) {
	if (((visits == 5) || (voteVisits >= 10)) && ((profileArray[3].indexOf('no') != -1) && (profileArray[3].indexOf('never') == -1))) {	
		cText = ''
			+ 'As you are a regular visitor (at least ' + visits + ' visits) we would like to automatically record your vote in the "Top 50 UK Cycling Websites".\n\n'
			+ 'The Bestsites page will load in the background and then record your vote.\n\n'
			+ 'Please click on [OK] if you agree or [Cancel] if you don\'t want to.'
		if (modalWindow(cText, "yes/no",600,215)) { profileArray[3] = 'yes'; allowVote = true }
		else { profileArray[3] = 'no'; allowVote = false; profileArray[3] = 'never' }
		profileArray[4] = 0
		profile('autoVote', profileArray[3])
	}
	if (profileArray[3].indexOf('never') != -1) {	
		cText = ''	//	<span style="color:red;">animation</span>
			+ 'As soon as we stop the automatic voting so the "Top 50 UK Cycling Websites" starts updating again (we jumped 200 votes), '
			+ 'however it still inflicts adverts on the visitors.\n\n'
			+ 'If you would like to reactivate our automatic voting system then go to the <font color=red><b>animation</b></font> link on our home page.\n\n'
			modalWindow(cText, "alert",600,215)
			profileArray[3] = 'no'
			profile('autoVote', profileArray[3])
	}
*/
}

function profile(id, setting) {
	switch(id) {
		case 'animate':
			profileArray[0] = setting
			break
		case 'index':
			dt=new Date(profileArray[5])
			if ((dt.getDate() != today.getDate()) || (dt.getMonth() != today.getMonth()) || (dt.getFullYear() != today.getFullYear()) || visits > 10) {
				visits=0
				voteVisits=0
			}
			visits = visits + 1
			profileArray[1] = visits	
			if (!allowVote) { voteVisits = voteVisits + 1 }
			profileArray[4] = voteVisits
			profileArray[5] = today

//			if (allowVote  && (self.document.location.href.toLowerCase().indexOf('www') != -1)) {
			if (allowVote) { 	// && (self.document.location.href.toLowerCase().indexOf('http') != -1)) {
				profileArray[3] = 'never'
				allowVote = false
				cText = ''
					+ 'As the "Top 50 UK Cycling Websites" has failed to update its information for the past 6 weeks and still inflicts annoying adverts on the '
					+ 'visitors we have decided to remove our automatic voting system.\n\n'
					+ 'If you still wish to record your vote then click on their logo in the top banner.\n\n'
//				modalWindow(cText, "alert",600,215)
			}

/*
			if (allowVote) { 	// && (self.document.location.href.toLowerCase().indexOf('http') != -1)) {
				profileArray[3] = 'never'
				allowVote = false
				cText = ''
					+ 'As the "Top 50 UK Cycling Websites" has changed to record daily votes but is only updated weekly or even less frequently '
					+ 'and also now inflicts adverts on the visitors we have decided to remove our automatic voting system.\n\n'
					+ 'If you still wish to record your vote then click on their logo in the top banner.\n\n'
				modalWindow(cText, "alert",600,215)
			}
*/
			if (allowVote && !voted && (self.document.location.href.toLowerCase().indexOf('www') != -1)) {
				altPage=window.open(
					"http://www.topsitelists.com/topsites.cgi?ID=140&user=gslr&area=bestsites","VoteForUs"
				)
				self.focus()
			}
			break
		case 'autoVote':
			profileArray[3] = setting
			break
	}	
	SaveCookie("profile", profileArray.join(','), 100)
//alert(GetCookie("profile"))
}

function checkFrame() {
	var val = GetCookie('frame')
return		// added 07/02/08 to avoid message while using questronics.org but hiding prefix
	if (((val == null) || (val != 'noShow')) && (!top.banner)) {
		cText = "The Shaftesbury website is much easier to use when not trapped inside another site's frame.\n"
			+ 'Please click on [OK] to load in a New Window \nor [Cancel] to stay as you are.'
		if (modalWindow(cText, "yes/no",500,175)) { top.location="index.html" }
/*
		cText = "The Shaftesbury website is much easier to use when not trapped inside another site's frame. To achieve this, go back to the link to our site "
			+ 'and right click on it and then select "Open in a New Window".'
		alert(cText)
*/
		SaveCookie('frame','noShow',0)
	}
}

function blink() {
	var no, nos = items, slash
//alert(nos)
	while (nos.length > 0) {
		slash = nos.indexOf('/')
		if (slash <= 0) { break }
		no=nos.substring(0,slash)
//		with (parent.main.document.links[no].style) {
		with (document.links[no].style) {
			backgroundColor = (!original) ? 'cyan' : 'yellow'
		}
		nos = nos.substr(slash + 1)
	}
	firsttime=false
	original = !original
}

function blink2() {
	var no, nos = items, slash
	while (nos.length > 0) {
		slash = nos.indexOf('/')
		if (slash <= 0) { break }
		no = parseInt(nos.substring(0,slash))
		nos = nos.substr(slash + 1)
		with (parent.main.document.links[no].style) {
			backgroundColor = (!original) ? 'cyan' : 'yellow'
		}
	}
	firsttime=false
	original = !original
}

function blinker(nos) {
	if (noMove) { return }
	if (parent.window.frames.length == 0) { return }
	items = ''
	with (parent.main.document) {
		for (var i = 0; i < links.length; i++) {
			if (links[i].id.substring(0,4) == 'blnk') { items += i + '/' }
		}
	}
//	b1 = window.setInterval('blink()',800)
	b1 = window.setInterval('blink()',(isNav ? 1500 : 800))
	window.setTimeout('clearInterval(b1); original=true; blink()',30000)
}


function blinker2(nos) {
	if (noMove) { return }
	if (parent.window.frames.length == 0) { return }
	items = ''
alert(parent.main.document.links.length)
	with (parent.main.document) {
		for (var i = 0; i < links.length; i++) {
			if (links[i].id == 'blnk') { items += i.toString() + '/' }
		}
	}
//	b1 = window.setInterval('blink()',800)
	b1 = window.setInterval('blink()',(isNav ? 1500 : 800))
	window.setTimeout('clearInterval(b1); original=true; blink()',30000)
}

function entryFormRR(event) {
	var pName = getDir() + 'entryforms/'
	var typ = event.substring(0,2).toUpperCase()
	var no = parseInt(event.substr(2)) - 1
	var entryEvent = eval('Races[' + no + ']')
	with (parentName.banner.document.f) {
		msg1.value = typ
		msg2.value = parentName.changeCase(entryEvent[0], 'ucase')
		msg3.value = entryEvent[1]
		msg4.value = entryEvent[2]
		msg5.value = entryEvent[3]
	}
	loadEntry('RR', 'DONE')
}

today = new Date()

var now = new Date()
var blinkDate = now.setTime(new Date().getTime() - (14 *  24 * 3600000))		 // 14 days back
var newDate = now.setTime(new Date().getTime() - (7 *  24 * 3600000))		 // 7 days back

function ListArray(link, msg, desc, dat, target) {
	var entryDate = new Date(cMonths[dat.substr(3,2) - 1] + dat.substr(0,2) + ", " + dat.substr(6))
	if (dat.indexOf("00/00") == -1) {
//	if (entryDate >= blinkDate) {
		this.msg = 
			' onmouseover="popupMsg(\'' + msg + '<br>Updated on ' + cMonths[dat.substr(3,2) - 1] + '&nbsp;' + dat.substr(0,2) + ",&nbsp;" + dat.substr(6) + '\')"'
			+ ' onmouseout="killMsg()"'
	} else {
		this.msg = ' title="' + msg + '"'
	}
	this.link = '<tr><td class=box>' + ((entryDate >= 	newDate) ? '<img src="images/new4.gif" align="right" border="0">' : '')
	if (link != "") {
		this.link += '<a href="' + link + '" ' + this.msg 
			+ (((target == null) || (target == "undefined") || (typeof target != "string")) ? '' : ' target="' + target + '"')
			+ ((entryDate >= blinkDate) ? ' id="blnk"' : '')
 			+ '>' + desc + '</a></td></tr>\n'
	} else {
		this.link += desc + '</td></tr>\n'
	}
}

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

function showBoxes() {
	if (!dom	&&	!ie	&&	!ns4) { return }
	var crosshtml, cText
	crosshtml = (dom) ? document.getElementById("leftBox") : ie ? document.all.leftBox : document.leftBox
//alert(crosshtml.innerHTML+ ' - '+typeof crosshtml.innerHTML)
	if (typeof crosshtml.innerHTML == "string") { 
		cText = "<table border=3 cellpadding=5 cellspacing=0 bordercolor='orange' bgcolor='yellow'>\n"
/*
			+ "<tr><th>Member's Section<br>"
//			+ '<span style="font-size:12pt; font-weight:600"><a href="javascript:login()" onmouseover="popupMsg('+"'Click to login to Member Section'"
//			+ '<span style="font-size:12pt; font-weight:600"><a href="http://www.ShaftesburyCC.co.uk/database/login.php" target="_top">Login</a></span>'

		if (parent.banner.f.username.value == "") {
			cText=cText+'<a href="http://www.ShaftesburyCC.co.uk/database/login.php" target="main" onmouseover="popupMsg(\'Click to login to Member Section\')" onmouseout="killMsg()">Login</a></span>'
		} else {
			cText=cText+'<a href="http://www.ShaftesburyCC.co.uk/database/login.php?a=logout" onmouseover="popupMsg('+"'Click to logout of Member Section')"+'" onmouseout="killMsg()">Logout</a></span>'
		}
		cText=cText+'</th></tr>\n'
*/
			+ "<tr><th>What's Happening</th></tr>\n"
		for (i = 0; i < leftbox.length; i++ ) {
			cText = cText + leftbox[i].link+ '\n'
		}
		cText = cText + '</table>'
//alert(cText)
		crosshtml.innerHTML = cText
	}
//return
	crosshtml = (dom) ? document.getElementById("rightBox") : ie ? document.all.rightBox : document.rightBox
	if (isIE) {
//alert(typeof crosshtml.outerHTML)
		if (typeof crosshtml.outerHTML == "string") { 
/*
		cText = '<table border="3" cellpadding="5" cellspacing="0" bordercolor="orange" bgcolor="yellow">\n'
			+ '<tr><td align="center">'
//			+ '<span class="bold">Latest News</span><br><span class="scrpt"><script type="text/javascript">updated(true)</script></span>'
			+ '<span class="bold">Latest News</span><br><span class="scrpt" id="updateBox"></span>'
			+ '</td></tr>\n'
			+ '<tr><td class="box">2004</td></tr>\n'
		cText = crosshtml.outerHTML
		for (i = 0; i < rightbox.length; i++ ) {
			cText = cText + rightbox[i].link
		}
//		cText = cText + '</table>'
*/
			cText = crosshtml.outerHTML
			var lText = ''
			i = cText.toUpperCase().indexOf('</TBODY>')
			if (i > -1) {
				lText = '</TBODY></TABLE>'
				cText = cText.substring(0, i)
			} else {
				i = cText.toUpperCase().indexOf('</TABLE>')
				if (i > -1) {
					lText = '</TABLE>'
					cText = cText.substring(0, i)
				}
			}
			for (i = 0; i < rightbox.length; i++ ) {
				cText = cText + rightbox[i].link
			}
			cText = cText + lText
//alert(cText)
			crosshtml.outerHTML = cText
		}
	} else {
		if (typeof crosshtml.innerHTML == "string") { 
//alert(crosshtml.innerHTML+ ' - '+typeof crosshtml.innerHTML)
			cText = crosshtml.innerHTML
			var lText = ''
			i = cText.toUpperCase().indexOf('</TBODY>')
			if (i > -1) {
				lText = '</TBODY></TABLE>'
				cText = cText.substring(0, i)
			} else {
				i = cText.toUpperCase().indexOf('</TABLE>')
				if (i > -1) {
					lText = '</TABLE>'
					cText = cText.substring(0, i)
				}
			}
			for (i = 0; i < rightbox.length; i++ ) {
				cText = cText + rightbox[i].link
			}
			cText = cText + lText
//alert(cText)
			crosshtml.innerHTML = cText
		}
	}
}

function login()
{
	if (!dom	&&	!ie	&&	!ns4) { return }
	var crosshtml, cText
	crosshtml = (dom) ? document.getElementById("login") : ie ? document.all.login : document.login
	cText='<iframe id="reports" name="reports" class="reports" style="width:460; height:400;" src="http://www.ShaftesburyCC.co.uk/database/login.php">'
		+'There would be a Floating Frame here if your browser supported it</iframe>'
	crosshtml.style.visibility='visible'
	crosshtml.innerHTML = cText
}