// JavaScript Document
var minTextSize = 0.7;
var maxTextSize = 1.5;
var defaultSize = 1;
var textSizeUnits = 'em';

function addBookmark(title,url)
{
	if (window.sidebar)							// Mozilla Firefox Bookmark
	{
		window.sidebar.addPanel(title, url,"");
	}
	else if (window.external)					// IE Favorite
	{
		window.external.AddFavorite( url, title);
	}
	else if (window.opera && window.print)		// Opera Hotlist
	{
		return true;
	}
}

function modifyTextSize(adjust)
{
	bodySize = document.body.style.fontSize;
	currSize = Number(bodySize.substr(0, bodySize.length - 2));
	newSize = Number(currSize) + Number(adjust);

	if (newSize < Number(minTextSize))
		newSize = minTextSize;

	if (newSize > Number(maxTextSize))
		newSize = maxTextSize;

	if (adjust == null)
		newSize = defaultSize;
	else if (Number(adjust) == -99)
		newSize = defaultSize;

	createCookie('textAdjust', newSize - defaultSize, 28);
	document.getElementById('a1').style.fontSize = newSize + textSizeUnits;
	document.getElementById('a2').style.fontSize = newSize + textSizeUnits;
	document.getElementById('a3').style.fontSize = newSize + textSizeUnits;
	document.body.style.fontSize = newSize + textSizeUnits;

	return true;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ')
			c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function runOnloadTasks(headlines, newsLinks)
{
	modifyTextSize(readCookie('textAdjust'));
	runNewsTicker(headlines, newsLinks);
	MyReload();
	anylinkcssmenu.init("anchorclass")
	return true;
}


function MyReload() { 
if (window.name != 'CPPHT') { 
location.reload(true); 
window.name = "CPPHT"; 
} 
} 

function showHideDownloadContents(rowName)
{
	//downloadImg_
	var els = document.getElementsByTagName('div');
	var el;
	var currState = els[rowName].style.display;

	for (el in els)
		if (els[el].id != null)
			if (els[el].id != '')
			{
				els[el].style.display = 'none';

				if (document.getElementById('downloadImg_' + els[el].id.substr(10)))
				{
					document.getElementById('downloadImg_' + els[el].id.substr(10)).src = 'images/expandPlus.gif';
					document.getElementById('downloadImg_' + els[el].id.substr(10)).alt = 'Expand this section';
					document.getElementById('downloadImg_' + els[el].id.substr(10)).title = 'Expand this section';
				}

				if (document.getElementById('expandLink_' + els[el].id.substr(10)))
				{
					document.getElementById('expandLink_' + els[el].id.substr(10)).innerHTML = 'expand';
					document.getElementById('expandLink_' + els[el].id.substr(10)).title = 'Expand this section';
				}
			}

	if (currState == 'none')
	{
		els[rowName].style.display = '';

		if (document.getElementById('downloadImg_' + rowName.substr(10)))
		{
			document.getElementById('downloadImg_' + rowName.substr(10)).src = 'images/expandMinus.gif';
			document.getElementById('downloadImg_' + rowName.substr(10)).alt = 'Collapse this section';
			document.getElementById('downloadImg_' + rowName.substr(10)).title = 'Collapse this section';
		}

		if (document.getElementById('expandLink_' + rowName.substr(10)))
		{
			document.getElementById('expandLink_' + rowName.substr(10)).innerHTML = 'collapse';
			document.getElementById('expandLink_' + rowName.substr(10)).title = 'Collapse this section';
		}
	}

	return true;
}

function showHideNews()
{
	if (document.getElementById('hiddenNews'))
		if (document.getElementById('hiddenNews').style.display == 'none')
			document.getElementById('hiddenNews').style.display = '';
		else
			document.getElementById('hiddenNews').style.display = 'none';

	return true;
}

function checkField(fieldObj, errMsg)
{
	if (fieldObj.value == '')
	{
		alert (errMsg);
		fieldObj.focus();
		return false;
	}

	return true;
}

function checkEmail(fieldObj, emptyMsg, invalidMsg)
{
	if (fieldObj.value == '')
	{
		alert (emptyMsg);
		fieldObj.focus();
		return false;
	}

	if (fieldObj.value.indexOf('@') == -1 || fieldObj.value.lastIndexOf('.') < fieldObj.value.indexOf('@'))
	{
		alert (invalidMsg);
		fieldObj.focus();
		return false;
	}

	return true;
}

function checkITYHLogin(form)
{
	if (!checkField(form.txtAccNo, 'Please enter your account number.'))
		return false;

	if (!checkField(form.txtPostCode, 'Please enter your post code.'))
		return false;

	return true;
}

function checkAILogin(form)
{
	if (!checkField(form.txtPostCode, 'Please enter your post code.'))
		return false;

	return true;
}

function checkCCCForm(form)
{
	if (!checkField(form.txtName, 'Please enter your name.'))
		return false;

	if (!checkField(form.txtAddress, 'Please enter your address.'))
		return false;

	if (form.txtPhone.value == '' && form.txtEmail.value == '')
	{
		alert ('Please enter either your contact number or your email, or both.');
		form.txtPhone.focus();
		return false;
	}

	if (form.txtEmail.value != '')
		if (!checkEmail(form.txtEmail, 'Please enter your email address.', 'Please enter your email address. The address entered is not a valid email address.'))
			return false;

	if (!checkField(form.txtFeedback, 'Please enter your feedback.'))
		return false;

/*
	if (form.optMale.checked == false && form.optFemale.checked == false)
	{
		alert ('Please select your gender.');
		form.optMale.focus();
		return false;
	}

	if (form.optDisabilityYes.checked == false && form.optDisabilityNo.checked == false)
	{
		alert ('Please indicate whether you consider yourself to have a disability.');
		form.optDisabilityNo.focus();
		return false;
	}

	if (form.optWhiteBritish.checked == false && form.optWhiteIrish.checked == false && 
		form.optWhiteOther.checked == false && form.optWhiteBlackCaribbean.checked == false &&
		form.optWhiteBlackAfrican.checked == false && form.optWhiteAsian.checked == false &&
		form.optMixedOther.checked == false && form.optIndian.checked == false &&
		form.optPakistani.checked == false && form.optBangladeshi.checked == false &&
		form.optAsianOther.checked == false && form.optCaribbean.checked == false &&
		form.optAfrican.checked == false && form.optBlackOther.checked == false &&
		form.optChinese.checked == false && form.optOther.checked == false)
	{
		alert ('Please indicate your ethnicity.');
		form.optWhiteBritish.focus();
		return false;
	}
*/
	return true;
}

function checkPayRent(form)
{
	if (form.txtAccNo.value == '')
	{
		alert('Please enter your account number. This is a 9 digit number.');
		form.txtAccNo.focus();
		return false;
	}

	if (isNaN(form.txtAccNo.value))
	{
		alert('Please check your account number. This should be a 9 digit number.');
		form.txtAccNo.focus();
		return false;
	}

	if (form.txtSurname.value == '')
	{
		alert('Please enter the surname associated with your account number.');
		form.txtSurname.focus();
		return false;
	}

	if (form.txtToPay.value == '')
	{
		alert('Please enter the amount you would like to pay.');
		form.txtToPay.focus();
		return false;
	}

	if (form.txtToPay.value.substr(0, 1) == "£")
		form.txtToPay.value = form.txtToPay.value.substr(1);

	if (isNaN(form.txtToPay.value))
	{
		alert('Please enter the amount you would like to pay. This needs to be a number WITHOUT the pound sign.');
		form.txtToPay.focus();
		return false;
	}

	return true;
}

function checkLogRepair(form)
{
	if (!checkField(form.txtName, 'Please enter your name.'))
		return false;

	if (!checkField(form.txtAddress, 'Please enter your address.'))
		return false;

	if (!checkField(form.txtContactNumber, 'Please enter your contact number.'))
		return false;

	if (!checkEmail(form.txtEmail, 'Please enter your email address.', 'Please enter your email address. The address entered is not a valid email address.'))
		return false;

	if (!checkField(form.txtRepair, 'Please enter details of the repair.'))
		return false;

	if (!checkField(form.txtLocation, 'Please enter the location of the repair.'))
		return false;

	return true;
}

function checkSALogin(form)
{
	if (!checkField(form.txtUsername, 'Please enter your username.'))
		return false;

	if (!checkField(form.txtPassword, 'Please enter your password.'))
		return false;

	return true;
}

function checkMyDetails(form)
{
	if (!checkField(form.txtFullName, 'Please enter your full name.'))
		return false;

	if (!checkField(form.txtUsername, 'Please enter your desired username.'))
		return false;

	if (!checkField(form.txtPassword, 'Please enter your current password.'))
		return false;

	if (form.txtNewPassword.value != form.txtConfirm.value)
	{
		form.txtPassword.value = '';
		form.txtNewPassword.value = '';
		form.txtConfirm.value = '';
		alert('New passwords do not match. Please re-enter your password');
		form.txtPassword.focus();
		return false;
	}

	if (!checkEmail(form.txtEmail, 'Please enter your email address.', 'Please enter your email address. The address entered is not a valid email address.'))
		return false;

	return true;
}

function checkChangeDetails(form)
{
	if (form.hidResetPass.value != 'Reset')
	{
		if (!checkField(form.txtFullName, 'Please enter your full name.'))
			return false;

		if (!checkEmail(form.txtEmail, 'Please enter email address.', 'Please enter email address. The address entered is not a valid email address.'))
			return false;

		if (!checkField(form.txtUsername, 'Please enter your desired username.'))
			return false;
	}

	return true;
}

function showHideAdminLevelDesc(val, maxVal)
{
	//Hide all the relevant tables
	for (var x = 1; x <= maxVal; x++)
		document.getElementById('L_' + x + '_Admin').style.display = 'none';

	//show the requested table
	document.getElementById('L_' + val + '_Admin').style.display = '';

	return true;
}

function checkNewAccount(form)
{
	if (!checkField(form.txtFullName, 'Please enter the new users full name.'))
		return false;

	if (!checkField(form.txtUsername, 'Please enter the new users desired username.'))
		return false;

	if (!checkField(form.txtPassword, 'Please enter the new users password.'))
	{
		form.txtConfirm.value = '';
		return false;
	}

	if (!checkField(form.txtConfirm, 'Please confirm the new users password.'))
	{
		form.txtPassword.value = '';
		return false;
	}

	if (form.txtPassword.value != form.txtConfirm.value)
	{
		alert('Passwords do not match. Please re-enter both passwords.');
		form.txtPassword.value = '';
		form.txtConfirm.value = '';
		form.txtPassword.focus();
		return false;
	}

	if (!checkEmail(form.txtEmail, 'Please enter the new users email address.', 'Please enter the new users email address. The address entered is not a valid email address.'))
		return false;

	return true;
}

function checkHL(form)
{
	if (document.getElementById('txtCaption').value == '')
	{
		alert('Please enter a caption to go under the hot link image.');
		document.getElementById('txtCaption').focus();
		return false;
	}

	return true;
}

function checkAddHLImage(form)
{
	if (!checkField(form.txtFileName, 'Please select an image to upload.'))
		return false;

	var fileExt = form.txtFileName.value;
	fileExt = fileExt.substr(fileExt.lastIndexOf('.') + 1);

	if (fileExt != 'jpg' && fileExt != 'gif' && fileExt != 'jpeg')
	{
		alert('Images must be saved either as "gif" or "jpg" format.');
		form.txtFileName.value = '';
		form.txtFileName.focus();
		return false;
	}

	form.txtAltName.value = form.txtNewName.value.replace(/ /g, '_');

	return true;
}

function checkAddCustMag(form)
{
	if (form.txtName.value == '')
	{
		alert('Please enter the edition name.');
		form.txtName.focus();
		return false;
	}

	if (form.editing.value == 'no')
		if (form.txtPDFFileName.value == '')
		{
			alert('Please select the PDF file for users to download.');
			form.txtPDFFileName.focus();
			return false;
		}

	if (form.txtPDFFileName.value.substr(form.txtPDFFileName.value.lastIndexOf('.')) != '.pdf' && form.txtPDFFileName.value != '')
	{
		alert('The file selected in the \'PDF File\' box must be a \'.pdf\' file. Please select a valid file.');
		form.txtPDFFileName.focus();
		return false;
	}

	form.txtAltName.value = form.txtName.value.replace(' ', '_');

	return true;
}

function checkEvent(form)
{
	if (form.txtEvent.value == '')
	{
		alert('Please enter the event description.');
		form.txtEvent.focus();
		return false;
	}

	if (form.txtLocation.value == '')
	{
		alert('Please enter the event location.');
		form.txtLocation.focus();
		return false;
	}

	var daysInMonth = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (form.selYear.value % 4 == 0)
		daysInMonth[2] = 29;

	if (form.selDay.value > daysInMonth[form.selMonth.value])
	{
		alert('Please select a valid date.');
		form.selDay.focus();
		return false;
	}

	return true;
}

function addSideBorder(leftSideEl, rightSideEl, borderStyle)
{
	leftHeight = leftSideEl.offsetHeight;
	rightHeight = rightSideEl.offsetHeight;

	if (leftHeight > rightHeight)
	{
		leftSideEl.style.borderRight = borderStyle;
		rightSideEl.style.borderLeft = 'none';
	}
	else	
	{
		leftSideEl.style.borderRight = 'none';
		rightSideEl.style.borderLeft = borderStyle;
	}

	return true;
}

function checkAddNewPage(form)
{
	if (form.txtFileName.value == '')
	{
		alert('Please enter the file name.');
		form.txtFileName.focus();
		return false;
	}

	if (form.txtFileName.value.indexOf(' ') != -1 || form.txtFileName.value.indexOf('.') != -1 || form.txtFileName.value.indexOf('/') != -1 || form.txtFileName.value.indexOf('\\') != -1)
	{
		alert('Please check the file name. The file name must not contain spaces, full stops, or slashes.');
		form.txtFileName.focus();
		return false;
	}

	if (form.txtMenuText.value == '')
	{
		alert('Please enter the menu text. This is the text that will appear on the menu.');
		form.txtMenuText.focus();
		return false;
	}

	if (form.txtPageTitle.value == '')
	{
		alert('Please enter a page title. This is the text which will appear in the title bar on the browser.');
		form.txtPageTitle.focus();
		return false;
	}

	return true;
}

function checkAddNewSec(form)
{
	if (form.txtSecName.value == '')
	{
		alert('Please enter a name for the new section. This will appear on the top menu.');
		form.txtSecName.focus();
		return false;
	}

	if (form.txtFileName.value == '')
	{
		alert('Please enter the file name.');
		form.txtFileName.focus();
		return false;
	}

	if (form.txtFileName.value.indexOf(' ') != -1 || form.txtFileName.value.indexOf('.') != -1 || form.txtFileName.value.indexOf('/') != -1 || form.txtFileName.value.indexOf('\\') != -1)
	{
		alert('Please check the file name. The file name must not contain spaces, full stops, or slashes.');
		form.txtFileName.focus();
		return false;
	}

	if (form.txtMenuText.value == '')
	{
		alert('Please enter the menu text. This is the text that will appear on the menu.');
		form.txtMenuText.focus();
		return false;
	}

	if (form.txtPageTitle.value == '')
	{
		alert('Please enter a page title. This is the text which will appear in the title bar on the browser.');
		form.txtPageTitle.focus();
		return false;
	}

	return true;
}

function showHideDataTable(pathToImages)
{
	imgEl = document.getElementById('viewDTImage');
	linkEl = document.getElementById('viewDT');
	DTEl = document.getElementById('dataTable');

	if (DTEl.style.display == '')
	{
		DTEl.style.display = 'none';
		imgEl.src = pathToImages + 'minus.gif';
		linkEl.innerHTML = 'View data table';
	}
	else
	{
		DTEl.style.display = '';
		imgEl.src = pathToImages + 'plus.gif';
		linkEl.innerHTML = 'Hide data table';
	}

	return;
}

function popUp(url, width, height)
{
	if (isNaN(width) || width == '') { width = 400; }
	if (isNaN(height) || height == '') { height = 300; }

	window.open(url, 'popUpWindow','width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,menubar=0,scrollbars=1');
	return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}