/*
 * ID Generator (ID 產生器)
 *
 * 用來產生唯一的ID(對同一IDGenerator而言，若在同一document中
 * 存在多個IDGenerator，它們將可能產生相同ID)。
 */

//IDGenerator Constructor
//nextID: 初始的ID值

  var sFolder  = "";        //表示此 js 存放目錄
  var sFolder1 = "";        //表示此 js 存放之絕對目錄
  var sFolder2 = "";        //表示程式所在目錄
  var path     = "images";  //圖片目錄
  var bgcolor  = "";        //背景色

  function IDGenerator(nextID){
    this.nextID = nextID;
    this.GenerateID = IDGeneratorGenerateID;
  }

//取得唯一ID
  function IDGeneratorGenerateID(){
    return this.nextID++;
  }

  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);
  }

/*
 * Button (編輯器上工具列的按鈕)
 *
 * 用來產生編輯器上工具列的按鈕，並定義按鈕圖片及動作。
 */

  var BUTTON_IMAGE_PREFIX = "buttonImage";
  var BUTTON_DIV_PREFIX   = "buttonDiv";
  var BUTTON_PAD1_PREFIX  = "buttonPad1";
  var BUTTON_PAD2_PREFIX  = "buttonPad2";
  var buttonMap = new Object();

/* Button Constructor
 * idGenerator: 要採用的IDGenerator
 * caption: 按鈕提示說明
 * action: 按下按鈕所要進行的動作
 * image: 按鈕圖片
 */

  function Button(idGenerator, caption, action, image,imageSize){
  //properties
    this.idGenerator = idGenerator;
    this.caption = caption;
    this.action = action;
    this.image = image;
    this.imageSize = imageSize;
    this.enabled = true;
  //member functions
    this.Instantiate = ButtonInstantiate;
    this.Enable = ButtonEnable;
  }

//根據建造按鈕時的定義，實際產生HTML碼
  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="'+this.imageSize +'"';
    html += '" name=Image'+this.id+'';
    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);
  }

//設定按鈕的可用狀態
//enable: 可設為true或false
  function ButtonEnable(enabled){
    this.enabled = enabled;
    if (this.enabled){
      document.all[BUTTON_DIV_PREFIX + this.id].className = "ButtonNormal";
      document.all[BUTTON_IMAGE_PREFIX + this.id].style.filter = "";
    }else{
      document.all[BUTTON_IMAGE_PREFIX + this.id].style.filter = "progid:DXImageTransform.Microsoft.Emboss(enabled='true')";
      document.all[BUTTON_DIV_PREFIX + this.id].className = "ButtonDisabled";
    }
  }

//取消按鈕被選取的狀態
  function ButtonOnSelectStart(){
    window.event.returnValue = false;
  }

//取消按鈕被拖曳的狀態
  function ButtonOnDragStart(){
    window.event.returnValue = false;
  }

//處理滑鼠按下按鈕的動作
//element: 被滑鼠按下的按鈕物件
  function ButtonOnMouseDown(element){
  //left button is pressed
/*
    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);
      }
    }
*/
  }

//處理放開滑鼠動作
//element: 釋放滑鼠時的按鈕物件
  function ButtonOnMouseUp(element){
  //left button is pressed
    if (event.button == 1){
      var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
      var button = buttonMap[id];
      if (button.enabled){
        ButtonOverButton(id);
      }
    }
  }

//處理滑鼠離開按鈕的動作
//element: 滑鼠離開的按鈕物件
  function ButtonOnMouseOut(element){
    MM_swapImgRestore();
/*
    var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
    var button = buttonMap[id];
    if (button.enabled){
      ButtonNormalButton(id);
    }
*/
  }

//處理滑鼠移至按鈕上方的動作
//element: 滑鼠下方的按鈕物件
  function ButtonOnMouseOver(element){
    var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
    var sid = "icon_"+id;
    if (id.length == 1){
      sid = "icon_0"+id;
    }

    MM_swapImage('Image'+id,'',path+'/'+sid+'s.gif',1);

/*
    var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
    var button = buttonMap[id];
    if (button.enabled){
      ButtonOverButton(id);
    }
*/
  }

//處理滑鼠在按鈕上單點的動作
//element: 滑鼠點擊的按鈕物件
  function ButtonOnClick(element){
  //element.style.display = "none";
    var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
    var button = buttonMap[id];
    if (button.enabled){
      eval(button.action);
    }
  }

//處理滑鼠在按鈕上點二下的動作
//element: 滑鼠點擊二下的按鈕物件
  function ButtonOnDblClick(element){
  //ButtonOnClick(element);
  }

