﻿function submit() {
    removeInfo();

    btn = $('#button');

    $('#button').replaceWith('<img id="theimage" src="/images/ajax-loader.gif" />');

    $.post ('/jregister',
            {
                username: $('#username').val(),
                email: $('#email').val(),
                emailC: $('#emailC').val(),
                captcha: $('#captcha').val()
            },
            function (data) {
                if (data.status == 'SUCCESS') {
                    $('#registerTable').slideUp('slow', function () { $('#divSuccess').fadeIn('slow', function () { }); });
                }
                else {
                    $(data.errorInput).addClass('inputerror');
                    $(data.errorInput).focus();
                    $('#spanFailed').text(data.info);
                    appear('#divFailed');
                    if (data.errorInput == '#captcha') {
                        captchaimage.src = '/captcha?i=2' + Math.floor(Math.random() * 11);
                    }
                }
                $('#theimage').replaceWith(btn);
            },
            'json'
           );
}