function isDigit( c ) {
	return ! isNaN( parseInt( c ) );
}

function isLetter( c ) {
	var reLetter = /^[a-zA-Z]$/;
	return reLetter.test( c );
}

function handleKey(e) {
	var kC = ( e ) ? e.which : window.event.keyCode;
	var targ = ( e ) ? e.target : window.event.srcElement;
	if ( kC == 13 )
		return validatePC( targ.value );
}

function validatePC( inputPC ) {
	validPC = false;
	inputPC = inputPC.replace( / /g, "" ); // Replace any spaces in the field so was can parse a post code
	if ( inputPC.toUpperCase().indexOf( "BT" ) == 0 ) {
		validPC = inputPC.length <= 7;
		validPC = validPC && parseInt( inputPC.substring( 2, 4 ) ) != NaN;
		validPC = validPC && isDigit( inputPC.charAt(2) ) && isDigit( inputPC.charAt(3) );
		if ( inputPC.length == 7 ) {
			validPC = validPC && isDigit( inputPC.charAt(4) );
			validPC = validPC && isLetter( inputPC.charAt(5) ) && isLetter( inputPC.charAt(6) )
		} else {
			validPC = validPC && isLetter( inputPC.charAt(4) ) && isLetter( inputPC.charAt(5) )
		}
	} else
		// Must be a street/area name - proceed on that premise
		return true;
	
	if ( ! validPC )
		alert( "Sorry, this is not a valid Northern Ireland postcode.\n\nPlease try again or try a street/area name." );
	
	return validPC;
}
