/*---------------------------------------------------------------------------------------------------------------------
 *
 *	Written by Tom Sayers - SQUAREZONE Ltd +44 (0)870 890 0522
 *	Copyright © 2001 - 2005 Squarezone Ltd.  All rights reserved.
 *	This software may not be copied by any method in whole || part without
 *	the express written permission of the copyright holder.
 *	www.squarezone.co.uk & www.speedEweb.net
 *
 *---------------------------------------------------------------------------------------------------------------------*/

function jNavigator(goTo){
	if(goTo.value){
	    window.location.href = goTo.value;
	}
}

// ------------------------------------ Form Validation functions ------------------------------------

function validForm(thisForm) {
	if(!document.getElementsByTagName) return;
	var cook = /O\d+_(.*)/;
	var pattern = /[-A-Za-z0-9 \.]{3,}/;
	var psword0 = /^[a-zA-Z0-9]+$/;
	var psword1 = /[A-Z]+/;
	var psword2 = /[a-z]+/;
	var psword3 = /[0-9]+/;
	var passwd;
	var zipcheck = /[A-Z]{2}([0-9]{1,2}|[0-9]{1}[A-Z]{1})\s?[0-9]{1}[A-Z]{2}/i;
	var required = "no";
	var fcus;
	var reqd = /(.*)_(.*)/;
	inp = document.getElementsByTagName("input")
//alert('SUBMIT=' + document.form.submitbtnname);
	for(var ii = 0; ii < inp.length; ii++) {
/*		if(inp[ii].name == "Delete" && inp[ii].value == 'Delete User'){
			if(!confirm('You are about to permanently delete this!')){
				return false;
			}
		}*/
		if(inp[ii].alt == "UK Postcode"){
			if(inp[ii].value && !zipcheck.test(inp[ii].value)){
				inp[ii].focus();
				inp[ii].style.backgroundColor = '#DDF4E9';
				alert("Please enter a Postcode in the form\nAB12 3CD or AB1Y 3CD");
				return false;
			}
		}
		if(inp[ii].title == "Required"){
			if(cook.test(inp[ii].name)){
				var fieldNm = RegExp.$1;
			} else {
				var fieldNm = inp[ii].name;
			}
			if(!inp[ii].value){
				inp[ii].focus();
				inp[ii].style.backgroundColor = '#DDF4E9';
				alert("The highlighted field is required!\nThis applies to any marked with an asterisk.");
				return false;
			}
			//if(!pattern.test(inp[ii].value)){
			//	inp[ii].focus();
			//	alert("The '" + fieldNm + "' field cannot be that short");
			//	return false;
			//}
		}
		if(inp[ii].title == "One required" && required != "ok"){
			if(inp[ii].value){
				required = "ok";
			} else {
				required = inp[ii].name;
				fcus = ii;
			}
		}
		if((inp[ii].type == "password" && (inp[ii].value || passwd)) || inp[ii].alt == "Password"){
			if(passwd){
				if(passwd != inp[ii].value){
					inp[ii].focus();
					inp[ii].style.backgroundColor = '#DDF4E9';
					alert("Passwords do not match");
					return false;
				}
			} else {
				var pswd = inp[ii].value;
				if(!psword0.test(pswd) || pswd.length < 6 || pswd.length > 12 || !psword1.test(pswd) || !psword2.test(pswd) || !psword3.test(pswd)){
					inp[ii].style.backgroundColor = '#DDF4E9';
					inp[ii].focus();
					alert("Passwords must be between\n6 & 12 characters long\nand contain a mixture of\nupper case, lower case and\nnumbers only");
					return false;
				} else {
					passwd = inp[ii].value;
				}
			}
		}
//		if(inp[ii].name == "form" && inp[ii].value == "basket" && !document.cookie){
//			alert("If you wish to place an order online, you need to enable cookies on your browser.\nWe use temporary cookies to store the details of your order.");
//			return false;
//		}
	}
	
	if(required != "no" && required != "ok"){
		inp[fcus].focus();
		if(reqd.test(required)){
			var fieldNm = RegExp.$1;
			alert("At least one " + fieldNm + " is required");
		} else {
			alert("At least one entry is required");
		}
		return false;
	}

	inp = document.getElementsByTagName("textarea")
	for(var ii = 0; ii < inp.length; ii++) {
		if(inp[ii].title == "Required"){
			if(cook.test(inp[ii].name)){
				var fieldNm = RegExp.$1;
			} else {
				var fieldNm = inp[ii].name;
			}
			if(!inp[ii].value){
				inp[ii].focus();
				alert("The " + fieldNm + " field is required");
				return false;
			}
			//if(!pattern.test(inp[ii].value)){
			//	inp[ii].focus();
			//	alert("The " + fieldNm + " field cannot be that short");
			//	return false;
			//}
		}
	}
	return true;
}

