var CommentSubmitLock = false;
var domain_bbs = 'http://bbs-t.danawa.com';

function getGalleryCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer,nPage) {
	var url			= "/include/include_Gallery_comment.php";
	var pars		= "nSeq="+nSeq+"&nGroup="+nGroup+"&nBlogCateSeq1="+nBlogCateSeq1+"&nDpLayer="+nDpLayer+"&nPage="+nPage;
	var myAjax = new Ajax.Updater(
				{success: nDpLayer},
				url,
				{
					method: 'post',
					parameters: pars,
					onFailure: rpError
				});
} // end function getGalleryCommentList

//´ñ±Û ºí·¯¿À±â
function getCommunityCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer,nPage) {
	var url			= "/include/include_community_comment.php";
	var pars		= "nSeq="+nSeq+"&nGroup="+nGroup+"&nBlogCateSeq1="+nBlogCateSeq1+"&nDpLayer="+nDpLayer+"&nPage="+nPage;
	var myAjax = new Ajax.Updater(
				{success: nDpLayer},
				url,
				{
					method: 'post',
					parameters: pars,
					onFailure: rpError 
				});
}//end function


// ¿¡·¯ Ãâ·Â
function rpError()
{
	alert("Á¤»óÀûÀ¸·Î Ã³¸®µÇÁö ¾Ê¾Ò½À´Ï´Ù.");
}//end function rpError()

//Å¬¸¯½Ã ´ñ±Û ºÒ·¯¿À±â
function setCommunityCommentView(nSeq,nGroup,nBlogCateSeq1,nDpLayer)
{
	var obj = document.getElementById(nDpLayer);

	if(obj.style.display == "none")
	{
		obj.style.display = "block";

		getCommunityCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer);
	}else{
		obj.style.display = "none";
	}//end if
}//end function



function setGalleryCommentView(nSeq,nGroup,nBlogCateSeq1,nDpLayer)
{
	var obj = document.getElementById(nDpLayer);

	if(obj.style.display == "none")
	{
		obj.style.display = "block";

		getGalleryCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer);
	}else{
		obj.style.display = "none";
	}//end if
}//end function


//´ñ±Û ÀÌ¹ÌÁö Ã¼ÀÎÁö
function setRepImgChange(nId,nDpLayer) {
	var objDiv = document.getElementById(nDpLayer);
	var objImg = document.getElementById(nId);

	if(objDiv.style.display == "none") {
		objImg.src = "http://img.danawa.com/new/blog_brand/img/btn_up.gif";
		objDiv.style.display = "";
	}else{
		objImg.src = "http://img.danawa.com/new/blog_brand/img/btn_down.gif";
		objDiv.style.display = "none";
	}//end if

}//end function


