var editwin = null;


function Help(daLink) {
var helpWnd=window.open(daLink,"help","width=400,height=500,scrollbars=yes,dependent=yes");
}


function UtilBeginScript()
{
return String.fromCharCode(60, 115, 99, 114, 105, 112, 116, 62);
}

function UtilEndScript()
{
return String.fromCharCode(60, 47, 115, 99, 114, 105, 112, 116, 62);
}

function IDGenerator(nextID)
{
this.nextID = nextID;
this.GenerateID = IDGeneratorGenerateID;
}

function IDGeneratorGenerateID()
{
return this.nextID++;
}

var BUTTON_IMAGE_PREFIX = "buttonImage";
var BUTTON_DIV_PREFIX = "buttonDiv";
var BUTTON_PAD1_PREFIX = "buttonPad1";
var BUTTON_PAD2_PREFIX = "buttonPad2";
var buttonMap = new Object();

function Button
(
idGenerator,
caption,
action,
image
)
{
this.idGenerator = idGenerator;
this.caption = caption;
this.action = action;
this.image = image;
this.enabled = true;
this.Instantiate = ButtonInstantiate;
this.Enable = ButtonEnable;
}

function ButtonInstantiate()
{
this.id = this.idGenerator.GenerateID();
buttonMap[this.id] = this;
var html = "";
html += '<div id="';
html += BUTTON_DIV_PREFIX;
html += this.id;
html += '" class="ButtonNormal"';
html += ' onselectstart="ButtonOnSelectStart()"';
html += ' ondragstart="ButtonOnDragStart()"';
html += ' onmousedown="ButtonOnMouseDown(this)"';
html += ' onmouseup="ButtonOnMouseUp(this)"';
html += ' onmouseout="ButtonOnMouseOut(this)"';
html += ' onmouseover="ButtonOnMouseOver(this)"';
html += ' onclick="ButtonOnClick(this)"';
html += ' ondblclick="ButtonOnDblClick(this)"';
html += '>';
html += '<table cellpadding=0 cellspacing=0 border=0><tr><td><img id="';
html += BUTTON_PAD1_PREFIX;
html += this.id;
html += '" width=2 height=2></td><td></td><td></td></tr><tr><td></td><td>';
html += '<img id="';
html += BUTTON_IMAGE_PREFIX;
html += this.id;
html += '" src="';
html += this.image;
html += '" title="';
html += this.caption;
html += '" class="Image"';
html += '>';
html += '</td><td></td></tr><tr><td></td><td></td><td><img id="';
html += BUTTON_PAD2_PREFIX;
html += this.id;
html += '" width=2 height=2></td></tr></table>';
html += '</div>';
document.write(html);
}

function ButtonEnable(enabled)
{
this.enabled = enabled;
if (this.enabled)
{
document.all[BUTTON_DIV_PREFIX + this.id].className = "ButtonNormal";
}
else
{
document.all[BUTTON_DIV_PREFIX + this.id].className = "ButtonDisabled";
}
}

function ButtonOnSelectStart()
{
window.event.returnValue = false;
}

function ButtonOnDragStart()
{
window.event.returnValue = false;
}

function ButtonOnMouseDown(element)
{
if (event.button == 1)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonPushButton(id);
}
}
}

function ButtonOnMouseUp(element)
{
if (event.button == 1)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
}
}
}

function ButtonOnMouseOut(element)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
}
}

function ButtonOnMouseOver(element)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
ButtonReleaseButton(id);
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonMouseOver";
}
}

function ButtonOnClick(element)
{
var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
var button = buttonMap[id];
if (button.enabled)
{
eval(button.action);
}
}

function ButtonOnDblClick(element)
{
ButtonOnClick(element);
}

function ButtonPushButton(id)
{
document.all[BUTTON_PAD1_PREFIX + id].width = 3;
document.all[BUTTON_PAD1_PREFIX + id].height = 3;
document.all[BUTTON_PAD2_PREFIX + id].width = 1;
document.all[BUTTON_PAD2_PREFIX + id].height = 1;
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonPressed";
}

function ButtonReleaseButton(id)
{
document.all[BUTTON_PAD1_PREFIX + id].width = 2;
document.all[BUTTON_PAD1_PREFIX + id].height = 2;
document.all[BUTTON_PAD2_PREFIX + id].width = 2;
document.all[BUTTON_PAD2_PREFIX + id].height = 2;
document.all[BUTTON_DIV_PREFIX + id].className = "ButtonNormal";
}

