
var bodyid,htmlableID,tmp_uppath;
var jk_edit_olddocmd; 

var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1];
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1];
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 );
var is_ie4 = ((parseInt(navigator.appVersion)  == 4) && (navigator.userAgent.toLowerCase().indexOf("msie 5")==-1) && (navigator.userAgent.toLowerCase().indexOf("msie 6")==-1) );

aeObjects = new Array(); 
var aeFieldnames = new Array();
var DHTMLSafe; 
var jk_edit_count;
var jk_edit_hot; 
var jk_edit_sourceview=false; 
var jk_edit_oldfontfamily='';  
var jk_edit_oldfontsize='';
var jk_edit_HTMLMode = new Array(); 

var tableparamobj=new ActiveXObject("DEInsertTableParam.DEInsertTableParam");
tableparamobj.NumRows=3;
tableparamobj.NumCols=3;   
tableparamobj.Caption="";
tableparamobj.TableAttrs="border=0 cellpadding=0 cellspacing=0 width=75%";
tableparamobj.CellAttrs="";

var alloweditsource = new Array();
var tabview = new Array();
var jk_edit_fieldname = new Array();        
var jk_edit_imagedata = new Array();        
var jk_edit_imageurl = new Array();
var jk_edit_defaultfont = new Array();        
var jk_edit_baseurl = new Array();        
var jk_edit_breakonenter = new Array();
var inc = '';  
jk_edit_breakonenter[1] = true;
jk_edit_baseurl[1] = document.location;
jk_edit_defaultfont[1] ="" ;
tabview[1] = false;
alloweditsource[1] = true;
jk_edit_imagedata[1] = '';        
//jk_edit_imageurl[1] = '/media';
jk_edit_imageurl[1] = '../piclibrary';

function jk_edit_init(num)
{
  var q=window.location.href;
  var a;
  q=q.substr(q.indexOf("?")+1);
  q=q.split("&");
  if (q.length<2) { return true; }
  a=q[0].split("=");
  bodyid=a[1];
  a=q[1].split("=");
  htmlableID=a[1];
  a=q[2].split("=");
  tmp_uppath=a[1];
  if (bodyid=="2")
  { eval("document.all.jk_word.value=self.opener."+htmlableID+".value;"); }
  else
  { eval("document.all.jk_word.value=ubb2html(self.opener."+htmlableID+".value);"); }
}

function jk_edit_save(num)
{
  eval("self.opener."+htmlableID+".value=DHTMLSafe.DOM.body.innerHTML;");
  self.close();
}

function jk_edit_initialize(num)
{
  jk_edit_count=num;
  thisContentItem=eval("document.all.jk_word");
  thisForm=thisContentItem;
  while(thisForm.tagName!="FORM"&&thisForm.tagName!="HTML") { thisForm=thisForm.parentElement; }
  if(thisForm.tagName!="HTML")
  {    
    DHTMLSafe = eval("thisForm.DHTMLSafe"+num);
    aeObjects[num] = DHTMLSafe;
    aeObjects[thisContentItem.name] = DHTMLSafe;
    aeFieldnames[num] = thisContentItem.name;
    thisForm.onsubmit = jk_edit_onSubmit;
  }
  else
  {
    alert("对不起，操作出错。", "", true);
    return;
  }
  DHTMLSafe.NewDocument();
  DHTMLSafe.BaseURL=jk_edit_baseurl[num];
  set_tbstates(num);
  jk_edit_onLoad(num);
  jk_edit_HTMLMode[num] = false;
}

function jk_edit_onerror(msg, detail, popup)
{
  errwin = this;
  if(popup) errwin = window.open("","","scrollbars=yes,width=500,height=400,resizable=yes", true);
  errwin.document.write("<HR>对不起，操作出错。</H4><P>");
  errwin.document.write(msg);
  errwin.document.write(detail);
  errwin.document.write("<P><P></TD></TR></TABLE><P><HR>");
}

function jk_edit_previewNewWin(p)
{
  prevWin = window.open("", "", "left=40,top=10,width=720,height=540,menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes");
  if (jk_edit_HTMLMode[1] == true) { prevWin.document.write("<body size=2>" + DHTMLSafe.DOM.body.innerText);  }
  else { prevWin.document.write("<body size=2>" + DHTMLSafe.DOM.body.innerHTML);  }
  if (p==0)
  { prevWin.document.title = "内容预览"; }
  else
  {
    prevWin.document.write ("\n<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WB width=0></OBJECT>\n<script language=\"JavaScript\">WB.ExecWB(7,1);\<\/script>");
    prevWin.document.close;
  }
}

function jk_edit_onLoad(num)
{
  DHTMLSafe=aeObjects[num];
  if(DHTMLSafe.Busy)
  {
    setTimeout("jk_edit_onLoad("+num+");", 100);  
    return;
  }
  if(num==1) window.onunload = jk_edit_onUnload;
  if(jk_edit_defaultfont[num].length) 
  { DHTMLSafe.DOM.body.style.font=jk_edit_defaultfont[num]; }
  else
  {
    DHTMLSafe.DOM.body.style.fontFamily="宋体";
    DHTMLSafe.DOM.body.style.fontSize="12px";
  }
  if(oSel=eval('document.all.oQuickFormat'+num))
  {
    var f=new ActiveXObject("DEGetBlockFmtNamesParam.DEGetBlockFmtNamesParam");
    DHTMLSafe.ExecCommand(5012,0,f);
    vbarr = new VBArray(f.Names);
    arr = vbarr.toArray();
    for (var i=0;i<arr.length;i++)
    {
      oOption = document.createElement("OPTION");
      oSel.options.add(oOption);
      oOption.text=arr[i];
      oOption.name=arr[i];
    }
  }
  thisContentItem=eval("document.all.jk_word");
  if(thisContentItem.value.length) { aeObjects[num].DOM.body.innerHTML = thisContentItem.value; }
  else { aeObjects[num].DOM.body.innerHTML = " "; }
  set_tbstates(num);
  if(typeof(aeapi_local_onLoad)=='function') { aeapi_local_onLoad(DHTMLSafe, aeFieldnames[num]); }
  if (typeof(aeapi_onLoad)=='function') { aeapi_onLoad(DHTMLSafe, aeFieldnames[num]); }
}

function jk_edit_onUnload()
{
  var jk_edit_content = "";
  var i;
  for(i=1;i<=jk_edit_count;i++)
  {
    DHTMLSafe=aeObjects[i];
    thisContentItem = eval("document.all.jk_word");
    if(jk_edit_sourceview) jk_edit_editsourceinline(i,false);
    var content = DHTMLSafe.DOM.body.innerHTML;
    thisContentItem.value = content;
  }
}

