@@ -1,26 +1,34 @@
 // $Id: address.js,v 1.1.2.3.4.1 2007/02/03 11:04:45 gordon Exp $

-if (Drupal.jsEnabled) {
-  $(document).ready( function () {
-    $('#edit-country').each( function () {
-      Drupal.addressToggleFields(this.options[this.selectedIndex].value);
-    });
-    $('#edit-state').each( function () {
-      this.remove(this.length-1);
-    });
-    $('#edit-country').change( function() {
-      Drupal.addressToggleFields(this.options[this.selectedIndex].value);
-    });
+$(function () {
+  $('#edit-country').change( function() {
+    Drupal.addressToggleFields($('#edit-country').val());
   });
-}
+  Drupal.addressToggleFields($('#edit-country').val());
+});

 Drupal.addressToggleFields = function(country) {
-  if (country == 'us') {
-    $('#wrapper-province').hide();
-    $('#wrapper-state').show();
+  if (Drupal.settings.states[country]) {
+    var states = '<option value="0">Please choose...</option>';
+    for (state in Drupal.settings.states[country]) {
+      states = states + '<option value="'+ state +'">'+ Drupal.settings.states[country][state] +"</option>";
+    }
+    $('#wrapper-state input').remove();
+    $('#wrapper-state select').remove();
+    $('#wrapper-state').append('<select name="state" class="form-select" id="edit-state" >');
+    $('#edit-state').html(states);
+    if (Drupal.settings.current_state[0] == country) {
+      $('#edit-state').val(Drupal.settings.current_state[1]);
+      Drupal.settings.current_state[0] = "";
+    }
   }
   else {
-    $('#wrapper-province').show();
-    $('#wrapper-state').hide();
+    $('#wrapper-state input').remove();
+    $('#wrapper-state select').remove();
+    $('#wrapper-state').append('<input type="text" maxlength="64" name="state" id="edit-state"  size="30" value="" class="form-text required" />');
+    if (Drupal.settings.current_state[0] == country) {
+      $('#edit-state').val(Drupal.settings.current_state[1]);
+      Drupal.settings.current_state[0] = "";
+    }
   }
-}
+}
\ No newline at end of file