var EDITOR_COMPOSITION_PREFIX = "editorComposition";
var EDITOR_PARAGRAPH_PREFIX = "editorParagraph";
var EDITOR_LIST_AND_INDENT_PREFIX = "editorListAndIndent";
var EDITOR_TOP_TOOLBAR_PREFIX = "editorTopToolbar";
var EDITOR_BOTTOM_TOOLBAR_PREFIX = "editorBottomToolbar";
var EDITOR_SMILEY_BUTTON_PREFIX = "editorSmileyButton";
var EDITOR_IMAGE_CHOOSER_PREFIX = "editorImageChooser";
var editorMap = new Array();

var editorIDGenerator = null;

function Editor(idGenerator)
{
this.idGenerator = idGenerator;
this.textMode = false;
this.brief = false;
this.instantiated = false;
this.Instantiate = EditorInstantiate;
this.GetText = EditorGetText;
this.SetText = EditorSetText;
this.GetHTML = EditorGetHTML;
this.SetHTML = EditorSetHTML;
this.GetBrief = EditorGetBrief;
this.SetBrief = EditorSetBrief;
}


function EditorInstantiate(text_height,format_bar,path_img)
{
if (this.instantiated) {
return;
}
this.id = this.idGenerator.GenerateID();
editorMap[this.id] = this;
editorIDGenerator = this.idGenerator;

var html = "";
var str_html = "";
var str_htmledit = "";

	str_htmledit += "<tr>";
	str_htmledit += "<td>";
	str_htmledit += "<iframe style=\"border:0px solid\"  id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"100%\" height=\"" + text_height + "\">";
	str_htmledit += "</iframe>";
	str_htmledit += "</td>";
	str_htmledit += "</tr>";


if(format_bar!=0){
	html += "<tr>";
	html += "<td id=\"" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";
	html += "<table cellpaddin=\"0\" cellspacing=\"0\" border=\"0\">";
	html += "<tr>";
	html += "<td>";
	html += "<div class=\"Space\"></div>";
	html += "</td>";
	html += "<td>";
	html += "<div class=\"Swatch\"></div>";
	html += "</td>";

	/*html += "<td>";
	html += "<select class=\"List\" onchange=\"EditorOnCharset(" + this.id + ", this)\">";
	html += "<option class=\"Heading\" value=\"iso-8859-1\">B&#7843;ng m&#227;</option>";
	html += "<option value=\"Unicode\">16bit Unicode</option>";
	html += "<option value=\"iso-8859-1\">ISO-8859-1</option>";
	html += "<option value=\"UTF-8\">UTF-8</option>";
	html += "<option value=\"windows-1258\">cp1258-TCVN</option>";
	html += "</select>";
	html += "</td>";*/

	html += "<td>";
	html += "&nbsp; <span id=\"" + EDITOR_PARAGRAPH_PREFIX + this.id + "\" style=\"display:" + (this.brief ? "none" : "inline") + "\">";
	html += "<select class=\"List\" onchange=\"EditorOnParagraph(" + this.id + ", this)\">";
	html += "<option class=\"Heading\">&#272;&#7847;u &#273;&#7873;</option>";
	html += "<option value=\"Normal\">B&#236;nh th&#432;&#7901;ng</option>";
	html += "<option value=\"Heading 1\">&#272;&#7847;u &#273;&#7873; 1 &lt;H1&gt;</option>";
	html += "<option value=\"Heading 2\">&#272;&#7847;u &#273;&#7873; 2 &lt;H2&gt;</option>";
	html += "<option value=\"Heading 3\">&#272;&#7847;u &#273;&#7873; 3 &lt;H3&gt;</option>";
	html += "<option value=\"Heading 4\">&#272;&#7847;u &#273;&#7873; 4 &lt;H4&gt;</option>";
	html += "<option value=\"Heading 5\">&#272;&#7847;u &#273;&#7873; 5 &lt;H5&gt;</option>";
	html += "<option value=\"Heading 6\">&#272;&#7847;u &#273;&#7873; 6 &lt;H6&gt;</option>";
	html += "<option value=\"Address\">&#272;&#7883;a ch&#7881; &lt;ADDR&gt;</option>";
	html += "<option value=\"Formatted\">Gi&#7919; &#273;&#7883;nh d&#7841;ng &lt;PRE&gt;</option>";
	html += "</select>";
	html += "</span>";
	html += "</td>";
	html += "<td>";
	html += "&nbsp; <select class=\"List\" onchange=\"EditorOnFont(" + this.id + ", this)\">";
	html += "<option class=\"Heading\">Ki&#7875;u ch&#7919;</option>";
	html += "<option value=\"Arial\">Arial</option>";
	html += "<option value=\"Arial Black\">Arial Black</option>";
	html += "<option value=\"Arial Narrow\">Arial Narrow</option>";
	html += "<option value=\"Comic Sans MS\">Comic Sans MS</option>";
	html += "<option value=\"Courier New\">Courier New</option>";
	html += "<option value=\"System\">System</option>";
	html += "<option value=\"Times New Roman\">Times New Roman</option>";
	html += "<option value=\"Tahoma\">Tahoma</option>";
	html += "<option value=\"Verdana\">Verdana</option>";
	html += "<option value=\"Wingdings\">Wingdings</option>";
	html += "</select>";
	html += "</td>";
	html += "<td>";
	html += "<select class=\"List\" onchange=\"EditorOnSize(" + this.id + ", this)\">";
	html += "<option class=\"Heading\">C&#7905; ch&#7919;</option>";
	html += "<option value=\"1\">1</option>";
	html += "<option value=\"2\">2</option>";
	html += "<option value=\"3\">3</option>";
	html += "<option value=\"4\">4</option>";
	html += "<option value=\"5\">5</option>";
	html += "<option value=\"6\">6</option>";
	html += "<option value=\"7\">7</option>";
	html += "</select>";
	html += "</td>";
	//html += "<td width=\"170\">&nbsp;";
	//html += "</td>";
	//html += "<td><a href='http://www.yahoo.com' target='_blank'><b><font color='red'>Yahoo</font></b></a>";
	//html += "</td>";

	//html += "<td>";
	//html += "</td>";
	
	//html += "<td>";
	//html += "<div class=\"Divider\"></div>";
	//html += "</td>";
	//html += "<td class=\"Text\" NOWRAP>";
	//html += "<input type=\"checkbox\" onclick=\"EditorOnViewHTMLSource(" + this.id + ", this.checked)\">";
	//html += "Xem HTML";
	//html += "</td>";
	html += "</tr>";
	html += "</table>";
	html += "</td>";
	html += "</tr>";
	
	html += "<tr>";
	html += "<td id=\"" + EDITOR_BOTTOM_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";
	html += "<table cellpaddin=\"0\" cellspacing=\"0\" border=\"0\">";
	html += "<tr>";
	html += "<td>";
	html += "<div class=\"Space\"></div>";
	html += "</td>";
	html += "<td>";
	html += "<div class=\"Swatch\"></div>";
	html += "</td>";


	//html += "<td>";
	//html += "<div class=\"Divider\"></div>";
	//html += "</td>";
	
	html += "<td>";
	html += UtilBeginScript();
	html += "var cutButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"C&#7855;t\",";
	html += "\"EditorOnCut(" + this.id + ")\",";
	
	html += "\"" + path_img +"/cut.gif\"";
	//html += "\"" + path_img +"/cut.gif\"";
	html += ");";
	html += "cutButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var copyButton = new Button(";
	html += "editorIDGenerator,";
	html += "\" Copy\",";
	html += "\"EditorOnCopy(" + this.id + ")\",";
	html += "\"" + path_img +"/copy.gif\"";
	html += ");";
	html += "copyButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var pasteButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"D&#225;n\",";
	html += "\"EditorOnPaste(" + this.id + ")\",";
	html += "\"" + path_img +"/paste.gif\"";
	html += ");";
	html += "pasteButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
/*
	html += "<td>";
	html += UtilBeginScript();
	html += "var undoButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Undo\",";
	html += "\"EditorOnUndo(" + this.id + ")\",";
	html += "\"" + path_img +"/undo.gif\"";
	html += ");";
	html += "undoButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var redoButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Redo\",";
	html += "\"EditorOnRedo(" + this.id + ")\",";
	html += "\"" + path_img +"/redo.gif\"";
	html += ");";
	html += "redoButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
*/
	html += "<td>";
	html += "<div class=\"Divider\"></div>";
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var boldButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Ch&#7919; &#273;&#7853;m\",";
	html += "\"EditorOnBold(" + this.id + ")\",";
	html += "\"" + path_img +"/bold.gif\"";
	html += ");";
	html += "boldButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var italicButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Ch&#7919; nghi&#234;ng\",";
	html += "\"EditorOnItalic(" + this.id + ")\",";
	html += "\"" + path_img +"/italic.gif\"";
	html += ");";
	html += "italicButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var underlineButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"G&#7841;ch ch&#226;n\",";
	html += "\"EditorOnUnderline(" + this.id + ")\",";
	html += "\"" + path_img +"/uline.gif\"";
	html += ");";
	html += "underlineButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += "<div class=\"Divider\"></div>";
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var foregroundColorButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"M&#7847;u ch&#7919;\",";
	html += "\"EditorOnForegroundColor(" + this.id + ",'"+path_img+"')\",";
	html += "\"" + path_img +"/tpaint.gif\"";
	html += ");";
	html += "foregroundColorButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var backgroundColorButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"M&#7847;u n&#7873;n\",";
	html += "\"EditorOnBackgroundColor(" + this.id + ",'"+ path_img+ "')\",";
	html += "\"" + path_img +"/parea.gif\"";
	html += ");";
	html += "backgroundColorButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += "<div class=\"Divider\"></div>";
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var alignLeftButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"L&#7873; tr&#225;i\",";
	html += "\"EditorOnAlignLeft(" + this.id + ")\",";
	html += "\"" + path_img +"/aleft.gif\"";
	html += ");";
	html += "alignLeftButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var centerButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Gi&#7919;a h&#224;ng\",";
	html += "\"EditorOnCenter(" + this.id + ")\",";
	html += "\"" + path_img +"/center.gif\"";
	html += ");";
	html += "centerButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var alignRightButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"L&#7873; ph&#7843;i\",";
	html += "\"EditorOnAlignRight(" + this.id + ")\",";
	html += "\"" + path_img +"/aright.gif\"";
	html += ");";
	html += "alignRightButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += "<div class=\"Divider\"></div>";
	html += "</td>";
	html += "<td id=\"" + EDITOR_LIST_AND_INDENT_PREFIX + this.id + "\" style=\"display:" + (this.brief ? "none" : "inline") + "\">";
	html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	html += "<tr>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var numberedListButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Li&#7879;t k&#234; s&#7889;\",";
	html += "\"EditorOnNumberedList(" + this.id + ")\",";
	html += "\"" + path_img +"/nlist.gif\"";
	html += ");";
	html += "numberedListButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var bullettedListButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Li&#7879;t k&#234; ch&#7845;m &#273;&#7847;u h&#224;ng\",";
	html += "\"EditorOnBullettedList(" + this.id + ")\",";
	html += "\"" + path_img +"/blist.gif\"";
	html += ");";
	html += "bullettedListButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	/*
	html += "<td>";
	html += UtilBeginScript();
	html += "var decreaseIndentButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"Thu h&#7865;p l&#7873;\",";
	html += "\"EditorOnDecreaseIndent(" + this.id + ")\",";
	html += "\"" + path_img +"/ileft.gif\"";
	html += ");";
	html += "decreaseIndentButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	html += "<td>";
	html += UtilBeginScript();
	html += "var increaseIndentButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"N&#7899;i r&#7897;ng l&#7873;\",";
	html += "\"EditorOnIncreaseIndent(" + this.id + ")\",";
	html += "\"" + path_img +"/iright.gif\"";
	html += ");";
	html += "increaseIndentButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	*/
	//html += "<td>";
	//html += "<div class=\"Divider\"></div>";
	//html += "</td>";
	html += "</tr>";
	html += "</table>";
	html += "</td>";
	/*
	html += "<td>";
	html += UtilBeginScript();
	html += "var createHyperlinkButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"T&#7841;o li&#234;n k&#7871;t\",";
	html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
	html += "\"" + path_img +"/wlink.gif\"";
	html += ");";
	html += "createHyperlinkButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";
	*/
	/*html += "<td>";
	html += UtilBeginScript();
	html += "var createImgButton = new Button(";
	html += "editorIDGenerator,";
	html += "\"G&#7855;n hình\",";
	html += "\"EditorOnCreateImg(" + this.id + ")\",";
	html += "\"" + path_img +"/img.gif\"";
	html += ");";
	html += "createImgButton.Instantiate();";
	html += UtilEndScript();
	html += "</td>";*/
	
	/*html += "<td>";
	html += "<div class=\"Divider\"></div>";
	html += "</td>";*/
	html += "</tr>";
	html += "</table>";
	html += "</td>";
	html += "</tr>";
}
	str_html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
	switch(format_bar){
		case 0 :		
			str_html += str_htmledit; 			
			break;
		case 1 :
			str_html += html+ str_htmledit ; 				
			break;
		case 2 :
			str_html += str_htmledit + html; 		
			break;
	}
	str_html += "</table>";

document.write(str_html);
html = '';
html += '<body style="font:10pt verdana">';
html += '</body>';
var ifrm = eval(EDITOR_COMPOSITION_PREFIX + this.id);
ifrm.document.open();
ifrm.document.write(html);
ifrm.document.close();
ifrm.document.designMode = "on";
//ifrm.document.onclick = new Function("EditorOnClick(" + this.id + ")");
editwin = ifrm;

editorIDGenerator = null;
this.instantiated = true;
}
function  EditorGetText()
{
	return editwin.document.body.innerText;
}

