
var oEBDiv  = null;
var aEBCmds  = new Array();
var aEBEditors  = new Array();
var sEBBackColor  = null;
var sEBForeColor  = null;
var sEBCancelTab  = true;
var sEBImgPath  = "img/";
var dlgHelper = null;
var EBWinLoaded  = false;

var colorData = new Array('00','33','66','99','CC','FF');

function PopUpEdit(_obj, _win, _text, _noStyle) {
  var _Xelement;
  var _elementFound = false;
  _win.show(0,0,0,300, document.body);
  _win.hide();
  if (_noStyle) {
      if (_noStyle[0]) _win.document.body.style.color = _noStyle[0];
      if (_noStyle[1]) _win.document.body.style.backgroundColor = _noStyle[1];
  }
  if (_win.document.Xelement) {
      _win.document.Xelement.style.border="0px dashed #4169E1";
      if (_win.document.Xelement.SetInActive) _win.document.Xelement.SetInActive();
  }
  if (_text) {
      var _elements = _win.document.all.tags("TD");
      for (i=0; i < _elements.length; i++) {
           if (_elements[i].Data && _text && (LowerCase(_elements[i].Data)==LowerCase(_text))) {
               _win.document.Xelement = _elements[i];
               _elementFound = true;
               _win.document.Xelement.style.border="2px groove #4169E1";
               if (_win.document.Xelement.SetActive) _win.document.Xelement.SetActive();
               break;
           } 
      }
  }
  _win.show(0,
            _obj.offsetHeight,
//            Math.max(_win.document.body.scrollWidth,20),
            Math.max(_win.document.body.scrollWidth,_obj.offsetWidth),
            Math.min(_win.document.xtable.scrollHeight+5,300),
            _obj);
  _win.document.body.children(0).scrollTop = 0;
  if (_elementFound) _win.document.Xelement.scrollIntoView(true);
}

function CreateColorPopUp(_isBack, _isSel) {
  var _win=window.createPopup();

      _win.document.body.callback_handler = null;
      _win.document.body.callback_data = null;
      _win.document.body.onselectstart = function() { return false; }
  var _cont = _win.document.createElement("DIV");
      _cont.style.height="100%";
      _cont.style.overflowX="visible";
      _cont.style.overflowY="scroll";
      _cont.style.border="2px solid #666666";
      _cont.style.cursor="default";
  var _tb = _win.document.createElement("TABLE");
      _tb.width="100%";
//      _tb.height="100%";
//      _tb.cellSpacing=(_isSel)?3:0;
  var _tbb = _win.document.createElement("TBODY");
  _tb.appendChild(_tbb);
  var c1 = 0; var c2 = 0; var c3 = 0;
  for (var i=0; i<12; i++) {
    var _el = _win.document.createElement("TR");
    for (var j=0; j<18; j++) {
      var _element = _win.document.createElement("TD");
      _element.noWrap = true;
      _element.innerText='';
      var _color = '#'+colorData[c1]+colorData[c2]+colorData[c3];
      _element.Data = _color;
      _element.title = _element.Data;
      _element.menu = _win;
      _element.width = "10px";
      _element.height = "10px";
      if (_isBack) {
          _element.onmouseover = function() { this.style.backgroundColor = "#4169E1"; this.style.color = this.Data; }
          _element.onmouseout = function() { this.style.backgroundColor = this.Data; this.style.color = this.parentElement.style.color; }
          _element.style.backgroundColor = _color;
      } else {
          _element.onmouseover = function() { this.style.backgroundColor = "#4169E1"; this.style.color = "#FFFFFF"; }
          _element.onmouseout = function() { this.style.backgroundColor = 'transparent'; this.style.color = this.Data; }
          _element.style.color = _color;
          _element.style.fontFamily = "Verdana";
          _element.style.fontSize = "8px";
          _element.style.fontWeight = "bold";
          _element.style.padding = "0px";
          _element.style.textAlign = "center";
          _element.innerText='X';
      }
      _element.onclick = function() { if (this.menu.document.body.callback_handler==null) return; this.onmouseout(); this.menu.hide(); this.menu.document.body.callback_handler(this.Data, this.menu.document.body.callback_data); }
      _el.appendChild(_element);
      c3++; 
      if (c3>5) {c3 = 0; c2++;} 
      if (c2>5) {c2 = 0; c1++;} 
    }
    _tbb.appendChild(_el);
  }
  _cont.appendChild(_tb);
  _win.document.body.appendChild(_cont);
  _win.document.xcont = _cont;
  _win.document.xtable = _tb;
  return _win;
}

