$(document).ready(function(){
  $("#submit").attr("disabled", "disabled");
  $("#js_form").css("display", "block");
  $("#form").css("display", "none");
  if($('#state').val() != "" ){
    jQuery.post("/county.php", { state: $("#state").val() }, function(data){
      $("#county").replaceWith(data);
    });
  }
  
  $("#state").change(function(){
    $('#submit').attr("disabled", "disabled");
    if($('#state').val() == ""){
      $("#county").attr("disabled", "disabled");
    } else {
      $("#county").replaceWith("<img src='http://www.publicrecordssearch.com/ajax-loader.gif' id='county'>");
      jQuery.post("/county.php", { state: $("#state").val() }, function(data){
        $("#county").replaceWith(data);
        initCounty();
		});
    }
  });
  
  function initCounty(){
    $("#county").change(function(){
      if($('#county').val() == ""){
        $("#submit").attr("disabled", "disabled");
      } else {
        $("#submit").removeAttr("disabled");
      };
    });
  }
  
  $('#submit').click(function(){
    window.location = "http://www.publicrecordssearch.com/state-records/" + $("#state").val() + "/" + $("#county").val() + "/";
    return false;
  })
  
});

