var oSelSave;
var sSelType;
var srcSave;
function saveSelection(src)
{
srcSave=src;
oSelSave = src.document.selection.createRange()
sSelType = src.document.selection.type
}
function restoreSelection()
{
oSelSave.select()
}
function drawIcon(left,ttop,width,id,title,command)
{
    atop=-ttop-22;
    btop=-ttop-44;
   document.write("<span style=\"width: "+width+";height:22;\">")
   document.write("<span unselectable='on' style=\"position:absolute;clip: rect(0 "+width+" 22 0)\">")
   document.write("<img style=\"clip: rect(0 "+width+" 22 0) unselectable='on' id=\""+id+"\" ")
   document.write("title=\""+title+"\" onclick=\""+command+"\" src=\""+imgpath+"tblr.gif\" ")
   document.write("style=\"position:absolute;top:-"+ttop+";left:-"+left+";\" ")
   document.write("onmouseover=\"if(this.en==false)return;this.style.pixelTop="+atop+"\" ")
   document.write("onmousedown=\"if(this.en==false)return;this.style.pixelTop="+btop+"\" ")
   document.write("onmouseup=\"if(this.en==false)return;this.style.pixelTop="+atop+"\" ")
   document.write("onmouseout=\"if(this.en==false)return;this.style.pixelTop=-"+ttop+"\" ")
   document.write(">")
   document.write("<table width="+width+"><tr><td unselectable='on' onselectstart='return false' style=\"position:absolute;top:4;left:7;\" id=\""+id+"Text\"></td></tr></table>")
   document.write("</span>")
   document.write("</span>")
}
function initEditor(a,n,i)
{
   ad=a.document;
   var sHTML = "<style>body {border: 1px lightgrey solid;}</style>" +
            "<body oncontextmenu=\"return false\" topmargin=5 leftmargin=5>"+"   <div></div>" +"</body>"
   ad.designMode = "on"
   ad.open("text/html","replace")
   ad.write(sHTML)
   ad.close()
   a.displayMode="RICH"
   ad.execCommand("2D-Position", true, true);
   ad.execCommand("MultipleSelection", true, true);
   ad.execCommand("LiveResize", true, true);
   s=mainform[i].value
   if(s=='')
     ad.body.innerHTML="<font size=2></font>"
   else
     ad.body.innerHTML = s
   a.ezenabled=true;
   var sATag = ad.all.tags("A");
   var urlRemove=new String(document.location);
   if(urlRemove.charAt(urlRemove.length-1)!='/'){
      sBaseUrl=urlRemove.substring(0,urlRemove.lastIndexOf("/"))+"/";
      }
   for (var i = sATag.length - 1; i >= 0; i--)
      {
      oA = sATag[i];
      oA.href = vbReplace(oA.href,sBaseUrl,sBaseUrlNew)
      }
	ad.designMode = "on"
//    ad.onkeypress=new Function("return _keypress("+n+")")
}
function saveHtml(a,i)
{
    if(a.ezenabled && a.ezenabled==true){
      if(a.displayMode=="HTML")setDisplayMode(a)
      mainform[i].value=a.document.body.innerHTML
      }
}
function doCmd(sCmd,src,sOption)
{
   popupHide()
   src.focus()

   var oSel = src.document.selection.createRange()
   var sType = src.document.selection.type
   var oTarget = (sType == "None" ? src.document : oSel)
   oSel.select()

   if(sCmd=="DialogImage")
      {
        ezw(imgedurl);
        srcSave=src;
      return true;
      }
   oTarget.execCommand(sCmd,false,sOption)
}
function ezw(url)
{
    var popleft=((document.body.clientWidth - 440) / 2)+window.screenLeft;
    var poptop=(((document.body.clientHeight - 460) / 2))+window.screenTop-40;
    window.open(url,"AAAA","scrollbars=YES,width=480,height=520,left="+popleft+",top="+poptop)
}

