/* 
	eccaLatest.js
	File containing scripts for generating ECCA Homepage details
	Created by Questronics Computing Service
 */

var ns4 = document.layers
var ie4 = document.all
var ns6 = document.getElementById && !document.all
var isNav = (ns4 || ns6)
var isIE = !isNav

today = new Date()
var now = new Date()
var noShowDate = now.setTime(new Date().getTime() - (30 *  24 * 3600000))	 // 30 days back - used to be 20 days back
var blinkDate = now.setTime(new Date().getTime() - (7 *  24 * 3600000))		 // 7 days back

function newYear() {
	var cText = ""
	var xmas = ((today.getMonth() == 11) && (today.getDate() > 11) && (today.getDate() < 29)) 	//	Note:  0 = January ...... 11 = December
	var newyear = (((today.getMonth() == 0) && (today.getDate() < 7)) || ((today.getMonth() == 11) && (today.getDate() > 28)))	
			//	Note:  0 = January ...... 11 = December
	if (xmas) {
		cText = "a Happy Christmas and<br> a Happy, Safe and Successful New Year"
	}
	if (newyear) {
		cText = "a Happy, Safe and Successful New Year"
	}
	if (cText.length > 0) {
		cText = '<p>\n<table align=center cellpadding=10px style="border:double green 6px; background-color:yellow;">\n'
			+ '<tr>\n<td align=center style="font-family:Comic Sans MS, cursive; font-size:20pt; color:red; font-weight:bold">'
			+ 'We wish all Visitors to the' + (newyear ? '<br>' : ' ') + 'Eastern Counties Website<br>' + cText + "\n</td>\n</tr>\n</table>\n</p>"
		document.write(cText)
	}
}

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 (entryDate >= 	noShowDate) {
		Latest[Latest.length] = new LstArray(link, msg, desc, dat, target)
	}
}

function LstArray(link, msg, desc, dat, target) {
	this.link = link
	this.msg = msg
	this.desc = desc
	this.dat = dat
	if ((target == null) || (target == "undefined") || (typeof target != "string")) { this.target = "_top" }
	else { this.target = target }
}

var original, items

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

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

var cMonths = new Array('January','February','March','April','May','June','July','August','September','October','November','December')

function showLatest(Latest) {
	if (Latest.length == 0) { return }
	var i, x, space, cText = ""	//	, now = new Date()
	var nDay, nMonth, nYear, entryDate 
	var cText = '<p><table class=embedded align=right border=1 bordercolor=red cellspacing=0 cellpadding=3 '
		+ 'style="border:double red 5px; background-color:yellow; margin-left:10px; margin-bottom:10px;">\n<tr><th colspan=2><b>Last Updates</b></th></tr>\n'
	for (i = 0; (i < Latest.length) && (i < 9); i++) {
		x = Latest[i]
		entryDate = new Date(cMonths[x.dat.substr(3,2) - 1] + x.dat.substr(0,2) + ", " + x.dat.substr(6))
		space = ((entryDate >= blinkDate) ? "id = 'blnk" + i + "'" : "")
		if (entryDate >= 	noShowDate) {
			cText += '<tr><td nowrap>' + addLatest(x.link, x.msg, x.desc, space, x.target, true) + '</td><td>' + x.dat + '</td></tr>\n'
		}
	}
	cText += '</table></p>'
//alert(cText)
	document.write(cText)
}

function addLatest(link, msg, desc, space, target) {
	var cText = "", suffix = "", blink = ""
	if ((space != "") && (space != null) && (space != "undefined")) {
		if ((typeof space == "boolean") && (space == true)) { suffix = "&nbsp;&nbsp;&nbsp;&nbsp;" }
		if ((typeof space == "string") && (space.toLowerCase().indexOf('blnk') != -1)) { blink = " " + space }
	}
	if ((link.toLowerCase().indexOf('javascript') >=0) && (link.toLowerCase().indexOf('newwindow') == -1)) { cText += '<a class=blink href="' + eval(link) + '"' }
	else { cText += '<a class=blink href="' + link + '"' }
	cText += ' title="' + msg + '"' + blink + ' onmouseover="return setMsg(\'' + escape(msg) + '\')" onmouseout="return setMsg()"'
	if ((target != "") && (target != null) && (target != "undefined")) { cText += ' target="' + target + '"' }
	cText += ' onclick="return setMsg()">' + desc + '</a>' + suffix
//alert(cText)
	return cText
}

function setMsg(msg) {
	if ((msg == null) || (msg == "undefined")) { msg = '' }
	if ((msg != '') && (msg != ' ')) {
		msg = unescape(msg)
		var msg2 = msg.toLowerCase()
		if ((msg2.indexOf('show') != 0) && (msg2.indexOf('go') != 0) && (msg2.indexOf('select') != 0) && (typeof selectedYear != "undefined")) { 
			msg = 'Show ' + selectedYear + ' ' + msg 
		}
	}
	window.status = msg
	return true
}


