BVB Source Codes

Pcook CMS bubble guest v3.0 SDCMS version Show editor.js Source code

Return Download Pcook CMS bubble guest v3.0 SDCMS version: download editor.js Source code - Download Pcook CMS bubble guest v3.0 SDCMS version Source code - Type:.js
  1. /***********************************************************
  2. InnovaStudio WYSIWYG Editor 3.1
  3. ?2008, InnovaStudio (www.innovastudio.com). All rights reserved.
  4. ************************************************************/
  5.  
  6. var editor = new Array();
  7.  
  8. /*** Utility Object ***/
  9. var oUtil=new InnovaEditorUtil();
  10. function InnovaEditorUtil()
  11.     {
  12.     /*** Localization ***/
  13.   this.langDir="zh-CHS";
  14.   try{if(LanguageDirectory)this.langDir=LanguageDirectory;}catch(e){;}
  15.     var oScripts=document.getElementsByTagName("script");
  16.     for(var i=0;i<oScripts.length;i++)
  17.         {
  18.         var sSrc=oScripts[i].src.toLowerCase();
  19.         if(sSrc.indexOf("moz/editor.js")!=-1)
  20.             {
  21.             this.scriptPath=oScripts[i].src.replace(/editor.js/,"");
  22.             }
  23.         else if(sSrc.indexOf("scripts/innovaeditor.js")!=-1)/*optional, kalau embed innovaeditor.js (khusus firefox perlu)*/
  24.             {
  25.             if(!this.scriptPath)
  26.         this.scriptPath=oScripts[i].src.replace(/innovaeditor.js/,"")+"moz/";
  27.             }
  28.         }
  29.     this.scriptPathLang=this.scriptPath.replace(/\/moz/,"")+"language/"+this.langDir+"/";
  30.   if(this.langDir=="en-US")
  31.   document.write("<scr"+"ipt src='"+this.scriptPathLang+"editor_lang.js'></scr"+"ipt>");
  32.   /*** /Localization ***/
  33.  
  34.     this.oName;
  35.     this.oEditor;
  36.     this.obj;
  37.     this.oSel;
  38.     this.sType;
  39.     this.bInside=bInside;
  40.     this.useSelection=true;
  41.     this.arrEditor=[];
  42.     this.onSelectionChanged=function(){return true;};
  43.     this.activeElement;
  44.     this.activeModalWin;
  45.     this.setEdit = setEdit;
  46.     this.bOnLoadReplaced=false;
  47.    
  48.     this.spcCharCode=[[169, "&copy;"],[163, "&pound;"],[174, "&reg;"],[233, "&eacute;"],[201, "&Eacute;"],[8364,"&euro;"]];
  49.     this.spcChar=[];
  50.     for(var i=0;i<this.spcCharCode.length;i++)
  51.       {
  52.       this.spcChar[i]=[new RegExp(String.fromCharCode(this.spcCharCode[i][0]), "g"), this.spcCharCode[i][1]];
  53.       }
  54.  
  55.     this.replaceSpecialChar=function(sHTML)
  56.       {
  57.       for(var i=0;i<this.spcChar.length;i++)
  58.         {
  59.         sHTML=sHTML.replace(this.spcChar[i][0], this.spcChar[i][1]);
  60.         }
  61.       return sHTML;
  62.       }
  63.    
  64.     }
  65.  
  66. /*** Focus stuff ***/
  67. function bInside(oElement)
  68.     {
  69.     while(oElement!=null)
  70.         {
  71.         if(oElement.designMode && oElement.designMode=="on")return true;
  72.         oElement=oElement.parentNode;
  73.         }
  74.     return false;
  75.     }
  76.  
  77. function checkFocus()
  78.     {
  79.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  80.     var oSel=oEditor.getSelection();
  81.     var parent = getSelectedElement(oSel);
  82.     if(parent!=null)
  83.         {
  84.         if(!bInside(parent))return false;
  85.         }
  86.     else
  87.         {
  88.         if(!bInside(parent))return false;
  89.         }
  90.     return true;
  91.     }
  92.  
  93. function iwe_focus()
  94.     {
  95.     var oEditor=document.getElementById("idContent"+this.oName);
  96.     if(oEditor) oEditor.contentWindow.focus();
  97.     }
  98.  
  99. /*** setEdit ***/
  100. function setEdit(oName)
  101.   {
  102.   if ((oName != null) && (oName!=""))
  103.     {
  104.     try
  105.       {
  106.       var wnd=document.getElementById("idContent"+oName);
  107.       wnd.contentDocument.designMode="on";
  108.       wnd.focus();
  109.       } catch(e) {}
  110.     }
  111.   else
  112.     {
  113.     for (var i=0; i<this.arrEditor.length; i++)
  114.       {
  115.       try
  116.         {
  117.           var wnd=document.getElementById("idContent"+this.arrEditor[i]).contentWindow;
  118.           wnd.document.designMode="on";
  119.           var r = wnd.getSelection().getRangeAt(0);
  120.           r.selectNode(wnd.document.getElementsByTagName("Body")[0]);
  121.           r.collapse(true);
  122.           wnd.focus();
  123.         } catch(e) {}
  124.       }
  125.     }
  126.   }
  127.  
  128. /*** icons related ***/
  129. var iconHeight;
  130.  
  131. /*** EDITOR OBJECT ***/
  132. function InnovaEditor(oName)
  133.     {
  134.     this.oName=oName;
  135.     this.init=initISEditor;
  136.     this.RENDER=RENDER;
  137.  
  138.     this.loadHTML=loadHTML;
  139.     this.loadHTMLFull=loadHTMLFull;
  140.     this.getHTMLBody=getHTMLBody;
  141.     this.getHTML=getHTML;
  142.     this.getXHTMLBody=getXHTMLBody;
  143.     this.getXHTML=getXHTML;
  144.     this.getTextBody=getTextBody;
  145.     this.putHTML=putHTML;//source dialog
  146.     this.css="";
  147.    
  148.     this.onKeyPress=function(){return true;};
  149.    
  150.   this.styleSelectionHoverBg="#acb6bf";
  151.     this.styleSelectionHoverFg="white";
  152.    
  153.   //clean
  154.   this.cleanEmptySpan=cleanEmptySpan;
  155.   this.cleanFonts=cleanFonts;
  156.   this.cleanTags=cleanTags;
  157.   this.replaceTags=replaceTags;
  158.   this.cleanDeprecated=cleanDeprecated;
  159.    
  160.   this.doClean=doClean;
  161.   this.applySpanStyle=applySpanStyle;
  162.  
  163.     this.bInside=bInside;
  164.     this.checkFocus=checkFocus;
  165.     this.focus=iwe_focus;
  166.  
  167.     this.doCmd=doCmd;
  168.     this.applyParagraph=applyParagraph;
  169.     this.applyFontName=applyFontName;
  170.     this.applyFontSize=applyFontSize;
  171.     this.applyBullets=applyBullets;
  172.     this.applyNumbering=applyNumbering;
  173.     this.applyJustifyLeft=applyJustifyLeft;
  174.     this.applyJustifyCenter=applyJustifyCenter;
  175.     this.applyJustifyRight=applyJustifyRight;
  176.     this.applyJustifyFull=applyJustifyFull;
  177.     this.applyBlockDirLTR=applyBlockDirLTR;
  178.     this.applyBlockDirRTL=applyBlockDirRTL;
  179.     this.applySpan=applySpan;
  180.     this.makeAbsolute=makeAbsolute;
  181.     this.insertHTML=insertHTML;
  182.     this.clearAll=clearAll;
  183.     this.insertCustomTag=insertCustomTag;
  184.     this.selectParagraph=selectParagraph;
  185.  
  186.     this.useB=false;//not used
  187.  
  188.     this.hide=hide;
  189.  
  190.     this.width="560px";
  191.     this.height="350px";
  192.     this.publishingPath="";//ex."http://localhost/innovastudio/"
  193.  
  194.     var oScripts=document.getElementsByTagName("script");
  195.     for(var i=0;i<oScripts.length;i++)
  196.       {
  197.       var sSrc=oScripts[i].src.toLowerCase();
  198.       if(sSrc.indexOf("moz/editor.js")!=-1)
  199.         {
  200.         this.scriptPath=oScripts[i].src.replace(/editor.js/,"");
  201.         break;
  202.         }
  203.       else if(sSrc.indexOf("innovaeditor.js")!=-1) //Utk mengatasi masalah di NS7.1 (NS7.2 & 8.0 tdk masalah)
  204.         {
  205.         this.scriptPath=oScripts[i].src.replace(/innovaeditor.js/,"moz/"); break;
  206.         }
  207.       }
  208.  
  209.   /*** icons related ***/
  210.     this.iconPath="icons/";
  211.     this.iconWidth=23; //25;
  212.     this.iconHeight=25; //22;
  213.   /*** /icons related ***/
  214.  
  215.     this.dropTopAdjustment_moz=0;
  216.     this.dropLeftAdjustment_moz=0;
  217.     this.heightAdjustment=0;  //not use, for IE only
  218.  
  219.     this.applyColor=applyColor;
  220.     this.customColors=[];//["#ff4500","#ffa500","#808000","#4682b4","#1e90ff","#9400d3","#ff1493","#a9a9a9"];
  221.     this.oColor1 = new ColorPicker("oColor1",this.oName);//to call: oEdit1.oColor1
  222.     this.oColor2 = new ColorPicker("oColor2",this.oName);//rendered id: ...oColor1oEdit1
  223.     this.expandSelection=expandSelection;
  224.  
  225.     this.useLastForeColor=false;
  226.     this.useLastBackColor=false;
  227.     this.stateForeColor="";
  228.     this.stateBackColor="";
  229.  
  230.     this.fullScreen=fullScreen;
  231.     this.stateFullScreen=false;
  232.  
  233.     this.getElm=iwe_getElm;
  234.  
  235.     this.features=[];
  236.    
  237.  
  238.    
  239.     this.buttonMap=["Save","FullScreen","Preview","Print","Search","SpellCheck",
  240.     "Cut","Copy","Paste","PasteWord","PasteText","Undo","Redo",
  241.     "ForeColor","BackColor","Bookmark","Hyperlink","Unlink",
  242.     "Image","Flash","Media","ContentBlock","InternalLink","InternalImage","CustomObject",
  243.     "Table","Guidelines","Absolute","Characters","Line",
  244.     "Form","RemoveFormat","HTMLFullSource","HTMLSource","XHTMLFullSource",
  245.     "XHTMLSource","ClearAll","BRK",
  246.     "StyleAndFormatting","Styles","CustomTag","Paragraph","FontName","FontSize",
  247.     "Bold","Italic",
  248.     "Underline","Strikethrough","Superscript","Subscript",
  249.     "JustifyLeft","JustifyCenter","JustifyRight","JustifyFull",
  250.     "Numbering","Bullets","Indent","Outdent","CustomName1","LTR","RTL"];//complete, default
  251.    
  252.     //diff: btnSearch, btnCut, btnCopy, btnPaste, btnGuidelines
  253.     this.btnSave=false;this.btnPreview=true;this.btnFullScreen=true;this.btnPrint=false;this.btnSearch=true;
  254.     this.btnSpellCheck=false;this.btnTextFormatting=true;
  255.     this.btnListFormatting=true;this.btnBoxFormatting=true;this.btnParagraphFormatting=true;this.btnCssText=true;this.btnCssBuilder=false;
  256.     this.btnStyles=false;this.btnParagraph=true;this.btnFontName=true;this.btnFontSize=true;
  257.     this.btnCut=true;this.btnCopy=true;this.btnPaste=true;this.btnPasteText=false;this.btnUndo=true;this.btnRedo=true;
  258.     this.btnBold=true;this.btnItalic=true;this.btnUnderline=true;this.btnUnlink=true;
  259.     this.btnStrikethrough=false;this.btnSuperscript=false;this.btnSubscript=false;
  260.     this.btnJustifyLeft=true;this.btnJustifyCenter=true;this.btnJustifyRight=true;this.btnJustifyFull=true;
  261.     this.btnNumbering=true;this.btnBullets=true;this.btnIndent=true;this.btnOutdent=true;
  262.     this.btnLTR=false;this.btnRTL=false;this.btnForeColor=true;this.btnBackColor=true;
  263.     this.btnHyperlink=true;this.btnBookmark=true;this.btnCharacters=true;this.btnCustomTag=false;
  264.     this.btnImage=true;this.btnFlash=false;this.btnMedia=false;
  265.     this.btnTable=true;this.btnGuidelines=true;
  266.     this.btnAbsolute=true;this.btnPasteWord=true;this.btnLine=true;
  267.     this.btnForm=true;this.btnRemoveFormat=true;
  268.     this.btnHTMLFullSource=false;this.btnHTMLSource=false;
  269.     this.btnXHTMLFullSource=false;this.btnXHTMLSource=true;
  270.     this.btnClearAll=false;
  271.  
  272.     this.tabs=null;
  273.     this.groups=null;
  274.  
  275.  
  276.     //*** CMS FUNCTIONS ***
  277.     this.cmdAssetManager="";
  278.  
  279.     this.cmdFileManager="";
  280.     this.cmdImageManager="";
  281.     this.cmdMediaManager="";
  282.     this.cmdFlashManager="";
  283.  
  284.     this.btnContentBlock=false;
  285.     this.cmdContentBlock=";";//needs ;
  286.     this.btnInternalLink=false;
  287.     this.cmdInternalLink=";";//needs ;
  288.     this.insertLink=insertLink;
  289.     this.btnCustomObject=false;
  290.     this.cmdCustomObject=";";//needs ;
  291.     this.btnInternalImage=false;
  292.     this.cmdInternalImage=";";//needs ;
  293.     //**********
  294.  
  295.     this.arrStyle=[];
  296.     this.isCssLoaded=false;
  297.     this.openStyleSelect=openStyleSelect;
  298.  
  299.     this.arrParagraph=[[getTxt("Heading 1"),"H1"],
  300.         [getTxt("Heading 2"),"H2"],
  301.         [getTxt("Heading 3"),"H3"],
  302.         [getTxt("Heading 4"),"H4"],
  303.         [getTxt("Heading 5"),"H5"],
  304.         [getTxt("Heading 6"),"H6"],
  305.         [getTxt("Preformatted"),"PRE"],
  306.         [getTxt("Normal (P)"),"P"],
  307.         [getTxt("Normal (DIV)"),"DIV"]];
  308.  
  309.     this.arrFontName=["\u5B8B\u4F53","\u9ED1\u4F53","\u6977\u4F53_GB2312",
  310.                         "\u4EFF\u5B8B_GB2312","\u96B6\u4E66","\u5E7C\u5706 ","Microsoft YaHei",
  311.                         "Arial","Verdana","Georgia","Book Antiqua","Times New Roman"];
  312.  
  313.     this.arrFontSize=[[getTxt("Size 1"),"1"],
  314.         [getTxt("Size 2"),"2"],
  315.         [getTxt("Size 3"),"3"],
  316.         [getTxt("Size 4"),"4"],
  317.         [getTxt("Size 5"),"5"],
  318.         [getTxt("Size 6"),"6"],
  319.         [getTxt("Size 7"),"7"]];
  320.  
  321.     this.arrCustomTag=[];//eg.[["Full Name","{%full_name%}"],["Email","{%email%}"]];
  322.  
  323.     this.docType="";
  324.     this.html="<html>";
  325.     this.headContent="";
  326.     this.preloadHTML="";
  327.  
  328.     this.onSave=function(){document.getElementById("iwe_btnSubmit"+this.oName).click()};
  329.  
  330.     this.onFullScreen=function(){return true;};
  331.     this.onNormalScreen=function(){return true;};
  332.  
  333.     this.initialRefresh=false;//not used
  334.  
  335.     this.doUndo=doUndo;
  336.     this.doRedo=doRedo;
  337.     this.saveForUndo=saveForUndo;
  338.     this.doUndoRedo=doUndoRedo;
  339.  
  340.     this.arrUndoList=[];
  341.     this.arrRedoList=[];
  342.  
  343.     this.useTagSelector=true;
  344.     this.TagSelectorPosition="bottom";
  345.     this.moveTagSelector=moveTagSelector;
  346.     this.selectElement=selectElement;
  347.     this.removeTag=removeTag;
  348.     this.doClick_TabCreate=doClick_TabCreate;
  349.     this.doRefresh_TabCreate=doRefresh_TabCreate;
  350.  
  351.     this.arrCustomButtons = [["CustomName1","alert(0)","caption here","btnSave.gif"],
  352.                             ["CustomName2","alert(0)","caption here","btnSave.gif"]];
  353.  
  354.     this.onSelectionChanged=function(){return true;};
  355.  
  356.     this.spellCheckMode="ieSpell";
  357.    
  358.     this.encodeIO=false;
  359.     this.changeHeight = changeHeight;
  360.  
  361.     this.REPLACE=REPLACE;
  362.     this.mode="HTMLBody";
  363.     this.idTextArea;
  364.  
  365.     var me=this;
  366.     this.tbar=new ISToolbarManager(this.oName);
  367.  
  368.    
  369.     editor[editor.length] = this;
  370.     return this;
  371.     }
  372.  
  373. /*** Undo/Redo ***/
  374. function saveForUndo()
  375.     {
  376.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  377.     var obj=this;
  378.     if(obj.arrUndoList[0])
  379.         if(oEditor.document.body.innerHTML==obj.arrUndoList[0][0])return;
  380.     for(var i=20;i>1;i--)obj.arrUndoList[i-1]=obj.arrUndoList[i-2];
  381.     obj.focus();
  382.     var oSel=oEditor.getSelection();
  383.     var range = oSel.getRangeAt(0);
  384.     obj.arrUndoList[0]=[oEditor.document.body.innerHTML, range.cloneRange()];
  385.  
  386.     this.arrRedoList=[];//clear redo list
  387.  
  388.     if(this.btnUndo) this.tbar.btns["btnUndo"+this.oName].setState(1);
  389.     if(this.btnRedo) this.tbar.btns["btnRedo"+this.oName].setState(5);
  390.     }
  391. function doUndo()
  392.   {
  393.     this.doUndoRedo(this.arrUndoList, this.arrRedoList);
  394.   }
  395.  
  396. function doRedo()
  397.   {
  398.     this.doUndoRedo(this.arrRedoList, this.arrUndoList);
  399.   }
  400. function doUndoRedo(listA, listB)
  401.     {
  402.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  403.     var obj=this;
  404.     if(!listA[0])return; //return of undo/redo array empty
  405.  
  406.     for(var i=20;i>1;i--)listB[i-1]=listB[i-2];
  407.     var oSel=oEditor.getSelection();
  408.     var range = oSel.getRangeAt(0);
  409.     listB[0]=[oEditor.document.body.innerHTML, range.cloneRange()];
  410.  
  411.     sHTML=listA[0][0];
  412.  
  413.     oEditor.document.body.innerHTML=sHTML;
  414.  
  415.     oSel = oEditor.getSelection();
  416.     oSel.removeAllRanges();
  417.     oSel.addRange(listA[0][1]);
  418.  
  419.     for(var i=0;i<19;i++)listA[i]=listA[i+1];
  420.     listA[19]=null;
  421.     realTime(this);
  422.     }
  423.  
  424. /*** RENDER ***/
  425. var bOnSubmitOriginalSaved=false;
  426. function REPLACE(idTextArea, dvId)
  427.   {
  428.   this.idTextArea=idTextArea;
  429.   var oTextArea=document.getElementById(idTextArea);
  430.   oTextArea.style.display="none";
  431.   var oForm=oTextArea.form;
  432.   if(oForm)
  433.     {
  434.     if(!bOnSubmitOriginalSaved)
  435.       {
  436.       if(oForm.onsubmit)
  437.       onsubmit_original=oForm.onsubmit;
  438.      
  439.       bOnSubmitOriginalSaved=true;  
  440.       }
  441.     oForm.onsubmit = new Function("return onsubmit_new()");
  442.     }
  443.  
  444.   var sContent=document.getElementById(idTextArea).value;
  445.   sContent=sContent.replace(/&/g,"&amp;");
  446.   sContent=sContent.replace(/</g,"&lt;");
  447.   sContent=sContent.replace(/>/g,"&gt;");
  448.  
  449.   this.RENDER(sContent, dvId);
  450.   }
  451. function onsubmit_new()
  452.   {
  453.   var sContent;
  454.   for(var i=0;i<oUtil.arrEditor.length;i++)
  455.     {
  456.     var oEdit=eval(oUtil.arrEditor[i]);
  457.     if(oEdit.mode=="HTMLBody")sContent=oEdit.getHTMLBody();
  458.     if(oEdit.mode=="HTML")sContent=oEdit.getHTML();
  459.     if(oEdit.mode=="XHTMLBody")sContent=oEdit.getXHTMLBody();
  460.     if(oEdit.mode=="XHTML")sContent=oEdit.getXHTML();
  461.     document.getElementById(oEdit.idTextArea).value=sContent;
  462.     }
  463.   if(onsubmit_original)return onsubmit_original();
  464.   }
  465. function onsubmit_original(){}
  466.  
  467. function RENDER(sPreloadHTML, dvId)
  468.     {
  469.   /*** icons related ***/
  470.   iconHeight=this.iconHeight;
  471.  
  472.     /*** Tetap Ada (For downgrade compatibility) ***/    
  473.     if(sPreloadHTML.substring(0,4)=="<!--" &&
  474.   sPreloadHTML.substring(sPreloadHTML.length-3)=="-->")
  475.   sPreloadHTML=sPreloadHTML.substring(4,sPreloadHTML.length-3);
  476.  
  477.   if(sPreloadHTML.substring(0,4)=="<!--" &&
  478.   sPreloadHTML.substring(sPreloadHTML.length-6)=="--&gt;")
  479.   sPreloadHTML=sPreloadHTML.substring(4,sPreloadHTML.length-6);
  480.  
  481.   /*** Converting back HTML-encoded content (kalau tdk encoded tdk masalah) ***/  
  482.   sPreloadHTML=sPreloadHTML.replace(/&lt;/g,"<");
  483.   sPreloadHTML=sPreloadHTML.replace(/&gt;/g,">");
  484.   sPreloadHTML=sPreloadHTML.replace(/&amp;/g,"&");
  485.  
  486.   /*** enable required buttons ***/
  487.   if(this.cmdContentBlock!=";")this.btnContentBlock=true;
  488.   if(this.cmdInternalLink!=";")this.btnInternalLink=true;
  489.   if(this.cmdInternalImage!=";")this.btnInternalImage=true;
  490.   if(this.cmdCustomObject!=";")this.btnCustomObject=true;
  491.   if(this.arrCustomTag.length>0)this.btnCustomTag=true;
  492.   if(this.mode=="HTMLBody"){this.btnXHTMLSource=true;this.btnXHTMLFullSource=false;}
  493.   if(this.mode=="HTML"){this.btnXHTMLFullSource=true;this.btnXHTMLSource=false;}
  494.   if(this.mode=="XHTMLBody"){this.btnXHTMLSource=true;this.btnXHTMLFullSource=false;}
  495.   if(this.mode=="XHTML"){this.btnXHTMLFullSource=true;this.btnXHTMLSource=false;}
  496.  
  497.     /*** features ***/
  498.     var bUseFeature=false;
  499.     if(this.features.length>0)
  500.         {
  501.         bUseFeature=true;
  502.         for(var i=0;i<this.buttonMap.length;i++)
  503.             eval(this.oName+".btn"+this.buttonMap[i]+"=true");//ex: oEdit1.btnStyleAndFormatting=true (no problem), oEdit1.btn|=true (no problem), oEdit1.btnBRK=true (no problem)
  504.  
  505.         this.btnTextFormatting=false;this.btnListFormatting=false;
  506.         this.btnBoxFormatting=false;this.btnParagraphFormatting=false;
  507.         this.btnCssText=false;this.btnCssBuilder=false;
  508.         for(var j=0;j<this.features.length;j++)
  509.             eval(this.oName+".btn"+this.features[j]+"=true");//ex: oEdit1.btnTextFormatting=true
  510.  
  511.         for(var i=0;i<this.buttonMap.length;i++)
  512.             {
  513.             sButtonName=this.buttonMap[i];          
  514.             bBtnExists=false;
  515.             for(var j=0;j<this.features.length;j++)
  516.                 if(sButtonName==this.features[j])bBtnExists=true;//ada;
  517.  
  518.             if(!bBtnExists)//tdk ada; set false
  519.                 eval(this.oName+".btn"+sButtonName+"=false");//ex: oEdit1.btnBold=false, oEdit1.btn|=false (no problem), oEdit1.btnBRK=false (no problem)
  520.             }
  521.         //Remove:"TextFormatting","ListFormatting",dst.=>tdk perlu(krn diabaikan)
  522.         this.buttonMap=this.features;
  523.         }
  524.     /*** /features ***/
  525.  
  526.     this.preloadHTML=sPreloadHTML;
  527.  
  528.     var sHTMLDropMenus="";
  529.     var sHTMLIcons="";
  530.     var sTmp="";
  531.  
  532.     //Render Color Picker (forecolor)
  533.     this.oColor1.url=this.scriptPath+"color_picker_fg.htm";
  534.     this.oColor1.onShow = new Function(this.oName+".hide()");
  535.     this.oColor1.onMoreColor = new Function(this.oName+".hide()");
  536.     this.oColor1.onPickColor = new Function(this.oName+".applyColor('ForeColor', "+this.oName+".oColor1.color)");
  537.     this.oColor1.onRemoveColor = new Function(this.oName+".applyColor('ForeColor','')");
  538.     this.oColor1.txtCustomColors=getTxt("Custom Colors");
  539.     this.oColor1.txtMoreColors=getTxt("More Colors...");
  540.    
  541.     //Render Color Picker (backcolor)
  542.     this.oColor2.url=this.scriptPath+"color_picker_bg.htm";
  543.     this.oColor2.onShow = new Function(this.oName+".hide()");
  544.     this.oColor2.onMoreColor = new Function(this.oName+".hide()");
  545.     this.oColor2.onPickColor = new Function(this.oName+".applyColor('hilitecolor', "+this.oName+".oColor2.color)");
  546.     this.oColor2.onRemoveColor = new Function(this.oName+".applyColor('HiliteColor','')");
  547.     this.oColor2.txtCustomColors=getTxt("Custom Colors");
  548.     this.oColor2.txtMoreColors=getTxt("More Colors...");
  549.    
  550.     var me=this;
  551.  
  552.     if(this.tabs) {
  553.       var tmp=null, tmpTb, grpMap=new Object();
  554.       //create toolbar.
  555.       for (var i=0;i<this.buttonMap.length;i++) {
  556.         eval(this.oName+".btn"+this.buttonMap[i]+"=false");
  557.       }
  558.       for (var i=0; i<this.groups.length;i++) {
  559.         tmp=this.groups[i];
  560.         tmpTb=this.tbar.createToolbar(this.oName+"tbar"+tmp[0]);
  561.         tmpTb.onClick=function(id) {tbAction(tmpTb, id, me, me.oName);};
  562.         tmpTb.style.toolbar="main_istoolbar";
  563.         tmpTb.iconPath=this.scriptPath.substring(0, this.scriptPath.indexOf("moz/"))+this.iconPath;
  564.         tmpTb.btnWidth=this.iconWidth;
  565.         tmpTb.btnHeight=this.iconHeight;
  566.         for (var j=0;j<tmp[2].length;j++) {
  567.           eval(this.oName+".btn"+tmp[2][j]+"=true");
  568.         }
  569.         buildToolbar(tmpTb, this, tmp[2]);
  570.         grpMap[tmp[0]]=tmp[1];
  571.       }
  572.  
  573.       //create tab
  574.       var eTab=this.tbar.createTbTab("tabCtl"+this.oName), tmpGrp;
  575.       for(var i=0; i<this.tabs.length; i++) {
  576.         tmp=this.tabs[i];
  577.         tmpGrp=this.tbar.createTbGroup(this.oName+"grp"+tmp[0]);
  578.         for (var j=0; j<tmp[2].length;j++) {
  579.           tmpGrp.addGroup(this.oName+tmp[2][j], grpMap[tmp[2][j]] , this.oName+"tbar"+tmp[2][j]);
  580.         }
  581.         eTab.addTab(this.oName+tmp[0], tmp[1], tmpGrp);
  582.       }
  583.  
  584.     } else {
  585.       var orTb=this.tbar.createToolbar(this.oName);  
  586.         orTb.onClick=function(id) {tbAction(orTb, id, me, me.oName);};
  587.         //orTb.style.toolbar="main_istoolbar";
  588.         orTb.iconPath=this.scriptPath.substring(0, this.scriptPath.indexOf("moz/"))+this.iconPath;
  589.         orTb.btnWidth=this.iconWidth;
  590.         orTb.btnHeight=this.iconHeight;
  591.         buildToolbar(orTb, this, this.buttonMap);
  592.     }
  593.  
  594.     var sHTML="";
  595.     var icPath=this.scriptPath.substring(0, this.scriptPath.indexOf("moz/"))+this.iconPath;    
  596.  
  597.     if(!document.getElementById("id_refresh_z_index"))
  598.         sHTML+="<div id=id_refresh_z_index style='margin:0px'></div>";
  599.  
  600.     sHTML+="<table id=idArea"+this.oName+" name=idArea"+this.oName+" border='0px' "+
  601.             "cellpadding=0 cellspacing=0 width='"+this.width+"' height='"+this.height+"'>"+
  602.             "<tr><td colspan=2 style=\"padding:0px;padding-left:1px;border:#cfcfcf 0px solid;background:url('"+icPath+"bg.gif')\">"+
  603.             "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td dir=ltr style='padding:0px;'>"+
  604.             this.tbar.render()+
  605.             "</td></tr></table>"+
  606.             "</td></tr>"+
  607.             "<tr id=idTagSelTopRow"+this.oName+"><td colspan=2 id=idTagSelTop"+this.oName+" height=0px style='padding:0px;'></td></tr>";
  608.  
  609.  
  610.     sHTML+="<tr style='width:100%;height:100%'><td colspan=2 valign=top height=100% style='padding:0px;background:white;padding-right:2px'>";
  611.    
  612.     sHTML+="<table id='cntContainer"+this.oName+"' cellpadding=0 cellspacing=0 width=100% height=100%><tr style='width:100%;height:100%'><td width='100%' height='100%' style='padding:0px;'>";//StyleSelect
  613.  
  614.     sHTML+="<iframe style='width:100%;height:100%; margin-top:1px;border:solid 1px #cfcfcf' "+
  615.             " name=idContent"+ this.oName + " id=idContent"+this.oName+ "></iframe>";
  616.  
  617.     sHTML+="<iframe style='width:1px;height:1px;overflow:auto;border:0px' id=\"myStyle"+this.oName+"\" name=\"myStyle"+this.oName+"\" src='"+this.scriptPath+"blank.gif'></iframe>";
  618.  
  619.     sHTML+="</td><td id=idStyles"+this.oName+" style='padding:0px;background:#E9E8F2'></td></tr></table>"//StyleSelect
  620.  
  621.     sHTML+="</td></tr>";
  622.     sHTML+="<tr id=idTagSelBottomRow"+this.oName+"><td colspan=2 id=idTagSelBottom"+this.oName+" style='padding:0px;'></td></tr>";
  623.     sHTML+="</table>";
  624.  
  625.     sHTML+=sHTMLDropMenus;//dropdown
  626.    
  627.     sHTML+="<input type=submit name=iwe_btnSubmit"+this.oName+" id=iwe_btnSubmit"+this.oName+" value=SUBMIT style='display:none' >";//hidden submit button
  628.  
  629.     if(dvId) {
  630.       var edtStr=[];
  631.       edtStr[0]=sHTML;
  632.       document.getElementById(dvId).innerHTML=edtStr.join("");
  633.     } else {
  634.       //document.write(sHTML);
  635.           document.getElementById("loadedit").innerHTML=sHTML;
  636.     }
  637.        
  638.     var clPick=document.getElementById("isClPiker"+this.oName);
  639.     if(!clPick) {
  640.       clPick = document.createElement("DIV");
  641.       clPick.id="isClPiker"+this.oName;
  642.       clPick.innerHTML=this.oColor1.generateHTML() + this.oColor2.generateHTML();
  643.       document.body.insertBefore(clPick, document.body.childNodes[0]);
  644.     }
  645.    
  646.  
  647.     this.init();
  648.  
  649.     }
  650.  
  651. function initISEditor() {
  652.  
  653.     if(this.useTagSelector)
  654.         {
  655.         if(this.TagSelectorPosition=="bottom")this.TagSelectorPosition="top";
  656.         else this.TagSelectorPosition="bottom";
  657.         this.moveTagSelector()
  658.         }
  659.  
  660.     var oEditor = document.getElementById("idContent"+this.oName).contentWindow;
  661.  
  662.     oUtil.oName=this.oName;//default active editor
  663.     oUtil.oEditor=oEditor;
  664.     oUtil.obj=this;
  665.  
  666.     oUtil.arrEditor.push(this.oName);
  667.  
  668.     try { oEditor.document.designMode="on"; } catch(e) {}
  669.  
  670.     var arrA = String(this.preloadHTML).match(/<HTML[^>]*>/ig);
  671.     if(arrA)
  672.         {//full html
  673.           this.loadHTMLFull(this.preloadHTML);
  674.         }
  675.     else
  676.         {
  677.         this.loadHTML(this.preloadHTML);
  678.         }
  679.  
  680.     /***** Replace current body onload ******/
  681.     if(!oUtil.bOnLoadReplaced)
  682.       {
  683.       if(window.onload)onload_original=window.onload;
  684.       window.onload = new Function("onload_new()");
  685.       oUtil.bOnLoadReplaced=true;
  686.       }
  687.     /****************************************/
  688.  
  689.     this.focus();
  690.    
  691.     try {
  692.       var cnt = oEditor.document.body.innerHTML;
  693.       cnt = cnt.replace(/\s+/gi, "");
  694.       if(cnt=="") {
  695.         oEditor.document.body.innerHTML="<br class=\"innova\" />";
  696.       }
  697.      
  698.       var range = oEditor.document.createRange();
  699.       range.selectNode(oEditor.document.body.childNodes[0]);
  700.       range.collapse(true);
  701.      
  702.       var sel = oEditor.getSelection();
  703.       sel.removeAllRanges();
  704.       sel.addRange(range);      
  705.      
  706.     } catch (e) {}
  707.    
  708.     this.focus();
  709. }
  710.  
  711. function buildToolbar(tb, oEdt, btnMap) {
  712.   var oName=oEdt.oName;
  713.  
  714.   for(var i=0;i<btnMap.length;i++)
  715.     {
  716.     sButtonName=btnMap[i];
  717.     switch(sButtonName)
  718.       {
  719.       case "|":
  720.           tb.addSeparator();
  721.           break;
  722.       case "BRK":
  723.           tb.addBreak();
  724.           break;
  725.       case "Save":
  726.           if(oEdt.btnSave)tb.addButton("btnSave"+oName, "btnSave.gif", getTxt("Save"));
  727.           break;
  728.       case "Preview":
  729.           if(oEdt.btnPreview) {
  730.             tb.addDropdownButton("btnPreview"+oName, "ddPreview"+oName, "btnPreview.gif",getTxt("Preview"));
  731.             var pvDD=new ISDropdown("ddPreview"+oName);
  732.             pvDD.addItem("btnPreview1"+oName, "640x480");
  733.             pvDD.addItem("btnPreview2"+oName, "800x600");
  734.             pvDD.addItem("btnPreview3"+oName, "1024x768");
  735.             pvDD.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  736.           }
  737.           break;
  738.       case "FullScreen":
  739.           if(oEdt.btnFullScreen)tb.addButton("btnFullScreen"+oName, "btnFullScreen.gif",getTxt("Full Screen"));
  740.           break;
  741.       case "Print":
  742.           if(oEdt.btnPrint)tb.addButton("btnPrint"+oName,"btnPrint.gif",getTxt("Print"));
  743.           break;
  744.       case "Search":
  745.         if(oEdt.btnSearch)tb.addButton("btnSearch"+oName,"btnSearch.gif",getTxt("Search"));
  746.         break;
  747.       case "SpellCheck":
  748.         if(oEdt.btnSpellCheck)
  749.           {
  750.           if (oEdt.spellCheckMode!="ieSpell") tb.addButton("btnSpellCheck"+oName, "btnSpellCheck.gif",getTxt("Check Spelling"));
  751.           }
  752.         break;
  753.       case "StyleAndFormatting":
  754.         if(oEdt.btnTextFormatting||oEdt.btnParagraphFormatting||oEdt.btnListFormatting||oEdt.btnBoxFormatting||oEdt.btnCssText||oEdt.btnCssBuilder) {
  755.           tb.addDropdownButton("btnStyleAndFormat"+oName, "ddFormatting"+oName, "btnStyle.gif",getTxt("Styles & Formatting"));
  756.           var ddFmt=new ISDropdown("ddFormatting"+oName);
  757.           ddFmt.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  758.           if(oEdt.btnTextFormatting) ddFmt.addItem("btnTextFormatting"+oName, getTxt("Text Formatting"));
  759.           if(oEdt.btnParagraphFormatting) ddFmt.addItem("btnParagraphFormatting"+oName, getTxt("Paragraph Formatting"));
  760.           if(oEdt.btnListFormatting) ddFmt.addItem("btnListFormatting"+oName, getTxt("List Formatting"));
  761.           if(oEdt.btnBoxFormatting) ddFmt.addItem("btnBoxFormatting"+oName, getTxt("Box Formatting"));
  762.           if(oEdt.btnCssText) ddFmt.addItem("btnCssText"+oName, getTxt("Custom CSS"));
  763.           if(oEdt.btnCssBuilder) ddFmt.addItem("btnCssBuilder"+oName, getTxt("CSS Builder"));
  764.         }
  765.         break;
  766.       case "Styles":
  767.         if(oEdt.btnStyles)tb.addButton("btnStyles"+oName,"btnStyleSelect.gif",getTxt("Style Selection"));
  768.         break;
  769.       case "Paragraph":
  770.         if(oEdt.btnParagraph)
  771.           {
  772.           tb.addDropdownButton("btnParagraph"+oName,"ddParagraph"+oName, oUtil.langDir+"/btnParagraph.gif",getTxt("Paragraph"), 77);
  773.           var ddPar=new ISDropdown("ddParagraph"+oName);
  774.           ddPar.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  775.           for(var j=0;j<oEdt.arrParagraph.length;j++)
  776.             {
  777.             ddPar.addItem("btnParagraph_"+j+oName,
  778.               "<"+oEdt.arrParagraph[j][1]+" style=\"\margin-bottom:4px\"  unselectable=on> "+
  779.               oEdt.arrParagraph[j][0]+"</"+oEdt.arrParagraph[j][1]+">");
  780.             }
  781.           }
  782.         break;
  783.       case "FontName":
  784.         if(oEdt.btnFontName)
  785.           {
  786.           tb.addDropdownButton("btnFontName"+oName,"ddFontName"+oName,oUtil.langDir+"/btnFontName.gif",getTxt("Font Name"),77);
  787.           var ddFont=new ISDropdown("ddFontName"+oName);
  788.           ddFont.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  789.           for(var j=0;j<oEdt.arrFontName.length;j++)
  790.             {
  791.             ddFont.addItem("btnFontName_"+j+oName, "<span style='font-family:"+oEdt.arrFontName[j]+"' unselectable=on>"+oEdt.arrFontName[j]+"</span><span unselectable=on style='font-family:tahoma'>("+ oEdt.arrFontName[j] +")</span>");
  792.             }
  793.           }
  794.         break;
  795.       case "FontSize":
  796.         if(oEdt.btnFontSize)
  797.           {
  798.           tb.addDropdownButton("btnFontSize"+oName,"ddFontSize"+oName,oUtil.langDir+"/btnFontSize.gif",getTxt("Font Size"),60);
  799.           var ddFs=new ISDropdown("ddFontSize"+oName);
  800.           ddFs.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  801.           for(var j=0;j<oEdt.arrFontSize.length;j++)
  802.             {
  803.             ddFs.addItem("btnFontSize_"+j+oName,
  804.               "<font unselectable=on size=\""+oEdt.arrFontSize[j][1]+"\">"+
  805.               oEdt.arrFontSize[j][0]+"</font>");
  806.             }
  807.           }
  808.         break;
  809.       case "Undo":
  810.         if(oEdt.btnUndo)tb.addButton("btnUndo"+oName,"btnUndo.gif",getTxt("Undo"));
  811.         break;
  812.       case "Redo":
  813.         if(oEdt.btnRedo)tb.addButton("btnRedo"+oName,"btnRedo.gif",getTxt("Redo"));
  814.         break;
  815.           case "Unlink":
  816.           if(oEdt.btnUnlink)tb.addButton("btnUnlink"+oName,"btnUnlink.gif",getTxt("Unlink"));
  817.           break;
  818.       case "PasteWord":
  819.         if(oEdt.btnPasteWord)tb.addButton("btnPasteWord"+oName,"btnPasteWord.gif",getTxt("Paste from Word"));
  820.         break;
  821.       case "PasteText":
  822.         if(oEdt.btnPasteText)tb.addButton("btnPasteText"+oName,"btnPasteText.gif",getTxt("Paste Text"));
  823.         break;
  824.       case "Bold":
  825.         if(oEdt.btnBold)tb.addToggleButton("btnBold"+oName,"",false,"btnBold.gif",getTxt("Bold"));
  826.         break;
  827.       case "Italic":
  828.         if(oEdt.btnItalic)tb.addToggleButton("btnItalic"+oName,"",false,"btnItalic.gif",getTxt("Italic"));
  829.         break;
  830.       case "Underline":
  831.         if(oEdt.btnUnderline)tb.addToggleButton("btnUnderline"+oName,"",false,"btnUnderline.gif",getTxt("Underline"));
  832.         break;
  833.       case "Strikethrough":    
  834.         if(oEdt.btnStrikethrough)tb.addToggleButton("btnStrikethrough"+oName,"",false,"btnStrikethrough.gif",getTxt("Strikethrough"));
  835.         break;
  836.       case "Superscript":
  837.         if(oEdt.btnSuperscript)tb.addToggleButton("btnSuperscript"+oName,"",false,"btnSuperscript.gif",getTxt("Superscript"));
  838.         break;
  839.       case "Subscript":
  840.         if(oEdt.btnSubscript)tb.addToggleButton("btnSubscript"+oName,"",false,"btnSubscript.gif",getTxt("Subscript"));
  841.         break;
  842.       case "JustifyLeft":
  843.         if(oEdt.btnJustifyLeft)tb.addToggleButton("btnJustifyLeft"+oName,"align",false,"btnLeft.gif",getTxt("Justify Left"));
  844.         break;
  845.       case "JustifyCenter":
  846.         if(oEdt.btnJustifyCenter)tb.addToggleButton("btnJustifyCenter"+oName,"align",false,"btnCenter.gif",getTxt("Justify Center"));
  847.         break;
  848.       case "JustifyRight":
  849.         if(oEdt.btnJustifyRight)tb.addToggleButton("btnJustifyRight"+oName,"align",false,"btnRight.gif",getTxt("Justify Right"));
  850.         break;
  851.       case "JustifyFull":
  852.         if(oEdt.btnJustifyFull)tb.addToggleButton("btnJustifyFull"+oName,"align",false,"btnFull.gif",getTxt("Justify Full"));
  853.         break;
  854.       case "Numbering":
  855.         if(oEdt.btnNumbering)tb.addToggleButton("btnNumbering"+oName,"bullet",false,"btnNumber.gif",getTxt("Numbering"));
  856.         break;
  857.       case "Bullets":
  858.         if(oEdt.btnBullets)tb.addToggleButton("btnBullets"+oName,"bullet",false,"btnList.gif",getTxt("Bullets"));
  859.         break;
  860.       case "Indent":
  861.         if(oEdt.btnIndent)tb.addButton("btnIndent"+oName,"btnIndent.gif",getTxt("Indent"));
  862.         break;
  863.       case "Outdent":
  864.         if(oEdt.btnOutdent)tb.addButton("btnOutdent"+oName,"btnOutdent.gif",getTxt("Outdent"));
  865.         break;
  866.       case "LTR":
  867.         if(oEdt.btnLTR)tb.addToggleButton("btnLTR"+oName,"dir",false,"btnLTR.gif",getTxt("Left To Right"));
  868.         break;
  869.       case "RTL":
  870.         if(oEdt.btnRTL)tb.addToggleButton("btnRTL"+oName,"dir",false,"btnRTL.gif",getTxt("Right To Left"));
  871.         break;
  872.       case "ForeColor":
  873.         if(oEdt.btnForeColor)tb.addButton("btnForeColor"+oName,"btnForeColor.gif",getTxt("Foreground Color"));
  874.         break;
  875.       case "BackColor":
  876.         if(oEdt.btnBackColor)tb.addButton("btnBackColor"+oName,"btnBackColor.gif",getTxt("Background Color"));
  877.         break;
  878.       case "Bookmark":
  879.         if(oEdt.btnBookmark)tb.addButton("btnBookmark"+oName,"btnBookmark.gif",getTxt("Bookmark"));
  880.         break;
  881.       case "Hyperlink":
  882.         if(oEdt.btnHyperlink)tb.addButton("btnHyperlink"+oName,"btnHyperlink.gif",getTxt("Hyperlink"));
  883.         break;
  884.       case "CustomTag":
  885.         if(oEdt.btnCustomTag)
  886.           {
  887.           tb.addDropdownButton("btnCustomTag"+oName,"ddCustomTag"+oName,oUtil.langDir+"/btnCustomTag.gif",getTxt("Tags"),60);
  888.           var ddCustomTag=new ISDropdown("ddCustomTag"+oName);
  889.           ddCustomTag.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  890.           for(var j=0;j<oEdt.arrCustomTag.length;j++)
  891.             {
  892.               ddCustomTag.addItem("btnCustomTag_"+j+oName, oEdt.arrCustomTag[j][0]);
  893.             }
  894.           }
  895.         break;
  896.       case "Image":
  897.         if(oEdt.btnImage)tb.addButton("btnImage"+oName,"btnImage.gif",getTxt("Image"));
  898.         break;
  899.       case "Flash":
  900.         if(oEdt.btnFlash)tb.addButton("btnFlash"+oName,"btnFlash.gif",getTxt("Flash"));
  901.         break;
  902.       case "Media":
  903.         if(oEdt.btnMedia)tb.addButton("btnMedia"+oName,"btnMedia.gif",getTxt("Media"));
  904.         break;
  905.        
  906.       case "ContentBlock":
  907.         if(oEdt.btnContentBlock)tb.addButton("btnContentBlock"+oName,"btnContentBlock.gif",getTxt("Content Block"));
  908.         break;
  909.       case "InternalLink":
  910.         if(oEdt.btnInternalLink)tb.addButton("btnInternalLink"+oName,"btnInternalLink.gif",getTxt("Internal Link"));
  911.         break;
  912.       case "InternalImage":
  913.         if(oEdt.btnInternalImage)tb.addButton("btnInternalImage"+oName,"btnInternalImage.gif",getTxt("Internal Image"));
  914.         break;
  915.       case "CustomObject":
  916.         if(oEdt.btnCustomObject)tb.addButton("btnCustomObject"+oName,"btnCustomObject.gif",getTxt("Object"));
  917.         break;
  918.       case "Table":
  919.         if(oEdt.btnTable)
  920.           {
  921.           var sdd=[], sZ=0;
  922.           sdd[sZ++]="<table width='175' id='dropTableCreate"+oName+"' style='cursor:default;background:#f3f3f8;' cellpadding=0 cellspacing=1 unselectable=on>";
  923.           for(var m=0;m<8;m++)
  924.             {
  925.             sdd[sZ++]="<tr>";
  926.             for(var n=0;n<8;n++)
  927.               {
  928.               sdd[sZ++]="<td onclick='"+oName+".doClick_TabCreate(this)' onmouseover='doOver_TabCreate(this);event.cancelBubble=true;' style='background:#ffffff;font-size:1px;border:#d3d3d3 1px solid;width:20px;height:20px;' unselectable=on>&nbsp;</td>";
  929.               }
  930.             sdd[sZ++]="</tr>";
  931.             }
  932.           sdd[sZ++]="<tr><td colspan=8 onclick=\""+oName+".hide();modelessDialogShow('"+oEdt.scriptPath+"table_insert.htm',380,270);\" onmouseover=\"doOut_TabCreate(document.getElementById('dropTableCreate"+oName+"'));this.innerHTML='"+getTxt("Advanced Table Insert")+"';this.style.border='#777777 1px solid';this.style.backgroundColor='#8d9aa7';this.style.color='#ffffff'\" onmouseout=\"this.style.border='#f3f3f8 1px solid';this.style.backgroundColor='#f3f3f8';this.style.color='#000000'\" align=center style='font-family:verdana;font-size:10px;color:#000000;border:#f3f3f8 1px solid;padding:1px 1px 1px 1px' unselectable=on>"+getTxt("Advanced Table Insert")+"</td></tr>";
  933.           sdd[sZ++]="</table>";
  934.          
  935.           tb.addDropdownButton("btnTable"+oName,"ddTable"+oName,"btnTable.gif",getTxt("Insert Table"));
  936.           var ddTable=new ISDropdown("ddTable"+oName);
  937.           ddTable.add(new ISCustomDDItem("btnInsertTable", sdd.join("")));
  938.                    
  939.           tb.addDropdownButton("btnTableEdit"+oName,"ddTableEdit"+oName,"btnTableEdit.gif",getTxt("Edit Table/Cell"));
  940.           var ddTblEdit=new ISDropdown("ddTableEdit"+oName);
  941.           ddTblEdit.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  942.           ddTblEdit.addItem("mnuTableSize"+oName, getTxt("Table Size"));
  943.           ddTblEdit.addItem("mnuTableEdit"+oName, getTxt("Edit Table"));
  944.           ddTblEdit.addItem("mnuCellEdit"+oName, getTxt("Edit Cell"));
  945.           }
  946.         break;
  947.       case "Absolute":
  948.         if(oEdt.btnAbsolute)tb.addButton("btnAbsolute"+oName,"btnAbsolute.gif",getTxt("Absolute"));
  949.         break;
  950.       case "Characters":
  951.         if(oEdt.btnCharacters)tb.addButton("btnCharacters"+oName,"btnSymbol.gif",getTxt("Special Characters"));
  952.         break;
  953.       case "Line":
  954.         if(oEdt.btnLine)tb.addButton("btnLine"+oName,"btnLine.gif",getTxt("Line"));
  955.         break;
  956.       case "Form":
  957.         if(oEdt.btnForm)
  958.           {
  959.           var arrFormMenu = [[getTxt("Form"),"form_form.htm","280","177"],
  960.             [getTxt("Text Field"),"form_text.htm","285","289"],
  961.             [getTxt("List"),"form_list.htm","295","332"],
  962.             [getTxt("Checkbox"),"form_check.htm","235","174"],
  963.             [getTxt("Radio Button"),"form_radio.htm","235","177"],
  964.             [getTxt("Hidden Field"),"form_hidden.htm","235","152"],
  965.             [getTxt("File Field"),"form_file.htm","235","132"],
  966.             [getTxt("Button"),"form_button.htm","235","174"]];
  967.          
  968.           tb.addDropdownButton("btnForm"+oName, "ddForm"+oName, "btnForm.gif",getTxt("Form Editor"));
  969.           var ddForm=new ISDropdown("ddForm"+oName);
  970.           ddForm.onClick=function(id) {ddAction(tb, id, oEdt, oEdt.oName)};
  971.           for(var j=0;j<arrFormMenu.length;j++)
  972.             {
  973.               ddForm.addItem("btnForm"+j+oName, arrFormMenu[j][0]);
  974.             }
  975.           }
  976.         break;
  977.  
  978.       case "RemoveFormat":
  979.         if(oEdt.btnRemoveFormat)tb.addButton("btnRemoveFormat"+oName,"btnRemoveFormat.gif",getTxt("Remove Formatting"));
  980.         break;
  981.       case "HTMLFullSource":
  982.         if(oEdt.btnHTMLFullSource)tb.addButton("btnHTMLFullSource"+oName,"btnSource.gif",getTxt("View/Edit Source"));
  983.         break;
  984.       case "HTMLSource":
  985.         if(oEdt.btnHTMLSource)tb.addButton("btnHTMLSource"+oName,"btnSource.gif",getTxt("View/Edit Source"));
  986.         break;
  987.       case "XHTMLFullSource":
  988.         if(oEdt.btnXHTMLFullSource)tb.addButton("btnXHTMLFullSource"+oName,"btnSource.gif",getTxt("View/Edit Source"));
  989.         break;
  990.       case "XHTMLSource":
  991.         if(oEdt.btnXHTMLSource)tb.addButton("btnXHTMLSource"+oName,"btnSource.gif",getTxt("View/Edit Source"));
  992.         break;
  993.       case "ClearAll":
  994.         if(oEdt.btnClearAll)tb.addButton("btnClearAll"+oName,"btnDelete.gif",getTxt("Clear All"));
  995.         break;
  996.       default:
  997.         for(j=0;j<oEdt.arrCustomButtons.length;j++)
  998.           {
  999.           if(sButtonName==oEdt.arrCustomButtons[j][0])
  1000.             {
  1001.             sCbName=oEdt.arrCustomButtons[j][0];
  1002.             //sCbCommand=oEdt.arrCustomButtons[j][1];
  1003.             sCbCaption=oEdt.arrCustomButtons[j][2];
  1004.             sCbImage=oEdt.arrCustomButtons[j][3];
  1005.             if(oEdt.arrCustomButtons[j][4])
  1006.               tb.addButton(sCbName+oName,sCbImage,sCbCaption,oEdt.arrCustomButtons[j][4]);
  1007.             else
  1008.               tb.addButton(sCbName+oName,sCbImage,sCbCaption);
  1009.             }
  1010.           }
  1011.         break;
  1012.        
  1013.       }
  1014.     }
  1015. }
  1016.  
  1017.  
  1018. function iwe_getElm(s)
  1019.   {
  1020.   return document.getElementById(s+this.oName)
  1021.   }
  1022.  
  1023. /*** Replace current body onload ***/
  1024. function onload_new()
  1025.   {
  1026.   onload_original();  
  1027.   //alert("setEdit here");
  1028.   //oUtil.setEdit();
  1029.   }
  1030. function onload_original()
  1031.   {
  1032.   }
  1033.  
  1034. /*** Color Picker Object ***/
  1035. var arrColorPickerObjects=[];
  1036. function ColorPicker(sName,sParent)
  1037.     {
  1038.     this.oParent=sParent;
  1039.     if(sParent)
  1040.         {
  1041.         this.oName=sParent+"."+sName;
  1042.         this.oRenderName=sName+sParent;
  1043.         }
  1044.     else
  1045.         {
  1046.         this.oName=sName;
  1047.         this.oRenderName=sName;
  1048.         }
  1049.     arrColorPickerObjects.push(this.oName);
  1050.  
  1051.     this.url="color_picker.htm";
  1052.     this.onShow=function(){return true;};
  1053.     this.onHide=function(){return true;};
  1054.     this.onPickColor=function(){return true;};
  1055.     this.onRemoveColor=function(){return true;};
  1056.     this.onMoreColor=function(){return true;};  
  1057.     this.show=showColorPicker;
  1058.     this.hide=hideColorPicker;
  1059.     this.hideAll=hideColorPickerAll;
  1060.     this.color;
  1061.     this.customColors=[];
  1062.     this.refreshCustomColor=refreshCustomColor;
  1063.     this.isActive=false;
  1064.     this.txtCustomColors="Custom Colors";
  1065.     this.txtMoreColors="More Colors...";
  1066.     this.align="left";
  1067.     this.currColor="#ffffff";//default current color
  1068.     this.generateHTML=generateHTML;
  1069.     this.RENDER=drawColorPicker;
  1070.     }
  1071. function generateHTML()
  1072.   {
  1073.     var arrColors=[["#800000","#8b4513","#006400","#2f4f4f","#000080","#4b0082","#800080","#000000"],
  1074.                 ["#ff0000","#daa520","#6b8e23","#708090","#0000cd","#483d8b","#c71585","#696969"],
  1075.                 ["#ff4500","#ffa500","#808000","#4682b4","#1e90ff","#9400d3","#ff1493","#a9a9a9"],
  1076.                 ["#ff6347","#ffff00","#32cd32","#87ceeb","#00bfff","#9370db","#ff69b4","#dcdcdc"],
  1077.                 ["#ffdab9","#ffffe0","#98fb98","#e0ffff","#87cefa","#e6e6fa","#dda0dd","#ffffff"]];
  1078.     var sHTMLColor="<table id=dropColor"+this.oRenderName+" style=\"z-index:1;display:none;position:absolute;border:#9b95a6 1px solid;cursor:default;background-color:#E9E8F2;padding:2px\" unselectable=on cellpadding=0 cellspacing=0 width=145px><tr><td unselectable=on style='padding:0px;'>";
  1079.     sHTMLColor+="<table align=center cellpadding=0 cellspacing=0 border=0 unselectable=on>";
  1080.     for(var i=0;i<arrColors.length;i++)
  1081.         {
  1082.         sHTMLColor+="<tr>";
  1083.         for(var j=0;j<arrColors[i].length;j++)
  1084.             sHTMLColor+="<td onclick=\""+this.oName+".color='"+arrColors[i][j]+"';"+this.oName+".onPickColor();"+this.oName+".currColor='"+arrColors[i][j]+"';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#E9E8F2 1px solid'\" style=\"padding:0px;cursor:default;padding:1px;border:#E9E8F2 1px solid;\" unselectable=on>"+
  1085.                 "<table style='margin:0px;width:13px;height:13px;background:"+arrColors[i][j]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
  1086.                 "<tr><td unselectable=on style='padding:0px;'></td></tr>"+
  1087.                 "</table></td>";
  1088.         sHTMLColor+="</tr>";        
  1089.         }
  1090.    
  1091.     //~~~ custom colors ~~~~
  1092.     sHTMLColor+="<tr><td colspan=8 id=idCustomColor"+this.oRenderName+" style='padding:0px;'></td></tr>";
  1093.    
  1094.     //~~~ remove color & more colors ~~~~
  1095.     sHTMLColor+= "<tr>";
  1096.     sHTMLColor+= "<td unselectable=on style='padding:0px;'>"+
  1097.         "<table style='padding:0px;margin-left:1px;width:14px;height:14px;background:#E9E8F2;' cellpadding=0 cellspacing=0 unselectable=on>"+
  1098.         "<tr><td onclick=\""+this.oName+".onRemoveColor();"+this.oName+".currColor='';"+this.oName+".hideAll()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='white 1px solid'\" style=\"cursor:default;padding:1px;border:white 1px solid;font-family:verdana;font-size:10px;color:#000000;line-height:9px;\" align=center valign=top unselectable=on>x</td></tr>"+
  1099.         "</table></td>";
  1100.     sHTMLColor+= "<td colspan=7 unselectable=on style='padding:0px;'>"+
  1101.         "<table style='padding:0px;margin:1px;width:117px;height:16px;background:#E9E8F2;border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
  1102.         "<tr><td id=\""+this.oName+"moreColTd\" onclick=\""+this.oName+".onMoreColor();"+this.oName+".hideAll();modalDialogShow('"+this.url+"?" +this.oName+ "', 442, 380)\" onmouseover=\"this.style.border='#777777 1px solid';this.style.background='#8d9aa7';this.style.color='#ffffff'\" onmouseout=\"this.style.border='#E9E8F2 1px solid';this.style.background='#E9E8F2';this.style.color='#000000'\" style=\"cursor:default;font-family:verdana;font-size:9px;color:#000000;line-height:9px;padding:1px\" align=center valign=top nowrap unselectable=on>"+this.txtMoreColors+"</td></tr>"+
  1103.         "</table></td>";
  1104.     sHTMLColor+= "</tr>";
  1105.    
  1106.     sHTMLColor+= "</table>";            
  1107.     sHTMLColor+="</td></tr></table>";
  1108.     return sHTMLColor;
  1109.   }
  1110. function drawColorPicker()
  1111.     {  
  1112.     document.write(this.generateHTML());
  1113.     }    
  1114. function refreshCustomColor()
  1115.     {
  1116.     this.customColors=eval(this.oParent).customColors;//[CUSTOM] (Get from public definition)
  1117.    
  1118.     if(this.customColors.length==0)
  1119.         {
  1120.         document.getElementById("idCustomColor"+this.oRenderName).innerHTML="";
  1121.         return;
  1122.         }
  1123.     sHTML="<table cellpadding=0 cellspacing=0 width=100%><tr><td colspan=8 style=\"font-family:verdana;font-size:9px;color:#000000;line-height:9px;padding:1px\">"+this.txtCustomColors+":</td></tr></table>";
  1124.     sHTML+="<table cellpadding=0 cellspacing=0><tr>";  
  1125.     for(var i=0;i<this.customColors.length;i++)
  1126.         {
  1127.         if(i<22)
  1128.             {
  1129.             if(i==8||i==16||i==24||i==32)sHTML+="</tr></table><table cellpadding=0 cellspacing=0><tr>"  
  1130.             sHTML+="<td onclick=\""+this.oName+".color='"+this.customColors[i]+"';"+this.oName+".onPickColor()\" onmouseover=\"this.style.border='#777777 1px solid'\" onmouseout=\"this.style.border='#E9E8F2 1px solid'\" style=\"cursor:default;padding:1px;border:#E9E8F2 1px solid;\" unselectable=on>"+
  1131.                 "   <table  style='margin:0px;width:13px;height:13px;background:"+this.customColors[i]+";border:white 1px solid' cellpadding=0 cellspacing=0 unselectable=on>"+
  1132.                 "   <tr><td unselectable=on></td></tr>"+
  1133.                 "   </table>"+
  1134.                 "</td>";
  1135.             }          
  1136.         }
  1137.     sHTML+="</tr></table>";
  1138.     document.getElementById("idCustomColor"+this.oRenderName).innerHTML=sHTML;
  1139.     }    
  1140. function showColorPicker(oEl)
  1141.     {
  1142.     this.onShow();
  1143.    
  1144.     this.hideAll();
  1145.  
  1146.     var box=document.getElementById("dropColor"+this.oRenderName);
  1147.  
  1148.     //remove hilite
  1149.     var allTds = box.getElementsByTagName("TD");
  1150.     for (var i = 0; i<allTds.length; i++)
  1151.     {
  1152.         allTds[i].style.border="#E9E8F2 1px solid";
  1153.         if (allTds[i].id==this.oName+"moreColTd")
  1154.       {
  1155.       allTds[i].style.border="#E9E8F2 1px solid";
  1156.       allTds[i].style.background="#E9E8F2";
  1157.       allTds[i].style.color="#000000";
  1158.       }
  1159.     }
  1160.  
  1161.     box.style.display="block";
  1162.     var nTop=0;
  1163.     var nLeft=0;
  1164.  
  1165.     oElTmp=oEl;
  1166.     while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
  1167.         {
  1168.         nTop+=oElTmp.offsetTop;
  1169.         oElTmp = oElTmp.offsetParent;
  1170.         }
  1171.  
  1172.     oElTmp=oEl;
  1173.     while(oElTmp.tagName!="BODY" && oElTmp.tagName!="HTML")
  1174.         {
  1175.         nLeft+=oElTmp.offsetLeft;
  1176.         oElTmp=oElTmp.offsetParent;
  1177.         }
  1178.    
  1179.     if(this.align=="left")
  1180.         box.style.left=(nLeft+oUtil.obj.dropLeftAdjustment_moz)+"px";
  1181.     else//right
  1182.         box.style.left=(nLeft-143+oEl.offsetWidth+oUtil.obj.dropLeftAdjustment_moz)+"px";
  1183.        
  1184.     box.style.top=(nTop+iconHeight+1+oUtil.obj.dropTopAdjustment_moz)+"px";//[CUSTOM]
  1185.    
  1186.     box.style.zIndex=200;
  1187.    
  1188.     this.isActive=true;
  1189.    
  1190.     this.refreshCustomColor();
  1191.     }    
  1192. function hideColorPicker()
  1193.     {
  1194.     this.onHide();
  1195.    
  1196.     var box=document.getElementById("dropColor"+this.oRenderName);
  1197.     box.style.display="none";
  1198.     this.isActive=false;
  1199.     }    
  1200. function hideColorPickerAll()
  1201.     {
  1202.     for(var i=0;i<arrColorPickerObjects.length;i++)
  1203.         {
  1204.         var box=document.getElementById("dropColor"+eval(arrColorPickerObjects[i]).oRenderName);
  1205.         box.style.display="none";
  1206.         eval(arrColorPickerObjects[i]).isActive=false;
  1207.         }
  1208.     }
  1209.  
  1210. /*** CONTENT ***/
  1211. function loadHTML(sHTML)//hanya utk first load.
  1212.     {
  1213.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1214.     var oDoc=oEditor.document.open("text/html","replace");
  1215.     if(this.publishingPath!="")
  1216.         {
  1217.         var arrA = String(this.preloadHTML).match(/<base[^>]*>/ig);
  1218.         if(!arrA)
  1219.             {//if no <base> found
  1220.             sHTML=this.docType+"<HTML><HEAD><BASE HREF=\""+this.publishingPath+"\"/>"+this.headContent+"</HEAD><BODY>" + sHTML + "</BODY></HTML>";
  1221.             //kalau cuma tambah <HTML><HEAD></HEAD><BODY.. tdk apa2.
  1222.             }
  1223.         }
  1224.     else
  1225.         {
  1226.         sHTML=this.docType+"<HTML><HEAD>"+this.headContent+"</HEAD><BODY>"+sHTML+"</BODY></HTML>";
  1227.         }
  1228.     oDoc.write(sHTML);
  1229.     oDoc.close();
  1230.  
  1231.     //RealTime
  1232.    
  1233.     var me=this;
  1234.     oEditor.document.addEventListener("keyup", new Function("editorDoc_onkeyup("+this.oName+")"), true);
  1235.     oEditor.document.addEventListener("mouseup", function(e) {editorDoc_onmouseup(e, me.oName);}, true);
  1236.  
  1237.   oEditor.document.addEventListener("keydown", new Function("var e=arguments[0];doKeyPress(eval(e), "+this.oName+")"), false);
  1238.  
  1239.     /*** Apply this.arrStyle to the content ***/
  1240.     if(this.arrStyle.length>0)
  1241.         {
  1242.         var oElement=oEditor.document.createElement("STYLE");
  1243.         oEditor.document.documentElement.childNodes[0].appendChild(oElement);
  1244.         var sCssText = "";
  1245.         for(var i=0;i<this.arrStyle.length;i++)
  1246.             {
  1247.             selector=this.arrStyle[i][0];
  1248.             style=this.arrStyle[i][3];
  1249.             sCssText += selector + " { " + style + " } ";    
  1250.             }
  1251.         oElement.appendChild(oEditor.document.createTextNode(sCssText));
  1252.         }
  1253.  
  1254.   /*** Apply this.css to the content ***/
  1255.     if(this.css!="")
  1256.         {
  1257.         var cssFrame = document.getElementById("myStyle"+this.oName).contentWindow;
  1258.         var cssDoc = cssFrame.document.open("text/html","replace");
  1259.         cssDoc.write("<html><head><link href=\""+this.css+"\" rel=\"stylesheet\" type=\"text/css\"></head><body onload=\"parent.ApplyCSS('"+this.oName+"')\"></body></html>");
  1260.         cssDoc.close();
  1261.         }
  1262.  
  1263.   this.cleanDeprecated();
  1264.     }
  1265.  
  1266. function loadHTMLFull(sHTML, firstLoad)//first load full HTML
  1267.     {
  1268.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1269.  
  1270.     //save doctype (if any/if not body only)
  1271.     var arrA=String(sHTML).match(/<!DOCTYPE[^>]*>/ig);
  1272.     if(arrA)
  1273.         for(var i=0;i<arrA.length;i++)
  1274.             {
  1275.             this.docType=arrA[i];
  1276.             }
  1277.     else this.docType="";//back to default value
  1278.  
  1279.     //save html (if any/if not body only)
  1280.     var arrB=String(sHTML).match(/<HTML[^>]*>/ig);
  1281.     if(arrB)
  1282.         for(var i=0;i<arrB.length;i++)
  1283.             {
  1284.             s=arrB[i];
  1285.             s=s.replace(/\"[^\"]*\"/ig,function(x){
  1286.                         x=x.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/\s+/ig,"#_#");
  1287.                         return x});
  1288.             s=s.replace(/<([^ >]*)/ig,function(x){return x.toLowerCase()});
  1289.             s=s.replace(/ ([^=]+)=([^" >]+)/ig," $1=\"$2\"");
  1290.             s=s.replace(/ ([^=]+)=/ig,function(x){return x.toLowerCase()});
  1291.             s=s.replace(/#_#/ig," ");
  1292.             this.html=s;
  1293.             }
  1294.     else this.html="<html>";//back to default value
  1295.  
  1296.     //Dalam pengeditan kalau pakai doctype,
  1297.     //membuat mouse tdk bisa di-klik di empty area
  1298.   //sHTML=String(sHTML).replace(/<!DOCTYPE[^>]*>/ig,"");
  1299.     if(this.publishingPath!="")
  1300.         {
  1301.         var arrA = sHTML.match(/<base[^>]*>/ig);
  1302.         if(!arrA)
  1303.             {
  1304.             sHTML="<BASE HREF=\""+this.publishingPath+"\"/>"+sHTML;
  1305.             }
  1306.         }
  1307.  
  1308.   /*** Remove link to external css (content with links to external css can't be edited), then the set css property ***/
  1309.     this.css="";
  1310.     var arrExtCss=String(sHTML).match(/<link[^>]*>/ig);
  1311.     if(arrExtCss)
  1312.         for(var i=0;i<arrExtCss.length;i++)
  1313.             {
  1314.             var s=arrExtCss[i];
  1315.             var arrTmp = s.split("href=\"");
  1316.             if (arrTmp.length > 1)
  1317.         {
  1318.         s = arrTmp[1];
  1319.         arrTmp = s.split("\"");
  1320.         if (arrTmp.length > 1)
  1321.           this.css=arrTmp[0];
  1322.         }
  1323.             }
  1324.  
  1325.   sHTML=sHTML.replace(/<link[^>]*>/ig,"");
  1326.   /*** end ***/
  1327.  
  1328.     if (firstLoad) {
  1329.       try {oEditor.document.designMode="on";} catch(e) {}
  1330.     }
  1331.     var oDoc=oEditor.document.open("text/html","replace");
  1332.     oDoc.write(sHTML);
  1333.     oDoc.close();
  1334.    
  1335.     //RealTime
  1336.     var me=this;
  1337.     oEditor.document.addEventListener("keyup", new Function("editorDoc_onkeyup("+me.oName+")"), true);
  1338.     oEditor.document.addEventListener("mouseup", function(e) {editorDoc_onmouseup(e, me.oName);}, true);
  1339.  
  1340.     //<br> or <p>
  1341.     oEditor.document.addEventListener("keydown", new Function("var e=arguments[0];doKeyPress(eval(e), "+this.oName+")"), false);
  1342.  
  1343.   /*** Change linked css to embedded css ***/
  1344.     if(this.css!="")
  1345.         {
  1346.         var cssFrame = document.getElementById("myStyle"+this.oName).contentWindow;
  1347.         var cssDoc = cssFrame.document.open("text/html","replace");
  1348.         cssDoc.write("<html><head><link href=\""+this.css+"\" rel=\"stylesheet\" type=\"text/css\"></head><body onload=\"parent.ApplyCSS('"+this.oName+"')\"></body></html>");
  1349.         cssDoc.close();
  1350.         }
  1351.   /*** end ***/
  1352.  
  1353.   this.cleanDeprecated();
  1354.     }
  1355.  
  1356. function putHTML(sHTML)
  1357.   {//used by source editor
  1358.   this.loadHTMLFull(sHTML, true);
  1359.   }
  1360.  
  1361. function encodeHTMLCode(sHTML) {
  1362.   return sHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  1363. }
  1364.  
  1365. function cleanHTML(sHTML) {
  1366.   var h = sHTML.replace(/<br class="innova" \/>/gi, "");
  1367.   return h;
  1368. }
  1369.  
  1370. function getTextBody()
  1371.   {
  1372.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1373.   return oEditor.document.body.textContent;
  1374.   }
  1375. function getHTML()
  1376.     {
  1377.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1378.     this.cleanDeprecated();
  1379.  
  1380.     sHTML=getOuterHTML(oEditor.document.documentElement);
  1381.     sHTML=String(sHTML).replace(/ contentEditable=true/g,"");
  1382.     sHTML=this.docType+sHTML;//restore doctype (if any)
  1383.     sHTML=oUtil.replaceSpecialChar(sHTML);
  1384.     if(this.encodeIO) sHTML=encodeHTMLCode(sHTML);
  1385.     sHTML = cleanHTML(sHTML);
  1386.     return sHTML;
  1387.     }
  1388. function getHTMLBody()
  1389.     {
  1390.     var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1391.     this.cleanDeprecated();
  1392.  
  1393.     sHTML=oEditor.document.body.innerHTML;
  1394.     sHTML=String(sHTML).replace(/ contentEditable=true/g,"");
  1395.     sHTML=oUtil.replaceSpecialChar(sHTML);
  1396.     if(this.encodeIO) sHTML=encodeHTMLCode(sHTML);
  1397.     sHTML = cleanHTML(sHTML);
  1398.     return sHTML;
  1399.     }
  1400. var sBaseHREF="";
  1401. function getXHTML()
  1402.   {
  1403.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1404.   this.cleanDeprecated();
  1405.  
  1406.   //base handling
  1407.   sHTML=getOuterHTML(oEditor.document.documentElement);
  1408.   var arrTmp=sHTML.match(/<BASE([^>]*)>/ig);
  1409.   if(arrTmp!=null)sBaseHREF=arrTmp[0];
  1410.   var arrBase = oEditor.document.getElementsByTagName("BASE");
  1411.   if (arrBase.length != null)
  1412.     {
  1413.     for(var i=0; i<arrBase.length; i++)
  1414.       {
  1415.       arrBase[i].parentNode.removeChild(arrBase[i]);
  1416.       }
  1417.     }
  1418.    
  1419.   //~~~~~~~~~~~~~
  1420.   sBaseHREF=sBaseHREF.replace(/<([^ >]*)/ig,function(x){return x.toLowerCase()});              
  1421.   sBaseHREF=sBaseHREF.replace(/ [^=]+="[^"]+"/ig,function(x){
  1422.    x=x.replace(/\s+/ig,"#_#");
  1423.    x=x.replace(/^#_#/," ");
  1424.    return x});
  1425.  sBaseHREF=sBaseHREF.replace(/ ([^=]+)=([^" >]+)/ig," $1=\"$2\"");
  1426.   sBaseHREF=sBaseHREF.replace(/ ([^=]+)=/ig,function(x){return x.toLowerCase()});
  1427.   sBaseHREF=sBaseHREF.replace(/#_#/ig," ");
  1428.  
  1429.   sBaseHREF=sBaseHREF.replace(/>$/ig," \/>").replace(/\/ \/>$/ig,"\/>");
  1430.   //~~~~~~~~~~~~~
  1431.  
  1432.   sHTML=recur(oEditor.document.documentElement,"");
  1433.  
  1434.   sHTML=this.docType+this.html+sHTML+"\n</html>";//restore doctype (if any) & html
  1435.   sHTML=sHTML.replace(/<head>/i,"<head>"+sBaseHREF);//restore base href  
  1436.   sHTML=oUtil.replaceSpecialChar(sHTML);
  1437.   if(this.encodeIO) sHTML=encodeHTMLCode(sHTML);
  1438.   sHTML = cleanHTML(sHTML);
  1439.   return sHTML;
  1440.   }
  1441. function getXHTMLBody()
  1442.   {
  1443.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1444.   this.cleanDeprecated();
  1445.  
  1446.   //base handling
  1447.   sHTML=getOuterHTML(oEditor.document.documentElement);
  1448.   var arrTmp=sHTML.match(/<BASE([^>]*)>/ig);
  1449.   if(arrTmp!=null)sBaseHREF=arrTmp[0];
  1450.   var arrBase = oEditor.document.getElementsByTagName("BASE");
  1451.   if (arrBase.length != null)
  1452.     {
  1453.     for(var i=0; i<arrBase.length; i++)
  1454.       {
  1455.       arrBase[i].parentNode.removeChild(arrBase[i]);
  1456.       }
  1457.     }
  1458.   //~~~~~~~~~~~~~
  1459.  
  1460.   sHTML=recur(oEditor.document.body,"");
  1461.   sHTML=oUtil.replaceSpecialChar(sHTML);
  1462.   if(this.encodeIO) sHTML=encodeHTMLCode(sHTML);
  1463.   sHTML = cleanHTML(sHTML);
  1464.   return sHTML;
  1465.   }
  1466. function ApplyCSS(oName)
  1467.   {
  1468.     var sTmp="";
  1469.     var myStyle=document.getElementById("myStyle"+oName).contentWindow;
  1470.     for(var i=0;i<myStyle.document.styleSheets[0].cssRules.length;i++)
  1471.         {
  1472.         var sSelector=myStyle.document.styleSheets[0].cssRules[i].selectorText;
  1473.         if(sSelector!=undefined)
  1474.       {
  1475.       sCssText=myStyle.document.styleSheets[0].cssRules[i].style.cssText.replace(/"/g,"&quot;");
  1476.       var itemCount = sSelector.split(".").length;
  1477.       if(itemCount>1)
  1478.         {
  1479.         sCaption=sSelector.split(".")[1];
  1480.         sTmp+=",[\""+sSelector+"\",true,\""+sCaption+"\",\""+ sCssText + "\"]";
  1481.         }
  1482.       else sTmp+=",[\""+sSelector+"\",false,\"\",\""+ sCssText + "\"]";
  1483.       }
  1484.         }
  1485.     var arrStyle = eval("["+sTmp.substr(1)+"]");
  1486.  
  1487.     if(arrStyle.length>0)
  1488.         {
  1489.         var oEditor=document.getElementById("idContent"+oName).contentWindow;
  1490.         var oElement=oEditor.document.createElement("STYLE");
  1491.         //oElement.id="idExtCss"
  1492.         oEditor.document.documentElement.childNodes[0].appendChild(oElement);
  1493.         var sCssText = "";
  1494.         for(var i=0;i<arrStyle.length;i++)
  1495.             {
  1496.             selector=arrStyle[i][0];
  1497.             style=arrStyle[i][3].replace(/&quot;/g,"\"");
  1498.             sCssText += selector + " { " + style + " } ";    
  1499.             }
  1500.         oElement.appendChild(oEditor.document.createTextNode(sCssText));        
  1501.         }
  1502.   }
  1503. function ApplyExternalStyle(oName)
  1504.     {
  1505.   var oEditor=document.getElementById("idContent"+oName).contentWindow;
  1506.   var sTmp="";
  1507.   for(var j=0;j<oEditor.document.styleSheets.length;j++)
  1508.     {
  1509.     var myStyle=oEditor.document.styleSheets[j];
  1510.  
  1511.     //In full HTML editing: this will parse linked & embedded stylesheet
  1512.     //In Body content editing: this will parse all embedded/applied css & arrStyle.
  1513.     for(var i=0;i<myStyle.cssRules.length;i++)
  1514.       {
  1515.       sSelector=myStyle.cssRules[i].selectorText;
  1516.       if(sSelector!=undefined)
  1517.         {
  1518.         sCssText=myStyle.cssRules[i].style.cssText.replace(/"/g,"&quot;");
  1519.         var itemCount = sSelector.split(".").length;
  1520.         if(itemCount>1)
  1521.           {
  1522.           sCaption=sSelector.split(".")[1];
  1523.           sTmp+=",[\""+sSelector+"\",true,\""+sCaption+"\",\""+ sCssText + "\"]";
  1524.           }
  1525.         else sTmp+=",[\""+sSelector+"\",false,\"\",\""+ sCssText + "\"]";
  1526.         }
  1527.       }
  1528.     }
  1529.  
  1530.   var arrStyle = eval("["+sTmp.substr(1)+"]");
  1531.   eval(oName).arrStyle=arrStyle;//Update arrStyle property
  1532.     }
  1533.  
  1534. function doApplyStyle(oName,sClassName)
  1535.   {
  1536.     var oEditor=document.getElementById("idContent"+oName).contentWindow;
  1537.     var oSel=oEditor.getSelection();
  1538.     eval(oName).saveForUndo();
  1539.  
  1540.   var element;
  1541.     if(oUtil.activeElement)
  1542.         {
  1543.         element=oUtil.activeElement;
  1544.         element.className=sClassName;
  1545.         }
  1546.     else
  1547.     {
  1548.     element = getSelectedElement(oSel);
  1549.     if (isTextSelected(oSel))
  1550.       {
  1551.       if(oSel!="")
  1552.         {
  1553.         /*
  1554.         var idNewSpan=eval(oName).applySpan();
  1555.         if(idNewSpan)idNewSpan.className=sClassName;
  1556.         else
  1557.           {
  1558.           oElement.className=sClassName;
  1559.           }
  1560.         */
  1561.         eval(oName).applySpanStyle([],sClassName);
  1562.         }
  1563.       else
  1564.         {
  1565.         if(element.tagName=="BODY")return;
  1566.         element.className=sClassName;
  1567.         }
  1568.       }
  1569.     else
  1570.       {
  1571.       if(element.tagName=="BODY")return;
  1572.       element.className=sClassName;
  1573.       }
  1574.     }
  1575.   realTime(eval(oName));
  1576.   }
  1577.  
  1578. function openStyleSelect()
  1579.   {
  1580.   if(!this.isCssLoaded)ApplyExternalStyle(this.oName);
  1581.   this.isCssLoaded=true;//make only 1 call to ApplyExternalStyle()
  1582.  
  1583.   var idStyles=document.getElementById("idStyles"+this.oName);
  1584.   if(idStyles.innerHTML!="")
  1585.     {//toggle
  1586.     if(idStyles.style.display=="")
  1587.       idStyles.style.display="none";
  1588.     else
  1589.       idStyles.style.display="";
  1590.     return;
  1591.     }
  1592.   idStyles.style.display="";
  1593.  
  1594.   var h=document.getElementById("idContent"+this.oName).offsetHeight-27;
  1595.  
  1596.   var arrStyle=this.arrStyle;
  1597.  
  1598.   var sHTML="";
  1599.   sHTML+="<div unselectable=on style='margin:5px;margin-top:0;margin-right:0' align=right>"
  1600.  
  1601.   sHTML+="<table style='margin:1px;margin-top:2px;margin-bottom:3px;width:14px;height:14px;background:#E9E8F2;' cellpadding=0 cellspacing=0 unselectable=on>"+
  1602.     "<tr><td onclick=\""+this.oName+".openStyleSelect();\" onmouseover=\"this.style.border='#708090 1px solid';this.style.color='white';this.style.backgroundColor='9FA7BB'\" onmouseout=\"this.style.border='white 1px solid';this.style.color='black';this.style.backgroundColor=''\" style=\"cursor:default;padding:1px;border:white 1px solid;font-family:verdana;font-size:10px;color:#000000;line-height:9px;\" align=center valign=top unselectable=on>x</td></tr>"+
  1603.     "</table>";
  1604.  
  1605.   var sBody="";
  1606.   for(var i=0;i<arrStyle.length;i++)
  1607.     {
  1608.     sSelector=arrStyle[i][0];
  1609.     if(sSelector=="body")sBody=arrStyle[i][3];
  1610.     }
  1611.  
  1612.   sHTML+="<div unselectable=on style='overflow:auto;width:200px;height:"+h+"px;'>";
  1613.   sHTML+="<table name='tblStyles"+this.oName+"' id='tblStyles"+this.oName+"' cellpadding=0 cellspacing=0 style='background:#fcfcfc;"+sBody+";height:100%;width:100%;margin:0;'>";
  1614.  
  1615.   for(var i=0;i<arrStyle.length;i++)
  1616.     {
  1617.     sSelector=arrStyle[i][0];
  1618.     isOnSelection=arrStyle[i][1];
  1619.  
  1620.     sCssText=arrStyle[i][3];
  1621.     //sCssText=sCssText.replace(/color: rgb\(255, 255, 255\)/,"COLOR: #000000");
  1622.  
  1623.     sCaption=arrStyle[i][2];
  1624.     if(isOnSelection)
  1625.       {
  1626.       if(sSelector.split(".").length>1)//sudah pasti
  1627.         {
  1628.         var tmpSelector = sSelector;
  1629.         if (sSelector.indexOf(":")>0) tmpSelector = sSelector.substring(0, sSelector.indexOf(":"));
  1630.         sHTML+="<tr style=\"cursor:default\" onmouseover=\"if(this.style.marginRight!='1px'){this.style.background='"+this.styleSelectionHoverBg+"';this.style.color='"+this.styleSelectionHoverFg+"'}\" onmouseout=\"if(this.style.marginRight!='1px'){this.style.background='';this.style.color=''}\">";
  1631.         sHTML+="<td unselectable=on onclick=\"doApplyStyle('"+this.oName+"','"+tmpSelector.split(".")[1]+"')\" style='padding:2px'>";
  1632.         if(sSelector.split(".")[0]=="")
  1633.           sHTML+="<span unselectable=on style=\""+sCssText+";margin:0;\">"+sCaption+"</span>";
  1634.         else
  1635.           sHTML+="<span unselectable=on style=\""+sCssText+";margin:0;\">"+sSelector+"</span>";
  1636.         sHTML+="</td></tr>";
  1637.         }
  1638.       }
  1639.     }
  1640.   sHTML+="<tr><td height=100%>&nbsp;</td></tr></table></div>";
  1641.   sHTML+="</div>"
  1642.   document.getElementById("idStyles"+this.oName).innerHTML=sHTML;
  1643.   }
  1644.  
  1645. /**************************
  1646.   NEW SPAN OPERATION
  1647. **************************/
  1648.  
  1649. /*** CLEAN ***/
  1650. function cleanFonts()
  1651.   {
  1652.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1653.   var allFonts = oEditor.document.body.getElementsByTagName("FONT");
  1654.   if(allFonts.length==0)return false;
  1655.  
  1656.   var f; var range;
  1657.   while (allFonts.length>0)
  1658.     {
  1659.     f = allFonts[0];
  1660.     if (f.hasChildNodes && f.childNodes.length==1 && f.childNodes[0].nodeType==1 && f.childNodes[0].nodeName=="SPAN")
  1661.       {
  1662.       //if font containts only span child node
  1663.      
  1664.       var theSpan = f.childNodes[0];
  1665.       copyAttribute(theSpan, f);
  1666.      
  1667.       range = oEditor.document.createRange();
  1668.       range.selectNode(f);
  1669.       range.insertNode(theSpan);
  1670.       range.selectNode(f);
  1671.       range.deleteContents();
  1672.       }
  1673.     else
  1674.       if (f.parentNode.nodeName=="SPAN" && f.parentNode.childNodes.length==1)
  1675.         {
  1676.         //font is the only child node of span.
  1677.         var theSpan = f.parentNode;
  1678.         copyAttribute(theSpan, f);
  1679.         theSpan.innerHTML = f.innerHTML;
  1680.         }
  1681.       else
  1682.         {
  1683.         var newSpan = oEditor.document.createElement("SPAN");
  1684.         copyAttribute(newSpan, f);
  1685.         newSpan.innerHTML = f.innerHTML;
  1686.         f.parentNode.replaceChild(newSpan, f);
  1687.         }
  1688.     }
  1689.   return true;
  1690.   }
  1691. function cleanTags(elements,sVal)
  1692.   {
  1693.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1694.   if(elements.length==0)return false;
  1695.  
  1696.   var f;var range;
  1697.   while(elements.length>0)
  1698.     {
  1699.     f = elements[0];
  1700.     if(f.hasChildNodes && f.childNodes.length==1 && f.childNodes[0].nodeType==1 && f.childNodes[0].nodeName=="SPAN")
  1701.       {//if font containts only span child node      
  1702.       var theSpan=f.childNodes[0];
  1703.       if(sVal=="bold")theSpan.style.fontWeight="bold";
  1704.       if(sVal=="italic")theSpan.style.fontStyle="italic";
  1705.       if(sVal=="line-through")theSpan.style.textDecoration="line-through";
  1706.       if(sVal=="underline")theSpan.style.textDecoration="underline";
  1707.  
  1708.       range=oEditor.document.createRange();
  1709.       range.selectNode(f);
  1710.       range.insertNode(theSpan);
  1711.       range.selectNode(f);
  1712.       range.deleteContents();
  1713.       }
  1714.     else
  1715.       if (f.parentNode.nodeName=="SPAN" && f.parentNode.childNodes.length==1)
  1716.         {
  1717.         //font is the only child node of span.
  1718.         var theSpan=f.parentNode;
  1719.         if(sVal=="bold")theSpan.style.fontWeight="bold";
  1720.         if(sVal=="italic")theSpan.style.fontStyle="italic";
  1721.         if(sVal=="line-through")theSpan.style.textDecoration="line-through";
  1722.         if(sVal=="underline")theSpan.style.textDecoration="underline";
  1723.        
  1724.         theSpan.innerHTML=f.innerHTML;
  1725.         }
  1726.       else
  1727.         {
  1728.         var newSpan = oEditor.document.createElement("SPAN");
  1729.         if(sVal=="bold")newSpan.style.fontWeight="bold";
  1730.         if(sVal=="italic")newSpan.style.fontStyle="italic";
  1731.         if(sVal=="line-through")newSpan.style.textDecoration="line-through";
  1732.         if(sVal=="underline")newSpan.style.textDecoration="underline";
  1733.  
  1734.         newSpan.innerHTML=f.innerHTML;
  1735.         f.parentNode.replaceChild(newSpan,f);
  1736.         }
  1737.     }
  1738.   return true;
  1739.   }
  1740. function replaceTags(sFrom,sTo)
  1741.   {
  1742.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1743.  
  1744.   var elements=oEditor.document.body.getElementsByTagName(sFrom);
  1745.  
  1746.   while(elements.length>0)
  1747.     {
  1748.     f = elements[0];
  1749.    
  1750.     var newSpan = oEditor.document.createElement(sTo);
  1751.     newSpan.innerHTML=f.innerHTML;
  1752.     f.parentNode.replaceChild(newSpan,f);
  1753.     }
  1754.   }
  1755. /************************************
  1756.   Used in loadHTML, loadHTMLFull,
  1757.   doKeyPress,
  1758.   getHTML, getXHTML,
  1759.   getHTMLBody, getXHTMLBody,
  1760.   pasteWord.htm,
  1761.   source_html.htm, source_xhtml.htm
  1762. *************************************/
  1763. function cleanDeprecated()
  1764.   {
  1765.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1766.  
  1767.   var elements;
  1768.  
  1769.   elements=oEditor.document.body.getElementsByTagName("STRONG");
  1770.   this.cleanTags(elements,"bold");
  1771.   elements=oEditor.document.body.getElementsByTagName("B");
  1772.   this.cleanTags(elements,"bold");
  1773.  
  1774.   elements=oEditor.document.body.getElementsByTagName("I");
  1775.   this.cleanTags(elements,"italic");
  1776.   elements=oEditor.document.body.getElementsByTagName("EM");
  1777.   this.cleanTags(elements,"italic");
  1778.  
  1779.   elements=oEditor.document.body.getElementsByTagName("STRIKE");
  1780.   this.cleanTags(elements,"line-through");
  1781.   elements=oEditor.document.body.getElementsByTagName("S");
  1782.   this.cleanTags(elements,"line-through");
  1783.  
  1784.   elements=oEditor.document.body.getElementsByTagName("U");
  1785.   this.cleanTags(elements,"underline");
  1786.  
  1787.   this.replaceTags("DIR","DIV");
  1788.   this.replaceTags("MENU","DIV");
  1789.   this.replaceTags("CENTER","DIV");
  1790.   this.replaceTags("XMP","PRE");
  1791.   this.replaceTags("BASEFONT","SPAN");//will be removed by cleanEmptySpan()
  1792.  
  1793.   elements=oEditor.document.body.getElementsByTagName("APPLET");
  1794.   while(elements.length>0)
  1795.     {
  1796.     var f = elements[0];
  1797.     theParent = f.parentNode;
  1798.     theParent.removeChild(f);
  1799.     }
  1800.  
  1801.   this.cleanFonts();
  1802.   this.cleanEmptySpan();
  1803.  
  1804.   return true;
  1805.   }
  1806.  
  1807. /*** APPLY ***/
  1808. function applySpanStyle(arrStyles,sClassName, blockTag)
  1809.   {
  1810.   var useBlock = "SPAN";
  1811.   if (blockTag!=null && blockTag!="") useBlock = blockTag;
  1812.  
  1813.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1814.   var oSel=oEditor.getSelection();
  1815.  
  1816.   var range;
  1817.   var oElement;
  1818.   if (!isTextSelected(oSel))
  1819.     { //if not text selection
  1820.     range = oSel.getRangeAt(0);
  1821.     oElement = getSelectedElement(oSel);
  1822.     if(oElement.nodeName==useBlock) return oElement;
  1823.     return;
  1824.     }
  1825.  
  1826.   this.hide();
  1827.   this.doCmd("fontsize","0");
  1828.  
  1829.   replaceWithSpan(oEditor,arrStyles,sClassName, useBlock);
  1830.   realTime(this);  
  1831.   }
  1832. function doClean()
  1833.     {
  1834.     this.saveForUndo();//Save for Undo
  1835.  
  1836.     if(oUtil.activeElement) var element=oUtil.activeElement;
  1837.     else
  1838.         {
  1839.         var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1840.         var oSel=oEditor.getSelection();        
  1841.     element = getSelectedElement(oSel);
  1842.     if(isTextSelected(oSel))
  1843.       {
  1844.       if(oSel!="")
  1845.         {
  1846.         var range = oSel.getRangeAt(0);
  1847.         if(element.innerHTML!=range.toString())
  1848.           {
  1849.           this.doCmd('RemoveFormat');
  1850.           realTime(this);
  1851.           return;
  1852.           }
  1853.         }
  1854.       else
  1855.         {
  1856.         if(element.tagName=="BODY")return;
  1857.         }
  1858.       }
  1859.     else
  1860.       {
  1861.       if(element.tagName=="BODY")return;
  1862.       }
  1863.         }
  1864.        
  1865.   element.removeAttribute("className");
  1866.   element.removeAttribute("style");
  1867.  
  1868.   if(element.tagName=="H1"||
  1869.     element.tagName=="H2"||
  1870.     element.tagName=="H3"||
  1871.     element.tagName=="H4"||
  1872.     element.tagName=="H5"||
  1873.     element.tagName=="H6"||
  1874.     element.tagName=="PRE"||
  1875.     element.tagName=="P"||
  1876.     element.tagName=="DIV")
  1877.     {
  1878.     this.doCmd('FormatBlock','<P>');
  1879.     }
  1880.  
  1881.     this.doCmd('RemoveFormat');
  1882.     realTime(this);
  1883.     }
  1884.  
  1885. function cleanEmptySpan()
  1886.   {
  1887.   var bReturn=false;
  1888.   var oEditor=document.getElementById("idContent"+this.oName).contentWindow;
  1889.   var reg = /<\s*SPAN\s*>/gi;
  1890.  
  1891.   while (true)
  1892.     {
  1893.     var allSpans = oEditor.document.getElementsByTagName("SPAN");
  1894.     if(allSpans.length==0) break;
  1895.  
  1896.     var emptySpans = [];
  1897.     for (var i=0; i<allSpans.length; i++)
  1898.       {
  1899.       if (getOuterHTML(allSpans[i]).search(reg) == 0)
  1900.         emptySpans[emptySpans.length]=allSpans[i];
  1901.       }
  1902.     if (emptySpans.length == 0) break;
  1903.     var theSpan, theParent;
  1904.     for (var i=0; i<emptySpans.length; i++)
  1905.       {
  1906.       theSpan = emptySpans[i];
  1907.       theParent = theSpan.parentNode;
  1908.       if (!theParent) continue;
  1909.       if (theSpan.hasChildNodes())
  1910.         {
  1911.         var range = oEditor.document.createRange();
  1912.         range.selectNodeContents(theSpan);
  1913.         var docFrag = range.extractContents();
  1914.         theParent.replaceChild(docFrag, theSpan);
  1915.         }
  1916.       else
  1917.         {
  1918.         theParent.removeChild(theSpan);
  1919.         }
  1920.       bReturn=true;
  1921.       }
  1922.     }
  1923.   return bReturn;
  1924.   }
  1925.  
  1926. /*** COMMON ***/
  1927. function copyStyleClass(newSpan,arrStyles,sClassName)
  1928.   {
  1929.   if(arrStyles)
  1930.     {
  1931.     for(var i=0;i<arrStyles.length;i++) eval("newSpan.style."+arrStyles[i][0]+"=\""+arrStyles[i][1]+"\"");
  1932.     if(newSpan.style.cssText=="")newSpan.removeAttribute("style",0);
  1933.     }
  1934.   if(sClassName)
  1935.     newSpan.className=sClassName;
  1936.   }
  1937.  
  1938. function copyAttribute(newSpan,f)
  1939.   {
  1940.   if ((f.face != null) && (f.face != ""))newSpan.style.fontFamily=f.face;
  1941.   if ((f.size != null) && (f.size != ""))
  1942.     {
  1943.     var nSize="";
  1944.     if(f.size==1)nSize="8pt";
  1945.     else if(f.size==2)nSize="10pt";
  1946.     else if(f.size==3)nSize="12pt";
  1947.     else if(f.size==4)nSize="14pt";
  1948.     else if(f.size==5)nSize="18pt";
  1949.     else if(f.size==6)nSize="24pt";
  1950.     else if(f.size>=7)nSize="36pt";
  1951.     else if(f.size<=-2||f.size=="0")nSize="8pt";
  1952.     else if(f.size=="-1")nSize="10pt";
  1953.     else if(f.size==0)nSize="12pt";
  1954.     else if(f.size=="+1")nSize="14pt";
  1955.     else if(f.size=="+2")nSize="18pt";
  1956.     else if(f.size=="+3")nSize="24pt";
  1957.     else if(f.size=="+4"||f.size=="+5"||f.size=="+6")nSize="36pt";
  1958.     else nSize="";
  1959.     if(nSize!="")newSpan.style.fontSize=nSize;
  1960.     }
  1961.   if ((f.style.backgroundColor != null)&&(f.style.backgroundColor != ""))newSpan.style.backgroundColor=f.style.backgroundColor;
  1962.   if ((f.color != null)&&(f.color != ""))newSpan.style.color=f.color;
  1963.   if((f.className!=null)&&(f.className!=""))newSpan.className=f.className;
  1964.   }
  1965.  
  1966. function replaceWithSpan(oEditor, arrStyles, sClassName, blockTag)
  1967.   {
  1968.   var useBlock = "SPAN";
  1969.   if (blockTag!=null && blockTag!="") useBlock = blockTag;
  1970.  
  1971.   var oSel = oEditor.getSelection();
  1972.  
  1973.   //mark selection start font and selection end font.
  1974.   var range = oSel.getRangeAt(0);
  1975.   var startFont = GetElement(range.startContainer, "FONT");
  1976.   if (startFont == null) startFont = range.startContainer.nextSibling;
  1977.   startFont.setAttribute("startcont", "this");
  1978.  
  1979.   var endFont = GetElement(range.endContainer, "FONT");
  1980.   if (endFont == null) endFont = range.endContainer.prevSibling;
  1981.   if (endFont != null) endFont.setAttribute("endcont", "this");
  1982.  
  1983.   var startCont = range.startContainer;
  1984.   var endCont = range.endContainer;
  1985.  
  1986.   //assume, FONT tag are created when applying font size command
  1987.   var allFonts = oEditor.document.getElementsByTagName("FONT");
  1988.   var newSpan = null;
  1989.   var f = null;
  1990.   while(allFonts.length > 0)
  1991.     {
  1992.     f = allFonts[0];      
  1993.     //if a font tag have only 1 child nodes and the child nodes is SPAN, then remove the font tag
  1994.     if (f.childNodes && f.childNodes.length==1 && f.childNodes[0].nodeType==1 && f.childNodes[0].nodeName==useBlock)
  1995.       {
  1996.       newSpan = f.childNodes[0];
  1997.  
  1998.       var spans = newSpan.getElementsByTagName(useBlock);
  1999.       if (spans)
  2000.         {
  2001.         for (var j=0; j<spans.length; j++)
  2002.           {
  2003.           if(arrStyles||sClassName)copyStyleClass(spans[j],arrStyles,sClassName);
  2004.           else copyAttribute(spans[j], f);
  2005.           }
  2006.         }
  2007.  
  2008.       if(arrStyles||sClassName)copyStyleClass(newSpan,arrStyles,sClassName);
  2009.       else copyAttribute(newSpan, f);
  2010.  
  2011.       range = oEditor.document.createRange();
  2012.  
  2013.       //check whether this is the font tag to start/end the selection
  2014.       if (f.getAttribute("startcont")=="this") startCont = newSpan;
  2015.       if (f.getAttribute("endcont")=="this") endCont = newSpan;
  2016.  
  2017.       range.selectNode(f);
  2018.       range.insertNode(newSpan);
  2019.       range.selectNode(f);
  2020.       range.deleteContents();
  2021.       }
  2022.     else
  2023.       {
  2024.       //check if there are spans in the selection
  2025.       var spans = f.getElementsByTagName(useBlock);
  2026.       if (spans)
  2027.         {
  2028.         for (var j=0; j<spans.length; j++)
  2029.           {
  2030.           if(arrStyles||sClassName)copyStyleClass(spans[j],arrStyles,sClassName);
  2031.           else copyAttribute(spans[j], f);
  2032.           }
  2033.         }
  2034.  
  2035.       newSpan = oEditor.document.createElement(useBlock);
  2036.       newSpan.innerHTML = f.innerHTML;
  2037.  
  2038.       if(arrStyles||sClassName)copyStyleClass(newSpan,arrStyles,sClassName);
  2039.       else copyAttribute(newSpan, f);
  2040.  
  2041.       //check whether this is the font tag to start/end the selection
  2042.       if (f.getAttribute("startcont")=="this") startCont = newSpan;
  2043.       if (f.getAttribute("endcont")=="this") endCont = newSpan;
  2044.  
  2045.       f.parentNode.replaceChild(newSpan, f);
  2046.       }
  2047.     }
  2048.  
  2049.   //create selection
  2050.   //set selection start
  2051.   range = oEditor.document.createRange();
  2052.   range.setStart(startCont.childNodes[0], 0);
  2053.   //set selection end
  2054.   var lastNode = endCont.childNodes[endCont.childNodes.length-1];
  2055.   var endOffsetPos = 0;
  2056.   if (lastNode.nodeType==Node.TEXT_NODE)
  2057.     {
  2058.     endOffsetPos = lastNode.nodeValue.length;
  2059.     }
  2060.   else
  2061.     {
  2062.     endOffsetPos = lastNode.childNodes.length;
  2063.     }
  2064.   range.setEnd(lastNode, endOffsetPos);
  2065.   //do the selection
  2066.   oSel = oEditor.getSelection();
  2067.   oSel.removeAllRanges();
  2068.   oSel.addRange(range);
  2069.   }
  2070. /******** /NEW SPAN OPERATION *********/
  2071.  
  2072. /*** REALTIME ***/
  2073. /*
  2074. function editorDoc_onkeydown(edtObj)
  2075.     {
  2076.   edtObj.onKeyPress();
  2077.     realTime(edtObj);    
  2078.     }*/
  2079. function editorDoc_onkeyup(oEdt)
  2080.     {
  2081.    
  2082.     if(oEdt.tmKeyup) {clearTimeout(oEdt.tmKeyup); oEdt.tmKeyup=null;}
  2083.     if(!oEdt.tmKeyup)oEdt.tmKeyup=setTimeout(function(){realTime(oEdt);}, 1000);
  2084.  
  2085.     //realTime(edtObj);
  2086.     }
  2087. function editorDoc_onmouseup(e, oName)
  2088.     {
  2089.     var edtObj=eval(oName);
  2090.     var edtFrm=document.getElementById("idContent"+edtObj.oName);
  2091.    
  2092.     oUtil.activeElement=null;//focus ke editor, jgn pakai selection dari tag selector
  2093.     oUtil.oName=oName;
  2094.     oUtil.oEditor=edtFrm.contentWindow;
  2095.     oUtil.obj=edtObj;
  2096.     edtObj.hide();//pengganti onfocus
  2097.     realTime(edtObj);      
  2098.     }
  2099. function setActiveEditor(edtObj)
  2100.     {
  2101.     oUtil.oName=edtObj.oName;
  2102.     oUtil.oEditor=document.getElementById("idContent"+edtObj.oName).contentWindow;
  2103.     oUtil.obj=edtObj;
  2104.     }
  2105.  
  2106. var arrTmp=[];
  2107. function GetElement(oElement,sMatchTag)//Used in realTime() only.
  2108.     {
  2109.     while (oElement!=null&&oElement.tagName!=sMatchTag)
  2110.         {
  2111.         if(oElement.tagName=="BODY")return null;
  2112.         oElement=oElement.parentNode;
  2113.         }
  2114.     return oElement;
  2115.     }
  2116.    
  2117. var arrTmp2=[];//TAG SELECTOR
  2118. function realTime(edtObj)
  2119.     {
  2120.     try{
  2121.     var oName = edtObj.oName;
  2122.  
  2123.     var oEditor=document.getElementById("idContent"+oName).contentWindow;
  2124.  
  2125.     var oSel=oEditor.getSelection();
  2126.     var element = getSelectedElement(oSel);
  2127.  
  2128.     var obj=edtObj;
  2129.     var tbar=obj.tbar;
  2130.     var btn=null;
  2131.  
  2132.     //Enable/Disable Table Edit & Cell Edit Menu
  2133.     if(obj.btnTable)
  2134.         {
  2135.        
  2136.         var btn=tbar.btns["btnTableEdit"+oName];
  2137.         var ddTbl=isDDs[btn.ddId];
  2138.         ddTbl.enableItem("mnuTableSize"+oName, true);
  2139.         ddTbl.enableItem("mnuTableEdit"+oName, true);
  2140.         ddTbl.enableItem("mnuCellEdit"+oName, true);
  2141.         var oTable=GetElement(element,"TABLE");
  2142.         if (oTable)
  2143.             {
  2144.             ddTbl.enableItem("mnuCellEdit"+oName, false);
  2145.             btn.setState(1);
  2146.             }
  2147.         else btn.setState(5);
  2148.  
  2149.         var oTD=GetElement(element,"TD");
  2150.         if (oTD)
  2151.             {
  2152.             ddTbl.enableItem("mnuCellEdit"+oName, true);
  2153.             }
  2154.         }
  2155.  
  2156.     //REALTIME BUTTONS HERE
  2157.     var doc=oEditor.document;
  2158.    
  2159.     if(obj.btnParagraph)
  2160.         {
  2161.         btn=tbar.btns["btnParagraph"+oName];
  2162.         btn.setState(doc.queryCommandEnabled("FormatBlock")?1:5);        
  2163.         }
  2164.     if(obj.btnFontName)
  2165.         {
  2166.         btn=tbar.btns["btnFontName"+oName];
  2167.         btn.setState(doc.queryCommandEnabled("FontName")?1:5);
  2168.         }
  2169.  
  2170.     if(obj.btnFontSize)
  2171.         {
  2172.         btn=tbar.btns["btnFontSize"+oName];
  2173.         btn.setState(doc.queryCommandEnabled("FontSize")?1:5);
  2174.         }
  2175.  
  2176.     if(obj.btnUndo)
  2177.         {
  2178.         btn=tbar.btns["btnUndo"+oName];
  2179.         btn.setState(!obj.arrUndoList[0]?5:1);
  2180.         }
  2181.     if(obj.btnRedo)
  2182.         {
  2183.         btn=tbar.btns["btnRedo"+oName];
  2184.         btn.setState(!obj.arrRedoList[0]?5:1);
  2185.         }
  2186.  
  2187.     if(obj.btnBold)
  2188.         {
  2189.         btn=tbar.btns["btnBold"+oName];
  2190.         btn.setState(doc.queryCommandEnabled("Bold")?(doc.queryCommandState("Bold")?4:1):5);
  2191.         }
  2192.        
  2193.     if(obj.btnItalic)
  2194.         {
  2195.         btn=tbar.btns["btnItalic"+oName];
  2196.         btn.setState(doc.queryCommandEnabled("Italic")?(doc.queryCommandState("Italic")?4:1):5);
  2197.         }
  2198.  
  2199.     if(obj.btnUnderline)
  2200.         {
  2201.         btn=tbar.btns["btnUnderline"+oName];
  2202.         btn.setState(doc.queryCommandEnabled("Underline")?(doc.queryCommandState("Underline")?4:1):5);
  2203.         }
  2204.  
  2205.     if(obj.btnStrikethrough)
  2206.         {
  2207.         btn=tbar.btns["btnStrikethrough"+oName];
  2208.         btn.setState(doc.queryCommandEnabled("Strikethrough")?(doc.queryCommandState("Strikethrough")?4:1):5);
  2209.         }
  2210.  
  2211.     if(obj.btnSuperscript)
  2212.         {
  2213.         btn=tbar.btns["btnSuperscript"+oName];
  2214.         btn.setState(doc.queryCommandEnabled("Superscript")?(doc.queryCommandState("Superscript")?4:1):5);
  2215.         }
  2216.  
  2217.     if(obj.btnSubscript)
  2218.         {
  2219.         btn=tbar.btns["btnSubscript"+oName];
  2220.         btn.setState(doc.queryCommandEnabled("Subscript")?(doc.queryCommandState("Subscript")?4:1):5);
  2221.         }
  2222.  
  2223.     if(obj.btnNumbering)
  2224.         {
  2225.         btn=tbar.btns["btnNumbering"+oName];
  2226.         btn.setState(doc.queryCommandEnabled("InsertOrderedList")?(doc.queryCommandState("InsertOrderedList")?4:1):5);
  2227.         }
  2228.        
  2229.     if(obj.btnBullets)
  2230.         {
  2231.         btn=tbar.btns["btnBullets"+oName];
  2232.         btn.setState(doc.queryCommandEnabled("InsertUnorderedList")?(doc.queryCommandState("InsertUnorderedList")?4:1):5);
  2233.         }
  2234.  
  2235.     if(obj.btnJustifyLeft)
  2236.         {
  2237.         btn=tbar.btns["btnJustifyLeft"+oName];
  2238.         btn.setState(doc.queryCommandEnabled("JustifyLeft")?(doc.queryCommandState("JustifyLeft")?4:1):5);
  2239.         }
  2240.     if(obj.btnJustifyCenter)
  2241.         {
  2242.         btn=tbar.btns["btnJustifyCenter"+oName];
  2243.         btn.setState(doc.queryCommandEnabled("JustifyCenter")?(doc.queryCommandState("JustifyCenter")?4:1):5);
  2244.         }
  2245.  
  2246.     if(obj.btnJustifyRight)
  2247.         {
  2248.         btn=tbar.btns["btnJustifyRight"+oName];
  2249.         btn.setState(doc.queryCommandEnabled("JustifyRight")?(doc.queryCommandState("JustifyRight")?4:1):5);
  2250.         }
  2251.     if(obj.btnJustifyFull)
  2252.         {
  2253.         btn=tbar.btns["btnJustifyFull"+oName];
  2254.         btn.setState(doc.queryCommandEnabled("JustifyFull")?(doc.queryCommandState("JustifyFull")?4:1):5);
  2255.         }
  2256.     if(obj.btnUnlink)
  2257.         {
  2258.         btn=tbar.btns["btnUnlink"+oName];
  2259.         btn.setState(doc.queryCommandEnabled("Unlink")?1:5);
  2260.         }
  2261.        
  2262.     if(obj.btnIndent)
  2263.         {
  2264.         btn=tbar.btns["btnIndent"+oName];
  2265.         btn.setState(doc.queryCommandEnabled("Indent")?1:5);
  2266.         }
  2267.  
  2268.     if(obj.btnOutdent)
  2269.         {
  2270.         btn=tbar.btns["btnOutdent"+oName];
  2271.         btn.setState(doc.queryCommandEnabled("Outdent")?1:5);
  2272.         }
  2273.  
  2274.     if(obj.btnLTR)
  2275.         {
  2276.         btn=tbar.btns["btnLTR"+oName];
  2277.         btn.setState(element.dir?(element.dir.toLowerCase()=="ltr"?4:1):5);
  2278.         }
  2279.     if(obj.btnRTL)
  2280.         {
  2281.         btn=tbar.btns["btnRTL"+oName];
  2282.         btn.setState(element.dir?(element.dir.toLowerCase()=="rtl"?4:1):5);
  2283.         }
  2284.  
  2285.  
  2286.     var v=(element?1:5);
  2287.     if(obj.btnForeColor)tbar.btns["btnForeColor"+oName].setState(v);
  2288.     if(obj.btnBackColor)tbar.btns["btnBackColor"+oName].setState(v);
  2289.     if(obj.btnLine)tbar.btns["btnLine"+oName].setState(v);
  2290.  
  2291.     try{oUtil.onSelectionChanged()}catch(e){;}
  2292.  
  2293.     try{obj.onSelectionChanged()}catch(e){;}
  2294.  
  2295.   //STYLE SELECTOR ~~~~~~~~~~~~~~~~~~
  2296.   var idStyles=document.getElementById("idStyles"+oName);
  2297.   if(idStyles.innerHTML!="")
  2298.     {
  2299.     var oElement;
  2300.     if(oUtil.activeElement)
  2301.       oElement=oUtil.activeElement
  2302.     else
  2303.       oElement = getSelectedElement(oSel);    
  2304.     var sCurrClass=oElement.className;
  2305.    
  2306.     var oRows=document.getElementById("tblStyles"+oName).rows;
  2307.     for(var i=0;i<oRows.length-1;i++)
  2308.       {
  2309.       sClass=oRows[i].childNodes[0].childNodes[0].innerHTML;
  2310.       if(sClass.split(".").length>1 && sClass!="")sClass=sClass.split(".")[1];
  2311.       if(sCurrClass==sClass)
  2312.         {
  2313.         oRows[i].style.marginRight="1px";
  2314.         oRows[i].style.backgroundColor=obj.styleSelectionHoverBg;
  2315.         oRows[i].style.color=obj.styleSelectionHoverFg;
  2316.         }
  2317.       else
  2318.         {
  2319.         oRows[i].style.marginRight="";