function comment_del( form )
{
	msg = "Á¤¸»·Î »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?";

	if( !confirm( msg ) )
	{
		return false;
	}

        form.mode.value = 'del';
        return true;
}

function board_read_mileage_pop( user_id, tmp )
{
	
	if( !user_id )
	{
		alert( 'Àû¸³±Ý¹Ù·ÎÁÖ±â´Â È¸¿ø¿¡°Ô¸¸ °¡´ÉÇÕ´Ï´Ù.' );

		return false;
	}

	href = '/admin/php/c/member_admin_d_f.php';
	href += '?user_id=' + user_id + '&mode=3&comment_tmp=' + tmp;

	option = 'toolbar=no location=no scrollbars=yes resizable=yes width=680 height=780';

	window.open( href, '', option  );

}

// 2009-07-02 ¿øÅ¬¸¯À¸·Î Àû¸³±Ý Áö±Þ ¹× °ü¸®ÀÚ °Ô½ÃÇÏ±â - ±ÇÇõÃµ
function board_read_mileage_board_pop( user_id, tmp, board_no, bbs_no )
{
	
	if( !user_id )
	{
		alert( 'Àû¸³±Ý¹Ù·ÎÁÖ±â´Â È¸¿ø¿¡°Ô¸¸ °¡´ÉÇÕ´Ï´Ù.' );

		return false;
	}

	href = '/admin/php/c/member_admin_d_f.php';
	href += '?user_id=' + user_id + '&mode=3&comment_tmp=' + tmp + '&board_no=' + board_no + '&bbs_no=' + bbs_no;

	option = 'toolbar=no location=no scrollbars=yes resizable=yes width=680 height=780';

	window.open( href, '', option  );

}

// 2009-07-02 ¿øÅ¬¸¯À¸·Î Àû¸³±Ý Áö±Þ ¹× °ü¸®ÀÚ °Ô½ÃÇÏ±â - ±ÇÇõÃµ
function board_read_mileage_board_frame( mile_again, member_id, board_no, product_name, bbs_no)
{
	if( !member_id )
	{
		alert( 'Àû¸³±Ý¹Ù·ÎÁÖ±â´Â È¸¿ø¿¡°Ô¸¸ °¡´ÉÇÕ´Ï´Ù.' );

		return false;
	}

    var pre_selt = document.getElementsByName('mile_money'); 
    for (var i=0; i<5; i++){ 
        if (pre_selt[i].checked==true){ 
            break; 
        } 
    }
    var mile_money = document.getElementsByName('mile_money')[i].value; 

	msg = mile_money+"¿øÀ» Áö±ÞÇÏ½Ã°Ú½À´Ï±î?";

	if( confirm( msg ) ) {
		if ( mile_again == 'T' ) {
			msg2 = "ÀÌ¹Ì µ¿ÀÏ »óÇ°¸íÀ¸·Î Áö±ÞµÈ Àû¸³±ÝÀÌ ÀÖ½À´Ï´Ù.\n±×·¡µµ Áö±ÞÇÏ½Ã°Ú½À´Ï±î?";
			if( confirm( msg2 ) ) {
				document.give_mile.location.href = "/admin/php/c/member_admin_pop03_hidden.php?member_id="+member_id+"&mileage_money="+mile_money+"&board_no="+board_no+"&product_name="+product_name + '&bbs_no=' + bbs_no;
			}else{
				return false;
			}
		}else{
			document.give_mile.location.href = "/admin/php/c/member_admin_pop03_hidden.php?member_id="+member_id+"&mileage_money="+mile_money+"&board_no="+board_no+"&product_name="+product_name + '&bbs_no=' + bbs_no;
		}
	}else{
		return false;
	}
}