//設定滑鼠移至按鈕上方時按鈕的外觀
//CSS設定參照 RichtextEditor.css
  function ButtonOverButton(id){
    document.all[BUTTON_PAD1_PREFIX + id].width = 1;
    document.all[BUTTON_PAD1_PREFIX + id].height = 1;
    document.all[BUTTON_PAD2_PREFIX + id].width = 3;
    document.all[BUTTON_PAD2_PREFIX + id].height = 3;
  //document.all[BUTTON_IMAGE_PREFIX + id].style.filter = "progid:DXImageTransform.Microsoft.dropshadow(offX=1,offY=1,Color='gray',Positive='true')";
    document.all[BUTTON_DIV_PREFIX + id].className = "ButtonMouseOver";
  }

//設定按下按鈕時按鈕的外觀
//CSS設定參照 RichtextEditor.css
  function ButtonPushButton(id){
  //document.all[BUTTON_IMAGE_PREFIX + id].style.filter = "";
  //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 = "ButtonPressed";
  }

//設定按鈕平時的外觀
//CSS設定參照 RichtextEditor.css
  function ButtonNormalButton(id){
  //document.all[BUTTON_IMAGE_PREFIX + id].style.filter = "";
    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";
  }

/*
 * Editor (HTML編輯器)
 *
 * 用來產生HTML編輯器，編輯器上方為工具列，下方則為編輯區。
 */

  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 EDITOR_TABLE_TOOL_PREFIX      = "editorTableTool";
  var editorMap = new Object();
  var editorIDArray = new Array();
  var editorIDGenerator = null;

//Editor Constructor
//idGenerator: 要採用的IDGenerator
//textID: 和編輯器關連的HTML物件id，通常是textarea
//        編輯區的初始內容將會從該物件的value取得
//edHeight: 編輯區的高度，預設為250px
  function Editor(idGenerator, textID, edHeight){
  //properties
    this.idGenerator = idGenerator;
    this.textMode = false;
    this.brief = false;
    this.instantiated = false;
    this.height = edHeight || 250;
    this.textID = textID;
  //member functions
    this.Instantiate = EditorInstantiate;
    this.GetText = EditorGetText;
    this.SetText = EditorSetText;
    this.GetHTML = EditorGetHTML;
    this.SetHTML = EditorSetHTML;
    this.GetBrief = EditorGetBrief;
    this.SetBrief = EditorSetBrief;
  }

