


$(function ()
{
	var g = document.getElementById('addgood');
	var b = document.getElementById('addbad');
	var m = document.getElementById('domodify');
	var d = document.getElementById('dodelete');
	var r = document.recoform;
	var o = document.opform;
	
	if (g) {
		g.onclick = function () {
			if (confirm('추천 하시겠습니까?')) {
				r.mode.value = "reco";
				r.submit();
				return true;
			} 
			
			return false;
		}
	}
	
	if (b) {
		b.onclick = function () {
			if (confirm('신고 하시겠습니까?')) {
				r.mode.value = "repo";
				r.submit();
				return true;
			} 
			
			return false;
		}
	}
	
	if (m) {
		m.onclick = function () {
			if (confirm('수정 하시겠습니까?')) {
				o.mode.value = "trymodify"
				o.submit();
				return true;
			}
			
			return false;
		}
	}
	
	if (d) {
		d.onclick = function () {
			if (confirm('삭제 하시겠습니까?')) {
				o.mode.value = "trydelete"
				o.submit();
				return true;
			}
			
			return false;
		}
	}
	
	/* comment */
	
	/* image resize */
	$('.v_content img').each(function (){

		if ($(this).width() > $('.v_content').width()) {
			$(this).width($('.v_content').width())
		}
	});
	
	
	/**
	 * CONTROL COMMENT
	 */
	 
	// COMMON FUNCTINO COMMENT
	// ______________________________________
	
		function checkDocomment ()
		{
			var cn = document.getElementById('coName');
			var cp = document.getElementById('coPasswd');
			
			if (cn) {
				if (cn.value.trim() == '') {
					alert('이름을 입력하세요.');
					cn.focus();
					return false;
				}
			}
			if (cp) {
				if (cp.value == '') {
					alert('비밀번호를 입력하세요.');
					cp.focus();
					return false;
				}
			}
			if ($('textarea[name=coContent]').val().trim() == '') {
				alert('내용을 입력하세요.');
				$('textarea[name=coContent]').focus().val('');
				return false;
			}
			
			return true;
		}
	
	
	// DO COMMENT
	// ______________________________________
	
		$('#btn_docomment').click(function () 
		{
			return checkDocomment();
		});
		
	// DO COMMENT AND VOTE
	// ______________________________________
	
		$('#btn_docommentandvote1').click(function ()
		{
			if (!checkDocomment()) {
				return false;
			}
			
			document.commentForm.mode.value = 'docommentandvote';
		});
		
	// MODIFY COMMENT
	// ______________________________________
	
		$('.btn_modifyopen').click(function ()
		{
			$('.modifybox').remove();
			$('.deletebox').remove();
			$('.replybox').remove();
			
			$(this).parent().append(mbox);
			
			// IS MEMBER'S COMMENT?
			if ($(this).parent().parent().find('.ismember').val()) {
				// REMOVE PASSWORD INPUTBOX
				$('.passwordbox').remove();
			}
			$('.modifybox > textarea').val($(this).parent().parent().find('input[name=coHiddenContent]').val());

			var form = $(this).parent().parent()
			var modeinput = $(this).parent().parent().find('input[name=mode]');
			modeinput.val('modifycomment');


			// SUBMIT BUTTON EVENT HANDLER
			
				$('#btn_modify_submit').click(function ()
				{
					return (
						$(this).parent().parent().parent().find('input[name=mode]').val() == 'modifycomment'
					);
				});
		});
		
	
	// DELETE COMMENT
	// _______________________________________
	
		$('.btn_deleteopen').click(function ()
		{
			$('.modifybox').remove();
			$('.deletebox').remove();
			$('.replybox').remove();
			
			var form = $(this).parent().parent();
			var modeinput = $(this).parent().parent().find('input[name=mode]');
			var ismember = $(this).parent().parent().find('.ismember');
			
			modeinput.val('deletecomment');
			
			// IS MEMBER'S COMMENT?
			if (ismember.val()) {
				// REMOVE PASSWORD INPUTBOX
				if (confirm('삭제하시겠습니까?')) {
					if (modeinput.val() == 'deletecomment') {
						form.submit();
					}
				}
			}
			else {
				$(this).parent().append(dbox);
				
				// SUBMIT BUTTON EVENT HANDLER
			
					$('#btn_delete_submit').click(function ()
					{
						if (confirm('삭제하시겠습니까?')) {
							return (
								$(this).parent().parent().parent().find('input[name=mode]').val() == 'deletecomment'
							)
						}
						else {
							return false;
						}
					});
			}

			return false;
		});
		
	// REPLY COMMENT
	// _______________________________________
	
		$('.btn_replyopen').click(function ()
		{
			$('.modifybox').remove();
			$('.deletebox').remove();
			$('.replybox').remove();
			
			$(this).parent().append(rbox);
			
			// IS MEMBER'S COMMENT?
			if ($('#ismember').val()==1) {
				// REMOVE PASSWORD INPUTBOX
				$('.passwordbox').remove();
			}
			
			var form = $(this).parent().parent()
			var modeinput = $(this).parent().parent().find('input[name=mode]');
			modeinput.val('replycomment');
		});
});
