function getComments(media, media_id)
{
    new Ajax.Updater('comments-div', '/comments.php', {
        method: 'post', 
        parameters: 'get=1&media='+media+'&media_id='+media_id, 
    	onComplete: function(transport) {
    	    $('comment-process').hide()
    	    $('comments-div').show()
    	},
    	onLoading: function(transport) {
    	    $('comments-div').hide()
    	    $('comment-process').show()
    	},
    	onFailure: function(transport) {
    	   alert('error')
    	},
        evalScripts: true
    });	
}
function getCommentForm(media, media_id, id)
{
    Dialog.info({
      url: "/comments.php", 
      options: {method: 'post', parameters: 'ajax=1&form=1&media='+media+'&media_id='+media_id+(id? '&id='+id : ''), evalScripts: true}}, 
      {windowParameters: {className: "abris", width:640, title: "Комментарий:"}});
}
function saveComment(media, media_id) 
{    
  new Ajax.Updater('commentEditor', '/index.php', 
  {
    method: 'post', 
    parameters: Form.serialize('commentEditorForm'),
    onComplete: function(transport) {
        getComments(media, media_id)
    },
    onLoading: function(transport) {
        $('commentEditor').hide()
        $('comment-process').show()
    },
    onLoaded: function(transport) {
        $('comment-process').hide()
        $('commentEditor').show()
    },
    onFailure: function(transport) {
        alert('error')
    },
    evalScripts: true
  });
}

function deleteComment(id, media, media_id)
{
    if (!confirm('Вы действительно хотите удалить этот комментарий?')) return false
    
    Dialog.info("Пожалуйста, подождите ...", {windowParameters: {title: "Удаление комментария", width:250, height:100, className: "abris"}, showProgress: true});
    
    new Ajax.Updater('', '/index.php',
    {
        method: 'post',
        parameters: 'ajax=1&actComment-deleteComment='+id,
        onLoaded: function(transport) {
            Dialog.closeInfo()
            getComments(media, media_id)
        },
        onFailure: function(transport) {
            alert('error')
        },
        evalScripts: false
    });
}

var processComment = new Template('<div id="comment-process" style="margin-top:20px;display:none">Обработка данных...<br /><img src="/images/progress_bar.gif" border="0" /></div>')