//根據建造按鈕時的定義，實際產生HTML碼
  function EditorInstantiate(){
    if (this.instantiated){
      return;
    }
    this.id = this.idGenerator.GenerateID();
    editorMap[this.id] = this;
    editorIDArray[editorIDArray.length] = this.id;
    editorIDGenerator = this.idGenerator;

    var html = "";

  //編輯器起始點
  //CSS設定參照RichtextEditor.css
    html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
    html += "<tr>";
    html += "<td class=\"Text\" nowrap>";
  //html += "<input type=\"checkbox\" onclick=\"EditorOnViewHTMLSource(" + this.id + ", this.checked)\">";
    html += "<span id=textmode><a href=javascript:EditorOnViewHTMLSource(0,1)><font size=-1>文字模式(原始碼)</font></a>&nbsp;&nbsp;&nbsp;</span>";
    html += "<span id=htmlmode><strong><font size=-1>HTML編輯器</font></strong></span>";
    html += "</td>";
    html += "</tr>";
  //第一行工具列開始
    html += "<tr>";
    html += "<td id=\"" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar1\">";
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  //html += "</td>";
  //加入"剪下"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var cutButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"剪下\",";
    html += "\"EditorOnCut(" + this.id + ")\",";
    html += "\""+path+"/icon_01.gif\"";
    html += ",\"Image1\");";
    html += "cutButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"複製"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var copyButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"複製\",";
    html += "\"EditorOnCopy(" + this.id + ")\",";
    html += "\""+path+"/icon_02.gif\"";
    html += ",\"Image1\");";
    html += "copyButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"貼上"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var pasteButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"貼上\",";
    html += "\"EditorOnPaste(" + this.id + ")\",";
    html += "\""+path+"/icon_03.gif\"";
    html += ",\"Image1\");";
    html += "pasteButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    html += "</td>";
  //加入"復原"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var undoButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"復原\",";
    html += "\"EditorOnUndo(" + this.id + ")\",";
    html += "\""+path+"/icon_04.gif\"";
    html += ",\"Image1\");";
    html += "undoButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"重做"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var redoButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"取消復原\",";
    html += "\"EditorOnRedo(" + this.id + ")\",";
    html += "\""+path+"/icon_05.gif\"";
    html += ",\"Image1\");";
    html += "redoButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    html += "</td>";
  //加入"網頁背景圖"工具按鈕
/*
    html += "<td>";
    html += UtilBeginScript();
    html += "var createBGPicButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"網頁背景圖\",";
    html += "\"EditorOnBGPic(" + this.id + ")\",";
    html += "\""+path+"/icon_07.gif\"";
    html += ",\"Image1\");";
    html += "createBGPicButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
*/
  //加入"建立超連結"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var createHyperlinkButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"建立超連結\",";
    html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
    html += "\""+path+"/icon_06.gif\"";
    html += ",\"Image1\");";
    html += "createHyperlinkButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"建立超連結"工具按鈕
/*
    html += "<td>";
    html += UtilBeginScript();
    html += "var createHyperlinkButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"建立超連結\",";
    html += "\"EditorOnCreateHyperlink(" + this.id + ")\",";
    html += "\""+path+"/icon_09.gif\"";
    html += ",\"Image1\");";
    html += "createHyperlinkButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
*/
  //加入"插入圖片"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var createImageButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"插入圖片\",";
    html += "\"EditorImage(" + this.id + ")\",";
    html += "\""+path+"/icon_07.gif\"";
    html += ",\"Image1\");";
    html += "createImageButton.Instantiate();";
    html += UtilEndScript();
    html += "<input type=\"hidden\" id=\"obj_image_s\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"obj_image_b\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"obj_image_note\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"obj_youtube_code\" class=\"Text\" size=\"1\">";
    html += "</td>";
  //加入"插入表單控制項"工具
/*
    html += "<td>";
    html += "<select class=\"List\" onchange=\"EditorOnFormInput(" + this.id + ", this)\">";
    html += "<option class=\"Heading\">插入表單控制項</option>";
    html += "<option value=\"InsertInputText\">文字輸入項</option>";
    html += "<option value=\"InsertTextArea\">文字區塊</option>";
    html += "<option value=\"InsertInputButton\">按鈕</option>";
    html += "<option value=\"InsertInputRadio\">選鈕</option>";
    html += "<option value=\"InsertInputCheckbox\">核取方塊</option>";
    html += "<option value=\"InsertSelectDropdown\">下拉選單</option>";
    html += "<option value=\"InsertSelectListbox\">清單列表</option>";
    html += "<option value=\"InsertInputPassword\">密碼輸入項</option>";
    html += "<option value=\"InsertInputSubmit\">送出按鈕</option>";
    html += "<option value=\"InsertInputReset\">取消按鈕</option>";
    html += "</select>";
    html += "</td>";
  //加入"文字區塊"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var createTextAreaButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"插入文字區塊\",";
    html += "\"EditorOnTextArea(" + this.id + ")\",";
    html += "\""+path+"/icon_08.gif\"";
    html += ",\"Image1\");";
    html += "createTextAreaButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "<td>";
    html += UtilBeginScript();
    html += "var createBGPicButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"插入表格\",";
    html += "\"EDITOR_TABLE_TOOL_PREFIX(" + this.id + ")\",";
    html += "\""+path+"/icon_12.gif\"";
    html += ",\"Image1\");";
    html += "EditorOnTable();";
    html += UtilEndScript();
    html += "</td>";
*/
  //加入"插入表格"工具
    html += "<td>";
    html += UtilBeginScript();
    html += "var createTableButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"插入表格\",";
    html += "\"EditorOnTable(" + this.id + ")\",";
    html += "\""+path+"/icon_08.gif\"";
    html += ",\"Image1\");";
    html += "createTableButton.Instantiate();";
    html += UtilEndScript();
    html += "<input type=\"hidden\" id=\"row\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"col\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"width\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"widthtype\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"border\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"padding\" class=\"Text\" size=\"1\">";
    html += "<input type=\"hidden\" id=\"spacing\" class=\"Text\" size=\"1\">";
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    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 += "\"編號列表\",";
    html += "\"EditorOnNumberedList(" + this.id + ")\",";
    html += "\""+path+"/icon_13.gif\"";
    html += ",\"Image2\");";
    html += "numberedListButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分項列表"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var bullettedListButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"分項列表\",";
    html += "\"EditorOnBullettedList(" + this.id + ")\",";
    html += "\""+path+"/icon_14.gif\"";
    html += ",\"Image2\");";
    html += "bullettedListButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src=\"/images/hr-2.gif\" width=\"2\" >";
    html += "</td>";
  //加入"減少縮排"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var decreaseIndentButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"減少縮排\",";
    html += "\"EditorOnDecreaseIndent(" + this.id + ")\",";
    html += "\""+path+"/icon_15.gif\"";
    html += ",\"Image2\");";
    html += "decreaseIndentButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"增加縮排"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var increaseIndentButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"增加縮排\",";
    html += "\"EditorOnIncreaseIndent(" + this.id + ")\",";
    html += "\""+path+"/icon_16.gif\"";
    html += ",\"Image2\");";
    html += "increaseIndentButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</td>";
*/
  //進階工具結束

/*
   html += "<td>";
   html += "<input type=\"text\" class=\"Text\" id=\"" + EDITOR_TABLE_TOOL_PREFIX + this.id + "_r\" size=1>";
             html += "<span class=\"Text\">X</span>";
   html += "<input type=\"text\" class=\"Text\" id=\"" + EDITOR_TABLE_TOOL_PREFIX + this.id + "_c\" size=1>";
             html += "<input type=\"button\" class=\"Text\" id=\"" + EDITOR_TABLE_TOOL_PREFIX + this.id + "\" value=\"插入表格\" onclick=\"EditorOnTable(" + this.id + ")\">";
   html += "</td>";
*/
/*
  //加入"檢查HTML原始檔"工具按鈕
    html += "<td class=\"Text\" nowrap>";
    html += "<input type=\"checkbox\" onclick=\"EditorOnViewHTMLSource(" + this.id + ", this.checked)\">";
    html += "檢視HTML原始檔";
    html += "</td>";
*/
    html += "</tr>";
    html += "</table>";
    html += "</td>";
    html += "</tr>";
  //第一行工具列結束
  //第二行工具列開始
    html += "<tr>";
    html += "<td id=\"" + EDITOR_BOTTOM_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar2\">";
    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=\"EditorOnFont(" + this.id + ", this)\" id=fontname_1>";
    html += "<option class=\"Heading\">字型</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=\"Verdana\">Verdana</option>";
    html += "<option value=\"Wingdings\">Wingdings</option>";
    html += '<option value=\"細明體\">細明體</option>';
    html += '<option value=\"新細明體\" selected>新細明體</option>';
    html += '<option value=\"標楷體\">標楷體</options>';
    html += "</select>";
    html += "</td>";
  //加入"字體大小選擇"工具
    html += "<td>";
    html += "<select class=\"List\" onchange=\"EditorOnSize(" + this.id + ", this)\" id=fontsize_1>";
    html += "<option class=\"Heading\">大小</option>";
    html += "<option value=\"1\">1</option>";
    html += "<option value=\"2\" selected>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>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    html += "</td>";
  //加入"粗體"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var boldButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"粗體\",";
    html += "\"EditorOnBold(" + this.id + ")\",";
    html += "\""+path+"/icon_09.gif\"";
    html += ",\"Image2\");";
    html += "boldButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"斜體"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var italicButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"斜體\",";
    html += "\"EditorOnItalic(" + this.id + ")\",";
    html += "\""+path+"/icon_10.gif\"";
    html += ",\"Image2\");";
    html += "italicButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"底線"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var underlineButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"底線\",";
    html += "\"EditorOnUnderline(" + this.id + ")\",";
    html += "\""+path+"/icon_11.gif\"";
    html += ",\"Image2\");";
    html += "underlineButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    html += "</td>";
  //加入"字體顏色"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var foregroundColorButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"字體顏色\",";
    html += "\"EditorOnForegroundColor(" + this.id + ")\",";
    html += "\""+path+"/icon_12.gif\"";
    html += ",\"Image2\");";
    html += "foregroundColorButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"字底顏色"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var backgroundColorButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"字底顏色\",";
    html += "\"EditorOnBackgroundColor(" + this.id + ")\",";
    html += "\""+path+"/icon_13.gif\"";
    html += ",\"Image2\");";
    html += "backgroundColorButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"分隔"
    html += "<td>";
    html += "<img src="+path+"\"/hr-2.gif\" width=\"2\" >";
    html += "</td>";
 //加入"靠左對齊"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var alignLeftButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"靠左對齊\",";
    html += "\"EditorOnAlignLeft(" + this.id + ")\",";
    html += "\""+path+"/icon_14.gif\"";
    html += ",\"Image2\");";
    html += "alignLeftButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"置中"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var centerButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"置中\",";
    html += "\"EditorOnCenter(" + this.id + ")\",";
    html += "\""+path+"/icon_15.gif\"";
    html += ",\"Image2\");";
    html += "centerButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
  //加入"靠右對齊"工具按鈕
    html += "<td>";
    html += UtilBeginScript();
    html += "var alignRightButton = new Button(";
    html += "editorIDGenerator,";
    html += "\"靠右對齊\",";
    html += "\"EditorOnAlignRight(" + this.id + ")\",";
    html += "\""+path+"/icon_16.gif\"";
    html += ",\"Image2\");";
    html += "alignRightButton.Instantiate();";
    html += UtilEndScript();
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</td>";
    html += "</tr>";
  //第二行工具列結束
  //編輯區開始
    html += "<tr>";
    html += "<td>";
  //編輯區主體為一iframe 編輯區寬度：680
    html += "<iframe id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"680\" height=\"" + this.height + "\">";
  //html += "<iframe onfocus=\"clickToPaste(0)\" id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"100%\" height=\"" + this.height + "\">";
    html += "</iframe>";
    html += "</td>";
    html += "</tr>";
  //編輯區結束
    html += "</table>";
  //編輯器結束

  //在網頁上產生編輯器
    document.write(html);

  //初始化編輯區
    html = '';
  //html += '<body oncontextmenu="return false">';

    if (document.all[this.textID].value){
      html += '';
    }else{
    //html += '<font name=新細明體 size=2>';
      html += '';
    }

  //若有關連的物件，取得其value作為編輯區的初始值
    if (this.textID){
      html += document.all[this.textID].value;
    }
    if (document.all[this.textID].value){
      html += '';
    }else{
    //html += '</font>';
      html += '';
    }

    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();

  //設定編輯區的document為編輯模式
    eval(EDITOR_COMPOSITION_PREFIX + this.id).document.designMode = "on";
    EditorAfterInstantiate(this.id);

    editorIDGenerator = null;
    this.instantiated = true;
  }

