jQuery(document).ready(
    function ()
    {                
        jQuery('#zipcode').live("keypress", function(e) {
                if (e.keyCode == 13) {
                    SearchZipCode();
                }
        });
        
        jQuery('#searchButton').bind("click", function(){            
            SearchZipCode();
                          
            //jQuery('#contactFormArea').css('display', 'none');
            //LoadSeries(jQuery(this).val());
        });
        
     });
     
function SearchZipCode()
{
    if(jQuery("#zipcode").val() == '')
    {
        alert("Please enter a valid zip code");
        return;
    }
    jQuery("#dealerResult").html("Searching nearest local dealers...");
    jQuery.getJSON("/locator.php?z=" + jQuery("#zipcode").val(), function(data)
    {
       var output = [];
       if(data.Error != null)
       {
           jQuery("#dealerResult").html('');
           alert(data.Error);
           return;
       }
       jQuery.each(data, function(index, item)
       {
          output.push("<div class='dealerEntry'><div style='width:200px'><b>" + item.Name + "</b></div><div style='width:400px'>" + item.Street + ", " + item.City + "," + item.State + " " + item.Zip + " " + item.Country + "</div><div style='width:100px'>&nbsp;" + item.Phone + "</div><div style='width:100px;text-align:right;'>" + item.Distance + " miles</div></div>");
       });
       if(output.length < 1)
        jQuery("#dealerResult").html("Unable to locate any dealer within 100 miles from your area.  Please <a href='/contact'>contact us</a> for dealer information.");
       else
        jQuery("#dealerResult").html(output.join("\r\n"));
    });
}