{{ header|raw }}
<body data-open="click" data-menu="vertical-menu" data-col="2-columns"
      class="vertical-layout vertical-menu 2-columns  fixed-navbar">

{{ top|raw }}

{{ menu|raw }}

<div class="app-content content container-fluid">
    <div class="content-wrapper">
        <div class="content-header row">
        </div>
        <div class="content-body">
            <div class="card-body collapse in">
                <div class="card-block">
                    <form class="form-horizontal form-simple" action="{{ update_url }}" method="post" name="update_form"
                          id="update_form">
                        <div class="col-xs-6">
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="vat">Δώστε ΑΦΜ :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="vat" name="vat"
                                           onkeypress="allowNumbersOnly(event)" maxlength="9" placeholder="Δώστε ΑΦΜ"
                                           value="{{ vat }}" required>
                                    {% if error.vat is defined %}
                                        <div class="alert alert-danger" id="vat-error"
                                             style="display:block;margin-top: 5px;">{{ error.vat }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="companyname">Επωνυμία :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="companyname"
                                           name="companyname" placeholder="" value="{{ companyname }}" readonly>
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="address">Διεύθυνση :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="address"
                                           name="address" placeholder="" value="{{ address }}" readonly>
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="profession">Επάγγελμα:</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="profession"
                                           name="profession" placeholder="" value="{{ profession }}" readonly>
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="phone">Τηλέφωνο* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="phone"
                                           name="phone" placeholder="Τηλέφωνο" maxlength="10"
                                           onkeypress="allowNumbersOnly(event)" value="{{ phone }}" required>
                                    {% if error.phone is defined %}
                                        <div class="alert alert-danger" id="phone-error"
                                             style="display:block;margin-top: 5px;">{{ error.phone }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="fax">Φαξ :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="fax" name="fax"
                                           placeholder="Φαξ" maxlength="10" onkeypress="allowNumbersOnly(event)"
                                           value="{{ fax }}">
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="mobile">Κινητό* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="mobile"
                                           name="mobile" maxlength="10" onkeypress="allowNumbersOnly(event)"
                                           placeholder="Κινητό" value="{{ mobile }}" required>
                                    {% if error.mobile is defined %}
                                        <div class="alert alert-danger" id="mobile-error"
                                             style="display:block;margin-top: 5px;">{{ error.mobile }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="fname">Όνομα* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="fname"
                                           name="fname" placeholder="Όνομα" value="{{ fname }}" required>
                                    {% if error.fname is defined %}
                                        <div class="alert alert-danger" id="fname-error"
                                             style="display:block;margin-top: 5px;">{{ error.fname }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="lname">Επώνυμο* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="lname"
                                           name="lname" placeholder="Επώνυμο" value="{{ lname }}" required>
                                    {% if error.lname is defined %}
                                        <div class="alert alert-danger" id="lname-error"
                                             style="display:block;margin-top: 5px;">{{ error.lname }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="col-xs-12 text-md-left">
                                <div>
                                    {% if newsletter == 'on' %}
                                        <input type="checkbox" id="newletter" class="magic-checkbox" name="newsletter"
                                               checked="checked">
                                    {% else %}
                                        <input type="checkbox" id="newletter" class="magic-checkbox" name="newsletter">
                                    {% endif %}

                                    <label for="newletter">Newsletter</label>
                                </div>
                                <div>
                                    {% if terms == 'on' %}
                                        <input type="checkbox" id="terms" class="magic-checkbox" name="terms"
                                               checked="checked">
                                    {% else %}
                                        <input type="checkbox" id="terms" class="magic-checkbox" name="terms" require>
                                    {% endif %}
                                    <label for="terms">Όροι χρήσης</label>
                                    {% if error.terms is defined %}
                                        <div class="alert alert-danger" id="terms-error"
                                             style="display:block;margin-top: 5px;">{{ error.terms }}</div>
                                    {% endif %}
                                </div>
                                <div class="text-center">
                                    <button type="submit" class="btn btn-primary btn-lg btn-block"><i
                                                class="icon-unlock2"></i> ΕΓΓΡΑΦΗ
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-6">
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="postalcode">ΤΚ* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="postalcode"
                                           name="postalcode" placeholder="" value="{{ postalcode }}" readonly>
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="doy">ΔΟΥ* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left select_box">
                                    <select class="form-control form-control-lg input-lg" id="doy" name="doy" required>
                                        <option value="-1">Επιλέξτε...</option>
                                        {% for office in tax_offices %}
                                            {% if taxoffice == office.id %}
                                                <option value="{{ office.id }}" code="{{ office.code }}"
                                                        selected="selected">{{ office.name }} ({{ office.code }})
                                                </option>
                                            {% else %}
                                                <option value="{{ office.id }}"
                                                        code="{{ office.code }}">{{ office.name }} ({{ office.code }})
                                                </option>
                                            {% endif %}
                                        {% endfor %}
                                    </select>
                                </div>
                                <input type="hidden" name="taxoffice" id="taxoffice" value=""/>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="prefecture">Περιφέρεια* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left select_box">
                                    <select class="form-control form-control-lg input-lg" id="prefecture"
                                            name="prefecture" required>
                                        <option value="-1">Επιλέξτε...</option>
                                        {% for prefectures in prefectures_list %}
                                            {% if prefecture == prefectures.id %}
                                                <option value="{{ prefectures.id }}"
                                                        selected>{{ prefectures.name }}</option>
                                            {% else %}
                                                <option value="{{ prefectures.id }}">{{ prefectures.name }}</option>
                                            {% endif %}
                                        {% endfor %}
                                    </select>
                                </div>
                                {% if error.prefecture is defined %}
                                    <div class="alert alert-danger" id="prefecture-error"
                                         style="display:block;margin-top: 5px;">{{ error.prefecture }}</div>
                                {% endif %}
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="county">Νομός* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left select_box">
                                    <select class="form-control form-control-lg input-lg" id="county" name="county"
                                            required></select>
                                </div>
                                {% if error.county is defined %}
                                    <div class="alert alert-danger" id="county-error"
                                         style="display:block;margin-top: 5px;">{{ error.county }}</div>
                                {% endif %}
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="municipality">Δήμος* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left select_box">
                                    <select class="form-control form-control-lg input-lg" id="municipality"
                                            name="municipality" required></select>
                                </div>
                                {% if error.municipality is defined %}
                                    <div class="alert alert-danger" id="municipality-error"
                                         style="display:block;margin-top: 5px;">{{ error.municipality }}</div>
                                {% endif %}
                            </div>

                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="email">Email* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="text" class="form-control form-control-lg input-lg" id="email"
                                           name="email" placeholder="Email" value="{{ email }}" required>
                                    {% if error.email is defined %}
                                        <div class="alert alert-danger" id="email-error"
                                             style="display:block;margin-top: 5px;">{{ error.email }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="password">Κωδικός* :</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="password" class="form-control form-control-lg input-lg" id="password"
                                           name="password" placeholder="Κωδικός" required>
                                    {% if error.password is defined %}
                                        <div class="alert alert-danger" id="password-error"
                                             style="display:block;margin-top: 5px;">{{ error.password }}</div>
                                    {% endif %}
                                </div>
                            </div>
                            <div class="form-group col-xs-12">
                                <div class="col-md-4 col-xs-12 float-left">
                                    <label for="password2">Επιβεβαίωση Κωδικού*:</label>
                                </div>
                                <div class="col-md-9 col-xs-12 float-left">
                                    <input type="password" class="form-control form-control-lg input-lg" id="password2"
                                           name="password2" placeholder="Επιβεβαίωση κωδικού" required>
                                    {% if error.password_confirm is defined %}
                                        <div class="alert alert-danger" id="password-confirm-error"
                                             style="display:block;margin-top: 5px;">{{ error.password_confirm }}</div>
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        jQuery(document).ready(function () {

            $(window).load(function () {
                $('#prefecture').trigger('change');
                $('#county').trigger('change');
                $('#taxoffice').val($('#doy option:selected').val());
            });

            $(document).on('change', '#prefecture', function (e) {

                var county = '{{ county }}';

                $.ajax({
                    url: '{{ counties_list_url }}',
                    datatype: 'json',
                    data: {
                        prefecture: $('#prefecture').val()
                    },
                    method: 'POST',
                    success: function (json) {
                        var result = $.parseJSON(json);
                        var html = '';
                        if (result) {
                            for (i = 0; i < result.length; i++) {
                                if (result[i]['id'] == county) {
                                    html += '<option value="' + result[i]['id'] + '" selected>' + result[i]['name'] + '</option>';
                                } else {
                                    html += '<option value="' + result[i]['id'] + '">' + result[i]['name'] + '</option>';
                                }
                            }
                        }

                        $('#county').html('');
                        $('#county').html(html);

                        $('#county').trigger('change');
                    } //end function
                }); //end ajax
            });//end change

            $(document).on('change', '#county', function (e) {

                var municipality = '{{ municipality }}';

                $.ajax({
                    url: '{{ municipalities_list_url }}',
                    datatype: 'json',
                    data: {
                        county: $('#county').val()
                    },
                    method: 'POST',
                    success: function (json) {
                        var result = $.parseJSON(json);
                        console.log(result);
                        var html = '';
                        if (result) {
                            for (i = 0; i < result.length; i++) {
                                if (result[i]['id'] == municipality) {
                                    html += '<option value="' + result[i]['id'] + '" selected>' + result[i]['name'] + '</option>';
                                } else {
                                    html += '<option value="' + result[i]['id'] + '">' + result[i]['name'] + '</option>';
                                }
                            }
                        }

                        $('#municipality').html('');
                        $('#municipality').html(html);
                    } //end function
                }); //end ajax
            });//end change

            $(document).on('focusout', '#email', function (e) {
                $.ajax({
                    url: '{{ check_email_unique_url }}',
                    datatype: 'json',
                    data: {
                        email: $('#email').val()
                    },
                    method: 'POST',
                    success: function (json) {
                        var result = $.parseJSON(json);
                        var html = '';
                        if (result['email_exists']) {
                            $('#email-error').fadeIn("slow");
                        }
                        else {
                            $('#email-error').fadeOut("slow");
                        }
                    } //end function
                }); //end ajax
            });//end focusout

            $(document).on('focusout', '#vat', function (e) {

                var vat_exist = false;

                $.ajax({
                    url: '{{ checkvat_url }}',
                    datatype: 'json',
                    data: {
                        vat: $('#vat').val()
                    },
                    method: 'POST',
                    success: function (json) {
                        var result = $.parseJSON(json);
                        var html = '';
                        if (result == true) {
                            vat_exist = true;
                        }
                        else {
                            getVatInfo();
                        }
                    } //end function
                }); //end ajax

                if ($(this).val() == '' || vat_exist == true) {
                    return false;
                }
            });//end focusout
        });//end jquery ready

        function getVatInfo() {
            $.ajax({
                url: '{{ getinfofromvat_url }}',
                datatype: 'json',
                data: {
                    vat: $('#vat').val()
                },
                method: 'POST',
                success: function (json) {
                    var result = $.parseJSON(json);
                    var html = '';
                    if (result) {
                        $('#profession').val(result['PROFESSION']);
                        $('#address').val(result['POSTALADDRESS'] + ' ' + result['POSTALADDRESSNO']);
                        $('#companyname').val(result['ONOMASIA']);
                        $('#postalcode').val(result['POSTALZIPCODE']);
                        $('#doy option[code=' + result['DOY'] + ']').attr('selected', 'selected');
                        $('#doy').attr("disabled", true);
                        $('#taxoffice').val($('#doy option:selected').val());
                    }
                } //end function
            }); //end ajax
        }
    </script>
    {{ footer|raw }}
    </html>