//在展現編輯器後的動作
  function EditorAfterInstantiate(id){
    if (eval(EDITOR_COMPOSITION_PREFIX + id).document.readyState != 'complete'){
      window.setTimeout('EditorAfterInstantiate(' + id + ')', 50);
      return;
    }
    eval(EDITOR_COMPOSITION_PREFIX + id).document.body.attachEvent('oncontextmenu', new Function('return false;'));
  }

//取得編輯區內的文字內容
  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;
  }

//取得編輯區內的HTML內容
  function EditorGetHTML(){
    if (this.textMode){
    //return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
      return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.outerText;
    }
  //return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML;
    return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.outerHTML;
  }

//設定編輯區內的HTML內容
  function EditorSetHTML(html){
    if (this.textMode){
    //eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText = html;
      eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.outerText = html;
    }else{
    //eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = html;
      eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.outerHTML = html;
    }
  }

//取得目前編輯器是否在精簡模式
  function EditorGetBrief(){
    return this.brief;
  }

//設定目前編輯器是否在精簡模式
//brief: true表示切換成精簡模式，false表示切換成一般模式
  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;
    }
  }

//處理Undo的動作
  function EditorOnUndo(id){
  //EditorFormat(id, "undo");
    eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand("undo");
  }

//處理Redo的動作
  function EditorOnRedo(id){
  //EditorFormat(id, "redo");
    eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand("redo");
  }

