var editor;
var bHtmlMode = true;
var wAttachFileCnt = 0;

//HTML DESIGN_ON
function wInitEditor()
{
	setTimeout("wInitMsg()", 500);
	editor = this["iEditor"];
	editor.document.write("<style> body {font-size:9pt;padding:3px;margin:0 } p {margin:0} td {font-size:9pt} </style>");
	editor.document.designMode = "On";	
}

function wInitMsg()
{
	var f = document.__f;
	if(!f) return;
	try
	{
		
		editor.document.body.innerHTML = f.wTextContents.value;
	} 
	catch(error)
	{
		setTimeout("wInitMsg()", 500);
	}
}

function wExecuteCommand(vValue)
{
	if(!bHtmlMode) return;
	if(vValue != "")
	{
		if(editor.document.selection.type == "None")
		{
			editor.document.execCommand(vValue);
			editor.focus();
		}
		else
		{
			editor.document.selection.createRange().execCommand(vValue);
		}
	}
}

function wExecuteCommandV(sCommand, bUserInterface, vValue)
{
	if(!bHtmlMode) return;
	if(vValue != "")
	{
		if(editor.document.selection.type == "None")
		{
			editor.document.execCommand(sCommand, bUserInterface, vValue);
			editor.focus();
		}
		else
		{
			editor.document.selection.createRange().execCommand(sCommand, bUserInterface, vValue);
		}
	}
}

function wWriteModeChange(sel)
{
	var f = sel.form;
	if(sel.selectedIndex == 0 ) // 
	{
		wTextPanel.style.display = "none";
		wHtmlPanel.style.display = "";
		bHtmlMode = true;
		editor.document.body.innerHTML = f.wTextContents.value;		
	}
	else
	{
		wHtmlPanel.style.display = "none";
		wTextPanel.style.display = "";
		bHtmlMode = false;
		f.wTextContents.value = editor.document.body.innerHTML;		
	}
}

function wFontStyleChange(sel)
{
	var f = sel.form;
	wExecuteCommandV("FontName", false, sel.options[sel.selectedIndex].innerText);
}

function wFontSizeChange(sel)
{
	if(!bHtmlMode) return;
	if (sel.selectedIndex == 0) return;
	wExecuteCommandV("FontSize", false, sel.options[sel.selectedIndex].innerText );
}

function wBtnBoldClick()
{
	wExecuteCommand("BOLD");
}

function wBtnItalicClick()
{
	wExecuteCommand("ITALIC");
}

function wBtnUnderLineClick()
{
	wExecuteCommand("UNDERLINE");
}

function wBtnForeColorClick()
{
	window.showModelessDialog("/PopWColor.aspx", window , "dialogHeight:205px;dialogWidth:135px;help:no;scroll:no;status:no;");
}

function wBtnForeColorClickResult(color)
{
	wExecuteCommandV("ForeColor", false, color);
}

function wBtnBackColorClick()
{
	window.showModelessDialog("/PopWColor.aspx?op=BG", window , "dialogHeight:205px;dialogWidth:135px;help:no;scroll:no;status:no;");	
}

function wBtnBackColorClickResult(color)
{
	wExecuteCommandV("BackColor", false, color);
}

function wBtnAlignLeftClick()
{
	wExecuteCommand("JustifyLeft");
}

function wBtnAlignCenterClick()
{
	wExecuteCommand("JustifyCenter");
}

function wBtnAlignRightClick()
{
	wExecuteCommand("JustifyRight");
}

function wBtnAddTableClick()
{
	if(!bHtmlMode) return;
	var rtn =	showModelessDialog("/PopWtable.aspx", this ,"help:no;scroll:no;status:no;dialogWidth:355px;dialogHeight:280px");
}

function wAddTable(obj)
{
	var div = document.createElement("div");
	
	var tbl = document.createElement("table");
	tbl.cols = obj.__col;
	tbl.border = obj.__border;
	tbl.width = obj.__w + "%";
	var tbody = document.createElement("tbody");

	for(k = 0; k < obj.__row; k++)
	{
		tr = document.createElement("tr");
		for(i = 0; i < obj.__col; i++)
		{
			td = document.createElement("td");
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
	}
	tbl.appendChild(tbody);
	editor.document.body.innerHTML += tbl.outerHTML;
	
}

function wBtnAddImageClick()
{
	if(!bHtmlMode) return;
	OpenPopWindow("/PopWimg.aspx", "_PopWimg", 340, 250);
}

function wAddImage(vValue)
{
	editor.focus();
	wExecuteCommandV("InsertImage", false, vValue);
	editor.document.body.innerHTML += "<br>";
	editor.focus();
}

function wBtnAddFileClick()
{
	if(!bHtmlMode) return;
	OpenPopWindow("/PopWfile.aspx", "_PopWfile", 340, 250);
}

function wAddFile(vValue, zValue)
{
	var str = "<br>÷  : <a href='" + vValue + "'><img src='http://image.solon.co.kr/img/buw_f.gif' border='0' alt='ٿε' align=absmiddle>" + zValue;
	var div = editor.document.createElement("div");
	div.id="solon_attach";
	div.align="right";
	div.innerHTML = str;	
	editor.document.body.appendChild(div);
	wAttachFileCnt++;
}

function wBtnHyperLinkClick()
{
	wExecuteCommand("CreateLink");
}

function wBtnOLClick()
{
	wExecuteCommand("InsertOrderedList");
}

function wBtnULClick()
{
	wExecuteCommand("InsertUnorderedList");
}

function wBtnOutdentClick()
{
	wExecuteCommand("Outdent");
}

function wBtnIndentClick()
{
	wExecuteCommand("Indent");
}

function wSetContents(f)
{
	if(f.wWriteMode.selectedIndex == 0)
	{
		f.wTextContents.value = editor.document.body.innerHTML;
	}
}

function wPreview(f)
{
	if(f == null)
	{
		if(document.__f) f = document.__f;
	}
	if(f.wTextContents)
	{
		wSetContents(f);
		if(isEmpty(f.wTextContents)) return;
	}
	var rtn =	showModelessDialog("/PopPreView.aspx", f ,"status:true;center:yes;resizable;yes;dialogWidth:650px;dialogHeight:600px;dialogTop;100px");
}

function verify()
{
	if (xmlDoc.readyState != 4)
	{
		return false;
	}
}

function wValidSubject(input)
{
	var xStr = new Array("","","","00%","50%","~","","","","","","","","","","#","@","*","","ٺ","","","޵","ū","^&amp;^","","","ٻ","","","","","","","","","޻","","","","㺸","","","","","","no","nomo","mo","","ȭ","ߵ","http","wo.to","ce.ro",".com","co.kr","ŹŹŹ","","","","߼","","","","","","","","","","","","","","Ϲ","Ծ","","","","","","","","","","ڽ","ڽ","ģ","","","","","","","ں","ĸ","ó","Ĺ","ó","","","","","","","","Ų","","","","ֵ","ִ","","밡","뱸","ù","","","","","Ѱ","h","س","","","","");

	var bExist = false;
	var alert_str = "";

	var src = input.value;
	src = src.replace(/ /gi, "");
	src = src.replace(/_/gi, "");
	src = src.replace(/-/gi, "");
	for(i = 0; i < xStr.length; i++)
	{
		if(src.indexOf(xStr[i]) != -1)
		{
			alert_str = alert_str + "\n" + xStr[i];
			bExist = true;
		}
	}
	
	if(bExist) 
	{
		alert(" ܾ ԵǾ ֽϴ\n----------------------------------" + alert_str + "\n----------------------------------");
		input.select();
		input.focus();
	}
	return (!bExist);
}