function update_region_field(src, dest, clear, callback) {
    $.getJSON('/countries/ajax/region-codes/'+$(src).val()+'/', function(json) {
       var parent = $(dest).parent();
       var value = $(dest).val()
       var attributes = $(dest)[0].attributes;
       var name = $(dest).attr('name');
       var stored = new Array(attributes.length);
       for (var index in attributes) {
	 var attribute = attributes[index];
	 if (attribute.nodeName == 'type') {
	      continue;
	 }
	 if (index == 'length') {
	      break; //weird bug?
	 }
	 var arr = new Array(2);
	 arr[0] = attribute.nodeName;
	 arr[1] = attribute.nodeValue;
	 stored[index] = arr;
       }
       var child_text = '';
       if (json.type == 'text') {
	 child_text = '<input type="text" id="'+dest.substring(1)+'" name="'+name+'"/>';
       } else {
	 child_text = '<select id="'+dest.substring(1)+'" name="'+name+'">'+json.html+'</select>';
       }
       parent.html(child_text);
       ndest = parent.children();
       for (var index in stored) {
	 var attribute = stored[index];
	 ndest.attr(attribute[0], attribute[1]);
       }
       if (!clear) {
	 ndest.val(value);
       }
        if(callback) callback();
    });
}

