<!DOCTYPE html>
<html>
    <head>
    <title><%block name="title">${lang('admin', 'login', 'Paramecio Login')}</%block></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
    <link href="${make_media_url('css/login.css', 'admin')}" rel='stylesheet' type='text/css'>
    <link href="${make_media_url('css/font-awesome.min.css', 'admin')}" rel='stylesheet' type='text/css'>
    <%block name="extra_css">
    </%block>
    <script language="Javascript" src="${make_media_url('js/jquery.min.js', 'admin')}"></script>
    <%block name="extra_js">
    </%block>
    <%block name="ajax">
    <script language="javascript">
        $(document).ready( function () {
        
            $('#login_submit').click( function () {
            
                $('#loading').show();
                
                data_form={'username': $('#username_form').val(), 'password': $('#password_form').val(), 'csrf_token': $("#csrf_token").val()};
            
                if($('#remember_login:checked').val())
                {
                    
                    data_form.remember_login=$('#remember_login').val();
                }
            
                $.ajax({
                url: "${url_for('.login')}",
                method: "POST",
                dataType: "json",
                data: data_form
                }).done(function(data) {
                
                    if(data.error==0)
                    {
                        
                        //location.reload()
                        location.href="${url_for('.admin')}";
                    
                    }
                    else
                    {
                        
                        //$('#csrf_token').val(data.csrf_token);
                        
                        // Firefox have a horrible and stupid bug and you need attr for set de new csrf_token
                        
                        $('#csrf_token').attr('value', data.csrf_token);
                    
                        $('#loading').hide('slow');

                        $('#username_error').html("${lang('common', 'error_login', 'Error, wrong username or password')}");
                        
                    }
                
                });
                
                return false;
            
            });
        
        });
    </script>
    </%block>
    </head>
    <body>
        <%block name="content">
        <form id="login">
            <div id="title">
                ${lang('admin', 'login', 'Paramecio Login')}
            </div>
            ${forms|n}
            <div class="form">
                ${lang('admin', 'remember_login', 'Remember login?')} <input type="checkbox" id="remember_login" name="remember_login" value="1">
            </div>
            <div id="submit_block">
                <input type="submit" value="${lang('common', 'login', 'Login')}" class="submit" id="login_submit"/>
                <span id="loading">&nbsp;</span>
            </div>
            % if yes_recovery_login:
                <div class="form"><a href="${url_for('.recovery_password')}">${lang('admin', 'recovery_password', 'Recovery password?')}</a></div>
            % endif
            <div class="form">${lang('admin', 'remember_tries', 'Remember that only have 3 attempts')}</div>
        </form>
        </%block>
    </body>
</html>