function board_read_mileage_frame( mile_again, member_id, board_no, product_name )
{
	if( !member_id )
	{
		alert( 'Àû¸³±Ý¹Ù·ÎÁÖ±â´Â È¸¿ø¿¡°Ô¸¸ °¡´ÉÇÕ´Ï´Ù.' );

		return false;
	}

    var pre_selt = document.getElementsByName('mile_money'); 
    for (var i=0; i<5; i++){ 
        if (pre_selt[i].checked==true){ 
            break; 
        } 
    }
    var mile_money = document.getElementsByName('mile_money')[i].value; 

	msg = mile_money+"¿øÀ» Áö±ÞÇÏ½Ã°Ú½À´Ï±î?";

	if( confirm( msg ) ) {
		if ( mile_again == 'T' ) {
			msg2 = "ÀÌ¹Ì µ¿ÀÏ »óÇ°¸íÀ¸·Î Áö±ÞµÈ Àû¸³±ÝÀÌ ÀÖ½À´Ï´Ù.\n±×·¡µµ Áö±ÞÇÏ½Ã°Ú½À´Ï±î?";
			if( confirm( msg2 ) ) {
				document.give_mile.location.href = "/admin/php/c/member_admin_pop03_hidden.php?member_id="+member_id+"&mileage_money="+mile_money+"&board_no="+board_no+"&product_name="+product_name;
			}else{
				return false;
			}
		}else{
			document.give_mile.location.href = "/admin/php/c/member_admin_pop03_hidden.php?member_id="+member_id+"&mileage_money="+mile_money+"&board_no="+board_no+"&product_name="+product_name;
		}
	}else{
		return false;
	}
}

function comment_submit_check( form, used_name )
{
    form.target="_self";
    var max_length = 14;
    var comment = get_string_trim(form.comment.value);
    var comment_name = get_string_trim(form.comment_name.value);
    form.comment.value = comment;
    
    
    if (form.bbs_name_authed.value == 'F') {
        window.open('/front/php/b/pop_name_auth.php','bbs_name_auth','width=420,height=562');
        return false;
    }
    
    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);

        var size1 = get_string_length(form.comment_name.value);
        var size2 = get_string_length(form.comment_passwd.value);
		if(size1 > 100) {
            alert('ÀÌ¸§À» 100byteÀÌÇÏ·Î ÀÔ·ÂÇÏ¼¼¿ä');
            form.comment_name.focus();
            return false;
        } else if (size2 > 16) {
            alert('ºñ¹Ð¹øÈ£¸¦ 16byteÀÌÇÏ·Î ÀÔ·ÂÇÏ¼¼¿ä');
            form.comment_passwd.focus();
            return false;
		}

		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(form.comment.value == '') {
			alert('³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä');
			form.comment.focus();
			return false;
		}

		// 2009-05-19 : ÀÎÁõÅ° Ã¼Å© Ãß°¡ - cmc_jymaeng
		try {
			if(form.captcha.value == '') {
				if (document.getElementById("captcha_img").style.display == 'block') {
					alert('ÀÎÁõÅ°¸¦ ÀÔ·ÂÇÏ¼¼¿ä.');
					form.captcha.focus();
					return false;
				}
			}
		} catch (e) {}
    }

	/*
	var name_size = get_string_length(form.comment_name.value);

	if(name_size > max_length) {
		alert('ÀÌ¸§Àº ' + max_length + 'Byte ÀÌ»ó ÀÛ¼ºÇÒ ¼ö ¾ø½À´Ï´Ù.');
        form.comment_name.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;
    }
    */

    json_init(form,"add");
    return false;
}

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 get_comment_cut_length( string )
{
    var count = 0;
    var cut_count = 0;
    var tmp_str = new String(string);
    var temp = tmp_str.length;

    var onechar;

    var max_len = 199;

    for ( k=0; k<temp; k++ )
    {
        onechar = tmp_str.charAt(k);

        if (escape(onechar).length > 4)
        {
            if(count<max_len){
                cut_count +=1;
            }
            count += 2;
        }
        else
        {
            if(count<max_len){
                cut_count +=1;
            }
            count += 1;
        }
    }

    return cut_count;
}
// syjung200907
function substring_k( string, max_len )
{
    var count = 0;

    var tmp_str = new String(string);
    var temp = tmp_str.length;
	var str_valid_len = '' ;
    var onechar;

    for ( k=0; k<temp; k++ )
    {
        onechar = tmp_str.charAt(k);

        if (escape(onechar).length > 4)
        {
            count += 2;
        }
        else
        {
            count += 1;
        }
		if ( count <= max_len )
		{
			str_valid_len += onechar ;
		}
		else
			return str_valid_len
    }

    return str_valid_len;
}
function str_limit_check( obj, max_len, comment_no )
{
	comment = obj.value;
	// syjung200907
	if ( max_len == 0 ) return ;
	if ( !max_len ) max_len = 200;
	if ( !comment_no ) comment_no = '' ;

	var obj_cmt_size_msg = document.getElementById( 'cbyte_span' + comment_no ) ;

	content_length = get_string_length( comment );

	if ( obj_cmt_size_msg ) obj_cmt_size_msg.innerHTML = content_length;

	if( content_length > max_len )
	{
		msg = '¸Þ½ÃÁö´Â ' + max_len + ' Byte ÀÌÇÏ·Î ÀÔ·ÂÇØÁÖ¼¼¿ä.';
		alert( msg );
		//obj.value = comment.substr(0, max_len);
		obj.value = substring_k(comment, max_len);

		if ( obj_cmt_size_msg ) obj_cmt_size_msg.innerHTML = max_len;
	}
}
/*
function str_limit_check( obj )
{
	comment = obj.value;
	max_len = 200;

	content_length = get_string_length( comment );

	if( typeof( document.all['cbyte_span'] ) == "object" )
	{
		document.all['cbyte_span'].innerHTML = content_length;
	}

	if( content_length > max_len )
	{
		msg = '¸Þ½ÃÁö´Â ' + max_len + ' Byte ÀÌÇÏ·Î ÀÔ·ÂÇØÁÖ¼¼¿ä.';
		alert( msg );

				obj.value = comment.substr(0, max_len);

                cut_length = get_comment_cut_length( comment );

                obj.value = comment.substr(0, cut_length);

                content_length = get_string_length( obj.value );

		if( typeof( document.all['cbyte_span'] ) == "object" )
		{
			document.all['cbyte_span'].innerHTML = content_length;
		}
	}

}
*/

