<?php
$title      = '';
$content    = '';
$faq_category_code1 = '';
$faq_category_code2 = '';
if($mode=='edit') {
    $title              = $result['title'];
    $title 				= htmlspecialchars($title);
    $content    		= htmlentities($result['content']);
    $faq_category_code1 = $result['faq_category_code1'];
    $faq_category_code2 = $result['faq_category_code2'];

} else {
    $faq_category_code1 = substr($search_category_code, 0, 2);
    $faq_category_code2 = substr($search_category_code, 2, 2);
}

?>

<script src="/ckeditor/ckeditor.js"></script>

<?
$menu_code = '72';
require_once (APPPATH.'views/skin/admin/_content_comm.php');
?>

<form name="input_form" id="input_form" action="/admin/cs/cs_faq_reg_proc" method="post">
<input type="hidden" name="idx" id="idx" value="<?=$idx?>">
<input type="hidden" id="search_type" name="search_type" value="<?=$search_type?>">
<input type="hidden" id="search_keyword" name="search_keyword" value="<?=$search_keyword?>">
<input type="hidden" id="page" name="page" value="<?=$page?>">
<input type="hidden" id="mode" name="mode" value="<?=$mode?>">
<input type="hidden" id="search_category_code" name="search_category_code" value="<?=$search_category_code?>">
<input type="hidden" id="img_path" name="img_path">
    
    
<div class="common_table">
    <table>
    <tr>    
        <th>1차 카테고리</th>
        <td class="tl">
            <select name="category1" id="category1" onchange="change_category1(this.value);" class="type01">
                <option value="">선택</option>
        <?  foreach ($arr_category1 as $val) { ?>
                <option value="<?=$val['category_code']?>" <? if($faq_category_code1==$val['category_code']) { echo 'selected';}?>><?=$val['category_name']?></option>
        <?  }?>
            </select>
        </td>
    </tr>
    <tr>
        <th>2차 카테고리</th>
        <td class="tl">
            <select name="category2" id="category2" class="type01">
                <option value="">선택</option>
    <?  if($faq_category_code1!='') {
            foreach($arr_category2 as $val) {
                if($val['p_category_code'] == $faq_category_code1) {
    ?>
                    <option value="<?=$val['category_code']?>" <? if($faq_category_code2==$val['category_code']) { echo 'selected';}?>><?=$val['category_name']?></option>
    <?           }
            }
        }
    ?>
            </select>
        </td>
    </tr>
    <tr>
        <th>제목</th>
        <td class="tl">
            <input type="text" name="title" id="title" value="<?=$title?>">
        </td>
    </tr>
    <tr>
        <th>내용</th>
        <td>
		<!-- <textarea id="content" name="content"><?=$content?></textarea> -->
		<textarea name="content" id="ir1" style="width:100%; height:500px;" /><?=$content?></textarea>
        </td>
    </tr>
    </tr>
    </table>
</div>
<div class="write_btn tc">
	<a href="javascript:faq_reg_proc();">저장하기</a>
	<a href="/admin/cs/cs_faq_list/7/<?=$page?>?search_type=<?=$search_type?>&search_keyword=<?=$search_keyword?>&search_category_code=<?=$search_category_code?>">목록으로</a>
</div>
    
</form>




<script type="text/javascript">
var oEditors = [];
var oEditors2 = [];

$(function(){
      nhn.husky.EZCreator.createInIFrame({
          oAppRef: oEditors,
          elPlaceHolder: "ir1",
          sSkinURI: "/smarteditor/SmartEditor2Skin.html",  
          htParams : {
              bUseToolbar : true,             
              bUseVerticalResizer : true,     
              bUseModeChanger : true,         
              fOnBeforeUnload : function(){
              }
          }, 
          fOnAppLoad : function(){
          },
          fCreator: "createSEditor2"
      });
      
      nhn.husky.EZCreator.createInIFrame({
          oAppRef: oEditors2,
          elPlaceHolder: "ir2", 
          sSkinURI: "/smarteditor/SmartEditor2Skin.html",  
          htParams : {
              bUseToolbar : true,             
              bUseVerticalResizer : true,     
              bUseModeChanger : true,         
              fOnBeforeUnload : function(){
              }
          }, 
          fOnAppLoad : function(){
          },
          fCreator: "createSEditor2"
      });

});
</script>

<script type="text/javascript">
$(document).ready(function() {
    /*
	CKEDITOR.replace('content', {
        height: '400px'
    });
	*/
});

function faq_reg_proc(){
	//CKEDITOR.instances.content.updateElement();
	oEditors.getById["ir1"].exec("UPDATE_CONTENTS_FIELD", []);
	//oEditors2.getById["ir2"].exec("UPDATE_CONTENTS_FIELD", []);

    if($("#category1").val()=='') {
		alert("1차 카테고리를 입력해주세요.");
		return false;
	}
    if($("#category2").val()=='') {
		alert("2차 카테고리를 입력해주세요.");
		return false;
	}
	if($("#title").val()=='') {
		alert("제목을 입력해주세요.");
		return false;
	}
	/*
	if($("#content").val()=='') {
		alert("내용을 입력해주세요.");
		return false;
	}
	*/
	if($("#ir1").val()=='' || $("#ir1").val()=='null' || $("#ir1").val()=='&nbsp;' || $("#ir1").val()=='<p>&nbsp;</p>') {
		alert("내용을 입력해주세요.");
		oEditors.getById["ir1"].exec("focus");
		return false;
	}

	$("#input_form").submit();

}

var json_category = '<?=json_encode($arr_category2)?>';
json_category = eval(json_category);
function change_category1(val){

    $('#category2').empty();
    var option = '';

    option = $("<option value=''>선택</option>");
    $('#category2').append(option);

    for(key in json_category) {
        if(json_category[key]['p_category_code'] == val) {
            option = $("<option value='"+json_category[key]['category_code']+"'>"+json_category[key]['category_name']+"</option>");
            $('#category2').append(option);

        }
    }

}



</script>