function new_user(){
    if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
    var url = "/user/new_/";
    find = $('#find').val();
    if(find != '' && find != default_variable.find ){
    }else{
        find = '';
    }
    var param = {
        find : find
    };
    $.ajax({
        url: url,
        type: 'post',
        data: param,
        success: function (html)
        {
            $('#content').html(html);
            $('#control').append("<input type='button' value='Save' id='button_save' disabled onclick='save_user();'>");
            $('#button_new_user').attr('disabled' , true);
        }
    });
}

function chek_user_form(izmen){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        login = $('#login_edit').val();
        id = $('#id_edit').val(); 
        email = $('#email_edit').val(); 
        password = $('#password_edit').val(); 
        chek_password = $('#confirm_password_edit').val(); 
        
        type = document.getElementById('type_edit').options[document.getElementById('type_edit').selectedIndex].value;
        
        name = $('#name').val(); 
        surname = $('#surname').val(); 
        secname = $('#secname').val(); 
        phone = $('#phone').val(); 
        info = $('#info').val(); 
        
        
        count_login = login.length;
        count_email = email.length;
        count_password = password.length;
        count_chek_password = chek_password.length;
        
        count_name = name.length;
        count_surname = surname.length;
        count_secname = secname.length;
        count_phone = phone.length;
        
        k=0;

        if(count_login < 5 && izmen=='login_user'){
            k= 5 - count_login;
            $('#check_login_user').css('display ','');
            $('#check_login_user').html('<font color=red>Enter '+k+' sumbol</font>');
        }else{
            if(izmen == 'login_user'){ 
                $.ajax({
                    url: '/check/login/',
                    type: 'post',
                    data: {'login' : login, 'id' : id},
                    success: function (html)
                    {
                       $('#check_login_user').html(html);
                       chek_user_form('');
                    }
                });
                login_chek_div = document.getElementById('check_login_user').innerHTML;
                if(login_chek_div == ""){
                    document.getElementById('check_login_user').innerHTML = '';
                }
            }
        }
        
        if(count_name < 2 && izmen=='name'){
            k= 2 - count_name;
            $('#check_name').css('display', '');
            $('#check_name').html('<font color=red>Enter '+k+' sumbol </font>');
        }else{
            if(izmen == 'name'){
                $('#check_name').html('');
            }
        }
        
        if(count_surname < 2 && izmen=='surname'){
            k= 3 - count_surname;
            $('#check_surname').css('display','');
            $('#check_surname').html('<font color=red>Enter '+k+' sumbol</font>');
        }else{
            if(izmen == 'surname'){
                $('#check_surname').html('');
            }
        }
        if(count_secname < 2 && izmen=='secname'){
            k= 2 - count_secname;
            $('#check_secname').css('display','');
            $('#check_secname').html('<font color=red>Enter '+k+' sumbol</font>');
        }else{
            if(izmen == 'secname'){
                $('#check_secname').html('');
            }
        }
        
        if(count_phone < 5 && izmen=='phone'){
            k= 5 - count_phone;
            $('#check_phone').css('display','');
            $('#check_phone').html('<font color=red>Enter '+k+' sumbol</font>');
        }else{
            if(izmen == 'phone'){
                $('#check_phone').html('');
            }
        }
        if(izmen=='email' && email != ''){
            $('#check_email').css('display','');
            if(echeck(email) == true){
                $.ajax({
                    url: '/check/email_host/',
                    type: 'post',
                    data: {'email' : email, 'id' : id},
                    success: function (html)
                    {
                       $('#check_email').html(html);
                       chek_user_form('');
                    }
                });
                email_chek_div = $('#check_email').html();
                if(email_chek_div != '<font color=red>Error email</font>'){
                    $('#check_email').html('');
                }
            }else{
                $('#check_email').html('<font color=red>Error email</font>');
            }
        }else{
            if(izmen=='email'){
                $('#check_email').html('');
            }
        }

        if(count_password < 6 && count_password != 0 && izmen=='password'){
            k= 6 - count_password;
            $('#check_password').css('display', '');
            $('#check_password').html('<font color=red>Enter '+k+' sumbol</font>');
        }else{
            if(izmen == 'password'){
                $('#check_password').html('');
            }
        }
        if(izmen == 'chek_password'){
            if(chek_password != password){
                $('#check_chek_password').css('display', '');
                $('#check_chek_password').html('<font color=red>Passwords do not match </font>');
            }else{
                $('#check_chek_password').html('');
            }
        }


        check_login_user = $('#check_login_user').html();
        check_email = $('#check_email').html(); 
        check_password = $('#check_password').html(); 
        check_chek_password = $('#check_chek_password').html(); 
        check_name = $('#check_name').html(); 
        check_surname = $('#check_surname').html(); 
        check_secname = $('#check_secname').html(); 
        check_phone = $('#check_phone').html(); 

        if(
            login != '' &&
            name != '' && 
            surname != '' && 
            secname != '' && 
            email != '' &&
            check_login_user == '' &&
            check_email == '' &&
            check_password == '' &&
            check_chek_password == '' &&
            check_name == '' &&
            check_surname == '' &&
            check_secname == '' &&
            check_phone == ''
        ){
            $('#button_save').attr('disabled', false);
        }else{
            $('#button_save').attr('disabled', true);
        }
    }
    
    function default_user(){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        $('#button_save').remove();
        $('#button_new_user').attr('disabled' , false); 
    }
    
    function save_user(){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        login = $('#login_edit').val();
        id = $('#id_edit').val();
        type = $('#type_edit option:selected').val(); 
        email = $('#email_edit').val();
        password = $('#password_edit').val();
        name = $('#name').val();
        surname = $('#surname').val();
        secname = $('#secname').val();
        phone = $('#phone').val();
        mob_phone = $('#mob_phone').val();
        city = $('#city option:selected').val(); 
        adress = $('#adress').val();
        skype = $('#skype').val();
        icq = $('#icq').val();
        info = $('#info').val();
        find = $('#find').val();
        if(find != '' && find != default_variable.find ){
            find = find;
        }else{
            find = '';
        }
        $.ajax({
            url: '/user/save_/',
            type: 'post',
            data: {
                find : find,
                login_e : login,
                email : email,
                id : id,
                type : type,
                password_e : password,
                name : name,
                surname : surname,
                secname : secname,
                phone : phone,
                mob_phone : mob_phone,
                city : city,
                adress : adress,
                skype : skype,
                icq : icq,
                info : info},
            success: function (html)
            {
               $('#content').html(html);
               $('#button_new_user').attr('disabled' , false); 
               $('#button_save').remove();
            }
        });     
    }
    
    function check_del(mess, nomess, div, url, id){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        if (confirm(mess)){
                find = $('#find').val();
                if(find != '' && find != default_variable.find ){
                }else{
                    find = '';
                }
                $.ajax({
                url: url,
                type: 'post',
                data: {id : id , find : find},
                success: function (html)
                {
                   $('#'+div).html(html);
                   $('#button_new_user').attr('disabled' , false); 
                   $('#button_save').remove();
                }
            });
        }else{
            alert(nomess);
        }
    }
    
    function edit_user(div, url, id){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        default_user();
        find = $('#find').val();
        if(find != '' && find != default_variable.find ){
        }else{
            find = '';
        }
        $.ajax({
            url: url,
            type: 'post',
            data: {id : id , find : find},
            success: function (html)
            {
               $('#'+div).html(html);
               $('#control').append("<input type='button' value='Save' id='button_save' disabled onclick='save_user();'>");
               $('#button_new_user').attr('disabled' , true);
            }
        });
    }
    
    function ban_user(act, id){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        find = $('#find').val();
        if(find != '' && find != default_variable.find ){
        }else{
            find = '';
        }
        $.ajax({
            url: '/user/ban_/',
            type: 'post',
            data: {id : id, act : act , find : find},
            success: function (html)
            {
               $('#content').html(html);
               default_user();
            }
        });
    }
    
    function page_user(i){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        find = $('#find').val();
        if(find != '' && find != default_variable.find ){
        }else{
            find = '';
        }
        $.ajax({
            url: '/user/edit_/',
            type: 'post',
            data: {page_user : i , find : find},
            success: function (html)
            {
               $('#content').html(html);
               default_user();
            }
        });
    }
    
    function pagination_user(i){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        find = $('#find').val();
        if(find != '' && find != default_variable.find ){
        }else{
            find = '';
        }
        $.ajax({
            url: '/user/edit_/',
            type: 'post',
            data: {pagination_user : i , find : find},
            success: function (html)
            {
               $('#content').html(html);
               default_user();
            }
        });
    }
    
    function find_user(find){
        if(default_variable.ajax_send != 0){ $('#ajax_send_now').fadeIn('slow').html(default_variable.ajax_send_text); return false; }
        var param = {
        find : find
        };
        var url = "/user/find_/";
        $.ajax({
            url: url,
            type: 'post',
            data: param,
            success: function (html)
            {
                $('#content').html(html);
                $('#button_save').remove();
                $('#button_new_user').attr('disabled' , false);
            }
        });    
    }
    
    
