function openComment(no)
{
	openId = eval("document.all.commentList_" + no );

	if(openId.style.display == 'block') {
		type = 'none';
	} else {
		type = 'block';
	}

	openId.style.display = type;
}

function delComment(no, comment_no, page, offset)
{
	if(confirm('삭제하시겠습니까?')) {
		location.href = "admindiary_a.php?mode=delete&page_type=comment&comment_no="+comment_no+"&no="+no+"&page="+page+"&offset="+offset;
	}
}

function comment_submit_check( form, used_name )
{
    var max_length = 200;
    var comment = get_string_trim(form.comment.value);
    form.comment.value = comment;

    if(used_name == 'block')
    {
        form.comment_name.value = get_string_trim(form.comment_name.value);
        form.comment_passwd.value = get_string_trim(form.comment_passwd.value);

        if(form.comment_name.value == '') {
            alert('이름을 입력하세요');
            form.comment_name.focus();
            return false;
        }

        if(form.comment_passwd.value == '') {
            alert('비밀번호를 입력하세요');
            form.comment_passwd.focus();
            return false;
        }
    }

    if(comment == '')
    {
        alert('댓글 내용을 입력하세요');
        form.comment.focus();
        return false;
    }

    var comment_size = get_string_length(comment);

    if(comment_size > max_length)
    {
        alert('댓글은 ' + max_length + '자 이상 작성할 수 없습니다.');
        form.comment.value = comment.substr(0, max_length);
        form.comment.focus();
        return false;
    }

    return true;
}

function get_string_trim( string )
{
    return string.replace(/(^\s*)|(\s*$)/g, "");
}

function get_string_length( string )
{
    var count = 0;

    var tmp_str = new String(string);
    var temp = tmp_str.length;

    var onechar;

    for ( k=0; k<temp; k++ )
    {
        onechar = tmp_str.charAt(k);

        if (escape(onechar).length > 4)
        {
            count += 2;
        }
        else
        {
            count += 1;
        }
    }

    return count;
}

function str_limit_check( obj , index )
{
	comment = obj.value;
	max_len = 200;

	content_length = get_string_length( comment );

	spanId = document.all['cbyte_span_' + index];

	if( typeof( spanId ) == "object" )
	{
		spanId.innerHTML = content_length;
	}

	if( content_length > max_len )
	{
		msg = '메시지는 ' + max_len + ' Byte 이하로 입력해주세요.';
		alert( msg );

		tmp = comment.substr(0, max_len);
		obj.value = tmp;
		obj.focus();

		if( typeof( spanId ) == "object" )
		{
			spanId.innerHTML = max_len;
		}
	}

}
