function splitSelects(){
	selects=document.getElementsByTagName('select');
	for(i=0;i<selects.length;i++){
		if(selects[i].multiple && selects[i].id.indexOf('splitSelect_')==-1){
			splitSelect(selects[i]);
		}
	}
}

function splitSelect(obj){
	SPLITSELECT_ARROW=true;
	SPLITSELECT_IMAGEPATH='fileadmin/template/images/forms/';

	// give an id if it doesn't have one
	if(!obj.id) obj.id='select'+Math.round(Math.random()*1000000);
	// get parent element
	par=obj.parentNode;
	// create left selectbox
	l=document.createElement('select');
	l.className='splitSelect_l';
	l.id=obj.id+'_splitSelect_l';
	l.setAttribute('size',5);
	// create right selectbox
	r=document.createElement('select');
	r.className='splitSelect_r';
	r.id=obj.id+'_splitSelect_r';
	r.setAttribute('size',5);
	// copy options
	for(j=0;j<obj.options.length;j++){
		if(obj.options[j].selected){
			l.options[l.options.length]=new Option(obj.options[j].text,j);
		}else{
			r.options[r.options.length]=new Option(obj.options[j].text,j);
		}
	}
	// create arrows
	if(SPLITSELECT_ARROW){
		t=document.createElement('table');
		t.className='splitSelect';
		t.border=0;
		tb=document.createElement('tbody');
		tr=document.createElement('tr');
		tdl=document.createElement('td');
		tdm=document.createElement('td');
		tdr=document.createElement('td');
		rla=document.createElement('a');
		rl=document.createElement('img');
		rl.src=SPLITSELECT_IMAGEPATH+'left.png';
		rl.setAttribute('onclick',"moveEntry('"+obj.id+"',true);");
		br=document.createElement('br');
		lr=document.createElement('img');
		lr.src=SPLITSELECT_IMAGEPATH+'right.png';
		lr.setAttribute('onclick',"moveEntry('"+obj.id+"',false);");
		if(document.all){
			// IE don't understand dynamic onclick
			rla=document.createElement('a');
			rla.href="javascript:moveEntry('"+obj.id+"',true);";
			lra=document.createElement('a');
			lra.href="javascript:moveEntry('"+obj.id+"',false);";
			rla.appendChild(rl);
			lra.appendChild(lr);
			rl=rla;
			lr=lra;
		}
		obj.className='nopretty';
		obj.style.display='none';
		par.appendChild(t);
		t.appendChild(tb);
		tb.appendChild(tr)
		tr.appendChild(tdl);
		tr.appendChild(tdm);
		tr.appendChild(tdr);
		tdl.appendChild(l);
		tdm.appendChild(rl);
		tdm.appendChild(br);
		tdm.appendChild(lr);
		tdr.appendChild(r);
	}else{
		l.setAttribute('onclick',"moveEntry('"+obj.id+"',false);");
		r.setAttribute('onclick',"moveEntry('"+obj.id+"',true);");
		par.appendChild(l);
		par.appendChild(r);
	}
}

function moveEntry(id,select){
	o=document.getElementById(id);
	l=document.getElementById(id+'_splitSelect_l');
	r=document.getElementById(id+'_splitSelect_r');
	if(select){
		from=r;
		to=l;
	}else{
		from=l;
		to=r;
	}
	o.options[from.value].selected=select;
	to.options[to.options.length]=new Option(from.options[from.selectedIndex].text,from.value);
	from.options[from.selectedIndex]=null;
}
