{% extends "master.html" %}

{% block main %}

{% if output %}
  <a href="#output" class="skip">Jump to formatted query</a>
{% endif %}

<form method="post" action="" id="form_options" enctype="multipart/form-data">
  <div id="input">
    <div>
      <strong>Type your SQL here:</strong><br />
	  <textarea id="id_data" rows="10" cols="40" name="data" class="resizable">{{ sql_orig }}</textarea>
    </div>
    <div style="margin-top: .5em;">
      <strong>...or upload a file:</strong>
      <input type="file" name="datafile" id="id_datafile" />
    </div>
    <div id="examples" style="margin-top: .5em;"></div>
    <div id="actions" style="margin-top: .5em;">
      <input type="submit" value="Format SQL" id="btn_format" />
    </div>
    {% if output %}<a name="output"></a>
    <div id="response">{{output|safe}}</div>
    {% else %}
    <div id="response"></div>
    {% endif %}
    <div id="proc_time">
      {% if proc_time %}Processed in {{proc_time}} seconds.{% endif %}
    </div>
    <div style="margin-top: 1em;">
      <script type="text/javascript">
	<!--
	   google_ad_client = "pub-8870624642249726";
	   /* 468x60, Erstellt 07.03.09 */
	   google_ad_slot = "9840041509";
	   google_ad_width = 468;
	   google_ad_height = 60;
	//-->
      </script>
      <script type="text/javascript"
	      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
      </script>
    </div>

  </div>
  <div id="options">
    <h1 class="skip">Options</h1>
    <fieldset><legend id="general"><strong>General Options</strong></legend>
      <div id="general_content" class="content">
      <input type="checkbox" id="id_remove_comments" name="remove_comments" value="1" {% if extra.comments %}checked="checked"{% endif %}/>
      <label for="id_remove_comments">Remove comments</label>
      <br />
      <input type="checkbox" id="id_highlight" name="highlight" value="1" {% if extra.highlight %}checked="checked"{% endif %} />
      <label for="id_highlight">Enable syntax highlighting</label>
      </div>
    </fieldset>
    <fieldset><legend id="kwcase">
	<strong>Keywords &amp; Identifiers</strong></legend>
      <div>
	  Keywords: <select id="id_keyword_case" name="keyword_case">
			<option value="">Unchanged</option>
			<option value="lower" {% if extra.keywords == 'lower' %}selected="selected"{% endif %}>Lower case</option>
			<option value="upper"  {% if extra.keywords == 'upper' %}selected="selected"{% endif %}>Upper case</option>
			<option value="capitalize"  {% if extra.keywords == 'capitalize' %}selected="selected"{% endif %}>Capitalize</option>
	  </select>
	</div>
	<div>
	  Identifiers: <select name="identifier_case" id="id_identifier_case">
		<option value="">Unchanged</option>
		<option value="lower" {% if extra.idcase == 'lower' %}selected="selected"{% endif %}>Lower case</option>
		<option value="upper" {% if extra.idcase == 'upper' %}selected="selected"{% endif %}>Upper case</option>
		<option value="capitalize" {% if extra.idcase == 'capitalize' %}selected="selected"{% endif %}>Capitalize</option>
	  </select>
	</div>
    </fieldset>
    <fieldset><legend id="indent"><strong>Indentation &amp; Margins</strong>
	</legend>
	  <div id="indent_content" class="content">
	    <label for="id_n_indents">Indentation: </label>
	    <input name="n_indents" value="{{extra.n_indents}}" maxlength="2" type="text" id="id_n_indents" size="2" /> spaces
	    <div class="help">Empty field means leave indentation unchanged.</div>
	  </div>
    </fieldset>
    <fieldset><legend id="output"><strong>Output Format</strong></legend>
      <label for="id_output_format">Language: </label>
	  <select name="output_format" id="id_output_format">
		<option value="sql" {% if extra.lang == 'sql' %}selected="selected"{% endif %}>SQL</option>
		<option value="python" {% if extra.lang == 'python' %}selected="selected"{% endif %}>Python</option>
		<option value="php" {% if extra.lang == 'php' %}selected="selected"{% endif %}>PHP</option>
	  </select>
    </fieldset>

    <div class="dev">This software is in development.</div>

	<div>
	  <g:plusone size="medium"></g:plusone>
	  <a href="http://flattr.com/thing/350724/SQLFormat-Online-SQL-formatting-service" target="_blank">
		<img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" />
	  </a>
	</div>
	<div style="padding-top: 15px;">
	  <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="andialbrecht">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
	</div>
  </div>
  <div class="clearfix"></div>
</form>

<script language="javascript">
html = '<strong>...or select an example:</strong> ';
html = html + '<select onchange="load_example();" id="sel_example">';
html = html + '<option value="">-- Choose Example --</option>';
{% for ex in examples %}
  html = html + '<option value="{{ex}}">{{ex}}</option>';
{% endfor %}
html = html + '</select>';
$('#examples').html(html);
</script>
{% endblock %}