function fnEBNewComboItem(_obj, _value, _text) {
       var _o = document.createElement("OPTION");
       _o.value=_value;
       _o.text=(_text==null)?_value:_text;
       _obj.add(_o);
}

function fnEBOnLoad() {
  fnEBFillStyles();
  for (var i=0; i<aEBEditors.length; i++) {
      aEBEditors[i].fnEBUpdatePanel();
  }
  EBWinLoaded  = true;
}

window.attachEvent("onload", fnEBOnLoad);

function fnEBNewElement(mainObj, containerObj, elementName, elementId, elementType) {
   var _c_obj = (containerObj!=null)?containerObj:mainObj;
   var _obj = document.createElement(elementName);
   if (elementType) _obj.type=elementType;
   _obj.mainObj = mainObj;
   if (_c_obj!=null) _c_obj.appendChild(_obj);
   if (mainObj!=null && elementId) {
       _obj.id = elementId;
       mainObj[elementId] = _obj;
       if (containerObj!=null) containerObj[elementId] = _obj;
   }
   return _obj;
}

function fnEBCreateToolBar(mainObj, containerObj, tbName) {
   var _tb_obj = fnEBNewElement(mainObj, (containerObj)?containerObj:mainObj, "TABLE", "tbName");
   _tb_obj.cellPadding=0;
   _tb_obj.cellSpacing=0;
   _tb_obj.border=0;
   _tb_obj.className="EB-toolbar";
   _tb_obj.width="100%";
   var _tb_body = fnEBNewElement(mainObj, _tb_obj, "TBODY", tbName+"TBody");
   var _tb_row = _tb_body.insertRow();
       _tb_row.mainObj = mainObj;
       _tb_row.parentObj = _tb_obj;
   mainObj[tbName+"Row"] = _tb_row;
   return _tb_row;
}

function fnEBNewButton(row, cmdName, cmdFunc) {
        _Obj = row.insertCell(); row.mainObj["tdEB"+cmdName] = _Obj;
        _Obj.id = "tdEB"+cmdName;
        _Obj.className = "EB-normal";
        _Obj.width=20;
        _Obj.height=20;
        _Obj.onmouseover=row.mainObj.elOver;
        _Obj.onmouseout=row.mainObj.elOut;
        var _imgObj=fnEBNewElement(row.mainObj, _Obj, "IMG", "imgEB"+cmdName);
            _imgObj.width=20;
            _imgObj.height=20;
            _imgObj.alt = cmdName;
            _imgObj.xcommand = cmdName;
            _imgObj.xfunc = cmdFunc;
            _imgObj.onclick=function() { if (EBWinLoaded) this.xfunc(this.xcommand); }
            _imgObj.src = sEBImgPath+"EB"+cmdName+".gif";
   return _Obj;
}

function fnEBNewCmdButton(row, cmdName, bLonely, bState) {
        _Obj = row.insertCell(); row.mainObj["tdEB"+cmdName] = _Obj;
        _Obj.id = "tdEB"+cmdName;
        _Obj.className = "EB-normal";
//        _Obj.width=20;
//        _Obj.height=20;
//        _Obj.style.display="none";
        _Obj.onmouseover=row.mainObj.elOver;
        _Obj.onmouseout=row.mainObj.elOut;
        var _imgObj=fnEBNewElement(row.mainObj, _Obj, "IMG", "imgEB"+cmdName);
            _imgObj.width=20;
            _imgObj.height=20;
            _imgObj.alt = cmdName;
            _imgObj.xcommand = cmdName;
            _imgObj.onclick=function() { if (EBWinLoaded) row.mainObj.fnEBToggle(this.xcommand); }
            _imgObj.src = sEBImgPath+"EB"+cmdName+".gif";
            row.mainObj.fnEBAppendCommand(cmdName, bLonely, bState);
   return _Obj;
}