//處理Cut的動作
  function EditorOnCut(id){
    EditorFormat(id, "cut");
  }

//處理Copy的動作
  function EditorOnCopy(id){
    EditorFormat(id, "copy");
  }

//處理Paste的動作
  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){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
  //開啟顏色選擇對話盒
  //若內容網頁路徑有更動，這裡需修正
    var color = showModalDialog("main_tools_color_select.php", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:25em");
    if (color){
      EditorFormat(id, "forecolor", color);
    }else{
      eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    }
  }

//處理設定字體背景色的動作
  function EditorOnBackgroundColor(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
  //開啟顏色選擇對話盒
  //若內容網頁路徑有更動，這裡需修正
    var color = showModalDialog("main_tools_color_select.php", "", "font-family:Verdana;font-size:12;dialogWidth:30em;dialogHeight:25em");
    if (color){
      EditorFormat(id, "backcolor", color);
    }else{
      eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    }
  }

//處理插入圖片的動作，先另開一視窗，填入圖片網址，再將值傳回
  function EditorImage(id){
    popupwin = window.open('main_tools_upload.php?id='+id+'&mode=image_insert','table_image','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=790,height=534');
  }

  function EditorImage1(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
    var obj_image_s = document.all["obj_image_s"].value;
    var obj_image_b = document.all["obj_image_b"].value;
    var obj_image_note = document.all["obj_image_note"].value;
    var imageTag;

    imageTag = '<a href="' + obj_image_b + '" title="' + obj_image_note + '" rel="thickbox"><img src="' + obj_image_s + '" border="0"></a>';

    EditorInsertHTML(id, imageTag);
  }

  function EditorImage2(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
    var obj_image_s = document.all["obj_image_s"].value;
    var imageTag;

    imageTag = '<img src="' + obj_image_s + '">';

    EditorInsertHTML(id, imageTag);
  }

  function EditorImage3(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
    var obj_youtube_code = document.all["obj_youtube_code"].value;
    var imageTag;

    imageTag = obj_youtube_code;

    EditorInsertHTML(id, imageTag);
  }

//處理設定網頁背景圖的動作
  function EditorOnBGPic(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
    var wnd = window.open("bg_library.html","BGLib","width=550,height=480,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
    wnd.moveTo(0,0);
    window.BGLibCaller = id;
    wnd.focus();
  }

  function EditorSetBGPic(id, pic){
    if (!pic) pic = '';

    var editor = editorMap[id];
    eval(EDITOR_COMPOSITION_PREFIX + id).document.body.background = pic;
    editor.background = pic;
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
  }

//處理插入表單控制項的動作
  function EditorOnFormInput(id, select){
    EditorFormat(id, select[select.selectedIndex].value);
    select.selectedIndex = 0;
  }

//處理插入HTML至編輯區的動作
  function EditorInsertHTML(id, html){
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    var oCurrSel = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection;
    if (oCurrSel.type != "Control"){
      var oTextRange = oCurrSel.createRange();
      var oParent = oTextRange.parentElement();
      if (oParent && (oParent.tagName != "BODY" && oParent.isTextEdit)){
        alert("在此僅支援文字編輯，無法插入HTML物件");
        return;
      }else{
        oTextRange.pasteHTML(html);
        oTextRange.select();
      }
    }else{
      var oElement = oCurrSel.createRange().item(0);
      if (oElement && oElement.outerHTML){
        oElement.outerHTML = html;
      }
    }
  }

//處理插入文字區塊的動作
  function EditorOnTextArea(id){
    if (!EditorValidateMode(id)) return;

    var html = '<textarea style="border-width:0px;overflow:visible"></textarea>';

    EditorInsertHTML(id, html);
  }

//將另開的視窗關閉
  function doCloseWin(){
    popupwin.close();
  }

//處理插入表格的動作，先另開一視窗，填入適當寬高，再將值傳回
  function EditorOnTable(id){
    popupwin = window.open('main_tools_table.php?id='+id,'table_size','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=360,height=220');
  }

  function EditorOnTable1(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
  //var row = document.all[EDITOR_TABLE_TOOL_PREFIX + id + "_r"].value;
  //var col = document.all[EDITOR_TABLE_TOOL_PREFIX + id + "_c"].value;
    var row = document.all["row"].value;
    var col = document.all["col"].value;
    var width = document.all["width"].value;
    var widthtype = (document.all["widthtype"].value=="pixels") ? "" : "%";
    var border = document.all["border"].value;
    var padding = document.all["padding"].value;
    var spacing = document.all["spacing"].value;

    var pattern = /[^\d]/i;
    var tableTag, tdWidth;

    if (pattern.test(row) || Number(row) <= 0 ){
      alert("表格列的數目請填入大於零的數字");
    //document.all[EDITOR_TABLE_TOOL_PREFIX + id + "_r"].focus();
      return;
    }else if (pattern.test(col) || Number(col) <= 0){
      alert("表格欄的數目請填入大於零的數字");
    //document.all[EDITOR_TABLE_TOOL_PREFIX + id + "_c"].focus();
      return;
    }

    row = Number(row);
    col = Number(col);
    tdWidth = Math.floor(100 / col);

    tableTag = '<table border="' + border + '" width="' + width + widthtype + '" cellspacing="' + spacing + '" cellpadding="' + padding + '">';
    for (var i = 0; i < row; i++){
      tableTag += '<tr>';
      for (var j = 0; j < col; j++)
      tableTag += (j == col - 1) ? '<td></td>' : '<td width="' + tdWidth + '%"></td>';
      tableTag += '</tr>';
    }
    tableTag += '</table>';

    EditorInsertHTML(id, tableTag);
  }

//處理段落靠左對齊的動作
  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 EditorOnInnerUrl(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
  //取得先前設定的連結
    var oCurrSel = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection;
  //oCurrSel.createRange().execCommand("CreateLink",true);
    var anchor;
    var oTextRange;

    if (oCurrSel.type == "None" || oCurrSel.type == "Text"){
      anchor = EditorGetElement("A", oCurrSel.createRange().parentElement());
      if (!anchor && oCurrSel.type == "None"){
        alert("請先選擇要設定鏈結的文字或圖片");
        return;
      }
      if (anchor){
        oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
        oTextRange.moveToElementText(anchor);
      }else{
        oTextRange = oCurrSel.createRange();
      }
    }else{
      anchor = EditorGetElement("A", oCurrSel.createRange().item(0));
      oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();

      if (anchor){
        oTextRange.moveToElementText(anchor);
      }else{
        oTextRange.moveToElementText(oCurrSel.createRange().item(0));
      }
    }
    oTextRange.select();

  //var link = prompt("加入網站連結 (如 http://www.goodnews.org.tw)：", anchor ? anchor.href : "http://");
  //原來的鏈結
    var sOldLink = anchor ? anchor.href : "none";
  //跳出檔案列表視窗
    popupwin = window.open(sFolder2+'/select_inner_link.html?id='+id+'&sLink='+sOldLink,'table_size','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=195,height=380');
    popupwin.moveTo(0,0);
  }

//處理設定內部連結的動作
  function EditorOnSetInnerUrl(id,sFile){
  //取得先前設定的連結
    var oCurrSel = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection;
  //oCurrSel.createRange().execCommand("CreateLink",true);
    var anchor;
    var oTextRange;
    if (oCurrSel.type == "None" || oCurrSel.type == "Text"){
      anchor = EditorGetElement("A", oCurrSel.createRange().parentElement());
      if (!anchor && oCurrSel.type == "None"){
        alert("請先選擇要設定鏈結的文字或圖片");
        return;
      }
      if (anchor){
        oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
        oTextRange.moveToElementText(anchor);
      }else{
        oTextRange = oCurrSel.createRange();
      }
    }else{
      anchor = EditorGetElement("A", oCurrSel.createRange().item(0));
      oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();

      if (anchor){
        oTextRange.moveToElementText(anchor);
      }else{
        oTextRange.moveToElementText(oCurrSel.createRange().item(0));
      }
    }
    oTextRange.select();

    link = sFile;
    if (link && link != "http://"){
      oTextRange.execCommand("CreateLink", false, link);
    }else if (link == ""){
      oTextRange.execCommand("Unlink");
    }
  }

//處理固定版型
  function EditorOnFixTemp(id){
  //alert("將儘速開發!!");
  //var wnd = window.open(sFolder+"selectSample.html?status=0","BGLib","width=400,height=200,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
  //var wnd = window.open(sFolder+"selectSample.html?status=0&sTitle="+document.editors.PageName.value,"BGLib","width=450,height=600,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
    var wnd = window.open(sFolder+"index_sample.html?status=0&sTitle="+document.editors.PageName.value,"BGLib","width=500,height=500,location=no,menubar=no,resizable=no,scrollbars=no,status=yes,toolbar=no");
    wnd.moveTo(0,0);
    wnd.focus();
}

//幫助
  function EditorOnHelp(id){
    var wnd = window.open(sFolder+"help/index.htm","BGLib","width=800,height=500,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
    wnd.moveTo(0,0);
    wnd.focus();
  }

//將另開的視窗關閉
  function doCloseWnd(){
    wnd.close();
  }

//處理設定連結的動作
  function EditorOnCreateHyperlink(id){
  //若目前是在HTML原始檔編輯模式，則不處理
    if (!EditorValidateMode(id)){
      return;
    }
  //取得先前設定的連結
    var oCurrSel = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection;
  //oCurrSel.createRange().execCommand("CreateLink",true);
    var anchor;
    var oTextRange;
    if (oCurrSel.type == "None" || oCurrSel.type == "Text"){
      anchor = EditorGetElement("A", oCurrSel.createRange().parentElement());
      if (!anchor && oCurrSel.type == "None"){
        alert("請先選擇要設定鏈結的文字或圖片");
        return;
      }
      if (anchor){
        oTextRange = oCurrSel.createRange();
      //oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
      //oTextRange.moveToElementText(anchor);
      }else{
        oTextRange = oCurrSel.createRange();
      }
    }else{
      anchor = EditorGetElement("A", oCurrSel.createRange().item(0));
      oTextRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.createTextRange();
      if (anchor){
        oTextRange.moveToElementText(anchor);
      }else{
        oTextRange.moveToElementText(oCurrSel.createRange().item(0));
      }
    }
    oTextRange.select();
  //產生連結設定對話盒
    var link = prompt("加入網站連結 (如 http://www.goodnews.org.tw)：", 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);
      }
*/
      oTextRange.execCommand("CreateLink", false, link);
    }else if (link == ""){
      oTextRange.execCommand("Unlink");
    }
  }

//處理字型設定的動作
  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;
  }

