$().ready(function() {
  $.validator.messages.required = "";
  $.validator.messages.email = ""; 
  $.validator.messages.number = "";
  
  $(".frmValidate").validate();
  $("input[rel^=date]").datepicker();
  
  $(".changeState").change(function() {    
    var country = $(this).val();
    var thisField = $(this).attr("id");
    var stateField = $(this).attr("rel");
    var state = $("#"+stateField).val();
    
    if (country=="US"||country=="CA"||country=="IE") {      
      $.getJSON("options.php",
        {f: (country=="US"?"us_states":(country=="CA"?"ca_provinces":(country=="IE"?"irish_states":""))) },
        function(j){        
          var options = "";
          for (var i = 0; i < j.length; i++) {
            options += "<option value=\"" + j[i].optionValue + "\"" + (j[i].optionValue==state?" selected=\"selected\"":"")+">" + j[i].optionDisplay + "</option>";
          }                  
          $("#"+stateField).html(options);
      });    
      $("#"+stateField).addClass("required");
      $("#span_"+stateField).show();
      $("#span_"+stateField+"_other").hide();      
    } else {
      $("#"+stateField).removeClass("required");
      $("#span_"+stateField).hide();
      $("#span_"+stateField+"_other").show();
    }
    $("#span_"+stateField+"_req").html((country=="US"||country=="IE"?"*":(country=="CA"?"*":"")));
  });
});
