//--------------------------------------------------------------------------------------------------
// Editor
//--------------------------------------------------------------------------------------------------
function clearEditWindow()
{
  try {
    // clear edit window
    if(userMode == 1) {
      editor.editWrite("");
    } else {
      document.getElementById("display").contentWindow.document.body.innerHTML = "";
    }
  } catch(e) {}
}

function editOnMouseDown(e)
{
  try {
    if(toolbarsStandard)
      toolbarsStandard.reset();
    if(toolbarsTOC)
      toolbarsTOC.reset();
    if(toolbarsEditor1)
      toolbarsEditor1.reset();
    if(toolbarsEditor2)
      toolbarsEditor2.reset();
    if(toolbarsEditor3)
      toolbarsEditor3.reset();
    if(toolbarsEditor4)
      toolbarsEditor4.reset();

    if(objMenuBar) {
      var objMenu = objMenuBar.getActiveBarItem();
      if(objMenu)
        objMenu.reset();
    }

    tree.hideContextMenu();

    // set editor tab active
    var activeTab = objTabMain.getActiveTab();
    if(activeTab != 2 && activeTab != 3 && activeTab != 4) {
      // set toc tab active
      objTabMain.setActiveTab(2);
      // call event
      activateTab(objTabMain.getTabItemByIndex(2));
    }

  } catch (Error) { }

  if (useRibbon) {
    try {
      ribbon.reset();
      ribbon.getElementByTagName("EDITOR").setActive();
    } catch (e) {
    }
  }
}

function editOnChangeToolbar(window,data)
{
  if (useRibbon) {
    try {
      var aData = data.split(":");
      var obj = ribbon.getElementByTagName("FONT");
      var value = aData[13];
      if (value == "")
        value = "Times New Roman";
      obj.setSelectedText(value);

      obj = ribbon.getElementByTagName("FONTSIZE");
      obj.setSelectedText(aData[14].substring(0,aData[14].length-2));

      obj = ribbon.getElementByTagName("BOLD");
      obj.setStatus(aData[0] > 0 ? true : false);
      obj = ribbon.getElementByTagName("ITALIC");
      obj.setStatus(aData[1] > 0 ? true : false);

//      if (cmbFontSize)
//        cmbFontSize.setText(aData[14]);
//      if (cmbStyle)
//        cmbStyle.setSelectedText(aData[11]);
//      if (cmbFormat)
//        cmbFormat.setSelectedText(aData[12]);
//      // set button status
//      if (btnItalic)
//        btnItalic.setStatus(aData[1] > 0 ? true : false);
//      if (btnUnderline)
//        btnUnderline.setStatus(aData[2] > 0 ? true : false);
//      if (btnStrike)
//        btnStrike.setStatus(aData[19] > 0 ? true : false);
//      if (btnSuperscript)
//        btnSuperscript.setStatus(aData[3] > 0 ? true : false);
//      if (btnSubscript)
//        btnSubscript.setStatus(aData[4] > 0 ? true : false);
//      if (btnJustifyLeft)
//        btnJustifyLeft.setStatus(aData[5] > 0 ? true : false);
//      if (btnJustifyCenter)
//        btnJustifyCenter.setStatus(aData[6] > 0 ? true : false);
//      if (btnJustifyRight)
//        btnJustifyRight.setStatus(aData[7] > 0 ? true : false);
//      if (btnJustifyFull)
//        btnJustifyFull.setStatus(aData[8] > 0 ? true : false);
//      if (btnInsertOrderedList)
//        btnInsertOrderedList.setStatus(aData[9] > 0 ? true : false);
//      if (btnInsertUnorderedList)
//        btnInsertUnorderedList.setStatus(aData[10] > 0 ? true : false);

//      // set combo
//      //if(btnColor)
//      //	btnColor.setColor(aData[15]);
//      //if(btnBackColor)
//      //	btnBackColor.setColor(aData[16]);
//      if (btnRowB)
//        btnRowB.setEnabled(aData[17] == "1" ? true : false);
//      if (btnRowA)
//        btnRowA.setEnabled(aData[17] == "1" ? true : false);
//      if (btnRowDelete)
//        btnRowDelete.setEnabled(aData[17] == "1" ? true : false);
//      if (btnColB)
//        btnColB.setEnabled(aData[17] == "1" ? true : false);
//      if (btnColA)
//        btnColA.setEnabled(aData[17] == "1" ? true : false);
//      if (btnColDelete)
//        btnColDelete.setEnabled(aData[17] == "1" ? true : false);
//      if (btnCellDelete)
//        btnCellDelete.setEnabled(aData[17] == "1" ? true : false);
//      if (btnCellAdd)
//        btnCellAdd.setEnabled(aData[17] == "1" ? true : false);
//      if (btnColSpan)
//        btnColSpan.setEnabled(aData[17] == "1" ? true : false);
//      if (btnCellDivide)
//        btnCellDivide.setEnabled(aData[17] == "1" ? true : false);
//      if (btnRowSpan)
//        btnRowSpan.setEnabled(aData[17] == "1" ? true : false);
//      if (btnCellConvert)
//        btnCellConvert.setEnabled(aData[17] == "1" ? true : false);
//      if (btnCellProp)
//        btnCellProp.setEnabled(aData[17] == "1" ? true : false);
//      if (btnTableProp)
//        btnTableProp.setEnabled(aData[18] == "1" ? true : false);
    } catch (e) { }
  } else {
    try {
      var aData = data.split(":");
      if (cmbFont)
        cmbFont.setSelectedText(aData[13]);
      if (cmbFontSize)
        cmbFontSize.setText(aData[14]);
      if (cmbStyle)
        cmbStyle.setSelectedText(aData[11]);
      if (cmbFormat)
        cmbFormat.setSelectedText(aData[12]);
      // set button status
      if (btnBold)
        btnBold.setStatus(aData[0] > 0 ? true : false);
      if (btnItalic)
        btnItalic.setStatus(aData[1] > 0 ? true : false);
      if (btnUnderline)
        btnUnderline.setStatus(aData[2] > 0 ? true : false);
      if (btnStrike)
        btnStrike.setStatus(aData[19] > 0 ? true : false);
      if (btnSuperscript)
        btnSuperscript.setStatus(aData[3] > 0 ? true : false);
      if (btnSubscript)
        btnSubscript.setStatus(aData[4] > 0 ? true : false);
      if (btnJustifyLeft)
        btnJustifyLeft.setStatus(aData[5] > 0 ? true : false);
      if (btnJustifyCenter)
        btnJustifyCenter.setStatus(aData[6] > 0 ? true : false);
      if (btnJustifyRight)
        btnJustifyRight.setStatus(aData[7] > 0 ? true : false);
      if (btnJustifyFull)
        btnJustifyFull.setStatus(aData[8] > 0 ? true : false);
      if (btnInsertOrderedList)
        btnInsertOrderedList.setStatus(aData[9] > 0 ? true : false);
      if (btnInsertUnorderedList)
        btnInsertUnorderedList.setStatus(aData[10] > 0 ? true : false);

      // set combo
      //if(btnColor)
      //	btnColor.setColor(aData[15]);
      //if(btnBackColor)
      //	btnBackColor.setColor(aData[16]);
      if (btnRowB)
        btnRowB.setEnabled(aData[17] == "1" ? true : false);
      if (btnRowA)
        btnRowA.setEnabled(aData[17] == "1" ? true : false);
      if (btnRowDelete)
        btnRowDelete.setEnabled(aData[17] == "1" ? true : false);
      if (btnColB)
        btnColB.setEnabled(aData[17] == "1" ? true : false);
      if (btnColA)
        btnColA.setEnabled(aData[17] == "1" ? true : false);
      if (btnColDelete)
        btnColDelete.setEnabled(aData[17] == "1" ? true : false);
      if (btnCellDelete)
        btnCellDelete.setEnabled(aData[17] == "1" ? true : false);
      if (btnCellAdd)
        btnCellAdd.setEnabled(aData[17] == "1" ? true : false);
      if (btnColSpan)
        btnColSpan.setEnabled(aData[17] == "1" ? true : false);
      if (btnCellDivide)
        btnCellDivide.setEnabled(aData[17] == "1" ? true : false);
      if (btnRowSpan)
        btnRowSpan.setEnabled(aData[17] == "1" ? true : false);
      if (btnCellConvert)
        btnCellConvert.setEnabled(aData[17] == "1" ? true : false);
      if (btnCellProp)
        btnCellProp.setEnabled(aData[17] == "1" ? true : false);
      if (btnTableProp)
        btnTableProp.setEnabled(aData[18] == "1" ? true : false);
    } catch (e) { }
  }
}

