$().ready(function() {

  // validate signup form on keyup and submit
  $("#property").validate({
    rules: {
      email: {
        email: true,
        required: true
      },
      zip: {
        digits: true,
        required: true,
        rangelength: [5,5]
      },
      property_address: {
        required: true
      },
      property_city: {
        required: true
      },
      property_zip: {
        digits: true,
        required: true,
        rangelength: [5,5]
      }
    },
    messages: {
      email:            "Please enter a valid email address",
      zip:              "Please enter your five digit zipcode",
      property_zip:     "Please enter the five digit zipcode of the forclosed property",
      property_address: "Please enter the address of the forclosed property",
      property_city:     "Please enter the city of the forclosed property"
    },
    submitHandler: function(form) {

      var address = $("#property_address").val() + ', ' + $("#property_city").val() + ', California, ' + $("#property_zip").val();

      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
            alert(address + " not found");
          } else {
            $("#lat").val(point.y);
            $("#lng").val(point.x);
            form.submit();
          }
        }
      );

    }
  });

});

