def radio_input (label, name, vals, helptext='', env={}, default=None):
	"""
	:Parameters:
		vals
			a list of value - label pairs
		env
			the environ or request dict
	"""
	## Preconditions & preparation:
	checked_vals = env.get (name, [vals[0][0]])
	if type(checked_vals) != type([]):
		checked_vals = [checked_vals]
	## Main:
	radio_vals = []
	for val, choice_label in vals:
		if str(val) in checked_vals:
			checked = 'checked'
		else:
			checked = ''
		radio_vals.append ([val, choice_label, checked])
	
	radio_body = htmltags.tag_with_contents ('div',
		_class = 'radio',
		contents = "<br />\n".join ([
			"<input type='radio' name='%s' value='%s' %s />%s" % (name, val, check, choice_label) for 
			val, choice_label, check in radio_vals
		])
	)

	## Postconditions & return:
	return form_field (label, radio_body, helptext)
def seq_table_input (gene_choices, env={}):
	if gene_choices:
		
		def format_vals (v):
			if v is None:
				return ''
			else:
				return "%s" % v
			

		col_headers = [
			'accession_number',
			'isolate_name',
			'sequencing_method',
			'author'
		]
		
		theader = htmltags.tag_with_contents ('thead',
			htmltags.tag_with_contents ('tr',
				' '.join ([
					htmltags.tag_with_contents ('td', 
						h.replace('_', ' ').title()
					) for h in [''] + col_headers
				])
			)
		)
		
		checked_vals = dict (*[(v, 'checked') for v in env.get ('refseqs', [])])
		tbody = htmltags.tag_with_contents ('tbody',
			'\n'.join ([
				htmltags.tag_with_contents ('tr',
					' '.join (
						[
							"<td><input type='checkbox' name='refseqs' value='%s' %s /></td>" % \
								(g['id'], checked_vals.get(g['id'], ''))
						] + 
						[htmltags.tag_with_contents ('td', format_vals (g[h])) for h in col_headers]
					)
				) for g in gene_choices
			])
		)
		
		tab = htmltags.tag_with_contents ('table',
			theader + '\n' + tbody,
			_class="refseq_table"
		)
		helptext = """
			<p class='helptext'>Select at least 3 sequences
			to be matched. Select 
			<a href="javascript:SetAllCheckBoxes('dvifish', 'refseqs', true)">all</a> or
			<a href=\"javascript:SetAllCheckBoxes('dvifish', 'refseqs', false)">none</a>.
			</p>
		"""
		return helptext + tab + helptext
def dropdown_input (label, name, vals, helptext='', env={}, default=None):
	"""
	:Parameters:
		label
			what the title will be on the form
		helptext
			a useful descriptive paragraph
		vals
			a list of value - label pairs
		env
			the environ or request dict

	Should look like::

		<select name="mydropdown">
		<option value="Milk">Fresh Milk</option>
		<option selected value="Cheese">Old Cheese</option>
		<option value="Bread">Hot Bread</option>
		</select>

	"""
	## Preconditions & preparation:
	checked_val = env.get (name, None)
	## Main:
	menu_vals = []
	for val, choice_label in vals:
		if str(val) == checked_val:
			checked = 'selected'
		else: 
			checked = ''
		menu_vals.append ([val, choice_label, checked])
	
	menu_body = htmltags.tag_with_contents ('select',
		name=name,
		contents = "<br />\n".join ([
			"<option value='%s' %s />%s</option>" % (val, check, choice_label) for 
			val, choice_label, check in menu_vals
		])
	)

	## Postconditions & return:
	return form_field (label, menu_body, helptext)