var tId; var bo_idx; var field; var search; var UserId; //comment function loadCommentResult() { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { var xmlDoc = httpRequest.responseXML; var textDoc = httpRequest.responseText; var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue; if (code == 'success') { var commentList = xmlDoc.getElementsByTagName('data'); //alert(commentList.length); var listDiv = document.getElementById('j-commentList'); for (var i = 0 ; i < commentList.length ; i++) { var commentDiv = makeCommentView(commentList.item(i)); listDiv.appendChild(commentDiv); } } } else { alert("댓글 목록 로딩 실패"); } } } function makeCommentView(comment) { var commentDiv = document.createElement('div'); commentDiv.setAttribute('id', 'c'+comment.getElementsByTagName('idx').item(0).firstChild.nodeValue); //alert(comment.getElementsByTagName('idx').item(0).firstChild.nodeValue); var html = ''; html += '
'+comment.getElementsByTagName('memo').item(0).firstChild.nodeValue.replace(/\n/g, '\n
')+'
'; html += '
'+comment.getElementsByTagName('name').item(0).firstChild.nodeValue+'' + '님' + '    '; html += 'from '+comment.getElementsByTagName('ip').item(0).firstChild.nodeValue + '    ' +'작성일 '+ comment.getElementsByTagName('reg_date').item(0).firstChild.nodeValue+'    '; html += '수정' + '  '; html += '삭제
'; html += '
'; commentDiv.innerHTML = html; commentDiv.comment = comment; commentDiv.className = "comment"; return commentDiv; } function addComment(addForm) { var tId = addForm.tId.value; var bo_idx = addForm.bo_idx.value; var UserId = addForm.UserId.value; var name = addForm.name.value; var memo = addForm.memo.value; var passwd = addForm.passwd.value; if(name.length < 3){ alert('이름을 적어주십시오'); addForm.name.focus(); return false; } if(memo.length < 3){ alert('간단한 글을 적어주십시오'); addForm.memo.focus(); return false; } if(!UserId || UserId=="default"){ if(passwd.length < 3){ alert('비밀번호를 적어주십시오'); addForm.passwd.focus(); return false; } } sendRequest('./COMMENTadd.php', 'tId='+tId+'&tNum='+bo_idx+'&UserId='+UserId+'&name='+name+'&memo='+memo+'&passwd='+passwd+'', addResult, 'POST'); } function addResult() { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { var xmlDoc = httpRequest.responseXML; var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue; if (code == 'success') { var comment = xmlDoc.getElementsByTagName('data'); var listDiv = document.getElementById('j-commentList'); var commentDiv = makeCommentView(comment.item(0)); listDiv.insertBefore(commentDiv,document.getElementById('j-commentList').firstChild); document.addForm.name.value = ''; document.addForm.memo.value = ''; document.addForm.passwd.value = ''; } } else { alert("서버 에러 발생: " + httpRequest.status); } } } function viewUpdateForm(commentId) { hideForm('j-commentDel'); var commentDiv = document.getElementById('c'+commentId); var updateFormDiv = document.getElementById('j-commentUpdate'); if (updateFormDiv.parentNode != commentDiv) { updateFormDiv.parentNode.removeChild(updateFormDiv); commentDiv.appendChild(updateFormDiv); } var comment = commentDiv.comment; document.updateForm.idx.value = comment.getElementsByTagName('idx').item(0).firstChild.nodeValue; document.updateForm.name.value = comment.getElementsByTagName('name').item(0).firstChild.nodeValue; document.updateForm.memo.value = comment.getElementsByTagName('memo').item(0).firstChild.nodeValue; updateFormDiv.style.display = ''; } function hideForm(hForm) { var FormDiv = document.getElementById(hForm); FormDiv.style.display = 'none'; FormDiv.parentNode.removeChild(FormDiv); document.documentElement.appendChild(FormDiv); } function updateComment(updateForm) { var tId = updateForm.tId.value; var bo_idx = updateForm.bo_idx.value; var UserId = updateForm.UserId.value; var UserClass = updateForm.UserClass.value; var idx = updateForm.idx.value; var name = updateForm.name.value; var memo = updateForm.memo.value; var passwd = updateForm.passwd.value; var param = 'idx='+idx+'&tId='+tId+'&tNum='+bo_idx+'&UserId='+UserId+'&userClass='+UserClass+'&name='+name+'&memo='+memo+'&passwd='+passwd+''; sendRequest('./COMMENTm.php', param, updateResult, 'POST'); } function updateResult() { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { var xmlDoc = httpRequest.responseXML; var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue; if (code == 'success') { hideForm('j-commentUpdate'); var comment = xmlDoc.getElementsByTagName('data'); if(comment.length > 0){ var listDiv = document.getElementById('j-commentList'); var newCommentDiv = makeCommentView(comment.item(0)); var oldCommentDiv = document.getElementById('c'+comment.item(0).getElementsByTagName('idx').item(0).firstChild.nodeValue); listDiv.replaceChild(newCommentDiv, oldCommentDiv); alert("수정했습니다!"); }else{ alert("비밀번호가 일치하지 않습니다."); } } else { alert("수정에 실패했습니다."); location.reload(); } } else { alert("서버 에러 발생: " + req.status); } } } function viewDelForm(commentId) { hideForm('j-commentUpdate'); var commentDiv = document.getElementById('c'+commentId); var FormDiv = document.getElementById('j-commentDel'); //alert(FormDiv); //alert(commentDiv); if (FormDiv.parentNode != commentDiv) { FormDiv.parentNode.removeChild(FormDiv); commentDiv.appendChild(FormDiv); } FormDiv.style.display = ''; document.deleteForm.idx.value = commentId; } function delForm(deleteForm){ var idx = deleteForm.idx.value; var passwd = deleteForm.passwd.value; var tId = updateForm.tId.value; var bo_idx = updateForm.bo_idx.value; var UserId = updateForm.UserId.value; var UserClass = updateForm.UserClass.value; var params = 'idx='+idx+'&tId='+tId+'&tNum='+bo_idx+'&UserId='+UserId+'&userClass='+UserClass+'&passwd='+passwd+''; sendRequest('COMMENTdel.php', params, removeResult, 'POST'); } function removeResult() { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { var xmlDoc = httpRequest.responseXML; var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue; if (code == 'success') { var comment = xmlDoc.getElementsByTagName('data'); if(comment.length > 0){ var deletedId = xmlDoc.getElementsByTagName('idx').item(0).firstChild.nodeValue; var commentDiv = document.getElementById("c"+deletedId); //commentDiv.parentNode.removeChild(commentDiv); commentDiv.style.display='none'; alert("삭제했습니다"); }else{ alert("비밀번호가 일치하지 않습니다."); } } } else { alert("서버 에러 발생: " + httpRequest.status); } } } function startComment(tId,bo_idx,field,search){ tId = tId; bo_idx = bo_idx; field = field; search = search; sendRequest('COMMENTlist.php', 'tId='+tId+'&tNum='+bo_idx+'&field='+field+'&search='+search+'', loadCommentResult, 'POST'); }