var MSG_JS001;
var MSG_JS002;
var MSG_JS003;
var MSG_JS004;
var MSG_JS005;

if(CFG_charset=="euc-kr"){
	MSG_JS001 = "이름을 입력하여 주세요.";
	MSG_JS002 = "내용을 입력하여 주세요.";
	MSG_JS003 = "comment를 등록한 사용자만이 삭제가 가능합니다.";
	MSG_JS004 = "정말로 삭제하시겠습니까?";
	MSG_JS005 = "등록된 comment가 없습니다.";

}else if(CFG_charset=="Shift_JIS"){
	MSG_JS001 = "会員だけが書き込みが可能です。";
	MSG_JS002 = "内容を入力してください。";
	MSG_JS003 = "コメントを登録した使用者だけが削除が可能です。";
	MSG_JS004 = "削除しますか。";
	MSG_JS005 = "登録されたコメントがありません。";

}else if(CFG_charset=="iso-8859-1"){
	MSG_JS001 = "The member only can write the comments.";
	MSG_JS002 = "Please put the comments..";
	MSG_JS003 = "The deletion can be done by the author only.";
	MSG_JS004 = "Do you want to delete the comments?";
	MSG_JS005 = "There is no comments.";
}else if(CFG_charset=="gb2312"){
	MSG_JS001 = "请输入名字。";
	MSG_JS002 = "请输入内容。";
	MSG_JS003 = "只有登陆comment的用户才能删除。";
	MSG_JS004 = "确定删除吗？";
	MSG_JS005 = "没有登陆的comment。";
}

function _saveComment(work, idx, writerID){
	var oReq=_getHttpReqObj();
	
	oReq.onreadystatechange = function(){
		if( oReq.readyState==4 ){
			document.commentFrm.content.value="";
			_loadComment();
		}
	};
	if(oReq.overrideMimeType) oReq.overrideMimeType('text/html');
	if(work=="add"){
		var NickName=document.commentFrm.NickName.value;
		var content=document.commentFrm.content.value;
		if(NickName==""){
			alert( MSG_JS001 );
			return;			
		}else if(content==""){
			alert( MSG_JS002 );
			return;			
		}
		var strPost="work=add&bidx="+g_DMook_idx+"&NickName="+escape(NickName)+"&content="+escape(content);
		oReq.open("POST", "/mbs/c_write_prc.asp");
		oReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		oReq.send(strPost);
	}else if(work=="delete"){
		if(g_memLevel!=="100" && (g_memUserID!=writerID || g_memUserID=="") ){
			alert( MSG_JS003 );
			return;
		}
		if(confirm(MSG_JS004)){
			oReq.open("GET", "/mbs/c_write_prc.asp?work=delete&bidx="+g_DMook_idx+"&idx="+idx);
			oReq.send(null);
		}
	}
	
}

function _removeHtml(str){
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	
	str = str.replace(/\n/g, "<br>");
	return str;
}
function _loadStateChange(oReq){
	if( oReq.readyState==4 ){
		var oCommentList = oReq.responseXML.documentElement.getElementsByTagName("Comment");
		var sHtml='<table width="440" border="0" cellspacing="0" cellpadding="0">';
		if( oCommentList.length==0 ){
			sHtml+='<tr><td align="center" valign="middle" height="40">'+MSG_JS005+"</td></tr>"; 
		}else{
			for(var i=0;i<oCommentList.length;i++){
				var oComment = oCommentList.item(i);
				var idx=oComment.attributes.getNamedItem("idx").value;
				var writerID=oComment.attributes.getNamedItem("writerID").value;
				var NickName=_removeHtml(oComment.attributes.getNamedItem("NickName").value);
				var regDate=oComment.attributes.getNamedItem("regDate").value;
				var content=_removeHtml(oComment.attributes.getNamedItem("content").value);
				sHtml+='<tr>'; 
				sHtml+='<td width="70" height="20" style="word-wrap:break-word;word-break:break-all;padding-left:5px;">'+NickName+'</td>'
				sHtml+='<td width="270" height="20" style="word-wrap:break-word;word-break:break-all;">'+content+'</td>';
				sHtml+='<td width="80" height="20">['+regDate+']</td>';
				sHtml+='<td width="20" height="20" align="center"><img src="'+CFG_IMG_URL+'albumgallery/bbs/ed_delete.gif" width="18" height="18" style="cursor:pointer;" onfocus="this.blur();" onclick="javascript:_saveComment(\'delete\','+idx+',\''+writerID+'\');"/></td>';
				sHtml+='</tr>'; 
				sHtml+='<tr><td height="7" colspan="4" background="'+CFG_IMG_URL+'sephor7.gif"><spacer type="block" height="7"/></td></tr>'; 
			}
		}
		sHtml+='</table>';
		document.getElementById("div_CommentList").innerHTML=sHtml;
		document.getElementById("b_comment_num").innerText=oCommentList.length;
		frame_init();
	}
}
function _loadComment(){
	var oReq=_getHttpReqObj();
	if(oReq==null){
		document.getElementById("tbl_CommentList").style.display="none";
	}
	oReq.onreadystatechange = function(){
		_loadStateChange(oReq);
	};
	
	if(oReq.overrideMimeType) oReq.overrideMimeType('text/xml');
	oReq.open("GET", "/mbs/c_list.asp?bidx="+g_DMook_idx);
	oReq.send(null);
}

function _getHttpReqObj(){
	var oReq;
	if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}
	return null;
}

