//-------------------------------------------------------------------//
//  ÇÁ·Î±×·¥¸í : gmEditor v1.1
//-------------------------------------------------------------------//
//  ÃÖÃÊ °³¹ß ¿Ï·áÀÏ : 2006-01-05
//  °³¹ß»ç ¹× ÀúÀÛ±ÇÀÚ : PHP¸ó½ºÅÍ
//  À¥»çÀÌÆ® : http://www.phpmonster.co.kr
//  °³ ¹ß ÀÚ : ¹Ú¿äÇÑ (misnam@gmail.com)
//-------------------------------------------------------------------//
//                           Ä«ÇÇ¶óÀÌÆ®
//-------------------------------------------------------------------//
//  º» ÇÁ·Î±×·¥Àº ¹«·á ÇÁ·Î±×·¥À¸·Î ¹èÆ÷µË´Ï´Ù.
//  gmEditor´Â GNU General Public License(GPL) ¸¦ µû¸¨´Ï´Ù.
//  º¸´Ù ÀÚ¼¼ÇÑ ³»¿ëÀº LICENSE¸¦ ÂüÁ¶ÇÏ½Ê½Ã¿ä.
//  Âü°í: http://korea.gnu.org/people/chsong/copyleft/gpl.ko.htmll
//-------------------------------------------------------------------//
//                           °³¹ßÈ¯°æ
//-------------------------------------------------------------------//
//  Browser: ÀÍ½ºÇÃ·Î·¯, ÆÄÀÌ¾îÆø½º, ³×½ºÄÉÀÌÇÁ
//  Server : PHP°¡ Áö¿øµÇ´Â ¸ðµç ¼­¹ö
//-------------------------------------------------------------------//


var str,os,gmFrame;
var ostmp = navigator.appName.charAt(0);

// ºê¶ó¿ìÀú È®ÀÎ
if(ostmp=='M') os = ''; else if(ostmp=='N') os = 1; else os = '';

// ÇÁ·¹ÀÓ Å¸ÀÔ
gmFrame = !os ? frames.gmEditor : document.getElementById("gmEditor").contentWindow;

// IE ? Nets
str = "<style>p{margin-top:1px;margin-bottom:1px;}</style>\n";



// ºó¹®¼­ ºÒ·¯¿À±â
function newDoc(){
	gmFrame.document.open("text/html");
	gmFrame.document.write(str);
	gmFrame.document.write("&nbsp;");
	gmFrame.document.close();
	gmFrame.focus();
}

// HTMLÆíÁý
function editor_html(){
	obj = window.open(_editor_url+'/html_edit.html','_editor_Html','width=650,height=530,scrollbars=no');
}

// ¹Ì¸®º¸±â
function editor_view(){
	obj = window.open(_editor_url+'/preview.html','_editor_view','width=650,height=550,scrollbars=yes');
}

// ÀÌ¹ÌÁö,¹Ìµð¾î Ã·ºÎ
function file_upload(id){
	var _tps = '';

	// ¹Ìµð¾î ¾÷·Îµå
	if(id > 0){
		// ¾÷·Îµå¸¦ Çã¿ë (1Àº ¾÷·ÎµåºÒ°¡)
		if(_m_uploaded==1) return false;
		_height = 170;
	}
	// ÀÌ¹ÌÁö ¾÷·Îµå
	else{
		// ¾÷·Îµå¸¦ Çã¿ë (1Àº ¾÷·ÎµåºÒ°¡)
		if(_i_uploaded==1) return false;
		_tps = '?op=1';
		_height = 350;
	}
	return window.open(_editor_url+'/upfile.html'+_tps,'_editor_tb','staus=no, width=300, height='+_height+',scrollbars=no,toolbar=no,menubar=no');
} // end func