function fnEBNewPromptCmdButton(row, cmdName, bLonely, bState, pText, pDefault) {
        _Obj = row.insertCell(); row.mainObj["tdEB"+cmdName] = _Obj;
        _Obj.id = "tdEB"+cmdName;
        _Obj.className = "EB-normal";
        _Obj.onmouseover=row.mainObj.elOver;
        _Obj.onmouseout=row.mainObj.elOut;
        var _imgObj=fnEBNewElement(row.mainObj, _Obj, "IMG", "imgEB"+cmdName);
            _imgObj.width=20;
            _imgObj.height=20;
            _imgObj.alt = cmdName;
            _imgObj.xcommand = cmdName;
            _imgObj.onclick=function() { if (EBWinLoaded) { pValue = prompt(pText,pDefault); if (pValue&&(pValue!=pDefault)) row.mainObj.fnEBToggle(this.xcommand,pValue); } }
            _imgObj.src = sEBImgPath+"EB"+cmdName+".gif";
            row.mainObj.fnEBAppendCommand(cmdName, bLonely, bState);
   return _Obj;
}

function fnEBNewComboCmdButton(row, cmdName, bLonely, bState, _width) {
        _Obj = row.insertCell(); row.mainObj["tdEB"+cmdName] = _Obj;
        _Obj.id = "tdEB"+cmdName;
        _Obj.className = "EB-normal";
//        _Obj.style.display="none";
        _Obj.onmouseover=row.mainObj.elOver;
        _Obj.onmouseout=row.mainObj.elOut;
        _Obj.selObj=fnEBNewElement(row.mainObj, _Obj, "SELECT", "selectEB"+cmdName);
        _Obj.selObj.xcommand = cmdName;
        _Obj.selObj.onchange=function() { if (EBWinLoaded) row.mainObj.fnEBToggle(this.xcommand, this.value); }
        if (_width) _Obj.selObj.style.width = _width;
        row.mainObj.fnEBAppendCommand(cmdName, bLonely, bState);
   return _Obj;
}

function fnEBNewColorCmdButton(row, cmdName, bLonely, bState) {
        _Obj = row.insertCell(); row.mainObj["tdEB"+cmdName] = _Obj;
        _Obj.id = "tdEB"+cmdName;
        _Obj.className = "EB-normal";
//        _Obj.width=20;
//        _Obj.height=20;
//        _Obj.style.display="none";
        _Obj.onmouseover=row.mainObj.elOver;
        _Obj.onmouseout=row.mainObj.elOut;
        _Obj.xcommand = cmdName;
        _Obj.onclick=function() { row.mainObj.fnEBToggleColor(this.xcommand); }
        var _divObj=fnEBNewElement(_Obj, _Obj, "DIV");
            _divObj.style.position="absolute";
            _divObj.style.width=20;
        var _tbObj=fnEBNewElement(_divObj, _divObj, "TABLE");
            _tbObj.cellPadding=0;
            _tbObj.cellSpacing=0;
            _tbObj.border=0;
            _tbObj.width=16;
            _tbObj.align="center";
        var _tb_body = fnEBNewElement(_tbObj, _tbObj, "TBODY");
        var _tb_cell = _tb_body.insertRow().insertCell();
            var _imgObj=fnEBNewElement(_tb_cell, _tb_cell, "IMG");
                _imgObj.height=14;
                _imgObj.width=1;
            var _tb_cell = _tb_body.insertRow().insertCell();
                _tb_cell.id="tdEB"+cmdName+"Help";
                _tb_cell.bgColor="#FFFFFF";
                row.mainObj["tdEB"+cmdName+"Help"] = _tb_cell;
                fnEBNewElement(_tb_cell, _tb_cell, "IMG").height=4;

        var _tbObj=fnEBNewElement(_Obj, _Obj, "TABLE");
            _tbObj.cellPadding=0;
            _tbObj.cellSpacing=0;
            _tbObj.border=0;
            _tbObj.width=16;
            _tbObj.align="center";
        var _tb_body = fnEBNewElement(_tbObj, _tbObj, "TBODY");
        var _tb_row = _tb_body.insertRow();

        var _tb_cell = _tb_row.insertCell();
        var _imgObj=fnEBNewElement(_tb_cell, _tb_cell, "IMG");
            _imgObj.width=20;            
            _imgObj.height=20;
            _imgObj.border=0;
            _imgObj.alt = cmdName;
            _imgObj.src = sEBImgPath+"EB"+cmdName+".gif";

        var _tb_cell = _tb_row.insertCell();
        var _imgObj=fnEBNewElement(_tb_cell, _tb_cell, "IMG");
            _imgObj.width=11;
            _imgObj.height=20;
            _imgObj.border=0;
            _imgObj.alt = "Choose color";
            _imgObj.xcommand = cmdName;
            _imgObj.button_obj = _Obj;
            _imgObj.onclick=function() { row.mainObj.fnEBChooseColor(this.button_obj, this.xcommand); }
            _imgObj.src = sEBImgPath+"EBDown.gif";
        row.mainObj.fnEBAppendCommand(cmdName, bLonely, bState);

   return _Obj;
}

