//-------------------------------------------------------------------//
//  ÇÁ·Î±×·¥¸í : gmEditor v1.2
//-------------------------------------------------------------------//
//  ÃÖÃÊ °³¹ß ¿Ï·áÀÏ : 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,array;
var ostmp = navigator.appName.charAt(0);

// browser
os = (ostmp=='M') ? '' : 1;

// frame type
gmFrame = !os ? frames.gmEditor : document.getElementById("gmEditor").contentWindow;

// IE ? Nets
str = "<style>body{font-family: Tahoma,Verdana,Arial;font-size: 11px;color: #555555;margin: 0px}td{font-size :11px; font-family: Tahoma,Verdana,Arial;}p{margin-top:1px;margin-bottom:1px;}</style>\n";



// new document
function newDoc(){
	gmFrame.document.open("text/html");
	gmFrame.document.write(str);
	gmFrame.document.write("&nbsp;");
	gmFrame.document.close();
	gmFrame.focus();
}

// layer Hide
function Layerhide(name){
	document.getElementById(name).innerHTML = '';
}

// HTML edit
function editor_html(){
	obj = window.open(_editor_url+'/html_edit.html','_editor_Html','width=650,height=495,scrollbars=no');
}

// Preview
function editor_view(){
	obj = window.open(_editor_url+'/preview.html','_editor_view','width=650,height=550,scrollbars=yes');
}

// File uploaded
function file_upload(id,name){
	if(id > 0){
		document.getElementById('editor_stom').value = document.getElementById('editor_stom').value + '#' + _m_uploaded;
	}
	else{
		document.getElementById('editor_stom').value = document.getElementById('editor_stom').value + '#' + _i_uploaded;
	}

	return window.open(_editor_url+'/'+name+'.html','_editor_tb','staus=no, width=400, height=435,scrollbars=no,toolbar=no,menubar=no');

} // end func


// zoom
function zoom(id){
	if(id) gmFrame.document.body.style.zoom = id + '%';
} // end func

function zoom_click(){
	if(os == 1) return false;
	var zoom_per = ['300','250','200','150','100','75','50','25'];
	var body = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="90" bgcolor="CCCCCC" style="cursor:hand;" onMouseLeave="Layerhide(\'zoomin\');">';
		body += '<tr><td height=1></td></tr>';
		body += '<tr>';
		body += '  <td>';
		body += '  <table align="center" border="0" cellpadding="0" cellspacing="0" width="98%" bgcolor="#FFFFFF">';

		body += '<tr height="25" bgcolor="#EFEFEF">';
		body += '   <td>';
		body += '       &nbsp;&nbsp;<b>' + editor_lang[78];
		body += '   </td>';
		body += '   <td align="right">';
		body += '       <img src="' + _editor_url + '/img/close.gif" border=0 align="absmiddle" oncliCk="divhide(\'zoomin\');">&nbsp;&nbsp;';
		body += '   </td>';
		body += '</tr>';
		body += '<tr><td bgcolor="#EFEFEF" height=1 colspan="2"></td></tr>';

		for(var i=0; i<zoom_per.length; i++){
			body += '<tr onmouseover="this.style.backgroundColor=\'#B6BCD2\';" style="BACKGROUND-COLOR: WHITE" onmouseout="this.style.backgroundColor=\'WHITE\';">';
			body += '   <td height="20" align="center" colspan="2">';
			body += '       &nbsp;&nbsp;<a style="cursor:hand;" onclick="zoom(' + zoom_per[i] + ')">' + zoom_per[i] + '%</a>';
			body += '   </td>';
			body += '</tr>';
			body += '<tr><td bgcolor="#EFEFEF" height=1 colspan="2"></td></tr>';
		} // end for

		body += '	<tr><td bgcolor="#CCCCCC" height=1 colspan="2"></td></tr>';
		body += '	</table>';
		body += '   </td>';
		body += '</tr>';
		body += '</table>';

	document.getElementById('zoomin').innerHTML = body;

} // end func


// modal
function createHTML(val,key){
	var width,height,filename;

	switch(key){
		case 1: // Table
			width = 352; height = 457; filename = 'table.html';
		break;

		case 2: // charac
			width = 304; height = 375; filename = 'characteristic.html';
		break;

		case 3: // icon
			width = 232; height = 248; filename = 'emotions.html';
		break;

		case 4: // Fontname
			width = 250; height = 302; filename = 'fontname.html';
		break;

		case 5: // color
			width = 260; height = 278; filename = 'color.html';
		break;

		case 6: // BG Color
			width = 260; height = 278; filename = 'color.html';
		break;

		case 7: // Font Size
			width = 350; height = 249; filename = 'fontsize.html';
		break;

		case 8: // Link
			width = 360; height = 173; filename = 'hyperLink.html';
		break;
	}

	if(!os){
		if((key == 5) || (key == 6)){
			val = (key == 6) ? 'backcolor' : 'forecolor';
		}
	}
	document.getElementById('editor_stom').value = document.getElementById('editor_stom').value + '#' + val;
	obj = window.open(_editor_url+'/'+filename,'_editor_tb','staus=no, width='+width+', height='+height+',scrollbars=no,toolbar=no,menubar=no');
}


// Contents
function Edit_Modify(_contentName,_contentValue){
	return eval("document." + _contentName + "." + _contentValue + ".value");
}

// Submit's
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(/<style>(.*?)<(\/?)style>/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);
	}

	// Net
	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";