function  EditorSetText(text)
{
text = text.replace(/\n/g, "<br>");
editwin.document.body.innerHTML = text;
}

function  EditorGetHTML()
{
if (this.textMode) {
return editwin.document.body.innerText;
}
EditorCleanHTML(this.id);
EditorCleanHTML(this.id);
return editwin.document.body.innerHTML;
}

function  EditorSetHTML(html)
{
if (this.textMode) {
editwin.document.body.innerText = html;
}
else {
editwin.document.body.innerHTML = html;
}
}

function EditorGetBrief()
{
return this.brief;
}

function EditorSetBrief(brief)
{
this.brief = brief;
var display = this.brief ? "none" : "inline";
if (this.instantiated) {
eval(EDITOR_PARAGRAPH_PREFIX + this.id).style.display = display;
eval(EDITOR_LIST_AND_INDENT_PREFIX + this.id).style.display = display;
}
}

function EditorOnCut(id)
{
EditorFormat(id, "cut");
}

function EditorOnCopy(id)
{
EditorFormat(id, "copy");
}

function EditorOnUndo(id)
{
EditorFormat(id, "undo");
}

function EditorOnRedo(id)
{
EditorFormat(id, "redo");
}

function EditorOnSave(id)
{
EditorFormat(id, "SaveAs", "vietunidoc.html");
}

