$.getComments = function(ItemId){
    var cssObj = {
        'background-image' : 'url("/img/loader.gif")',
        'background-repeat' : 'no-repeat',
        'background-position' : '50% 50%'
    };
    $('#form-comment :input').attr('disabled', 'true');
    $.post("/ajax.php", ({Action: 'getComments', ItemId: ItemId, Target: Target}), function(data) {
        $('#comments').html(data).css('background', 'none');
        $('#form-comment :input').removeAttr('disabled');
    });
}

$(document).ready(function(){
    $('#form-comment').submit(function(){
        re = /[a-zA-Z0-9\.\-_]+\@[a-zA-Z0-9\.\-_]+\.[a-zA-Z]+/;
        if (!re.test($('#form-comment input:text[name=Email]').val()) && $('#form-comment input:text[name=Email]').val().length) {
            alert('Вы ввели некорректный e-mail');
            $('#form-comment input:text[name=Email]').focus();
            return false;
        }
		re = /^[0-9\-]{6,}$/;
        if (!re.test($('#form-comment input:text[name=ICQ]').val()) && $('#form-comment input:text[name=ICQ]').val().length) {
            alert('Вы ввели некорректный ICQ');
            $('#form-comment input:text[name=ICQ]').focus();
            return false;
        }
		if (!$('#form-comment textarea[name=Message]').val().length)	{
			alert('Вы не ввели текст комментария');
			$('#form-comment textarea[name=Message]').focus();
			return false;
		}
	
        $.post("/ajax.php", ({
            Action: 'addComment', 
			Target: Target, 
            ItemId: ItemId,
            Name: $('#form-comment input:text[name=Name]').val(),
            Email: $('#form-comment input:text[name=Email]').val(),
            ICQ: $('#form-comment input:text[name=ICQ]').val(),
            Message: $('#form-comment textarea[name=Message]').val()
        }), function(data){
            $.getComments(ItemId);
        });
        return false;

    });
});

