﻿function dopostcomment(id){
showloadernow();
$("#comment_button").html("<img src='http://www.wink.in.th/backend/images/loading.gif'>");
$.ajax({
type: "POST",
url : "http://www.wink.in.th/backend/news_post_comment.php?id="+id,
data: "text="+($('#comment_text').val())+"&name="+(document.getElementById("comment_name").value),
success : function (data) {
hideloadernow();
if(data=="true")
{
$("#comment_button").fadeOut("fast");
$("#comment_button").html("<font color=\"lime\">ข้อความคุณได้โพสแล้ว...</font><br><br><span onClick='dopostcomment("+id+");'><img src=http://www.wink.in.th/backend/images/com.jpg border=0></span>");
document.getElementById("comment_text").value = "";
$("#comment_button").fadeIn("fast");
setTimeout(function(){loadcomment(id);},500);
}else if(data=="fill")
{
$("#comment_button").fadeOut("fast");
$("#comment_button").html("<font color=\"red\">คุณยังไม่ได้ระบุข้อความหรือมีโค้ดที่ไม่ถูกต้องในการโพส (อนุณาตเฉพาะ &lt;b&gt;)</font><br><br><span onClick='dopostcomment("+id+");'><img src=http://www.wink.in.th/backend/images/com.jpg border=0></span>");
$("#comment_button").fadeIn("fast");
}else if(data=="locked"){
$("#comment_button").fadeOut("fast");
$("#comment_button").html("<font color=\"red\">กระทู้ที่คุณกำลังทำการโพสแสดงความคิดเห็น กระทู้ถูกล็อกระหว่างที่คุณกำลังพิมพ์ข้อความ</font><br><br><span onClick='dopostcomment("+id+");'><img src=http://www.wink.in.th/backend/images/com.jpg border=0></span>");
$("#comment_button").fadeIn("fast");
setTimeout(function(){doloadajaxnews(id);},500);
}else{
$("#comment_button").fadeOut("fast");
$("#comment_button").html("<font color=\"red\">มีปัญหาเกิดขึ้น</font> : "+data+"<br><br><span onClick='dopostcomment("+id+");'><img src=http://www.wink.in.th/backend/images/com.jpg border=0></span>");
$("#comment_button").fadeIn("fast");
}

}

});
}function loadcomment(id)
		{
		showloadernow();
		$.ajax({
url : "http://www.wink.in.th/backend/news_comment.php?id="+id,
success : function (data) {
$("#comment_list").hide();
$("#comment_list").html(data);
setTimeout(function(){$("#comment_list").fadeIn("normal"); hideloadernow(); },500);
}
});
		}function loadawesomeclick(id,html)
		{
		showloadernow();
		$.ajax({
url : "http://www.wink.in.th/backend/news_js.php?view=awesome&id="+id,
success : function (data) {
$("#"+html).html(data);
setTimeout(function(){hideloadernow();},500);
}
});
		}function addawesome(id,html,bt_html)
		{
		showloadernow();
		$.ajax({
url : "http://www.wink.in.th/backend/news_js.php?add=awesome&id="+id,
success : function (data) {

if(data=="false")
	{
	alert('คุณได้ให้เฉ๋งงกับข้อคิดเห็นนี้แล้ว');
	}else{
	checkawesome(id,bt_html);
	loadawesomeclick(id,html);
	}

setTimeout(function(){hideloadernow();},500);
}
});
		}function checkawesome(id,html)
		{
		showloadernow();
		$.ajax({
url : "http://www.wink.in.th/backend/news_js.php?check=awesome&id="+id,
success : function (data) {

if(data=="false")
	{
	$("#"+html).hide();
	//document.getElementById(html).style.display="none";
	}else{
	$("#"+html).fadeIn("normal");
	//document.getElementById(html).style.display="block";
	}

setTimeout(function(){hideloadernow();},500);
}
});
		}
