var divAspCmt;

function setDivAspCmt(iAspBrdCmtIdx)
{
	if(iAspBrdCmtIdx <=0 )return;
	divAspCmt = document.getElementById('divAspCmt_'+iAspBrdCmtIdx);
}
function getDivAspCmt()
{
	return divAspCmt;
}
function resetDivAspCmt()
{
	divAspCmt = null;
}
function fn_comment_submit(btnObj)
{
	var f = btnObj.form;
	if(f == null)return;
	var iAspBrdCmtIdx = f.asp_comment_idx.value;
	if(iAspBrdCmtIdx<=0)return;
	setDivAspCmt(iAspBrdCmtIdx);
	//fn_valid_ajaxSubmit(f,'fn_comment_submit_out'); //20090705 By Sam Kim
	if(fn_validation(f))
	{
		ajaxSubmit(f,'fn_comment_submit_out');
		fn_comment_form_reset(f);
	}
}
function fn_comment_submit_out_delete(responseText)
{
	return fn_comment_submit_out_proc(responseText,"Deleted Successfully","Fail to Delete");
}

function fn_comment_submit_out(responseText)
{
	fn_comment_submit_out_proc(responseText,"","Error");
}

function fn_comment_submit_out_proc(responseText,succMsg,errMsg)
{
    var divObj = getDivAspCmt();
    if(responseText != "0")
	{
		if(succMsg != "")alert(succMsg);
        divObj.innerHTML = responseText;
	}
    else
        alert(errMsg);
    resetDivAspCmt();
}

function fn_comment_form_reset(f)
{
	if(f == null)return;
	if(f.pAspCmtCt_writer != null && f.pAspCmtCt_writer.type == 'text')f.pAspCmtCt_writer.value = "";
	if(f.pAspCmtCt_passwd != null)f.pAspCmtCt_passwd.value = "";
	f.pAspCmtCt_content.value = "";
}

function fn_comment_delete(btnObj)
{
	var f = btnObj.form;

	var iAspBrdCmtIdx = f.asp_comment_idx.value;
	if(f.pAspCmtCt_passwd != null) /*Guest ÀÎ °æ¿ì*/
	{
		if(iAspBrdCmtIdx <=0 ) return;	
		
		var divPasswd = document.getElementById('dAspBrdCmt'+iAspBrdCmtIdx);
		if(divPasswd == null)return;
		
		if(f.pAspCmtCt_passwd.value == "")
		{
			divPasswd.style.display = 'block';
			f.pAspCmtCt_passwd.focus();
			return;
		}
		else divPasswd.style.display = 'none';
	}
	
	f.sMode.value = 'DELETE';
	setDivAspCmt(iAspBrdCmtIdx);
	fn_valid_ajaxSubmit(f,'fn_comment_submit_out_delete');
	f.pAspCmtCt_passwd.value = "";
	f.sMode.value = "";
}

function fn_comment_delete_cancel(btnObj)
{
	if(btnObj == null)return;
	var f = btnObj.form;
	if(f==null)return;
	
	if(f.pAspCmtCt_passwd != null) /*Guest ÀÎ °æ¿ì*/
	{
		var iAspBrdCmtIdx = f.asp_comment_idx.value;
		if(iAspBrdCmtIdx <=0 ) return;	
		
		var divPasswd = document.getElementById('dAspBrdCmt'+iAspBrdCmtIdx);
		if(divPasswd == null)return;
		f.pAspCmtCt_passwd.value = "";
		divPasswd.style.display = "none";
		resetDivAspCmt();
	}
}

function fn_comment_paging(id_page,page,id_linecnt,linecnt)
{
	var arr 			= id_page.split("_");
	var iAspBrdCmtIdx	= arr[1];

	var f = document.getElementById("fAspCmtList_"+iAspBrdCmtIdx);
	if(f == null)return;
	//f.action='/pages/common/comment/commentAction.php3';
	
	setDivAspCmt(iAspBrdCmtIdx);
	
	var ctlPg = eval("f."+id_page);
	var ctlLn = eval("f."+id_linecnt);
	if(ctlPg == null || ctlLn == null)return;

	ctlPg.value = page;
	ctlLn.value = linecnt;
	
	f.sMode.value ="";
	fn_valid_ajaxSubmit(f,'fn_comment_submit_out');
}
