﻿// RichText Editor, VietJie
// Copyright 2002 Vovisoft, website: www.vovisoft.com
// Written by Vinh Tai Tang, email: vtang@vovisoft.com 
// Please do send feedback of any bugs to the above email address.

// This scriptlet is based on the Yahoo rich text editor
// and combined with the enhanced version of Vietjie.js by Xuong D. Au

// You are free to use the editor for non commercial purpose.
// Vovisot, www.vovisoft.com is a non profit organisation located in Australia 
// Please help to promote our devotion to doing something for our people

// You are welcome to make improvement or modification to this script.
// If you do modify it, please send a copy to the above authors.
// Our view is that the more people working on it the better it will be!!!

//'BaseLoc' is the location of your Editor. If the application using this editor
//is located at the same folder as the editor, just leave the BaseLoc blank.
var BaseLoc="";
var ImgLoc = BaseLoc + "Images";
// Start Cookie

function setCookie(name,value,expiry) {
	var expires = new Date();
	expires.setTime (expires.getTime() + 24*60*60*365*1000);
	var nameString = name + "=" + value + ";" ;
	var expiryString = (expiry == null) ? "expires=" + expires.toGMTString()+ ";": "expires=" + expiry.toGMTString() + ";";
	window.document.cookie = nameString + expiryString ;
}

function getCookie(name) {
   var cookieFound = false;
   var start = 0;
   var end = 0;
   var cookieString = document.cookie;

   var i = 0;
   //LOOK FOR name IN cookieString
   while (i <= cookieString.length) {
      start = i;
      end = start + name.length;
      if (cookieString.substring(start,end) == name) {
         cookieFound = true;
         break;
      }
      i++;
   }

   //CHECK IF NAME WAS FOUND
   if (cookieFound) {
      start = end + 1;
      end = cookieString.indexOf(";",start);
      if (end < start)
         end = cookieString.length;
      return unescape(cookieString.substring(start,end));
   }

   //NAME WAS NOT FOUND
   return "";
}
	
	//End Cookie
//common functions	
    function BeginScript()
    {
	return String.fromCharCode(60, 115, 99, 114, 105, 112, 116, 62);
    }

    function EndScript()
    {
	return String.fromCharCode(60, 47, 115, 99, 114, 105, 112, 116, 62);
    }
	function IDGenerate(nextID)
	{
		this.nextID = nextID;
		this.GenerateID = IDGeneratorGenerateID;
	}

	function IDGeneratorGenerateID()
	{
		return this.nextID++;
	}

