﻿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(str)
{
if (this.instantiated) {
return;
}
this.id = this.idGenerator.GenerateID();
editorMap[this.id] = this;
editorIDGenerator = this.idGenerator;
if (!str){str="";};
var html = "";
//html += "<table  bgcolor=red width=80% align=center cellpadding=\"0\" cellspacing=\"0\" border=\"5\" width=\"100%\">";
//html += "<tr>";
//html += "<td id=\"" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";

html += "<table bgcolor=gray align=center cellpaddin=\"0\" cellspacing=\"0\" border=\"1\">";
/*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ảng mã</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\">Chương mục</option>";
html += "<option value=\"Normal\">Bình thường</option>";
html += "<option value=\"Heading 1\">Đầu đề 1 &lt;H1&gt;</option>";
html += "<option value=\"Heading 2\">Đầu đề 2 &lt;H2&gt;</option>";
html += "<option value=\"Heading 3\">Đầu đề 3 &lt;H3&gt;</option>";
html += "<option value=\"Heading 4\">Đầu đề 4 &lt;H4&gt;</option>";
html += "<option value=\"Heading 5\">Đầu đề 5 &lt;H5&gt;</option>";
html += "<option value=\"Heading 6\">Đầu đề 6 &lt;H6&gt;</option>";
html += "<option value=\"Address\">Địa chỉ &lt;ADDR&gt;</option>";
html += "<option value=\"Formatted\">Giữ định dạng &lt;PRE&gt;</option>";
html += "</select>";
//html += "</span>";
html += "</td>";
html += "<td align=left>";
html += "&nbsp; <select class=\"List\" onchange=\"EditorOnInsert(" + this.id + ", this)\">";
html += "<option class=\"Heading\">Lắp ghép</option>";
html += "<option value=\"InsertHorizontalRule\">Horizontal Rule</option>";
html += "<option value=\"InsertIFrame\">iframe</option>";
html += "<option value=\"InsertMarquee\">Marquee</option>";
html += "<option value=\"InsertButton\">Button</option>";
html += "<option value=\"InsertInputButton\">Input Button</option>";
html += "<option value=\"InsertInputCheckbox\">Input Checkbox</option>";
html += "<option value=\"InsertInputHidden\">Hidden input</option>";
html += "<option value=\"InsertInputImage\">Input Image</option>";
html += "<option value=\"InsertInputPassword\">Input Password</option>";
html += "<option value=\"InsertInputRadio\">Input Radio</option>";
html += "<option value=\"InsertInputReset\">Input Reset</option>";
html += "<option value=\"InsertInputSubmit\">Input Submit</option>";
html += "<option value=\"InsertInputText\">Input Text</option>";
html += "<option value=\"InsertSelectDropdown\">Dropdown</option>";
html += "<option value=\"InsertSelectListbox\">Select List</option>";
html += "<option value=\"InsertTextArea\">TextArea</option>";
html += "</select>";
html += "</td>";
html += "</tr>"; */
html += "<tr><td>";
html += "<select class=\"List\" onchange=\"EditorOnSize(" + this.id + ", this)\">";
html += "<option class=\"Heading\">Cỡ chữ</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 align=center>";
html += " <select class=\"List\" onchange=\"EditorOnFont(" + this.id + ", this)\">";
html += "<option class=\"Heading\">Kiểu chữ</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 += "<div class=\"Divider\"></div>";
//html += "</td>";
html += "<td class=\"Text\" NOWRAP align=left>";
html += "<input type=\"checkbox\" onclick=\"EditorOnViewHTMLSource(" + this.id + ", this.checked)\">";
html += "Xem HTML-code";
html += "</td>";
//html += "<td width=100% align=right>";
// html += '<b><a href="http://www.yahoo.com" target=_blank><font color=#FF0000>Yahoo!</a> &nbsp;</font></b>';
//html += "</td>";
html += "</tr>";
html += "</table>";
html += "</td>";
html += "</tr>";

html += "<tr>";
html += "<td>";
//html += "<td id=\"" + EDITOR_BOTTOM_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";


html += "<table align=center cellpaddin=\"0\" cellspacing=\"0\" border=\"1\">";
html += "<tr>";
//html += "<td>";
//html += "<div class=\"Space\"></div>";
//html += "</td>";
//html += "<td>";
//html += "<div class=\"Swatch\"></div>";
//html += "</td>";

/*html += "<td>";
html += UtilBeginScript();
html += "var saveButton = new Button(";
html += "editorIDGenerator,";
html += "\"Nhớ vào đĩa cứng\",";
html += "\"EditorOnSave(" + this.id + ")\",";
html += "\"images/save.gif\"";
html += ");";
html += "saveButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var openButton = new Button(";
html += "editorIDGenerator,";
html += "\"Mở văn bản trên máy\",";
html += "\"EditorOnOpen(" + this.id + ")\",";
html += "\"images/open.gif\"";
html += ");";
html += "openButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var openURLButton = new Button(";
html += "editorIDGenerator,";
html += "\"Mở văn bản trên web\",";
html += "\"EditorOnOpenURL(" + this.id + ")\",";
html += "\"images/url.gif\"";
html += ");";
html += "openURLButton.Instantiate();";
html += UtilEndScript();
html += "</td>";*/

//html += "<td>";
//html += "<div class=\"Divider\"></div>";
//html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var createHyperlinkButton = new Button(";
html += "editorIDGenerator,";
html += "\"Tạo liên kết\",";
html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
html += "\"images/wlink.gif\"";
html += ");";
html += "createHyperlinkButton.Instantiate();";
html += UtilEndScript();
html += "</td>";

html += "<td>";
html += UtilBeginScript();
html += "var cutButton = new Button(";
html += "editorIDGenerator,";
html += "\"Cắt\",";
html += "\"EditorOnCut(" + this.id + ")\",";
html += "\"images/cut.gif\"";
html += ");";
html += "cutButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var copyButton = new Button(";
html += "editorIDGenerator,";
html += "\" Quay cóp :-)\",";
html += "\"EditorOnCopy(" + this.id + ")\",";
html += "\"images/copy.gif\"";
html += ");";
html += "copyButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var pasteButton = new Button(";
html += "editorIDGenerator,";
html += "\"Dán\",";
html += "\"EditorOnPaste(" + this.id + ")\",";
html += "\"images/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 += "\"images/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 += "\"images/redo.gif\"";
html += ");";
html += "redoButton.Instantiate();";
html += UtilEndScript();
html += "</td>";

//html += "<td>";
//html += "<div class=\"Divider\"></div>";
//html += "</td>";
html += "<td align=left>";
html += UtilBeginScript();
html += "var boldButton = new Button(";
html += "editorIDGenerator,";
html += "\"Chữ đậm\",";
html += "\"EditorOnBold(" + this.id + ")\",";
html += "\"images/bold.gif\"";
html += ");";
html += "boldButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var italicButton = new Button(";
html += "editorIDGenerator,";
html += "\"Chữ nghiêng\",";
html += "\"EditorOnItalic(" + this.id + ")\",";
html += "\"images/italic.gif\"";
html += ");";
html += "italicButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var underlineButton = new Button(";
html += "editorIDGenerator,";
html += "\"Gạch chân\",";
html += "\"EditorOnUnderline(" + this.id + ")\",";
html += "\"images/uline.gif\"";
html += ");";
html += "underlineButton.Instantiate();";
html += UtilEndScript();
html += "</td></td>";

html += "<td>";
//html += "<div class=\"Divider\"></div>";
//html += "</td>";
//html += "<td>";
html += UtilBeginScript();
html += "var imageButton = new Button(";
html += "editorIDGenerator,";
html += "\"Chen hinh\",";
html += "\"EditorOnInsertImg(" + this.id + ")\",";

html += "\"images/img.gif\"";
//html += "\"images/uline.gif\"";
html += ");";
html += "imageButton.Instantiate();";
html += UtilEndScript();
html += "</td></tr>";






html += "<tr><td>";
//html += "<div class=\"Divider\"></div>";
//html += "</td>";
//html += "<td>";
html += UtilBeginScript();
html += "var tableButton = new Button(";
html += "editorIDGenerator,";
html += "\"Ke bang\",";
html += "\"EditorOnTable(" + this.id + ")\",";
//html += "\"images/tpaint.gif\"";
html += "\"images/table.gif\"";
html += ");";
html += "tableButton.Instantiate();";
html += UtilEndScript();
html += "</td>";

html += "<td>";
html += UtilBeginScript();
html += "var foregroundColorButton = new Button(";
html += "editorIDGenerator,";
html += "\"Mầu chữ\",";
html += "\"EditorOnForegroundColor(" + this.id + ")\",";
html += "\"images/tpaint.gif\"";
//html += "\"images/table.gif\"";
html += ");";
html += "foregroundColorButton.Instantiate();";
html += UtilEndScript();
html += "</td>";



html += "<td>";
html += UtilBeginScript();
html += "var backgroundColorButton = new Button(";
html += "editorIDGenerator,";
html += "\"Mầu nền\",";
html += "\"EditorOnBackgroundColor(" + this.id + ")\",";
html += "\"images/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ề trái\",";
html += "\"EditorOnAlignLeft(" + this.id + ")\",";
html += "\"images/aleft.gif\"";
html += ");";
html += "alignLeftButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var centerButton = new Button(";
html += "editorIDGenerator,";
html += "\"Giữa hàng\",";
html += "\"EditorOnCenter(" + this.id + ")\",";
html += "\"images/center.gif\"";
html += ");";
html += "centerButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var alignRightButton = new Button(";
html += "editorIDGenerator,";
html += "\"Lề phải\",";
html += "\"EditorOnAlignRight(" + this.id + ")\",";
html += "\"images/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ệt kê số\",";
html += "\"EditorOnNumberedList(" + this.id + ")\",";
html += "\"images/nlist.gif\"";
html += ");";
html += "numberedListButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var bullettedListButton = new Button(";
html += "editorIDGenerator,";
html += "\"Liệt kê chấm đầu hàng\",";
html += "\"EditorOnBullettedList(" + this.id + ")\",";
html += "\"images/blist.gif\"";
html += ");";
html += "bullettedListButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var decreaseIndentButton = new Button(";
html += "editorIDGenerator,";
html += "\"Thu hẹp lề\",";
html += "\"EditorOnDecreaseIndent(" + this.id + ")\",";
html += "\"images/ileft.gif\"";
html += ");";
html += "decreaseIndentButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
html += "<td>";
html += UtilBeginScript();
html += "var increaseIndentButton = new Button(";
html += "editorIDGenerator,";
html += "\"Nới rộng lề\",";
html += "\"EditorOnIncreaseIndent(" + this.id + ")\",";
html += "\"images/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ạo liên kết\",";
html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
html += "\"images/wlink.gif\"";
html += ");";
html += "createHyperlinkButton.Instantiate();";
html += UtilEndScript();
html += "</td>";

html += "<td>";
html += UtilBeginScript();
html += "var createImgButton = new Button(";
html += "editorIDGenerator,";
html += "\"Gắn hình\",";
html += "\"EditorOnCreateImg(" + this.id + ")\",";
html += "\"images/img.gif\"";
html += ");";
html += "createImgButton.Instantiate();";
html += UtilEndScript();
html += "</td>";
*/

//html += "<td>";
//html += "<div class=\"Divider\"></div>";
//html += "</td>";

//html += "<td align=right>";
//html += UtilBeginScript();
//html += "var helpButton = new Button(";
//html += "editorIDGenerator,";
//html += "\"Trợ giúp\",";
//html += "\"EditorOnRTEHelp(" + this.id + ")\",";
//html += "\"images/help.gif\"";
//html += ");";
//html += "helpButton.Instantiate();";
//html += UtilEndScript();
//html += "</td>";

html += "</tr>";
html += "</table>";
html += "</td>";
html += "</tr>";
html += "<tr>";
html += "<td align=center>";
html += "<iframe id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"98%\"  align=center height=\"170\">";
html += "</iframe>";
html += "</td>";
html += "</tr>";
html += "</table>";
document.write(html);


html = '';
html += '<body style="font:10pt arial">';
html += str
//html += '<P align=center><FONT size=4>A mega-big thank to</FONT></P>';
//html += '<P align=center><FONT size=4>sister</FONT>';
//html += '&nbsp; <B><FONT face="Courier New" size=5>Yahoo!</FONT>';
//html += '<FONT face="Courier New" color=#ff0000 size=6>Yahoo!</FONT>';
//html += '<FONT face="Courier New" color=#0000ff size=7>Yahoo!</FONT></B></P>';
//html += '<P align=center><FONT size=4>for&nbsp;the rich-text editor! :-)</FONT></P>';
//html += '<P align=center><IMG src="images/m595d.gif"></P>';
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)
{
if (!EditorValidateMode(id)) {
return;
}
var color = showModalDialog("rte/ColorSelect.htm", "", "font-family:Verdana;font-size:12;dialogWidth:29em;dialogHeight:31em");
//var color = showModalDialog("rte/instable.htm", "", "font-family:Verdana;font-size:12;dialogWidth:20em;dialogHeight:15em");
if (color) {
EditorFormat(id, "forecolor", color);
//if (color) {
//tempstr=editwin.document.body.innerHTML;
//tempstr= editwin.GetHTML()
//alert(tempstr)
//editwin.SetHTML(tempstr+color)
//cot= color.substring(2,4)
//hang= color.substring(0,2)
//tempstr=tempstr+ "<table border=1>"
//for (i=0; i<hang; i++)
//{
//tempstr=tempstr+ "<tr>"
//for (j=0; j<cot; j++)
//{
//tempstr=tempstr+ "<td>&nbsp;</td>"
//}
//tempstr=tempstr+ "<tr>"
//}
//tempstr=tempstr+ "<table border=1>"
//editwin.document.body.innerHTML=tempstr;
}
else {
editwin.focus();
}
}