function fnEBInsertBtnSpacer(_RowObj) {
    var _cell = null;
    var _img = null;

    _cell = _RowObj.insertCell(); _cell.width=3;
    _img=fnEBNewElement(_cell, _cell, "IMG"); _img.width=3;

    _cell = _RowObj.insertCell(); _cell.width=1;
    fnEBNewElement(_cell, _cell, "DIV", "xdiv");
    _cell.xdiv.style.backgroundColor = "buttonshadow";
    _cell.xdiv.style.height = 16;
    _img=fnEBNewElement(_cell.xdiv, _cell.xdiv, "IMG"); _img.width=1;
                                                            
    _cell = _RowObj.insertCell(); _cell.width=3;
    _img=fnEBNewElement(_cell, _cell, "IMG"); _img.width=3;

    return _cell;
}

function fnEBInsertSqeezer(_RowObj) {
    var _cell = null;
    _cell = _RowObj.insertCell();
    _cell.mainObj=_RowObj.mainObj;
    _cell.width="100%";
    _cell.align="right";
    _cell.innerText = ' ';
    return _cell;
}

function fnEBInsertBlankContainer(_RowObj) {
    var _cell = null;
    _cell = _RowObj.insertCell();
    _cell.mainObj=_RowObj.mainObj;
    _cell.width="16";
    _cell.align="left";
    _cell.innerText = ' ';
    return _cell;
}

