function switchCommentsPage(type,id,page) {
	commentsDIV = $("#comments_"+type+id);
	commentsLoadingDIV = $("#comments_ld_"+type+id);
	commentsLoadingDIV.fadeIn("slow", function () {
		$.ajax({
			type: "POST",
			url: "/comments/page/",
			timeout: 5000,
			data: "type=" + type + "&id=" + id + "&page=" + page,
			success: function(msg){
				commentsDIV.fadeOut("slow", function() {
					commentsDIV.html(msg);
					commentsDIV.fadeIn("slow");					
				});
			},
			error: function() {
				commentsLoadingDIV.fadeIn("slow");
				alert('Извините, произошла ошибка.');
			}
		});
	});
}

function sendComment(type,id) {
	commentsForm = $("#comments_"+type+id+"_form");
	commentsLoading = $("#comments_"+type+id+"_loading");
	commentsName = $("#comments_"+type+id+"_name").val();
	commentsText = $("#comments_"+type+id+"_text").val();
	if (commentsName == '') {
		alert('Вы не указали свое имя');
		return false;
	}
	if (commentsText == '') {
		alert('Вы не указали текст комментария');
		return false;
	}
	commentsLoading.fadeOut("slow", function() {
		commentsLoading.html('<img src=\"/files/imgs/loading.gif\" />&nbsp;Отправляем комментарий...');
		commentsLoading.fadeIn("slow", function() {
		commentsForm.fadeTo("slow", 0.2, function() {
			commentsLoading.fadeIn("slow", function () {
				$.ajax({
					type: "POST",
					url: "/comments/add/",
					timeout: 5000,
					data: "type=" + type + "&id=" + id + "&name=" + commentsName + "&text=" + commentsText,
					success: function(msg){
						commentsLoading.fadeOut("slow", function() {
							if (msg.charAt(0) == "0") {
								$("#comments_"+type+id+"_text").val("");									
								msg = msg.substr(1, msg.length - 1);
							}
							commentsLoading.html(msg);
							commentsLoading.fadeIn("slow", function() {
								commentsForm.fadeTo("slow", 1);		
							});
						});
					},
					error: function() {
						commentsLoadingDIV.fadeIn("slow");
						alert('Извините, произошла ошибка.');
					}
				});
			});
		});	
		});	
	});	
}