<!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'>
    ${add_js_home_local('jquery.min.js', 'admin')}
    ${add_css_home_local('login.css', 'admin')}
    ${add_css_home_local('font-awesome.min.css', 'admin')}
    ${HeaderHTML.css_home()|n}
    ${HeaderHTML.js_home()|n}
    <%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: "${make_url('admin/login')}",
                method: "POST",
                dataType: "json",
                data: data_form
                }).done(function(data) {
                
                    if(data.error==0)
                    {
                        
                        //window.location.href="${make_url('admin')}";
                        location.reload()
                    
                    }
                    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="${make_url('admin/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>
