var system = "";
var __currentURL = "";
var __editDocumentLoadedFlag = false;
var __editActiveObject;
var __editIsBR = true;
var __editFieldCounter = 1;
var __zindex = 1000;

var __isIntelli = false;
var __intelliPos = -1;
var __intelliRowCount = 10;
var __intelliLeft = 0;
var __intelliTop = 0;
var __intelliData = new Array();
var HTMLMode =  globalHTMLMode;

//try {
//  if(__getKey() != "ANBH543EFRHHJBGHU23PZh7fRE")
//    __toolbar_setkey(true);
//  else
    __toolbar_setkey(false);
//} catch(Error) {
//    __toolbar_setkey(true);
//}

function globalGetPositonY(obj)
{
  var y = 0;
  var parent = obj;
  while(parent.tagName.toUpperCase() != "BODY") {
    if(parent.tagName.toUpperCase() != "TD")
      y = y + parent.offsetTop;
    parent = parent.parentNode;
  }
  return y - 2;
};

function globalGetPositonY2(obj)
{
  var y = 0;
  var parent = obj;
  while(parent.tagName.toUpperCase() != "BODY") {
    y = y + parent.offsetTop;
    parent = parent.parentNode;
  }
  return y - 4;
};

function globalGetPositonX(obj)
{
  var x = 0;
  var parent = obj;
  while(parent.tagName.toUpperCase() != "BODY") {
    x = x + parent.offsetLeft;
    parent = parent.parentNode;
  }
  return x-4;
};


function __editGetEditorUrl()
{
  var url = document.location.href;
  var pos = url.indexOf("//");
  var temp = url.substring(pos + 2,url.length);

  newpos = temp.indexOf("/");
  var temp = temp.substring(newpos + 1,temp.length);
  pos = pos + newpos + 1;

  newpos = temp.indexOf("/");
  pos = pos + newpos + 1;
  temp = url.substring(0,pos +1);
  return temp + "/editor/";
};

function onchangeEDIT()
{
  try {
    // call method to close open popups
    toolbarstop.reset();
    __intelliHide();
    // set buttons to active
    // get all buttons
    var objComponents = toolbarstop.getComponents();
    // check if active
    for(var i=0;i<objComponents.length;i++) {
      if(objComponents[i].tag != "" && objComponents[i].tag != null) {
        var tag = objComponents[i].tag;
        var res = editQuery(tag);
        if(res != null) {
          objComponents[i].setStatus(res);
        }
      }
    }

    cmbFont.setSelected(editQuery("FontName"));
    cmbFontSize.setSelected(editQuery("FontSize"));
  } catch(Error) {}
};

function oncontextmenuEDIT()
{
//alert(document.frames['Edit'].window.event.srcElement.tagName);
//  editPopup(document.frames['Edit'].window.event);
  if(browser.ie55 || browser.ie6)
    editPopup(getWindow().event);
  return false;
};

function onmousedownEDIT()
{
  __editActiveObject = getWindow().event.srcElement;
};


function onkeydownEDIT()
{
  if(__intelliAction())
    return;

  var evt = getWindow().event;

  if (__isIntelli ) {
    evt.cancelBubble = true;
    evt.returnValue = false;
    return;
  }

  if(__editIsBR) {
    if (evt.keyCode == 13) {
      var sel = getDoc().selection;
      if (sel.type == "Control")
        return;

      var r = sel.createRange();
      r.pasteHTML("<BR>");
      evt.cancelBubble = true;
      evt.returnValue = false;

      r.select();
      r.moveEnd("character", 1);
      r.moveStart("character", 1);
      r.collapse(false);

      return false;
    }
  }
};

function __intelliHide()
{
  try {
    __isIntelli = false;
    document.getElementById("__popup").style.visibility = "hidden";
    document.getElementById("__intelli0").scrollIntoView(false);
    __intelliPos = -1;
    __intelliData = new Array();
  } catch(Error) {}
};

function __intelliMouseClick(row)
{
  editInsertHtml(document.getElementById("__intelli" + row).innerHTML);
  __intelliHide();
};

function __intelliAction()
{
  if (__isIntelli ) {
    for(var i=0;i<__intelliRowCount;i++) {
      document.getElementById("__intelli" + i).style.backgroundColor= "white";
      document.getElementById("__intelli" + i).style.borderColor="white";
    }
    var evt = getWindow().event;

    if (evt.keyCode == 40) {
      __intelliPos++;
      if(__intelliPos >= __intelliRowCount)
        __intelliPos = 0;
      document.getElementById("__intelli" + __intelliPos).style.backgroundColor= "#B1C0D2";
      document.getElementById("__intelli" + __intelliPos).style.borderColor="#0A246A";
      document.getElementById("__intelli" + __intelliPos).scrollIntoView(false);
    }
    if (evt.keyCode == 38) {
      __intelliPos--;
      if(__intelliPos < 0)
        __intelliPos = __intelliRowCount-1;
      document.getElementById("__intelli" + __intelliPos).style.backgroundColor= "#B1C0D2";
      document.getElementById("__intelli" + __intelliPos).style.borderColor="#0A246A";
      document.getElementById("__intelli" + __intelliPos).scrollIntoView(false);
    }
    if (evt.keyCode == 13 || evt.keyCode == 32) {
      if(__intelliPos>=0 && __intelliPos <= __intelliRowCount)
        editInsertHtml(__intelliData[__intelliPos]);
      evt.cancelBubble = true;
      evt.returnValue = false;
      __intelliHide();
      return true;
    }
    if (evt.keyCode == 27 || evt.keyCode == 8) {
      __intelliHide();
    }
  }
};
function __intelliProcess(data)
{
  var temp = "";
  temp += "<table width='100%' cellspacing='0' cellpadding='0' border=0 style='padding: 1px;font-family: arial;font-size: 11px'>";
  temp += "<tr><td>";

  var aTexts = __data.split("&&;");
  __intelliRowCount = aTexts.length-1;
  for(var i=0;i<aTexts.length-1;i++) {
    var aText = aTexts[i].split("&&:");
    var temp1 = aText[0];
    var image = "";
    if(temp1 != "")
      image = "<img src='" + temp1 + "' border='0'>";
    var text = aText[1];
    var value = aText[2];
    __intelliData[i] = value;
    //temp += "<table id='__intelli" + i + "' onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'>" + image + "</td><td style='margin-left: 2px;color: black' onclick='javascript: __intelliMouseClick(" + i + ")'>" + text + "</td></tr><table>"
    temp += "<table id='__intelli" + i + "' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'>" + image + "</td><td style='margin-left: 2px;color: black'>" + text + "</td></tr><table>"
  }
  temp += "</td></tr>";
  temp += "</table>";
  var objPopup = document.getElementById("__popup");
  objPopup.innerHTML = temp;
  objPopup.style.left = __intelliLeft;
  objPopup.style.top = __intelliTop;
  objPopup.style.visibility = "visible";
  __isIntelli = true;
};

