<? if ( !defined("_INCLUDED_GLOBAL") ) exit;		// [Security]Allow_url_fopen = On ?>

<script language="JavaScript" src="<?= $nmpath ?>/addon/js/prototype.js?v=<?= NM_VER ?>"></script>
<script language="JavaScript" src="<?= $nmpath ?>/addon/actb/actb.js?v=<?= NM_VER ?>"></script>
<script language="JavaScript" src="<?= $nmpath ?>/addon/actb/common.js?v=<?= NM_VER ?>"></script>
<script language="JavaScript">
<!--

	var get_qs = "<?= get_qs() ?>";
	var nm_php_self = "mail_write_ok.php";
	var wform = document.forms.write;

	// [2007-06-14] 주소 자동완성
	var actb_to = actb(wform.mf_to,new Array());
	if (wform.mf_cc)
		var actb_cc = actb(wform.mf_cc,new Array());
	if (wform.mf_bcc)
		var actb_bcc = actb(wform.mf_bcc,new Array());

	var nm_webeditor = '<?= $G_SYS['WEBEDITOR'] ?>';

	<? if ($G_SYS['WEBEDITOR'] == 'FCK') { ?>
		var sBasePath = '<?= $nmpath ?>/addon/fckeditor/';
		var oFCKeditor = new FCKeditor( 'mf_body_html', '100%', '350', 'Nmail' ) ;
		oFCKeditor.BasePath	= sBasePath ;
		oFCKeditor.Config['SkinPath'] = 'skins/office2003/';

		oFCKeditor.ReplaceTextarea() ;
	<? }	// if() ?>

	<? if ($view['mf_cc']) { ?>
		addCc();
	<? }	// if() ?>

	<? if ($view['mf_bcc']) { ?>
		addBcc();
	<? }	// if() ?>

	// 받는 사람 주소 자동확장.
	rowsUp(wform.mf_to, 40, 10);

	// 입력안내
	//input_guide(true);

	// 임시보관함에 자동 저장.
	function mail_write_draft_save_auto()
	{
		mail_write_draft_save(1);
		window.setTimeout('mail_write_draft_save_auto()', <?= ($G_SYS['DRAFT_SAVE_AUTO_TIME']*1000) ?>);
	}
	var mwdsa = window.setTimeout('mail_write_draft_save_auto()', <?= ($G_SYS['DRAFT_SAVE_AUTO_TIME']*1000) ?>);

	// 메일전달시 첨부파일
	function forward_attach_add()
	{
		<?= $view['forward_attach_add_js'] ?>
	}	// function()


	<? if ($G_SYS['NM_LETTER_USE'] && (strpos($_SERVER['PHP_SELF'], 'mailer/send.php') === false || $G['__MAILER_MAIL_WRITE_JS_UPDATE'])) {		// 편지지 사용시 ?>
		// 편지지
		var _mf_body_html_tbl_width = '';		// 편지지 적용전 에디터 너비
		var _mf_body_html_tbl_height = '';		// 편지지 적용전 에디터 높이
		var _mf_body_html_ifr_height = '';		// 편집창
		var mf_body_letter_view = false;
		function mf_body_letter_click()
		{
			if (mf_body_letter_view == false)
			{
				_mf_body_html_tbl_width = document.getElementById('mf_body_html_tbl').style.width;
				_mf_body_html_tbl_height = document.getElementById('mf_body_html_tbl').style.height;
				_mf_body_html_ifr_height = document.getElementById('mf_body_html_ifr').style.height;
				document.getElementById('mf_body_html_tbl').style.width = '766px';
				document.getElementById('mf_body_html_tbl').style.height = '420px';
				document.getElementById('mf_body_html_ifr').style.height = '350px';
				document.getElementById('mf_body_right').style.width = '160px';
				document.getElementById('mf_body_right').style.height = '100%';
				document.getElementById('mf_body_right').style.display= '';
				document.getElementById('mf_body_right').innerHTML = '<iframe width=160 height=100% frameborder=0 src="<?= $nmpath ?>/mail_write_letter.php" style="width:160px; height:100%; margin:0px"></iframe>';
				mf_body_letter_view = true;
			} else
			{
				if (document.getElementById('mf_body_letter').value != '')
				{
					alert("편지지가 선택된 상태에서는 편지지 목록을 숨길 수 없습니다.\n\n편지지를 사용하지 않으려면 [편지지 빼기]를 눌러주셔야 합니다.");
					return;
				}
				document.getElementById('mf_body_html_tbl').style.width = _mf_body_html_tbl_width;
				document.getElementById('mf_body_html_tbl').style.height = _mf_body_html_tbl_height;
				document.getElementById('mf_body_html_ifr').style.height = _mf_body_html_ifr_height;
				document.getElementById('mf_body_right').style.display= 'none';
				mf_body_letter_view = false;
			}
		}

		function mf_body_letter_active()
		{
			if(typeof window.addEventListener != 'undefined')
			{
				document.getElementById('mf_body_html_nm_letter_box_text').addEventListener("click", function() { mf_body_letter_click(); }, false);
				document.getElementById('mf_body_html_nm_letter_box_open').addEventListener("click", function() { mf_body_letter_click(); }, false);
			} else if(typeof window.attachEvent != 'undefined') 
			{
				document.getElementById('mf_body_html_nm_letter_box_text').attachEvent( "onclick", function () { mf_body_letter_click(); } );
				document.getElementById('mf_body_html_nm_letter_box_open').attachEvent( "onclick", function () { mf_body_letter_click(); } );
			}
		}

		tinymce.create('tinymce.plugins.nmLetterPlugin', {
			createControl: function(n, cm) {
				switch (n) {
					case 'nm_letter_box':
						var mlb = cm.createListBox('nm_letter_box', {
							 title : '편지지'
						});
						return mlb;
				}
				return null;
			}
		});
		tinymce.PluginManager.add('nm_letter', tinymce.plugins.nmLetterPlugin);
	<? } else { ?>
		function mf_body_letter_active()
		{
			//
		}
	<? }	// if() ?>


	window.onload = function()
	{
		<? /* [2010-05-27] tinyMCE.init : mail_write.html -> mail_write_js.php */ ?>
		<? if ($G_SYS['WEBEDITOR'] == 'TINYMCE' && (strpos($_SERVER['PHP_SELF'], 'mailer/send.php') === false || $G['__MAILER_MAIL_WRITE_JS_UPDATE'])) { ?>
			// 웹에디터
			tinyMCE.init({
				// General options
				language : "<?= $G_SYS['nm_lang'] ?>",
				mode : "exact",
				theme : "advanced",
				elements : "mf_body_html",
				// [2011-08-08] disable convert url
				//document_base_url  : "<?= $G_SYS['HTTP_URL_ROOT'] ?>",
				relative_urls : false,
				remove_script_host : false,
				oninit : "mf_body_letter_active",
				visual : false,		// 가이드라인 비표시
			
				plugins : "safari,table,advimage,advlink,preview,media,contextmenu,fullscreen,visualchars,inlinepopups,paste<? if ($G_SYS['NM_LETTER_USE']) {		// 편지지 사용시 ?>,-nm_letter<? }	// if() ?>",

				// Theme options
				<? if ($G_SYS['nm_lang'] == 'ko') { ?>
					theme_advanced_fonts : '굴림=굴림,돋움=돋움,바탕=바탕,궁서=궁서,Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;WingDings=wingdings',
				<? } else { ?>

				<? }	// if() ?>

				theme_advanced_buttons1 : "fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,|,removeformat",
				theme_advanced_buttons2 : "image,media,charmap,|,hr,|,tablecontrols,|,visualaid,|,code,preview,fullscreen<? if ($G_SYS['NM_LETTER_USE']) {		// 편지지 사용시 ?>,|,nm_letter_box<? }	// if() ?>",
				theme_advanced_buttons3 : "",
				theme_advanced_buttons4 : "",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : true,
				theme_advanced_resize_horizontal : false,

				// [2010-02-09] Performance tuning
				// [2012-11-16] 3.5.7 - 크롬/사파리 빈라인 무시 현상 해결
				//verify_html : false,
				cleanup : false,

				// [2010-05-27] path hidden
				theme_advanced_path : false,

				// [2013-07-09] style
				paste_retain_style_properties : 'all',

				content_css : '<?= $nmpath ?>/addon/tinymce/themes/advanced/skins/default/content.css?v=<?= NM_VER ?>'
			});
		<? }	// if() ?>

		<? if (get_activex_use()) { ?>
			uploadConfigSet();
		<? }	// if() ?>

		<? if ($_GET['me']) {		// [2013-07-09] 좌측메뉴에 내게쓰기 추가?>
		mail_write_me('<?= $AUTH['auth_m_id'].'@'.$G_SYS['MAIL_DOMAIN'] ?>');
		<? }	// if() ?>

		// [2007-06-05] 받는사람/제목에 커서 이동
		if (wform.mf_to.value == '')
		{
			wform.mf_to.focus();	
		} else 
		{
			wform.mf_subject.focus();	
		}	// if()

		// 메일전달시 첨부파일
		forward_attach_add();

		<? if (get_activex_use()) { ?>
		// 용량갱신
		attachSizeUpdate();
		<? }	// if() ?>
	}

//-->
</script>
