var Myselect = null;

function temp()
{
}

function SetFont(ch)
{
	if (ch.options[ch.selectedIndex].value != '')
		HTMLEDITOR.document.execCommand("FontName", null, ch.options[ch.selectedIndex].value);
	ch.selectedIndex = 0;
	//document.all.HTMLEDITOR.focus();
}
function SetFontSize(ch)
{
	if (ch.options[ch.selectedIndex].value != '')
		HTMLEDITOR.document.execCommand("FontSize", null, ch.options[ch.selectedIndex].value);
		ch.selectedIndex = 0;
	//document.all.HTMLEDITOR.focus();
}
function GetSource()
{

	var backcolor = HTMLEDITOR.document.body.style.backgroundColor;
	var obj = HTMLEDITOR.document.all["backcolor"];
	var HTMLSOURCE = '';

	if (HTMLEDITOR.document.body.innerHTML == '')
	{
		alert('³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä');
		HTMLEDITOR.focus();
		return;
	}


	if (backcolor.length == 0 || obj != null)
		HTMLSOURCE = "<STYLE> {MARGIN-TOP: 1px; MARGIN-BOTTOM: 1px}</STYLE>\n" + HTMLEDITOR.document.body.innerHTML;
	else
		HTMLSOURCE = "<div id='backcolor' style='background-color:" + backcolor + "'><STYLE> {MARGIN-TOP: 1px; MARGIN-BOTTOM: 1px}</STYLE>\n" + HTMLEDITOR.document.body.innerHTML + "</div>";
	/*
	if (backcolor.length == 0 || obj != null)
	HTMLSOURCE = HTMLEDITOR.document.body.innerHTML;
	else
	HTMLSOURCE = "<div id='backcolor' style='background-color:" + backcolor + "'>" + HTMLEDITOR.document.body.innerHTML + "</div>";
	*/

	return HTMLSOURCE;
}

function mouse_on(obj)
{
	obj.borderColorDark = "white";
	obj.borderColorLight = "black";
	obj.style.cursor = "hand";
	//alert(obj.id);
}

function mouse_out(obj)
{
	obj.borderColorDark = "#F9F9F9";
	obj.borderColorLight = "#F9F9F9";
	//alert(obj.id);
}
function mouse_click(obj)
{
	Myselect = HTMLEDITOR.document.selection.createRange();

	obj.borderColorDark = "black";
	obj.borderColorLight = "white";
}

function menu_click(obj)
{
	HTMLEDITOR.focus();
	if (Myselect!=null)Myselect.select();

	if (obj.id == "btnBold")
	{
	  HTMLEDITOR.document.execCommand("Bold",true);

	}
	else if (obj.id == "btnItalic")
	{
	  HTMLEDITOR.document.execCommand("Italic");
	}
	else if (obj.id == "btnUnderline")
	{
	  HTMLEDITOR.document.execCommand("Underline");
	}
	else if (obj.id == "btnColor")
	{
	  Preview_Color('1');
	}
	else if (obj.id == "btnBgcolor")
	{
	  Preview_Color('2');
	}
	else if (obj.id == "id_backcolor")	// X
	{
	  Preview_Color('3');
	}
	else if (obj.id == "id_emoticon")	// X
	{
	  Preview_Emoticon();
	}
	else if (obj.id == "btnLeft")
	{
	  HTMLEDITOR.document.execCommand("JustifyLeft");
	}
	else if (obj.id == "btnCenter")
	{
	  HTMLEDITOR.document.execCommand("JustifyCenter");
	}
	else if (obj.id == "btnRight")
	{
	  HTMLEDITOR.document.execCommand("JustifyRight");
	}
	else if (obj.id == "id_imgup") // X
	{
	  Preview_Img();
	}
	else if (obj.id == "btnLink")
	{
	  Set_link();
	}
	
}

function Preview_Color(type)
{
    window.open(gamePath + '/_html/color_popup.html?type=' + type, 'Editcolorpicker', 'width=410,height=290,status=yes');
}

function Preview_Emoticon()
{
    window.open(Domain_WWW + gamePath + '/popup/emoticon.asp', 'Emoticon', 'width=400,height=310,resizable=no,menubar=no');
}

function Set_fontcolor(color)
{
    HTMLEDITOR.document.execCommand("forecolor", null, color);
}

function Set_bgcolor(color)
{
	HTMLEDITOR.document.execCommand( "BackColor", null, color );
}

function Set_backcolor(color)
{
	var obj = HTMLEDITOR.document.all["backcolor"];
	if (obj != null)
		HTMLEDITOR.document.all["backcolor"].style.backgroundColor = color;
	else
		HTMLEDITOR.document.body.style.backgroundColor = color;
}

function Set_link()
{
	window.open(gamePath + '/_html/linkurl.html', 'LinkURL', 'width=360,height=280,resizable=no,menubar=no');
	//var mylink = prompt("¸µÅ©¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.","http://");
	//HTMLEDITOR.document.execCommand("CreateLink", null, mylink);
	//Myselect = HTMLEDITOR.document.selection.createRange();
	//if (Myselect!=null)
	//{
	//    Myselect.pasteHTML("<a href=\"" + mylink + "\" target=\"_blank\">" + Myselect.text + "</a> ");
	//}
}
function imginsert(url,type)
{
	try
	{
		var sText = HTMLEDITOR.document.selection.createRange();
		if (sText.parentElement().all.HTMLEDITOR == null)
		{
			if (sText.parentElement().outerHTML.indexOf('<BODY') > 0)
			{
				sText.parentElement().innerHTML = "<P><img src='" + url + "' align='" + type + "'>" + sText.parentElement().innerHTML + "</P>"
			}
			else
			{
				sText.parentElement().innerHTML = "<img src='" + url + "' align='" + type + "'>" + sText.parentElement().innerHTML;
			}
		}
		else
		{
			HTMLEDITOR.document.body.innerHTML =  "<img src='" + url + "' align='" + type + "'>" + HTMLEDITOR.document.body.innerHTML
		}
	}
	catch(e)
	{
		alert('¾ÆÀÌÄÜ »ðÀÔÀ» ÇÒ ¼ö ¾ø½À´Ï´Ù')
	}
}
function imginsert2(url)
{
	try
	{
		var sText = HTMLEDITOR.document.selection.createRange();
		if (sText.parentElement().all.HTMLEDITOR == null)
		{
			sText.pasteHTML("<img src='" + url +"'>");
			sText.select();
			//HTMLEDITOR.document.execCommand("InsertImage", null, url);
		}
		else
		{
			HTMLEDITOR.document.body.innerHTML =  "<img src='" + url + "'>" + HTMLEDITOR.document.body.innerHTML
			HTMLEDITOR.focus();
		}
	}
	catch(e)
	{
		alert('¾ÆÀÌÄÜ »ðÀÔÀ» ÇÒ ¼ö ¾ø½À´Ï´Ù')
	}
}