function onkeypressEDIT()
{
  var evt = getWindow().event;

  if (__isIntelli ) {
    evt.cancelBubble = true;
    evt.returnValue = false;
    return;
  }

  if (globalISKey.inArray(evt.keyCode)) {
	var sel = getDoc().selection;
    var r = sel.createRange();
    r.moveStart("character",-1);
    var text = r.text;
    var moved = 0;
    while(text.charCodeAt(0) != "32" && text.charCodeAt(0) != "13" && text.charCodeAt(0) != "10") {
      if(r.moveStart("character",-1) == 0)
        break;
      text = r.text;
    }
    // the first char must be excluded
    if(text.charCodeAt(0) == "32" || text.charCodeAt(0) == "13" || text.charCodeAt(0) == "10") {
      text = text.substring(1,text.length);
      if(text.charCodeAt(0) == "32" || text.charCodeAt(0) == "13" || text.charCodeAt(0) == "10") {
        text = text.substring(1,text.length);
      }
    }
    for(var i=0;i<text.length + 1;i++) {
      r.moveStart("character",1);
    }
    // save position
    __intelliLeft = r.boundingLeft + 7;
    var top = globalGetPositonY(getEdit())
    __intelliTop = r.boundingTop + r.boundingHeight + top;
    // call server
    __comm = new Comm(targetIntellisense);
    __comm.execute("INTELLI",text,evt.keyCode,HTMLMode);
  }
  if(__editIsBR) {
    var evt = getWindow().event;
    __NoBr(evt);
  }
};

function onkeyupEDIT()
{
  mirror();
  var evt = getWindow().event;

  if (__isIntelli ) {
    evt.cancelBubble = true;
    evt.returnValue = false;
    return;
  }

  if(__editIsBR) {
    var evt = getWindow().event;
    __NoBr(evt);
  }
};

function __NoBr(evt)
{
  if (evt.keyCode == 13) {
    evt.cancelBubble = true;
    evt.returnValue = false;
    return false;
  }
};

function getDoc()
{
  if(browser.ns6)
    return document.getElementById('Edit').contentWindow.document;
  else
    return Edit.document;
};

function getWindow()
{
  if(browser.ns6)
    return document.getElementById('Edit').contentWindow;
  else
    return document.frames('Edit').window;
};

function getEdit()
{
  return document.getElementById('Edit');
};

function getText()
{
  return document.getElementById("Text");
};

function setEvent()
{
  if(!browser.ns6) {
    getDoc().oncontextmenu     = oncontextmenuEDIT;
    getDoc().onselectionchange = onchangeEDIT;
    getDoc().onmouseup         = onmousedownEDIT;
    getDoc().onkeydown         = onkeydownEDIT;
    getDoc().onkeypress        = onkeypressEDIT;
    getDoc().onkeyup           = onkeyupEDIT;
  }
};

function editCancel()
{
  document.location.href = __currentURL;
};