//·Î±×ÀÎ
function setCommunityCommentLogin(frm)
{
	var nFrm = document.getElementById(frm);
	nFrm.hdnUrl.value = location.href;

	if(!nFrm.txtId.value)
	{
		alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
		nFrm.txtId.focus();
		return false;
	}//end if

	if(!nFrm.pwdPasswd.value)
	{
		alert("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
		nFrm.pwdPasswd.focus();
		return false;
	}//end if

	CommentSubmitLock = true;

	nFrm.submit();
}//end function

//±ÛÀÚ ¼öÁ¦ÇÑ ÇÏ±â
function getCommunityCharByte(nCheckFld,nDpFld,nCutCnt) {
//	alert(nCheckFld +'\n'+nDpFld+'\n'+nCutCnt);
	var nChObj	= document.getElementById(nCheckFld);	//Ã¼Å© ´ë»ó
	var nDpObj	= (!nDpFld) ? "" : document.getElementById(nDpFld) ;//»óÅÂÇ¥½Ã ´ë»ó

	var nChString		= nChObj.value;
	var nChStringCnt	= nChString.length;

	var i = 0;			//¹Ýº¹¹® º¯¼ö
	var nCutByte = 0;	//¹ÙÀÌÆ®¼ö Ä«¿îÅÍ
	var nOneCharAscii;	//±ÛÀÚ´ç ¾Æ½ºÅ°ÄÚµå
	var nDpByte;		//Ç¥½ÃµÉ ¹ÙÀÌÆ®¼ö

	//±ÛÀÚ¼ö Ä«¿îÆ®
	for(i=0; i<nChStringCnt; i++)
	{
		nOneCharAscii = escape(nChString.charAt(i));

		//ÇÑ±ÛÃ³¸®
		if(nOneCharAscii.length > 4)
		{
			nCutByte += 2;
		}else if(nOneCharAscii != "%0D" || nOneCharAscii != "%0A"){ //°³Çà ¹®ÀÚ ÇÊÅÍ
			nCutByte += 1;
		}//end if
	}//end for


	//±ÛÀÚ Á¦ÇÑ
	if(nCutByte <= nCutCnt)
	{
		(!nDpFld) ? "" : nDpObj.lastChild.nodeValue = nCutByte ;
		return true;
	}else{
		alert(nCutCnt+"ÀÚ ÀÌ»óÀº ÀÔ·Â ÇÏ½Ç¼ö ¾ø½À´Ï´Ù!");

		//Á¦ÀÏ ¸¶Áö¸·¿¡ ÀÔ·ÂµÈ ¹®ÀÚ
		nOneCharAscii = escape(nChString.charAt(nChString.length-1));

		if(nOneCharAscii == "%0D" || nOneCharAscii == "%0A") //°³Çà ¹®ÀÚ ÇÊÅÍ
		{
			nChObj.value = nChString.substr(0,nChString.length-2);
		}else{
			nChObj.value = nChString.substr(0,nChString.length-1);
		}//end if

		(!nDpFld) ? "" : nDpObj.lastChild.nodeValue = nCutCnt ;
		nChObj.focus();
		return false;
	}//end if
}//end getCharByte


//2Â÷ ´ñ±Û ´Þ±â
function setCommunityCreateForm2Depth(nSeq)
{
	var objW = document.getElementById("CCWrite2dW_"+nSeq);

	if(objW.style.display == "block")
	{
		objW.style.display = "none";
	}else{
		objW.style.display = "block";
	}//end if
}


//1Â÷ ´ñ±Û ¼öÁ¤¹öÆ°
function setCommunityModifyForm1Depth(nSeq)
{
	var objW = document.getElementById("CCWrite1dL_"+nSeq);
	var objM = document.getElementById("CCWrite1dM_"+nSeq);

	objW.style.display = "none";
	objM.style.display = "block";
}

//2Â÷ ´ñ±Û ¼öÁ¤¹öÆ°
function setCommunityModifyForm2Depth(nSeq)
{
	var objW = document.getElementById("CCWrite2dL_"+nSeq);
	var objM = document.getElementById("CCWrite2dM_"+nSeq);

	objW.style.display = "none";
	objM.style.display = "block";
}

//2Â÷ ´ñ±Û ÀÛ¼º

function setCommunityComment( nListSeq , nParensSeq , sComment  , oDpLayer ) {

}

//´ñ±Û ÀÛ¼º
/**
 * ´ñ±ÛÀÛ¼º
 * @param nSeq int ±Û¹øÈ£
 * @param nCSeq 
 */
function setCCControl(nSeq,nCSeq,sMode,nDepth,nGroup,nBlogCateSeq1,sComment,nDpLayer,nPage){
//	alert(nSeq + '\n' + nCSeq + '\n' + sMode + '\n' + nDepth + '\n' + nGroup + '\n' + nBlogCateSeq1 + '\n' + sComment + ' \n' + nDpLayer + '\n' + nPage);
//	alert('nListSeq='+nSeq + '\nCommentSeq='+nCSeq + '\nSmode=' + sMode + '\n' + nPage);
	var nActive = false;

	switch(sMode)
	{
		case"new":
			var objDesc = document.getElementById(sComment);
			var nDescM = encodeURIComponent(objDesc.value);

			if(!nDescM)
			{
				alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
				objDesc.focus();
				return false;
			}//end if

			var nActive = true;
		break;

		case"modify":
			var objDesc = document.getElementById(sComment);
			var nDescM = encodeURIComponent(objDesc.value);

			if(!nDescM)
			{
				alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
				objDesc.focus();
				return false;
			}//end if

			var nActive = true;
		break;

		case"delete":
			var nActive = true;
		break;

		default:
		break;
	}//end switch


	if(nActive) {
		if(CommentSubmitLock == true) {
			alert("¿äÃ»ÀÌ ÁøÇàÁßÀÔ´Ï´Ù Àá½Ã ±â´Ù·Á ÁÖ¼¼¿ä!");
		} else {
			CommentSubmitLock = true;

			var url		= "/include/include_community_comment_cnt.php";
			var pars	= "nSeq="+nSeq
							+ "&nCSeq="+nCSeq
							+ "&sMode="+sMode
							+"&nDepth="+nDepth
							+"&nGroup="+nGroup
							+"&sComment="+nDescM
							+"&nBlogCateSeq1="+nBlogCateSeq1;
			var div_id = "coCnt";
			var myAjax = new Ajax.Updater(
						{success: div_id},
						url,
						{
							method: 'post',
							parameters: pars,
							onFailure: rpError,
							evalScripts: true,
							onSuccess : function( e ) {
								if( e.responseText == 'SystemCheck' || e.responseText == 'DBError' ) {
									alert('½Ã½ºÅÛ Á¡°Ë ÁßÀÔ´Ï´Ù.');
									return false;
								}
							} ,
							onComplete: function(e)
							{
								getCommunityCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer,nPage);
								CommentSubmitLock = false;
							}
						});
		}//end if
	}//end if
}//end function


