
function updateChar(charCnt, obj) {
	var strCount=0;
	var tempStr,tempStr2;

	for(var i=0;i<obj.value.length;i++) {
		tempStr=obj.value.charAt(i);
		if(escape(tempStr).length>4) strCount+=2;
		else strCount+=1;
	}

	if(strCount>charCnt){
		alert("ÃÖ´ë "+charCnt+"byteÀÌ¹Ç·Î ÃÊ°úµÈ ±ÛÀÚ¼ö´Â ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");
		strCount=0;tempStr2="";
		for(i=0;i<obj.value.length;i++) {
			tempStr=obj.value.charAt(i);

			if(escape(tempStr).length>4) strCount+=2;
			else strCount+=1;

			if(strCount>charCnt){
				if(escape(tempStr).length>4)strCount-=2;
				else strCount-=1;
				
				break;
			} else tempStr2+=tempStr;
		}
		obj.value=tempStr2;
	}
	document.getElementById("textlimit_"+obj.name).innerHTML="<font color=#ff6633>"+strCount+"</font>";
}

function saveComment(paper){
	var comment = document.list_form.comment.value;
	
	if( paper.empty() ) { window.reload(); return; }
	if( comment.empty() ) { alert('³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä!!!'); return; }
	
	//var bead = Form.getInputs('frmComment','radio','bead').find(function(radio) { return radio.checked; }).value;
	var bead = 0;
	var frm=document.list_form;
		frm.method="post";
		frm.act.value="save";
		frm.action="/comment/comment.do"
		frm.submit();	
		
	//document.location.href="/comment/comment.do?act=save&paper="+paper+"&comment="+comment;
}

function saveCommentPlus(paper,id,depth,page){
	var comment = document.list_form.commentPlus.value;
	
	//alert(comment+"/"+paper+"/"+id+"/"+depth+"/");
	
	//if( paper.empty() ) { window.reload(); return; }
	if( comment.empty() ) { alert('³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä!!!'); return; }
	
	//var bead = Form.getInputs('frmComment','radio','bead').find(function(radio) { return radio.checked; }).value;
	var bead = 0;
	var frm=document.list_form;
		frm.method="post";
		frm.act.value="saveReply";
		frm.comment.value=comment;
		frm.parent.value=id;
		frm.depth.value=depth;
		frm.page.value=page;
		frm.action="/comment/comment.do"
		frm.submit();	
	//document.location.href="/comment/comment.do?act=saveReply&paper="+paper+"&comment="+comment+"&parent="+id+"&depth="+depth+"&page="+page;
}

function delComment(paper, comment_id){
	if( paper.empty() ) { window.reload(); return; }

	document.location.href="/comment/comment.do?act=del&paper="+paper+"&id="+comment_id;
}

function saveBead(paper){
	if( paper.empty() ) { window.reload(); return; }
	

		
		var bead = document.frmBead.bead.value;
        var paper = paper;
        var strParams = "bead="+bead + "&paper=" + paper + "&action=save"
        var loader1=new net.ContentLoader('/comment/bead.do',CreateScript,null,"POST",strParams);
       
		
}
 function CreateScript(){
            strText = this.req.responseText;
            alert(strText);
           // eval(this.req.responseText);
            window.location.reload();
 }

function popupSupport(paper) {
	if( paper.empty() ) { window.reload(); return; }
	var w =600, h=420;
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	window.open('/comment/supportform.do?paper=', 'support','width='+w+', height='+h+', left='+x+', top='+y);	
}

function removeCommentForm(parentId, tagName) {
}

function addWrite(div_id,paper,id,depth,page){

		var pId = document.getElementById("commentForm");
		if ( pId )
			pId.removeNode(true);


	//var divEls = document.getElementsByTagName("div");
	//var i = 0;
	//for(i=0;i<divEls.length;i++)
	//alert(divEls[i].id);
	
	var str;
	if (div_id == ""){
		if (confirm("·Î±×ÀÎ ÇÏ¼Å¾ß ÀÌ¿ëÀÌ °¡´ÉÇÕ´Ï´Ù.\n·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?")){
			top.location.href="/member/intro.do";
		}
	}else{
		str="<div id='commentForm'>";
		str=str+"<table width='' height='35' border='0' cellpadding='0' cellspacing='0'>";
		str=str+"<tr> ";
		if (depth == "2"){
		str=str+"<td width='40'></td>";
		}
		str=str+"<td class='gm r04 b0'>[ ´ñ±Û ] </td>";
		str=str+"<td class='gray12 l_12'>¶ç¾î¾²±â Æ÷ÇÔÇÏ¿© (ÃÖ´ë 1200 byte - ÇÑ±Û 600ÀÚ) <span class=glay6 id=textlimit_commentPlus>0</span> byte</td>";
		str=str+"</tr>";
		str=str+"</table>";
		str=str+"<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		str=str+"<tr>";
		if (depth == "2"){
		str=str+"<td width='40'></td>";
		}
		str=str+"<td>";
		str=str+"<textarea name='commentPlus' cols='60' rows='3' class='textarea_01' style='width:468px; height:77px;' onkeyup='updateChar(1200, this);'></textarea>";
		str=str+"<a href=\"javascript:saveCommentPlus('"+paper+"',"+id+","+depth+","+page+")\"><img name='btn_researcher' src='/img/btn_reply.gif' alt='´ñ±Û ¿Ã¸®±â' ></a>";
		str=str+"</td>";
		str=str+"</tr>";
		str=str+"</table>";
		str=str+"</div>";
		
		document.getElementById(div_id).innerHTML = str;
		bodyResize()
	}
}

function showMoreComment(div_id){
	
	if(document.getElementById(div_id).style.display == "none"){
		document.getElementById(div_id).style.display = "block";
		bodyResize()
	}else{
		document.getElementById(div_id).style.display = "none";
		bodyResize()
	}
	
}

function updateBead(paper, bead, comment_id, page){
	if( paper.empty() ) { window.reload(); return; }
	
	if(getCookie("chuChk") == comment_id){
		alert('ÀÌ¹Ì ³ªµµ °ø°¨ ÇÏ¿´½À´Ï´Ù.'); return;
	}else{
		setCookie("chuChk",comment_id,1);
		alert('³ªµµ °ø°¨ ÇÏ¿´½À´Ï´Ù.');
	}

	document.location.href="/comment/comment.do?action=act&paper="+paper+"&bead="+bead+"&id="+comment_id+"&page="+page;
}