function editOpen(mode,localPath)
{
  if(mode == 0) {
    parent.editFile.click();
  }
  if(mode == 1) {
    if(browser.ns6) {
      var left = screen.width/2 - 600/2;
      var top = screen.height/2 - 300/2;
      window.open("dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=OPEN&language=" + language + "&docdir=" + globalDocDir,"color","modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
    } else {
      var path = window.showModalDialog("dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=OPEN&language=" + language + "&docdir=" + globalDocDir,"","dialogHeight:300px;dialogWidth:600px;resizable:1;status:0;scroll:0");
      if(path != "0" && path != null) {
        editLoad(path);
      }
    }
  }
  if(mode == 2) {
    setPropertyValue("editPath",localPath);
    invokeMethodInModel("onLoad");
  }
  if(mode == 3) {
    if(browser.ns6) {
      var left = screen.width/2 - 600/2;
      var top = screen.height/2 - 300/2;
      window.open("../dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=IMAGE&language=" + language+ "&imagedir=" + globalImageDir,"color","modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
    } else {
      var path = window.showModalDialog("dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=IMAGE&language=" + language+ "&imagedir=" + globalImageDir,"","dialogHeight:300px;dialogWidth:600px;resizable:1;status:0;scroll:0");
      if(path != "0" && path != null) {
        content = "<img src='" + path + "'>";
        editInsertHtml(content);
      }
    }
  }
};

function editOpenLocal(url)
{
  //getDoc().designMode = 'Off';
  //getEdit().src = url;
  location.href="EditExtended.html?url=" + url;
};

function editSave()
{
  var text = editGetBodyHtml();
  var html = "";
  html+= "<html>";
  html+= "<body>";
  html+= "<form name='frmComm' id='frmComm' name='frmComm' target='_self' method ='POST' action='" + target + "'>";
  html+= "<input type='hidden' id='html' name='html'>";
  html+= "<input type='hidden' id='url' name='url'>";
  html+= "<input type='hidden' id='pageid' name='pageid'>";
  html+= "</form>";
  html+= "</body>";
  html+= "</html>";
  var doc = null;
  if(browser.ns6)
    doc = document.getElementById('subframe').contentWindow.document;
  else
    doc = subframe.document;
  doc.open();
  doc.write(html);
  doc.close();
  doc.getElementById("pageid").value = pageId;
  doc.getElementById("html").value = text;
  doc.getElementById("url").value = __currentURL;
  doc.getElementById("frmComm").submit();
  alert("Your page has been saved");
  opener.location.reload();
};

function editSaveDialog()
{
  if(browser.ns6) {
    var left = screen.width/2 - 600/2;
    var top = screen.height/2 - 300/2;
    window.open("dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=SAVE&language=" + language + "&docdir=" + globalDocDir,"color","modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
  } else {
    var path = window.showModalDialog("dialogs/" + globalTechnology + "/dialog." + globalTechnology + "?mode=SAVE&language=" + language + "&docdir=" + globalDocDir,"","dialogHeight:300px;dialogWidth:400px;resizable:1;status:0;scroll:0");
    if(path != "0" && path != null) {
      if(system == "GUIS") {
        setPropertyValue("editHtml",editGetHtml());
        setPropertyValue("editPath",path);
        invokeMethodInModel("onSave");
      } else {
        var text = editGetHtml();
        var ret = __setFileToServer(path,text);
      }
    }
  }
};

function editNew()
{
  if(browser.ns) {
    //var doc  = getDoc();
    //doc.body.innerHTML = "";
    editWrite("");
  } else {
    editWrite("");
    editSetStyleSheetRules();
  }
  __currentURL = "";
};

function editLoad(url)
{
  __editDocumentLoadedFlag = false;
  if(url) {
    getEdit().src = url;
  }
  window.setTimeout("delay()",300) ;
};

function delay()
{
  try {
    var egal = getDoc().body.clientLeft
  } catch(Error) {
    window.setTimeout("delay()",200) ;
    return;
  }
  if(!browser.ns6) {
    setEvent();
    __editDocumentLoadedFlag = true;
    editSetStyleSheetRules();
    editMultipleSelection();
    __editShowSymbols();
  } else {
    try {
      document.getElementById('Edit').contentWindow.document.designMode = "on";
    } catch(Error) {}
  }
  __currentURL = getDoc().location.href;
  editSetFocus();
};

var __editStyleSheetComboId = "";
function editSetStyleSheetObject(comboid)
{
  __editStyleSheetComboId = comboid;
};

function editSetStyleSheetRules()
{
  if(__editStyleSheetComboId == "") {
    //alert("No Style Sheet Combo !")
    return;
  }

  try {
    var combo = document.getElementById(__editStyleSheetComboId);
    while(combo.length) {
      combo.remove(0);
    }
    var item = document.createElement("option");
    item.text = "Standard";
    item.value = "";
    if(browser.ie) {
      combo.add(item);
    } else {
      combo.add(item,null);
    }

    if(getDoc().styleSheets.length > 0) {
      var objStyleSheet = getDoc().styleSheets[0];
      var objRules = objStyleSheet.rules;
      for(var i=0;i<objRules.length;i++) {
        var value = objRules.item(i).selectorText;
        if(value.substring(0,1) == ".") {
          item = document.createElement("option");
          value = value.substring(1,value.length);
          item.text = value;
          item.value = value;
          if(browser.ie) {
            combo.add(item);
          } else {
            combo.add(item,null);
          }
        }
      }
    }
  } catch(Error) {}
};

function editSetStyle(style)
{

  try {
    editSetFocus();
    document.getElementById(__editStyleSheetComboId).selectedIndex=0;
    if(__editActiveObject) {
      __editActiveObject.className = style;
    }
  } catch(Error) {}
};

function editSearch()
{
  var aParam = new Array();
  aParam[0] = language;
  aParam[1] = design;
  aParam[2] = "";
  aParam[3] = "";
  aParam[4] = "";
  aParam[5] = getDoc();

  var values = window.showModalDialog("dialogs/search.html",aParam,"dialogHeight:165px;dialogWidth:400px;resizable:0;status:0;scroll:0;unadorned:no");
  editSetFocus();
};

function editPrint()
{
  execute('print',true);
};

function editPreview()
{
  execute('printpreview',true);
};

function editUpload()
{
  var left = screen.width/2 - 476/2;
  var top = screen.height/2 - 166/2;
  window.open("../dialogs/" + globalTechnology + "/upload." + globalTechnology + "?path=" + "/" + globalImageDir + "&language=" + language,"","modal=1,left=" + left + ",top=" + top + ",height=166,width=476,resizable=0,status=0,scrollbars=0");
};

function __editHideSymbols()
{
  if(browser.ns6)
    return;

  var body = getDoc().body;

  for (var i=0; i<body.all.length;i++) {
    var object = body.all[i];
    // remove form border
    if(object.tagName.toUpperCase() == "FORM") {
      if(object.style.borderStyle.toUpperCase() == "DOTTED") {
        object.style.borderWidth = "";
        object.style.borderStyle = "";
        object.style.borderColor = "";
      }
    }
    // check if we have an anchor
    if(object.tagName.toUpperCase() == "A") {
      if(object.name != "") {
        // remove style
        object.style.borderWidth = "";
        object.style.borderStyle = "";
        object.style.borderColor = "";
        // remove image
        object.innerHTML = "";
      }
    }
  }
};

function __editShowSymbols()
{
  if(browser.ns6)
    return;

  var body = getDoc().body;

  for (var i=0; i<body.all.length;i++) {
    var object = body.all[i];
    // remove form border
    if(object.tagName.toUpperCase() == "FORM") {
      object.style.borderWidth = 1;
      object.style.borderStyle = "dotted";
      object.style.borderColor = "red";
    }
    // check if we have an anchor
    if(object.tagName.toUpperCase() == "A") {
      if(object.name != "") {
        object.style.borderWidth = "1";
        object.style.borderStyle = "dotted";
        object.style.borderColor = "blue";
        // remove image
        var url = __editGetEditorUrl();
        object.innerHTML = "<IMG src='" + url + "design/image/anchor.gif' border=0 unselectable='ON'>";
      }
    }
  }
};

function editGetXHtml()
{
//el.supportsXHTML = el.frameWindow.document.documentElement && el.frameWindow.document.childNodes != null;
/*
  var nodes = getDoc().childNodes;
  alert(nodes.length);
  for(int i=0;i<nodes.length;i++) {
    temp = temp +
  }
*/
};

function editSelectAll()
{
  var rng = getDoc().body.createTextRange();
  rng.select();
};

function editCut()
{
  execute('cut',false,null);
};

function editCopy()
{
  execute('copy',false,null);
};

function editPaste()
{
  execute('paste',false,null);
};

function editUndo()
{
  execute('undo');
};

function editRedo()
{
  execute('redo');
};

function editLink()
{
  if(browser.ns) {
      var left = screen.width/2 - 200;
      var top = screen.height/2 - 115;
      window.open("dialogs/link.html?language=" + language,"color","modal=1,left=" + left + ",top=" + top + ",height=120,width=400,resizable=0,status=0,scrollbars=0");
  } else {
    execute('createlink',true);
  }
};

function editBold()
{
  execute('bold');
};

function editItalic()
{
  execute('italic');
};

function editUnderline()
{
  execute('underline');
};

function editSuperscript()
{
  execute('superscript');
};

function editSubscript()
{
  execute('subscript');
};

function editBookmark(value)
{
  if(value)
    execute('createbookmark',null,'Text');
  else
    execute('UnBookmark');
};

function editStikeThrough()
{
  execute('stikethrough');
};

function editIndent()
{
  execute('indent');
};

function editOutdent()
{
  execute('outdent');
};

function editJustifyLeft()
{
  execute('justifyleft');
};

function editJustifyCenter()
{
  execute('justifycenter');
};

function editJustifyRight()
{
  execute('justifyright');
};

function editJustifyFull()
{
  execute('justifyfull');
};

function editOrderedList()
{
  execute('InsertOrderedList');
};

function editUnorderedList()
{
  execute('InsertUnorderedList');
};

function editRemoveFormat()
{
  execute('RemoveFormat');
};

function editFormat(format)
{
  execute('FormatBlock',false,format);
};

function editParagraph()
{
  execute('InsertParagraph');
};

function editBackColor(color)
{
  if(browser.ns6)
    execute('hilitecolor','',color)
  else
   execute('BackColor','',color)
};

function editColor(color)
{
  execute('ForeColor','',color)
};


function editSetFocus()
{
  getWindow().focus();
};

function editWrite(text)
{
  var doc  = getDoc();
  doc.open();
  doc.write(text);
  doc.close();
  if(!browser.ns6) {
    __editShowSymbols();
    setEvent();
    editMultipleSelection();
  }
  editSetFocus();
  __currentURL = "";
};

function editSetBodyHtml(html)
{
  var doc  = getDoc();
  doc.body.innerHTML = html;
  __editShowSymbols();
};

function editGetHtml()
{
  var doc  = getDoc();
  if(browser.ns6) {
    return doc.documentElement.innerHTML;
  } else {
    __editHideSymbols();
    return doc.documentElement.innerHTML;
  }
};

function editGetBodyHtml()
{
  var doc  = getDoc();
  if(browser.ns6) {
    return doc.body.innerHTML;
  } else {
    __editHideSymbols();
    return doc.body.innerHTML;
  }
};

function editGetText()
{
  var doc  = getDoc();
  if(browser.ns6) {
    var text = doc.body.innerHTML;
    text = text.replace(/&lt;/gi, "<");
    text = text.replace(/&gt;/gi, ">");
    return text;;
  } else {
    return doc.body.innerText;
  }
};

function editSetText(text)
{
  var doc  = getDoc();

  if(browser.ns6) {
    text = text.replace(/</gi, "&lt;");
    text = text.replace(/>/gi, "&gt;");
    doc.body.innerHTML = text;
  } else {
    doc.body.innerText = text;
  }
};

function editInsertHtml(html)
{
  if(browser.ns6) {
    editWrite(html);
  } else {
    editSetFocus();
    pasteHTML(html);
    editSetFocus();
  }
};


function editInsertText(text)
{
  editSetFocus();
  if(browser.ns6) {
    __MozillaInsertNodeAtSelection(getDoc().createTextNode(text));
  } else {
    pasteHTML(text);
  }
  editSetFocus();
};

function pasteHTML(html)
{
  try {
    var doc  = getDoc();
    var range = doc.selection.createRange();
    range.pasteHTML(html);
  } catch(Error) {}
};


function editGetSelectedHtml()
{
  var doc  = getDoc();
  var range = doc.selection.createRange();
  return range.htmlText;
};

function executeSelection(command,value,ui)
{
  var doc  = getDoc();
  var range = doc.selection.createRange();
  range.execCommand(command, ui, value);
};

function execute(command,ui,value)
{
  try {
    editSetFocus();
    getDoc().execCommand(command,ui,value);
  } catch(Error) {}
};

function editQuery(command)
{
  try {
    var doc  = getDoc();
    var range = doc.selection.createRange();
    return range.queryCommandValue(command);
  } catch(Error) {
    return null;
  }
};

function editAbsolute()
{
  execute('AbsolutePosition','',true);
  execute('2D-Position','',true);
};

function editMultipleSelection()
{
  execute('MultipleSelection','',true);
};

function editInsert()
{
  execute('OverWrite','',false);
};

function editOverwrite()
{
  execute('OverWrite','',true);
};

function editRefresh()
{
  //execute('Refresh','',false);
};

function editFont(font)
{
  execute('FontName','',font);
};

function editFontSize(size)
{
  execute('fontsize','',size);
};

function editZoom(value)
{
  getEdit().style.zoom = value;
};

function editCreateTable(row,col)
{
  editSetFocus();

  if(browser.ns6) {
    var doc = getDoc();
    var table = doc.createElement("table");
    table.setAttribute("border", "1");
    table.setAttribute("cellpadding", "2");
    table.setAttribute("cellspacing", "2");
    var tbody = doc.createElement("tbody");
    for (var i=0; i < row; i++) {
      tr = doc.createElement("tr");
      for (var j=0; j < col; j++) {
        td = doc.createElement("td");
        br = doc.createElement("br");
        td.appendChild(br);
        tr.appendChild(td);
      }
      tbody.appendChild(tr);
    }
    table.appendChild(tbody);
    __MozillaInsertNodeAtSelection(table);
  } else {
    var temp = "";
    temp = "<table style='width:100%' border='1'>";
    for(var i=0;i<row;i++) {
      temp+= "<tr>";
      for(var j=0;j<col;j++) {
        temp+= "<td></td>";
      }
      temp+= "</tr>";
    }
    temp+= "</table>";
    editInsertHtml(temp);
  }
};

function editInsertObject(obj)
{
  var content = '';

  if(obj=='FORM') {
    content = "<form style='border: 1px dotted red'>&nbsp;</form>&nbsp;";
  }
  if(obj=='BUTTON') {
      execute('InsertInputButton');
      return;
  }
  if(obj=='FIELDSET') {
      execute('InsertFieldset');
      return;
  }
  if(obj=='INPUT') {
      execute('InsertInputText');
      return;
  }
  if(obj=='LISTBOX') {
      execute('InsertSelectListBox');
      return;
  }
  if(obj=='COMBO') {
      execute('InsertSelectDropDown');
      return;
  }
  if(obj=='CHECK') {
      execute('InsertInputCheckbox');
      return;
  }
  if(obj=='OPTION') {
      execute('InsertInputRadio');
      return;
  }
  if(obj=='AREA') {
      execute('InsertTextArea');
      return;
  }
  if(obj=='IFRAME') {
      execute('InsertIFrame');
      return;
  }
  if(obj=='MARQUEE') {
      execute('InsertMarquee');
      return;
  }
  if(obj=='HIDDEN') {
      execute('InsertInputHidden');
      return;
  }
  if(obj=='FILE') {
      execute('InsertInputFileUpload');
      return;
  }
  if(obj=='UPLOAD') {
      execute('InsertInputFileUpload');
      return;
  }
  if(obj=='TABLE') {
    content = "<table border='1' width='100%'><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr><table>";
  }
  if(obj=='DIV') {
    content = "<div style='z-index:" + __zindex + ";width:100;height:100;position:absolute;background-color:#c0c0c0 '></div>";
    __zindex++;
  }
  if(obj=='LABEL') {
    content = "<p style='z-index:" + __zindex + ";padding-left: 3px;width:100px;height:25px;position:absolute;'>Text</p>";
    __zindex++;
  }
  if(obj=='IMAGE') {
    execute('InsertImage',true);
    return;
  }
  if(obj=='IMAGEWEB') {
    if(browser.ns6) {
      var left = screen.width/2 - 200;
      var top = screen.height/2 - 115;
      window.open("../dialogs/webimage.html","color","modal=1,left=" + left + ",top=" + top + ",height=120,width=400,resizable=0,status=0,scrollbars=0");
    } else {
      var aParam = new Array();
      aParam[0] = language;
      aParam[1] = design;

      var url = window.showModalDialog("dialogs/webimage.html",aParam,"dialogHeight:120px;dialogWidth:400px;resizable:0;status:0;scroll:0");
      if(url != "")
        content = "<img src='" + url + "' border=0>";
      else
        return;
    }
  }
  if(obj=='RULE') {
    execute('inserthorizontalrule');
    return;
  }
  if(obj=='ANCHOR') {
    var name = window.showModalDialog("dialogs/anchor.html?language=" + language,null,"dialogHeight:120px;dialogWidth:400px;resizable:0;status:0;scroll:0");
    var url = __editGetEditorUrl();
    if(name != "")
      content = "<a style='border: 1px dotted blue' name='" + name + "'><IMG src='" + url + "design/image/anchor.gif' border=0 unselectable='ON'></a>";
    else
      return;
  }
  if(obj=='PAGEBREAK') {
    content = "<DIV title='Page Break' contentEditable=false style='FONT-SIZE: 1px; PAGE-BREAK-AFTER: always; HEIGHT: 1px; BACKGROUND-COLOR: #c0c0c0'></DIV>";
  }
  if(obj=='FIELD') {
    content = "<Span id='" + "Field" + __editFieldCounter + "' class='FIELD' contentEditable=true class='FieldDesign' style='margin-left: 2px; height: 16px; width: 80px; BACKGROUND-COLOR: #c0c0c0'>Field " + __editFieldCounter + "</Span>";
    __editFieldCounter++;
  }
  editInsertHtml(content);
};
var lastMode = 'EDIT';

var __lastHeight = 0;

var interv;
function setMode(mode)
{

  if(mode == lastMode)
    return;

  var doc = getDoc();
  if(mode == "EDIT") {
	clearInterval(interv);
    doc.body.style.fontFamily = '';
    doc.body.style.fontSize = '';
    toolbarstop.show();
    document.getElementById("EditPreview").style.display = 'none';
	document.getElementById("split").style.display = 'none';
	document.getElementById("EditPreview").style.height = '100%';
	document.getElementById("Edit").style.height = '100%';
    document.getElementById("Edit").style.display = 'inline';
    if(lastMode == 'HTML' || lastMode == 'SPLITTEXT') {
      var html = editGetText();
      if(globalHTMLMode == "1")
        editSetBodyHtml(html);
      if(globalHTMLMode == "2")
        editWrite(html);
    } else {
		var html = editGetHtml();
      //__editShowSymbols();
    }
	HTMLMode="1";
  }
  if(mode == "HTML") {
    clearInterval(interv);
    doc.body.style.fontFamily = 'Courier New';
    doc.body.style.fontSize = '10pt';
    toolbarstop.hide();
    document.getElementById("EditPreview").style.display = 'none';
	document.getElementById("split").style.display = 'none';
	document.getElementById("EditPreview").style.height = '100%';
	document.getElementById("Edit").style.height = '100%';
    document.getElementById("Edit").style.display = 'inline';
    getDoc().body.style.backgroundColor = 'white';
    if(lastMode == 'SPLITTEXT') {
      var html = editGetText();
	} else {
		if(globalHTMLMode == "1"){
		  var html = editGetBodyHtml();
		}
		if(globalHTMLMode == "2"){
		  var html = editGetHtml();
		}
    }
	editSetText(html);
	HTMLMode="2";
  }
  if(mode == "PREVIEW") {
	clearInterval(interv);
    var html = "";
    toolbarstop.hide();
    document.getElementById("EditPreview").style.display = 'inline';
	document.getElementById("split").style.display = 'none';
	document.getElementById("EditPreview").style.height = '100%';
	document.getElementById("Edit").style.height = '100%';
    document.getElementById("Edit").style.display = 'none';
    if(lastMode == 'HTML' || lastMode == 'SPLITTEXT') {
      var html = editGetText();
      if(globalHTMLMode == "1"){
        editSetBodyHtml(html);
      }
      if(globalHTMLMode == "2"){
        editWrite(html);
      }
      
    }
	HTMLMode="3";
    html = editGetHtml();
    if(browser.ns6){
      doc = document.getElementById('EditPreview').contentWindow.document;
    } else {
      doc = EditPreview.document;
    };
    doc.open();
    doc.write(html);
    doc.close();
  }
  if(mode == "SPLIT"){
    clearInterval(interv);
	doc.body.style.fontFamily = '';
    doc.body.style.fontSize = '';
    toolbarstop.show();
    document.getElementById("EditPreview").style.display = 'inline';
	document.getElementById("split").style.display = 'inline';
	document.getElementById("EditPreview").style.height = '50%';
	document.getElementById("Edit").style.height = '50%';
    document.getElementById("Edit").style.display = 'inline';
    if(lastMode == 'HTML' || lastMode == 'SPLITTEXT') {
      var html = editGetText();
      if(globalHTMLMode == "1")
        editSetBodyHtml(html);
      if(globalHTMLMode == "2")
        editWrite(html);
    } else {
      __editShowSymbols();
    }
	HTMLMode="4";
	mirror();
	interv = setInterval("mirror();",10000);
  }
  if(mode == "SPLITTEXT"){
	clearInterval(interv);
    doc.body.style.fontFamily = 'Courier New';
    doc.body.style.fontSize = '10pt';
    toolbarstop.hide();    

	document.getElementById("EditPreview").style.display = 'inline';
	document.getElementById("split").style.display = 'inline';
	document.getElementById("EditPreview").style.height = '50%';
	document.getElementById("Edit").style.height = '50%';
    document.getElementById("Edit").style.display = 'inline';
    getDoc().body.style.backgroundColor = 'white';
    if(lastMode == 'HTML' || lastMode == 'SPLITTEXT') {
      var html = editGetText();
      if(globalHTMLMode == "1")
        editSetBodyHtml(html);
      if(globalHTMLMode == "2")
        editWrite(html);
    } else {
		if(globalHTMLMode == "1"){
		  var html = editGetBodyHtml();
		}
		if(globalHTMLMode == "2"){
		  var html = editGetHtml();
		}
    }

    editSetText(html);    
	HTMLMode="5";
	mirror();
	interv = setInterval("mirror();",10000);
  }


  lastMode = mode;
}

var table;
var objSelected;
var popup;
var currentRow;
var currentCol;
//var objImage;

function mirror(){
	if (HTMLMode=="4"){
		html = editGetHtml();
	} else {
		html = editGetText();
	}
	
    if(browser.ns6){
      doc = document.getElementById('EditPreview').contentWindow.document;
    } else {
      doc = EditPreview.document;
    };
    doc.open();
    doc.write(html);
    doc.close();
}

function __insertRow(mode)
{
  var row;
  if(mode == 0 ) {
    row = table.insertRow(currentRow.rowIndex);
  } else {
    row = table.insertRow(currentRow.rowIndex + 1);
  }
  for(var i=0;i<currentRow.cells.length;i++) {
    row.insertCell();
  }
  popup.hide();
};

function __deleteRow()
{
  table.deleteRow(currentRow.rowIndex);
  popup.hide();
};

function __insertColumn(mode)
{
  var index;
  if(mode == 0) {
    index = currentCol.cellIndex;
  } else {
    index = currentCol.cellIndex + 1;
  }

  for(var i=0;i<table.rows.length;i++) {
    table.rows[i].insertCell(index);
  }
  popup.hide();
};

function __deleteColumn()
{
  var index = currentCol.cellIndex;
  for(var i=0;i<table.rows.length;i++) {
    table.rows[i].deleteCell(index);
  }
  popup.hide();
};

function __deleteCell()
{
  try {
    table.rows[currentRow.rowIndex].deleteCell(currentCol.cellIndex);
  } catch(Error) {;}
  popup.hide();
};

function __mergeCell()
{
  try {
    table.rows[currentRow.rowIndex].deleteCell(currentCol.cellIndex + 1);
    currentCol.colSpan = 2;
  } catch(Error) {;}
  popup.hide();
};

function __divideCell()
{
  try {
    if(currentCol.colSpan > 1) {
      currentCol.colSpan = currentCol.colSpan - 1;
      table.rows[currentRow.rowIndex].insertCell(currentCol.cellIndex);
    }
  } catch(Error) {}
  popup.hide();
};

function __setforeground()
{
  editSetToForeground();
  popup.hide();
};

function __setbackground()
{
  editSetToBackground();
  popup.hide();
};

function editSetToForeground()
{
  var body = getDoc().body;
  var index = 0;

  for (var i=0; i<body.all.length;i++) {
    var object = body.all[i];
    // remove form border
    var tag = object.tagName.toUpperCase();
    if(tag =="DIV" || tag == "SELECT" || tag == "INPUT" || tag == "P") {
      var curIndex = parseInt(object.style.zIndex);
      if(curIndex > index) {
        index = curIndex;
      }
    }
  }
  objSelected.style.zIndex = index + 1;
};

function editSetToBackground()
{
  objSelected.style.zIndex = 0;
};

function __removeAnchor()
{
  try {
    objSelected.parentNode.removeNode(true);
  } catch(Error) {;}
  popup.hide();
};

function __removeForm()
{
  try {
    objSelected.removeNode(true);
  } catch(Error) {}
  popup.hide();
};

function __properties(type)
{
  var aParam = new Array();
  aParam[0] = language;
  aParam[1] = design;
  aParam[2] = "";
  aParam[3] = "";
  aParam[4] = "";

  if(type == 0) {
    aParam[5] = table;
    var values = window.showModalDialog("dialogs/table.html",aParam,"dialogHeight:240px;dialogWidth:400px;resizable:0;status:0;scroll:0");
  }
  if(type == 2) {
    aParam[5] = getDoc();
    var values = window.showModalDialog("dialogs/cell.html",aParam,"dialogHeight:210px;dialogWidth:430px;resizable:0;status:0;scroll:0");
  }
  if(type == 3) {
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/image.html",aParam,"dialogHeight:180px;dialogWidth:370px;resizable:0;status:0;scroll:0");
  }
  if(type == 4) {
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/body.html",aParam,"dialogHeight:150px;dialogWidth:250px;resizable:0;status:0;scroll:0");
  }
  if(type == 5) {
    aParam[2] = "DIV";
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/input.html",aParam,"dialogHeight:340px;dialogWidth:290px;resizable:0;status:0;scroll:0");
  }
  if(type == 6) {
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/iframe.html",aParam,"dialogHeight:175px;dialogWidth:300px;resizable:0;status:0;scroll:0");
  }
  // label
  if(type == 7) {
    aParam[2] = "LABEL";
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/input.html",aParam,"dialogHeight:340px;dialogWidth:290px;resizable:0;status:0;scroll:0");
  }
  if(type == 8) {
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/anchor.html",aParam,"dialogHeight:120px;dialogWidth:400px;resizable:0;status:0;scroll:0");
  }
  if(type == 9) {
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/form.html",aParam,"dialogHeight:238px;dialogWidth:290px;resizable:0;status:0;scroll:0");
  }
  if(type == 10) {
    aParam[2] = "INPUT";
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/input.html",aParam,"dialogHeight:340px;dialogWidth:290px;resizable:0;status:0;scroll:0");
  }
  if(type == 11) {
    aParam[2] = "SELECT";
    aParam[5] = objSelected;
    var values = window.showModalDialog("dialogs/input.html",aParam,"dialogHeight:340px;dialogWidth:290px;resizable:0;status:0;scroll:0");
  }
  editSetFocus();
};

function editPopup(event)
{
  var source = event.srcElement;
  var mode = "";
  var isCell = false;
  var path = "";

  try {
    objSelected = source;
    var parent = source;
    if(source.tagName == "TR") {
      currentRow = source;
      mode = "TABLE";
    } else {
      currentRow = null;
    }
    if(source.tagName == "TD") {
      isCell = true;
      mode = "TABLE";
      objSelected = source;
      currentRow = source.parentNode;
      currentCol = source;
    } else {
      isCell = false;
      currentCol = null;
    }
    if(source.tagName == "TD" || source.tagName == "TR") {
      while(parent.tagName != "TABLE") {
        parent = parent.parentNode;
      }
      mode = "TABLE";
    }
    if(source.tagName == "TABLE") {
      mode = "TABLE";
      isCell = false;
    }
    if(source.tagName == "IMG") {
      var temp = objSelected.src;
      temp = temp.substring(temp.length-10,temp.length).toUpperCase();
      if(temp == "ANCHOR.GIF")
        mode = "ANCHOR";
      else
        mode = "IMAGE";
    }
    if(source.tagName == "BODY") {
      mode = "BODY";
    }
    if(source.tagName == "DIV") {
      mode = "DIV";
    }
    if(source.tagName == "SPAN") {
      // check if it is a field
      if(objSelected.className == "FIELD"){
        mode = "FIELD";
      }
    }
    if(source.tagName == "IFRAME") {
      mode = "IFRAME";
    }
    if(source.tagName == "P") {
      mode = "P";
    }
    if(source.tagName == "FORM") {
      mode = "FORM";
    }
    if(source.tagName == "INPUT") {
      mode = "INPUT";
    }
    if(source.tagName == "SELECT") {
      mode = "SELECT";
    }
    if(source.tagName == "TEXTAREA") {
      mode = "TEXTAREA";
    }
  } catch(Error){}

  if(parent != null) {
    table = parent;
    var objPopup = window.createPopup();
    popup = objPopup;
    var objBody = objPopup.document.body;
    var tableHeader = "<table width='100%' height='100%' cellspacing='0' cellpadding='1' style='border: 1px outset;font-family: arial;font-size: 11px'>";
    var separator = "<table cellspacing='0' cellpadding='0' style='border: 1px solid white; border-top-color: buttonface;height:1px;' width='100%'><tr><td></td></tr><table>";
    var foreground = "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/foreground.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__setforeground();'>" + getLanguageString(language,814) + "</a></td></tr><table>";
    foreground += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/background.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__setbackground();'>" + getLanguageString(language,2000) + "</a></td></tr><table>";

    if(mode == "TABLE") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/insertrow.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__insertRow(0);'>" + getLanguageString(language,801) + "</a></td></tr><table>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/insertrow.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__insertRow(1);'>" + getLanguageString(language,802) + "</a></td></tr><table>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='16'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__deleteRow();'>" + getLanguageString(language,803) + "</a></td></tr><table>"
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/insertcol.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__insertColumn(0);'>" + getLanguageString(language,804) + "</a></td></tr><table>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/insertcol.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__insertColumn(1);'>" + getLanguageString(language,805) + "</a></td></tr><table>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='16'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__deleteColumn();'>" + getLanguageString(language,806) + "</a></td></tr><table>";
      temp += separator;

      if(isCell) {
        temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='16'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__deleteCell();'>" + getLanguageString(language,807) + "</a></td></tr><table>";
        temp += separator;
        temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='16'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__mergeCell();'>" + getLanguageString(language,808) + "</a></td></tr><table>";
        temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='16'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__divideCell();'>" + getLanguageString(language,809) + "</a></td></tr><table>";
        temp += separator;
        temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(2);'>" + getLanguageString(language,810) + "</a></td></tr><table>";
      }

      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(0);'>" + getLanguageString(language,811) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      if(isCell)
        objPopup.show(event.clientX,event.clientY, 153, 227, getEdit());
      else
        objPopup.show(event.clientX,event.clientY, 153, 150, getEdit());
    }
    if(mode == "BODY") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(4);'>" + getLanguageString(language,812) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 140, 24, getEdit());
    }
    if(mode == "IMAGE") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(3);'>" + getLanguageString(language,813) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 130, 70, getEdit());
    }
    if(mode == "DIV") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(5);'>" + getLanguageString(language,815) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 158, 70, getEdit());
    }
    if(mode == "IFRAME") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(6);'>" + getLanguageString(language,816) + "</a></td></tr><table>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__setforeground();'>" + getLanguageString(language,814) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 160, 46, getEdit());
    }
    if(mode == "P") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(7);'>" + getLanguageString(language,817) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 130, 70, getEdit());
    }
    if(mode == "FIELD") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(5);'>" + "Field properties" + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 158, 46, getEdit());
    }
    if(mode == "ANCHOR") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/remove.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__removeAnchor();'>" + getLanguageString(language,1104) + "</a></td></tr><table>";
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(8);'>" + getLanguageString(language,1103) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 158, 51, getEdit());
    }
    if(mode == "FORM") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/remove.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__removeForm();'>" + getLanguageString(language,1204) + "</a></td></tr><table>";
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a nowrap style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(9);'>" + getLanguageString(language,1203) + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 158, 51, getEdit());
    }
    if(mode == "INPUT") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(10);'>" + "Input properties" + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 130, 70, getEdit());
    }
    if(mode == "SELECT") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(11);'>" + "Select properties" + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 130, 70, getEdit());
    }
    if(mode == "TEXTAREA") {
      var temp = "";
      temp += tableHeader;
      temp += "<tr><td>";
      temp += foreground;
      temp += separator;
      temp += "<table onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'><img src='" + path + "design/image/properties.gif' border='0'></td><td><a style='margin-left: 2px;text-decoration: none;color: black' href='' onclick='javascript: parent.__properties(10);'>" + "Textarea properties" + "</a></td></tr><table>";
      temp += "</td></tr>";
      temp += "</table>";
      objBody.innerHTML = temp;
      objPopup.show(event.clientX,event.clientY, 130, 70, getEdit());
    }
  }
  return false;
};