function board_copy( form )
{
    msg = "±Û º¹»ç½Ã Ã·ºÎÆÄÀÏ ¹× ÀÌ¹ÌÁö´Â ¿øº»±Û°ú °°ÀÌ »ç¿ëÇÏ°Ô µÇ¹Ç·Î ±Û»èÁ¦½Ã ÁÖÀÇÇÏ½Ã±â ¹Ù¶ø´Ï´Ù. \r\rº¹»çÇÏ½Ã°Ú½À´Ï±î?";

    if( !confirm( msg ) )
    {
         return false;
    }
    else
    {
        form.mode.value = 'copy_board';
        return true;
    }
}



function json_init(form,mode) {
    
    if(mode=="add") {
		var captcha = "";
		var obj_list = document.getElementsByName( 'comment_point' ) ;
		var comment_point = 0 ;
		for ( var cnt = 0, len = obj_list.length ; cnt < len ; cnt++ )
		{
			if ( obj_list[cnt].checked && !obj_list[cnt].disabled )
				comment_point = obj_list[cnt].value ;
		}

		// 2009-05-19 : ÀÎÁõÅ° Ã¼Å© Ãß°¡ - cmc_jymaeng
		try {
			var captcha = "&captcha="+form.captcha.value;
		} catch (e) {}

//        parma_str = "&mode=comment_add&board_no="+form.board_no.value+"&comment_name="+form.comment_name.value+"&comment_passwd="+form.comment_passwd.value+"&comment="+form.comment.value+"&no="+form.no.value+captcha;
		// syjung200907
        parma_str = "&mode=comment_add&board_no="+form.board_no.value+"&comment_name="+form.comment_name.value+"&comment_passwd="+form.comment_passwd.value+"&comment="+encodeURIComponent(form.comment.value)+"&no="+form.no.value+captcha+"&comment_point="+comment_point;
        sendRequest(json_comment_insert, parma_str,'POST', '/front/php/b/board_write_a_new.php', true, true);
    }
    else if(mode=="del") {
    }
}