// ------------------------------------ Are cookies switched on? ------------------------------------

function cookOk(thisForm){
//	if(document.cookie == "" || !document.cookie){
//		alert("If you wish to place an order online || login to this website, you need to enable cookies on your browser.\nWe use temporary cookies to store the details of your order and your login details.");
//		return false;
//	}
	return true;
}

// ------------------------------------ Thumbnail functions ------------------------------------

function updPic(PicFileName){
	// Remove path and print file name
	fn = PicFileName.lastIndexOf("/");
	ff = PicFileName.slice(fn + 1);
	aa = document.getElementById("picCaption");
	aa.innerHTML = ff;
	// Change main picture
	document.images.picMain.alt="Photograph " + ff;
	// Get image path
	fn = document.images.picMain.src.lastIndexOf("/");
	ff = document.images.picMain.src.substring(0,fn + 1);
	document.images.picMain.src=ff + PicFileName;
	// Update input box with current picture number
	var currPat = /p(\d+)\.jpg/;
	document.jToPic.ToPic.value = 1 * (currPat.exec(PicFileName))[1];
}
function goToPic(firstPic,filmLen,numfiles){
	nextFilmStrip = document.jToPic.ToPic.value - 1;
	if(isNaN(nextFilmStrip)){nextFilmStrip = 1;}
	if(nextFilmStrip < 1){nextFilmStrip = 1;}
	if(nextFilmStrip > numfiles){nextFilmStrip = numfiles;}
	nextFilmStrip = Math.floor(nextFilmStrip / filmLen) * filmLen + 1;
	nxtT(nextFilmStrip,filmLen,numfiles);

	// Update main picture
	targetPic = document.jToPic.ToPic.value;
	if(isNaN(targetPic)){targetPic = 1;}
	if(targetPic < 1){targetPic = 1;}
	if(targetPic > numfiles){targetPic = numfiles;}
	if(targetPic <= 999){targetPic = '0' + targetPic;}
	if(targetPic <= 99){targetPic = '0' + targetPic;}
	if(targetPic <= 9){targetPic = '0' + targetPic;}
	targetPic = 'p' + targetPic + '.jpg';
	updPic(targetPic);

	return false;
}

