function preview(msg)
{
	var url="preview.php";
	var param="msg="+encodeURIComponent(msg.value);
	goto1("preview.php",param,"preview");
}

function chkTopicForum(x)
{
	if(x.value.length>0)
		$("topicForumBox").innerHTML="<img src='"+path+"images/t.gif' width=15>";
	else
		$("topicForumBox").innerHTML="<img src='"+path+"images/f.gif' width=15>";
}

function chkDetailForum(x)
{
	if(x.value.length>0)
		$("detailForumBox").innerHTML="<img src='"+path+"images/t.gif' width=15>";
	else
		$("detailForumBox").innerHTML="<img src='"+path+"images/f.gif' width=15>";
}

function chkNameForum(x)
{
	if(x.value.length>0)
		$("nameForumBox").innerHTML="<img src='"+path+"images/t.gif' width=15>";
	else
		$("nameForumBox").innerHTML="<img src='"+path+"images/f.gif' width=15>";
}

function chkSubmitReply(topicID,mainTopic)
{
	var chkForm=0;
	var chkWord="t.gif";

	if($("guest").value==1)
	{
		if($("nameForumBox").innerHTML.indexOf(chkWord)==-1)
		{
			chkNameForum($("name"));
			$("name").focus();
			chkForum++;
			return false;
		}
	}
	if($("detailForumBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkDetailForum($("message"));
		$("message").focus();
		chkForm++;
		return false;
	}
	else if($("spamBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkSpam("spam");
		$("spam").focus();
		chkForm++;
		return false;
	}

	if(chkForm==0)
	{
		var url="postForum.php";
		var param="detail="+encodeURIComponent($("message").value);
		param+="&topicID="+encodeURIComponent(topicID);
		param+="&mainTopicID="+encodeURIComponent(mainTopic);
		if($("guest").value==1)
		{
			param+="&name="+encodeURIComponent($("name").value);
		}
		param+="&action=postReply";


		$("submit").disabled=true;
		$("view").disabled=true;
		$("submit").value="กรุณารอสักครู่";
		$("view").value="กรุณารอสักครู่";

		postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"submitZone",path+"images/loading4.gif",
		function (text)
		{
			if(text=='error')
			{
				$("submitZone").innerHTML="ERROR";
			}
			else if(text!='')
			{
				//$('progressComment').innerHTML='';
				/*goto1('listComment.php','albumID='+albumID,'comment');
				goto1('commentAlbum.php','albumID='+albumID,'commentForm');
				parent.location='#topComment';
				goto1('updateDetailOfAlbum.php','albumID='+albumID+'&action=comment','commentDetail');*/
				window.location=path+"forum/findMsg.php?replyID="+text;
				//window.location.reload();
//				window.location=window.location.href+'#'+text;
			}
		});

	}
	else
		alert("กรุณากรอกข้อมูลให้ครบถ้วน");
}

function chkSubmitEdit(replyID,topicID,mainTopic,No)
{
	var chkForm=0;
	var chkWord="t.gif";

	if($("detailForumBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkDetailForum($("message"));
		$("message").focus();
		chkForm++;
		return false;
	}
	else if($("spamBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkSpam("spam");
		$("spam").focus();
		chkForm++;
		return false;
	}
	else if(No==0)
	{
		if($("topicForumBox").innerHTML.indexOf(chkWord)==-1)
		{
			chkTopicForum("topic");
			$("topic").focus();
			chkForm++;
			return false;
		}
	}

	if(chkForm==0)
	{
		var url="postForum.php";
		var param="detail="+encodeURIComponent($("message").value);
		param+="&replyID="+encodeURIComponent(replyID);
		param+="&topicID="+encodeURIComponent(topicID);
		param+="&mainTopicID="+encodeURIComponent(mainTopic);
		param+="&No="+encodeURIComponent(No);
		if(No==0)
		{
			param+="&topic="+encodeURIComponent($("topic").value);
		}
		if($("stick"))
		{
			if($("stick").checked==true)
				param+="&stick=1";
			else
				param+="&stick=0";
		}
		else
			param+="&stick=0";

		if($("lock"))
		{
			if($("lock").checked==true)
				param+="&lock=1";
			else
				param+="&lock=0";
		}
		else
			param+="&lock=0";
		param+="&action=editReply";

		$("submit").disabled=true;
		$("view").disabled=true;
		$("submit").value="กรุณารอสักครู่";
		$("view").value="กรุณารอสักครู่";

		postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"submitZone",path+"images/loading4.gif",
		function (text)
		{
			if(text=='error')
			{
				$("submitZone").innerHTML="ERROR";
			}
			else if(text!='')
			{
				window.location=path+"forum/findMsg.php?replyID="+text;
			}
		});

	}
	else
		alert("กรุณากรอกข้อมูลให้ครบถ้วน");
}

function chkSubmitTopic(mainTopic)
{
	var chkForm=0;
	var chkWord="t.gif";

	if($("topicForumBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkTopicForum($("topic"));
		$("topic").focus();
		chkForm++;
		return false;
	}
	else if($("detailForumBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkDetailForum($("message"));
		$("message").focus();
		chkForm++;
		return false;
	}
	else if($("spamBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkSpam("spam");
		$("spam").focus();
		chkForm++;
		return false;
	}

	if(chkForm==0)
	{
		var url="postForum.php";
		var param="topic="+encodeURIComponent($("topic").value);
		param+="&detail="+encodeURIComponent($("message").value);
		param+="&mainTopicID="+encodeURIComponent(mainTopic);

		if($("stick"))
		{
			if($("stick").checked==true)
				param+="&stick=1";
			else
				param+="&stick=0";
		}
		else
			param+="&stick=0";

		if($("lock"))
		{
			if($("lock").checked==true)
				param+="&lock=1";
			else
				param+="&lock=0";
		}
		else
			param+="&lock=0";

		param+="&action=postTopic";

		$("submit").disabled=true;
		$("view").disabled=true;
		$("submit").value="กรุณารอสักครู่";
		$("view").value="กรุณารอสักครู่";
		postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"submitZone",path+"images/loading4.gif",
		function (text)
		{
			if(text=='error')
			{
				$("submitZone").innerHTML="ERROR";
			}
			else if(text!='')
			{
				parent.location=text;
				//window.location.reload();
			}
		});
	}
	else
		alert("กรุณากรอกข้อมูลให้ครบถ้วน");
}


function editPost(topicID,mainTopicID,msgID,No)
{
	goto1('formEdit.php','msgID='+msgID+'&topicID='+topicID+'&mainTopicID='+mainTopicID+'&No='+No,'postZone');
	$("submit").focus();
}

function delMsg(replyID,No,topicID,mainTopicID)
{
	if(No==0)
		var msg="ลบหัวข้อนี้ ?";
	else
		var msg="ลบข้อความนี้ ?";

	if(!confirm(msg))
		return false;



	var url="delForum.php";
	var param="replyID="+replyID;
	param+="&No="+No;
	param+="&topicID="+topicID;
	param+="&mainTopicID="+mainTopicID;
	param+="&action=delReply";

	postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"displayMsg"+replyID,path+"images/loading2.gif",
	function (text)
	{
		if(text=='error')
		{
			$("displayMsg"+replyID).innerHTML="ERROR";
		}
		else if((text!='')&&(No!=0))
		{
			window.location=path+"forum/findMsg.php?replyID="+text;
		}
		else if((text!='')&&(No==0))
		{
			window.location=path+"forum/findMsg.php?topicID="+text;
		}
	});
}
function movePost(topicID,moveTo)
{

	if(moveTo!=0)
	{
		if(confirm("ย้ายหัวข้อ ?"))
		{
			postDataReturnTextPic('moveForum.php', 'topicID='+topicID+'&moveTo='+moveTo+"&r="+new Date().getTime(),"moveForumZone",path+"images/loading3.gif",
			function (text)
			{
				if(text=='error')
				{
					alert("ERROR");
				}
				else
				{
					window.location.reload();
				}
			});
		}
	}
}
function adviceDel(userID,replyID)
{
	//alert("userID : "+userID+"-replyID : "+replyID);
	if(confirm("ต้องการแจ้งลบหัวข้อนี้ ?"))
	{
		postDataReturnTextPic('shouldDel.php', 'userID='+userID+'&replyID='+replyID+"&r="+new Date().getTime(),"shouldDelZone"+replyID,path+"images/loading3.gif",
		function (text)
		{
			if(text=='error')
			{
				alert("แจ้งลบไม่สำเร็จ");
			}
			else
			{
				$("shouldDelZone"+replyID).innerHTML="";
				alert("ขอบคุณมากค่ะ ทางเราจะเร่งดำเนินการตรวจสอบอย่างรวดเร็ว");
			}
		});
	}
}

function voteGood(id)
{
	postDataReturnTextPic('voteGood.php', 'userID='+id+"&r="+new Date().getTime(),"progressVote",path+"images/loading3.gif",
	function (text)
	{
		if(text=='error1')
			alert("คุณไม่สามารถ Vote ให้ตัวเองได้");
		else if(text=='error2')
			alert("คุณได้โหวตไปแล้ว กรุณาโหวตใหม่ในวันพรุ่งนี้นะคะ");
		else if(text=='ok')
			alert("ได้รับการโหวตเรียบร้อยแล้วค่ะ");
		else
			alert(text);
		$("progressVote").innerHTML="<br>";
	});
}
/*
function chkSubmitReply(albumID)
{
	var chkForm=0;
	var chkWord="t.gif";

	if($("nameCommentBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkNameComment("nameComment");
		$("nameComment").focus();
		chkForm++;
	}
	else if($("spamBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkSpamComment("spam");
		$("spam").focus();
		chkForm++;
	}
	else if($("detailCommentBox").innerHTML.indexOf(chkWord)==-1)
	{
		chkDetailComment("detailComment");
		$("detailComment").focus();
		chkForm++;
	}


	if(chkForm==0)
	{

		var url="commentAlbum.php";
		var param="name="+encodeURIComponent($("nameComment").value);
		param+="&userID="+encodeURIComponent($("userID").value);
		param+="&detail="+encodeURIComponent($("detailComment").value);
		param+="&albumID="+encodeURIComponent(albumID);
		param+="&action=addDB";

		$("submit").disabled=true;

		postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"submit",path+"images/loading4.gif",
		function (text)
		{
			if(text=='error')
			{
				$("commentForm").innerHTML="ERROR";
			}
			else if(text=='ok')
			{
				//$('progressComment').innerHTML='';
				goto1('listComment.php','albumID='+albumID,'comment');
				goto1('commentAlbum.php','albumID='+albumID,'commentForm');
				parent.location='#topComment';
				goto1('updateDetailOfAlbum.php','albumID='+albumID+'&action=comment','commentDetail');
			}
			else
				alert(text);
		});

	}/*
	else
		alert("กรุณากรอกข้อมูลให้ครบถ้วน");
	

}*/
