﻿	function showReply(page, photoID, alwaysShow)
	{
		if ( (layerReply.style.display == "" || layerReply.style.display == "inline")
			&& !alwaysShow)
		{
			layerReply.style.display = "none";
		}
		else
		{
			var url = "/PhotoShare/AJAX/GetReplyTable.aspx";
			var pars
				= "page=" + page;

			pars
				= pars 
				+ "&photoID=" + photoID;
			
			var newAjax = new Ajax.Request(
				url,
				{
					method: "post",
					parameters: pars,
					onComplete : showReplyFinish
				});
			
			startFloatLabel("댓글 리스트를 가져오고 있습니다.");
		}
	}
	
	function showReplyFinish(ajaxRequest)
	{
		stopFloatLabel();
		
		if (ajaxRequest.responseText == "fail")
		{
			alert("댓글리스트를 가져오는 중 오류가 발행했습니다.");
		}
		else
		{
			if (ajaxRequest.responseText.replace(/ /g, "").length > 0)
			{
				layerReply.style.display = "";
//				layerPhotoList.style.display = "none";
				
				layerReply.innerHTML = ajaxRequest.responseText;
			}
		}
	}
	
	function showPhotoList()
	{
		layerReply.style.display = "none";
//		layerPhotoList.style.display = "";
		if (document.all.lblPhotoReply != null) lblPhotoReply.style.fontWeight = "normal";
		if (document.all.lblKeywordReply != null) lblKeywordReply.style.fontWeight = "normal";
	}
	
	
	function submitReplyWriteForm(photoReplyIcon)
	{
		if (photoReplyIcon == null) photoReplyIcon = -1;
		document.replyWriteForm.photoReplyIcon.value = photoReplyIcon;
		
		if ($F(document.replyWriteForm.photoReplyIcon) < 0)
		{
			alert("이모티콘을 선택해 주세요.");
		}
		else if (document.replyWriteForm.replyPassword != null && document.replyWriteForm.replyPassword.value.blank())
		{
			alert("비밀번호를 입력해 주세요.");
			document.replyWriteForm.replyPassword.focus();
		}
		else if (document.replyWriteForm.description.value.blank())
		{
			alert("댓글 내용을 입력해 주세요.");
			document.replyWriteForm.description.focus();
		}
		else
		{
			addReply();
		}
	}
	
	
	function addReply()
	{
		var url = "/PhotoShare/AJAX/AddReplyPS.aspx";

		var pars
			= $("replyWriteForm").serialize();

		var newAjax = new Ajax.Request(
			url,
			{
				method: "post",
				parameters: pars,
				onComplete : modifyReplyFinish
			});
			
		startFloatLabel("댓글을 입력하고 있습니다.");
	}
	
	function modifyReplyFinish(ajaxRequest)
	{
		stopFloatLabel();
		
		if (ajaxRequest.responseText == "true")
		{
			var photoID = document.replyWriteForm.photoID.value;
			
			showReply(1, photoID, true)
		}
		else
		{
			alert(ajaxRequest.responseText);
		}
	}
	

	function removeReply(replyID, replyPassword)
	{
		if (replyPassword == null) replyPassword = "";
		
		var url = "/PhotoShare/AJAX/RemoveReplyPS.aspx";

		var pars
			= "replyID=" + replyID
			+ "&replyPassword=" + replyPassword;

		var newAjax = new Ajax.Request(
			url,
			{
				method: "post",
				parameters: pars,
				onComplete : modifyReplyFinish
			});
			
		startFloatLabel("댓글을 삭제하고 있습니다.");
	}