function jk_edit_onSubmit()
{
  var jk_edit_content = "";
  var i;
  for(i=1;i<=jk_edit_count;i++)
  {
    DHTMLSafe=aeObjects[i];
    if(jk_edit_sourceview) jk_edit_editsourceinline(i,false);
    thisContentItem = eval("document.all.jk_word");
    if(typeof(aeapi_local_onBeforeSave)=='function')
    { jk_edit_content = aeapi_local_onBeforeSave(DHTMLSafe, aeFieldnames[i]); }
    else if (typeof(aeapi_onBeforeSave)=='function')
    { jk_edit_content = aeapi_onBeforeSave(DHTMLSafe, aeFieldnames[i]); }
    else
    { jk_edit_content = jk_edit_onBeforeSave(DHTMLSafe, aeFieldnames[i]); }
    thisContentItem.value = jk_edit_content;
  }
}

function jk_edit_onkeypress(num)
{
  var sel;
  DHTMLSafe=aeObjects[num];
  if(jk_edit_breakonenter[num]||jk_edit_sourceview)
  {
    switch(DHTMLSafe.DOM.parentWindow.event.keyCode)
    {
      case 10:
        DHTMLSafe.DOM.parentWindow.event.keyCode = 13;      
        break;
      case 13:
        if(DHTMLSafe.QueryStatus(5051)!=7)
        {
          DHTMLSafe.DOM.parentWindow.event.returnValue = false;    
          sel = DHTMLSafe.DOM.selection.createRange();
          sel.pasteHTML("<BR>");
          sel.collapse(false);
          sel.select();
        }
        break;
      default:
        break;
    }
  }
}

function jk_edit_clear()
{
  if (confirm("您真的要清除所写的内容吗？")) { DHTMLSafe.DOM.body.innerHTML=""; }
  DHTMLSafe.focus();
  DHTMLSafe.DOM.body.focus();
}

function jk_edit_onmousedown(num)
{
  if(typeof(document.all.jk_edit_frame) != "undefined")
  {
    if(document.all.jk_edit_frame.style.visibility == "visible")
    {
      cancelTable(false);
      return;
    }
  }
}

function jk_edit_onclick(num) { set_tbstates(num); }

function jk_edit_ondisplaychange(num)
{
  if(DHTMLSafe.Busy) { return; }
  set_tbstates(num);
}

function jk_edit_onmenuaction(itemIndex, num) { jk_edit_onCommand(ContextMenu[itemIndex].cmdId, num); }

function jk_edit_Clear(cmdId, num) { }

function jk_edit_onCommand(cmdId, num)
{
  if (jk_edit_HTMLMode[num]) { alert("请先切换到可视编辑模式。");return; }
  if(typeof(num)=="undefined") { num=jk_edit_hot; }
  DHTMLSafe=aeObjects[num];
  if(cmdId==null) { cmdid=eval(window.event.srcElement.cid); }
  else { cmdid=cmdId; }
  doFocus=true;  
  switch(parseInt(cmdid))
  {
    case 5017:
      oSel = DHTMLSafe.DOM.selection;
      if (oSel.type == "Control")
      { jk_edit_imageProperties(num); }
      else
      {
        DHTMLSafe.DOM.selection.createRange().collapse(false);
        onImagewin(num);
      }
      doFocus=false;
      break;
    case 5022:
      onTableWin(num);
      doFocus=false;
      break;
    case 6001:
      if(tabview[num])
      { jk_edit_editsourceinline(num); }
      else
      { 
        jk_edit_editsource(num);
        doFocus=false;
      }
      break;
    case 6002:
      jk_edit_about();
      doFocus=false;
      break;
    case 6004:
      jk_edit_onToggleDetails(null, num);
      break;
    case 6006:
      editTableWin(num);
      doFocus=false;
      break;
    case 5016:
      jk_edit_hyperlinkwin(num);
      doFocus=false;
      break;
    case 6007:
      jk_edit_spellcheckwin(num);
      doFocus=false;
      break;
    case 6008:
      jk_edit_specialchars();
      doFocus=false;
      break;
    case 6009:
      oSel = DHTMLSafe.DOM.selection.createRange();
      for (i=0; i<oSel.length; i++)
      {
        if (oSel(i).tagName == "IMG")
        {
          jk_edit_imageProperties(num);
          doFocus=false;
        }
      }
      break;
    case 5032:
      jk_edit_onPaste(num);
      doFocus=false;
      break;
    case 6010:
      oSel = DHTMLSafe.DOM.selection;
      if (oSel.type == "Control")
      {
        alert("您已选中水平线。\n如需插入新的水平线，请先取消选择。");
        return;
      }
      else
      {
        jk_edit_onHr(num);
        doFocus=false;
      }
      break;
    default:
      if(DHTMLSafe.QueryStatus(cmdid)!=1) { DHTMLSafe.ExecCommand(cmdid, 0); }
      break;
  }
  if (doFocus)
  {
    DHTMLSafe.focus();
    DHTMLSafe.DOM.body.focus();
  }
}

