function addSelected(frm, s_from, s_to) {
	
	var e_from = document.forms[frm].elements[s_from],
		e_to   = document.forms[frm].elements[s_to],
		e_hm   = document.forms[frm].elements['csHM'];

	if (!e_from)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");

	if (!e_to)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");

	var n_moved = 0;
	for (var i = 0; i < e_from.options.length; i++) {
		if (e_from.options[i].selected && e_from.options[i].value != 0) {
			exists = 0;
			for (j = 0 ; j < e_to.options.length; j++)
				if (e_from.options[i].value == e_to.options[j].value)
					exists = 1;
			if (exists == 0) {
			
				//e_to.options[e_to.options.length] = new Option(e_from.options[i].text, e_from.options[i].value);
				e_to.options[e_to.options.length] = new Option(e_hm.options[i].text, e_hm.options[i].value);
				n_moved++;
			}
		}
		/*
		else if (n_moved)
			e_from.options[i - n_moved] = new Option(e_from.options[i].text, e_from.options[i].value);
		*/
	}

	//if (n_moved)
	//	e_from.options.length = e_from.options.length - n_moved;
}

function deleteSelected(frm, s_from, s_to) {

	var e_from = document.forms[frm].elements[s_from],
		e_to   = document.forms[frm].elements[s_to];

	if (!e_from)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");

	if (!e_to)
		return alert ("Error: selectbox with name '" + s_from + "' can't be found.");

	var n_moved = 0;
	for (var i = 0; i < e_from.options.length; i++) {
		if (e_from.options[i].selected) {
			
			//e_to.options[e_to.options.legth] = new Option(e_from.options[i].text, e_from.options[i].value);
			n_moved++;
		}
		else if (n_moved)
			e_from.options[i - n_moved] = new Option(e_from.options[i].text, e_from.options[i].value);
	}

	if (n_moved)
		e_from.options.length = e_from.options.length - n_moved;
}

function searchList(startIndex){
	
	if($('sbSearch').value.trim() == ''){
		$('csMain').selectedIndex = -1;
		return;
	}
	
	var sts = 0;
	for(var i = 0; i < $('csMain').options.length; i++) 
		if ($('csMain').options[i].text.indexOf('... ') != -1) { 
			sts = 4;
			break;
		}
	
	var selId = -1;	
	var st = (startIndex != null ? startIndex : 0);
	for(var i = st; i < $('csMain').options.length; i++) {
		
		if($('cs').checked){
			if($('csMain').options[i].text.indexOf($('sbSearch').value.trim()) == sts/* && $('csMain').options[i].value != 0*/) {
				selId = i;
				break;
			}			
		}else {			
			if($('csMain').options[i].text.toLowerCase().indexOf($('sbSearch').value.toLowerCase().trim()) == sts/* && $('csMain').options[i].value != 0*/) {
				selId = i;
				break;
			}			
		}
	}
	if (selId == '-1' && startIndex != null) {
		
		//selId = parseInt($('lPos').value) -1;
		$('lPos').value = '-1';
		$('csMain').selectedIndex = '-1';
		searchList();
		return;
	}
	
	$('lPos').value = parseInt(selId) + 1; 
	$('csMain').selectedIndex = selId;
  }
  
  function findNext() {
 	searchList($('lPos').value);
  }

