// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].value] = to.options[i].text;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] !== "0") {
				if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
					to.options[to.options.length] = new Option( o.text, o.value, false, false);
					}
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		var o=from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
			} 
		} 
	from.selectedIndex = -1; 
	}


// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
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;
	}


// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	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;
				}
			}
		}
	}


// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	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;
				}
			}
		}
	}


// -------------------------------------------------------------------
// addText
//  Add the value from a textfield to a selectbox/dropdown
// -------------------------------------------------------------------
//      var numItems = 1;  // manual list counter 
    function addText(from,to) { 
	   var numItems = to.options.length;
	   var txt = from.value;
	   if (txt != '@philips.com') {
           	addOption = new Option(txt,txt); 
           	to.options[numItems++] = addOption; 
	   		from.value = '@philips.com';
           	return true; 
	   }
    } 

    function addText2(from,to) { 
	   var numItems = to.options.length;
	   var txt = from.value;
	   if (txt != '') {
           	addOption = new Option(txt,txt); 
           	to.options[numItems++] = addOption; 
	   		from.value = '';
           	return true; 
	   }
    } 

    function addText3(from,to) { 
	   var numItems = to.options.length;
	   var txt = from.value;
	   if (txt != '') {
           	addOption = new Option(txt,'h_'+ txt); 
           	to.options[numItems++] = addOption; 
	   		from.value = '';
           	return true; 
	   }
    } 


// -------------------------------------------------------------------
// CopyText
//  Copy the value from a textfield to another textfield
// -------------------------------------------------------------------
        function CopyText(from,to,to2) { 
	   to.value = from.value;
	   to2.value = from.value;
           return true; 
       } 


// -------------------------------------------------------------------
// CopyText2
//  Copy the value from a selectbox/dropdown to a textfield
// -------------------------------------------------------------------
function CopyText2(from,to,to2) { 
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
				to.value = o.text;
				to2.value = o.value;
			}
		}
	}