<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<br />
<div class="panel panel-blue">
    <div class="panel-heading">
        <h3 class="panel-title">Setup</h3>
    </div>
    <div class="panel-body">
        <p>Almost done!
            <br /><br />
            Please enter your password, then press Finish.
        </p>
        <input type="password" id="passbox" class="form-control" placeholder="Password" style="display: block;" />
        <br />
        <div class="btn btn-primary" onclick="savePassword()"><i class="fa fa-check"></i> Finish</div>
    </div>
</div>

<script>
    function savePassword() {
        $.post(setupsyncurl, {
            username: setupusername,
            key: setupsynckey,
            password: $('#passbox').val(),
            action: "check_password"
        }, function (data) {
            if (data.status === 'OK') {
                setuppassword = $('#passbox').val();
                var accid = addaccount(setupusername, setuppassword, setupsyncurl, setupsynckey);
                switchaccount(accid);
                localStorage.setItem("firstrun", "1");
                navigator.notification.alert("Account connected!", null, "Success", 'Continue');
                restartApplication();
            } else {
                navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
            }
        }, "json").fail(function () {
            navigator.notification.alert("Could not connect to the server.  Try again later.", null, "Error", 'Dismiss');
        });
    }

    setnavbar("setup");
</script>