﻿function validateLocationForm()
{
        this.messages = [];
        if (document.getElementById('pc').value == '') {
            this.messages.push('Postal Code is a required field.');
        }

        if (!(isPostCode(document.getElementById('pc').value))) {
            this.messages.push('Postal Code appears to be invalid.');
        }
      
        if (this.messages.length > 0) {
            var alerts = 'Please review the following:\n\n';
            this.messages.each(function(item, index) {
                alerts += item + '\n';
            });
            alert(alerts);
            return false;
        }
        return true;
}

function isPostCode(entry)
    {
        strlen = entry.length; //if (strlen !== 6) { return false; }
        entry=entry.toUpperCase();
        if (' '.indexOf(entry.charAt(3)) < 0) 
        {
            if ('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0)) < 0) { return false; }
            if ('0123456789'.indexOf(entry.charAt(1)) < 0) { return false; }
            if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) { return false; }
            if ('0123456789'.indexOf(entry.charAt(3)) < 0) { return false; }
            if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4)) < 0) { return false; }
            if ('0123456789'.indexOf(entry.charAt(5)) < 0) { return false; } 
            return true;
        }
    else
        {
            if ('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0)) < 0) { return false; }
            if ('0123456789'.indexOf(entry.charAt(1)) < 0) { return false; }
            if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) { return false; }
            if (' '.indexOf(entry.charAt(3)) < 0) {return false;}
            if ('0123456789'.indexOf(entry.charAt(4)) < 0) { return false; }
            if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(5)) < 0) { return false; }
            if ('0123456789'.indexOf(entry.charAt(6)) < 0) { return false; } 
            return true;
        }
    }

