
function UpdateShippingMethods() {
	tmp_country = document.forms['thisform'].country.options[document.forms['thisform'].country.selectedIndex].value;
	var myAjax = new Ajax.Request(
		'ajax-shippingmethods.cfm',
			{
				method: 'get',
				parameters: 'country=' + tmp_country,
				onComplete: UpdateShippingMethodsResponse
			}
		);
}

function UpdateShippingMethodsResponse(req) {

	var form_shippingmethods = document.forms['thisform'].shippingmethodid;
	if (form_shippingmethods.hasChildNodes()) {
		var selected = document.forms['thisform'].shippingmethodid.options[document.forms['thisform'].shippingmethodid.selectedIndex].value;
	} else { var selected = ''; }

	// Clear Select
	if (form_shippingmethods.hasChildNodes()) {
		while (form_shippingmethods.firstChild) {
			form_shippingmethods.removeChild(form_shippingmethods.firstChild);
		}
	}

	// Retrieve States Via Ajax
	var shippingmethods = req.responseXML.getElementsByTagName('shippingmethod');
	
	// Any States?
	if (shippingmethods.length > 0) {

		// Define Variables
		var first_one = "";
		var found = 0;
		
		// Loop Through Results And Add To Select
		for (var i = 0; i < shippingmethods.length; i++) {
			var shippingmethod = shippingmethods.item(i);
			if (shippingmethod != null && shippingmethod.hasChildNodes()) {
				var temp_option = document.createElement("OPTION");
				temp_option.setAttribute('value', shippingmethod.getAttribute('id'));
				var the_text = document.createTextNode(shippingmethod.firstChild.nodeValue + '  ');
				temp_option.appendChild(the_text);
				form_shippingmethods.appendChild(temp_option);
				if (first_one == '') { first_one = shippingmethod.getAttribute('id'); }
				if (selected == shippingmethod.getAttribute('id')) { found = 1; }
			}
		}

		if (found == 0) { selected = first_one; }
		document.forms['thisform'].shippingmethodid.value = selected;
	}
}