function doCmd2(sCmd,sOption)
{
   popupHide()
   var oSel=oSelSave
   var sType=sSelType
   var oTarget=(sType=="None"?srcSave.document:oSel)
   oSel.select()

   oTarget.execCommand(sCmd, false, sOption)
}
function popupShow(width,title,html)
{
   popupHide();
   var sHTML = "<link rel=\"stylesheet\" href=\""+imgpath+"ace.css\" type=\"text/css\">" +
      "<style>" +
      "  select{height: 22px; top:2;   font:8pt verdana,arial,sans-serif}" +
      "  body {border: 0px lightgrey solid;}" +
      "  .bar{ border-top: #99ccff 1px solid; background: #316AC5; WIDTH: 100%; border-bottom: #000000 1px solid;height: 20px}" +
      "  .cellSymbol{border:solid black 1.0pt; border-left:none; padding:0in 2pt 0in 2pt; font-size:10pt; font-family:'Tahoma';}" +
      "  td {  font:8pt verdana,arial,sans-serif}" +
      "  div   {  font:10pt tahoma,arial,sans-serif}" +
      "</style>" +
      "<body style=\"overflow:hidden\" oncontextmenu=\"return false\" topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0 ONSELECTSTART=\"return event.srcElement.tagName=='INPUT'\">" +
      "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"table-layout: fixed\" bgcolor=Gainsboro ID=\"tblPopup\">" +
      "<col width="+width+"><col width=13>" +
      "<tr><td>" +
      "  <div class=\"bar\" style=\"padding-left: 5px;\">" +
      "  <font size=2 face=tahoma color=white><b>"+title+"</b></font>" +
      "  </div>" +
      "</td>" +
      "<td style=\"cursor:hand\" onclick=\"parent.popupHide()\">" +
      "  <div class=\"bar\">" +
      "  <font size=2 face=tahoma color=white><b>X</b></font>" +
      "  </div>" +
      "</td>" +
      "</tr>" +
      "<tr>" +
      "<td colspan=2 style=\"border-left: #336699 1px solid;border-right: #336699 1px solid;border-bottom: #336699 1px solid;\" valign=top>" +
      "  <br>" +
      "  <div id=\"divPopup\" align=center></div>" +
      "  <br>" +
      "</td>" +
      "</tr>" +
      "</table>" +
      "</body>"
   idContentTmp.document.open("text/html","replace")
   idContentTmp.document.write(sHTML)
   idContentTmp.document.close()
   document.all.idContentTmp.style.zIndex = 2
   document.all.idContentTmp.style.visibility = ""
   idContentTmp.document.all.tblPopup.focus()
   idContentTmp.divPopup.innerHTML = html
   document.all.idContentTmp.style.width = idContentTmp.document.all.tblPopup.offsetWidth
   document.all.idContentTmp.style.height = idContentTmp.document.all.tblPopup.offsetHeight
    x=document.body.clientHeight - document.all.idContentTmp.offsetHeight
// if(x > 0)
//    document.all.idContentTmp.style.pixelTop=(x/2);
// else
//    document.all.idContentTmp.style.pixelTop=0
   if(document.body.clientWidth - document.all.idContentTmp.offsetWidth > 0)
      document.all.idContentTmp.style.pixelLeft=(document.body.clientWidth - document.all.idContentTmp.offsetWidth) / 2 ;
   else
      document.all.idContentTmp.style.pixelLeft=0
}
function popupHide()
{
   document.all.idContentTmp.style.visibility = "hidden"
}
function displayFontNameBox(src)
{
   saveSelection(src)
    var c1 = new Array("Arial","Arial Black","Arial Narrow","Comic Sans MS",
        "Courier New","System","Tahoma","Times New Roman","Verdana","Wingdings")
   var sHTML = "<table align=center border=0 width=100% height=100% cellpadding=0 cellspacing=2>";
    for (i=0;i<c1.length;i++)
        {
        sHTML+="<tr onclick=\"parent.doCmd2('fontname','"+c1[i]+"');\" onmouseover=\"this.style.color='tomato'\" onmouseout=\"this.style.color='black'\" style=\"cursor:hand\"><td align=center><font face=\""+c1[i]+"\" size=1>"+c1[i]+"</font></td></tr>"
        }
   sHTML+="</table>";
   popupShow(213,"Font Name",sHTML)
}
function displayFontSizeBox(src)
{
   saveSelection(src)
   var sHTML = "<table align=center border=0 width=100% height=100% cellpadding=0 cellspacing=0>"
    for(i=1;i<8;i++)
    {
    sHTML+="<tr onclick=\"parent.doCmd2('fontsize',"+i+");\" onmouseover=\"this.style.color='tomato'\" onmouseout=\"this.style.color='black'\" style=\"cursor:hand\"><td align=center><font size="+i+">Size "+i+"</font></td></tr>"
    }
   sHTML+="</table>"
   popupShow(253,"Font Size",sHTML)
}
function displayFgColorBox(src)
{
   saveSelection(src)
   var sHTML = writeColorPicker("idForeColor","parent.doCmd2('ForeColor',idForeColor.value);",0);
   popupShow(433,"Foreground Color",sHTML)
}
function writeColorPicker(Name,Command,Type)
{
var OutputID = Name
var TextID = Name + "_1"
var ColorID = Name + "_2"
var c1 = new Array("FFFFCC","FFCC66","FF9900","FFCC99","FF6633","FFCCCC","CC9999","FF6699","FF99CC","FF66CC","FFCCFF","CC99CC","CC66FF","CC99FF","9966CC","CCCCFF","9999CC","3333FF","6699FF","0066FF","99CCFF","66CCFF","99CCCC","CCFFFF","99FFCC","66CC99","66FF99","99FF99","CCFFCC","33FF33","66FF00","CCFF99","99FF00","CCFF66","CCCC66","FFFFFF")
var c2 = new Array("FFFF99","FFCC00","FF9933","FF9966","CC3300","FF9999","CC6666","FF3366","FF3399","FF00CC","FF99FF","CC66CC","CC33FF","9933CC","9966FF","9999FF","6666FF","3300FF","3366FF","0066CC","3399FF","33CCFF","66CCCC","99FFFF","66FFCC","33CC99","33FF99","66FF66","99CC99","00FF33","66FF33","99FF66","99FF33","CCFF00","CCCC33","CCCCCC")
var c3 = new Array("FFFF66","FFCC33","CC9966","FF6600","FF3300","FF6666","CC3333","FF0066","FF0099","FF33CC","FF66FF","CC00CC","CC00FF","9933FF","6600CC","6633FF","6666CC","3300CC","0000FF","3366CC","0099FF","00CCFF","339999","66FFFF","33FFCC","00CC99","00FF99","33FF66","66CC66","00FF00","33FF00","66CC00","99CC66","CCFF33","999966","999999")
var c4 = new Array("FFFF33","CC9900","CC6600","CC6633","FF0000","FF3333","993333","CC3366","CC0066","CC6699","FF33FF","CC33CC","9900CC","9900FF","6633CC","6600FF","666699","3333CC","0000CC","0033FF","6699CC","3399CC","669999","33FFFF","00FFCC","339966","33CC66","00FF66","669966","00CC00","33CC00","66CC33","99CC00","CCCC99","999933","666666")
var c5 = new Array("FFFF00","CC9933","996633","993300","CC0000","FF0033","990033","996666","993366","CC0099","FF00FF","990099","996699","660099","663399","330099","333399","000099","0033CC","003399","336699","0099CC","006666","00FFFF","33CCCC","009966","00CC66","339933","336633","33CC33","339900","669933","99CC33","666633","999900","333333")
var c6 = new Array("CCCC00","996600","663300","660000","990000","CC0033","330000","663333","660033","990066","CC3399","993399","660066","663366","330033","330066","333366","000066","000033","003366","006699","003333","336666","00CCCC","009999","006633","009933","006600","003300","00CC33","009900","336600","669900","333300","666600","000000")
var sHTML = "";
sHTML += ("<table border=0 width=370 align=center cellpadding=0 cellspacing=0><tr><td width=45>  <table border=1 cellpadding=0 cellspacing=0><tr><td id='"+ColorID+"' width=25 height=25></td></tr></table>   <div id='"+TextID+"'><font size=1>&nbsp;</font></div> </td><td>&nbsp;</td><td>")
sHTML += ("<table cellpadding=0 cellspacing=1 bgcolor=black>")
if(Type==0)
    {
    for(var i=1;i<=6;i++)
        {
        sHTML += ("<tr>")
        for(var r=0;r<eval("c"+i).length;r++)
            {
            var colour = eval("c"+i+"[r]")
            sHTML += ("<td onclick=\""+OutputID+".value='"+colour+"';"+Command+"\" style=\"cursor:hand;background-color:"+colour+";\" width=9 height=6 onmouseover=\""+ColorID+".style.background='#"+colour+"';"+TextID+".innerHTML='<font size=1>"+colour+"</font>'\"></td>")
            }
        sHTML += ("</tr>")
        }
    }
if(Type==1)
    {
    for(var i=1;i<=6;i++)
        {
        sHTML += ("<tr>")
        for(var r=0;r<eval("c"+i).length;r++)
            {
            var colour = eval("c"+i+"[r]")
            sHTML += ("<td onclick=\""+ColorID+".style.background='#"+colour+"';"+TextID+".innerHTML='<font size=1>"+colour+"</font>';"+OutputID+".value='"+colour+"';"+Command+"\" style=\"cursor:hand;background-color:"+colour+";\" width=9 height=6 onmouseover=\"\"></td>")
            }
        sHTML += ("</tr>")
        }
    }
sHTML += ("</table>")
sHTML += ("<input type=hidden id='"+OutputID+"'>")
sHTML += ("</td></tr></table>")
return sHTML;
}
function setDisplayMode(src,tb)
{
   popupHide()
    b=src.document.body;
   if(src.displayMode=='RICH')
      {
      b.clearAttributes;
      b.style.fontFamily='Courier New';
      b.style.fontSize='12px';
      b.innerText=src.document.body.innerHTML;
      src.displayMode='HTML';
        if(tb)
       tb.style.display="none"
      }
   else
      {
      b.clearAttributes;
      b.style.fontFamily = '';
      b.style.fontSize = '';
      b.innerHTML = b.innerText;
      src.displayMode = 'RICH';
        if(tb)
       tb.style.display = "block"
      var sATag = b.all.tags("A");
      for (var i = sATag.length - 1; i >= 0; i--)
         {
         oA = sATag[i];
         oA.href = vbReplace(oA.href,sBaseUrl,sBaseUrlNew)
         }
/*
      var sImgTag = src.document.body.all.tags("IMG");
      for (var i = sImgTag.length - 1; i >= 0; i--)
         {
         oA = sImgTag[i];
         oA.src = vbReplace(oA.src,sBaseUrl,sBaseUrlNew)
         }
*/
      }
    src.focus()
}
function applyStyle(Style)
{
   popupHide()
   var oSel = oSelSave
   var sType = sSelType

   if(oSel.parentElement != null)
      {
      oSel.select()
      var sApplied = "<font class='"+Style+"'>"+oSel.text+"</font>"
      oSel.pasteHTML(sApplied)
      }
}
function displayStyleBox()
{
   saveSelection()

   var val;
   var sHTML = "<table align=center border=0 width=100% height=100% cellpadding=0 cellspacing=0>";
   for(var i=0;i<document.styleSheets(0).rules.length;i++)
      {
      h=document.styleSheets(0).rules.item(i).selectorText
      var selArr = h.split(".")
      var itemCount = selArr.length

      if(itemCount>1)
         val = selArr[1]
      else
         val = h
      sHTML+="<tr onclick=\"parent.applyStyle('"+val+"');\" onmouseover=\"this.style.color='tomato'\" onmouseout=\"this.style.color='black'\" style=\"cursor:'hand'\"><td align=\"center\"><span class=\""+val+"\">" + val + "</span></td></tr>";
      }
   sHTML += "</table>"
   popupShow(230,"Select Style (from CSS)",sHTML)
}
function insertSymbol(Symbol)
{
   popupHide()
   var oSel=oSelSave
   var sType=sSelType
   oSel.select()
   if(oSel.parentElement)
      oSel.pasteHTML(Symbol)
}
function CreateHyperlink()
{
   var inpURL = idContentTmp.idLinkURL.value
   var inpURLType = idContentTmp.idLinkType.value
    if(inpURLType=='1'){
        inpURLType='javascript:';
        inpURL="ezPOpen('"+idContentTmp.idLinkURL.value+"');"
    }
   var sURL = inpURLType + inpURL
   var oSel = oSelSave
   var sType = sSelType
   if ((oSel.item) && (oSel.item(0).tagName=="IMG"))
      {
      oSel.item(0).width = oSel.item(0).offsetWidth
      oSel.item(0).height = oSel.item(0).offsetHeight
      oSel.item(0).border = idContentTmp.idLinkImageBorder.value
      }
   if(inpURL!="")
      {
      if (oSel.parentElement)
         {
         if(idContentTmp.btnLinkAction.value == "Insert")
            {
            if(oSel.text!="")
               {
               }
            else
               {
               var oSelTmp = oSel.duplicate()
               oSel.text = sURL
               oSel.setEndPoint("StartToStart",oSelTmp)
               oSel.select()
               sType="Text"
               }
            }
         if(idContentTmp.btnLinkAction.value=="Update")
            {
            if(oSel.text!="")
               {
               }
            else
               {
               }
            }
         }
      oSel.execCommand("CreateLink",false,sURL)
      if (oSel.parentElement)
         oEl = GetElement(oSel.parentElement(),"A")
      else
         oEl = GetElement(oSel.item(0),"A")
      if(oEl)
         {
         if(idContentTmp.idLinkTarget.value=="")
            {
            oEl.removeAttribute("target",0)
            }
         else
            {
            oEl.target = idContentTmp.idLinkTarget.value;
            }
         }
      srcSave.focus()
      oSel.select()
      }
}
var oElStore;
var isLayerActive;
function typeswitch()
{
    if(idContentTmp.idLinkType.value=='1')
        idContentTmp.idLinkURL.disabled=true
    else
        idContentTmp.idLinkURL.disabled=false
}
function displayLinkBox(src)
{
   saveSelection(src)
   var sHTML="<table border=0 cellpadding=\"0\" cellspacing=\"3\" align=center>"+
         "<tr><td align=right>Type:</td><td>"+
         "<select id=\"idLinkType\" NAME=\"idLinkType\" onchange=\"parent.typeswitch()\">"+
         "<option value=\"\"></option>"+
         "<option value=\"http://\" selected>http://</option>"+
         "<option value=\"1\">Site Page</option>"+
         "<option value=\"https://\">https://</option>"+
         "<option value=\"mailto:\">mailto:</option>"+
         "</select></td></tr><tr><td align=right>Site Page:</td><td><a href=\"\" onclick=\"parent.ezw('"+pagelisturl+"');return false;\">select page</a></td></tr><tr><td align=right>URL:</td><td>"+
         "<input type=text size=25 id=idLinkURL value=\"\" style=\"height: 19px;font:8pt verdana,arial,sans-serif\" NAME=\"idLinkURL\">"+
         "</td></tr><tr><td align=right>Target:</td><td>"+
         "<select id=\"idLinkTarget\" NAME=\"idLinkTarget\">"+
         "<option value=\"\" selected></option>"+
         "<option value=\"_self\" selected>self</option><option value=\"_blank\">blank</option><option value=\"_parent\">parent</option></select><div id=\"idLinkImage\" style=\"display:none\"></td></tr><tr><td>Image Border:</td><td>"+
         "<select id=\"idLinkImageBorder\" NAME=\"idLinkImageBorder\"><option value=\"0\" selected>0</option><option value=\"1\">1</option><option value=\"2\">2</option><option value=\"3\">3</option><option value=\"4\">4</option><option value=\"5\">5</option></select>"+
         "</div></td></tr><tr><td align=center colspan=2><br>"+
         "<input type=\"button\" value=\"Cancel\" onclick=\"parent.popupHide();\" style=\"height: 22px;font:8pt verdana,arial,sans-serif\">"+
         "<input type=\"button\" id=\"btnLinkAction\" name=\"btnLinkAction\" value=\"Insert\" onclick=\"parent.CreateHyperlink();parent.popupHide();\" style=\"height: 22px;font:8pt verdana,arial,sans-serif\">"+
         "</td>"+
         "</tr>"+
         "</table>"
   popupShow(400,"Insert/Edit Link",sHTML)
   var sURL;
   var oSel=oSelSave
   var sType=sSelType
   if(oSel.parentElement)
      {
      oEl = GetElement(oSel.parentElement(),"DIV")
      oElStore=oEl
      isLayerActive=true
      }
   else
      isLayerActive=false

   if (oSel.parentElement)
      {
      oEl = GetElement(oSel.parentElement(),"A")
      idContentTmp.idLinkImage.style.display = "none";
      }
   else
      {
      oEl = GetElement(oSel.item(0),"A")
      if ((oSel.item) && (oSel.item(0).tagName=="IMG"))
         {
         idContentTmp.idLinkImage.style.display = "block";
         idContentTmp.idLinkImageBorder.value = oSel.item(0).border;
         }
      }
   if (oEl)
      {
      idContentTmp.btnLinkAction.value = "Update"
      sURL = oEl.href
      idContentTmp.idLinkTarget.value = oEl.target;
      if(sURL.indexOf(":")!=-1)
         {
         switch(sURL.split(":")[0])
            {
            case "http":
               idContentTmp.idLinkType.value = "http://";
               idContentTmp.idLinkURL.value = sURL.substr(7);
               break;
            case "https":
               idContentTmp.idLinkType.value = "https://";
               idContentTmp.idLinkURL.value = sURL.substr(8);
               break;
            case "mailto":
               idContentTmp.idLinkType.value = "mailto:";
               idContentTmp.idLinkURL.value = sURL.split(":")[1];
               break;
            case "ftp":
               idContentTmp.idLinkType.value = "ftp://";
               idContentTmp.idLinkURL.value = sURL.substr(6);
               break;
            case "news":
               idContentTmp.idLinkType.value = "news:";
               idContentTmp.idLinkURL.value = sURL.split(":")[1];
               break;
            case "javascript":
               idContentTmp.idLinkType.value = "1";
               zz=sURL.split(":")[1].substr(9);
               zz=zz.substr(0,zz.indexOf("'"));
               idContentTmp.idLinkURL.disabled=true
               idContentTmp.idLinkURL.value = zz;
               break;
            }
         }
      else
         {
         idContentTmp.idLinkType.value = "http://";
         idContentTmp.idLinkURL.value = sURL;
         }
      }
   else
      {
      idContentTmp.btnLinkAction.value = "Insert"

      idContentTmp.idLinkTarget.value = ""
      idContentTmp.idLinkType.value = ""
      idContentTmp.idLinkURL.value = ""
      idContentTmp.idLinkImageBorder.value = 0
      }
}
function pasteFromWord()
{
   idContent.focus()
   var oSel = idContent.document.selection.createRange()
   if(oSel.parentElement)
      {
      idWord.focus()
      idWord.document.execCommand("SelectAll")
      idWord.document.execCommand("Paste")

      oSel.pasteHTML(cleanFromWord())
      oSel.execCommand("SelectAll")
      }
}
function cleanFromWord()
{
      for (var i = 0; i < idWord.document.body.all.length; i++)
      {
      idWord.document.body.all[i].removeAttribute("className","",0);
      idWord.document.body.all[i].removeAttribute("style","",0);
      }
    var sHTML = idWord.document.body.innerHTML;
    alert(sHTML)
      return  sHTML;
}
function GetElement(oElement,sMatchTag)
{
   while (oElement!=null && oElement.tagName!=sMatchTag)
      {
      if(oElement.id=="idContent") return null;
      oElement = oElement.parentElement
      }
   return oElement
}
function setDefaultColor(Name,Color)
{
   var OutputID = Name
   var TextID = Name + "_1"
   var ColorID = Name + "_2"
   eval("idContentTmp."+OutputID).value = Color;
   eval("idContentTmp."+TextID).innerHTML = "<font size=1>"+Color+"</font>"
   eval("idContentTmp."+ColorID).style.background = Color;
}
function displayBgColor()
{
    idc=idContentTmp
   if(idc.divBgColorPick.style.display=="none")
      {
      if(idc.divBgColorPick.innerHTML=="")
         {
         idc.divBgColorPick.innerHTML = writeColorPicker("inpBgColorPick","inpBgColor.value=inpBgColorPick.value",1);
         setDefaultColor("inpBgColorPick",idc.inpBgColor.value)
         }
      else
         {
         setDefaultColor("inpBgColorPick",idc.inpBgColor.value)
         }
      idc.divBgColorPick.style.display="block"
      }
   else
      idc.divBgColorPick.style.display='none'
}
function displayBorderColor()
{
    idc=idContentTmp;
   if(idc.divBorderColorPick.style.display=="none")
      {
      if(idc.divBorderColorPick.innerHTML=="")
         {
         idc.divBorderColorPick.innerHTML = writeColorPicker("inpBorderColorPick","inpBorderColor.value=inpBorderColorPick.value",1);
         setDefaultColor("inpBorderColorPick",idc.inpBorderColor.value)
         }
      else
         setDefaultColor("inpBorderColorPick",idc.inpBorderColor.value)
      idc.divBorderColorPick.style.display="block"
      }
   else
      idc.divBorderColorPick.style.display='none'
}
function displayBgColor2()
{
    idc=idContentTmp;
   if(idc.divBgColor2Pick.style.display=="none")
      {
      if(idc.divBgColor2Pick.innerHTML=="")
         {
         idc.divBgColor2Pick.innerHTML = writeColorPicker("inpBgColor2Pick","inpBgColor2.value=inpBgColor2Pick.value",1);
         setDefaultColor("inpBgColor2Pick",idc.inpBgColor2.value)
         }
      else
         setDefaultColor("inpBgColor2Pick",idc.inpBgColor2.value)
      idc.divBgColor2Pick.style.display="block"
      }
   else
      idc.divBgColor2Pick.style.display='none'
}
function displayBorderColor2()
{
   if(idContentTmp.divBorderColor2Pick.style.display=="none")
      {
      if(idContentTmp.divBorderColor2Pick.innerHTML=="")
         {
         idContentTmp.divBorderColor2Pick.innerHTML = writeColorPicker("inpBorderColor2Pick","inpBorderColor2.value=inpBorderColor2Pick.value",1);
         setDefaultColor("inpBorderColor2Pick",idContentTmp.inpBorderColor2.value)
         }
      else
         setDefaultColor("inpBorderColor2Pick",idContentTmp.inpBorderColor2.value)
      idContentTmp.divBorderColor2Pick.style.display="block"
      }
   else
      idContentTmp.divBorderColor2Pick.style.display='none'
}
function displayCellBgColor()
{
    idc=idContentTmp
   if(idc.divCellBgColorPick.style.display=="none")
      {
      if(idc.divCellBgColorPick.innerHTML=="")
         {
         idc.divCellBgColorPick.innerHTML=writeColorPicker("inpCellBgColorPick","inpCellBgColor.value=inpCellBgColorPick.value",1);
         setDefaultColor("inpCellBgColorPick",idc.inpCellBgColor.value)
         }
      else
         {
         setDefaultColor("inpCellBgColorPick",idc.inpCellBgColor.value)
         }
      idc.divCellBgColorPick.style.display="block"
      }
   else
      idc.divCellBgColorPick.style.display='none'
}
function displayTableBox(src)
{
   saveSelection(src)

   var sHTML = "" +
   "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\" style=\"TABLE-LAYOUT: fixed\" align=center height=405>" +
   "<col width=438>" +
   "<tr>" +
   "<td align=center valign=top>" +
   "<table border=0 style=\"table-layout:fixed\" bgcolor=Gainsboro width=402 height=20 cellpadding=0 cellspacing=0>" +
   "  <col width=130><col width=130><col width=130><col width=42>" +
   "  <tr>" +
   "  <td align=center id=\"tab1\" style=\"border-top: darkgray 1px solid; border-left: darkgray 1px solid;\">" +
   "     &nbsp;" +
   "  </td>" +
   "  <td align=center id=\"tab2\" style=\"border-top: darkgray 1px solid; border-left: darkgray 1px solid;\">" +
   "     &nbsp;" +
   "  </td>" +
   "  <td align=center id=\"tab3\" style=\"border-top: darkgray 1px solid; border-left: darkgray 1px solid;  border-right: darkgray 1px solid;\">" +
   "     &nbsp;" +
   "  </td>" +
   "  <td style=\"border-bottom: darkgray 1px solid;\">&nbsp;</td>" +
   "  </tr>" +
   "  </table>" +
   "  <div id=\"idInsertTable\">" +
   "  <table border=0 style=\"table-layout:fixed\" width=420 cellpadding=2 cellspacing=2 bgcolor=\"#ececec\" style=\"border-left: darkgray 1px solid; border-bottom: darkgray 1px solid; border-right: darkgray 1px solid;\">" +
   "  <col width=80><col width=130><col width=80><col width=130>" +

   "  <tr><td>Rows:</td>" +
   "     <td><INPUT type=\"text\" id=inpRows name=inpRows size=2 value=2></td>" +
   "     <td>Columns:</td>" +
   "     <td><INPUT type=\"text\" id=inpCols name=inpCols size=2 value=2></td></tr>" +

   "  <tr><td>Width:</td>" +
   "     <td><INPUT type=\"text\" id=\"inpWidth\" name=inpWidth size=2>" +
   "     <SELECT ID=\"inpWidthMe\" NAME=\"inpWidthMe\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td>" +
   "     <td>Height:</td>" +
   "     <td><INPUT type=\"text\" id=\"inpHeight\" name=inpHeight size=2>" +
   "     <SELECT ID=\"Select2\" NAME=\"inpHeightMe\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Background Color:" +
   "     <INPUT type=\"text\" id=\"inpBgColor\" name=inpBgColor size=6>" +
   "     <INPUT type=\"button\" onclick=\"parent.displayBgColor()\" value=\"Pick\" ID=\"Button3\" NAME=\"Button3\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4>" +
   "     <div id=\"divBgColorPick\" style=\"display:none\"></div>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Background Image URL:" +
   "     <INPUT type=\"text\" id=inpBgImage name=inpBgImage size=30></td></tr>" +
   "  <tr><td>Border Size:</td>" +
   "     <td><INPUT type=\"text\" id=inpBorder name=inpBorder size=2 value=1></td>" +
   "     <td>Alignment:</td>" +
   "     <td>" +
   "     <SELECT ID=\"inpTblAlign\" NAME=\"inpTblAlign\">" +
   "        <OPTION value=\"\"></OPTION>" +
   "        <OPTION value=\"left\">Left</OPTION>" +
   "        <OPTION value=\"center\">Center</OPTION>" +
   "        <OPTION value=\"right\">Right</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Border Color:" +
   "     <INPUT type=\"text\" id=inpBorderColor name=inpBorderColor size=6 value=\"#000000\">" +
   "     <INPUT type=\"button\" onclick=\"parent.displayBorderColor()\" value=\"Pick\" ID=\"Button4\" NAME=\"Button4\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4>" +
   "     <div id=\"divBorderColorPick\" style=\"display:none\"></div>" +
   "     </td></tr>" +
   "  <tr><td>Cell Padding:</td>" +
   "     <td><INPUT type=\"text\" id=inpPadding name=inpPadding size=2 value=0></td>" +
   "     <td>Cell Spacing:</td>" +
   "     <td><INPUT type=\"text\" id=inpSpacing name=inpSpacing size=2 value=0></td></tr>" +
   "  <tr><td colspan=4><hr></td></tr>" +
   "  <tr><td>&nbsp;</td>" +
   "     <td align=right><INPUT type=\"button\" value=\"Cancel\" onclick=\"parent.popupHide();\"></td>" +
   "     <td><INPUT type=\"button\" value=\"&nbsp;&nbsp;OK&nbsp;&nbsp;\" onclick=\"if(parent.TableInsert())parent.popupHide();\"></td>" +
   "     <td>&nbsp;</td></tr>" +
   "  </table>" +
   "  </div>" +
   "  <div id=\"idEditTable\" align=left style=\"display:none\">" +
   "  <table border=0 style=\"table-layout:fixed\" width=420 cellpadding=2 cellspacing=2 bgcolor=\"#ececec\" style=\"border-left: darkgray 1px solid; border-bottom: darkgray 1px solid; border-right: darkgray 1px solid;\" ID=\"Table2\">" +
   "  <col width=80><col width=130><col width=80><col width=130>" +
   "  <tr><td colspan=4>Background Color:" +
   "     <INPUT type=\"text\" id=\"inpBgColor2\" name=inpBgColor2 size=6>" +
   "     <INPUT type=\"button\" onclick=\"parent.displayBgColor2()\" value=\"Pick\" ID=\"Button1\" NAME=\"Button1\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4>" +
   "     <div id=\"divBgColor2Pick\" style=\"display:none\"></div>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Background Image URL:" +
   "     <INPUT type=\"text\" id=inpBgImage2 name=inpBgImage2 size=30></td></tr>" +
   "  <tr><td>Width:</td>" +
   "     <td><INPUT type=\"text\" id=\"inpWidth2\" name=inpWidth2 size=2>" +
   "     <SELECT ID=\"inpWidth2Me\" NAME=\"inpWidth2Me\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td>" +
   "     <td>Height:</td>" +
   "     <td><INPUT type=\"text\" id=\"inpHeight2\" name=inpHeight2 size=2>" +
   "     <SELECT ID=\"Select1\" NAME=\"inpHeight2Me\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td>Cell Padding:</td>" +
   "     <td><INPUT type=\"text\" id=inpPadding2 name=inpPadding2 size=2 value=0></td>" +
   "     <td>Cell Spacing:</td>" +
   "     <td><INPUT type=\"text\" id=inpSpacing2 name=inpSpacing2 size=2 value=0></td></tr>" +
   "  <tr><td>Border Size:</td>" +
   "     <td><INPUT type=\"text\" id=inpBorder2 name=inpBorder2 size=2 value=1></td>" +
   "     <td>Alignment :</td>" +
   "     <td>" +
   "     <SELECT ID=\"inpTblAlign2\" NAME=\"inpTblAlign2\">" +
   "        <OPTION value=\"left\">Left</OPTION>" +
   "        <OPTION value=\"center\">Center</OPTION>" +
   "        <OPTION value=\"right\">Right</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Border Color:" +
   "     <INPUT type=\"text\" id=\"inpBorderColor2\" name=inpBorderColor2 size=6>" +
   "     <INPUT type=\"button\" onclick=\"parent.displayBorderColor2()\" value=\"Pick\" ID=\"Button7\" NAME=\"Button7\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4>" +
   "     <div id=\"divBorderColor2Pick\" style=\"display:none\"></div>" +
   "     </td></tr>" +
   "  <tr><td colspan=4><hr></td></tr>" +
   "  <tr><td>&nbsp;</td>" +
   "     <td align=right><INPUT type=\"button\" value=\"Cancel\" onclick=\"parent.popupHide();\" id=\"Button5\" name=button1></td>" +
   "     <td><INPUT type=\"button\" value=\"&nbsp;&nbsp;OK&nbsp;&nbsp;\" onclick=\"if(parent.TableUpdate())parent.popupHide();\" id=\"Button6\" name=button1></td>" +
   "     <td>&nbsp;</td></tr>" +
   "  </table>" +
   "  </div>" +
   "  <div id=\"idEditCell\" align=left style=\"display:none\">" +
   "  <table border=0 style=\"table-layout:fixed\" width=420 cellpadding=2 cellspacing=2 bgcolor=\"#ececec\" style=\"border-left: darkgray 1px solid; border-bottom: darkgray 1px solid; border-right: darkgray 1px solid;\" ID=\"Table3\">" +
   "  <col width=80><col width=130><col width=80><col width=130>" +
   "  <tr><td colspan=4>Cell Background Color :" +
   "     <INPUT type=\"text\" id=\"inpCellBgColor\" name=inpCellBgColor size=6>" +
   "     <INPUT type=\"button\" onclick=\"parent.displayCellBgColor()\" value=\"Pick\" ID=\"Button2\" NAME=\"Button1\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4>" +
   "     <div id=\"divCellBgColorPick\" style=\"display:none\"></div>" +
   "     </td></tr>" +
   "  <tr><td colspan=4>Cell Background Image URL :" +
   "     <INPUT type=\"text\" id=\"inpCellBgImage\" name=inpCellBgImage size=30></td></tr>" +
   "  <tr><td>Cell Width :</td>" +
   "     <td><INPUT type=\"text\" id=\"inpCellWidth\" name=inpCellWidth size=2>" +
   "     <SELECT ID=\"inpCellWidthMe\" NAME=\"inpCellWidthMe\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td>" +
   "     <td>Cell Height :</td>" +
   "     <td><INPUT type=\"text\" id=\"inpCellHeight\" name=inpCellHeight size=2>" +
   "     <SELECT ID=\"inpCellHeightMe\" NAME=\"inpCellHeightMe\">" +
   "        <OPTION value=\"\">pixels</OPTION>" +
   "        <OPTION value=\"%\">percent</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td>Alignment :</td>" +
   "     <td>" +
   "     <SELECT ID=\"inpCellAlign\" NAME=\"inpCellAlign\">" +
   "        <OPTION value=\"left\">Left</OPTION>" +
   "        <OPTION value=\"center\">Center</OPTION>" +
   "        <OPTION value=\"right\">Right</OPTION>" +
   "     </SELECT>" +
   "     </td>" +
   "     <td colspan=2>Vertical Alignment :" +
   "     <SELECT ID=\"inpCellVAlign\" NAME=\"inpCellVAlign\">" +
   "        <OPTION value=\"top\">Top</OPTION>" +
   "        <OPTION value=\"middle\">Middle</OPTION>" +
   "        <OPTION value=\"bottom\">Bottom</OPTION>" +
   "     </SELECT>" +
   "     </td></tr>" +
   "  <tr><td>Wrap Text :</td>" +
   "     <td><INPUT type=\"checkbox\" ID=\"inpCellWrap\" NAME=\"inpCellWrap\"></td>" +
   "     <td colspan=2></td></tr>" +
   "  <tr><td>Insert Row:</td>" +
   "     <td colspan=3>" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableInsertRow('above');parent.popupHide();\" value=\"Above\" id=\"btnInsertRow\" NAME=\"btnInsertRow\">" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableInsertRow('below');parent.popupHide();\" value=\"Below\" id=\"btnInsertRow\" NAME=\"btnInsertRow\">" +
   "     </td></tr>" +
   "  <tr><td>Insert Column:</td>" +
   "     <td colspan=3>" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableInsertCol('left');parent.popupHide();\" value=\"to the Left\" id=\"btnInsertColumn\" NAME=\"btnInsertColumn\">" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableInsertCol('right');parent.popupHide();\" value=\"to the Right\" id=\"btnInsertColumn\" NAME=\"btnInsertColumn\">" +
   "     </td></tr>" +
   "  <tr><td>Delete:</td>" +
   "     <td colspan=3>" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableDeleteRow();parent.popupHide();\" value=\"Delete Row\" id=\"btnDeleteRow\" NAME=\"btnDeleteRow\">" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableDeleteCol();parent.popupHide();\" value=\"Delete Column\" id=\"btnDeleteColumn\" NAME=\"btnDeleteColumn\">" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableDeleteCell();parent.popupHide();\" value=\"Delete Cell\" id=\"btnDeleteCell\" NAME=\"btnDeleteCell\">" +
   "     </td></tr>" +
   "  <tr><td>Span:</td>" +
   "     <td colspan=3>" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableColSpan();parent.popupHide();\" value=\"Columns Span\" id=\"btnColumnsSpan\" NAME=\"btnColumnsSpan\">" +
   "     <INPUT style=\"width=95\" type=\"button\" onclick=\"parent.TableRowSpan();parent.popupHide();\" value=\"Rows Span\" id=\"btnRowsSpan\" NAME=\"btnRowsSpan\">" +
   "     </td></tr>" +
   "  <tr><td colspan=4><hr></td></tr>" +
   "  <tr><td>&nbsp;</td>" +
   "     <td align=right><INPUT type=\"button\" value=\"Cancel\" onclick=\"parent.popupHide();\"></td>" +
   "     <td><INPUT type=\"button\" value=\"&nbsp;&nbsp;OK&nbsp;&nbsp;\" onclick=\"if(parent.CellUpdate())parent.popupHide();\"></td>" +
   "     <td>&nbsp;</td></tr>" +
   "  </table>" +
   "  </div>" +
   "</td>" +
   "</tr>" +
   "</table>"
   popupShow(440,"Create/Edit Table",sHTML)
    idc=idContentTmp
   idc.inpRows.value = 2;
   idc.inpCols.value = 2;
   idc.inpTblAlign.value = "";
   idc.inpWidth.value = "";
   idc.inpHeight.value = "";
   idc.inpPadding.value = 0;
   idc.inpSpacing.value = 0;
   idc.inpBorder.value = 1;
   idc.inpBorderColor.value = "";
   idc.inpBgImage.value = "";
   idc.inpBgColor.value = "";
   var oSel = oSelSave
   var sType = sSelType
   var oBlock = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))
   if (oBlock!=null)
      {
      idc.inpTblAlign2.value = oBlock.align
      var st = oBlock.width
      if(st.indexOf("%")!=-1)
         {
         idc.inpWidth2.value = st.substring(0,st.indexOf("%"))
         idc.inpWidth2Me.value = "%"
         }
      else
         {
         idc.inpWidth2.value = oBlock.width
         idc.inpWidth2Me.value = ""
         }
      var st2 = oBlock.height
      if(st2.indexOf("%")!=-1)
         {
         idc.inpHeight2.value = st2.substring(0,st2.indexOf("%")) //remove last %
         idc.inpHeight2Me.value = "%"
         }
      else
         {
         idc.inpHeight2.value = oBlock.height
         idc.inpHeight2Me.value = ""
         }
      idc.inpPadding2.value = oBlock.cellPadding
      idc.inpSpacing2.value = oBlock.cellSpacing
      idc.inpBorder2.value = oBlock.border

      idc.inpBorderColor2.value = (oBlock.borderColor).substring(1)
      idc.inpBgImage2.value = oBlock.background
      idc.inpBgColor2.value = (oBlock.bgColor).substring(1)

      if(oSel.parentElement != null)
         {
         var oTD = GetElement(oSel.parentElement(),"TD");
         if(oTD==null)return;
         var st3 = oTD.width
         if(st3.indexOf("%")!=-1)
            {
            idc.inpCellWidth.value = st3.substring(0,st3.indexOf("%"))
            idc.inpCellWidthMe.value = "%"
            }
         else
            {
            idc.inpCellWidth.value = oTD.width
            idc.inpCellWidthMe.value = ""
            }
         var st4 = oTD.height
         if(st4.indexOf("%")!=-1)
            {
            idc.inpCellHeight.value = st4.substring(0,st4.indexOf("%"))
            idc.inpCellHeightMe.value = "%"
            }
         else
            {
            idc.inpCellHeight.value = oTD.height
            idc.inpCellHeightMe.value = ""
            }
         idc.inpCellAlign.value = oTD.align
         idc.inpCellVAlign.value = oTD.vAlign
         idc.inpCellBgImage.value = oTD.background
         idc.inpCellBgColor.value = (oTD.bgColor).substring(1)
         idc.inpCellWrap.checked = !oTD.noWrap;
         TabEditCell()
         }
      else
         {
         TabEditTable()
         TabDisable1()
         }
      }
   else
      {
      TabInsertTable()
      TabDisable2()
      }
}
function TabInsertTable()
{
    idc=idContentTmp;
   idc.divBorderColorPick.style.display = "none";
   idc.divBgColorPick.style.display = "none";

   idc.idInsertTable.style.display="block";
   idc.idEditTable.style.display="none";
   idc.idEditCell.style.display="none";

   idc.tab1.style.cursor = "";
   idc.tab1.style.background = "#ececec";
   idc.tab1.style.color = "darkslateblue";
   idc.tab1.style.borderBottom = "";
   idc.tab1.innerHTML = "<b>Create Table</b>"

   idc.tab2.style.background = "#bebebe";
   idc.tab2.style.color = "darkslateblue";
   idc.tab2.style.borderBottom = "darkgray 1px solid";
   idc.tab2.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabEditTable()'><b><u>Edit Table</u></b></div>"

   idc.tab3.style.background = "#bebebe";
   idc.tab3.style.color = "darkslateblue";
   idc.tab3.style.borderBottom = "darkgray 1px solid";
   idc.tab3.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabEditCell()'><b><u>Edit Cell</u></b></div>"
}
function TabEditTable()
{
    idc=idContentTmp;
   idc.divBorderColor2Pick.style.display = "none";
   idc.divBgColor2Pick.style.display = "none";

   idc.idInsertTable.style.display="none";
   idc.idEditTable.style.display="block";
   idc.idEditCell.style.display="none";

   idc.tab1.style.background = "#bebebe";
   idc.tab1.style.color = "darkslateblue";
   idc.tab1.style.borderBottom = "darkgray 1px solid";
   idc.tab1.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabInsertTable()'><b><u>Create Table</u></b></div>"

   idc.tab2.style.cursor = "";
   idc.tab2.style.background = "#ececec";
   idc.tab2.style.color = "darkslateblue";
   idc.tab2.style.borderBottom = "";
   idc.tab2.innerHTML = "<b>Edit Table</b>"

   idc.tab3.style.background = "#bebebe";
   idc.tab3.style.color = "darkslateblue";
   idc.tab3.style.borderBottom = "darkgray 1px solid";
   idc.tab3.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabEditCell()'><b><u>Edit Cell</u></b></div>"
}
function TabEditCell()
{
    idc=idContentTmp;
   idc.idEditCell.style.display="block";
   idc.divCellBgColorPick.style.display = "none";

   idc.idInsertTable.style.display="none";
   idc.idEditTable.style.display="none";
   idc.idEditCell.style.display="block";

   idc.tab1.style.background = "#bebebe";
   idc.tab1.style.color = "darkslateblue";
   idc.tab1.style.borderBottom = "darkgray 1px solid";
   idc.tab1.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabInsertTable()'><b><u>Create Table</u></b></div>"

   idc.tab2.style.background = "#bebebe";
   idc.tab2.style.color = "darkslateblue";
   idc.tab2.style.borderBottom = "darkgray 1px solid";
   idc.tab2.innerHTML = "<div style='cursor:hand;width=100%;' onclick='parent.TabEditTable()'><b><u>Edit Table</u></b></div>"

   idc.tab3.style.cursor = "";
   idc.tab3.style.background = "#ececec";
   idc.tab3.style.color = "darkslateblue";
   idc.tab3.style.borderBottom = "";
   idc.tab3.innerHTML = "<b>Edit Cell</b>"
}
function TabDisable1()
{
    idc=idContentTmp;
   idc.tab1.style.cursor = "";
   idc.tab1.style.background = "#bebebe";
   idc.tab1.style.color = "darkgray";
   idc.tab1.style.borderBottom = "";
   idc.tab1.innerHTML = "<b><u>Create Table</u></b>"

   idc.tab3.style.cursor = "";
   idc.tab3.style.background = "#bebebe";
   idc.tab3.style.color = "darkgray";
   idc.tab3.style.borderBottom = "";
   idc.tab3.innerHTML = "<b><u>Edit Cell</u></b>"
}
function TabDisable2()
{
    idc=idContentTmp;
   idc.tab2.style.cursor = "";
   idc.tab2.style.background = "#bebebe";
   idc.tab2.style.color = "darkgray";
   idc.tab2.style.borderBottom = "";
   idc.tab2.innerHTML = "<b><u>Edit Table</u></b>"

   idc.tab3.style.cursor = "";
   idc.tab3.style.background = "#bebebe";
   idc.tab3.style.color = "darkgray";
   idc.tab3.style.borderBottom = "";
   idc.tab3.innerHTML = "<b><u>Edit Cell</u></b>"
}
function TableInsert()
{
   if(!(IsPosIntNotZero(idContentTmp.inpRows.value) &&
      IsPosIntNotZero(idContentTmp.inpCols.value) &&
      IsPosIntNotZero(idContentTmp.inpWidth.value) &&
      IsPosIntNotZero(idContentTmp.inpHeight.value) &&
      IsPosInt(idContentTmp.inpBorder.value) &&
      IsPosInt(idContentTmp.inpPadding.value) &&
      IsPosInt(idContentTmp.inpSpacing.value)))
      {
      alert("Invalid input.");
      return false;
   }
   var sHTML = ""
      + "<TABLE "
      + (((idc.inpBorder.value=="") || (idc.inpBorder.value=="0")) ? "class=\"NOBORDER\"" : "")
      +  (idc.inpTblAlign.value != "" ? "align=\"" + idc.inpTblAlign.value + "\" " : "")
      +  (idc.inpWidth.value != "" ? "width=\"" + idc.inpWidth.value + idc.inpWidthMe.value + "\" " : "")
      +  (idc.inpHeight.value != "" ? "height=\"" + idc.inpHeight.value + idc.inpHeightMe.value + "\" " : "")
      +  (idc.inpPadding.value != "" ? "cellPadding=\"" + idc.inpPadding.value + "\" " : "")
      +  (idc.inpSpacing.value != "" ? "cellSpacing=\"" + idc.inpSpacing.value + "\" " : "")
      +  (idc.inpBorder.value != "" ? "border=\"" + idc.inpBorder.value + "\" " : "")
      +  (idc.inpBorderColor.value != "" ? "bordercolor=\"" + idc.inpBorderColor.value + "\" " : "")
      +  (idc.inpBgImage.value != "" ? "background=\"" + idc.inpBgImage.value + "\" " : "")
      +  (idc.inpBgColor.value != "" ? "bgColor=\"" + idc.inpBgColor.value + "\" " : "")
      + ">"
   for (var i=0;i<idc.inpRows.value;i++)
      {
      sHTML += "<TR>"
      for (var j=0;j<idc.inpCols.value;j++)
      sHTML += "<TD>&nbsp;</TD>"
      sHTML += "</TR>"
      }
   sHTML += "</TABLE>"
   var oSel = oSelSave
   var sType = sSelType
   if (sType=="Control")oSel.item(0).outerHTML=sHTML
   else oSel.pasteHTML(sHTML)
   return true;
}
function TableUpdate()
{
   if(!(IsPosIntNotZero(idContentTmp.inpWidth2.value) &&
      IsPosIntNotZero(idContentTmp.inpHeight2.value) &&
      IsPosInt(idContentTmp.inpPadding2.value) &&
      IsPosInt(idContentTmp.inpSpacing2.value) &&
      IsPosInt(idContentTmp.inpBorder2.value)))
      {
      alert("Invalid input.");
      return false;
      }

   var oSel = oSelSave
   var sType = sSelType

   var oBlock = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))
   if (oBlock!=null)
      {
      oBlock.align = idContentTmp.inpTblAlign2.value
      if(idContentTmp.inpWidth2.value!="")
         {
         oBlock.style.width="";
         oBlock.width = idContentTmp.inpWidth2.value + idContentTmp.inpWidth2Me.value;
         }
      else
         {
         oBlock.width = ""
         }
      if(idContentTmp.inpHeight2.value!="")
         {
         oBlock.style.height="";
         oBlock.height = idContentTmp.inpHeight2.value + idContentTmp.inpHeight2Me.value;
         }
      else
         {
         oBlock.height = ""
         }
      oBlock.cellPadding = idContentTmp.inpPadding2.value
      oBlock.cellSpacing = idContentTmp.inpSpacing2.value
      oBlock.border = idContentTmp.inpBorder2.value
      oBlock.borderColor = idContentTmp.inpBorderColor2.value
      oBlock.background = idContentTmp.inpBgImage2.value
      oBlock.bgColor = idContentTmp.inpBgColor2.value
      }

   oSel.select()
   return true;
}
function CellUpdate()
{
   if(!(IsPosIntNotZero(idContentTmp.inpCellWidth.value) &&
      IsPosIntNotZero(idContentTmp.inpCellHeight.value)))
      {
      alert("Invalid input.");
      return false;
      }

   var oSel = oSelSave
   var sType = sSelType

   var oTD = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   if (oTD!=null)
      {
      if(idContentTmp.inpCellWidth.value!="")
         {
         oTD.width = idContentTmp.inpCellWidth.value + idContentTmp.inpCellWidthMe.value;
         }
      else
         {
         oTD.width = ""
         }
      if(idContentTmp.inpCellHeight.value!="")
         {
         oTD.height = idContentTmp.inpCellHeight.value + idContentTmp.inpCellHeightMe.value;
         }
      else
         {
         oTD.height = ""
         }

      oTD.align = idContentTmp.inpCellAlign.value ;
      oTD.vAlign = idContentTmp.inpCellVAlign.value;
      oTD.background = idContentTmp.inpCellBgImage.value;
      oTD.bgColor = idContentTmp.inpCellBgColor.value ;
      oTD.noWrap = !idContentTmp.inpCellWrap.checked;
      }

   oSel.select()

   return true;
}
function IsPosInt(sInput)
{
   if(sInput=="") return true;
   var sTmp = sInput.toString();
   for(var i=0;i<sTmp.length;i++)
      {
      var sChar = sTmp.charAt(i);
      if(sChar<"0"||sChar>"9") return false;
      }
   return true;
}
function IsPosIntNotZero(sInput)
{
   if(sInput=="") return true;
   var sTmp = sInput.toString();
   for(var i=0;i<sTmp.length;i++)
      {
      var sChar = sTmp.charAt(i);
      if(sChar<"0"||sChar>"9") return false;
      }
   if(sInput*1==0) {return false}
   else {return true};
}

