function checkPasswords() {
  if ($('#edit-pass-pass1').val() == $('#edit-pass-pass2').val()) {
    $('#' + form_id + ' input:password').removeClass('error');
  }
  else {
    $('#' + form_id + ' input:password').addClass('error');
  }
}

$(function() {
  // create validator object:
  validator = $('#' + form_id).validate({
    errorPlacement: showValidationError
  });

  // require that the email field look like an email address:
  $('#edit-mail').addClass('email');
  
  // if we have passwords, add custom validation:
  if ($('#edit-pass-pass1').length > 0) {
    $.validator.addMethod('same', function(value, element) {
      return $('#edit-pass-pass1').val() == $('#edit-pass-pass2').val();
    }, "Passwords must match.");
    $('#edit-pass-pass1').rules('add', {same: true});
    $('#edit-pass-pass2').rules('add', {same: true});
    // capture any changes to the password fields so that we can change the style of both together:
    $('#' + form_id + ' input:password').keyup(checkPasswords).blur(checkPasswords);
  }
  
  // if we have country and state fields, customise and add AJAX connection:
  if ($('#edit-locations-0-province-wrapper').length > 0) {
    // replace the state autocomplete with a select box:
    $('#edit-locations-0-province-wrapper').html(
      "<label for='edit-state'>State/Province/County: </label>" +
      "<select name='state' class='form-select' id='edit-state'>" +
      "  <option value=''>Please Select</option>" +
      "</select>");

    // move country before state:
    $('#edit-locations-0-country-wrapper').insertBefore('#edit-locations-0-province-wrapper');
    // when the country selector changes, update the state selector:
    init_country_state('edit-locations-0-country', 'edit-state');
  }
  
  // move the address after the personal info fieldset:
  $('fieldset.location').insertAfter('fieldset.group-personal-info');
});

