var moveModifyBox = {
	currentidx : 10000000
	
	,setIdx : function (idx) {
		this.dbox = document.getElementById('dynamicbox.' + idx);
		this.wbox = document.getElementById('dynamicbox.' + this.currentidx);
		this.cwriter = document.getElementById('commentwriter.' + idx);
		this.ccon = document.getElementById('commentcontent.' + idx);
	}
	
	,modifycomment : function (idx, ismembers) {
		if (this.currentidx != idx) {
			this.setIdx(idx);
			
			setHTML(this.dbox, getHTML(this.wbox));
			setHTML(this.wbox, '');

			document.commentModForm.mode.value = 'docomod';
			setText(document.commentModForm.coContent, getText(this.ccon));
				
			document.commentModForm.coIdx.value = idx;
			this.currentidx = idx;
			
			if (ismembers) {
				document.getElementById('ismember').style.display = 'inline';
				document.getElementById('notmember').style.display = 'none';
				setText(document.getElementById('commentwriter2'), getText(this.cwriter));
				document.commentModForm.isMembers.value = "Y";
			} else {
				document.getElementById('ismember').style.display = 'none';
				document.getElementById('notmember').style.display = 'inline';
				setText(document.getElementById('commentwriter1'), getText(this.cwriter));
				document.commentModForm.isMembers.value = "N";				
			}
		}
	}

};


$(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
	 */
	
	// MODIFY COMMENT
	// ______________________________________
	
		$('.btn_modifyopen').click(function ()
		{
			$('.modifybox').remove();
			$('.deletebox').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();
			
			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'
							)
						}

					});
			}
		});
});
