﻿// JScript 파일
/*
function goSearch()
{
    var searchValue = document.searchForm.searchValue.value;
    var searchType = document.searchForm.searchType.value;
    
    if (searchValue.replace(/ /g, "").length < 1)
    {
        alert("검색어를 입력하세요.");
        document.searchForm.searchValue.focus();
        
        return;
    }
    
    top.location.href = location.pathname
        + "?boardID="+_boardID
        + "&searchType="+searchType
        + "&searchValue="+searchValue
        + "&sortType="+_sortType;
}

function goSortPage(sortType)
{
    top.location.href =location.pathname
        + "?boardID="+_boardID
        + "&searchType="+_searchType
        + "&searchValue="+_searchValue
        + "&sortType="+sortType;
}
*/

function getRadioFormValue(element)
{
    if (element != null)
    {
        for (i=0; i < element.length; i++)
        {
            if (element[i].checked) { return element[i].value; }
        }
    }
    else
    {
        return 0;
    }
}


/*
function showPassowrdForm(replyID)
{
    document.all.confirmPassowrd.value = "";
    
    document.all.passwordDiv.style.top = window.event.clientY + document.body.scrollTop - window.event.offsetY;
    document.all.passwordDiv.style.left = window.event.clientX + document.body.scrollLeft - window.event.offsetX;
    
    document.all.passwordDiv.style.display = "";
    document.all.confirmPassword.focus();
}

function submitPasswordForm(replyID)
{
    var pwd = "";
    if (document.all.confirmPassword != null && document.all.confirmPassword.value.replace(/ /g, "").length < 1)
    {
        alert("비밀번호를 입력하세요");
        document.all.confirmPassword.select();
        document.all.confirmPassword.focus();
    }
    else
    {
        pwd = document.all.confirmPassword.value;
        document.all.passwordDiv.style.display = "none";
        
		removeReply(replyID, pwd);
    }
}
*/
//////////////////////////////////

    _layerPhotoView = null;
    _layerPhoto = null;
    _lblPhoto= null;
	
    _layerReplyView = null;
    _layerReply = null;
    _lblReply= null;
    
    _currentPostID = null;
	
    function setCurrentReplyLayer(currPostID)
    {
        if (currPostID != null)
        {
            _currentPostID = currPostID;
            _layerReplyView = eval("document.all.layerReplyView"+currPostID);
            _layerReply = eval("document.all.layerReply"+currPostID);
            _lblReply = eval("document.all.lblReply"+currPostID);
        }
        else
        {
            _layerReplyView = document.all.layerReplyView;
            _layerReply = document.all.layerReply;
            _lblReply = document.all.lblReply;    
        }
    }
    
	function showReply(page, replyPostID, isAllowAttach, allwaysView, isAddHitCount, userID)
	{
	    if (!isAllowAttach) { return; }
	    
	    setCurrentReplyLayer(replyPostID);
	  
	    if (_layerReply.style.display == "" && !allwaysView)
		{
		    if (_layerReplyView != null) { _layerReplyView.style.display = "none"; }
		    _layerReply.style.display = "none";
		    if (_lblReply != null) _lblReply.style.fontWeight = "normal";
		}
		else
		{
		    var url = "./AJAX/AttachView.aspx";
			var pars
			    = "postID=" + replyPostID
				+ "&page=" + page;
		
		    if (userID != null) { pars += "&userID="+userID; }
		    if (isAddHitCount != null) { pars += "&isAddHitCount="+isAddHitCount; }
		    
			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)
			{
			    if (_layerReplyView != null) { _layerReplyView.style.display = ""; }
				_layerReply.style.display = "";
//				layerPhotoList.style.display = "none";
				if (_lblReply != null) _lblReply.style.fontWeight = "bold";
				_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";
	}
	
	*/
	_replyWriteForm = null;
	function SetReplyWriteForm(currPostID)
	{
	    if (currPostID !=null)
	    {
	        _replyWriteForm = eval("document.replyWriteForm"+currPostID);
	    }
	    else
	    {
	        _replyWriteForm = document.replyWriteForm;
	    }
	}
	
	function submitReplyWriteForm(currPostID)
	{
	    SetReplyWriteForm(currPostID);
	
		if (getCheckedReplyIconNumber() < 0)
		{
			alert("이모티콘을 선택해 주세요.");
		}
		else if (_replyWriteForm.replyName != null && _replyWriteForm.replyName.value.replace(/ /g, "").length < 1)
		{
			alert("이름을 입력해 주세요.");
			_replyWriteForm.replyName.focus();
		}
		else if (_replyWriteForm.replyPassword != null && _replyWriteForm.replyPassword.value.replace(/ /g, "").length < 1)
		{
			alert("비밀번호를 입력해 주세요.");
			_replyWriteForm.replyPassword.focus();
		}
		else if (_replyWriteForm.description.value.replace(/ /g, "").length < 1)
		{
			alert("댓글 내용을 입력해 주세요.");
			_replyWriteForm.description.focus();
		}
		else
		{
			addReply(currPostID);
		}
	}
	
	function addReply(currPostID)
	{
		var url = "./AJAX/AddAttachPS.aspx";

        _currentPostID = currPostID;
        
		var pars
			= "postID=" + _replyWriteForm.postID.value;
			pars += "&description=" + encodeURIComponent(_replyWriteForm.description.value)
			pars += "&iconNumber=" + getCheckedReplyIconNumber();
			if (_replyWriteForm.replyName != null)
			{
				pars += "&replyName=" + encodeURIComponent(_replyWriteForm.replyName.value)
			}
			if (_replyWriteForm.replyPassword != null)
			{
				pars += "&replyPassword=" + encodeURIComponent(_replyWriteForm.replyPassword.value)
			}

		var newAjax = new Ajax.Request(
			url,
			{
				method: "post",
				parameters: pars,
				onComplete : modifyReplyFinish
			});
			
		startFloatLabel("댓글을 입력하고 있습니다.");
	}
	
	function modifyReplyFinish(ajaxRequest)
	{
		stopFloatLabel();
		
		try { replyCnt = parseInt(ajaxRequest.responseText);} catch (exception) {}
        
		if (ajaxRequest.responseText == "true")
		{
		    //showReply(1, _currentPostID, true, true)
		    showReply(1, _currentPostID, true, true, false);
		}
		else if (!isNaN(replyCnt))
		{
		    _replyCntLayer = eval("replyCntLayer"+_currentPostID);
		    _replyCntLayer.innerHTML = replyCnt;
		     showReply(1, _currentPostID, true, true, false);
		} 
		else
		{
			alert(ajaxRequest.responseText);
		}
	}
	
	
	function getCheckedReplyIconNumber()
	{
	    var iconNumber = -1;
		
		for (i = 0; i < _replyWriteForm.iconNumber.length; i++)
		{
			if (_replyWriteForm.iconNumber[i].checked)
			{
				iconNumber = _replyWriteForm.iconNumber[i].value;
				break;
			}
		}
		
		return iconNumber;
	}
	
	/*
	function confirmRemoveReply(replyID, postID)
	{
	    var replyPassword = window.showModalDialog("/Common/PasswordInputForm.htm", "", "dialogHeight:150px;dialogWidth:200px;");
		if (replyPassword != null)
		{
			removeReply(replyID, replyPassword, postID);
		}
	}
	*/
	
	function removeReply(replyID, replyPassword, userID)
	{
	    var url = "./AJAX/RemoveAttachPS.aspx";

		var pars
			= "replyID=" + replyID;
		if (_currentPostID != null) { pars += "&postID="+_currentPostID; }	
		if (replyPassword != null) { pars += "&replyPassword=" + encodeURIComponent(replyPassword); }
		if (userID != null) { pars += "&userID="+encodeURIComponent(userID); }

		var newAjax = new Ajax.Request(
			url,
			{
				method: "post",
				parameters: pars,
				onComplete : modifyReplyFinish
			});
			
		startFloatLabel("댓글을 삭제하고 있습니다.");
	}
	
	function removePasswordReply(clickedObj, replyID, postID)
	{
	    _currentPostID = postID;
	    
	    showReplyPasswordForm(clickedObj, replyID);
	}
	
	
	function showAnswer(page, answerTarget, allwaysView)
	{
	    if (layerAnswerView.style.display == "" && !allwaysView)
		{
		    layerAnswerView.style.display = "none";
		    layerAnswer.style.display = "none";
		    if (document.all.lblAnswer != null) lblAnswer.style.fontWeight = "normal";
		}
		else
		{
		    
		    var url = "./AJAX/AnswerView.aspx";
			var pars
			    = "postID=" + answerTarget
				+ "&page=" + page;
		
		    
			var newAjax = new Ajax.Request(
				url,
				{
					method: "post",
					parameters: pars,
					onComplete : showAnswerFinish
				});
			
			
			startFloatLabel("답글 리스트를 불러오고 있습니다.");
		}
	}
	
	function showAnswerFinish(ajaxRequest)
	{
		stopFloatLabel();
		
		if (ajaxRequest.responseText == "fail")
		{
			alert("답글리스트를 가져오는 중 오류가 발행했습니다.");
		}
		else
		{
			if (ajaxRequest.responseText.replace(/ /g, "").length > 0)
			{
			    layerAnswerView.style.display = "";
				layerAnswer.style.display = "";
				
				if (document.all.lblAnswer != null) lblAnswer.style.fontWeight = "bold";
				
				layerAnswer.innerHTML = ajaxRequest.responseText;
			}
		}
	}
	
	
    function setCurrentPhotoLayer(currPostID)
    {
        if (currPostID != null)
        {
            _currentPostID = currPostID;
            _layerPhotoView = eval("document.all.layerPhotoView"+currPostID);
            _layerPhoto = eval("document.all.layerPhoto"+currPostID);
            _lblPhoto = eval("document.all.lblPhoto"+currPostID);
        }
        else
        {
            _layerPhotoView = document.all.layerPhotoView;
            _layerPhoto = document.all.layerPhoto;
            _lblPhoto = document.all.lblPhoto;    
        }
    }
    
	function showPhoto(page, photoPostID, isAllowAttach, allwaysView, isAddHitCount)
	{
	    if (!isAllowAttach) { return; }
	    
	    setCurrentPhotoLayer(photoPostID);
	  
	    if (_layerPhoto.style.display == "" && !allwaysView)
		{
		    if (_layerPhotoView != null) { _layerPhotoView.style.display = "none"; }
		    _layerPhoto.style.display = "none";
		    if (_lblPhoto != null) _lblPhoto.style.fontWeight = "normal";
		}
		else
		{
		    var url = "./AJAX/PhotoView.aspx";
			var pars
			    = "postID=" + photoPostID
				+ "&page=" + page;
		
		    if (isAddHitCount != null) { pars += "&isAddHitCount="+isAddHitCount; }
		    
			var newAjax = new Ajax.Request(
				url,
				{
					method: "post",
					parameters: pars,
					onComplete : showPhotoFinish
				});
			
			
			startFloatLabel("사진을 불러오고 있습니다.");
		}
	}
	
	function showPhotoFinish(ajaxRequest)
	{
		stopFloatLabel();
		
		if (ajaxRequest.responseText == "fail")
		{
			alert("사진 리스트를 가져오는 중 오류가 발행했습니다.");
		}
		else
		{
			if (ajaxRequest.responseText.replace(/ /g, "").length > 0)
			{
			    if (_layerPhotoView != null) { _layerPhotoView.style.display = ""; }
				_layerPhoto.style.display = "";
				_layerPhoto.style.overflow = "auto";
				_layerPhoto.style.width = "670px";
				_layerPhoto.style.height = "130px";
				//overflow: auto; width: 680px; height: 90px;
				
				if (_lblPhoto != null) _lblPhoto.style.fontWeight = "bold";
				
				_layerPhoto.innerHTML = ajaxRequest.responseText;
			}
		}
	}