function domSwap(fromList, toList) {
// If nothing is selected then return
var selIndex = fromList.selectedIndex;
if(selIndex < 0) { return; }

// If adding a header then return
for(var i = fromList.length - 1; i >= 0; i--) {
	if(fromList.options.item(i).selected) {
		// Append to the toList unsorted initially
		//alert(fromList.options.item(i).value);
		if(fromList.options.item(i).value == '===') { return; }
	}
}



// Prepare variables
var arrLookup = new Array(); // To quickly find the index of the text
var arrToList = new Array(); // To use JavaScripts builtin sort
var newToList = toList.cloneNode(false); // Only clone the parent

// Decrement to keep the changing index from affecting the moves
for(var i = fromList.length - 1; i >= 0; i--) {
arrLookup[fromList.options.item(i).text] = i;
if(fromList.options.item(i).selected) {
// Append to the toList unsorted initially
toList.appendChild(fromList.options.item(i));
}
}

// Prepare the sorting arrays
for( var i = 0; i < toList.length; i++) {
arrLookup[toList.options.item(i).text] = i;
arrToList[i] = toList.options.item(i).text;
}
arrToList.sort(); // <-- Where the action really occurs

// Decrement to keep the index from being affected
for( var i = arrToList.length - 1; i >= 0; i-- ) {
// Use insertBefore instead of appendChild because of decrementing.
newToList.insertBefore(toList.options.item(arrLookup[arrToList[i]]).cloneNode(true), newToList.options.item(0));
}

// Swap the unsorted node with the sorted one.
//toList.replaceNode(newToList);

// Deselect any selected options.
fromList.selectedIndex = -1;
toList.selectedIndex = -1;
}

function remItem(fromList, toList) {
// If nothing is selected then return
var selIndex = fromList.selectedIndex;
if(selIndex < 0) { return; }

// If adding a header then return
for(var i = fromList.length - 1; i >= 0; i--) {
	if(fromList.options.item(i).selected) {
		// Append to the toList unsorted initially
		//alert(fromList.options.item(i).value);
		if(fromList.options.item(i).value == '===') { return; }
		fromList.options[i]=null;
	}
}



// Prepare variables
var arrLookup = new Array(); // To quickly find the index of the text
var arrToList = new Array(); // To use JavaScripts builtin sort
var newToList = toList.cloneNode(false); // Only clone the parent

// Decrement to keep the changing index from affecting the moves
for(var i = fromList.length - 1; i >= 0; i--) {
arrLookup[fromList.options.item(i).text] = i;
if(fromList.options.item(i).selected) {
// Append to the toList unsorted initially
toList.appendChild(fromList.options.item(i));
}
}

// Prepare the sorting arrays
for( var i = 0; i < toList.length; i++) {
arrLookup[toList.options.item(i).text] = i;
arrToList[i] = toList.options.item(i).text;
}
arrToList.sort(); // <-- Where the action really occurs

// Decrement to keep the index from being affected
for( var i = arrToList.length - 1; i >= 0; i-- ) {
// Use insertBefore instead of appendChild because of decrementing.
newToList.insertBefore(toList.options.item(arrLookup[arrToList[i]]).cloneNode(true), newToList.options.item(0));
}

// Swap the unsorted node with the sorted one.
//toList.replaceNode(newToList);

// Deselect any selected options.
fromList.selectedIndex = -1;
toList.selectedIndex = -1;
}

function addItem(fromList, toList) {
// If nothing is selected then return
var selIndex = fromList.selectedIndex;
if(selIndex < 0) { return; }

// If adding a header then return
for(var i = fromList.length - 1; i >= 0; i--) {
	if(fromList.options.item(i).selected) {
		// Append to the toList unsorted initially
		//alert(fromList.options.item(i).value);
		if(fromList.options.item(i).value == '===') { return; }
	}
}



// Prepare variables
var arrLookup = new Array(); // To quickly find the index of the text
var arrToList = new Array(); // To use JavaScripts builtin sort
var newToList = toList.cloneNode(false); // Only clone the parent

// Decrement to keep the changing index from affecting the moves
for(var i = fromList.length - 1; i >= 0; i--) {
//arrLookup[fromList.options.item(i).text] = i;
if(fromList.options.item(i).selected) {
// Append to the toList unsorted initially
//toList.appendChild(makeNewOption(fromList.options.item(i).text));

toList.insertBefore(fromList.options.item(i).cloneNode(true), toList.options.item(0));
}
}

// Prepare the sorting arrays
for( var i = 0; i < toList.length; i++) {
arrLookup[toList.options.item(i).text] = i;
arrToList[i] = toList.options.item(i).text;
}
arrToList.sort(); // <-- Where the action really occurs

// Decrement to keep the index from being affected
for( var i = arrToList.length - 1; i >= 0; i-- ) {
// Use insertBefore instead of appendChild because of decrementing.
newToList.insertBefore(toList.options.item(arrLookup[arrToList[i]]).cloneNode(true), newToList.options.item(0));
}

// Swap the unsorted node with the sorted one.
//toList.replaceNode(newToList);

// Deselect any selected options.
//fromList.selectedIndex = -1;
//toList.selectedIndex = -1;
}

function makeNewOption(txt) {
var newItem = document.createElement("option");
newItem.innerHTML = txt;
return newItem;
}

function selectAllOptions(ref)
{
for(i=0; i<ref.options.length; i++)
ref.options[i].selected = true;
}