function fnEBGenInterface(_oobj, _with_preview) {
    var row = null;
    var cell = null;
    var mainDiv = null;
    var currObjIndex = aEBEditors.length;
    if (_oobj) {
       mainDiv = fnEBNewElement(_oobj, _oobj, "DIV");
       mainDiv.id = "EBmainDiv"+currObjIndex;
    } else {
       document.write('<div id="EBmainDiv'+currObjIndex+'"></div>');
       mainDiv = document.getElementById("EBmainDiv"+currObjIndex);
    }
        aEBEditors[aEBEditors.length] = mainDiv;
        mainDiv.style.border = "solid 1px buttonshadow";
        mainDiv.aEBCmds  = new Array();
        mainDiv.ForeColorMenu = CreateColorPopUp();
        mainDiv.BackColorMenu = CreateColorPopUp(true);
        mainDiv.fnEBAboutBox = function () {
                                            alert(
                                                  "WebWord. Written By Sergej Iljinskij\n"+
                                                  "08.02.2003 Copyright by MagicA\n"+
                                                  "\n"+
                                                  "5.05.2003 ReWrited and fixed by DSD\n"+
                                                  "\n"+
                                                  "30.07.2004 ReWrited and fixed by Sunsai\n"+
              "\n"+
                                                  "28.08.2006 ReWrited and fixed by FoMa\n");
                                             }
        mainDiv.fnEBAppendCommand = function (sCommand, bLonely, bState) {
                                              this.aEBCmds[sCommand]  = new Array();
                                              this.aEBCmds[sCommand].l  = bLonely;
                                              this.aEBCmds[sCommand].s  = bState;
                                             }
        mainDiv.fnEBToggle = function (sCommand, sValue) {
                                         this.currEdit.focus();
                                         if (this.aEBCmds[sCommand].l)
                                           document.execCommand(sCommand);
                                         else
                                           document.execCommand(sCommand, false, sValue);
                                         this.fnEBUpdatePanel();
                                       }
        mainDiv.fnEBUpdatePanel = function () { for (var sCommand in this.aEBCmds) if (this.aEBCmds[sCommand].s) this.fnEBCheckCmdState(sCommand, this.aEBCmds[sCommand].s); }
        mainDiv.fnEBCheckCmdState = function (sCommand, nType) {
                                                if (nType == 2) {
                                                   var sValue  = document.queryCommandValue(sCommand);
                                                   if (sValue != null) this["selectEB"+sCommand].value  = sValue;
                                                } else if (nType == 3) {
                                                   var sValue  = document.queryCommandValue(sCommand);
                                                   if (sValue == null)  return;
                                                   sValue = sValue.toString(16);
                                                   if (sValue.length < 6) sValue  = "000000".substring(0, 6-sValue.length).concat(sValue);
                                                   sValue = sValue.substr(4, 2)+sValue.substr(2, 2)+sValue.substr(0, 2);
                                                   if (sCommand == "BackColor") sEBBackColor  = sValue;
                                                   else if (sCommand == "ForeColor") sEBForeColor  = sValue;
                                                   if (sValue) this["tdEB"+sCommand+"Help"].style.backgroundColor  = sValue;
                                                 } else {
                                                   var  oTd  = this["tdEB"+sCommand];
                                                   if (document.queryCommandState(sCommand))
                                                     oTd.olderName  = "EB-active";
                                                   else
                                                     oTd.olderName  = "EB-normal";
                                                   oTd.className  = oTd.olderName;
                                                 } 
                                             }
        mainDiv.fnEBToggleColor = function (sCommand) {
                                               this.fnEBToggle(sCommand, eval("sEB"+sCommand));
                                            }
        mainDiv.fnEBChooseColor = function (_obj, sCommand) {
                                               this.currEdit.focus();
                                               var stand = (this.currEdit.mainObj["cb_stand_dlg"] && this.currEdit.mainObj.cb_stand_dlg.checked);
                                               if (stand && dlgHelper && dlgHelper['fonts']) {
                                                 var sValue  = this.dlgHelper.ChooseColorDlg(eval("sEB"+sCommand));
                                                     sValue  = sValue.toString(16);
                                                 if (sValue.length < 6) sValue  = "000000".substring(0, 6-sValue.length).concat(sValue);
                                                 document.execCommand(sCommand, false, sValue);
                                                 if (sCommand == "BackColor") sEBBackColor  = sValue;
                                                 else if (sCommand == "ForeColor") sEBForeColor  = sValue;
                                                 this["tdEB"+sCommand+"Help"].style.backgroundColor  = sValue;
                                               } else {
                                                 this.currEdit.mainObj[sCommand+"Menu"].document.body.callback_data = [this, sCommand];
                                                 this.currEdit.mainObj[sCommand+"Menu"].document.body.callback_handler = function(_color, callback_data) {
                                                    var _obj = callback_data[0];
                                                    var _sCommand = callback_data[1];
                                                    if (_sCommand == "BackColor") sEBBackColor  = _color;
                                                    else if (_sCommand == "ForeColor") sEBForeColor  = _color;
                                                    _obj.currEdit.focus();
                                                    _obj.document.execCommand(_sCommand, false, _color);
                                                    _obj["tdEB"+_sCommand+"Help"].style.backgroundColor  = _color;
                                                 }
                                                 if (sCommand == "BackColor") {
                                                    PopUpEdit(_obj, this.currEdit.mainObj[sCommand+"Menu"], '', [this.currEdit.mainObj["tdEBForeColorHelp"].style.backgroundColor, false]);
                                                 } else if (sCommand == "ForeColor") {
                                                    PopUpEdit(_obj, this.currEdit.mainObj[sCommand+"Menu"], '', [false, this.currEdit.mainObj["tdEBBackColorHelp"].style.backgroundColor]);
                                                 }
                                               }
                                            }
        mainDiv.fnEBOnKeyDown = function (sCommand) {
                                             if (event.keyCode<41 && 36<event.keyCode) this.fnEBUpdatePanel();
                                             if (sEBCancelTab && event.keyCode==9) event.returnValue=false;
                                          }

        mainDiv.is_HTMLEdit = true;
        mainDiv.fnEBsetHTMLEdit = function (_is_html) {
                                                if (this.is_HTMLEdit==_is_html) return;
                                                this.is_HTMLEdit = _is_html;                                                 
                                                if (this.is_HTMLEdit) {
                                                   this.divEdit.innerHTML = this.body_container.value;
                                                   if (this.with_preview) this.divEdit_p.innerHTML = this.body_container_p.value;
                                                } else {
                                                   this.body_container.value = this.divEdit.innerHTML;
                                                   if (this.with_preview) this.body_container_p.value = this.divEdit_p.innerHTML;
                                                }                                                           
                                                this.textRow.style.display = (this.is_HTMLEdit)?"none":"block";
                                                if (this.with_preview) this.textRow_p.style.display = (this.is_HTMLEdit)?"none":"block";
                                                this.row1.style.display = (this.is_HTMLEdit)?"block":"none";
//                                                this.row2.style.display = (this.is_HTMLEdit)?"block":"none";
//                                                this.row3.style.display = (this.is_HTMLEdit)?"block":"none";
                                                if (this.with_preview) this.row4a.style.display = (this.is_HTMLEdit)?"block":"none";
                                                this.row4.style.display = (this.is_HTMLEdit)?"block":"none";
                                                this.html_toggle_button.className = (this.is_HTMLEdit)?"EB-normal":"EB-active";
                                            }


 
//        mainDiv.style.width = "600px";            
        mainDiv.style.height = "100%";
        mainDiv.oncontextmenu = function() { return false; }
        mainDiv.onselectstart = function() { return false; }
        mainDiv.elOver = function() { if (!EBWinLoaded) return; this.olderName  = this.className; this.className  = "EB-hover"; }
        mainDiv.elOut = function() { if (!EBWinLoaded) return; if (this.className != "EB-active") this.className  = this.olderName; }

        if (dlgHelper==null) {
            dlgHelper = fnEBNewElement(mainDiv, mainDiv, "OBJECT", "dlgHelper");
            mainDiv.dlgHelper.style.width="0px";
            mainDiv.dlgHelper.style.height="0px";
            mainDiv.dlgHelper.classid="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b";
        } else {
            mainDiv.dlgHelper = dlgHelper;
        }

        var _tbObj=fnEBNewElement(mainDiv, mainDiv, "TABLE");
            _tbObj.cellPadding=0;
            _tbObj.cellSpacing=3;
            _tbObj.border=0;
            _tbObj.width="100%";
            _tbObj.height="100%";
            _tbObj.className = "EB-normal";
        var _tb_body = fnEBNewElement(_tbObj, _tbObj, "TBODY");

        mainDiv.captRow = _tb_body.insertRow(); mainDiv.captRow.height="1%";
        row = fnEBCreateToolBar(mainDiv, mainDiv.captRow.insertCell(), "prefirstToolBar");
        cell = fnEBInsertSqeezer(row);
        cell.className = '';
        cell.style.padding = "2px";
        cell.style.backgroundColor = "#0000FF";
        cell.style.color = "#FFFFFF";
        cell.style.fontWeight = "bold";
        cell.style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#FF214DA6', EndColorStr='#FF218DE6')";
        cell.innerText = "Caption";
        cell.align = "center";
        mainDiv.captCell = cell;
        mainDiv.html_toggle_button = fnEBNewButton(row, 'Html', function() { mainDiv.fnEBsetHTMLEdit(!mainDiv.is_HTMLEdit); });
        
        

        mainDiv.curr_body_container = null;
        mainDiv.with_preview = _with_preview;

        if (_with_preview) {
            mainDiv.textRow_p = _tb_body.insertRow();
            mainDiv.textRow_p.height = 200;
            mainDiv.textRow_p.style.display = "none";
            mainDiv.body_container_p = fnEBNewElement(mainDiv, mainDiv.textRow_p.insertCell(), "TEXTAREA", "body_container_p");
            mainDiv.body_container_p.onselectstart=function() { event.cancelBubble=true; }
            mainDiv.body_container_p.style.width="100%";
            mainDiv.body_container_p.style.height="100%";
            mainDiv.body_container_p.rows = 10;
            mainDiv.body_container_p.cols = 60;
        }

        mainDiv.textRow = _tb_body.insertRow();
        mainDiv.textRow.style.display = "none";
        mainDiv.body_container = fnEBNewElement(mainDiv, mainDiv.textRow.insertCell(), "TEXTAREA", "body_container");
        mainDiv.body_container.onselectstart=function() { event.cancelBubble=true; }
        mainDiv.body_container.style.width="100%";
        mainDiv.body_container.style.height="100%";
        mainDiv.body_container.rows = 20;
        mainDiv.body_container.cols = 60;

        mainDiv.curr_body_container = mainDiv.body_container;

//   <textarea id="body_old" class="news_body_edit" style="display:none;width:100%;height:100%;" rows=20 cols=60 name="cntbody"><?=$body?></textarea>

        
        mainDiv.row1 = _tb_body.insertRow(); mainDiv.row1.height="1%";
        row = fnEBCreateToolBar(mainDiv, mainDiv.row1.insertCell(), "firstToolBar");
           fnEBNewCmdButton(row, "Bold", true, 1);
           fnEBNewCmdButton(row, "Italic", true, 1);
           fnEBNewCmdButton(row, "Underline", true, 1);
           fnEBInsertBtnSpacer(row);
           fnEBNewCmdButton(row, "JustifyLeft", true, 1);
           fnEBNewCmdButton(row, "JustifyCenter", true, 1);
           fnEBNewCmdButton(row, "JustifyRight", true, 1);
           fnEBNewCmdButton(row, "JustifyFull", true, 1);
           fnEBInsertBtnSpacer(row);
           fnEBNewColorCmdButton(row, "BackColor", false, 3);
           fnEBNewColorCmdButton(row, "ForeColor", false, 3);
           fnEBInsertBtnSpacer(row);
           fnEBNewCmdButton(row, "InsertHorizontalRule", true, false);
           fnEBInsertBtnSpacer(row);
           cell = fnEBInsertBlankContainer(row);
           cell.innerHTML = '<img src=img/EBCreateLink.gif border=0>';
           cell.title = 'Create Link';
           cell.className = "EB-normal";
           cell.onmouseover=mainDiv.elOver;
           cell.onmouseout=mainDiv.elOut;
           cell.onclick = function() {
                 this.mainObj.currEdit.focus();
             var sText = document.selection.createRange();
             var sp0 = "http://";
             if (sText.parentElement().tagName == "A") sp0=sText.parentElement().href;
             var sp1 = sText.text;
             var sp = ShowInterface(sp0, sp1);
             if (!sp || sp[0]=="") return false;
             if (sp[1]=="" && sText.text=="") sp[1] = sp[0];
             sText.pasteHTML('<a target="_blank" href="'+sp[0]+'">'+sp[1]+'</a>');
           }
//           fnEBNewCmdButton(row, "CreateLink", true, false);
           fnEBNewCmdButton(row, "Unlink", true, false);
           fnEBNewPromptCmdButton(row, "InsertImage", false, false,"URL картинки","http://");
           fnEBInsertBtnSpacer(row);

           cell = fnEBInsertBlankContainer(row);
           cell = fnEBInsertBlankContainer(row);
           cell.innerHTML = '<img src=images/item_left.gif border=0 hspace=5>';
           cell.title = 'Artifact';
           cell.className = "EB-normal";
           cell.onmouseover=mainDiv.elOver;
           cell.onmouseout=mainDiv.elOut;
           cell.onclick = function() {
                 this.mainObj.currEdit.focus();
             var sText = document.selection.createRange();
             var sp = sText.text;
             if (!sp) return false;
//             var s = window.showModalDialog("data.php?what=art&value="+sp,false,"dialogWidth:400px;dialogHeight:200px;center:1;scroll:0;resizable:1;help:0;status:0");
//             if (s) sText.pasteHTML(s);
             sText.pasteHTML('[[art'+sp+']]');
           }
                                                            
           fnEBInsertSqeezer(row);

/*           cell = fnEBInsertBlankContainer(row);
           cell.innerText = '[NW]';
           cell.style.cursor = 'hand';
           cell.title = 'To new window';
           cell.onclick = function() {
                                 var win=window.open("","_blank");
                                 win.document.open("text/html");
                                 win.document.write("<HTML>\n\n<BODY>\n"+this.mainObj.currEdit.innerHTML+"\n</BODY>\n</HTML>\n");
                                 fnEBFillStyles(win);
                                 win.document.close();
                                 }

           fnEBInsertBtnSpacer(row);*/

           cell = fnEBInsertBlankContainer(row);
           cell.innerHTML = '<font style="font-size: 10px;"><i><b><font color=red>W</font>eb</b><u><font style="background-color:yellow">W</font>ord</u><b>!</b>&nbsp;</i></font>';
           cell.style.cursor = 'hand';
           cell.title = 'About';
           cell.onclick = function() { this.mainObj.fnEBAboutBox(); }
  
        mainDiv.currEdit = null;

        if (_with_preview) {
            mainDiv.row4a = _tb_body.insertRow();
            mainDiv.row4a.height = 100;
            fnEBNewElement(mainDiv, mainDiv.row4a.insertCell(), "DIV", "divEdit_p");
            mainDiv.divEdit_p.contentEditable=true;
            mainDiv.divEdit_p.onclick=function() { this.mainObj.currEdit = this.mainObj.divEdit_p; this.mainObj.fnEBUpdatePanel(); }
            mainDiv.divEdit_p.onkeydown=function() { this.mainObj.currEdit = this.mainObj.divEdit_p; this.mainObj.fnEBOnKeyDown(); }
            mainDiv.divEdit_p.oncontextmenu=function() { event.cancelBubble=true; }                  
            mainDiv.divEdit_p.onselectstart=function() { event.cancelBubble=true; }
            mainDiv.divEdit_p.onfocus=function() { this.mainObj.currEdit = this.mainObj.divEdit_p; }
            mainDiv.divEdit_p.style.margin = "2px";
            mainDiv.divEdit_p.style.border = "solid 1px buttonshadow";
            mainDiv.divEdit_p.style.height = "100%";
            mainDiv.divEdit_p.style.overflow="auto";
            mainDiv.divEdit_p.style.backgroundColor="#FFFFFF";
        }

        mainDiv.row4 = _tb_body.insertRow();
        fnEBNewElement(mainDiv, mainDiv.row4.insertCell(), "DIV", "divEdit");
        mainDiv.divEdit.contentEditable=true;
        mainDiv.divEdit.onclick=function() { this.mainObj.currEdit = this.mainObj.divEdit; this.mainObj.fnEBUpdatePanel(); }
        mainDiv.divEdit.onkeydown=function() { this.mainObj.currEdit = this.mainObj.divEdit; this.mainObj.fnEBOnKeyDown(); }
        mainDiv.divEdit.oncontextmenu=function() { event.cancelBubble=true; }
        mainDiv.divEdit.onselectstart=function() { event.cancelBubble=true; }            
        mainDiv.divEdit.onfocus=function() { this.mainObj.currEdit = this.mainObj.divEdit; }
        mainDiv.divEdit.style.margin = "2px";
        mainDiv.divEdit.style.border = "solid 1px buttonshadow";
        mainDiv.divEdit.style.height = "100%";
        mainDiv.divEdit.style.overflow="auto";
        mainDiv.divEdit.style.backgroundColor="#FFFFFF";

        mainDiv.currEdit = mainDiv.divEdit;

        return mainDiv;
}