function editInsertTextModule(comboID)
{
  var combo = document.getElementById(comboID);
  var value = combo.options[combo.selectedIndex].value;
  if(value != '') {
    editInsertHtml(value);
  }
};

function editSetTextModule(comboID)
{
  var combo = document.getElementById(comboID);
  if(combo.length >= 10) {
    alert("Not more than 10 text modules allowed !");
    return;
  }

  var text = editGetSelectedHtml();
  if(text == "") {
    alert("Please select first a text range !")
    return;
  }
  var name = window.prompt('Please enter a name !','');
  if(name == null || name =='')
    return;
  __comm = new Comm(targetTextModule);
  __comm.comboid = comboID;
  __comm.execute("SETTEXT",name,text,"");
};

function editGetTextModule(comboID)
{
  __comm = new Comm(targetTextModule);
  __comm.comboid = comboID;
  __comm.execute("GETTEXT","","","");
};

function editRemoveTextModule(comboID)
{
  var combo = document.getElementById(comboID);
  var value = combo.options[combo.selectedIndex].text;
  if(value != '') {
    __comm = new Comm(targetTextModule);
    __comm.comboid = comboID;
    __comm.execute("REMOVETEXT",value,"","");
  }
};

function __setFileToServer(path,text)
{
  __comm = new Comm(target);
  __comm.execute("SAVE",path,text,"");
  return true;
};