//處理檢視HTML原始檔的動作
  function EditorOnViewHTMLSource(id, textMode){
    if(textMode){
      document.all.buttonDiv1.style.display = "none";
      document.all.buttonDiv2.style.display = "none";
      document.all.buttonDiv3.style.display = "none";
      document.all.buttonDiv4.style.display = "none";
      document.all.buttonDiv5.style.display = "none";
      document.all.buttonDiv6.style.display = "none";
      document.all.buttonDiv7.style.display = "none";
      document.all.buttonDiv8.style.display = "none";
      document.all.buttonDiv9.style.display = "none";
      document.all.buttonDiv10.style.display = "none";
      document.all.buttonDiv11.style.display = "none";
      document.all.buttonDiv12.style.display = "none";
      document.all.buttonDiv13.style.display = "none";
      document.all.buttonDiv14.style.display = "none";
      document.all.buttonDiv15.style.display = "none";
      document.all.buttonDiv16.style.display = "none";
      document.all.fontname_1.style.display = "none";
      document.all.fontsize_1.style.display = "none";
      document.all['textmode'].innerHTML="<strong><font size=-1>文字模式(原始碼)&nbsp;&nbsp;&nbsp;</font></strong>";
      document.all['htmlmode'].innerHTML="<a href=javascript:EditorOnViewHTMLSource(0,0)><font size=-1>HTML編輯器</font></a>";
      document.all[EDITOR_COMPOSITION_PREFIX + 0].height=310;
    }else{
      document.all.buttonDiv1.style.display = "block";
      document.all.buttonDiv2.style.display = "block";
      document.all.buttonDiv3.style.display = "block";
      document.all.buttonDiv4.style.display = "block";
      document.all.buttonDiv5.style.display = "block";
      document.all.buttonDiv6.style.display = "block";
      document.all.buttonDiv7.style.display = "block";
      document.all.buttonDiv8.style.display = "block";
      document.all.buttonDiv9.style.display = "block";
      document.all.buttonDiv10.style.display = "block";
      document.all.buttonDiv11.style.display = "block";
      document.all.buttonDiv12.style.display = "block";
      document.all.buttonDiv13.style.display = "block";
      document.all.buttonDiv14.style.display = "block";
      document.all.buttonDiv15.style.display = "block";
      document.all.buttonDiv16.style.display = "block";
      document.all.fontname_1.style.display = "block";
      document.all.fontsize_1.style.display = "block";
      document.all[EDITOR_COMPOSITION_PREFIX + 0].height=250;
      document.all['textmode'].innerHTML="<a href=javascript:EditorOnViewHTMLSource(0,1)><font size=-1>文字模式(原始碼)</font></a>&nbsp;&nbsp;&nbsp;";
      document.all['htmlmode'].innerHTML="<strong><font size=-1>HTML編輯器</font></strong>";
    }

    var editor = editorMap[id];
    var editorDoc = eval(EDITOR_COMPOSITION_PREFIX + id).document;
    editor.textMode = textMode;
    if (editor.textMode){
      editorDoc.body.innerText = editorDoc.body.innerHTML;
      editorDoc.body.bgColor = "";
      editorDoc.body.background = "";
    }else{
      editorDoc.body.innerHTML = editorDoc.body.innerText;
      if (editor.bgColor) editorDoc.body.bgColor = editor.bgColor;
      if (editor.background) editorDoc.body.background = editor.background;
    }
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
  }

