/* townlist selection */

	function copy_right()
	{
		
		str = lbox;
		str += document.getElementById(lbox).selectedItems;
		if( (lo = document.getElementById(lbox)) && (ro = document.getElementById(rbox)) )
		{
			n = 0;
			while( lo.selectedIndex != -1 && n < 1000 )
			{	
				text = lo.options[lo.selectedIndex].text;
				value = lo.options[lo.selectedIndex].value;
				
				// verify that the town is not already in the 'selected' list
				if( selected_str.search('<'+value+'>') == -1 ) // replace when safe
				{
					// copy to the right box
					ro.options[ro.options.length] = new Option(text, value, false, false);
					// add value to selected_str to prevent duplicate additions
					selected_str += '<' + value + '>'; // remove when safe
					
					// add to towns or areas string
					if( value.substr(0,4) == 'town' )
						towns += '<' + value.substr(5) + '>';
					else
						areas += '<' + value.substr(5) + '>';
				}
				
				// deselect the item in the left box -- this MUST be done to proceed
				lo.options[lo.selectedIndex].selected = false;
				n++;
			}
			update_hidden_fields();
		}
	}
	function removeit()
	{
		if( (ro = document.getElementById(rbox)) )
		{
			while( ro.selectedIndex != -1 )
			{
				value = ro.options[ro.selectedIndex].value;
				
				// remove value from the selected_str to allow it to be added in the future
				selected_str = selected_str.replace('<' + ro.options[ro.selectedIndex].value + '>', '');
				
				// remove from towns or areas string
				if( value.substr(0,4) == 'town' )
					towns = towns.replace('<'+value.substr(5)+'>','');
				else
					areas = areas.replace('<'+value.substr(5)+'>','');
				
				// remove item for the selected list
				ro.remove(ro.selectedIndex);
			}
			update_hidden_fields();
		}
	}
	
	function update_hidden_fields()
	{
		document.getElementById('towns').value = towns.replace(/></g,',').replace(/[<>]/g,'');
		document.getElementById('areas').value = areas.replace(/></g,',').replace(/[<>]/g,'');
	}

