- // when changing country, open up administrativearea choice
- function changeCountry(a2) {
- $(".autocompleteTarget[name='country']").attr('value',a2);
+ function setAddress(i, j, values)
+ {
+ var types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality');
+ var prev_type = types[i];
+ var next_type = types[j];
+ var next_list = next_type + '_list';
+
+ if (j == 3) {
+ $('tr#locality_text').hide()
+ $("select[name='localityTxt']").attr('value', '');
+ }
+
+ $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:values[i] }, function() {
+ if ($("select[name='" + next_type + "']").children("option").size() > 1) {
+ $("tr#" + next_list).show();
+ $("select[name='" + next_type + "']").attr('value', values[j]);
+ if (j < 6) {
+ setAddress(j, j + 1, values);
+ }
+ } else {
+ $("tr#" + next_list).hide();
+ $("select[name='" + next_type + "']").attr('value', '');
+ if (j < 6) {
+ setAddress(i, j + 1, values);
+ }
+ }
+ });