function fnEBFillStyles(_win) {
   if (!_win) _win=window;
   var st_sheet = _win.document.createStyleSheet();
//   st_sheet.addRule("BODY"," margin: 0px; padding: 0px; ");
//   st_sheet.addRule("SELECT"," font: 10px Verdana; ");
//   st_sheet.addRule("TD"," font: 10px Verdana; ");
   st_sheet.addRule("P"," margin: 0px; ");
   st_sheet.addRule("H1"," margin: 0px; ");
   st_sheet.addRule("H2"," margin: 0px; ");
   st_sheet.addRule("H3"," margin: 0px; ");
   st_sheet.addRule("H4"," margin: 0px; ");
   st_sheet.addRule("H5"," margin: 0px; ");
   st_sheet.addRule("H6"," margin: 0px; ");
   st_sheet.addRule(".EB-toolbar"," background-color: buttonface; ");
   st_sheet.addRule(".EB-normal"," border-style: solid; border-width: 1px; border-color: buttonface; background-color: buttonface; ");
   st_sheet.addRule(".EB-hover"," border-style: solid; border-width: 1px; border-color: #316AC5; background-color:  #E1E6E8; ");
   st_sheet.addRule(".EB-active"," border-style: solid; border-width: 1px; border-color: #316AC5; background-color:  #C1D2EE; ");
}

function fnEBPreInit(_obj, _with_preview) {

   // defines div for operating
   sEBCancelTab  = true;

   return fnEBGenInterface(_obj, _with_preview).divEdit;
}



