﻿//
// Validates that we have a UK postcode format
// or that the text box is empty
// For use with the postcode control
//
function ValidatePostCode()
{
	var txtPCode = $('input[id*="txtPostCode"]');
	var ValidForReturn = false;
	
	if (txtPCode.length > 0 && (txtPCode.val() != "Post Code" && txtPCode.val() != ""))
	{
		var ptext = txtPCode.val();

		var re = new RegExp('(GIR 0AA|GIR0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKPS-UW]) [0-9][ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKPS-UW])[0-9][ABD-HJLNP-UW-Z]{2})', 'i');

		if (re.exec(ptext))
		{
			ValidForReturn = true;
		}
	}
	else
	{
		ValidForReturn = true;
	}

	if (ValidForReturn)
	{
		$("#PostCodeVal").hide();
	}
	else
	{
		$("#PostCodeVal").show();
	}
	
	return ValidForReturn;

}
