function removeFromList( srcList ) {
	if (srcList.selectedIndex == -1 ) {
		return;
	}
	
	srcList.options[srcList.selectedIndex] = null;
}

function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}

function selectAllOptions(selStr) {
  var selObj = document.getElementById(selStr);
  for (var i=0; i<selObj.options.length; i++) {
    selObj.options[i].selected = true;
  }
}

function getSelectedValue(elmID) {
	var selObj = document.getElementById(elmID);
	return selObj.options[selObj.selectedIndex].value;
}

function moveOptionUp(obj) {
	if(!hasOptions(obj)){
		return;
	}
	
	for(i=0;i<obj.options.length;i++){
		if(obj.options[i].selected){
			if(i != 0 && !obj.options[i-1].selected){
				swapOptions(obj,i,i-1);obj.options[i-1].selected = true;
			}
		}
	}
}

function moveOptionDown(obj){
	if(!hasOptions(obj)){
		return;
	}
	
	for(i=obj.options.length-1;i>=0;i--){
		if(obj.options[i].selected){
			if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
			}
		}
	}
}

function moveDualList( srcList, destList, moveAll ) {

  // Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   ) {
	
    return;
  }

  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ )  {
    if ( destList.options[ len ] != null ) {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
	
	var remove = new Array();

  for( var i = 0; i < srcList.options.length; i++ ) { 
	
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ){
		//alert(i);
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, false);
       len++;
		
		// Remove from the old list
		//srcList.options[i] = null;
		remove[remove.length] = i;
    }
	
  }

	remove.sort();
	remove.reverse();

	for(i in remove) {
		srcList.options[remove[i]] = null;
	}

  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) {
    if ( newDestList[ j ] != null ){
      destList.options[ j ] = newDestList[ j ];
    }
  }
}