	tinyMCE.init({
		// General options
	    language : "ko",
		mode : "exact",
        entity_encoding : "raw",
		elements : "contents", 
		theme : "advanced",
		forced_root_block : 'p',
        force_br_newlines : false,
        force_p_newlines : true,
		
 		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
		 convert_urls : false,
		

		// Theme options
		theme_advanced_buttons1 : 
		"fontselect,fontsizeselect,bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,|,blockquote,code,han_chang,strip_tags",
		
		theme_advanced_buttons2 : "cut,copy,paste,tablecontrols,|,undo,redo,|,hr,charmap,|,link,unlink,|,imgbodyInsert",
		

		

		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
        theme_advanced_fonts : "굴림=굴림;"+
			   "바탕=바탕;"+
			   "돋움=돋움;"+
			   "궁서=궁서;"+
                "Arial=arial,helvetica,sans-serif;"+
                "Arial Black=arial black,avant garde;"+
                "Book Antiqua=book antiqua,palatino;"+
                "Comic Sans MS=comic sans ms,sans-serif;"+
                "Courier New=courier new,courier;"+
                "Georgia=georgia,palatino;"+
                "Helvetica=helvetica;",
               

		// Example content CSS (should be your site CSS)
		cleanup : false,

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

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

				// [2013-08-14] excel border hidden fix
				paste_auto_cleanup_on_paste : false,

		content_css : "/tinymce/examples/css/content_bbs.css?" + new Date().getTime(),

		

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		formats : {
			alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
			aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
			alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
			alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
			bold : {inline : 'span', 'classes' : 'bold'},
			italic : {inline : 'span', 'classes' : 'italic'},
			underline : {inline : 'span', 'classes' : 'underline', exact : true},
			strikethrough : {inline : 'del'}
		},

	   
		// Replace values for the template plugin
		template_replace_values : {
			username : "ins",
			staffid : "991234"
		},
			
		
		setup : function(ed) {   
            // 이미지 업로드 창   
			ed.addButton('imgbodyInsert', {   
                title : '이미지넣기',   
                image: '/tinymce/img/IconImage.gif',
				   onclick : function() {   
                    win_open_img_a();   
                }   
            });   
		  
		  ed.addButton('han_chang', {   
                title : '한줄뛰어(단락구분)',   
                image: '/tinymce/img/han_chang.gif',
				   onclick : function() {   
                    han_chang_row();   
                }   
            });   

			 ed.addButton('strip_tags', {   
                title : '태그제거',   
                image: '/tinymce/img/strip_tags.gif',
				   onclick : function() {   
					if(tinyMCE.activeEditor.selection.getContent()) { //선택한 내용이 있으면 선택한 내용만 적용
						var res=strip_tags(tinyMCE.activeEditor.selection.getContent(),"<br><p>");   
						tinyMCE.activeEditor.selection.setContent(res);
					} else { //선택한 내용이 없으면 전체 내용 적용 <table><tr><td><th><tbody><div><img>
						var res=strip_tags(tinyMCE.activeEditor.getContent(),"<br><p>");   
						tinyMCE.activeEditor.setContent(res);
					}
                }   
            });
        }     





	});

	


function win_open_img_a (){
	var poppedWindow;
	if(!poppedWindow || poppedWindow.closed){
		poppedWindow= window.open('/imgdata/plist_a.php', 'zipwin', 'width=650,height=650,status=no,scrollbars=1,resizable=yes');
		if(poppedWindow){
			poppedWindow.focus();
		}
		else{
			location.href='/imgdata/plist_a.php';
		}
	}
	else{
		poppedWindow.location.href='/imgdata/plist_a.php';
		poppedWindow.focus();
	}
}

function han_chang_row()
{
	//"force_br_newlines : true, force_p_newlines : false," 로 설정이 되있을 경우 한줄뛰어 안되는 문제 수정
	if (tinyMCE.activeEditor.getContent().indexOf("</p>") != -1) {
		var res = tinyMCE.activeEditor.getContent().replace(/<\/p>/ig, "</p><br />");
	} else {
		var res = tinyMCE.activeEditor.getContent().replace(/<br \/>/ig, "<br /><br />"); 
	}

	tinyMCE.activeEditor.setContent(res);

}

//p태그 속성제거
function replacer(match, p1, p2, p3, offset, string) {
	var tmp = [p1,p3].join('');
  return "<p >&nbsp;</p >"+tmp;
}

function strip_tags (input, allowed) {
	
	  var     input=input.replace(/<p class="0"><!--\[if !supportEmptyParas\]--> <!--\[endif\]-->/ig, '');
	  //var     input=input.replace(/\[endif\]/ig, '');
	 //  var     input=input.replace(/endif/ig, '');
	
   allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); 
   var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
       commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi;
	   
   return input.replace(/(<p|<br)( [^>]*)(>)/gi, replacer).replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
   });

 }
