
	function removeSpaces(string) 
	{
		return string.split(' ').join('');
	}

	function validatePostcode(postcode) 
	{
		postcode = removeSpaces(postcode);
		postcode = postcode.toUpperCase();
		
		size = postcode.length;		
		
		//Code length rule
		if (size < 5 || size > 7)
		{ 
		  	alert(postcode + " is not a valid postcode - wrong length");
		  	return false;
		}
		
		//leftmost character must be alpha character rule
		if ( !(isNaN(postcode.charAt(0))) )
		{ 
		   alert(test + " is not a valid postcode - cannot start with a number");
		   return false;
		 }
		 
		 //first character of inward code must be numeric rule
		 if ( isNaN(postcode.charAt(size-3)) )
		 {
		   alert(postcode + " is not a valid postcode.");
		   return false;
		 }
		 
		 //second character of inward code must be alpha rule
		 if ( !(isNaN(postcode.charAt(size-2))) ){ 
		   alert(postcode + " is not a valid postcode.");
		   return false;
		 }
		 
		 //third character of inward code must be alpha rule
		 if ( !(isNaN(postcode.charAt(size-1))) )
		 { 
		   alert(postcode + " is not a valid postcode - number in wrong position");
		   return false;
		 }
		 
		 /*//space in position length-3 rule
		 if (!(postcode.charAt(size-4) == " "))
		 {
		   alert(postcode + " is not a valid postcode - no space or space in wrong position");
		   return false;
		 }*/
	
		return true;
	
	}