<%inherit file="login.phtml"/>
<%block name="ajax">
    <script language="Javascript">
        $(document).ready( function () {
            
            $("#register_submit").click( function () {
                
                $('#loading').show();
                
                $.ajax({
                url: "${make_url('admin/signup')}",
                method: "POST",
                dataType: "json",
                data : JSON.stringify({'username': $('#username_form').val(), 'email': $('#email_form').val(), 'password': $('#password_form').val(), 'repeat_password': $('#repeat_password_form').val()}),
                contentType : 'application/json',
                error: function (data) {
                
                    $('#loading').hide();
                
                    $('#username_error').html("${_('Sorry, unknown error')}");
                
                }
                }).done(function(data) {
                //$( this ).addClass( "done" );
                //Redirect if register
                
                    if(data.error==0)
                    {
                    
                        //$('#result_register').html('Done!. Redirecting...');
                        $('#loading').hide();
                        window.location.href="${make_url('admin/login')}";
                    
                    }
                    else
                    {
                        
                        $('#loading').hide();
                        
                        $('#csrf_token').attr('value', data.csrf_token);
                        
                        $('#username_error').html(data.username);
                        $('#email_error').html(data.email);
                        $('#password_error').html(data.password);
                        
                        $('#repeat_password_error').html(data.password_repeat);
                    }
                
                });
                
                return false;
                
            });
            
        
        });
    </script>
</%block>
<%block name="title">${_('Paramecio Sign up')}</%block>
<%block name="content">
<form id="login">
    <div id="title">
                ${_('Paramecio Sign up')}
    </div>
    ${forms|n}
    </div>
    <div id="result_register"></div>
    <div id="submit_block">
        <input type="submit" value="${_('Sign up')}" class="submit" id="register_submit"/>
        <span id="loading">&nbsp;</span>
    </div>
</form>
</%block>