function TableInsertRow(type)
{
   var oSel=oSelSave
   var sType=sSelType

   var oBlock=(oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))

   var numofrows=oBlock.rows.length;

   var i,iRow;
   var oTR=(oSel.parentElement!=null?GetElement(oSel.parentElement(),"TR") : GetElement(oSel.item(0),"TR"))
   for (i=0;i<numofrows;i++)
      {
      if(oTR==oBlock.rows[i]) iRow=i;
      }

   var numofcols=oBlock.rows[0].cells.length

   var elRow;
   if(type=="above") elRow = oBlock.insertRow(iRow);
   if(type=="below") elRow = oBlock.insertRow(iRow+1);

   for (i=0;i<numofcols;i++)
      {
      try
         {
         var elCell = elRow.insertCell()
         elCell.innerHTML = "&nbsp;"
         }
      catch(e)
         {}
      }
}
function TableDeleteRow()
{
   var oSel=oSelSave
   var sType=sSelType

   var oBlock=(oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))
   var oTR=(oSel.parentElement != null ? GetElement(oSel.parentElement(),"TR") : GetElement(oSel.item(0),"TR"))

   try
      {
      var iRow;
      for (var i=0;i<oBlock.rows.length;i++)
         {
         if(oTR==oBlock.rows[i])oBlock.deleteRow(i);
         }
      }
   catch(e)
      {
      return;
      }
}
function TableInsertCol(type)
{
   var oSel = oSelSave
   var sType = sSelType

   var oBlock = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))

   var oTD = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   var iCol;
   iCol = oTD.cellIndex;
   if(type=="right") iCol=iCol+1;
   var numofrows=oBlock.rows.length;
   for(var i=0;i<numofrows;i++)
      {
      try
         {
         var elCell = oBlock.rows[i].insertCell(iCol)
         elCell.innerHTML = "&nbsp;"
         }
      catch(e)
         {}
      }
}
function TableDeleteCol()
{
   var oSel = oSelSave
   var sType = sSelType

   var oBlock = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))
   var oTD = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   try
      {
      var iRow;
      var oTR = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TR") : GetElement(oSel.item(0),"TR"))
      for (var i=0;i<oBlock.rows.length;i++)
         {
         if(oTR==oBlock.rows[i]) iRow=i;
         }
      var iCol = oTD.cellIndex;
      for (var i=0;i<oBlock.rows.length;i++)
         {
         oBlock.rows[i].deleteCell(iCol);
         }
      }
   catch(e)
      {
      return;
      }
}
function TableDeleteCell()
{
   var oSel = oSelSave
   var sType = sSelType

   var oBlock = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TABLE") : GetElement(oSel.item(0),"TABLE"))
   var oTD = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   try
      {
      var iRow;
      var oTR = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TR") : GetElement(oSel.item(0),"TR"))
      for (var i=0;i<oBlock.rows.length;i++)
         {
         if(oTR==oBlock.rows[i]) iRow=i;
         }
      var iCol = oTD.cellIndex;
      oBlock.rows[iRow].deleteCell(iCol);
      }
   catch(e)
      {
      return;
      }
}
function TableColSpan()
{
   var oSel = oSelSave
   var sType = sSelType

   var oTD = (oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   oTD.colSpan = 2;
}
function TableRowSpan()
{
   var oSel=oSelSave
   var sType=sSelType
   var oTD=(oSel.parentElement != null ? GetElement(oSel.parentElement(),"TD") : GetElement(oSel.item(0),"TD"))
   oTD.rowSpan = 2;
}
function buildToolbar(src)
{
    drawIcon(0,0,118,"btnFontName","Font Name","displayFontNameBox("+src+")")
    drawIcon(118,0,116,"btnFontSize","Font Size","displayFontSizeBox("+src+")")
    drawIcon(20,110,23,"btnCut","Cut","doCmd('Cut',"+src+");")
    drawIcon(43,110,21,"btnCopy","Copy","doCmd('Copy',"+src+");")
    drawIcon(64,110,22,"btnPaste","Paste","doCmd('Paste',"+src+");")
    drawIcon(86,110,21,"btnUndo","Undo","doCmd('Undo',"+src+")")
    drawIcon(107,110,21,"btnRedo","Redo","doCmd('Redo',"+src+")")
//    drawIcon(1105,23,"btnWord","Paste from Word","pasteFromWord()")
    drawIcon(128,110,21,"btnBold","Bold","doCmd('Bold',"+src+")")
    drawIcon(149,110,21,"btnItalic","Italic","doCmd('italic',"+src+");")
    drawIcon(170,110,21,"btnUnderline","Underline","doCmd('underline',"+src+");")
    drawIcon(191,110,21,"btnStrikethrough","Strikethrough","doCmd('strikethrough',"+src+");")
    drawIcon(212,110,21,"btnSuperscript","Superscript","doCmd('superscript',"+src+");")
    drawIcon(233,110,21,"btnSubscript","Subscript","doCmd('subscript',"+src+");")
    document.write("<br>")
    drawIcon(23,220,21,"btnJustifyLeft","Justify Left","doCmd('justifyleft',"+src+");")
    drawIcon(44,220,21,"btnJustifyCenter","Justify Center","doCmd('justifycenter',"+src+");")
    drawIcon(65,220,21,"btnJustifyRight","Justify Right","doCmd('justifyright',"+src+");")
    drawIcon(86,220,21,"btnJustifyFull","Justify Full","doCmd('justifyfull',"+src+");")
    drawIcon(107,220,21,"btnInsertOrderedList","Ordered List","doCmd('insertorderedlist',"+src+");")
    drawIcon(128,220,21,"btnInsertUnorderedList","Unordered List","doCmd('insertunorderedlist',"+src+");")
    drawIcon(149,220,21,"btnIndent","Indent","doCmd('indent',"+src+");")
    drawIcon(170,220,21,"btnOutdent","Outdent","doCmd('outdent',"+src+");")
    drawIcon(191,220,21,"btnHorizontalLine","Horizontal Line","doCmd('InsertHorizontalRule',"+src+")")
    drawIcon(212,220,21,"btnTable","Create Table","displayTableBox("+src+")")
    drawIcon(233,220,21,"btnExternalLink","External Link","displayLinkBox("+src+")")
    drawIcon(23,330,21,"btnUnlink","Unlink","doCmd('unlink',"+src+")")
//    drawIcon(65,330,21,"btnInternalImage","Insert/update Image","doCmd('DialogImage',"+src+")")
    drawIcon(86,330,21,"btnForeground","Foreground","displayFgColorBox("+src+")")
    drawIcon(148,330,21,"btnRemoveFormat","Remove Formatting","doCmd('removeformat',"+src+")")
}
function setImage(n)
{
   doCmd("InsertImage",srcSave,imgroot+n);
}
function setUrl(n)
{
    idContentTmp.idLinkURL.value=n
    idContentTmp.idLinkType.value = "1";
    typeswitch();
}
function _keypress(src)
{
    e=src.window.event
    if(e.keyCode==13 && e.shiftKey==false)
        {
        e.cancelBubble=true
        e.returnValue=false
        var oSel=src.document.selection.createRange()
        oSel.pasteHTML('<br>')
        oSel.select()
        oSel.moveEnd("character", 1);
        oSel.moveStart("character", 1);
        oSel.collapse(false);
        return false;
        }
    return true;
}