function EditorOnInsertImg(id)
{
if (!EditorValidateMode(id)) {
return;
}
//var color = showModalDialog("rte/ColorSelect", "", "font-family:Verdana;font-size:12;dialogWidth:29em;dialogHeight:31em");
window.open("insert.htm","Uploadimg", "height=400,width=750,status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
//window.open('form_saveasfile.htm');
/* var upl = showModalDialog("rte/upload", "", "font-family:Verdana;font-size:12;dialogWidth:40em;dialogHeight:30em");
if (upl) {
tempstr=editwin.document.body.innerHTML;

tempstr=tempstr+ "<IMG border=0 src="+upl+">"

editwin.document.body.innerHTML=tempstr;
}

else {

editwin.focus();
}
*/
}




function EditorOnTable(id)
{
if (!EditorValidateMode(id)) {
return;
}
//var color = showModalDialog("rte/ColorSelect", "", "font-family:Verdana;font-size:12;dialogWidth:29em;dialogHeight:31em");
var color = showModalDialog("rte/instable.htm", "", "font-family:Verdana;font-size:12;dialogWidth:20em;dialogHeight:15em");
//if (color) {
//EditorFormat(id, "forecolor", color);
if (color) {
tempstr=editwin.document.body.innerHTML;
//tempstr= editwin.GetHTML()
//alert(tempstr)
//editwin.SetHTML(tempstr+color)
cot= color.substring(2,4)
hang= color.substring(0,2)

tempstr=tempstr+ "<table border=1>"
for (i=0; i<hang; i++)
{
tempstr=tempstr+ "<tr>"
for (j=0; j<cot; j++)
{
tempstr=tempstr+ "<td>&nbsp;</td>"
}
tempstr=tempstr+ "<tr>"
}
tempstr=tempstr+ "<table border=1>"
editwin.document.body.innerHTML=tempstr;
}

else {

editwin.focus();
}

}




function EditorOnBackgroundColor(id)
{
if (!EditorValidateMode(id)) {
return;
}
var color = showModalDialog("rte/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");
//EditorFormat(id, "justifyjustify");
}

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^? có thê? dùng thanh cô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];
}
}
