$(function() {
  
  // override the submit of the form
  
  $('#register_member_form').submit(function() {
    var u = $('input[name=username]').val();
    var e = $('input[name=email]').val();
    
    if (u != e || (u == '' && e == '')) {
      alert('Email Address and Confirmation must be the same (and not blank). Please review the email addresses you entered.');
      $('input[name=username], input[name=email]').css({ background: '#F5CCCB' });
      return false;
    }
  });
  
  // settings
  
  var StateCountries = {
    'United States of America': 'AK',
    'United Kingdom': 'Eastern',
    'Canada': 'AB',
    'default': 'None'
  };
  
  // when the country drop down changes
  
  $('select[name=m_field_id_14]').change(function(e) {

    $this = $(this);
    
    var this_val = $this.val();
    
    var switch_to = StateCountries['default'];
    
    if (StateCountries[this_val]) {
      switch_to = StateCountries[this_val];
    }
    
    $('select[name=m_field_id_12]').val(switch_to);
    
  });
  
});