function isValidZipCode(value) {
  var re = /^\d{5}([\-]\d{4})?$/;
  return (re.test(value));
}

(function($) {
  var geocoder = null;
  zillow = {};
  zillow.lookup = function(address) {
    geocoder.geocode({'address': address}, function(results, status) {
      if (status != google.maps.GeocoderStatus.OK) {
        $('#errors').show().text('Unable to locate address');
        return;
      }
      $('#map_area').show();

      var result = results[0]
      var address = result.formatted_address;
      var location = result.geometry.location;

      var map = new google.maps.Map(document.getElementById("map"), {
        zoom: 15,
        center: location,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
      var marker = new google.maps.Marker({
        position: location, 
        map: map, 
        title: address
      });
      $('#external_map').click(function() {
        chrome.tabs.create({
          url: 'http://maps.google.com?near=' + address
        });
        return false;
      });
      
      var street_address = address.split(',')[0];
      var zip = null;
      $.each(result.address_components, function() {
        if (isValidZipCode(this.short_name) && isValidZipCode(this.long_name)) {
          zip = this.short_name;
        }
      });
      var data = {
        'zws-id': 'X1-ZWz1csm2cyipsb_6plsv', 
        'address': street_address,
        'citystatezip': zip
      };
      $.get('http://www.zillow.com/webservice/GetSearchResults.htm', data, function(xml) {
        if ($(xml).find('message code').text() != '0') {
          $('#errors').show().text($(xml).find('message text').text());
          return;
        }
        $('#errors').hide();
        $('#zestimate').show();
        $('#home_details').click(function() {
          chrome.tabs.create({
            url: $(xml).find('links homedetails').text()
          });
        });

        var result = $(xml).find('result');
        var zestimate = result.find('zestimate');

        $('#estimate').text(zestimate.find('amount').text());
        var valuation = zestimate.find('valuationRange');
        $('#estimate_low').text(valuation.find('low').text());
        $('#estimate_high').text(valuation.find('high').text());
      });
    });
  };
  $(function() {
    $('#form').submit(function() {
      zillow.lookup($('#address').val());
      return false;
    });
    geocoder = new google.maps.Geocoder();
  });
})(jQuery);

@@ -156,36 +156,198 @@
 low.
-lookup = function(address) %7B
+api_key = 'X1-ZWz1csm2cyipsb_6plsv';%0A  zillow.findAddress = function(address, callback) %7B%0A    $('#map_area').hide();%0A    %0A    if (geocoder == null) %7B geocoder = new google.maps.Geocoder(); %7D
 %0A   
@@ -1181,24 +1181,260 @@
  %7D);%0A      %0A
+      callback(result);%0A    %7D);%0A  %7D;%0A  zillow.findEstimate = function(address) %7B%0A    $('#errors').hide();%0A    $('#zestimate').hide();%0A    %0A    zillow.findAddress(address, function(result) %7B%0A      var address = result.formatted_address;%0A
       var st
@@ -1721,33 +1721,22 @@
 d': 
-'X1-ZWz1csm2cyipsb_6plsv'
+zillow.api_key
 , %0A 
@@ -1818,12 +1818,28 @@
   $.
-get(
+ajax(%7B%0A        url: 
 'htt
@@ -1894,14 +1894,91 @@
 tm',
- data,
+%0A        data: data,%0A        dataType: 'xml',%0A        type: 'GET',%0A        success:
  fun
@@ -1994,24 +1994,26 @@
 ) %7B%0A        
+  
 if ($(xml).f
@@ -2045,24 +2045,26 @@
 ) != '0') %7B%0A
+  
           $(
@@ -2129,32 +2129,34 @@
 ;%0A          
+ 
+ 
 return;%0A
         %7D%0A  
@@ -2139,24 +2139,26 @@
     return;%0A
+  
         %7D%0A  
@@ -2161,35 +2161,8 @@
 %7D%0A  
-      $('#errors').hide();%0A
     
@@ -2185,24 +2185,26 @@
 e').show();%0A
+  
         $('#
@@ -2239,32 +2239,34 @@
 n() %7B%0A          
+  
 chrome.tabs.crea
@@ -2262,32 +2262,34 @@
 e.tabs.create(%7B%0A
+  
             url:
@@ -2331,36 +2331,40 @@
 ext()%0A          
+  
 %7D);%0A
+  
         %7D);%0A%0A   
@@ -2356,24 +2356,26 @@
        %7D);%0A%0A
+  
         var 
@@ -2410,24 +2410,26 @@
 ');%0A        
+  
 var zestimat
@@ -2455,24 +2455,26 @@
 stimate');%0A%0A
+  
         $('#
@@ -2527,24 +2527,26 @@
 ));%0A        
+ 
+ 
 var valuatio
@@ -2579,24 +2579,26 @@
 ionRange');%0A
+  
         $('#
@@ -2640,32 +2640,34 @@
 'low').text());%0A
+  
         $('#esti
@@ -2711,24 +2711,34 @@
 ').text());%0A
+        %7D%0A
       %7D);%0A  
@@ -2748,16 +2748,17 @@
 );%0A  %7D;%0A
+%0A
   $(func
@@ -2818,14 +2818,20 @@
 low.
-lookup
+findEstimate
 ($('
@@ -2881,51 +2881,8 @@
 %7D);%0A
-    geocoder = new google.maps.Geocoder();%0A
   %7D)

refactor and extract helper methods