//判斷目前是否在一般編輯模式，若是則傳回true，否則傳回false
  function EditorValidateMode(id){
    var editor = editorMap[id];
  //if (!editor.textMode){
  //  return true;
  //}
  //alert("請先取消勾選 \"編輯HTML原始檔\"");
  //eval(EDITOR_COMPOSITION_PREFIX + id).focus();
  //return false;
    return true;
  }

//執行document的execCommand來完成編輯動作
  function EditorFormat(id, what, opt){
    if (what != "cut" && what != "copy" && what != "paste" && what != "undo" && what != "redo" && !EditorValidateMode(id)){
      return;
    }
    if (opt == "removeFormat"){
      what = opt;
      opt = null;
    }
    eval(EDITOR_COMPOSITION_PREFIX + id).focus();
    var oRange = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
    if (opt == null){
    //eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what);
      oRange.execCommand(what);
    }else{
    //eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what, "", opt);
      oRange.execCommand(what, "", opt);
    }
  }

//從start物件開始往物件階層上層尋找標籤名稱為tagName的物件
  function EditorGetElement(tagName, start){
    while (start && start.tagName != tagName){
      start = start.parentElement;
    }
    return start;
  }

//將編輯區的內容輸出至關連物件的value
//通常在將表單(form)送出前需呼叫此function
  function EditorExportHTML(){
    for (i = 0; i < editorIDArray.length; i++){
      var editor = editorMap[editorIDArray[i]];
      var txt = editor.GetHTML();
      document.all[editor.textID].value = editor.GetHTML();
    }
  //var tmp=document.all[editor.textID].value;
  //var re=/<p><\/p>/i;
  //var index = tmp.search(re);
  //alert(index);
  //var tmp=document.all[editor.textID].value;
  //var re=/^<table id=goods_comment width=100% bgcolor=/i;
  //re = /<table id=goods_comment width=100% bgcolor=/;
  //var index = tmp.search(re);
  //alert(index);
  //alert(document.all[editor.textID].value);
  //alert(re.test(document.all[editor.textID].value));
  //return false;
    if(bgcolor)document.all[editor.textID].value="<table id=goods_comment width=100% bgcolor="+bgcolor+"><tr><td>"+document.all[editor.textID].value+"</tr></td></table>";
  }