jQuery(function(){
    $.trostian.call();

    $('input[name=check_login]').click(function(){
        var login = $('input[name=reg_login]').val();
        if(login){
            var text = $.ajax({
                url:'/reg/login_check',
                type:'POST',
                data:{
                    'login': login
                },
                async:false
            }).responseText;

            if(text){
                alert('Пользователь с таким логином уже зарегистрирован');
            }else{
                alert('Логин свободный');
            }
        }else{
            alert('Введите логин');
        }
    });

    $('select[name=country],select[name=src[country]]').change(function(){
        $('select[name=city] option,select[name=src[city]] option').remove();
        $.post('/reg/get_city',
        {
            'country': $(this).val()
        },
        function(city){
            $('select[name=src[city]]').append('<option value="">Не выбрано</option>');
            $.each(city,function(k,v){
                $('select[name=city],select[name=src[city]]').append('<option value="'+k+'">'+v+'</option>');
            })
        }, 'json')
    });

    $('input[name=avatar]').change(function(){
        $('input[name=send]').trigger('click');
    });
});


