var validator;

$(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
}); 


$(document).ready(function() {

  $('a[rel]').overlay();

  validator = $('form#new_registration').validate({
    rules: {
      "registration[firstname]": "required",
      "registration[lastname]": "required",
      //"registration[street]": "required",
      //"registration[locality]": "required",
      //"registration[region]": "required",
      //"registration[postal_code]": {
      //  required: true,
      //  minlength: 5
      //},
      //"registration[phone]": "required",
      "registration[email]": {
        required: true,
        email: true
      },
      //"registration[apt_size]": "required",
      //"registration[contact_pref]": "required",
      //"registration[broker]": "required",
      "registration[company_name]": {
        required: {
          depends: function(element) {
            return $("#registration_broker_true:checked").length;
          }
        }
      }
    },
    messages: {
      "registration[firstname]": "Please enter your first name.",
      "registration[lastname]": "Please enter your last name.",
      "registration[street]": "Please enter your street address.",
      "registration[locality]": "Please enter your city.",
      "registration[region]": "Please enter your state",
      "registration[postal_code]": "Please enter your zip code",
      "registration[phone]": "Please enter your phone number.",
      "registration[email]": {
        required: "Please enter your email address.",
        email: "Please double check the format of your email address."
      },
      "registration[apt_size]": "Please select the size of apartment you are looking for.",
      "registration[contact_pref]": "Please select how you would prefer to be contacted.",
      "registration[broker]": "Please select whether you are a broker.",
      "registration[company_name]": "Please enter the name of your company."
    },
    errorLabelContainer: "div.errors",
    highlight: function(element, errorClass) {
      if($('#' + element.id + ':radio').length > 0)
        $(element).siblings('.question').addClass(errorClass);
      else
        $(element).addClass(errorClass);
    },
    unhighlight: function(element, errorClass) {
      if($('#' + element.id + ':radio').length > 0)
        $(element).siblings('.question').removeClass(errorClass);
      else
        $(element).removeClass(errorClass);
    }
  });

  $("button#reset").click(function() {
  	validator.resetForm();
  });

});
