function open_popup(n) {$(".popup"+n).show();}
function close_popup(n) {$(".popup"+n).hide();}
function pop_form(n){$(".pop_form"+n).toggle();}


$(function() {

$('.editinplace-save').click(function() {
    //alert($(this).attr('rel'));
    e = $(this).prev();
    $(this).toggle(); 
    $(this).removeClass('profile-enter');
    $(this).addClass('note-img');
    $(this).prev().toggle(); 
    i = $('#' + $(this).attr('rel')+'_input');
    $.post("ajax.php", { name: i.attr('name'), value : i.attr('value'), id : $('#id').attr('value'), 'action': "profile" } );       
    e.prev().children('div').html(i.attr('value'));
    e.css('display', 'block');
    
});

$('.editinplace').click(function() {
    //$(this).prev().children('div').html('<input type="text" id="'+$(this).attr('rel') + '_input' +'" name="'+$(this).attr('rel')+'" class="input" value="213" />');
    e = $(this);
    $(this).next().addClass('profile-enter');
    $(this).next().removeClass('note-img');
    
    element = $('<input />').attr( 
        { 
            'id' : e.attr('rel')+'_input', 
            'name' : e.attr('rel'), 
            'class' : 'input register_input_hide', 
            'value' : e.prev().children('div').text(), 
            'type' : 'text' 
        }
    );
    e.prev().children('div').html('');
    e.prev().children('div').append(element);
    e.css('display', 'none');
    e.next().css('display', 'block');
    
    
    //$(this).prev().children('div').insertAfter('<input id="2" />');
   // $(this).css('display', 'none');
   // $(this).next().css('display', 'block');
    //$(this).addClass('editinplace-save');
});      

$('.editinplace2').live('click',function() {
    e = $(this);
    element = $('<input />').attr( 
        { 
            'id' : e.attr('rel')+'_input', 
            'name' : e.attr('rel'), 
            'class' : 'input register_input_hide_1', 
            'value' : e.text().replace(/^\s+|\s+$/g,""), 
            'type' : 'text'
        }
    );
    
    element.keyup(function(e) {
                if(e.keyCode == 13) {   
                    $.post("ajax.php", { name: $(this).attr('name'), value : $(this).attr('value'), id : $('#id').attr('value'), 'action': "veteran" } );       
                    $(this).prev().text($(this).attr('value'));
                    $(this).prev().show();
                    $(this).hide();
                }
    });
    
    e.parent().append(element);
    e.hide();
    
}); 

$(".register_input_hide").live('keyup', function(e) {
    if(e.keyCode == 13) {
        e.preventDefault()
        var title = $(this).attr("title");            
        $(this).toggle(); 
        $(".an_a"+title).toggle(); 
        $.post("ajax.php", { name: $(this).attr('name'), value : $(this).attr('value'), id : $('#id').attr('value'), 'action': "profile" } );       
        $('#a'+title).html($(this).attr('value'));
    }
});

$(".register_input_hide_1").keyup(function(e) {
    //alert(e.keyCode);
    if(e.keyCode == 13) {
        e.preventDefault()
        var title = $(this).attr("title");            
        $(".an_a"+title).toggle(); 
        $.post("ajax.php", { name: $(this).attr('name'), value : $(this).attr('value'), id : $('#id').attr('value'), 'action': "veteran" } );       
        $('#a'+title).html($(this).attr('value'));
        $(this).remove(); 
             
    }
});


$('.sync').click(function(e) {
    e.preventDefault();
    id = $(this).attr('rel');
    $.ajax({
      url: $(this).attr('href') + '&ajax=1',
      success: function(response) {
            $('#' + id).html(response);
            return false;
      }
    }); 

    
    return false;
});

});


function sync(page, data, div) {
    
    $.ajax({
        url: page + '?ajax=1',
        data: data,
        success: function(response) {
            $('#' + div).html(response);
            return false;
        }
    });
}        

function _confirm() {
    
    var answer = confirm ("Вы уверены?");
    
    if (answer)
        return true;
    else
        return false;
}