function json_comment_insert(oj) {
	if ( !oj || !oj.responseText ) return ; // syjung200907
    eval("var res = " + oj.responseText);
    
    //comment_tpl = document.getElementById('div_comment_tpl').value;
    comment_tpl = document.getElementsByName('div_comment_tpl')[0].value;

	// 2009-05-19 : ºñÇ¥ÁØÀ¸·Î µ¿ÀÛÇÏ´ø ºÎºÐ ¼öÁ¤ - cmc_jymaeng
	var cmt = document.getElementsByName('comment');

	if (res.Static[0].error) {
		if (res.Static[0].error) alert(res.Static[0].error);
		return ; // syjung200907
        document.location.reload();
	} else {
		comment_tpl = comment_tpl.replace(/\[ajax_comment_no\]/g,res.Static[0].comment_no);
		comment_tpl = comment_tpl.replace("[ajax_comment_name]",res.Static[1].comment_name);
		comment_tpl = comment_tpl.replace("[ajax_comment]",res.Static[4].comment_comment);
		comment_tpl = comment_tpl.replace("[ajax_comment_member_id]",res.Static[2].comment_member_id);
		comment_tpl = comment_tpl.replace("[ajax_comment_write_date]",res.Static[3].comment_write_date);
		comment_tpl = comment_tpl.replace("[ajax_comment_point_html]",res.Static[6].comment_point_html);

		if(document.getElementById("captcha_img")){
			document.getElementById("captcha_img").src = res.Static[5].comment_captcha;
		}
		document.getElementsByName('comment')[0].value="";
		
		ret_comment_tpl = comment_tpl;
		ret_comment_tpl = document.getElementById('div_comment_list').innerHTML+ret_comment_tpl;
		document.getElementById('div_comment_list').innerHTML=ret_comment_tpl;
		
	   // syjung200907
	   var obj_cmt_size_msg = document.getElementById( 'cbyte_span' ) ;
	   if ( obj_cmt_size_msg ) obj_cmt_size_msg.innerHTML = '0' ;
		try {
			if(document.getElementById('blog_ck').value=="T") {
				self.resizeTo(document.body.scrollWidth, document.body.scrollHeight);
			}
		} catch (e) {}
    }
    
}

//Comment Layer Control
function comment_modify_div_control(idx, view, modify) {
    var arrDisplay = new Array('none','block');
    if (document.getElementById('view_'+idx)) document.getElementById('view_'+idx).style.display = arrDisplay[view];
    if (document.getElementById('modify_'+idx)) document.getElementById('modify_'+idx).style.display = arrDisplay[modify];
}

// Comment Modify
function comment_modify(board_no, no, comment_no) {
   
   var comment_passwd = document.getElementById("pw_comment_"+comment_no);
   var comment = document.getElementById("txt_comment_"+comment_no);
   // syjung200907
   var obj_cmt_size_msg = document.getElementById( 'cbyte_span' + comment_no ) ;
   if ( obj_cmt_size_msg ) obj_cmt_size_msg.innerHTML = '0' ;

   if(comment_passwd.value == '') {
        alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä');
        comment_passwd.focus();
        return;
    }

    if(comment.value == '') {
        alert('³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä');
        comment.focus();
        return;
    }

    //parma_str = "&mode=comment_modify&board_no="+board_no+"&no="+no+"&comment_no="+comment_no+"&comment_passwd="+comment_passwd.value+"&comment="+comment.value;
	// syjung200907
    parma_str = "&mode=comment_modify&board_no="+board_no+"&no="+no+"&comment_no="+comment_no+"&comment_passwd="+comment_passwd.value+"&comment="+encodeURIComponent(comment.value);
    sendRequest(json_comment_modify, parma_str,'POST', '/front/php/b/board_write_a_new.php', true, true);
    return;
}

// Comment Modify Result
function json_comment_modify(oj) {

    eval("var res = " + oj.responseText);

    if (res.Static[0].error) {
        alert(res.Static[0].error);
    } else {
        document.location.reload();
    }

    return;
}

// Comment Modify ±âº»Á¤º¸ ¼öÁý
function comment_modify_info(board_no, comment_no) {
   /*
     /front/php/b/board_read_new.php ÆäÀÌÁö¿¡¼­ Çã¿ëµÇÁö ¾ÊÀº REQUEST º¯¼ö¸¦
     UNSET ÇÏ¿© ±âÁ¸ º¯¼ö no·Î comment_no¸¦ Àü¼Û
   */
   parma_str = "&mode=comment_modify_info&board_no="+board_no+"&no="+comment_no;
   sendRequest(json_comment_modify_info, parma_str,'POST', '/front/php/b/board_read_new.php', true, true);

   return;
}

