$(function(){
  
  var checkedPostalCode = '';
  
  $('#postalCode').bind("keyup",function(){
  
        if ($(this).val().length == 4){
          
          if ($(this).val().length != 0 && $(this).val() != checkedPostalCode){
  
              if ( $('#City').val().length == 0 ){
  
              checkedPostalCode = $(this).val();             
              $.post("ajaxpublic/getcity", { postalCode: $(this).val() },
                  function(data){
                    if (data.length){
                        $('#City').val(data);
                    }
              });
                  
             }
  
          }

        }
  
  });



  $('#City').change(function(){
  
        if ($(this).val().length != 0){

            if ( $('#postalCode').val().length == 0 ){
                
            $.post("ajaxpublic/getpostalcode", { city: $(this).val() },
                function(data){
                  if (data.length){
                      $('#postalCode').val(data);
                  }
            });
                
            }

        }
  
  });




});