/*function EditorOnOpen(id)
{
//EditorFormat(id, "Open");
alert('Câ`n server-side scripting. Chu+a có thò+i gian... :-)');
editwin.focus();
}*/

/*function EditorOnOpenURL(id)
{
alert('Câ`n server-side scripting. Chu+a có thò+i gian... :-)');
editwin.focus();
}*/

function EditorOnPaste(id)
{
EditorFormat(id, "paste");
}

function EditorOnBold(id)
{
EditorFormat(id, "bold");
}

function EditorOnItalic(id)
{
EditorFormat(id, "italic");
}

function EditorOnUnderline(id)
{
EditorFormat(id, "underline");
}

function EditorOnForegroundColor(id,path_color)
{
if (!EditorValidateMode(id)) {
return;
}
var color = showModalDialog(path_color+"/ColorSelect.htm", "", "font-family:Verdana;font-size:12;dialogWidth:29em;dialogHeight:31em");
if (color) {
EditorFormat(id, "forecolor", color);
}
else {

editwin.focus();
}
}

function EditorOnBackgroundColor(id,path_color)
{
if (!EditorValidateMode(id)) {
return;
}
var color = showModalDialog(path_color+"/ColorSelect.htm", "", "font-family:Verdana;font-size:12;dialogWidth:	29em;dialogHeight:31em");
if (color) {
var doc = editwin;
if (doc.document.selection.type == "None") {
  editwin.document.body.style.backgroundColor = color;
}
EditorFormat(id, "backcolor", color);
}
else {
editwin.focus();
}
}

