function doLogin() {
	$("#popupBox .login .content").fadeOut("fast",function(){
		$("#popupBox .loading").fadeIn("fast",function(){
			$.ajax({
				type: "POST",
				url: "includes/lib/login.php",
				data: $("#popupBox .login .content").serialize(),
				dataType: "text",
				success: function(arr) {
					if (arr.length) {
						$("#popupBox .loading").fadeOut("fast",function() {
							$("#popupBox .login .content").fadeIn("fast");
						});
						alert(arr);
					} else {
						window.location.reload();
					}
				}
			});
		});
	});
}

function doLostPw() {
	$("#popupBox .lostpw .content").fadeOut("fast",function(){
		$("#popupBox .loading").fadeIn("fast",function(){
			$.ajax({
				type: "POST",
				url: "includes/lib/lostpw.php",
				data: "lostpwEmail="+$('#lostpwEmail').val(),
				dataType: "json",
				success: function(arr) {
					if (arr[0]) {
						$("#popupBox .loading").fadeOut("fast",function() {
							$("#popupBox .lostpw .content").fadeIn("fast");
						});
						alert(arr[1]);
					} else {
						alert(arr[1]);
						// window.location = '?p=index';
						window.location.reload();
					}
				}
			});
		});
	});
}

function delcomment(id) {
	$.ajax({
		type: "POST",
		url: "includes/lib/delcomment.php",
		data: "id="+id,
		dataType: "text",
		success: function(arr) {
			$('#c'+id).fadeOut('slow');
		}
	});
}

function addcomment(obj) {
	$('#comments .new-item').animate({opacity: 0}, 'slow');
	$.ajax({
		type: "POST",
		url: "includes/lib/addcomment.php",
		data: "comment="+$("#comments form.new-item textarea").val()+"&article_id="+$("#comments form.new-item input[name=article_id]").val(),
		dataType: "json",
		success: function(arr) {
			if (arr[0]) {
				alert(arr[1]);
				$('#comments .new-item').animate({opacity: 1}, 'slow');
			} else {
				$.scrollTo("#comments", {easing: 'easeOutElastic', duration: 1000, onAfter: function(){
					$("#comments .comments").after(arr[1]);
					$("#c"+arr[2]).fadeIn('slow');
					$("#comments form.new-item textarea").val('');
					$('#comments .new-item').animate({opacity: 1}, 'slow');
				}});
			}
		}
	});
}

function delcommforum(id) {
	$.ajax({
		type: "POST",
		url: "includes/lib/delcommforum.php",
		data: "id="+id,
		dataType: "text",
		success: function(arr) {
			$('#c'+id).fadeOut('slow');
		}
	});
}

function addcommforum(obj) {
	$('#comments .new-item').animate({opacity: 0}, 'slow');
	$.ajax({
		type: "POST",
		url: "includes/lib/addcommforum.php",
		data: "comment="+$("#comments form.new-item textarea").val()+"&article_id="+$("#comments form.new-item input[name=article_id]").val(),
		dataType: "json",
		success: function(arr) {
			if (arr[0]) {
				alert(arr[1]);
				$('#comments .new-item').animate({opacity: 1}, 'slow');
			} else {
				$.scrollTo("#comments", {easing: 'easeOutElastic', duration: 1000, onAfter: function(){
					$("#comments .comments").after(arr[1]);
					$("#c"+arr[2]).fadeIn('slow');
					$("#comments form.new-item textarea").val('');
					$('#comments .new-item').animate({opacity: 1}, 'slow');
				}});
			}
		}
	});
}