function jk_edit_onHr(num)
{
  DHTMLSafe=aeObjects[num];
  DHTMLSafe.focus();
  if (typeof(jk_edit_hrwin) == "undefined" || jk_edit_hrwin.closed)
  {
    var szURL=inc + "win_hr.htm?instance=" + num;
    jk_edit_hrwin = window.showModalDialog(szURL,window,"dialogHeight: 210px; dialogWidth: 355px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
  }
}

function jk_edit_imageProperties(num)
{
  DHTMLSafe=aeObjects[num];
  DHTMLSafe.focus();
  if (typeof(jk_edit_imgpropwin) == "undefined" || jk_edit_imgpropwin.closed)
  {
    var szURL=inc + "win_img_edit.htm?instance=" + num;
    jk_edit_imgpropwin = window.showModalDialog(szURL,window,"dialogHeight: 300px; dialogWidth: 420px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
  }
}

function replaceFontsWithSpans(aeObject, oElement, sNewClass)
{
  for(var i=0;i<oElement.childNodes.length;i++) { replaceFontsWithSpans(aeObject, oElement.childNodes[i], sNewClass); }
  if(oElement.tagName=="FONT")
  {
    if(oElement.face=="jk_edit_newclass")
    {
      sPreserve=oElement.innerHTML;
      oNewNode=aeObject.DOM.createElement("SPAN");
      oElement.replaceNode(oNewNode);
      oNewNode.innerHTML=sPreserve;
      oNewNode.className=sNewClass;
    }
    if(oElement.xclass!=null)
    {
      sPreserve=oElement.innerHTML;
      sClass=oElement.xclass;
      oNewNode=aeObject.DOM.createElement("SPAN");
      oElement.replaceNode(oNewNode);
      oNewNode.innerHTML=sPreserve;
      oNewNode.className=sClass;
    }
    else
    {
      var style = "";
      if (oElement.face.length) { style += "font-family: " + oElement.face + ";"; }  
      if (oElement.size.length)
      {
        var sizeMap = new Array(7,7,9,12,14,18,24,36);
        var size = oElement.size;
        if (size > 7) size = 7;
        if (size==-1) size = 2;
        if (size==-2) size = 1;
        if (size < -2) size = 1;
        var ptsize = sizeMap[size];
        style += "font-size: " + ptsize + "pt;";
      }
      if (oElement.color.length) { style += "color: " + oElement.color + ";"; }
      if (style.length)
      {
        sPreserve=oElement.innerHTML;
        oNewNode=aeObject.DOM.createElement("SPAN");
        oElement.replaceNode(oNewNode);
        oNewNode.innerHTML=sPreserve;
        oNewNode.style.cssText=style;
      }
    }
  }
}

function condenseSpans(aeObject, oElement, oPrevious)
{
  for(var i=0;i<oElement.childNodes.length;i++)
  {
    var child = oElement.childNodes[i];
    oElement = condenseSpans(aeObject, child, oElement);
  }
  if (oElement.tagName=="SPAN" && oPrevious != null && oPrevious.tagName =="SPAN")
  {
    if (oElement.innerText == oPrevious.innerText)
    {
      cClass=oElement.className;
      pClass=oPrevious.className;
      if(pClass.length && !cClass.length) { oElement.setAttribute("class", pClass); }
      var css = oPrevious.style.cssText;
      var styleProps = css.split("; ");
      var curStyleProps = oElement.style.cssText.split("; ");
      for (var i=0;i<styleProps.length;i++)
      {
        var kv = styleProps[i].split(":");
        var key = kv[0];
        var value = kv[1];
        var hasProp = false;
        for (var k=0;k<curStyleProps.length;k++)
        {
          var ckv = curStyleProps[k].split(":");
          var cProp = ckv[0];
          var cValue = ckv[1];
          if (cProp == key)
          {
            hasProp = true;
            break;
          }
        }
        if (!hasProp) { oElement.style.cssText = oElement.style.cssText + ";" + key + ":" + value; }
      }
      oPrevious.removeNode(false);
      return oElement;
    }
  }
  return oPrevious;
}

function removeExtraniousSpans(aeObject, oElement, oPrevious)
{
  for(var i=0;i<oElement.childNodes.length;i++) { removeExtraniousSpans(aeObject, oElement.childNodes[i], oElement); }
  if (oElement.tagName=="SPAN" && oPrevious != null && oPrevious.tagName =="P")
  {
    if (oElement.innerText == oPrevious.innerText)
    {
      cClass=oElement.className;
      pClass=oPrevious.className;
      if(cClass.length) { oPrevious.setAttribute("class", pClass); }
      var css = oPrevious.style.cssText;
      var styleProps = css.split("; ");
      var curStyleProps = oElement.style.cssText.split("; ");
      for (var i=0;i<curStyleProps.length;i++)
      {
        var kv = curStyleProps[i].split(":");
        var cProp = kv[0];
        var cValue = kv[1];
        var hasProp = false;
        for (var k=0;k<styleProps.length;k++)
        {
          var pkv = styleProps[k].split(":");
          var pProp = pkv[0];
          var pValue = pkv[1];
          if (cProp == pProp)
          {
            hasProp = true;
            break;
          }
        }
        if (!hasProp) { oPrevious.style.cssText = oPrevious.style.cssText + ";" + cProp + ":" + cValue; }
      }
      oElement.removeNode(false);
    }
  }
}

//paste
function jk_edit_onPaste(num)
{
  DHTMLSafe=aeObjects[num];
  window.event.returnValue = true;
  var tr = DHTMLSafe.DOM.selection.createRange();
  tr.execCommand("Paste");
  replaceFontsWithSpans(DHTMLSafe, DHTMLSafe.DOM.body, null);
  condenseSpans(DHTMLSafe, DHTMLSafe.DOM.body, null);
}

function jk_edit_onPastetext()
{
  var sText = HTMLEncode(clipboardData.getData("Text"));
  sText = sText.replace(/\n/g,'<BR>');
  insertHtml(sText);
}

function HTMLEncode(text)
{
  text = text.replace(/&/g, "&amp;") ;
  text = text.replace(/"/g, "&quot;") ;
  text = text.replace(/</g, "&lt;") ;
  text = text.replace(/>/g, "&gt;") ;
  text = text.replace(/'/g, "&#146;") ;
  return text ;
}

function jk_edit_onPasteWord()
{
  if (BrowserInfo.IsIE55OrMore)
  { cleanAndPaste(GetClipboardHTML()); }
  else if (confirm("这个操作需要Internet Explorer version 5.5 或以上版本. 你需要粘贴它而不去除格式吗?"))
  { decCommand(DECMD_PASTE); }
}

function GetClipboardHTML()
{
  var oDiv = document.getElementById("divTemp")
  oDiv.innerHTML = "";
  var oTextRange = document.body.createTextRange();
  oTextRange.moveToElementText(oDiv);
  oTextRange.execCommand("Paste");
  var sData = oDiv.innerHTML;
  oDiv.innerHTML = "";
  return sData;
}

function cleanAndPaste( html )
{
  html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
  html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
  html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3");
  html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
  html = html.replace(/<\\?\?xml[^>]*>/gi, "");
  html = html.replace(/<\/?\w+:[^>]*>/gi, "");
  html = html.replace(/&nbsp;/, " " );
  var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi");
  html = html.replace( re, "<div$2</div>" );
  insertHtml( html );
}

function jk_edit_onToggleDetails(bVal, num)
{
  DHTMLSafe=aeObjects[num];
  if (bVal == null) { DHTMLSafe.ShowDetails = !(DHTMLSafe.ShowDetails); }
  else { DHTMLSafe.ShowDetails = bVal; }
}

function editTableWin(num) { ditTbl = window.showModalDialog(inc + "win_table_edit.htm",window,"dialogHeight: 350px; dialogWidth: 350px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;"); }

function onTableWin(num)
{  
  DHTMLSafe=aeObjects[num];
  if(DHTMLSafe.QueryStatus(5022) == 1) 
  {
    DHTMLSafe.focus();
    return;
  }  
  jk_edit_hot = num;
  arr = window.showModalDialog(inc + "win_table.htm",window,"dialogHeight: 250px; dialogWidth: 480px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
}

function onTable(num)
{
  if (jk_edit_HTMLMode[num]) { return; }
  DHTMLSafe=aeObjects[num];
  if(DHTMLSafe.QueryStatus(5022) == 1) 
  {
    DHTMLSafe.focus();
    return;
  }
  if(  document.all.jk_edit_frame.style.visibility == "visible" )
  {
    cancelTable();
    return;
  }
  var str = "<div id=\"tblsel\" style=\"background-color:#000066;position:absolute;";
  str = str + "width:0;height:0;z-index:-1;\"></div>";
  str = str + makeTable(4, 5);
  str = str + "<div style=\"text-align:center;background-color:menu;font-size: 12px\" id=\"tblstat\">插入表格</div>";
  var ifrm = document.frames("jk_edit_frame");
  var obj=eval("document.all.jk_edit_tbtn"+num);
  var x=0,y=0;
  ifrm.document.body.innerHTML=str;
  while(obj.tagName!="BODY")
  {
    x+=obj.offsetLeft;
    y+=obj.offsetTop;
    obj=obj.offsetParent;
  }  
  document.all.jk_edit_frame.style.pixelTop = y + 24;
  document.all.jk_edit_frame.style.pixelLeft = x;
  document.all.jk_edit_frame.style.pixelWidth = 0;
  document.all.jk_edit_frame.style.pixelHeight = 0;
  document.all.jk_edit_frame.style.visibility = "visible";
  jk_edit_hot=num;
  document.frames("jk_edit_frame").document.body.onmouseover = paintTable;  
  document.frames("jk_edit_frame").document.body.onclick = insertTable;
  if(typeof(document.onmousedown)=="function") { jk_edit_olddocmd = document.onmousedown; }
  else { jk_edit_olddoccmd=null; }
  document.onmousedown = cancelTable;
  DHTMLSafe.onmousedown = cancelTable;
  event.cancelBubble = true;
  ifrm.document.body.onselectstart=new Function("return false;");
  document.all.jk_edit_frame.style.pixelWidth = ifrm.document.all.oTable.offsetWidth + 3
  document.all.jk_edit_frame.style.pixelHeight = ifrm.document.all.oTable.offsetHeight + 3 +
  ifrm.document.all.tblstat.offsetHeight;
}

function insertTable(rows, cols, attrs, num)
{
  if(typeof(num)=="undefined") { num=jk_edit_hot; }
  DHTMLSafe=aeObjects[num];
  if (typeof(rows) == "undefined")
  {
    var se = document.frames('jk_edit_frame').window.event.srcElement;
    if(se.tagName!='TD')
    {
      cancelTable();
      return;
    }
    tableparamobj.NumRows = se.parentElement.rowIndex + 1;
    tableparamobj.NumCols = se.cellIndex + 1;
    tableparamobj.TableAttrs = "style='border-collapse:collapse;' border=1 bordercolor=#000000 cellPadding=1 cellSpacing=0 width=98% align=center";
    cancelTable();
  }
  else
  {
    tableparamobj.NumRows = rows;
    tableparamobj.NumCols = cols;
    tableparamobj.TableAttrs = attrs;
  }
  DHTMLSafe.ExecCommand(5022,0, tableparamobj);    
  DHTMLSafe.focus();
}

function paintTable()
{
  var se = document.frames('jk_edit_frame').window.event.srcElement;
  var sr, sc, tbl, fAll;
  fAll = document.frames('jk_edit_frame').document.all;
  if(se.tagName!='TD')
  {
    sr = 0;
    sc = 0;
    var str="&nbsp;Cancel";
    fAll.tblsel.style.width = 0;
    fAll.tblsel.style.height = 0;
    return;
  }
  tbl=fAll.oTable;
  sr=se.parentElement.rowIndex;
  sc=se.cellIndex;
  if(!is_ie4)
  {
    if(tbl.rows.length == sr+1)
    {
      var r = tbl.insertRow(-1);
      var td;
      for(var i=0;i<tbl.rows(1).cells.length;i++)
      {
        td = r.insertCell(-1);
        td.innerHTML = "&nbsp;";
        td.style.pixelWidth = 20;
        td.style.pixelHeight = 20;
      }
      var bdy = document.frames("jk_edit_frame").document.body;      
      var ifrm = document.frames("jk_edit_frame");
      document.all.jk_edit_frame.style.pixelWidth = ifrm.document.all.oTable.offsetWidth + 3
      document.all.jk_edit_frame.style.pixelHeight = ifrm.document.all.oTable.offsetHeight + 3 +
      ifrm.document.all.tblstat.offsetHeight;
    }
    if(tbl.rows(1).cells.length == sc+1)
    {
      var td;
      for(var i=0;i<tbl.rows.length;i++)
      {
        td = tbl.rows(i).insertCell(-1);
        td.innerHTML = "&nbsp;";
        td.style.pixelWidth = 20;
        td.style.pixelHeight = 20;
      }      
      var bdy = document.frames("jk_edit_frame").document.body;
      document.all.jk_edit_frame.style.pixelWidth = bdy.createTextRange().boundingWidth + 5;
      document.all.jk_edit_frame.style.pixelHeight = bdy.createTextRange().boundingHeight + 5;
    }
  }
  var str=(sr+1) + "×" + (sc+1) + "表格";
  fAll.tblsel.style.width = se.offsetWidth*(sc+1)+5;
  fAll.tblsel.style.height = se.offsetHeight*(sr+1)+5;
  fAll.tblstat.innerHTML = str;
}

function makeTable(rows, cols)
{
  var a, b, str, n;
  str = "<table style=\"table-layout:fixed;border-style:solid; cursor:default;\" "; 
  str = str + "id=\"oTable\" cellpadding=\"0\" ";
  str = str + "cellspacing=\"0\" cols=" + cols;
  str = str + " border=6>\n";
  for (a=0;a<rows;a++)
  {
    str = str + "<tr>\n";
    for(b=0;b<cols;b++)
    {      
      str = str + "<td width=\"20\">" 
      str = str + "&nbsp;</td>\n";  
    }  
    str = str + "</tr>\n";
  }
  str = str + "</table>"
  return str;
}

function cancelTable(a)
{
  document.onmousedown=null;
  document.all.jk_edit_frame.style.visibility = "hidden";
  document.all.jk_edit_frame.style.pixelWidth = 0;
  document.all.jk_edit_frame.style.pixelHeight = 0;
  if(a==false) return;
  if(typeof(jk_edit_olddocmd)=="function")
  {
    jk_edit_olddocmd(false);
    document.onmousedown = jk_edit_olddocmd;
  }
  jk_edit_olddocmd = null;
  document.all.jk_edit_frame.style.pixelWidth = 10;
  document.all.jk_edit_frame.style.pixelHeight = 10;
}

function jk_edit_insertPage()
{
  DHTMLSafe.DOM.selection.createRange().pasteHTML("<br>[pagecute]<br>");
  DHTMLSafe.focus();
  DHTMLSafe.DOM.body.focus();
}

function onFilewin() { window.open("win_file.htm", "jk_edit_filewin", "left=240,top=220,width=320,height=150,menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes"); }

function jk_edit_insertFile(fPath,fText)
{
  if ((fText==null) || (fText=="")) { fText="[点击下载]"; }
  DHTMLSafe.DOM.selection.createRange().pasteHTML("<a href='" + fPath + "' target='_blank'>" + fText + "</a>");
  DHTMLSafe.focus();
  DHTMLSafe.DOM.body.focus();
}

function onImagewin(num)
{
  DHTMLSafe=aeObjects[num];
  DHTMLSafe.focus();
  if (typeof(jk_edit_imgwin) == "undefined" || jk_edit_imgwin.closed)
  {
    var szURL;
    szURL= "win_img.htm?"+tmp_uppath;
    //jk_edit_imgwin = window.showModalDialog(szURL,window,"dialogHeight: 240px; dialogWidth: 330px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;scroll:no;");
    jk_edit_imgwin = window.open(szURL, "jk_edit_imgwin", "left=240,top=200,width=400,height=240,menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes");
  }
  //jk_edit_imgwin.focus();
}

function onImage(u, base_url, iborder, ialign, ialt, num)
{
  DHTMLSafe=aeObjects[num];
  var img = "<img src=\"" + u + "\" border=\"" + iborder + "\" align=\"" + ialign + "\" alt=\"" + ialt + "\">";
  DHTMLSafe.DOM.selection.createRange().pasteHTML(img);
  //jk_edit_imgwin.close();
}

function jk_edit_onBeforeSave(aeObject)
{
  for (var i=0;i<aeObject.DOM.images.length;i++)
  {
    hs=aeObject.DOM.images[i].getAttribute("STYLE",0).height;
    ws=aeObject.DOM.images[i].getAttribute("STYLE",0).width;
    if(hs.length)
    {
      aeObject.DOM.images[i].removeAttribute("HEIGHT", 0);       
      aeObject.DOM.images[i].setAttribute("HEIGHT", replaceString("px", "", hs),0); 
      aeObject.DOM.images[i].getAttribute("STYLE",0).removeAttribute("HEIGHT",0);
    }
    if(ws.length)
    {
      aeObject.DOM.images[i].removeAttribute("WIDTH", 0);  
      aeObject.DOM.images[i].setAttribute("WIDTH", replaceString("px", "", ws),0); 
      aeObject.DOM.images[i].getAttribute("STYLE",0).removeAttribute("WIDTH",0);
    }
  }
  for (var k=0;k<aeObject.DOM.all.tags("TABLE").length;k++)
  {
    hs=aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).height;
    ws=aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).width;
    if(hs.length)
    {
      aeObject.DOM.all.tags("TABLE").item(k).removeAttribute("HEIGHT", 0);       
      aeObject.DOM.all.tags("TABLE").item(k).setAttribute("HEIGHT", replaceString("px", "", hs),0); 
      aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).removeAttribute("HEIGHT",0);
    }
    if(ws.length)
    {
      aeObject.DOM.all.tags("TABLE").item(k).removeAttribute("WIDTH", 0);  
      aeObject.DOM.all.tags("TABLE").item(k).setAttribute("WIDTH", replaceString("px", "", ws),0); 
      aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).removeAttribute("WIDTH",0);
    }
  }
  var content = aeObject.DOM.body.innerHTML;
  if(content.length) { content = aeObject.FilterSourceCode(content); }
  replaceString("&#65279;", " ", content); 
  return content;
}

function jk_edit_submit_form(obj, field)
{
  var i;  
  for(i=1;i<=jk_edit_count;i++)
  {  
    DHTMLSafe=aeObjects[i];
    if (typeof(aeapi_local_onBeforeSave) == "function") { var jk_edit_content = aeapi_local_onBeforeSave(DHTMLSafe, aeFieldnames[num]); }
    else if (typeof(aeapi_onBeforeSave) == "function") { var jk_edit_content = aeapi_onBeforeSave(DHTMLSafe, aeFieldnames[num]); }
    else { var jk_edit_content = jk_edit_onBeforeSave(DHTMLSafe, aeFieldnames[num]); }
    eval(obj).elements[element_idx].value = jk_edit_content;
  }
  eval(obj).submit();
}

function replaceString(oldS,newS,fullS)
{
  for (var i=0; i<fullS.length; i++) { if (fullS.substring(i,i+oldS.length) == oldS) { fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length); } }
  return fullS;
}

