function moveItems(ms_id, direction, lim)
{
  var j,lim_ctr=0;
  var itemexists;
  var nextitem;

  var opt_lim = "";

  if (lim && lim != "")
  {
  	opt_lim = lim;
  }

  var limArray = new Array(); // keep track of items' details


  if ( direction == "add" )
  {
    toCtrl = "target_select_"+ms_id;
    fromCtrl = "source_select_"+ms_id;
  }
  else
  {
    toCtrl = "source_select_"+ms_id;
    fromCtrl = "target_select_"+ms_id;
  }

  toCtrl = document.getElementById(toCtrl);
  fromCtrl = document.getElementById(fromCtrl);

//	alert("toCtrl options length: " + toCtrl.options.length + "\n Value: " + toCtrl.options[0].value + "\n has childnodes: " + toCtrl.options.hasChildNodes);

  remove_array = new Array();
  // step through all items in fromCtrl

  //	alert(fromCtrl.options.length+"\n"+toCtrl.options.length);

  for (var i = 0; i < fromCtrl.options.length; i++)
  {

    if (fromCtrl.options[i].selected)
    {
      // search toCtrl to see if duplicate
      j = 0;
      itemexists = false;
      while ((j < toCtrl.options.length) && (!(itemexists)))
      {
        if (toCtrl.options[j].value == fromCtrl.options[i].value)
        {
          itemexists = true;
          break;
          // alert(fromCtrl.options[i].value + " found!");
        }
        j++;
      }

      if (!(itemexists))
      {
      	if (ms_id == 111 && direction == "add")
      	{
	      	if (opt_lim != "")
	      	{
	      		if (toCtrl.options.length > 0)
	      		{
	      			lim_ctr = toCtrl.options.length;
	      		}
		      	lim_ctr++;
	      	}

	        // add the item
	        if (opt_lim != "" && lim_ctr <= opt_lim)
	        {
		        nextitem = toCtrl.options.length;
			    toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
		    	toCtrl.options[nextitem].value = fromCtrl.options[i].value;
		    	remove_array[remove_array.length] = i;
		    }
			if ( (opt_lim != "") && (lim_ctr > opt_lim) )
			{
				alert("Please limit your selections to " + opt_lim + ". ");
				break;
			}
		}
		else
		{
		        nextitem = toCtrl.options.length;
			    toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
		    	toCtrl.options[nextitem].value = fromCtrl.options[i].value;
		    	remove_array[remove_array.length] = i;
		}
      }
	}
  }

  for (var i = remove_array.length-1; i > -1 ; i--)
  {
    fromCtrl.options[remove_array[i]] = null;
  }

  target = document.getElementById("target_select_"+ms_id);
  hidden_variable = document.getElementById("hidden_select_"+ms_id);
  hidden_variable.value = "0";

  for (var i = 0; i < target.options.length; i++)
  {
    if ( !target.options[i].disabled )
    {
      hidden_variable.value += ","+target.options[i].value;
    }
  }


}

function toggle_display( section )
{
  section = document.getElementById(section);
  if ( section.style.display == "block" )
  {
    section.style.display = "none";
  }
  else
  {
    section.style.display = "block";
  }

}


function stringCheckbox (ms_id,invert)
{
  if ( invert == null ) 
  {
    invert = false;
  }
  checkboxes = document.getElementsByName("ms_checkbox_"+ms_id);
  hidden_variable = document.getElementById("hidden_select_"+ms_id);
  hidden_variable.value = "0";
  for (var i = 0; i < checkboxes.length; i++)
  {
    if (checkboxes[i].checked == !invert )
    {
      hidden_variable.value += ","+checkboxes[i].value;
    }
  }


}
