$(document).ready(function(){

 	$("a[rel=del_option]").click(function(){
    	var type = $(this).attr('type');
    	if (confirm('Удалить '+type+'?')) return true;
    	else return false;
    });

    $("a[rel=allow_join]").click(function(){
    	var user = $(this).attr('user');
    	var grtitle = $(this).attr('grtitle');
    	if (confirm('Разрешить пользователю "'+user+'" вступить в сообщество "'+grtitle+'"?')) return true;
    	else return false;
    });

    $("a[rel=exit_option]").click(function(){
    	var title = $(this).attr('grtitle');
    	if (confirm('Покинуть сообщество "'+title+'"?')) return true;
    	else return false;
    });

    $("a[rel=join_group]").click(function(){
    	var title = $(this).attr('grtitle');
    	var thetype = $(this).attr('type');
    	if (thetype=='locked') var more = '\nРегистрация в этом сообществе подтверждается модератором.'; else var more = '';
    	if (confirm('Вступить в сообщество "'+title+'"?'+more)) return true;
    	else return false;
    });

    $("a[rel=editblog]").click(function(){
    	$("#createblog").show();
    	document.location = '#createblog';
    	var id = $(this).attr('val');
    	var title = $("a[rel=title"+id+"]").text();
    	var text = $("sub[rel=text"+id+"]").text();

    	$("#blog_title").val(title);
    	$("#blog_text").val(text);
    	$("#blog_id").val(id);

    	$("#blog_form").attr('action','/groups/editblog/'+id);

    	return false;
    });

    $("a[rel=index_ddoms]").mouseover(function(){
    	var imgurl = $(this).attr('img');
    	var title = $(this).text();
    	if (!imgurl) return false;
    	$("#ddoms_index_img").html('<img src="/users/foto/'+imgurl+'"><br>'+title);
    	$(this).parent("li").attr('class','underline_');
    }).mouseout(function(){
    	//$("#ddoms_index_img").html('&nbsp;');
    	$(this).parent("li").attr('class','none');
    });

    $("a[rel=rating_minus]").click(function(){    	mid = $(this).attr('mid');
    	//alert (-1+' '+mid);
    	$("#RatingSpan").load('/ajax/txtrating',{mid : mid, rate : -1});
    	return false;
    });

    $("a[rel=rating_plus]").click(function(){
    	mid = $(this).attr('mid');
    	//alert (1+' '+mid);
    	$("#RatingSpan").load('/ajax/txtrating',{mid : mid, rate : 1});
    	return false;
    });

    $("a[rel=del_comment]").click(function(){
    	var type = $(this).attr('type');
    	if (!confirm('Удалить '+type+'?')) return false;
    	cid = $(this).attr('val');
    	//alert (cid);
    	$("#comment"+cid).load('/ajax/del_comment',{id : cid});
    	return false;
    });

    $("a[rel=edit_comment]").click(function(){
    	var type = $(this).attr('type');
    	cid = $(this).attr('val');
    	text = $("#commenttext"+cid).text();
    	$("#commenttext"+cid).html( "<textarea id='newcomment"+cid+"' class='edit_comment'>"+text+"</textarea><br>"+
    	"<input type='hidden' value='"+text+"' id='oldcomment"+cid+"'>"+
    	"<input type='button' onclick='save_edit_comment("+cid+")' value='сохранить'>"+
    	"<input type='button' onclick='cancel_edit_comment("+cid+")' value='отменить'>");
    	return false;
    });

    $("#notepad_content").keyup(function(){    	$("#notepad_save").removeAttr('disabled');
    });

    $("#notepad_save").click(function() {		$("#notepad_save").attr('disabled','disabled');
		content = $("#notepad_content").val();
		$("#notepad_span").load('/ajax/save_notepad',{content : content});
    });


});

function save_edit_comment(id) {
	text = $("#newcomment"+id).val();
	//alert (text);
	$("#commenttext"+id).load('/ajax/edit_comment',{id : id, text : text});
}

function cancel_edit_comment(id) {
	text = $("#oldcomment"+id).val();
	$("#commenttext"+id).html(text);
}