function EditorOnAlignLeft(id)
{
EditorFormat(id, "justifyleft");
}

function EditorOnCenter(id)
{
EditorFormat(id, "justifycenter");
}

function EditorOnAlignRight(id)
{
EditorFormat(id, "justifyright");
}

function EditorOnNumberedList(id)
{
EditorFormat(id, "insertOrderedList");
}

function EditorOnBullettedList(id)
{
EditorFormat(id, "insertUnorderedList");
}

function EditorOnDecreaseIndent(id)
{
EditorFormat(id, "outdent");
}

function EditorOnIncreaseIndent(id)
{
EditorFormat(id, "indent");
}

function EditorOnRTEHelp(id)
{
alert('coming soon...');
}

function EditorOnCreateHyperlink(id)
{
    if (!EditorValidateMode(id)) {
        return;
    }
    editwin.focus();
    EditorFormat(id, "CreateLink");
}

function EditorOnCreateImg(id)
{
    if (!EditorValidateMode(id)) {
        return;
    }
    editwin.focus();
    EditorFormat(id, "InsertImage");
}

function EditorOnInsert(id, select)
{
    if (!EditorValidateMode(id)) {
        return;
    }
    editwin.focus();
    EditorFormat(id, select[select.selectedIndex].value);
    select.selectedIndex = 0;
}

