/* this upDownMultiple functions differently from others -- dg (6/20/03) */



function moveLeftRightMultiple(selectName, selectTo) 
{
  //get list of which items to move over

  var index=0;
  var counter=0;
  var selectedItems = new Array("Z");
  from_select = document.getElementById(selectName);
  to_select = document.getElementById(selectTo);
  
  while ( index< from_select.length) {
  	if (from_select.options[index].selected) {
	  	selectedItems[counter] = index;
		from_select.options[index].selected = false;
		counter++;
    }
	index++;
  }
  //check to see that there is at least one selected
  if (selectedItems[0]=="Z"){
  	    alert("Please select an item first");
		return;
  }
  counter=selectedItems.length-1;
  index=from_select.length-1;
  while ( index >= 0) {
	for (count = 0; count < from_select.length; count++){
			from_select.options[count].selected = false;
	}
    if (selectedItems[counter] == index) {
		from_select.options[index].selected = true;
		moveLeftRight(selectName, selectTo);
		counter--;
   	}
    index--;
  }
}


function moveLeftRight(selectFrom, selectTo) 
{
  from_select = document.getElementById(selectFrom);
  to_select = document.getElementById(selectTo);
  o_sl = from_select.selectedIndex;
  d_sl = to_select.length;
  if (o_sl != -1 && from_select.options[o_sl].value > "") {
    oText = from_select.options[o_sl].text;
    oValue = from_select.options[o_sl].value;
    from_select.options[o_sl] = null;
    to_select.options[d_sl] = new Option (oText, oValue, true, true);
  } else {
    alert("Please select a module first");
  }
}  


function moveUpDownMultiple(direction, selectName){
  // when direction = "up" then it moves the selected item up, otherwise, it moves it down

  //get list of which items to move upwards
  selectObj = document.getElementById(selectName);
  var index=0;
  var counter=0;
  var selectedItems = new Array("Z");
  while ( index< selectObj.length) {
  	if (selectObj.options[index].selected) {
	  	selectedItems[counter] = index;
		counter++;
    }
	index++;
  }
  //check to see that there is at least one selected
  if (selectedItems[0]=="Z"){
  	    alert("Please select an item first");
		return false;
  }
  //move all the ones selected
  index=0;
  counter=0;

  if (direction == "up") {
      if (selectObj.options[0].selected)
	     return;
      counter=0;
	  index=0;
		//alert("cheese");
      while ( index < selectObj.length) {
		  if (selectedItems[counter] == index) {
		      sl=index;
		  	  if (sl != -1) {
			    oText = selectObj.options[sl].text;
			    oValue = selectObj.options[sl].value;

			    if (sl > 0) {
			      selectObj.options[sl].text = selectObj.options[sl-1].text;
			      selectObj.options[sl].value = selectObj.options[sl-1].value;
			      selectObj.options[sl-1].text = oText;
			      selectObj.options[sl-1].value = oValue;
			      selectObj.selectedIndex--;
			    }
			  }
			  counter++;
		  }
		  index++;
	  }
  }
  else if (direction == "down") {
      if (selectObj.options[selectObj.options.length-1].selected)
	     return;
      counter=selectedItems.length-1;
      index=selectObj.length-1;
      while ( index >= 0) {
		  if (selectedItems[counter] == index) {
		      sl=index;
		  	  if (sl != -1) {
			    oText = selectObj.options[sl].text;
			    oValue = selectObj.options[sl].value;
			    if (sl < selectObj.length-1) {
			      selectObj.options[sl].text = selectObj.options[sl+1].text;
			      selectObj.options[sl].value = selectObj.options[sl+1].value;
			      selectObj.options[sl+1].text = oText;
			      selectObj.options[sl+1].value = oValue;
			      selectObj.selectedIndex++;
			    }
			  }
			  counter--;
		  }
		  index--;
	  }
  }
  //because by moving them we mess up which ones are selected, deselect all of them, then reselect the appropriate ones
  index=0;
  while ( index < selectObj.length) {
  	selectObj.options[index].selected = false;
	index++;
  }
  index=0;
  if (direction == "up")
  	offset = 1;
  else
    offset = -1;
  while (index<selectedItems.length){
    if ( (selectedItems[index]-offset > -1) && (selectedItems[index]-offset < selectObj.length) ){
	    selectObj.options[selectedItems[index]-offset].selected = true;
	}
 	index++;
  }
  return true;
}

function selectAll(selectName, formname){
  var index=0;
  selectObj = document.getElementById(selectName);
  while ( index < selectObj.length) {
  	selectObj.options[index].selected = true;
	index++;
  }
}

function selectAllID(selectName){
  var sourceObj = document.getElementById(selectName);
  var targetObj = document.getElementById("LAST" + selectName);

	var index=0;
	while ( index < sourceObj.length) {
		myValue = sourceObj.options[index].text.replace(/,/g,"~");
		if ( (myValue == "")  ){
			myValue = "thereIsNoInfoInThisElement";
		}
		//alert(myValue);
		targetObj.options[index] = new Option(myValue,myValue,true,true);
		index++;
	}
  sourceObj.disabled = true;
}
	
function deleteSelected(selectName, formname) {
	// deletes the selected item in the list
	var selectObj = document.getElementById(selectName);
	sl = selectObj.selectedIndex;
	if (sl != -1) {
	    selectObj.options[sl]=null; 
    } else {
		alert("Please select an item to be deleted first");
		return false;
	}
	return true;
}	
/*
function deleteSelected(selectName, formname) {
  // deletes the selected item in the list
  var selectObj = document.getElementById(selectName);
  sl = selectObj.selectedIndex;
  if (sl != -1 && selectObj.options[sl].value > "") {
    //if (confirm("This will delete the selected module.")) {
	if (true) {
        if (selectObj.options[sl].value != ".none") {
          if (selectObj.length==1) {
            selectObj.options[0].text="";
            selectObj.options[0].value=".none";
          } else {
            selectObj.options[sl]=null; 
          } 
        } else {
          alert("Please select an item first");
		  return false;
        }
      }
    }
	return true;
}
*/