// Buttons 

	var buttonMap = new Object();
	function Button
	(
		idGenerator,
		caption,
		action,
		image,
		type
	)
	{
		this.idGenerator = idGenerator;
		this.caption = caption;
		this.action = action;
		this.image = image;
		this.type= type;
		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="btnDiv';
		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="btnPad1' + this.id + '" width=2 height=2>';
		html += '</td><td></td><td></td></tr><tr><td></td><td>';
		switch(this.type){
			case 'menuitm':
				html += '<span id="btnImg' + this.id + '" class="Menu">' + this.caption + '</span>';
				break;
			case 'tray':
				html += '<img id="btnImg' + this.id + '" src="' + this.image + '" title="' + this.caption + '" class="SysTray">';
				break;	
			default:
				html += '<img id="btnImg' + this.id + '" src="' + this.image + '" title="' + this.caption + '" class="Image">';
		}
		html += '</td><td></td></tr><tr><td></td><td></td><td>';
		html += '<img id="btnPad2' + this.id + '" width=2 height=2></td></tr></table>';
		html += '</div>';
		document.write(html);
		
	}

	function ButtonEnable(enabled)
	{
		this.enabled = enabled;
		if (this.enabled)
		{
			document.all['btnDiv' + this.id].className = "ButtonNormal";
		}
		else
		{
			document.all['btnDiv' + 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('btnDiv'.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('btnDiv'.length, element.id.length);
			var button = buttonMap[id];
			if (button.enabled)
			{
				ButtonReleaseButton(id);
			}
		}
	}

	function ButtonOnMouseOut(element)
	{
		var id = element.id.substring('btnDiv'.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled)
		{
			ButtonReleaseButton(id);
		}
	}

	function ButtonOnMouseOver(element)
	{
		var id = element.id.substring('btnDiv'.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled)
		{
			document.all['btnDiv' + id].blur();
			ButtonReleaseButton(id);
			document.all['btnDiv' + id].className = "ButtonMouseOver";
		}
	}

	function ButtonOnClick(element)
	{
		var id = element.id.substring('btnDiv'.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled)
		{
			eval(button.action);
		}
	}

	function ButtonOnDblClick(element)
	{
		ButtonOnClick(element);
	}

	function ButtonPushButton(id)
	{
		document.all['btnPad1' + id].width = 3;
		document.all['btnPad1' + id].height = 3;
		document.all['btnPad2' + id].width = 1;
		document.all['btnPad2' + id].height = 1;
		document.all['btnDiv' + id].className = "ButtonPressed";
	}

	function ButtonReleaseButton(id)
	{
		document.all['btnPad1' + id].width = 2;
		document.all['btnPad1' + id].height = 2;
		document.all['btnPad2' + id].width = 2;
		document.all['btnPad2' + id].height = 2;
		document.all['btnDiv' + id].className = "ButtonNormal";
	}

// Image and Wingding Chooser
 
    var IMAGE_CHOOSER_DIV_PREFIX = "imageChooserDiv";
    var IMAGE_CHOOSER_IMG_PREFIX = "imageChooserImg";
    var IMAGE_CHOOSER_ICON_PREFIX = "imageChooserIcon";
    var WINGDING_CHOOSER_DIV_PREFIX = "wingdingChooserDiv";
    var WINGDING_CHOOSER_IMG_PREFIX = "wingdingChooserImg";
    var WINGDING_CHOOSER_ICON_PREFIX = "wingdingChooserIcon";
    var imageChooserMap = new Object();
	
    function ImageChooser
    (
	    idGenerator,
	    numRows,
	    numCols,
	    images,
	    callback
    )
    {
	    this.idGenerator = idGenerator;
	    this.numRows = numRows;
	    this.numCols = numCols;
	    this.images = images;
	    this.callback = callback;
	    this.Instantiate = ImageChooserInstantiate;
	    this.Show = ImageChooserShow;
	    this.Hide = ImageChooserHide;
	    this.IsShowing = ImageChooserIsShowing;
	    this.SetUserData = ImageChooserSetUserData;
    }

    function ImageChooserInstantiate()
    {
	    this.id = this.idGenerator.GenerateID();
	    
	    
	    var html = '';
	    if (!this.images)
	    {
			imageChooserMap[this.id] = this
			html += '<div id="' + WINGDING_CHOOSER_DIV_PREFIX + this.id + '" style="display:none;position:absolute;background-color:buttonface;border-left:buttonhighlight solid 1px;border-top:buttonhighlight solid 1px;border-right:buttonshadow solid 1px;border-bottom:buttonshadow solid 1px; cursor: hand">';
			
	    }
	    else
	    {
			imageChooserMap[this.id] = this;
			html += '<div id="' + IMAGE_CHOOSER_DIV_PREFIX + this.id + '" style="display:none;position:absolute;background-color:buttonface;border-left:buttonhighlight solid 1px;border-top:buttonhighlight solid 1px;border-right:buttonshadow solid 1px;border-bottom:buttonshadow solid 1px; cursor: hand">';
		}	
	    html += '<table>';
	    for (var i = 0; i < this.numRows; i++) {
		    html += '<tr>';
		    for (var j = 0; j < this.numCols; j++) {
			    html += '<td>';
			    var k = i * this.numCols + j;
			    if (!this.images)
				{
				
					html += '<div id="' + WINGDING_CHOOSER_ICON_PREFIX + this.id + '_' + k + '" style="border:buttonface solid 1px">';
					html += '<font face="wingdings" size="3"><div id="' + WINGDING_CHOOSER_IMG_PREFIX + this.id + '_' + k + '" onmouseover="ImageChooserOnMouseOver(2)" onmouseout="ImageChooserOnMouseOut(2)" onclick="ImageChooserOnClick(2)">&#' + (k+32) + ';</div></font>' ;
					html += '</div>';
					html += '</td>';
				}
				else
				{
					html += '<div id="' + IMAGE_CHOOSER_ICON_PREFIX + this.id + '_' + k + '" style="border:buttonface solid 1px">';
					html += '<img src="' + this.images[k] + '" id="' + IMAGE_CHOOSER_IMG_PREFIX + this.id + '_' + k + '" onmouseover="ImageChooserOnMouseOver()" onmouseout="ImageChooserOnMouseOut()" onclick="ImageChooserOnClick()">';
					html += '</div>';
					html += '</td>';
				}	
		    }
		    html += '</tr>';
	    }
	    html += '</table>';
	    html += '</div>';
	    document.write(html);
    }

    function ImageChooserShow(x, y,wingding)
    {
	    if (!wingding)
		{
			eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display = "block";
			eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.left = x- eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).offsetWidth;
			eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.top = y;
			
		}
		else
		{
			eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).style.display = "block";
			eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).style.left = x- eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).offsetWidth;
			eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).style.top = y;
		}	
    }

    function ImageChooserHide(wingding)
    {
		if (!wingding)
		{
			eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display = "none";
		}
		else
		{
			eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).style.display = "none";
		}	
    }

    function ImageChooserIsShowing(wingding)
    {
		if (!wingding)
		{
			return eval(IMAGE_CHOOSER_DIV_PREFIX + this.id).style.display == "block";
		}
		else
		{
			return eval(WINGDING_CHOOSER_DIV_PREFIX + this.id).style.display == "block";
		}	
    }

    function ImageChooserSetUserData(userData)
    {
	this.userData = userData;
    }

    function ImageChooserOnMouseOver(wingding)
    {
		if (!wingding)
		{
			if (event.srcElement.tagName == "IMG") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
					var index = event.srcElement.id.substring(underscore + 1);
					eval(IMAGE_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "black";
				}
			}
		}
		else
		{
			if (event.srcElement.tagName == "DIV") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(WINGDING_CHOOSER_IMG_PREFIX.length, underscore);
					var index = event.srcElement.id.substring(underscore + 1);
					eval(WINGDING_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "black";
				}
			}
		}	
    }

    function ImageChooserOnMouseOut(wingding)
    {
		if (!wingding)
		{
			if (event.srcElement.tagName == "IMG") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
					var index = event.srcElement.id.substring(underscore + 1);
					eval(IMAGE_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "buttonface";
				}
			}
		}
		else
		{
			if (event.srcElement.tagName == "DIV") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(WINGDING_CHOOSER_IMG_PREFIX.length, underscore);
					var index = event.srcElement.id.substring(underscore + 1);
					eval(WINGDING_CHOOSER_ICON_PREFIX + id + "_" + index).style.borderColor = "buttonface";
				}
			}
		}	
    }

    function ImageChooserOnClick(wingding)
    {
		if (!wingding)
		{
			if (event.srcElement.tagName == "IMG") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(IMAGE_CHOOSER_IMG_PREFIX.length, underscore);
					var imageChooser = imageChooserMap[id];
					imageChooser.Hide();
					var index = event.srcElement.id.substring(underscore + 1);
					if (imageChooser.callback) {
						imageChooser.callback(imageChooser.images[index], imageChooser.userData);
					}
				}
			}
		}
		else
		{
			if (event.srcElement.tagName == "DIV") {
				var underscore = event.srcElement.id.indexOf("_");
				if (underscore != -1) {
					var id = event.srcElement.id.substring(WINGDING_CHOOSER_IMG_PREFIX.length, underscore);
					var imageChooser = imageChooserMap[id];
					imageChooser.Hide(2);
					var index = event.srcElement.id.substring(underscore + 1);
					if (imageChooser.callback) {
						imageChooser.callback(eval(index) + 32, imageChooser.userData);
					}
				}
			}
		}
    }
 
