{% if old_style %}
<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    <input type="file" name="txt">
    <button type="submit">Upload</button>
</form>
{% endif %}

<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    <input type="hidden" id="upload_action" name="upload_action" value=""/>
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="input-group">
                <span class="input-group-btn">
                    <button id="upload_button_browse" type="button" class="btn btn-default">
                        <span class="glyphicon glyphicon-file"></span>
                    </button>
                </span>
                <input type="file" id="files-input-upload" name="{{name}}" style="display:none">
                <input type="text" id="upload_filename" disabled="disabled" placeholder="Choisissez un fichier" class="form-control" style="margin-top: 1px">
            </div>
        </div>
        <div class="panel-footer">
            <button type="submit" id="upload_button" class="btn btn-primary" onclick="upload2();" disabled>Charger</button>
        </div>
    </div>
</form>

<script>

    function upload2() {
        document.getElementById('upload_action').value = 'upload';
        document.getElementById('form').submit();
    }

    document.getElementById('upload_button_browse').addEventListener('click', function() {
	    document.getElementById('files-input-upload').click();
    });

    document.getElementById('files-input-upload').addEventListener('change', function() {
        filename = this.value
        index = filename.lastIndexOf("\\")
        if (index > -1)
            filename = filename.substring(index + 1)
	    document.getElementById('upload_filename').value = filename;
	    document.getElementById('upload_button').removeAttribute('disabled');
    });
</script>