function nxtT(nextFilmStrip,filmLen,numfiles){
	// Set image file names for each film frame
	var count = nextFilmStrip;
	for(var ii = 1; ii <= filmLen; ii++) {
		aa = document.getElementById("Link" + ii);
		PicFileName = formatFileName(count);
		if(count <= numfiles){
			href = "javascript:onClick=updPic('" + PicFileName + "')";
			aa.setAttribute("href",href);
			document.images["Thmb" + ii].title = PicFileName;
			// Get image path
			fn = document.images.picMain.src.lastIndexOf("/");
			ff = document.images.picMain.src.substring(0,fn + 1) + 'thumbnails/';
			document.images["Thmb" + ii].src = ff + PicFileName;
			count++;
		} else {
			PicFileName = formatFileName(count-1);
			href = "javascript:onClick=updPic('" + PicFileName + "')";
			aa.setAttribute("href",href);
			document.images["Thmb" + ii].title = "The end";
			document.images["Thmb" + ii].src = "/common/film.gif";
		}
	}

	// Set thumbnails navigation display e.g. << 6 - 10 of 12 >>
	lastPic = nextFilmStrip + filmLen - 1;
	if(lastPic > numfiles){lastPic = numfiles;}
	thumbNavDisp = document.getElementById("ThumbNavId");
	thumbNavDisp.innerHTML = nextFilmStrip + " - " + lastPic + " of " + numfiles;

	// Set previous and next navigation links
	prev = nextFilmStrip - filmLen;
	if(prev < 1) prev = 1;
	if(nextFilmStrip + filmLen <= numfiles){nextFilmStrip += filmLen;}
	var prvhref = "javascript:onClick=nxtT(" + prev + "," + filmLen + "," + numfiles + ")";
	var nxthref = "javascript:onClick=nxtT(" + nextFilmStrip + "," + filmLen + "," + numfiles + ")";
	anxt = document.getElementById("ThumbNavNextId");
	anxt.setAttribute("href",nxthref);
	aprv = document.getElementById("ThumbNavPrevId");
	aprv.setAttribute("href",prvhref);

	// Pre-load next filmLen thumbnails for speed of display
	if(count < numfiles){
		// Get image path
		fn = document.images.picMain.src.lastIndexOf("/");
		ff = document.images.picMain.src.substring(0,fn + 1) + 'thumbnails/';
		for(var ii = 1; ii <= filmLen; ii++) {
			myImage = new Image();
			PicFileName = formatFileName(count);
			if(count <= numfiles){
				myImage.src = ff + PicFileName;
				count++;
			} else {
				myImage.src = "/common/film.gif";
				break;
			}
		}
	}
}
function formatFileName(count){
	PicFileName = "p" + count + ".jpg";
	if(count <= 999){PicFileName = "p0" + count + ".jpg";}
	if(count <= 99){PicFileName = "p00" + count + ".jpg";}
	if(count <= 9){PicFileName = "p000" + count + ".jpg";}
	return PicFileName;
}

// ------------------------------------- Editing functions -------------------------------------

	var eStyle = new Array();
	var aParams = new Array();
	var sTextG;
	var pattern = /([ a-zA-Z0-9]*)\s*(centre|right|left)\s*([ a-zA-Z0-9]*)\s*/i;
	var cPanel;
	var eWidth;
	var eHeight;

function eInit()	{
	aParams = eMain.name.split(',');
//	cPanel = window.open('http://81.29.65.152/common/cpanel.htm','_search');
	cPanel = window.open('/common/cpanel.htm','_search');
	if(aParams[1] != 99){	// Control pages may not be edited
		eMain.document.designMode = 'On';
		eMain.contentEditable = true;
		eMain.document.execCommand('liveResize', false, 1);
		eMain.document.execCommand('multipleSelection', false, 1);
	}

	eMain.setActive();
}

