
jQuery(document).ready(function() {
    $('.container .form .username, .container .form .code, .container .form .password, .container .form .repassword').keyup(function(){
        $(this).parent().find('.error').fadeOut('fast');
    });
});

function verify_click () {
    var that = $('.container .form');
    var username = $(that).find('.username').val();

    if(username == '') {
        $(that).find('.error').fadeOut('fast', function(){
            $(this).css('top', '27px');
        });
        $(that).find('.error').fadeIn('fast', function(){
            $(that).find('.username').focus();
        });
        return false;
    }

    verify(username);
}

function register_click() {
    var that = $('.container .form');
    var code = document.getElementById('code').value;
    var username = $(that).find('.username').val();
    var password = $(that).find('.password').val();
    var re_password = $(that).find('.repassword').val();

    console.log(username, password, re_password, code);
    if(username == '') {
        $(that).find('.error').fadeOut('fast', function(){
            $(this).css('top', '27px');
        });
        $(that).find('.error').fadeIn('fast', function(){
            $(that).find('.username').focus();
        });
        return false;
    }
    if(code == '') {
        console.log("code is ", code);
        $(that).find('.error').fadeOut('fast', function(){
            $(this).css('top', '96px');
        });
        $(that).find('.error').fadeIn('fast', function(){
            $(that).find('.code').focus();
        });
        return false;
    }
    if(password == '') {
        $(that).find('.error').fadeOut('fast', function(){
            $(this).css('top', '165px');
        });
        $(that).find('.error').fadeIn('fast', function(){
            $(that).find('.password').focus();
        });
        return false;
    }
    if(password !== re_password) {
        console.log(password, re_password);
        $(that).find('.error').fadeOut('fast', function(){
            $(this).css('top', '234px');
        });
        $(that).find('.error').fadeIn('fast', function(){
            $(that).find('.repassword').focus();
        });
        return false;
    }

    register(username, password, code);
};