function __getFileFromServer(path)
{
  __comm = new Comm(target);
  __comm.execute("OPEN",path,"");
  return true;
};

function callbackMozilla(mode, para1, para2)
{
  if(mode == "WEBIMAGE") {
    __MozillaInsertImage(para1);
  }
  if(mode == "OPENDOC") {
    if(para1 != "0" && para1 != null) {
      editLoad(para1);
    }
  }
  if(mode == "SAVEDOC") {
  }
  if(mode == "OPENIMAGE") {
    if(para1 != "0" && para1 != null) {
      __MozillaInsertImage(para1);
    }
  }
  if(mode == "LINK") {
    if(para1 != "0" && para1 != null) {
      __MozillaInsertLink(para1);
    }
  }
};
function __MozillaInsertLink(url)
{
  execute('createlink',false,url);
};

function __MozillaInsertImage(url)
{
  var doc = getDoc();
  var image = doc.createElement("img");
  image.setAttribute("border", "0");
  // prepare url
  //var temp = document.location.href;
  //var pos = temp.indexOf("?");
  //if(pos > 0)
  //  temp = temp.substring(0,pos);
  //pos = temp.lastIndexOf("/");
  //image.setAttribute("src", temp.substring(0,pos) + "/" + url);
  image.setAttribute("src", url);
  __MozillaInsertNodeAtSelection(image);
};