//Editor  
	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_MIDDLE_TOOLBAR_PREFIX="editorMiddleToolbar";
	var EDITOR_BOTTOM_TOOLBAR_PREFIX = "editorBottomToolbar";
	var EDITOR_SMILEY_BUTTON_PREFIX = "editorSmileyButton";
	var EDITOR_IMAGE_CHOOSER_PREFIX = "editorImageChooser";
	var EDITOR_WINGDING_BUTTON_PREFIX = "editorWingdingButton";
	var EDITOR_WINGDING_CHOOSER_PREFIX = "editorWingdingChooser";
	var editorMap = new Object();
	var editorIDGenerator = null;

	function Editor
	(
		idGenerator,
		onkeydownHandler,
		onkeypressHandler
	)
	{
		this.idGenerator = idGenerator;
		this.textMode = false;
		this.brief = false;
		this.vtypingMode=(getCookie("typingMode")=="")? 0 : parseInt(getCookie("typingMode"));
		this.instantiated = false;
		this.Instantiate = EditorInstantiate;
		this.GetText = EditorGetText;
		this.SetText = EditorSetText;
		this.GetHTML = EditorGetHTML;
		this.SetHTML = EditorSetHTML;
		this.GetBrief = EditorGetBrief;
		this.SetBrief = EditorSetBrief;
		this.SetFocus= EditorSetFocus;
		this.onkeydown=onkeydownHandler;
		this.onkeypress=onkeypressHandler;
	}
	
	function EditorInstantiate()
	{
		if (this.instantiated) {
			return;
		}
		this.id = this.idGenerator.GenerateID();
		editorMap[this.id] = this;
		editorIDGenerator = this.idGenerator;

		var html = "";
		html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
		html += "<tr class=\"TitleBar\">";
		html += "<td>";
		html += "<table width=\"100%\">";
		html += "<tr>";
		html += "<td width=\"70%\" class=\"TitleBarText\">";
		html += "<img src=\"" + ImgLoc + "/icon_edit_topic.gif\">";
		html += "&nbsp;";
		html += "</td>";
		html += "<td width=\"30%\" align=right class=\"TitleBarText\">";
		html += "<a  href=http://www.cedasit.com.vn>www.cedasit.com.vn</a>";
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</td>";
		html += "</tr>";
	
		html += "<tr>";
		html += "<td id=\"" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";
		html += "<table cellpadding=\"1\" 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 += "<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\">Paragraph</option>";
		html += "<option value=\"Normal\">Normal</option>";
		html += "<option value=\"Heading 1\">Heading 1 &lt;H1&gt;</option>";
		html += "<option value=\"Heading 2\">Heading 2 &lt;H2&gt;</option>";
		html += "<option value=\"Heading 3\">Heading 3 &lt;H3&gt;</option>";
		html += "<option value=\"Heading 4\">Heading 4 &lt;H4&gt;</option>";
		html += "<option value=\"Heading 5\">Heading 5 &lt;H5&gt;</option>";
		html += "<option value=\"Heading 6\">Heading 6 &lt;H6&gt;</option>";
		html += "<option value=\"Address\">Address &lt;ADDR&gt;</option>";
		html += "<option value=\"Formatted\">Formatted &lt;PRE&gt;</option>";
		html += "</select>";
		html += "</span>";
		html += "</td>";
		html += "<td>";
		html += "<select class=\"List\" onchange=\"EditorOnFont(" + this.id + ", this)\">";
		html += "<option class=\"Heading\">Font</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=\"Tahoma\">Tahoma</option>";
		html += "<option value=\"Times New Roman\">Times New Roman</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\">Size</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 class=\"Text\">";
		html += "<input type=\"checkbox\" onclick=\"EditorOnViewHTMLSource(" + this.id + ", this.checked)\">";
		html += "View HTML &nbsp;";
		html += "</td>";
		
		html += "</table>";
		html += "</td>";
		html += "</tr>";
		
		html += "<tr>";
		html += "<td id=\"" + EDITOR_MIDDLE_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";
		html += "<table cellpadding=\"1\" 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 += BeginScript();
		html += "var saveButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Save\",";
		html += "\"EditorOnSave(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/save.gif\"";
		html += ");";
		html += "saveButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var createHyperlinkButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Create Hyperlink\",";
		html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/wlink.gif\"";
		html += ");";
		html += "createHyperlinkButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var cutButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Cut\",";
		html += "\"EditorOnCut(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/cut.gif\"";
		html += ");";
		html += "cutButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var copyButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Copy\",";
		html += "\"EditorOnCopy(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/copy.gif\"";
		html += ");";
		html += "copyButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var pasteButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Paste\",";
		html += "\"EditorOnPaste(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/paste.gif\"";
		html += ");";
		html += "pasteButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var undoButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Undo\",";
		html += "\"EditorOnUndo(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/undo.gif\"";
		html += ");";
		html += "undoButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var redoButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Redo\",";
		html += "\"EditorOnRedo(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/redo.gif\"";
		html += ");";
		html += "redoButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var boldButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Bold\",";
		html += "\"EditorOnBold(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/bold.gif\"";
		html += ");";
		html += "boldButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var italicButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Italic\",";
		html += "\"EditorOnItalic(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/italic.gif\"";
		html += ");";
		html += "italicButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var underlineButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Underline\",";
		html += "\"EditorOnUnderline(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/uline.gif\"";
		html += ");";
		html += "underlineButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var strikethroughButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Strikethrough\",";
		html += "\"EditorOnStrikethrough(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/strike.gif\"";
		html += ");";
		html += "strikethroughButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var subscriptButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Subscript\",";
		html += "\"EditorOnSubscript(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/subscript.gif\"";
		html += ");";
		html += "subscriptButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var superscriptButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Superscript\",";
		html += "\"EditorOnSuperscript(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/superscript.gif\"";
		html += ");";
		html += "superscriptButton.Instantiate();";
		html += EndScript();
		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 cellpadding=\"1\" 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 += BeginScript();
		html += "var foregroundColorButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Foreground Color\",";
		html += "\"EditorOnForegroundColor(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/tpaint.gif\"";
		html += ");";
		html += "foregroundColorButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var backgroundColorButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Background Color\",";
		html += "\"EditorOnBackgroundColor(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/parea.gif\"";
		html += ");";
		html += "backgroundColorButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var alignLeftButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Align Left\",";
		html += "\"EditorOnAlignLeft(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/aleft.gif\"";
		html += ");";
		html += "alignLeftButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var centerButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Center\",";
		html += "\"EditorOnCenter(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/center.gif\"";
		html += ");";
		html += "centerButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var alignRightButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Align Right\",";
		html += "\"EditorOnAlignRight(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/aright.gif\"";
		html += ");";
		html += "alignRightButton.Instantiate();";
		html += EndScript();
		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=\"1\" cellspacing=\"0\" border=\"0\">";
		html += "<tr>";
		html += "<td>";
		html += BeginScript();
		html += "var numberedListButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Numbered List\",";
		html += "\"EditorOnNumberedList(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/nlist.gif\"";
		html += ");";
		html += "numberedListButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var bullettedListButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Bulletted List\",";
		html += "\"EditorOnBullettedList(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/blist.gif\"";
		html += ");";
		html += "bullettedListButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var decreaseIndentButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Decrease Indent\",";
		html += "\"EditorOnDecreaseIndent(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/ileft.gif\"";
		html += ");";
		html += "decreaseIndentButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var increaseIndentButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Increase Indent\",";
		html += "\"EditorOnIncreaseIndent(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/iright.gif\"";
		html += ");";
		html += "increaseIndentButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var horizontalLineButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Horizontal Line\",";
		html += "\"EditorOnHorizontalLine(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/HorizontalLine.gif\"";
		html += ");";
		html += "horizontalLineButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td>";
		html += "<div class=\"Divider\"></div>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var insertImageButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Insert Image\",";
		html += "\"EditorOnInsertImage(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/image.gif\"";
		html += ");";
		html += "insertImageButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td id=\"" + EDITOR_WINGDING_BUTTON_PREFIX + this.id + "\">";
		html += BeginScript();
		html += "var insertWingdingButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Insert Wingdings\",";
		html += "\"EditorOnStartInsertWingding(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/Wingdings.gif\"";
		html += ");";
		html += "insertWingdingButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "<td id=\"" + EDITOR_SMILEY_BUTTON_PREFIX + this.id + "\">";
		html += BeginScript();
		html += "var insertSmileyButton = new Button(";
		html += "editorIDGenerator,";
		html += "\"Insert Smiley\",";
		html += "\"EditorOnStartInsertSmiley(" + this.id + ")\",";
		html += "\"" + ImgLoc + "/smiley.gif\"";
		html += ");";
		html += "insertSmileyButton.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td>";
		html += "<iframe id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"100%\" height=\"190\">";
		html += "</iframe>";
		html += "</td>";
		html += "</tr>";
		html += "<tr class=StatusBar>";
		html += "<td>";
		html += "<table width=100%>";
		html += "<tr>";
		html += "<td class=Panel width=10%>";
		//html += "<a href=mailto:dixon@vovisoft.com;vtang@vovisoft.com ><font size=1>Feedback</font></a>";
		html += "</td>";
		html += "<td id=\"Tips\" class=Panel width=70% align=right>";
		html += "abc";
		html += "</td>";
		html += "<td id=\"Mode\" class=Panel width=10% align=right>";
		html += "OFF";
		html += "</td>";
		
		html += "<td class=Panel width=10% align=right>";
		html += "<table>";
		html += "<tr>";
		html += "<td>";
		html += "</td>";
		html += "<td>";
		html += BeginScript();
		html += "var VietTypingTrayMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"Viet Typing Mode\",";
		html += "\"ShowHideSystrayMenuItems(VietTypingTrayMenuItems,VietTypingTrayMenu.id," + this.id + ")\",";
		html += "\"" + ImgLoc + "/editicon.gif\",";
		html += "\"tray\"";
		html += ");";
		html += "VietTypingTrayMenu.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		html += "</td>";
		html += "</tr>";
		html += "</table>";
		
		html += BeginScript();
		html += "var " + EDITOR_WINGDING_CHOOSER_PREFIX + this.id + " = new ImageChooser(";
		html += "editorIDGenerator,";
		html += "14, 16,";
		html += "\"\",";
		html += "EditorOnEndInsertSmiley";
		html += ");";
		html += EDITOR_WINGDING_CHOOSER_PREFIX + this.id + ".SetUserData(" + this.id + ");";
		html += EDITOR_WINGDING_CHOOSER_PREFIX + this.id + ".Instantiate();";
		html += EndScript();
		
		html += BeginScript();
		html += "var " + EDITOR_IMAGE_CHOOSER_PREFIX + this.id + " = new ImageChooser(";
		html += "editorIDGenerator,";
		html += "5, 5,";
		html += "[";
		html += "\"" + ImgLoc + "/Smileys/1.gif\",";
		html += "\"" + ImgLoc + "/Smileys/2.gif\",";
		html += "\"" + ImgLoc + "/Smileys/3.gif\",";
		html += "\"" + ImgLoc + "/Smileys/4.gif\",";
		html += "\"" + ImgLoc + "/Smileys/5.gif\",";
		html += "\"" + ImgLoc + "/Smileys/6.gif\",";
		html += "\"" + ImgLoc + "/Smileys/7.gif\",";
		html += "\"" + ImgLoc + "/Smileys/8.gif\",";
		html += "\"" + ImgLoc + "/Smileys/9.gif\",";
		html += "\"" + ImgLoc + "/Smileys/a.gif\",";
		html += "\"" + ImgLoc + "/Smileys/b.gif\",";
		html += "\"" + ImgLoc + "/Smileys/c.gif\",";
		html += "\"" + ImgLoc + "/Smileys/d.gif\",";
		html += "\"" + ImgLoc + "/Smileys/e.gif\",";
		html += "\"" + ImgLoc + "/Smileys/f.gif\",";
		html += "\"" + ImgLoc + "/Smileys/g.gif\",";
		html += "\"" + ImgLoc + "/Smileys/h.gif\",";
		html += "\"" + ImgLoc + "/Smileys/i.gif\",";
		html += "\"" + ImgLoc + "/Smileys/j.gif\",";
		html += "\"" + ImgLoc + "/Smileys/k.gif\",";
		html += "\"" + ImgLoc + "/Smileys/l.gif\",";
		html += "\"" + ImgLoc + "/Smileys/m.gif\",";
		html += "\"" + ImgLoc + "/Smileys/n.gif\",";
		html += "\"" + ImgLoc + "/Smileys/o.gif\",";
		html += "\"" + ImgLoc + "/Smileys/y.gif\"";
		html += "],";
		html += "EditorOnEndInsertSmiley";
		html += ");";
		html += EDITOR_IMAGE_CHOOSER_PREFIX + this.id + ".SetUserData(" + this.id + ");";
		html += EDITOR_IMAGE_CHOOSER_PREFIX + this.id + ".Instantiate();";
		html += EndScript();
		
		html += BeginScript();
		html += "var VietTypingTrayMenuItems = new MenuItems(";
		html += "\"" + VietTypingTrayMenu_DIV_PREFIX + this.id + "\",";
		html += this.id ;
		html += ");";
	    html += "VietTypingTrayMenuItems.Instantiate();";
		html += EndScript();
		
		document.write(html);

		html = '';
		html += '<head>';
		html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
		html += '</head>';
		html += '<body style="font:12pt tahoma" onselect="CreateRange(' + this.id + ');">';
		html += '</body>';
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.open();
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.write(html);
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.close();
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.designMode = "on";
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.onclick = new Function("EditorOnClick(" + this.id + ")");
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.onkeydown=new Function(this.onkeydown);
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.onkeypress=new Function(this.onkeypress);
		ChangeVietTypingMode(this.vtypingMode);
		editorIDGenerator = null;
		this.instantiated = true;
	}
	
	function  EditorGetText()
	{
		return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
	}

	function  EditorSetText(text)
	{
		text = text.replace(/\n/g, "<br>");
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = text;
	}

	function  EditorGetHTML()
	{
		if (this.textMode) {
			return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
		}
		EditorCleanHTML(this.id);
		EditorCleanHTML(this.id);
		return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML;
	}

	function  EditorSetHTML(html)
	{
		if (this.textMode) {
			eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText = html;
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + this.id).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 EditorSetFocus(){
		eval(EDITOR_COMPOSITION_PREFIX + this.id).focus();
		return;
	}	
	
	function EditorOnInsert(id, select)
	{
    if (!EditorValidateMode(id)) {
        return;
    }
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    EditorFormat(id, select[select.selectedIndex].value);
    select.selectedIndex = 0;
}
	
	function EditorOnSave(id)
	{
		EditorFormat(id, "Saveas");
	}
	
	function EditorOnHorizontalLine(id)
	{
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		var range = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
		range.pasteHTML('<hr>');
		
	}
	
	function EditorOnUndo(id)
	{
		EditorFormat(id, "Undo");
	}
	
	function EditorOnRedo(id)
	{
		EditorFormat(id, "Redo");
	}
	
	function EditorOnInsertImage(id)
	{
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		EditorFormat(id, "InsertImage");
	}
	
	
	
	
	function EditorOnStrikethrough(id)
	{
		EditorFormat(id, "Strikethrough");
	}
	
	function EditorOnSubscript(id)
	{
		EditorFormat(id, "Subscript");
	}
	
	function EditorOnSuperscript(id)
	{
		EditorFormat(id, "Superscript");
	}
	
	function EditorOnCut(id)
	{
		EditorFormat(id, "cut");
	}

	function EditorOnCopy(id)
	{
		EditorFormat(id, "copy");
	}

	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(BaseLoc + "ColorSelect", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:23em");
		if (color) {
			EditorFormat(id, "forecolor", color);
		}
		else {

			eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		}
	}

	function EditorOnBackgroundColor(id)
	{
		if (!EditorValidateMode(id)) {
			return;
		}
		var color = showModalDialog(BaseLoc + "ColorSelect", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:23em");
		if (color) {
			EditorFormat(id, "backcolor", color);
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + id).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 EditorOnCreateHyperlink(id)
	{
		if (!EditorValidateMode(id)) {
			return;
		}
		var anchor = EditorGetElement("A", eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange().parentElement());
		var link = prompt("Enter link location (eg. http://www.cedasit.com.vn):", anchor ? anchor.href : "http://");
		if (link && link != "http://") {
			if (eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.type == "None") {
				var range = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
				range.pasteHTML('<A HREF="' + link + '"></A>');
				range.select();
			}
			else {
				EditorFormat(id, "CreateLink", link);
			}
		}
	}

	function CreateRange(id)
	{
		var editor = editorMap[id];	
		editor.selectionRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
	}
	
	function EditorOnStartInsertWingding(id)
	{
		if (eval(EDITOR_WINGDING_CHOOSER_PREFIX + id).IsShowing(2)) {
			eval(EDITOR_WINGDING_CHOOSER_PREFIX + id).Hide(2);
		}
		else {
			var editor = editorMap[id];	
			editor.selectionRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
			eval(EDITOR_WINGDING_CHOOSER_PREFIX + id).Show(GetAbsoluteX(eval(EDITOR_WINGDING_BUTTON_PREFIX + id),0),GetAbsoluteY(eval(EDITOR_WINGDING_BUTTON_PREFIX + id),0),2);
		}
			
	}
	
	function EditorOnStartInsertSmiley(id)
	{
		if (eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).IsShowing()) {
			eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).Hide();
		}
		else {
			var editor = editorMap[id];
		
			editor.selectionRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
			//eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).Show(eval(EDITOR_SMILEY_BUTTON_PREFIX + id).offsetLeft + 115 , eval(EDITOR_BOTTOM_TOOLBAR_PREFIX + id).offsetTop + eval(EDITOR_BOTTOM_TOOLBAR_PREFIX + id).offsetHeight + 115 );
			eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).Show(GetAbsoluteX(eval(EDITOR_SMILEY_BUTTON_PREFIX + id),0),GetAbsoluteY(eval(EDITOR_SMILEY_BUTTON_PREFIX + id),0));
		}
	}

	function GetAbsoluteX(obj,absoluteX){
		if (obj.offsetParent){
			absoluteX+= obj.offsetLeft;
			absoluteX=GetAbsoluteX(obj.offsetParent,absoluteX);
		}
		return absoluteX;
	}
	
	function GetAbsoluteY(obj,absoluteY){
		if (obj.offsetParent){
			absoluteY+= obj.offsetTop;
			absoluteY=GetAbsoluteY(obj.offsetParent,absoluteY);
		}
		return absoluteY;
	}

	function EditorOnEndInsertSmiley(image, id)
	{
	    if (!EditorValidateMode(id)) {
		return;
	    }
	    if (typeof(image)=="number")
	    {
			var imgTag = '<font face="wingdings" size="3">&#' + image + ';</font>';
	    }
	    else
	    {
			var imgTag = '<img src="' + image + '">';
		}	
	    var editor = editorMap[id];
	    var bodyRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
	    if (bodyRange.inRange(editor.selectionRange)) {
	    
	    editor.selectionRange.select();
	    
		editor.selectionRange.pasteHTML(imgTag);		
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
	    }
	    else {
		eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML += imgTag;
		editor.selectionRange.collapse(false);
		editor.selectionRange.select();
	    }
	}

	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 EditorOnViewHTMLSource(id, textMode)
	{
		var editor = editorMap[id];
		editor.textMode = textMode;
		if (editor.textMode) {
			EditorCleanHTML(id);
			EditorCleanHTML(id);
			eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerText = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML;
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerHTML = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.innerText;
		}
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
	}

	function EditorOnClick(id)
	{
		eval(EDITOR_IMAGE_CHOOSER_PREFIX + id).Hide();
		eval(EDITOR_WINGDING_CHOOSER_PREFIX + id).Hide(2);
		VietTypingTrayMenuItems.Hide();
	}
	
	function EditorOnBlur(id)
	{
		var editor = editorMap[id];	
		editor.selectionRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
	}
	
	function EditorValidateMode(id)
	{
		var editor = editorMap[id];
		if (!editor.textMode) {
			return true;
		}
		alert("Please uncheck the \"View HTML Source\" checkbox to use the toolbars.");
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		return false;
	}

	function EditorFormat(id, what, opt)
	{
		if (!EditorValidateMode(id)) {
			return;
		}
		if (opt == "removeFormat") {
			what = opt;
			opt = null;
		}
		if (opt == null) {
			eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what,true);
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what, "", opt);
		}
	}

	function EditorCleanHTML(id)
	{
		var fonts = eval(EDITOR_COMPOSITION_PREFIX + id).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;
	}
 
 
