/**

 * Ajax update function for selectboxes.

 */

function xAutoUpdateSelectBox(update_field_id, url, add_field) {

	url = url + '&update_field=' + update_field_id;

	

	if(add_field != '') {

		var f = document.getElementById(add_field);

		url = url + '&parameter_data=' + f.value;

	}

	

	var ajax_request = new Ajax.Request(url, {method: 'get', onComplete: xAutoUpdateSelectBoxResponse});

}



function xAutoUpdateSelectBoxResponse(orgRequest) {
//alert(orgRequest.responseText);
	var selectbox_id = orgRequest.responseXML.getElementsByTagName('ajax-update-field')[0].firstChild.data;

	var selectbox = document.getElementById(selectbox_id);

	if(!selectbox) return;



	while (selectbox.options.length > 0) {

		selectbox.options[0] = null;

	}



	var options = orgRequest.responseXML.getElementsByTagName('option');

	for(var i = 0; i < options.length; i++) {

		var optn = document.createElement("OPTION");

		optn.text = options[i].firstChild.nodeValue;

		optn.value = options[i].getAttribute('value');
if (options[i].getAttribute('selected')){
//alert(options[i].getAttribute('selected'));
optn.selected = options[i].getAttribute('selected');
}
		selectbox.options.add(optn);

	}

}