function __MozillaInsertNodeAtSelection(insertNode)
{

  // get current selection
  var sel = getWindow().getSelection();
  // get the first range of the selection
  // (there's almost always only one range)
  var range = sel.getRangeAt(0);
  // deselect everything
  sel.removeAllRanges();
  // remove content of current selection from document
  range.deleteContents();
  // get location of current selection
  var container = range.startContainer;
  var pos = range.startOffset;
  // make a new range for the new selection
  range=document.createRange();
  if (container.nodeType==3 && insertNode.nodeType==3) {
    // if we insert text in a textnode, do optimized insertion
    container.insertData(pos, insertNode.nodeValue);
    // put cursor after inserted text
    range.setEnd(container, pos+insertNode.length);
    range.setStart(container, pos+insertNode.length);
  } else {
    var afterNode;
    if (container.nodeType==3) {
      // when inserting into a textnode
      // we create 2 new textnodes
      // and put the insertNode in between
      var textNode = container;
      container = textNode.parentNode;
      var text = textNode.nodeValue;
      // text before the split
      var textBefore = text.substr(0,pos);
      // text after the split
      var textAfter = text.substr(pos);
      var beforeNode = document.createTextNode(textBefore);
      var afterNode = document.createTextNode(textAfter);
      // insert the 3 new nodes before the old one
      container.insertBefore(afterNode, textNode);
      container.insertBefore(insertNode, afterNode);
      container.insertBefore(beforeNode, insertNode);
      // remove the old node
      container.removeChild(textNode);
    } else {
      // else simply insert the node
      afterNode = container.childNodes[pos];
      container.insertBefore(insertNode, afterNode);
    }

    range.setEnd(afterNode, 0);
    range.setStart(afterNode, 0);
  }
  sel.addRange(range);
};

