// takes in the document IDs of the select boxes that the options move between
function moveOptions(fromId,toId) {
	// get the actual input objects
	from = document.getElementById(fromId);
	to = document.getElementById(toId);
	
	// save contents of "to"
	var arr = new Array();
	for (i = 0; i < to.options.length; i++) {
		arr[arr.length] = new Option(to.options[i].text, to.options[i].value, false, false);
	}
	
	// add new options to the list
	for (i = 0; i < from.options.length; i++) {
		o = from.options[i];
		if (o.selected) {
			arr[arr.length] = new Option(o.text, o.value, false, false);
		}
	}
	
	// sort the new list of options
	arr = arr.sort( 
		function(a,b) { 
			if (a.text < b.text) return -1;
			if (a.text > b.text) return 1;
			return 0;
		} 
	);

	// copy options back into "to"
	for (var i = 0; i < arr.length; i++) {
		to.options[i] = new Option(arr[i].text, arr[i].value, false, false);
	}
	
	// delete options from "from"
	for (i = from.options.length - 1; i >= 0; i--) {
		o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
		}
	}
	
	//clear selections
	from.selectedIndex = -1;
	to.selectedIndex = -1;
}


// takes in the ID of the selectbox that we are saving the values from, and the ID of the form element into which the
// values will be stored
function saveValuesToInput(selectBoxId, inputId) {
	selectBox = document.getElementById(selectBoxId);
	values = "";
	for (i = 0; i < selectBox.options.length; i++) {
		values += selectBox.options[i].value + ",";		
	}
	
	// trim trailing comma
	if (values.length > 0) {
		values = values.substring(0, values.length - 1);		
	}
	
	document.getElementById(inputId).value = values;
}