function eResize(){
	if(sTextG){
		var eTest = /.*centre.*/i;
		if(eTest.exec(sTextG.className)){
			sTextG.style.position = "relative";
			sTextG.style.left = document.all.eMain.offsetWidth/2 - sTextG.offsetWidth/2;
		}
		if(eWidth != sTextG.width && eHeight != sTextG.height){
			var eFactor =  eHeight / eWidth;
			var eW = sTextG.style.width.split('px');
			sTextG.style.height = eFactor * eW[0];
//			sTextG.height = eFactor * sTextG.width;
		}
		window.status = 'WIDTH:' + sTextG.width + ' HEIGHT:' + sTextG.height;
//			+ ' ORIGINAL WIDTH:' + eWidth + ' HEIGHT:' + eHeight;
	}
}
function eResizeEnd(){
	if(sTextG){
		var eTest = /.*centre.*/i;
		if(eTest.exec(sTextG.className)){
			sTextG.style.position = "relative";
			sTextG.style.left = document.all.eMain.offsetWidth/2 - sTextG.offsetWidth/2;
		}
	}
}
function eSelect(){
	// Fires onMouseDown in editing area
	if(eMain.isContentEditable == true){
		sTextG = window.event.srcElement;
		var eStatus = sTextG.tagName;
		eStatus += sTextG.id ? ' ID:' + sTextG.id : '';
		eStatus += sTextG.className ? ' CLASS:' + sTextG.className : '';
		eStatus += sTextG.title ? ' TITLE:' + sTextG.title : '';
		eStatus += sTextG.name ? ' NAME:' + sTextG.name : '';
		eStatus += sTextG.width ? ' WIDTH:' + sTextG.width : '';
		eStatus += (sTextG.height && sTextG.height < 2000) ? ' HEIGHT:' + sTextG.height : '';
//		eStatus += sTextG.style ? ' STYLE:' + sTextG.style : '';
		eStatus += sTextG.value ? ' VALUE:' + sTextG.value : '';
		if(sTextG.tagName.toUpperCase() == 'IMG'){
			if(sTextG.style.width){
//				var wStyle = sTextG.style.width;
//				var hStyle = sTextG.style.height;
//				sTextG.removeAttribute('style');
				eWidth = sTextG.width;	// for use in eResize
				eHeight = sTextG.height;
//				sTextG.style.width = wStyle;
//				sTextG.style.height = hStyle;
			} else {
				eWidth = sTextG.width;	// for use in eResize
				eHeight = sTextG.height;
				sTextG.style.width = eWidth;
				sTextG.style.height = eHeight;
			}
			sTextG.onResize = "eResize()";
			eStatus += sTextG.alt ? ' ALT:' + sTextG.alt : '';
			eStatus += sTextG.src ? ' SRC:' + sTextG.src : '';
		} else {
			eStatus += sTextG.href ? ' HREF:' + sTextG.href : '';
		}
		window.status = eStatus;
		eButtonCheck();
	}
}


// -------------------- Styles --------------------

function eImage(){
	if(!sTextG){
		eMain.setActive();
		sTextG = document.selection.createRange();
		sTextG = sTextG.parentElement();
	}
	if(sTextG){
   		var myImage = new Image();
		myImage.id = 'newImg';
		myImage.onResize = "eResize()";
		var sImage = cPanel.document.upload.eFilename.value;
		if(sImage != "" && !document.getElementById('newImg')){
			myImage.src = sImage;
			var newWidth = 450;
			if(myImage.width > newWidth){
				alert('This image is too big for this page. Width of ' + myImage.width + ' reduced to fit.');
				var eFactor = newWidth / myImage.width;
				myImage.width = newWidth;
				myImage.height = eFactor * myImage.height;
			}
			sTextG.insertAdjacentElement("beforeBegin",myImage);
			sTextG = document.getElementById('newImg');
			sTextG.setActive();
			if(!sTextG.alt){
				var aImage = sImage.lastIndexOf("\\");
				sImage = sImage.slice(aImage + 1);
				aImage = sImage.lastIndexOf(".");
				sTextG.alt = sImage.slice(0,aImage);
			}

			var aText = prompt('Title of this image:',sTextG.alt);
			if(aText != null)
				sTextG.alt = aText;
				
			if(aText == '')
				sTextG.removeAttribute('alt');
				
//			sTextG.document.execCommand('insertImage',true);
			window.status = 'Image width: ' + myImage.width + ' Height: ' + myImage.height;	
		} else {
			if(sTextG.tagName.toUpperCase() == 'IMG'){
				var aText = prompt('Title of this image:',sTextG.alt);
				if(aText != null)
					sTextG.alt = aText;
					
				if(aText == '')
					sTextG.removeAttribute('alt');
					
//				sTextG.document.execCommand('insertImage',true);
			} else {
				alert('Please select a file using the Browse button');
			}
		}
	}
}

