function checkForm(form)
{
	var strPostcode = form.p.value;
	if ((strPostcode=="") || (strPostcode==null))
	{
		alert("No postcode entered, please try again");
		return false;
	}
	if (strPostcode.length < 5)
	{
		alert("Invalid postcode entered, please try again");
		return false;
	}
	strPostcode = strPostcode.toUpperCase();

	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
		}
	}
	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;
	}

	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 (!isNaN(strUnit))
	{
		alert("Invalid postcode entered, please try again");
		return false;
	}

	strPostcode = strArea + strDistrict + ' ' + strSector + strUnit;

	form.p.value = strPostcode;
	
	var strTelnum = form.t.value;
	if ((strTelnum != "") && (strTelnum.length < 10))
	{
		alert("Invalid phone number entered, please try again");
		return false;
	}
	
	form.CheckNow.value = "Checking...";
	return true;
}


function explain(name, msg) {
newwin = window.open('','','top=150,left=150,width=180,height=150');
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<head><title>' + name + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title></head>');
write('<body><p style="font-family: arial,sans-serif;text-align: center;font-size: .8em;">' + msg);
write('<br><br><a href="javascript:window.close()">Close</a></p>');
write('</body></html>');
close();
   }
}


function processForm()
{
	if (CheckPostcode(document.CheckerForm))
	{
		document.CheckerForm.submit();
	}
}