function jk_edit_about() { window.showModalDialog(inc + "win_about.htm","","dialogHeight: 260px; dialogWidth: 400px; dialogTop: 150px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;"); }

function jk_edit_editsource(num)
{
  DHTMLSafe=aeObjects[num];
  DHTMLSafe.DOM.selection.empty();
  codewin =window.showModalDialog(inc + "win_source.htm",window,"dialogHeight: 490px; dialogWidth: 485px; dialogTop: 70px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
}

function jk_edit_editsourceinline(num, bVal)
{
  DHTMLSafe=aeObjects[num];
  thisContentItem=eval("document.all.jk_word");
  if(jk_edit_HTMLMode[num]==bVal) return;
  DHTMLSafe.DOM.selection.empty();
  if(jk_edit_HTMLMode[num])
  { 
    document.normaltag.className="latched";
    document.normaltag.type="";
    document.htmltag.className="flat";
    document.htmltag.type="btn";
    if(jk_edit_defaultfont[num].length) 
    { DHTMLSafe.DOM.body.style.font=jk_edit_defaultfont[num]; }
    else
    {
      DHTMLSafe.DOM.body.style.fontFamily="宋体";
      DHTMLSafe.DOM.body.style.fontSize="12px";
    }
    thisContentItem.value=DHTMLSafe.DOM.body.createTextRange().text;
    DHTMLSafe.DOM.body.innerHTML = thisContentItem.value;  
    jk_edit_HTMLMode[num] = false;
  }
  else
  { 
    var re=/((<br>)+)/ig;
    document.normaltag.className="flat";
    document.normaltag.type="btn";
    document.htmltag.className="latched";
    document.htmltag.type="";
    DHTMLSafe.DOM.body.style.fontFamily = "宋体";
    DHTMLSafe.DOM.body.style.fontSize = "12px";
    thisContentItem.value=DHTMLSafe.DOM.body.innerHTML;
    DHTMLSafe.DOM.body.innerHTML = "";
    DHTMLSafe.DOM.body.createTextRange().text = thisContentItem.value.replace(re, "$1\n");
    jk_edit_HTMLMode[num] = true;
  }
}

function jk_edit_specialchars()
{
  var szURL = inc + "win_specialchars.htm";
  jk_edit_specialwin = window.showModalDialog(szURL,window,"dialogHeight: 275px; dialogWidth: 390px; dialogTop: 70px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
}

function jk_edit_quickfont(num)
{
  if (jk_edit_HTMLMode[num]) { return; }
  DHTMLSafe=aeObjects[num];
  oSel=eval('document.all.oQuickFont'+num);  
  DHTMLSafe.ExecCommand(5044, 0, oSel.options[oSel.selectedIndex].name);
  DHTMLSafe.focus();
  DHTMLSafe.DOM.body.focus();
  replaceFontsWithSpans(DHTMLSafe, DHTMLSafe.DOM.body, null);
  condenseSpans(DHTMLSafe, DHTMLSafe.DOM.body, null);
}

function jk_edit_quickfontsize(num)
{
  if (jk_edit_HTMLMode[num]) { return; }
  DHTMLSafe=aeObjects[num];
  oSel=eval('document.all.oQuickFontSize'+num);  
  DHTMLSafe.ExecCommand(5045, 0, oSel.options[oSel.selectedIndex].value);
  DHTMLSafe.focus();
}

function jk_edit_quickformat(num)
{
  if (jk_edit_HTMLMode[num]) { return; }
  DHTMLSafe=aeObjects[num];
  oSel=eval('document.all.oQuickFormat'+num);  
  DHTMLSafe.ExecCommand(5043, 0, oSel.options[oSel.selectedIndex].name);
  DHTMLSafe.focus();
}

function jk_edit_hyperlinkwin(num)
{
  jk_edit_hot=num;
  DHTMLSafe=aeObjects[num];
  DHTMLSafe.focus();
  if(DHTMLSafe.DOM.selection.type=="Control")
  {
    var el=DHTMLSafe.DOM.selection.createRange().commonParentElement();
    var tr = DHTMLSafe.DOM.body.createTextRange();
    tr.moveToElementText(el);
    tr.select();
  }
  if (typeof(jk_edit_linkwin) == "undefined" || jk_edit_linkwin.closed)
  {
    var szURL=inc + "win_hyperlink.htm";
    jk_edit_linkwin = window.showModalDialog(szURL,window,"dialogHeight: 240px; dialogWidth: 400px; dialogTop: 70px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
  }
}

function jk_edit_imagepropertywin(num) { jk_edit_imgpropertywin =window.showModalDialog(inc + "win_img_edit.htm",window,"dialogHeight: 350px; dialogWidth: 490px; dialogTop: 70px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;"); }

function jk_edit_imageproperty(num, aWidth, aHeight, aBorder, aSrc, aAlt, aAlign)
{
  DHTMLSafe=aeObjects[num];
  var oSel=DHTMLSafe.DOM.selection.createRange().commonParentElement();
  var tr = DHTMLSafe.DOM.body.createTextRange();
  hs=oSel.getAttribute("STYLE",0).height;
  ws=oSel.getAttribute("STYLE",0).width;
  if (hs.length) { oSel.getAttribute("STYLE",0).removeAttribute("HEIGHT",0); }
  if (ws.length) { oSel.getAttribute("STYLE",0).removeAttribute("WIDTH",0); }
  oSel.width=aWidth;
  oSel.height=aHeight;
  oSel.border=aBorder;
  oSel.src=aSrc;
  oSel.alt=aAlt;
  oSel.align=aAlign;
  DHTMLSafe.focus();
  DHTMLSafe.DOM.body.focus();
  tr.moveToElementText(oSel);
  tr.collapse(false);
  tr.select();
}

function jk_edit_hyperlink(num, iHref, iTarget, iStyle, iClass, iName)
{
  DHTMLSafe=aeObjects[num];
  var uid="ae"+Math.random().toString();
  if(iHref=="" && !iName.length)
  { if(DHTMLSafe.QueryStatus(5050)==3) { DHTMLSafe.ExecCommand(5050); } }
  else
  {
    var trSel=DHTMLSafe.DOM.selection.createRange();
    if(trSel.compareEndPoints("StartToEnd",trSel)==0)
    {
      txtHTML="<A href=\""+iHref+"\" ";
      if(iTarget.length) { txtHTML+="target=\""+iTarget+"\" "; }
      if(iStyle.length) { txtHTML+="style=\""+iStyle+"\" "; }
      if(iClass.length) { txtHTML+="class=\""+iClass+"\" "; }
      if(iName.length) { txtHTML+="name=\""+iName+"\" "; }
      txtHTML+=">"+iHref+"</a>";
      trSel.pasteHTML(txtHTML);
    }
    else
    { 
      DHTMLSafe.ExecCommand(5016,2,uid);
      var coll=DHTMLSafe.DOM.all.tags("A");
      for(i=0;i<coll.length;i++)
      {
        if(coll[i].href==uid)
        {
          coll[i].href=iHref;
          if(iTarget.length) coll[i].target=iTarget;
          else coll[i].removeAttribute("TARGET",0);
          if(iStyle.length) { coll[i].style.cssText=iStyle; }
          else { coll[i].style.cssText=""; }
          if(iClass.length) { coll[i].className=iClass; }
          else { coll[i].className=""; }
        }
      }
    }
  }
  DHTMLSafe.focus();
}

function jk_edit_spellcheckwin(num)
{
  if (typeof(jk_edit_spellwin) == "undefined" || jk_edit_spellwin.closed)
  {
    var szURL=inc + "spellchecker/window.cfm?jsvar=aeObjects["+num+"].DOM.body.innerHTML";
    //window.showModalDialog(inc + "editsource.htm",window,"dialogHeight: 490px; dialogWidth: 485px; dialogTop: 70px; dialogLeft: 150px; center: Yes; help: No; resizable: No; status: No;");
    jk_edit_spellwin = window.open(szURL, null, "height=230,width=450,status=no,toolbar=no,menubar=no,location=no");
  }
  jk_edit_spellwin.focus();
}

function ShowMenu(num)
{
  var menuStrings = new Array();
  var menuStates = new Array();
  var state;
  var i;
  var idx = 0;
  jk_edit_hot=num;
  DHTMLSafe=aeObjects[num];
  ContextMenu.length = 0;
  if(alloweditsource[num]) { i=0; }
  else { i=2; }
  for (;i<GeneralContextMenu.length; i++) { ContextMenu[idx++] = GeneralContextMenu[i]; }
  if (DHTMLSafe.QueryStatus(5021) != 1) { for (i=0; i<TableContextMenu.length; i++) { ContextMenu[idx++] = TableContextMenu[i]; } }
  var tr = DHTMLSafe.DOM.selection.createRange();
  if (DHTMLSafe.DOM.selection.type == "Control") { for (i=0; i<ImageContextMenu.length; i++) { ContextMenu[idx++] = ImageContextMenu[i]; } }
  for (i=0; i<ContextMenu.length; i++)
  {
    menuStrings[i] = ContextMenu[i].string;
    if ((menuStrings[i] != MENU_SEPARATOR) && (ContextMenu[i].cmdId < 6000)) { state = DHTMLSafe.QueryStatus(ContextMenu[i].cmdId); }
    else { state = 3; }
    if (state == 1 || state == 0) { menuStates[i] = 2; }
    else if (state == 3 || state == 11) { menuStates[i] = 0; }
    else { menuStates[i] = 1; }
    if (ContextMenu[i].cmdId == 6004)
    {
      if (DHTMLSafe.ShowDetails) { menuStates[i] = 1; }
      else { menuStates[i] = 0; }  
    }
    if(ContextMenu[i].cmdId == 6001)
    {
      if(jk_edit_sourceview) { menuStates[i] = 1; }
      else { menuStates[i] = 0; }  
    }
  }
  DHTMLSafe.SetContextMenu(menuStrings, menuStates);
}

function ContextMenuItem(string, cmdId)
{
  this.string = string;
  this.cmdId = cmdId;
}

function QueryStatusItem(command, element)
{
  this.command = command;
  this.element = element;
}

var MENU_SEPARATOR = "";
var ContextMenu = new Array();
var GeneralContextMenu = new Array();
var TableContextMenu = new Array();
var ImageContextMenu = new Array();
var genId = 0; 
var tblId = 0;
var imgId = 0;

GeneralContextMenu[genId++] = new ContextMenuItem("编辑源代码", 6001);
GeneralContextMenu[genId++] = new ContextMenuItem(MENU_SEPARATOR, 0);

if (!is_ie4)
{
  TableContextMenu[tblId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
  TableContextMenu[tblId++] = new ContextMenuItem("表格属性", 6006);
}

TableContextMenu[tblId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
TableContextMenu[tblId++] = new ContextMenuItem("插入行", 5021);
TableContextMenu[tblId++] = new ContextMenuItem("删除行", 5007);
TableContextMenu[tblId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
TableContextMenu[tblId++] = new ContextMenuItem("插入列", 5020);
TableContextMenu[tblId++] = new ContextMenuItem("删除列", 5006);
TableContextMenu[tblId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
TableContextMenu[tblId++] = new ContextMenuItem("插入单元格", 5019);
TableContextMenu[tblId++] = new ContextMenuItem("删除单元格", 5005);
TableContextMenu[tblId++] = new ContextMenuItem("合并单元格", 5029);
TableContextMenu[tblId++] = new ContextMenuItem("拆分单元格", 5047);
ImageContextMenu[imgId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
ImageContextMenu[imgId++] = new ContextMenuItem("图片属性", 6009);
GeneralContextMenu[genId++] = new ContextMenuItem("查找", 5008);
GeneralContextMenu[genId++] = new ContextMenuItem("全部显示", 6004);
GeneralContextMenu[genId++] = new ContextMenuItem(MENU_SEPARATOR, 0);
GeneralContextMenu[genId++] = new ContextMenuItem("关于", 6002);

function jk_edit_m_out(src)
{
  if(src.state==0) return;  
  if(src.state==2) { src.className="latched"; return; }
  if(src.type=="btn")
  {
    window.status="";
    src.className="flat";
  }
}

function jk_edit_m_over(src)
{
  if(src.state==0) return;
  if(src.state==2) return;
  if(src.type=="btn")
  {
    window.status=src.alt;
    src.className="outset";
  }
}

function jk_edit_m_down(src)
{
  if(src.state==0) return;
  if(src.type=="btn") { src.className="inset"; }
}

function jk_edit_m_up(src)
{
  if(src.state==0) return;
  if(src.state==2) { src.className="latched"; return; }
  if(src.type=="btn") { src.className="outset"; }
}

function set_tbstates(num)
{
  var pbtn;
  var cid;
  var state;
  DHTMLSafe=aeObjects[num];
  jk_edit_tbar=eval("jk_edit_tbar"+num);
  if(DHTMLSafe.QueryStatus(5002)!=DHTMLSafe.QueryStatus(5003)) return;
  for(var i=0;i<jk_edit_tbar.all.length;i++)
  {
    pbtn= jk_edit_tbar.all(i);
    cid=pbtn.cid;
    if(cid < 6000&&cid!=5016)
    {
      if (!is_ie4) { pbtn.style.visibility="visible"; }
      state=DHTMLSafe.QueryStatus(cid)
      if(state == 1 || state == 0)
      {
        if(pbtn.state!=0)
        {
          pbtn.className = "disabled";
          pbtn.state = 0;
        }
      }
      else if (state == 3 || state == 11)
      {
        if(pbtn.state!=1)
        {
          pbtn.className = "flat";
          pbtn.state = 1;
        }
      }
      else
      {   
        if(pbtn.state!=2)
        {
          pbtn.className = "latched";
          pbtn.state = 2;
        }
      }
    }
    else if(cid==6004)
    {
      if(DHTMLSafe.ShowDetails)
      {
        if(pbtn.state!=2)
        {
          pbtn.className = "latched";
          pbtn.state = 2;
        }
      }
      else
      {
        if(pbtn.state!=1)
        {
          pbtn.className = "flat";
          pbtn.state = 1;
        }
      }
    }
  }
  if(oSel=eval('document.all.oQuickFont'+num))
  {
    if(DHTMLSafe.QueryStatus(5044)!=1&&DHTMLSafe.DOM.selection.type!="control")
    {
      if(oSel.disabled) oSel.disabled=false;
      fontname=DHTMLSafe.ExecCommand(5013);
      if(fontname!=""&&fontname!=null)
      {
        fCreateNew=true;
        for(i=0;i<oSel.options.length;i++)
        {
          if(oSel.options[i].name==fontname)
          {
            if(!oSel.options[i].selected) { oSel.options[i].selected=true; }
            fCreateNew=false;
          }
        }
        if(fCreateNew)
        {
          var oOption = document.createElement("OPTION");
          oSel.options.add(oOption,0);
          oOption.text = fontname;
          oOption.name = fontname;
          oOption.selected=true;
        }
      }
      else
      { oSel.selectedIndex=-1; }
    }
    else
    { if(!oSel.disabled) oSel.disabled=true; }
  }
  if(oSel=eval('document.all.oQuickFontSize'+num))
  {
    if(DHTMLSafe.QueryStatus(5045)!=1&&DHTMLSafe.DOM.selection.type!="control")
    {
      if(oSel.disabled) oSel.disabled=false; 
      fs=DHTMLSafe.ExecCommand(5014);
      if(fs!=null&&fs!="")
      {
        for(i=0;i<oSel.options.length;i++)
        {
          if(oSel.options[i].name=="jk_edit_fs"+fs&&!oSel.options[i].selected)
          { oSel.options[i].selected=true; }
        }
      }
      else
      { oSel.selectedIndex=-1; }
    }
    else
    { if(!oSel.disabled) oSel.disabled=true; }
  }  
  if(oSel=eval('document.all.oQuickFormat'+num))
  {
    if(DHTMLSafe.QueryStatus(5043)!=1&&DHTMLSafe.DOM.selection.type!="control")
    {
      if(oSel.disabled) oSel.disabled=false;
      fmt=DHTMLSafe.ExecCommand(5011);
      if(fmt!=""&&fmt!=null)
      { for(i=0;i<oSel.options.length;i++) { if(oSel.options[i].name==fmt&&!oSel.options[i].selected) { oSel.options[i].selected=true; } } }
      else
      { oSel.selectedIndex=-1; }
    }
    else
    { if(!oSel.disabled) oSel.disabled=true; }
  }  
}

function aeapi_onLoad(aeObject) { aeObject.ShowBorders = true; }

function aeapi_onBeforeSave(aeObject)
{
  for (var i=0;i<aeObject.DOM.images.length;i++)
  {
    hs=aeObject.DOM.images[i].getAttribute("STYLE",0).height;
    ws=aeObject.DOM.images[i].getAttribute("STYLE",0).width;
    if(hs.length)
    {
      aeObject.DOM.images[i].removeAttribute("HEIGHT", 0);       
      aeObject.DOM.images[i].setAttribute("HEIGHT", replaceString("px", "", hs),0); 
      aeObject.DOM.images[i].getAttribute("STYLE",0).removeAttribute("HEIGHT",0);
    }
    if(ws.length)
    {
      aeObject.DOM.images[i].removeAttribute("WIDTH", 0);  
      aeObject.DOM.images[i].setAttribute("WIDTH", replaceString("px", "", ws),0); 
      aeObject.DOM.images[i].getAttribute("STYLE",0).removeAttribute("WIDTH",0);
    }
  }
  for (var k=0;k<aeObject.DOM.all.tags("TABLE").length;k++)
  {
    hs=aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).height;
    ws=aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).width;
    if(hs.length)
    {
      aeObject.DOM.all.tags("TABLE").item(k).removeAttribute("HEIGHT", 0);       
      aeObject.DOM.all.tags("TABLE").item(k).setAttribute("HEIGHT", replaceString("px", "", hs),0); 
      aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).removeAttribute("HEIGHT",0);
    }
    if(ws.length)
    {
      aeObject.DOM.all.tags("TABLE").item(k).removeAttribute("WIDTH", 0);  
      aeObject.DOM.all.tags("TABLE").item(k).setAttribute("WIDTH", replaceString("px", "", ws),0); 
      aeObject.DOM.all.tags("TABLE").item(k).getAttribute("STYLE",0).removeAttribute("WIDTH",0);
    }
  }
  var content = aeObject.DOM.body.innerHTML;
  if(content.length) { content = aeObject.FilterSourceCode(content); }
  replaceString("&#65279;", " ", content); 
  return content;
}

function ubbcode()
{
  if (!validateMode()) { return; }
  cont=getPureHtml(Composition.document.body.innerHTML);
  var aryCode0 = new Array("<b>","[b]","</b>","[/b]","<p","[p","</p>","[/p]","<a href=","[url=","</a>","[/url]");
  var aryCode1 = new Array("<EM>","[i]","</EM>","[/i]","<u>","[u]","</u>","[/u]","<ul>","[list]","</ul>","[/list]","<ol>","[list=1]","</ol>","[/list]");
  var aryCode2 = new Array("<li>","[*]","</li>","","<font color=","[color=","<font face=","[face=","<font size=","[size=");
  var aryCode9 = new Array(">","]","<","[","</","[/");
  var aryCode = aryCode0.concat(aryCode1).concat(aryCode2).concat(aryCode9);
  for (var i=0;i<aryCode.length;i+=2) { cont=rCode(cont,aryCode[i],aryCode[i+1]); }
  eval("self.opener."+bodyID+".value=cont;");
  self.close();
}

function ubb2html(str)
{
  if (str=="") { return str; }
  var aryCode0 = new Array("<br>","\n","<b>","\\[b]","</b>","\\[/b]","<p","\\[p","</p>","\\[/p]","<a href=","\\[url=","</a>","\\[/url]");
  var aryCode1 = new Array("<i>","\\[i]","</i>","\\[/i]","<u>","\\[u]","</u>","\\[/u]");
  var aryCode = aryCode0.concat(aryCode1);
  for (var i=0;i<aryCode.length;i+=2) { str=rCode(str,aryCode[i+1],aryCode[i]); }
  return str;
}

function rCode(s,a,b)
{
  var r = new RegExp(a,"gi");
  return s.replace(r,b); 
}

function insertHtml(html)
{
  if (DHTMLSafe.DOM.selection.type.toLowerCase() != "none") { DHTMLSafe.DOM.selection.clear(); }
  DHTMLSafe.DOM.selection.createRange().pasteHTML(html); 
  SetFocus();
}

function SetFocus()
{
  if (BrowserInfo.IsIE55OrMore) { DHTMLSafe.DOM.focus(); }
  else {DHTMLSafe.focus(); }
}
