var pastor_email="pastor"+"@"+"tlc-royston.org.uk";
var admin_email="admin"+"@"+"tlc-royston.org.uk";
var web_email="webmaster"+"@"+"tlc-royston.org.uk";
var alpha_email="alpha"+"@"+"tlc-royston.org.uk";
var tapes_email=admin_email;
var gAutoPrint = true; // Flag for whether or not to automatically call the print function

iens6=document.all||document.getElementById
ns4=document.layers

function cookie(name, value, path){
	var cookieval;
	// 24 = 1 day
	var hours = 240;

	this.$name = name;
	if (hours) this.$expire = new Date((new Date()).getTime() + hours * 3600000);
	else this.$expire = null;
	if (path) this.$path = path;
	else this.$path = null;

	if (value != undefined) {
		cookieval  = value;
	}
	else { 
		cookieval = retrieve();
		if (!checkcookie(document.title)){
			if (cookieval != ""){ cookieval += "&";}
			translateHref = document.location.href.replace("&", "#amp;")
			translateTitle = document.title.replace("&", "#amp;")
			cookieval += escape(translateHref + "@" + translateTitle);
		}
	}

	var cookie = this.$name + '=' + cookieval;
	if (this.$expire) cookie += '; expires=' + this.$expire.toGMTString();
	if (this.$path) cookie += '; path=' + this.$path;

	document.cookie = cookie;	
	window.location.reload();		
}
	
function checkcookie(title){
	var value = retrieve();
	var a = new Array();
	if (value = retrieve()){
		var cookieval = "";
		amp = value.split('&');
		for (var i=0;i<amp.length;i++)
		{
			att = amp[i].split('@');
			if (unescape(att[1]) == title){ return true;}
		}
	return false;
	}
}
	
function retrieve(){
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("tlcquicklinks=");

	if (pos != -1)
	{
		var start = pos + 14;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		var value = allcookies.substring(start, end);
		return unescape(value);
	}
	else return "";	
}
			
function loadcookies(){		
	var value =  retrieve();
	var a = new Array();
	if (value = retrieve()){
		amp = value.split('&');
		for (var i=0;i<amp.length;i++)
		{
			att = amp[i].split('@');
			a[i] = new Array(2);
			for (var j=0;j<att.length;j++)
			{
				a[i][j] = unescape(att[j].replace("#amp;", "&"));
			}					
		}
		return a;					
	}
	else return false;
}

function removecookie(title){
	var value = retrieve();
	var a = new Array();
	if (value = retrieve()){
		var cookieval = "";
		amp = value.split('&');
		for (var i=0;i<amp.length;i++)
		{
			att = amp[i].split('@');
			if (unescape(att[1]) != title){
				if (cookieval != "") {cookieval += "&"}
				cookieval +=  escape(att[0] + "@" + att[1]);
			}
		}
	cookie('tlcquicklinks', cookieval);	
	}
}

function printSpecial()
{

	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n<script src="./script/tlc.js" type="text/javascript"></script>\n';

		html += '\n<link href="./stylesheet/tlc.css" type="text/css" rel="stylesheet"/>';
		html += '\n<stylesheet><style>body{background-color:white;}</style></stylesheet>';

		//if (document.getElementsByTagName != null)
		//{
		//	html += '<style>';
		//	var styleTags = document.getElementsByTagName("style");
		//	if (styleTags.length > 0) {html += styleTags[0].innerHTML;}
		//	html += '</style>';
		//}

		html += '\n<title>' + document.title + '</title>';

		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the Print feature is unavailable.");
	}
}

function showhide(divID, imgID, expandSrc, hideSrc){
	var divs = document.getElementsByTagName("div");
	var imgs = document.getElementsByTagName("img");
	var block = divs[divID];
	var arrow = imgs[imgID];
	if (block.style.display == "none"){
		block.style.display = "inline";
		block.style.visibility = "visible";
		arrow.src="./graphic/" + expandSrc;}
	else{
		block.style.display = "none";
		block.style.visibility = "hidden";
		arrow.src="./graphic/" + hideSrc;}
}

function calculateSum()
{

	var sumTotal = 0.00;
	var sums = document.getElementsByName("sum");
	for (i = 0; i < sums.length; i++)
		{
		if (sums[i].value != "")
			{
			sumValue = parseFloat(sums[i].value);
			sumTotal = sumTotal + sumValue;
			}
		}
	var decimal = sumTotal.toString();
	var dot = decimal.indexOf(".");

	if (dot != -1)
		{
		var fractions = decimal.split('.');
		if (fractions[1].length == 1) {fractions[1] = fractions[1] + "0";}
		if (fractions[1].length > 2) {fractions[1] = fractions[1].slice(0,2)}
		decimal = fractions[0] + "." + fractions[1];
		}
	else
		{
		decimal = decimal + ".00";
		}

	var sumtotal;		

	if (iens6){ sumtotal=document.getElementById ? document.getElementById("sumtotal") : document.all.sumtotal }
	else if (ns4){ sumtotal=document.sumtotal }

	sumtotal.value = decimal;
}