function eButtonCheck(){
	// Check and set each menu button
	if(sTextG){
		eResetMenu();	// reset all names to off

		cPanel.bBold.name = eCheckParents(1,'STRONG','B');
		cPanel.bItalic.name = eCheckParents(1,'EM','I');
		cPanel.bOrdered.name = eCheckParents(1,'OL');
		cPanel.bBulleted.name = eCheckParents(1,'UL');

		cPanel.bMarq.name = eCheckParents(1,'MARQUEE');

		if(sTextG.previousSibling && sTextG.previousSibling.tagName == 'BR' && sTextG.previousSibling.outerHTML.toUpperCase() == '<BR CLEAR=ALL>'){
				cPanel.bBreak.name = 'on';
		}

		cPanel.bLink.name = eCheckParents(1,'A');

		cPanel.document.upload.bImg.name = eCheckParents(1,'IMG');

		cPanel.bHr.name = eCheckParents(1,'HR');

		cPanel.bSpan.name = eCheckParents(1,'SPAN');

		cPanel.bLeft.name = eCheckParents(2,'LEFT');

		cPanel.bCentre.name = eCheckParents(2,'CENTRE');

		cPanel.bRight.name = eCheckParents(2,'RIGHT');

		if(sTextG.tagName == "BR")
			cPanel.bBreak.name = "on";

		if(eMain.isContentEditable)
			cPanel.bEdit.name = "on";

		if(eCheckParents(4)){
			cPanel.eEd.innerText = "Selection may not be edited";
		} else {
			cPanel.eEd.innerText = "";
		}

		cPanel.bNewDir.style.visibility = "hidden";	// Menu item may not be moved
		cPanel.bNewPage.style.visibility = "hidden";	// Menu item may not be moved
		cPanel.bMenuUp.style.visibility = "hidden";	// Menu item may not be moved
		cPanel.bMenuDown.style.visibility = "hidden";	// Menu item may not be moved

		eSetMenu();	// Set
		eTagSet();
		eClassSet();
	}
}

function eCheckParents(eTest,eValue,eValue2,eValue3,eValue4){
	var eText = sTextG;
	var eFound;
	for(var ii = 0; ii < 10; ii++) {
		if(eText && eText.id != "eMain"){
			if(eTest == 1){
				var eTextL = eText.tagName.toUpperCase();
				if(eTextL == eValue || eTextL == eValue2 || eTextL == eValue3 || eTextL == eValue4)
					return "on";
				eText = eText.parentNode;
			}
			if(eTest == 2){
				var eTextL = eText.className.toUpperCase();
					if(eTextL.indexOf(eValue) >= 0)
						return "on";
				eText = eText.parentNode;
			}
			if(eTest == 3){
				var eTextL = eText.tagName.toUpperCase();
				if(eTextL == eValue || eTextL == eValue2 || eTextL == eValue3 || eTextL == eValue4){
					eFound = 1;
					eText = eText.parentNode;
				}
			}
			if(eTest == 4){
				if(!eText.isContentEditable)
					return 1;
				eText = eText.parentNode;
			}
		}
	}
	if(eFound)
		return eText;
}
function eClassSet(){
	var ctrl = cPanel.sClass.options;
	var eSelected;
	var eTest;
	for(var ii = 1; ii < ctrl.length; ii++) {
		if((ctrl(ii).selected = eCheckParents(2,ctrl(ii).innerText.toUpperCase())) == "on"){
			eSelected = ii;
			break;
		}
	}
	if(!eSelected)
		ctrl(0).selected = "on";
}
function eTagSet(){
	var ctrl = cPanel.sTag.options;
	var eSelected;
	for(var ii = 0; ii < ctrl.length; ii++) {
		if(eCheckParents(1,ctrl(ii).innerText.toUpperCase()) == "on"){
			ctrl(ii).selected = "on";
//		if(ctrl(ii).selected = eCheckParents(1,ctrl(ii).innerText.toUpperCase()) == "on")
			eSelected = ii;
		}
	}
	if(!eSelected)
		ctrl(0).selected = "on";
}
function eResetMenu(){
	var ctrl = cPanel.document.getElementsByTagName("img")
	for(var ii = 0; ii < ctrl.length; ii++) {
		if(ctrl(ii).className == "butn"){
			ctrl(ii).name = "";
		}
	}
}
function eSetMenu(){
	var ctrl = cPanel.document.getElementsByTagName("img")
	for(var ii = 0; ii < ctrl.length; ii++) {
		if(ctrl(ii).className == "butn"){
			if(ctrl(ii).name == "on"){
				ctrl(ii).style.backgroundColor = 'buttonHighlight';
				// Depressed border
				ctrl(ii).style.borderTop = '1px solid threedShadow';
				ctrl(ii).style.borderLeft = '1px solid threedShadow';
				ctrl(ii).style.borderBottom = '1px solid threedHighlight';
				ctrl(ii).style.borderRight = '1px solid threedHighlight';
			} else {
				ctrl(ii).style.backgroundColor = 'buttonFace';
				ctrl(ii).style.borderColor = '';
			    ctrl(ii).style.border = '1px solid';
			}
		}
	}
}