// ¸ð´Þ»óÀÚ
function createHTML(opt,key){
	var width,height,filename,val;

	switch(key){
		case 1: // Å×ÀÌºí »ðÀÔ
			width=!os?358:352; height=!os?260:218; filename = 'table.html';
		break;

		case 2: // Æ¯¼ö¹®ÀÚ »ðÀÔ
			width=!os?308:304; height=!os?360:330; filename = 'characteristic.html';
		break;

		case 3: // ¾ÆÀÌÄÜ »ðÀÔ
			width=!os?238:232; height=!os?280:248; filename = 'emotions.html';
		break;

		case 4: // ±Û²Ã »ðÀÔ
			width = 250; height=!os?335:300; filename = 'fontname.html';
		break;

		case 5: // ±ÛÀÚ»ö »ðÀÔ
			width = 260; height=!os?309:280; filename = 'color.html';
		break;

		case 6: // ±ÛÀÚ ¹è°æ»ö »ðÀÔ
			var op = (os==1) ? '?op=1' : '';
			width = 260; height=!os?309:280; filename = 'color.html'+op;
		break;

		case 7: // ±ÛÀÚ Å©±â »ðÀÔ
			width = 350; height=!os?280:245; filename = 'fontsize.html';
		break;

		case 8: // ÇÏÀÌÆÛ ¸µÅ©
			width=!os?400:360; height=!os?180:135; filename = 'hyperLink.html';
		break;
	}

	if(!os)	val = showModalDialog(_editor_url+'/'+filename,null,'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogLeft:center;diallogTop:center;help:no;status:no;');
	else obj = window.open(_editor_url+'/'+filename,'_editor_tb','staus=no, width='+width+', height='+height+',scrollbars=no,toolbar=no,menubar=no');

	if(val){
		gmFrame.focus();
		if((key==4)||(key==5)||(key==6)||(key==7)) window.htmltrue(opt,val,true);
		// ÇÏÀÌÆÛ¸µÅ© »ðÀÔ
		else if((key==3)||(key==8)) {
			// ÀÌ¸ðÆ¼ÄÜ »ðÀÔ
			if(key==3) val = _editor_url + '/img/emotions/' + val;
			window.htmltrue(opt,val,false);
		}
		else window.HTMLPaste(val);
	}
	return false;
}


// ÀÌÀü ³»¿ëÀÌ ÀÖÀ¸¸é °¡Á®¿È
function Edit_Modify(_contentName,_contentValue){
	return eval("document." + _contentName + "." + _contentValue + ".value");
}

// Æû Àü¼Û½Ã ÀÔ·Â¹ÞÀ» °ª
function SubmitHTML(){
	var tmp = !os ? gmFrame.document.body.innerHTML : gmFrame.document.documentElement.innerHTML;
	var tmp_content = '';
	tmp_content = tmp.replace(/<(\/?)p>/gi,"");
	tmp_content = tmp_content.replace(/<br>/gi,"");
	tmp_content = tmp_content.replace(/ /gi,"");
	tmp_content = tmp_content.replace(/&nbsp;/gi,"");
	tmp_content = tmp_content.replace(/<head>(.*?)<(\/?)head>/gi,"");
	tmp_content = tmp_content.replace(/<(\/?)body>/gi,"");

	return (tmp_content==0) ? '' : tmp;
}

// °¢Á¾ HTML »ðÀÔ
function HTMLPaste(key){
	gmFrame.focus();

	// IE
	if(!os){
		past = gmFrame.document.selection.createRange();
		past.pasteHTML(key);
	}

	// Nets
	else if(os==1) gmFrame.document.execCommand("inserthtml",false,key);
	else return;

} // end if

function htmlfalse(key){
	gmFrame.focus();
	gmFrame.document.execCommand(key,false,null);
	return false;
}

function htmltrue(key,val,mode){
	gmFrame.focus();
	gmFrame.document.execCommand(key,mode,val);
	return false;
}

gmFrame.focus();
gmFrame.document.open("text/html");
gmFrame.document.writeln(str);
gmFrame.document.writeln(Edit_Modify(_contentName,_contentValue));
gmFrame.document.close();

gmFrame.document.designMode = "On";

