jQuery.noConflict();
jQuery(document).ready(function() {

jQuery('#zip').keyup(function() {
    if(jQuery(this).attr('value').length >= 5) {
        jQuery.getJSON('/zip.php?zip=' + jQuery(this).attr('value'), function(data) {
            if(data['city']) {
                jQuery('#city').attr('value', data['city']);
            }
            if(data['state']) {
                jQuery('#region_id *').each(function() {
                        if(jQuery(this).html() == data['state']) {
                                jQuery(this).attr('selected', 'selected');
                        }
                });
            }
        });
    }
});

});

postcode_id = '';
/*
jQuery(document).ready(function() {
	jQuery('input[id$=postcode]').keyup(function() {
		if(jQuery(this).attr('value').length >= 5)
			{
				postcode_id = jQuery(this).attr('id').replace('postcode', '');
				jQuery.getJSON('/zip.php?zip=' + jQuery(this).attr('value'), function(data) {
					if(data['city']) jQuery('input[id=' + postcode_id + 'city]').attr('value', data['city']);
					if(data['state'])
						{
							jQuery('select[id=' + postcode_id + 'region_id] *').each(function() {
									if(jQuery(this).html() == data['state'])
										jQuery(this).attr('selected', 'selected');
                });
            }
				});
			}
	});
});
*/

jQuery(document).ready(function() {

jQuery('#address_form_container input[id$=postcode]').keyup(function() {

    if(jQuery(this).attr('value').length >= 5) {
        postcode_id = jQuery(this).attr('id').replace('postcode', '');
	jQuery.getJSON('/zip.php?zip=' + jQuery(this).attr('value'), function(data) {
            if(data['city']) {
                jQuery('#address_form_container input[id$=' + postcode_id + 'city]').attr('value', data['city']);
            }
            if(data['state']) {
                jQuery('#address_form_container select[id$=' + postcode_id + 'region] *').each(function() {
                        if(jQuery(this).html() == data['state']) {
                                jQuery(this).attr('selected', 'selected');
                        }
                });
            }
        });
    }
});

});