function setCommunityScrap(seq,group,blog_cate_seq1)
{
	var	win	= window.open("http://blog.danawa.com/archive/form_scrap.php?nListSeq="+seq+"&nGroup="+group+"&nBlogCateSeq1="+blog_cate_seq1+"&nScrapSeq=38832&nSzBlogSeq=818638","scrap_pop","width=400, height=350");
	win.focus();
}

function setGCControl(nSeq,nCSeq,sMode,nDepth,nGroup,nBlogCateSeq1,sComment,nDpLayer,nPage){
//	alert(nSeq + '\n' + nCSeq + '\n' + sMode + '\n' + nDepth + '\n' + nGroup + '\n' + nBlogCateSeq1 + '\n' + sComment + ' \n' + nDpLayer + '\n' + nPage);
//	alert('nListSeq='+nSeq + '\nCommentSeq='+nCSeq + '\nSmode=' + sMode + '\n' + nPage);
	var nActive = false;

	switch(sMode)
	{
		case"new":
			var objDesc = document.getElementById(sComment);
			var nDescM = encodeURIComponent(objDesc.value);

			if(!nDescM)
			{
				alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
				objDesc.focus();
				return false;
			}//end if

			var nActive = true;
		break;

		case"modify":
			var objDesc = document.getElementById(sComment);
			var nDescM = encodeURIComponent(objDesc.value);

			if(!nDescM)
			{
				alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
				objDesc.focus();
				return false;
			}//end if

			var nActive = true;
		break;

		case"delete":
			var nActive = true;
		break;

		default:
		break;
	}//end switch


	if(nActive) {
		if(CommentSubmitLock == true) {
			alert("¿äÃ»ÀÌ ÁøÇàÁßÀÔ´Ï´Ù Àá½Ã ±â´Ù·Á ÁÖ¼¼¿ä!");
		} else {
			CommentSubmitLock = true;

			var url		= "/include/include_gallery_comment_cnt.php";
			var pars	= "nSeq="+nSeq
							+ "&nCSeq="+nCSeq
							+ "&sMode="+sMode
							+"&sComment="+nDescM
			var div_id = "coCnt";
			var myAjax = new Ajax.Updater(
						{success: div_id},
						url,
						{
							method: 'post',
							parameters: pars,
							onFailure: rpError,
							evalScripts: true,
							onSuccess : function( e ) {
								if( e.responseText == 'SystemCheck' || e.responseText == 'DBError' ) {
									alert('½Ã½ºÅÛ Á¡°Ë ÁßÀÔ´Ï´Ù.');
									return false;
								}
							} ,
							onComplete: function(e) {
								getGalleryCommentList(nSeq,nGroup,nBlogCateSeq1,nDpLayer,nPage);
								CommentSubmitLock = false;
							}
						});
		}//end if
	}//end if
}//end function

function setClaimComment(nCommentSeq, nGroup) {
	var width=400;
	var height=350;
	var posx=0;
	var posy=0;

	position = "width="+width+",height="+height+",scrollbars=no,resizable=yes,top="+posy+",left="+posx;
    window.open(domain_bbs + '/form_complaint.php?nCommentSeq='+nCommentSeq+'&nGroup='+nGroup,'CommentComplaint', position);
}// end function

function setRecommend(nLoginCheck, nBoardSeq, nListSeq, nMemberSeq, nType) {
	var sUrl = "";
	if (!nLoginCheck) {
		alert('·Î±×ÀÎ ÈÄ ÀÌ¿ëÇÏ½Ê½Ã¿À.');
		return;
	} else {
		if(nType){  // °¶·¯¸® ÃßÃµ
			sUrl = "GalleryRecommend.php?nBoardSeq="+nBoardSeq+"&nListSeq="+nListSeq+"&nMemberSeq="+nMemberSeq;
		} else {	// ÀÏ¹Ý±Û ÃßÃµ
			//alert('ÃßÃµ');
			sUrl = domain_bbs+"/BoardRecommend.php?nBlogCateSeq1="+nBoardSeq+"&nSeq="+nListSeq+"&nMemberSeq="+nMemberSeq+"&cDomain=BBS";
		}// end if

		if( confirm("ÃßÃµ ÇÏ½Ã°Ú½À´Ï±î?") ) {
			ifrRecommend.location.href = sUrl;
		}// end if
	}// end if
}// end function