$("#refreshimg").live('click',function(){

		$.post('/incs/captcha/newsession.php');
		$("#captchaimage").load('/incs/captcha/image_req.php');
		return false;
                
	});
    
function check_comments_captcha()
{
    var code = $('#captcha').val();

    $.ajax({
       type: "GET",
       url: '/incs/captcha/process.php',
       data: 'ajax=true&action=check_captha&captcha=' + code,
       dataType: "text",
       success: function(data){
            if ('false' == data)
            {
                $.post('/incs/captcha/newsession.php');
                $("#captchaimage").load('/incs/captcha/image_req.php');
                alert('Неверно введен код на картинке. Попробуйте еще раз');
                return false;
            }
            else
            {
                addComment($('#comment_prod_id').val());
                return true;
            }
       },
       error:function(XMLHttpRequest, textStatus, errorThrown){
           alert(XMLHttpRequest + '|' + textStatus +  '|' + errorThrown);
       }
     });       
}

function addComment(m_id)
{
    var user_name;
    var text;
    user_name=$('#comments_user_name').val();
    text=$('#comments_text').val();
    if(text=='' || user_name=='')
    {
        alert('Заполните обязательные поля!');    
    }
    else
    {
    $.ajax({
                    url:'/elements/comment_add.php',
                    async: false,
                    type: 'POST',
                    data: 'comment_add=1&maket_id='+m_id+'&user_name='+user_name+'&text='+text,
                    dataType: 'html',
                    success: function(data){
                        //alert(data);
                        $('.comments_body').prepend(data);
                    },
                    error: function(data){
                        alert('Ошибка: '+data.statusText+' '+data.status);    
                    }
                });
    }   
}