//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

var __xhtml = "";

function editGetXHtml()
{
  __xhtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

  var childs = getDoc().childNodes;
  var len = childs.length;

  for (var i=0; i<len; i++) {
    __processNode(childs[i]);
  }

  return __xhtml;
};

function __processNode(node)
{
  switch (node.nodeType)
  {
    // process element
    case 1:
      if (node.nodeName == "!") {	// IE5.0 and IE5.5
        __xhtml = __xhtml + node.text;
        break;
      }

      var name = node.nodeName;
      if (node.scopeName == "HTML")
        name = name.toLowerCase();
      __xhtml = __xhtml + "<" + name;

      // process node attributes
      var attributes = node.attributes;
      var len = attributes.length;
      for (var j=0; j<len; j++)
        __getAttributes(attributes[j], node);

      if (node.canHaveChildren || node.hasChildNodes()) {
        __xhtml = __xhtml + ">";
        // process childs
        var childs = node.childNodes;
        len = childs.length;
        for (var j=0; j<len; j++)
          __processNode(childs[j]);
        __xhtml = __xhtml + "</" + name + ">";
      } else if (name == "script") {
        __xhtml = __xhtml + ">" + node.text + "</" + name + ">";
      } else if (name == "title" || name == "style" || name == "comment") {
        __xhtml = __xhtml + ">" + node.innerHTML + "</" + name + ">";
      } else {
        __xhtml = __xhtml + " />";
      }
      break;

    // process text
    case 3:
      __xhtml = __xhtml + __checkText(node.nodeValue);
      break;

    // process data
    case 4:
      __xhtml = __xhtml + "<![CDA" + "TA[\n" + node.nodeValue + "\n]" + "]>";
      break;

    // process XML
    case 8:
      __xhtml = __xhtml + node.text;
      if (/(^<\?xml)|(^<\!DOCTYPE)/.test(node.text) )
        __xhtml = __xhtml + "\n";
      break;

    // process document
    case 9:
      var childs = node.childNodes;
      len = childs.length;
      for (var j=0; j<len; j++)
        __processNode(childs[j]);
      break;

    default:
      __xhtml = __xhtml + "<!-- Not found:" + "nodeName: " + node.nodeName + "-->";
  }
};

