<h2>
  <%= link_to t(:channels), channels_path %> &raquo;
	<%= link_to channel_path(@channel.id) do %> <%= t(:channel) %> <%= @channel.id %><% end %> &raquo;
  <%= t(:edit) %>
</h2>

<%= form_for @channel, :html => {:method => 'put'} do |d| %>
  <%= error_messages_for 'channel', :header_message => t(:try_again), :message => t(:channel_error) %>
	<input name='userlogin' class='userlogin' />
	<table class="table_no_header">
		<tr>
			<td class="left"><%= t(:channel_name) %></td>
			<td><%= d.text_field :name %></td>
		</tr>
		<tr>
			<td class="left"><%= t(:channel_description) %></td>
			<td><%= d.text_field :description %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:api_key) %></td>
			<td><%= @key %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:latitude) %></td>
			<td><%= d.text_field :latitude %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:longitude) %></td>
			<td><%= d.text_field :longitude %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:elevation) %></td>
			<td><%= d.text_field :elevation %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:public) %></td>
			<td><%= d.check_box :public_flag %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 1</td>
			<td><%= d.text_field :field1, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 2</td>
			<td><%= d.text_field :field2, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 3</td>
			<td><%= d.text_field :field3, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 4</td>
			<td><%= d.text_field :field4, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 5</td>
			<td><%= d.text_field :field5, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 6</td>
			<td><%= d.text_field :field6, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 7</td>
			<td><%= d.text_field :field7, :class => 'field' %></td>		
		</tr>
		<tr>
			<td class="left"><%= t(:field) %> 8</td>
			<td><%= d.text_field :field8, :class => 'field' %></td>		
		</tr>
		<tr>
			<td></td>
			<td><%= d.submit t(:channel_update) %>
		</tr>
	</table>
<% end %>
	
<br /><br />

<h2><%= t(:channel_clear_message) %></h2>
<%= button_to t(:channel_clear), clear_channel_path(@channel), :confirm => t(:confirm_channel_clear) %>

<br /><br />

<h2><%= t(:channel_delete_message) %></h2>
<%= button_to t(:channel_delete), channel_path(@channel), :method => 'delete', :confirm => t(:confirm_channel_delete) %>

<script type="text/javascript">
	// remember default field label
	var default_label = '<%= t(:channel_default_field) %>';
	// when document is ready
	$(function() {

		// iterate through each field textbox
		$('.field').each(function() {
			// if a value is present, show the 'remove' checkbox
			if ($(this).val()) {
				$(this).after('<span class="small" id="span_' + $(this).attr('id') + '"><input type="checkbox" onclick="removeField(\'' + $(this).attr('id') + '\')"  /><span class="up2">remove field</span></span>');
			// else disable
			} else {
				$(this).after('<span class="small" id="span_' + $(this).attr('id') + '"><input type="checkbox" onclick="addField(\'' + $(this).attr('id') + '\')"  /><span class="up2">add field</span></span>');
			}
		});

	});

	// adds a field
	function addField(id) {
		$('#span_'+id).remove()
		$('#'+id).val(default_label + ' ' + id.substring(id.length-1));
		$('#'+id).after('<span class="small" id="span_' + id + '"><input type="checkbox" onclick="removeField(\'' + id + '\')"  /><span class="up2">remove field</span></span>');
		$('#'+id).select();
	}

	// removes a field
	function removeField(id) {
		$('#span_'+id).remove();
		$('#'+id).val('');
		$('#'+id).after('<span class="small" id="span_' + id + '"><input type="checkbox" onclick="addField(\'' + id + '\')"  /><span class="up2">add field</span></span>');
	}
</script>