function eMenuCtrl(){
	sTextG = window.event.srcElement;
	// Hide menu controls unless focus is on menu item
	cPanel.bNewDir.style.visibility = "visible";	// Menu item may be added
	cPanel.bNewPage.style.visibility = "visible";	// SubMenu item may be added
	cPanel.eMenuSet();

}

// ------------------------------------ Calendar functions ------------------------------------

function calendar(whereTo){
	if (!document.getElementById) return;
	var months = ["", "January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	var days = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
	//                         J F M A M J J A S O N D
	var monthAdj = new Array(0,0,3,3,6,1,4,6,2,5,0,3,5);	// For leap years
	var monYr = document.getElementById("calMonYr");
	var calPrv = document.getElementById("calPrv");
	var calNxt = document.getElementById("calNxt");
	var calRO = document.getElementById("calReadOnly");
	var date_required = document.getElementById("date_required");
	var dateRe = /(\d+)-(\d+)-(\d+)/;
	var mName = /(\w+)\s(\d+)/;

	var current = mName.exec(monYr.innerText);
	var calx;
	var month = month2num(months,current[1]);
	var year = eval(current[2]);

	current = new Date();
	var yearNow = current.getFullYear();
	var monthNow = current.getMonth()+1;
	var dayNow = current.getDate();

	current = dateRe.exec(date_required.value);
	if(current){
		var yearRequired = current[1];
		var monthRequired = current[2];
		var dayRequired = current[3];
	} else {
		var yearRequired = yearNow;
		var monthRequired = monthNow;
		var dayRequired = dayNow;
	}
	
	dateSelected = dateRe.exec(whereTo);
	if(dateSelected){
		date_required.value = dateSelected[0];
		current = dateRe.exec(date_required.value);
		yearRequired = current[1];
		monthRequired = current[2];
		dayRequired = current[3];
		year = eval(current[1]);
		month = eval(current[2]);
		day = eval(current[3]);
	}
	if(whereTo){
		if(whereTo == "nxt"){
			month++;
			if(month > 12){
				year++;
				month = 1;
			}
		}
		if(whereTo == "prv"){
			month--;
			if(month < 1){
				year--;
				month = 12;
			}
		}
		if(whereTo == "toggle_month"){
			month += 3;
			if(month > 12){
				month %= 12;
				year++;
			}
			if(year <= yearNow){
				year = yearNow;
				if(month < monthNow)
					month = monthNow;
			}
		}
		if(whereTo == "toggle_year"){
			if(year > yearNow){
				year = yearNow;
				if(month < monthNow)
					month = monthNow;
			} else {
				year++;
			}
		}
	}
	if(year < yearNow || (year == yearNow && month < monthNow) || (year == yearNow && month == monthNow && day < dayNow)){
		year = yearNow;
		month = monthNow;
		day = dayNow;
		yearRequired = yearNow;
		monthRequired = monthNow;
		dayRequired = dayNow;
		date_required.value = yearNow + '-' + monthNow + '-' + dayNow;
	}
	monYr.innerHTML = '<a href="javascript:onClick=calendar(\'toggle_month\');" title="Forward 3 months">' + months[month] + '</a> <a href="javascript:onClick=calendar(\'toggle_year\');" title="Step +/- 1 year">' + year + '</a>';

	if(year * 12 + month > yearNow * 12 + monthNow){	// Allow 'Previous' month <<
		calPrv.innerHTML = '<a href="javascript:onClick=calendar(\'prv\');" title="Back 1 month"><<</a>';	// chevrons
	} else {
		calPrv.innerHTML = "<<<";
	}

	// Calculate weekday for 1st of the month. 0 = Monday
	var dayOfWeek = 5 + (year - 2000) * 365 + Math.floor((year - 2000 + 3) / 4);
	dayOfWeek += monthAdj[month];
	if(Math.floor((year - 2000) / 4) == (year - 2000) / 4){
		var leapYr = 1;
	}
	if(leapYr && month > 2){
		dayOfWeek++;
	}
	dayOfWeek %= 7;
	var firstDay = dayOfWeek;

	calx = document.getElementById("calPrv");
	var col = 0;
	// Fill blank spaces if Monday is not the first of the month
	for(firstDay; firstDay>0; firstDay--) {
		calx = document.getElementById("cal"+col);
		calx.innerHTML = "&nbsp;";
		calx.style.border = "none";
		calx.style.color = "black";
		calx.style.backgroundColor = 'Transparent';
		col++;
	}
	// Fill calendar with days 1-28 etc
	var weekendOk = document.getElementById("weekend");
	var todayOk = document.getElementById("today");
	for(var day=1; day<32; day++) {
		if(year == yearRequired && month == monthRequired && day == dayRequired) {	// Required date
			calx = document.getElementById("cal"+col);
			calx.style.color = "white";
			calx.style.backgroundColor = "black";
			calx.innerHTML = day;
		} else {
			if(year == yearNow && month == monthNow && day == dayNow) {	// Todays date
				calx = document.getElementById("cal"+col);
				calx.style.border = "none";
				calx.style.color = "white";
				calx.style.backgroundColor = "silver";
				if(todayOk){
					calx.innerHTML = "<a href=\"javascript:onClick=calendar('" + year + "-" + month + "-" + day + "')\";>" + day + "</a>";
				} else {
					calx.innerHTML = day;
				}
			} else {
				if(col % 7 >= 5){	// Weekend
					calx = document.getElementById("cal"+col);
					calx.innerHTML = day;
					calx.style.border = "none";
					calx.style.color = "silver";
					calx.style.backgroundColor = 'Transparent';
					if(weekendOk && ((year > yearNow || (year == yearNow) && (month > monthNow || (month == monthNow) && day > dayNow)))){
						calx.innerHTML = "<a href=\"javascript:onClick=calendar('" + year + "-" + month + "-" + day + "')\";>" + day + "</a>";
					} else {
						calx.innerHTML = day;
					}
				} else {
					if((year > yearNow || (year == yearNow) && (month > monthNow || (month == monthNow) && day > dayNow))) {	// Future
						calx = document.getElementById("cal"+col);
						calx.innerHTML = "<a href=\"javascript:onClick=calendar('" + year + "-" + month + "-" + day + "')\";>" + day + "</a>";
						calx.style.border = "none";
						calx.style.color = "black";
						calx.style.backgroundColor = 'Transparent';
					} else {
						calx = document.getElementById("cal"+col);
						calx.innerHTML = day;
						calx.style.border = "none";
						calx.style.color = "black";
						calx.style.backgroundColor = 'Transparent';
					}
				}
			}
		}
		col++;
		if(day >= 30 && (month == 4 || month == 6 || month == 9 || month == 11)){
			break;
		}
		if(!leapYr && day >= 28 && month == 2){
			break;
		}
		if(leapYr && day >= 29 && month == 2){
			break;
		}
	}
	// Fill any trailing spaces at end of table
	for(col; col<35; col++) {
		calx = document.getElementById("cal"+col);
		calx.innerHTML = "&nbsp;";
		calx.style.border = "none";
		calx.style.color = "black";
		calx.style.backgroundColor = 'Transparent';
	}
	// Create extra rows if necessary to give six rows in total
	for(col; col<42; col++) {
		calx = document.getElementById("cal"+col);
		calx.innerHTML = "&nbsp;";
		calx.style.border = "none";
		calx.style.color = "black";
		calx.style.backgroundColor = 'Transparent';
	}

	if(calRO){
		if(dayRequired < 10)
			dayRequired = '0' + eval(dayRequired);

		if(monthRequired < 10)
			monthRequired = '0' + eval(monthRequired);

		if(dayRequired == 0){
			dayRequired = '??';
			document.Events.eventtbc.checked = 'on';
		} else {
			document.Events.eventtbc.checked = '';
		}

		calRO.value = dayRequired + '-' + monthRequired + '-' + yearRequired;
	}

}

function month2num(months,mnth){
	for(var ii=1;ii<13;ii++){
		if(months[ii] == mnth){
			return ii;
		}
	}
	return 1;
}

function jEvent(eChoice) {
	// Update event table
	var ctrl = document.Events.eventlinks.options;
	document.Events.eventlinks.style.backgroundColor = 'transparent';
	document.Events.eventlinks.style.color = document.body.style.color;
	var eChoiceAr = eChoice.text.split(',');

	if(eChoice.text != 'New event'){
		document.Events.what.value = eChoiceAr[1].slice(1);	// slice(1) to remove leading space

		// Link page
		var eSelected;
		for(var ii = 1; ii < ctrl.length; ii++) {
			if(ctrl(ii).value == eChoiceAr[2].slice(1)){
				ctrl(ii).selected = "on";
				eSelected = ii;
				break;
			}
		}
		if(!eSelected){	// None found
			ctrl(0).selected = "on";
			if(eChoiceAr[2].slice(1) != ''){	// None found but Link page in database
				document.Events.eventlinks.style.backgroundColor = '#990000';
				document.Events.eventlinks.style.color = 'white';
			}
		}


		document.Events.where.value = eChoiceAr[3].slice(1);
		document.Events.zip.value = eChoiceAr[4].slice(1);
		document.Events.when.value = eChoiceAr[5].slice(1);
		calendar(eChoiceAr[0]);
	}
}

// -------------------------------------- File functions --------------------------------------

function eDownloadFile(eFileName) {
	cPanelOut = '<form style="display: none;" name="downLoad" method="post" enctype="multipart/form-data" action="">';
	cPanelOut += '	<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />';
	cPanelOut += '	<input type="hidden" name="xMenu" value="" />';
	cPanelOut += '	<input type="hidden" name="update" value="downloadFile" />';
	cPanelOut += '</form>';

	downloads.innerHTML = cPanelOut;

	document.downLoad.xMenu.value = eFileName;
	document.downLoad.submit();

	downloads.innerHTML = '';
}

function jSelect(eChoice) {
	window.location.href = "_users.html?choice=" + eChoice.value
}

// ---------------------------------------- Useful ---------------------------------------

// Countdown timer - Number of days until an event
//function eCountDown(eTarget) {
function eCountDown() {
	eTarget = new Date("2005 October 12");
	eCurrent = new Date();
	eDays = Math.ceil((eTarget - eCurrent) / 1000 / 60 / 60 / 24);
	if(eDays > 0){
		document.write('Days to my birthday: ' + eDays);
	}
//	return(eDays);
}

// ---------------------------------------- Development ---------------------------------------