//Tray Menu	
	
	var VietTypingTrayMenu_DIV_PREFIX="VietTypingTrayMenuDiv";
	
	function ShowHideSystrayMenuItems(MenuItemsName,MenuID,EditorID){
		if (MenuItemsName.IsShowing()){
			MenuItemsName.Hide();	
		}
		else{
			eval(VietTypingTrayMenu_DIV_PREFIX + EditorID).style.display = "block";
			MenuItemsName.Show(GetAbsoluteX(eval('btnDiv' + MenuID),0) - eval(VietTypingTrayMenu_DIV_PREFIX + EditorID).offsetWidth,eval(GetAbsoluteY(eval('btnDiv' + MenuID),0)) - eval(VietTypingTrayMenu_DIV_PREFIX + EditorID).offsetHeight);
		}	
	}
	
//Menu Items

	function MenuItems
    (
		Name,
		EditorID
    )
    {
	    this.Name= Name;
	    this.EditorID= EditorID;
	    this.Instantiate = MenuItemsInstantiate;
	    this.Show = MenuItemsShow;
	    this.Hide = MenuItemsHide;
	    this.IsShowing = MenuItemsIsShowing;
    }
	
	function MenuItemsInstantiate(){
		
		if (this.Name.indexOf(VietTypingTrayMenu_DIV_PREFIX,0)!=-1){
			LoadMenuVietTypingTrayItems(this.Name,this.EditorID);
		}
	}
	
	function MenuItemsShow(x, y)
    {
			
			eval(this.Name).style.display = "block";
			eval(this.Name).style.left = x;
			eval(this.Name).style.top = y;

    }

    function MenuItemsHide()
    {
		
			eval(this.Name).style.display = "none";
    }

    function MenuItemsIsShowing()
    {
		
			return eval(this.Name).style.display == "block";
		
    }
    
    
    function LoadMenuVietTypingTrayItems(MenuDivName,EditorID)
    {
		var html = "";
		html += "<div id=\"" + MenuDivName + "\" style=\"display:none;position:absolute;background-color:buttonface;border-left:buttonhighlight solid 1px;border-top:buttonhighlight solid 1px;border-right:buttonshadow solid 1px;border-bottom:buttonshadow solid 1px; zIndex: 8\">";
	    html += "<table >";
	    html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var ToUnicodeMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"ToUnicode\",";
		html += "\"ConvertVIQR2Unicode(" + EditorID + ")\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "ToUnicodeMenu.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
	    html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var ToVIQRMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"ToVIQR\",";
		html += "\"ConvertUnicode2VIQR(" + EditorID + ")\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "ToVIQRMenu.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td >";
		html += "<hr>";
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var TelexMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"TELEX\",";
		html += "\"ChangeVietTypingMode(1)\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "TelexMenu.Instantiate();";
		html += EndScript();
		html += "</td>";				
		html += "</tr>";
		html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var VIQRMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"VIQR\",";
		html += "\"ChangeVietTypingMode(3)\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "VIQRMenu.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var VNIMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"VNI\",";
		html += "\"ChangeVietTypingMode(2)\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "VNIMenu.Instantiate();";
		html += EndScript();
		html += "</td>";				
		html += "</tr>";
		html += "<tr>";
		html += "<td align=\"center\">";
		html += BeginScript();
		html += "var OffMenu = new Button(";
		html += "editorIDGenerator,";
		html += "\"OFF\",";
		html += "\"ChangeVietTypingMode(0)\",";
		html += "\"\",";
		html += "\"menuitm\"";
		html += ");";
		html += "OffMenu.Instantiate();";
		html += EndScript();
		html += "</td>";
		html += "</tr>";
	    html += "</table>";
	    html += "</div>";
	    document.write(html);
	    
    }
    function ChangeVietTypingMode(mode){
		var rule="";
		var pre1='<td align="center"><b><font face="Tahoma" size="1" color="#CC0099">';
		var sub1='</font></b></td>';
		var pre2='<td align="center"><b><font face="Tahoma" size="1" color="#9900FF">';
		var sub2='</font></b></td>';
		var r1="";
				r1 +='<tr>';
				r1 +=pre1 + 'á' + sub1;
				r1 +=pre1 + 'à' + sub1;
				r1 +=pre1 + 'ả' + sub1;
				r1 +=pre1 + 'ã' + sub1;
				r1 +=pre1 + 'ạ' + sub1;
				r1 +=pre1 + 'â ê ô' + sub1;
				r1 +=pre1 + 'ơ ư' + sub1;
				r1 +=pre1 + 'ă' + sub1;
				r1 +=pre1 + 'đ' + sub1;
				r1 +=pre1 + '/ \\' + sub1;
				r1 +='</tr>';
		TypingMode(mode);
		VietTypingTrayMenuItems.Hide();
		
		switch (mode){
			case 0:
				document.all.Mode.innerHTML="<font color=red>OFF</font>";
				rule +='<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="350" id="AutoNumber1">';
				r1='';
				r1 +='<tr>';
				r1 +=pre1 + 'CTRL \+ 1' + sub1;
				r1 +=pre1 + 'CTRL \+ 2' + sub1;
				r1 +=pre1 + 'CTRL \+ 3' + sub1;
				r1 +=pre1 + 'CTRL \+ 4' + sub1;
				r1 +=pre1 + 'CTRL \+ SHIFT' + sub1;
				r1 +='</tr>';
				rule += r1;
				rule +='<tr>';
				rule +=pre2 + 'OFF' + sub2;
				rule +=pre2 + 'TELEX' + sub2;
				rule +=pre2 + 'VNI' + sub2;
				rule +=pre2 + 'VIQR' + sub2;
				rule +=pre2 + 'Luân Phiên Chọn' + sub2;
				rule +='</tr>';
				rule +='</table>';
				break;
			case 1:
				document.all.Mode.innerHTML="<font color=blue>TELEX</font>";
				rule +='<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="350" id="AutoNumber1">';
				rule += r1;
				rule +='<tr>';
				rule +=pre2 + 's' + sub2;
				rule +=pre2 + 'f' + sub2;
				rule +=pre2 + 'r' + sub2;
				rule +=pre2 + 'x' + sub2;
				rule +=pre2 + 'j' + sub2;
				rule +=pre2 + 'a e o' + sub2;
				rule +=pre2 + 'w' + sub2;
				rule +=pre2 + 'w' + sub2;
				rule +=pre2 + 'd' + sub2;
				rule +=pre2 + 'thoát' + sub2;
				rule +='</tr>';
				rule +='</table>';
				break;
			case 2:
				document.all.Mode.innerHTML="<font color=blue>VNI</font>";
				
				rule +='<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="350" id="AutoNumber1">';
				rule += r1;
				rule +='<tr>';
				rule +=pre2 + '1' + sub2;
				rule +=pre2 + '2' + sub2;
				rule +=pre2 + '3' + sub2;
				rule +=pre2 + '4' + sub2;
				rule +=pre2 + '5' + sub2;
				rule +=pre2 + '6' + sub2;
				rule +=pre2 + '7' + sub2;
				rule +=pre2 + '8' + sub2;
				rule +=pre2 + '9' + sub2;
				rule +=pre2 + 'thoát' + sub2;
				rule +='</tr>';
				rule +='</table>';
				break;
			case 3:
				document.all.Mode.innerHTML="<font color=blue>VIQR</font>";
				rule +='<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="350" id="AutoNumber1">';
				rule += r1;
				rule +='<tr>';
				rule +=pre2 + '\'' + sub2;
				rule +=pre2 + '`' + sub2;
				rule +=pre2 + '?' + sub2;
				rule +=pre2 + '~' + sub2;
				rule +=pre2 + '.' + sub2;
				rule +=pre2 + '^' + sub2;
				rule +=pre2 + '*' + sub2;
				rule +=pre2 + '(' + sub2;
				rule +=pre2 + 'd' + sub2;
				rule +=pre2 + 'thoát' + sub2;
				rule +='</tr>';
				rule +='</table>';
				break;	
		}
		document.all.Tips.innerHTML=rule;
		
		setCookie("typingMode",mode,null);
		
		eval(editorComposition0.focus());
    }
    function ConvertVIQR2Unicode(EditorID){
		eval(EDITOR_COMPOSITION_PREFIX + EditorID).document.body.innerHTML= VIQR2Unicode(eval(EDITOR_COMPOSITION_PREFIX + EditorID).document.body.innerHTML);
	}	
	function ConvertUnicode2VIQR(EditorID){
		eval(EDITOR_COMPOSITION_PREFIX + EditorID).document.body.innerHTML= Unicode2VIQR(eval(EDITOR_COMPOSITION_PREFIX + EditorID).document.body.innerHTML);
	}	
