
function UpdateStates(field_state, field_country) {
	var tmp_form = document.forms['thisform'];
	var tmp_country = eval('tmp_form.' + field_country + '.options[tmp_form.' + field_country + '.selectedIndex].value');
	ajax_field_state = field_state;
	ajax_field_country = field_country;
	if (location.href.indexOf('/bema/') > -1) {
		AjaxGet('../ajax/states.cfm?country=' + tmp_country, UpdateStatesReply)
	} else {
		AjaxGet('ajax/states.cfm?country=' + tmp_country, UpdateStatesReply)
	}
}

function UpdateStatesReply() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			
			var tmp_form = document.forms['thisform'];
			var form_states = eval('tmp_form.' + ajax_field_state);
			if (form_states.hasChildNodes()) {
				var selected = eval('tmp_form.' + ajax_field_state + '.options[tmp_form.' + ajax_field_state + '.selectedIndex].value');
			} else { var selected = ''; }

			if (form_states.hasChildNodes()) {
				while (form_states.firstChild) {
					form_states.removeChild(form_states.firstChild);
				}
			}

			var states = req.responseXML.getElementsByTagName('state');

			if (states.length > 0) {

				var first_one = "";

				for (var i = 0; i < states.length; i++) {
					var state = states.item(i);
					if (state != null && state.hasChildNodes()) {
						var tmp_option = document.createElement("OPTION");
						tmp_option.setAttribute('value', state.getAttribute('abbrev'));
						var tmp_text = document.createTextNode(state.firstChild.nodeValue);
						tmp_option.appendChild(tmp_text);
						form_states.appendChild(tmp_option);
						if (first_one == '') { first_one = state.getAttribute('abbrev'); }
					}
				}

				if (selected == '') { selected = first_one; }
				if (browser.isIE == true) { var tmp_value = 'block'; } else { var tmp_value = 'table-row'; }
				document.getElementById('row_' + ajax_field_state).style.display = tmp_value;
				document.getElementById('row_' + ajax_field_state + '_other').style.display = 'none';
				eval('tmp_form.' + ajax_field_state + '.value = selected');

			} else {

				if (browser.isIE == true) { var tmp_value = 'block'; } else { var tmp_value = 'table-row'; }
				document.getElementById('row_' + ajax_field_state).style.display = 'none';
				document.getElementById('row_' + ajax_field_state + '_other').style.display = tmp_value;
				eval('tmp_form.' + ajax_field_state + '.value = \'\'');

			}
		}
	}
}
