
function select_sort(obj) {
  var o = new Array();
  for (var i=0; i<obj.options.length; i++) {
    o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
  }
  if (o.length==0) { return; }
  o = o.sort(
    function(a,b) {
      if ((a.text+"") < (b.text+"")) { return -1; }
      if ((a.text+"") > (b.text+"")) { return 1; }
      return 0;
    }
  );
  for (var i=0; i<o.length; i++) {
    obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
  }
}

function move_items(list1_id,list2_id,add_all) {
  var list1 = get_object_by_id(list1_id);
  var list2 = get_object_by_id(list2_id);
  for (i=0; i<list1.options.length; i++) {
    if ((list1.options[i].selected == true) || add_all) {
      list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, false);
    }
  }
  for (i=(list1.options.length-1); i>=0; i--) {
    if ((list1.options[i].selected == true) || add_all) {
      list1.options[i] = null;
    }
  }
  select_sort(list2);
}

function select_all_items() {  // pass ID's of form controls as ('id1', 'id2', 'id3')
  var argv = select_all_items.arguments;
  var argc = argv.length;
  for (x = 0; x < argc; x++) {
    var list1 = get_object_by_id(argv[x]);
    var list1_len = list1.options.length;
    for (i=0; i<list1_len; i++) {
      list1.options[i].selected = true;
    }
  }
}

///////////////////////////////////////

var FUSION_dom_type = '';
if (document.getElementById){
  FUSION_dom_type = 'std';
}else if (document.all){
  FUSION_dom_type = 'ie4';
}else if (document.layers){
  FUSION_dom_type = 'ns4';
}
var FUSION_objects = new Array();

function get_object_by_id(idname,forcefetch){
  if(typeof(idname)!='string') return idname;
  if(forcefetch || typeof(FUSION_objects[idname])=='undefined'){
    switch (FUSION_dom_type){
      case 'std': FUSION_objects[idname] = document.getElementById(idname);  break;
      case 'ie4': FUSION_objects[idname] = document.all[idname];             break;
      case 'ns4': FUSION_objects[idname] = document.layers[idname];          break;
    }
  }
  return FUSION_objects[idname];
}
