$(document).ready(function() {
   $('#addComment').click(function() {
      commentMes = $('#comment').val();
	  if(commentMes){
         if(typeof user == 'undefined') user = 'гость';
		 currentDate = new Date();
         fullDate = 'Сегодня в ' + currentDate.getHours() + ' ' + currentDate.getMinutes();
         $.ajax({
            type: "POST",
            url: "/AJAX/addCommentBP.php",
            data: "autor="+user+"& mes="+commentMes,
            success: function(data) {
               str = '<div id="Comment-bp_'+num+'">' +
                  '<table width="320" border="0" style="margin-bottom: 20px;">' +
                     '<tr>' +
                        /*'<td width="120" rowspan="3" valign="top" align="center" style="border-bottom: 1px solid #E0E0E0;">';
						if(user != 'гость') str +=
							'<a href="/user/'+user+'/"><img src="/users/Settings/Avatars/'+ava+'.jpg\" alt=\"\" /></a>';
						str += '</td>'*/
                        '<td width="320" valign="top" style="font-size:90%; border-top: 1px solid #87c445; border-bottom: 1px solid #E0E0E0; background: #f8f8f8; padding-left:6px">' +
                        '<a href="/user/'+user+'/" style="font-size:110%">'+user+'</a> написал(а)<br />'+fullDate+'</td>' +
                     '</tr>' +
                     '<tr>' +
                        '<td style="padding-left:6px"><p>'+commentMes+'</p></td>' +
                     '</tr>';
					 if(user != 'гость') {
						str +=
                     '<tr>' +
                        '<td style="border-bottom: 1px solid #E0E0E0; background: #f8f8f8; padding-left:6px"><a id="delComment-bp_'+num+'" style="font-size: 90%; cursor:pointer">Удалить</a></td>' +
                     '</tr>';
					 }
                  str += '</table>' +
               '</div>';
			   if(user != 'гость') {
				str +=
               '<div id="RestoreComment-bp_'+num+'">' +
                  '<table width="320" border="0" style="border: 1px solid #E0E0E0; padding: 5px; margin-bottom: 20px; background: #f8f8f8;">' +
                     '<tr>' +
                        '<td>Сообщение удалено. <a id="resComment-bp_'+num+'" style="font-size: 110%">Восстановить</a>.</td>' +
                     '</tr>' +
                  '</table>' +
               '</div>';
			   }
               $('#allComments').append(str);
               $('#RestoreComment-bp_'+num).hide();		   
               $('#comment').val("");
               $('#delComment-bp_'+num).click(function() {
                  alert('ku');return false;
				  n = $(this).attr('id').split("_")[1];
				  $('#Comment-bp_'+n).hide();
                  $('#RestoreComment-bp_'+n).show();
                  $.ajax({
                     type: "POST",
                     url: "/AJAX/delCommentBP.php",
                     data: "num="+n+"& user="+user,
                     success: function(data){}
                  });
               });
               $('#resComment-bp_'+num).click(function() {
                  n = $(this).attr('id').split("_")[1];
                  $('#Comment-bp_'+n).show();
                  $('#RestoreComment-bp_'+n).hide();
                  $.ajax({
                     type: "POST",
                     url: "/AJAX/restoreCommentBP.php",
                     data: "num="+n+"& user="+user,
                     success: function(data){}
                  });
               });
               num++;
            }
         });
      }
   });
	/*$(document).click(function(ev) {						
		e = ev.target?ev.target:ev.srcElement;
		alert($(e).attr('id'));
	});*/
});