// Comment Modify ±âº»Á¤º¸ ¼öÁý°á°ú Ã³¸®
// syjung200907 : Comment=>Static
function json_comment_modify_info(oj) {
	if ( !oj || !oj.responseText) return;  // syjung200907
    eval("var res = " + oj.responseText);

    if (res.Static[0].error) {
        if (res.Static[0].error) alert(res.Static[0].error);
    } else {
        var idx = res.Static[0].comment_no;
        comment_modify_div_control(idx,0, 1);

        document.getElementsByName('txt_comment_' + idx)[0].value = res.Static[1].comment_comment.replace(/\<br \/\>/g,"\r\n");
        document.getElementsByName('txt_comment_' + idx)[0].focus();

	   // syjung200907
	   var obj_cmt_size_msg = document.getElementById( 'cbyte_span' + idx ) ;
	   if ( obj_cmt_size_msg ) obj_cmt_size_msg.innerHTML = get_string_length( document.getElementsByName('txt_comment_' + idx)[0].value ) ;
    }

    return;
}

//2009-07-18 ½ºÆÔ½Å°í ÆË¾÷Ã¢ - ±ÇÇõÃµ
function is_spam(mode,bbs_no,bbs_type) {
    // º»¹®ÀÏ¶§´Â ±Û¹øÈ£ Àü´Þ, ÄÚ¸àÆ®´Â Ã¼Å©¹Ú½º¿¡¼­ ÃßÃâ
    if (bbs_no==''){
        var token = '';
        var f = document.getElementsByName('bbs_no[]');
        for (i=0;i<f.length;i++) {
            if (f[i].checked == true) {
                bbs_no += token + f[i].value;
                token = ',';
            }
        }
    }

    if (bbs_no) {
        if (mode=='move') {
            if (bbs_type=='contents')
                OpenWindow('/admin/php/b/board_spam_regist.php?mode='+mode+'&bbs_type='+bbs_type+'&bbs_no='+bbs_no+'&return_url=' + document.getElementById('sSpamDeleteReturnUrl').value, 'spamRegist', '450', '350','no');
            else
                OpenWindow('/admin/php/b/board_spam_regist.php?mode='+mode+'&bbs_type='+bbs_type+'&bbs_no='+bbs_no, 'spamRegist', '450', '350','no');
        } else {
            OpenWindow('/admin/php/b/board_spam_restore.php?mode='+mode+'&bbs_type='+bbs_type+'&bbs_no='+bbs_no, 'spamRestore', '470', '350','yes');
        }
    } else {
        alert('°Ô½Ã¹°À» ¼±ÅÃÇØÁÖ¼¼¿ä.');
    }
}

// syjung
var RECOM_CTL = {
	up_req : function ( bbs_no, board_no )
	{
		var str_param = '&mode=recom_up&no=' + bbs_no + '&board_no=' + board_no  ;
		sendRequest( RECOM_CTL.up_res, str_param, 'POST', '/front/php/b/board_write_a_new.php', true, true ) ;
	},
	up_res : function ( oj )
	{
//		alert( oj.responseText ) ;
		if ( !oj || !oj.responseText ) return ;
	    eval( "var res = " + oj.responseText ) ;
		if ( res.result_code == 'recom_up' )
		{
			alert( 'ÃßÃµµÇ¾ú½À´Ï´Ù' ) ;
			var obj_recom_cnt = document.getElementById( 'span_recom_cnt' ) ;
			var recom_cnt = parseInt( obj_recom_cnt.innerHTML ) ;
			obj_recom_cnt.innerHTML = recom_cnt + 1 ;
		}
		else if ( res.result_code == 'recom_max' )
		{
			alert( 'ÀÌ¹Ì ÃßÃµÇÏ¿´½À´Ï´Ù' ) ;
		}
		else
		{
			alert( 'ÃßÃµ Á¶°ÇÀÌ ¸ÂÁö ¾Ê½À´Ï´Ù' ) ;
		}
	}
}


function pre_comment(){
	OpenWindow('/admin/php/b/board_admin_pre_comment_l.php?mode=popup', 'pre_comment', '800', '500','auto');
}