function CheckPostcode(formfield)
{
	var strPostcode = formfield.GetValue();
	if ((strPostcode=="") || (strPostcode==null))
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}
	if (strPostcode.length < 5)
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}
	strPostcode = strPostcode.toUpperCase();

	// Strip all spaces and store the result in a new string...
	var strPostcode2 = ""
	var i, ch
	var validChars = /[a-zA-Z0-9]/
	for ( i = 0; i < strPostcode.length; i++ )
	{
		ch = strPostcode.charAt(i)
		if ( validChars.test(ch) )
		{
			strPostcode2 = strPostcode2 + ch
		}
	}

	var strIn, strOut;
	strOut = strPostcode2.substring(0,strPostcode2.length-3);
	strIn = strPostcode2.substring(strPostcode2.length-3);

	var n, strArea, strDistrict, strSector, strUnit;
	for (i = 1; i < 4; i++)
	{
		// Check each character in turn
		// First numeric digit is start of district code
		if(!isNaN(parseInt(strOut.charAt(i))))
		{
			strArea = strOut.substring(0, i);
			strDistrict = strOut.substring(i);
			break
		}
	}
	// Check that we found a number in the outward part of the postcode...
	if (i == 4)
	{
		alert("Invalid postcode entered, please try again.");
		return false
	}
	
	if (!isNaN(strArea))
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}

	if ((strArea.length > 2) || (strDistrict.length > 2))
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}

	// Inward code is simple...
	strSector = strIn.charAt(0);
	if (isNaN(strSector))
	{
		if (strSector == "O")
		{
			// The user has entered the letter "o" instead of the number zero
			strSector = "0";
		}
		else
		{
			alert("Invalid postcode entered, please try again.");
			return false;
		}
	}

	strUnit = strIn.substring(1);
	if ((strUnit.length != 2))
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}
	
	if (!(isNaN(strUnit.charAt(0)) && isNaN(strUnit.charAt(1))))
	{
		alert("Invalid postcode entered, please try again.");
		return false;
	}
	
	strOut = strArea + strDistrict;
	strIn = strSector + strUnit;
	if ((strOut.length == 4))
	{
		strPostcode = strOut + strIn;
	}
	else
	{
		strPostcode = strOut + ' ' + strIn;
	}

	formfield.SetValue(strPostcode);
	return true;
}