function editOnAddStyle(window,name,html,type,useImage,tag)
{
  if (useRibbon) {
    try {

      var control = ribbon.getElementByTagName("STYLE");

      // clear combo
      if(name == "") {
        control.clear();
      } else {
        var imagePath = webRoot + "application/images/";

        if(type == "img") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "image.gif","",name,type,tag));
          control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
        } else if (type == "td") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "cell.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else if (type == "table") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "table.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else if (type == "div") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "textbox.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else if (type == "p") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "paragraph.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else if (type == "li" || type == "ul" || type == "ol") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "unorderedlist.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else if (type == "span") {
		      //combo.add(toolbar.createStyleComboItem(html,imagePath + "border.gif","",name,type,tag));
		      control.add(name, imagePath + "image.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
		    } else {
	        if(useImage)
		        //combo.add(toolbar.createStyleComboItem(html,imagePath + "empty.gif","",name,"",tag));
	          control.add(name, imagePath + "empty.gif", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
	        else
		        //combo.add(toolbar.createStyleComboItem(html,"","",name,"",tag));
  	        control.add(name, "", "ITEM", "", true, true, tag, true, true, "Here is screen tip", "Here is super tip", "Here is tip");
	      }
      }
		} catch (error) { }

  } else {
    try {
      var toolbar = toolbarsEditor2;

      if (!toolbar)
        return;

      // get style combo
      var combo = toolbar.getElementByTag("STYLE");
      // clear combo
      if (name == "") {
        combo.clear();
      } else {
        var imagePath = webRoot + "application/images/";

        if (type == "img") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "image.gif", "", name, type, tag));
        } else if (type == "td") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "cell.gif", "", name, type, tag));
        } else if (type == "table") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "table.gif", "", name, type, tag));
        } else if (type == "div") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "textbox.gif", "", name, type, tag));
        } else if (type == "p") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "paragraph.gif", "", name, type, tag));
        } else if (type == "li" || type == "ul" || type == "ol") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "unorderedlist.gif", "", name, type, tag));
        } else if (type == "span") {
          combo.add(toolbar.createStyleComboItem(html, imagePath + "border.gif", "", name, type, tag));
        } else {
          if (useImage)
            combo.add(toolbar.createStyleComboItem(html, imagePath + "empty.gif", "", name, "", tag));
          else
            combo.add(toolbar.createStyleComboItem(html, "", "", name, "", tag));
        }
      }
    } catch (error) { }

  }

}

function editOnContextMenuItemClick(key,value)
{
  if(key == "LINK") {
    createLink(1);
    return true;
  }
  
  return false;
}

function editOnControlS()
{
  saveContent();

}


