//Move one or more items from one <select> list to another
function FRL_move_select2select(fid, tid) {
	var fList = document.getElementById(fid);
	var tList = document.getElementById(tid);
	//To keep things simple just append the new entries
	//to the end of the target list
	for(var i=0; i<fList.options.length; i++) {
		if(fList.options[i].selected && fList.options[i] != "") {
			//Create a new option and append it to the target list
			var opt = new Option(fList.options[i].text, fList.options[i].value);
			tList.options[tList.options.length] = opt;
			//Remove the option form the source list
			fList.options[i] = null;
			//Adjust to account for the removal of the option from the source array
			i--;
		}
	}
}
//Moves one or more <select> options up one step
function FRL_move_select_up(lid) {
	var lst = document.getElementById(lid);
	if (lst.options.selectedIndex < 0) {
		alert("Error: You must select the item(s) to shift up the list");
		return;
	}
	if (lst.options.length < 2) {
		alert("Error: There must be at leaset two items in the list to change its order.");
		return;
	}
	if (lst.options.selectedIndex == 0) {
		alert("Error: The select the item is already at the top of the list.");
		return;
	}
	//Since the selectedIndex is the first we can skip right to the first,
	//if not only, move.
	for(var i=lst.options.selectedIndex; i<lst.options.length; i++) {
		if(lst.options[i].selected) {
			//Get short names for the current and previous options for convenience
			var cur = lst.options[i];
			var pre = lst.options[i - 1];
			//Create new options that swap the values
			var nPre = new Option(cur.text, cur.value, cur.defaultSelected, cur.selected);
			var nCur = new Option(pre.text, pre.value, pre.defaultSelected, pre.selected);
			//Assign the new values to their new locations
			lst.options[i] = nCur;
			lst.options[i - 1] = nPre;
		}
	}
}
//Moves one or more <select> options down one step
function FRL_move_select_down(lid) {
	var lst = document.getElementById(lid);
	if (lst.options.selectedIndex < 0) {
		alert("Error: You must select the item(s) to shift down the list");
		return;
	}
	if (lst.options.length < 2) {
		alert("Error: There must be at leaset two items in the list to change its order.");
		return;
	}
	if (lst.options[lst.options.length - 1].selected) {
		alert("Error: The select the item is already at the bottom of the list.");
		return;
	}
	//If you process the list from top to bottom the selected
	//option shoots to the bottom because it moves a
	//selected record into the next place to be checked.
	for(var i=lst.options.length - 1; i>=0; i--) {
		if(lst.options[i].selected) {
			//Get short names for the current and next options for convenience
			var cur = lst.options[i];
			var nxt = lst.options[i + 1];
			//Create new options that swap the values
			var nNxt = new Option(cur.text, cur.value, cur.defaultSelected, cur.selected);
			var nCur = new Option(nxt.text, nxt.value, nxt.defaultSelected, nxt.selected);
			//Assign the new values to their new locations
			lst.options[i] = nCur;
			lst.options[i + 1] = nNxt;
		}
	}
}