function EditorOnParagraph(id, select)
{
EditorFormat(id, "formatBlock", select[select.selectedIndex].value);
select.selectedIndex = 0;
}

function EditorOnFont(id, select)
{
EditorFormat(id, "fontname", select[select.selectedIndex].value);
select.selectedIndex = 0;
}

function EditorOnSize(id, select)
{
EditorFormat(id, "fontsize", select[select.selectedIndex].value);
select.selectedIndex = 0;
}

function EditorOnCharset(id, select)
{
editwin.document.charset = select[select.selectedIndex].value;
editwin.focus();
}

function EditorOnViewHTMLSource(id, textMode)
{
var editor = editorMap[id];
editor.textMode = textMode;
if (editor.textMode) {
EditorCleanHTML(id);
EditorCleanHTML(id);
editwin.document.body.innerText = editwin.document.body.innerHTML;
}
else {
editwin.document.body.innerHTML = editwin.document.body.innerText;
}
editwin.focus();
}

function EditorOnClick(id)
{
}

function EditorValidateMode(id)
{
var editor = editorMap[id];
if (!editor.textMode) {
return true;
}
alert("Ha~y ta('t o^ \"Xem Html-Code\" dde^? co' the^ du`ng thanh co^ng cu.");
editwin.focus();
return false;
}

function EditorFormat(id, what, opt)
{
if (!EditorValidateMode(id)) {
return;
}
if (opt == "removeFormat") {
what = opt;
opt = null;
}
if (opt == null) {
editwin.document.execCommand(what, true);
}
else {
editwin.document.execCommand(what, "", opt);
}
editwin.focus();
}

function EditorCleanHTML(id)
{
var fonts = editwin.document.body.all.tags("FONT");
for (var i = fonts.length - 1; i >= 0; i--) {
var font = fonts[i];
if (font.style.backgroundColor == "#ffffff") {
font.outerHTML = font.innerHTML;
}
}
}

function EditorGetElement(tagName, start)
{
while (start && start.tagName != tagName) {
start = start.parentElement;
}
return start;
}

function Switch() {
if (editor.GetText() != "" && editor.GetText() != editor.GetHTML()) {
conf = confirm("Chi? da^~n: Tác vu. này se~ làm mâ't hê't ddi.nh da.ng. Thu+.c hiê.n?");
if (!conf) return;
  }
  document.Compose.Body.value = editor.GetText();
document.Compose.action = document.Compose.action + "&SWITCH=1";
  document.Compose.submit();
}


function SetVals() {
document.Compose.Body.value = editor.GetHTML();
}


var remote=null;
function rs(n,u,w,h,x) {
  args="width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=0";
  remote=window.open(u,n,args);
  if (remote != null) {
if (remote.opener == null)
  remote.opener = self;
  }
  if (x == 1) { return remote; }
}


var sigAttMap = [false];

function OnFromAddrChange()
{
var i = document.Compose.FromAddr.selectedIndex;
if (i >= 0 && i < sigAttMap.length) {
document.all.SA.checked = sigAttMap[i];
}
}