function __checkAttribute(s)
{
  return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
};

function __checkText(s)
{
  return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;");
};

function __getAttributes(attributeNode, node)
{
  if (!attributeNode.specified)
    return;

  var name = attributeNode.nodeName;
  var value = attributeNode.nodeValue;
  if (name != "style" ) {
    if (!isNaN(value))
      value = node.getAttribute(name);
    __xhtml = __xhtml + " " + (attributeNode.expando ? name : name.toLowerCase()) + "=\"" + __checkAttribute(value) + "\"";
  } else
    __xhtml = __xhtml + " style=\"" + __checkAttribute(node.style.cssText) + "\"";
};

function editPasteWord()
{
  editPaste();
  editClean(0);
  editClean(3);
};

function editClean(mode)
{
  editSetFocus();

  // Word
  if(mode==3) {
    __editCleanStyle();
    __editCleanTags();
    // Word specific
    var content = getDoc().body.innerHTML;
    content = content.replace(/o:title/gi, "title");
    content = content.replace(/v:imagedata/gi,"img");
    content = content.replace(/<\/IMG>/gi,"");
    content = content.replace(/<v:([^>]+)>/gi, "");
    content = content.replace(/<\/v:([^>]+)>/gi, "");
    content = content.replace(/<o:([^>]+)>/gi, "");
    content = content.replace(/<\/o:([^>]+)>/gi, "");
    content = content.replace(/<stl:([^>]+)>/gi, "");
    content = content.replace(/<\/stl:([^>]+)>/gi, "");
    content = content.replace(/<w:([^>]+)>/gi, "");
    content = content.replace(/<\/w:([^>]+)>/gi, "");
    content = content.replace(/<\?xml:([^>]+)>/gi, "");

    editSetBodyHtml(content);
  }
  // style and class
  if(mode==0) {
    __editCleanStyle();
  }
  // tags
  if(mode==2) {
    __editCleanTags();
  }
  // format
  if(mode==1) {
    editRemoveFormat();
  }
};

function __editCleanStyle()
{
  var body = getDoc().body;

  body.removeAttribute("style","",0);
  body.removeAttribute("className","",0);
  // remove the style and classes
  for (var i=0; i<body.all.length;i++) {
    var object = body.all[i];
    object.removeAttribute("style","",0);
    object.removeAttribute("className","",0);
  }
};

function __editCleanTags()
{
  var content = getDoc().body.innerHTML;
  // common
  content = content.replace(/\r/g, "");
  content = content.replace(/\n/g, "");
  content = content.replace(/\t/g, " ");
  content = content.replace(/<p>&nbsp;<\/p>/gi, "<BR>");
  content = content.replace(/&nbsp;/gi, " ");
  content = content.replace(/<font>/gi, "");
  content = content.replace(/<span>/gi, "");
  content = content.replace(/^\s/i, "");
  content = content.replace(/\s$/i, "");
  content = content.replace(/<font>([^<>]+)<\/font>/gi, '$1');
  content = content.replace(/<span>([^<>]+)<\/span>/gi, '$1');
  editSetBodyHtml(content);
};

/*
function setMode2(mode)
{
  var ed = getEdit();
  var tx = getText();

  if(mode == "EDIT") {
    __editShowSymbols();
    getDoc().designMode = 'On';
    if(browser.ns6) {
      tx.style.height = "1px";
      ed.style.height = __lastHeight;
    } else {
      ed.style.height = "100%";
      tx.style.height = "1px";
    }
    if(lastMode == 'HTML') {
      editWrite(tx.value);
      if(!browser.ns6)
        editSetStyleSheetRules();
    } else {
      setEvent();
    }
  }
  if(mode == "HTML") {
    if(browser.ns6) {
      __lastHeight = ed.style.height;
      ed.style.height = "1px";
      tx.style.height = __lastHeight;
    } else {
      ed.style.height = "1px";
      tx.style.height = "100%";
    }
    tx.value= editGetHtml();
  }
  if(mode == "PREVIEW") {
    var text = editGetHtml();
    getDoc().designMode = 'Off';
    if(lastMode == 'HTML')
      editSetText(tx.value);
    else
      editSetText(text);
    ed.style.height = "100%";
    tx.style.height = "1px";
  }
  lastMode = mode;
}
*/

