function addElem(from,to,baseName) {
    var len = from.length;
    var toLen = to.length;
    var i, j, val, id, name, found;
    //Clear out base text
    //alert(toLen + "::" + to.options[0].value);
    if ((toLen == 1) && (to.options[0].value == '0')) {
	    to.options[0] = null;
	    toLen = 0;
    }

    //Add new elements
    for (i=0; i<len; i++) {
	    if (from.options[i].selected == true) {
		    found = false;
		    val = from.options[i].value;
		    j = val.indexOf(',');
		    name = val.substr(j+1);
		    id = val.substr(0,j);
		    for (j=0; j<toLen; j++) {
			    if (to.options[j].value == id) {
				    found = true;
				    break;
			    }
		    }
		    if (!found) {
			    to.options[toLen] = new Option(name, id);
			    toLen++;
		    }
		    from.options[i].selected = false;
	    }
    }

    //If none to add, restore base text
    toLen = to.length;
    if (toLen == 0) {
	    to.options[0]=new Option(baseName,0);
    }

    return;
}

function removeFromList(list,whoText) {
    var found;
    var text;
    var j;
    var who;
    var fcnt=0;
    for (var i = 0; i < list.options.length; i++) {
        if(list.options[i].selected == true) {
            var message="Really remove "+list.options[i].text+"?";
            //var choice=confirm(message);
            var choice=true;
            if (choice===true) {
               list.options[i] = null;
               found=i;
               fcnt=fcnt+1;
            i--;
            }

        }
        if (i>=found) {        
        text = list.options[i].text;
        temp = new Option(text, list.options[i].value);
        list.options[i]=temp;}
    }
    if (list.options.length==0) {
        temp = new Option(whoText,0);
	list.options[0]=temp;
    }
}

function moveList(fromElem, toElem) {
    toElem.value = '';
    for (var i=0; i<fromElem.options.length; i++) {
        if (toElem.value == '') {
            if (fromElem.options[i].value!=0) {toElem.value =  fromElem.options[i].value;}
        }
        else {
            toElem.value = toElem.value + '|' + fromElem.options[i].value;
        }
    }
    return true;
}
