function swapOptions( selectObj, i, j ) {
	var iOption = new Option(selectObj.options[i].text, selectObj.options[i].value, false, false);
	var jOption = new Option(selectObj.options[j].text, selectObj.options[j].value, false, false);
	
	selectObj.options[i] = jOption;
	selectObj.options[j] = iOption;
	selectObj.options[j].selected = true;
}

function moveItem( listBox, isUp ) {

	var changeMade = 0;
	if (listBox.value != '') {

		if (listBox.selectedIndex >= 0) {

			var numItems = listBox.options.length;

			// Find out the new order of the items
			var itemOrderArr = new Array(numItems);

			// Set up the initial ordering
			for( var i=0; i < numItems; i++ ) {
				itemOrderArr[i] = i;
			}

			// Do another pass
			var inEnd = true;  // Are we still in a block at the end that is selected?
			var i, temp;

			// moving up
			if( isUp == 1 ) {

				for( i=0; i < numItems; i++ ) {

					// first we skip all the selected items at the end
					if( !(inEnd && listBox[i].selected) ) {

						inEnd = false;

						// If the current item is selected, switch with the one above
						if( listBox[i].selected ) {
							changeMade = 1;
							temp = itemOrderArr[i-1];
							itemOrderArr[i-1] = itemOrderArr[i];
							itemOrderArr[i] = temp;
						}
					}
				}

			// moving down
			} else {

				for( i=numItems-1; i >= 0; i-- ) {

					// first we skip all the selected items at the end
					if( !(inEnd && listBox[i].selected) ) {
						inEnd = false;

						// If the current item is selected, switch with the one above
						if( listBox[i].selected ) {
							changeMade = 1;
							temp = itemOrderArr[i+1];
							itemOrderArr[i+1] = itemOrderArr[i];
							itemOrderArr[i] = temp;
						}
					}
				}
			}

			if( changeMade ) {

				// build an array of the new Ids and Text locations
				var itemIdArr = new Array(numItems);
				var itemNameArr = new Array(numItems);
				var itemSelectedArr = new Array(numItems);

				for( i=0; i < numItems; i++ ) {

					itemIdArr[i] = listBox[i].value;
					itemNameArr[i] = listBox[i].text;
					itemSelectedArr[i] = listBox[i].selected;
				}

				// Reorder the items
				var newPostion;
				for( i=0; i < numItems; i++ ) {
					newPosition = itemOrderArr[i];
					listBox[i].value = itemIdArr[newPosition];
					listBox[i].text = itemNameArr[newPosition];
					listBox[i].selected = itemSelectedArr[newPosition];
				}		
			}
		}
	}
	return changeMade;
}

function moveItem_OldWay( listbox, isUp ) {
	var changeMade = 0;

	if (listbox.selectedIndex >= 0) {
			
		var numItems = listbox.options.length;

		// Find out the new order of the items
		var itemOrderArr = new Array(numItems);
		
		// Set up the initial ordering
		for( var i=0; i < numItems; i++ ) {
			itemOrderArr[i] = i;	
		}
		
		// Do another pass 
		var inEnd = 1;  // Are we still in a block at the end that is selected?
		var i, temp;
		
		// moving up
		if( isUp ) {
		
			for( i=0; i < numItems; i++ ) {
				// first we skip all the selected items at the start
				if( !(inEnd && listbox[i].selected) ) {
					inEnd = 0;
								
					// If the current item is selected, switch with the one above	
					if( listbox[i].selected ) {		
						changeMade = 1;
						swapOptions( listbox, i, i-1 );
					}
				}
			}
		}
		// moving down
		else {
		
			for( i=numItems-1; i >= 0; i-- ) {											
				
				// first we skip all the selected items at the end
				if( !(inEnd && listbox[i].selected) ) {
					inEnd = 0;
								
					// If the current item is selected, switch with the one above	
					if( listbox[i].selected ) {		
						changeMade = 1;
						swapOptions( listbox, i, i+1 );
					}
				}											
			}
		}
	}
	return changeMade;
}