$(document).ready(function() {
  $("input[name='shipping_data_shipping_zip']").length > 0 && $("input[name='shipping_data_shipping_zip']").keyup(function() {
    if($(this).val().length == 4) {
      var e = $(this).val(), f = {"background-image":"url(/images/cms-ajax-loader.gif)", "background-position":"98% center", "background-repeat":"no-repeat"};
      $("input[name='shipping_data_shipping_city']").css(f);
      $.post("/postcodes", {pc_code:e}, function(a) {
        var b = {"background-image":"none"};
        $("input[name='shipping_data_shipping_city']").css(b);
        if(a.status) {
          $("#cityselector").remove();
          if(a.result.length > 1) {
            b = $("<div/>").attr("id", "cityselector").append($("<label/>").text("V\u00e1lassza ki a telep\u00fcl\u00e9st:"));
            for(var d = $("<select/>").attr("name", "ps_city_selector").addClass("input_select"), c = 0;c < a.result.length;c++)d.append($("<option/>").val(a.result[c].pc_city).text(a.result[c].pc_city));
            d.change(function() {
              $("input[name='shipping_data_shipping_city']").val($(this).val())
            });
            b.append(d);
            $("input[name='shipping_data_shipping_zip']").after(b)
          }$("input[name='shipping_data_shipping_city']").val(a.result[0].pc_city)
        }else {
          $("#cityselector").remove();
          $("input[name='shipping_data_shipping_city']").val("Nincs ilyen telep\u00fcl\u00e9s")
        }
      }, "json")
    }
  });
  $("input[name='new_shipping_data_shipping_zip']").length > 0 && $("input[name='new_shipping_data_shipping_zip']").keyup(function() {
    if($(this).val().length == 4) {
      var e = $(this).val(), f = {"background-image":"url(/images/cms-ajax-loader.gif)", "background-position":"98% center", "background-repeat":"no-repeat"};
      $("input[name='new_shipping_data_shipping_city']").css(f);
      $.post("/postcodes", {pc_code:e}, function(a) {
        var b = {"background-image":"none"};
        $("input[name='new_shipping_data_shipping_city']").css(b);
        if(a.status) {
          $("#new_cityselector").remove();
          if(a.result.length > 1) {
            b = $("<div/>").attr("id", "new_cityselector").append($("<label/>").text("V\u00e1lassza ki a telep\u00fcl\u00e9st:"));
            for(var d = $("<select/>").attr("name", "ps_city_selector").addClass("input_select"), c = 0;c < a.result.length;c++)d.append($("<option/>").val(a.result[c].pc_city).text(a.result[c].pc_city));
            d.change(function() {
              $("input[name='new_shipping_data_shipping_city']").val($(this).val())
            });
            b.append(d);
            $("input[name='new_shipping_data_shipping_zip']").after(b)
          }$("input[name='new_shipping_data_shipping_city']").val(a.result[0].pc_city)
        }else {
          $("#new_cityselector").remove();
          $("input[name='new_shipping_data_shipping_city']").val("Nincs ilyen telep\u00fcl\u00e9s")
        }
      }, "json")
    }
  });
});
