<style type="text/css">
.row {
	margin-top: 10px;
}

h5.heading {
	text-transform: none;
	font-weight: normal;
}

</style>
<div class='row'><div class='span9'><div class='small-form-container'>
    <h5 class="heading">Add New Column</h5>
	<form class="variable_form tt_form" action="" method="post" accept-charset="utf-8">
		<div class='msg-placeholder'></div>
		{% csrf_token %}
		<table class='compact-form'><tbody>
	  	{% for field in form %}
	  		{% comment %} field 'insert_position' must be the last field and has some special styling {% endcomment %}
	  		{% if field.name == 'insert_position' %}
	  		{% comment %} field 'values' are hidden until it is needed {% endcomment %}
	    	
	    	{% elif field.label == 'values' %}
	    		<tr class='hidden values-needed'>
	    			<td>{{field.label_tag}}</td><td  class="contains-input">{{field}}</td>
	    			<td colspan='2' style="color:#999;">{{field.help_text}}</td>
	    		</tr>

			{% elif field.name not in table_fields and field.label not in odd_fields %}
				<tr><td class="input-header">{{field.label_tag}}<td class="contains-input">{{field|safe}}</td>

			{% elif dialect == 'postgresql' and field.label == 'type' %}
			 <td class="input-header">{{field.label_tag}}{{field}}

			{% elif field.name not in table_fields and field.label in odd_fields %}
				<td class="input-header">{{field.label_tag}}</td><td class="contains-input">{{field}}</td></tr>
			{% endif %}
	    {% endfor %}
	    </tbody></table>
	  <div class="form-controls" style="margin-top:-10px;">
	  	<p>
	  	{% if dialect == 'mysql' %}
	  		<label for='id_insert_position' style='margin-right:30px;width:auto;'>{{ form.insert_position.label }}</label>
	  		{{ form.insert_position}}
	    {% endif %}
	    <input type="submit" class='btn submit-button' value="Submit &rarr;" style='margin-left:50px' />
	  	</p>
	  </div>
	</form>
</div></div></div>

<script type="text/javascript" ajaxKey="{{ajaxKey}}" charset="utf-8">
	// this scripts makes the insert_position field lists itself horizontally
	// instead of verticall which is the default
	if ($E('table.compact-form td ul')) {
		var j = $E('table.compact-form td ul'); // the first ul elmnt corresponds to the 'insert_position' field
		var con = new Elements();
		j.getChildren().each(function(item, key) {
			// each item is an li element
			// now attach the first child of the li element which should be a form label with an inner input
			// to the con elements
			con.include(item.getChildren()[0]); 
		});
		j.getParent('tr').adopt(new Element('td', {
			'colspan' : 5,
			'class' : 'occupy'
		}).adopt(con));
		j.getParent().destroy();	
	}
</script>

<div id='undisplayed_result' class='hidden' style="display:none;"></div>
