//
// common.js
//

// Author: Colin Jaggs
// Date: 6th October 2004
// Description: Common JS functions use throughout the site

// common variables
var popUpWin = false;
var rollOvers = new Array();

// close any existing popup windows
function closePopups()
{
	if (popUpWin) popUpWin.close();
}

// only allow numbers to be entered in text boxes (usage: onKeyPress="return numberOnly()")
function numbersOnly(e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if ((keycode == 13) || ((keycode >= 48) && (keycode <= 57))) { return true; }
	else return false;
}

// ensure a text box can only contain a given number of characters
function charLimit(maxLength) { if (event.srcElement.value.length >= maxLength) return false; }

// check the number of characters in a text box and compare with the maximum number of characters allowed - call the updatecounter function to inform the user how many characters remain
function charCount(counterLabel, maxLength)
{ 
	if ((event.keyCode == 0) || (event.keyCode >= 40))
	{
		if (event.srcElement.name)
		{
			if (event.srcElement.value.length >= maxLength) event.srcElement.value = event.srcElement.value.substring(0, maxLength);
		}
	}
	updateCounter(counterLabel, event.srcElement, maxLength);
}

// update a counter label with the number of characters in a text box
function updateCounter(counterLabel, srcElement, maxLength)
{
	if (counterLabel) counterLabel.innerText = maxLength - srcElement.value.length;
}

function printerFriendly(url)
{
	if (popUpWin.open) popUpWin.close();
	
	popUpWin = window.open(url, "popupwin", "width=650,height=500,scrollbars=1,toolbar=1")
}
