/***********************************************************
	Copyright © 2003, InnovaStudio.com. All rights reserved.
************************************************************/

/*********************
	Utility Object
**********************/
var oUtil=new InnovaEditorUtil();
function InnovaEditorUtil()
	{
	this.oName;
	this.oSel;
	this.sType;
	this.bInside=bInside;
	this.useSelection=true;
	}

/*********************
	Focus stuff (FOR DIALOGS & EDITOR)
**********************/
function doBlur()
	{
	/*
	doBlur dipanggil saat cursor yg semula ada di dalam editor area di-click-kan di luar editor area.
	Ada 2 kemungkinan:
	1.	Jika yg di-klik "unselectable" :
		maka oSel diambil dari posisi terakhir cursor dalam area editor (ini kondisi yg diharapkan).
	2.	Jika yg di-klik tidak "unselectable" (berarti "selectable") :
		maka oSel diambil dari posisi saat ini di luar area editor (ini tdk diharapkan)
	Solusi:
	Dicek lagi menggunakan bInside().
	Kalau "true" (inside) => oUtil.useSelection=true (Kemungkinan 1)
	Kalau "false" (outside/oSel diambil dari posisi saat ini di luar area editor) => oUtil.useSelection=false (Kemungkinan 2)
	------------
	Nanti di setiap dialog & di checkFocus() (di editor) akan dilakukan pengecekan berdasarkan oUtil.useSelection, sbb:

		var oName=dialogArguments.oUtil.oName;
		var oEditor=eval("dialogArguments.idContent"+oName);
		var oSel=oEditor.document.selection.createRange();
		var sType=oEditor.document.selection.type;
		//----------
		//	Kalau selection saat ini sudah berada di dalam area editor => JALAN TERUS (pakai selection saat ini)
		//	Kalau tidak => CEK  oUtil.useSelection
		//		Kalau  oUtil.useSelection=true   (doBlur sesuai harapan/ yg diambil selection dlm area editor) => PAKAI  oUtil.oSel
		//		Kalau  oUtil.useSelection=false  (doBlur tdk sesuai harapan) => RETURN (operasi dihentikan)
		//----------
		isInside=true;
		if(oSel.parentElement!=null)
			{
			if(!bInside(oSel.parentElement()))isInside=false;
			}
		else
			{
			if(!bInside(oSel.item(0)))isInside=false;
			}

		if(!isInside)
			{
			if(dialogArguments.oUtil.useSelection)
				{
				oSel = dialogArguments.oUtil.oSel;
				sType = dialogArguments.oUtil.sType;
				}
			else
				{
				return;
				}
			}
	*/
	var oEditor=eval("idContent"+this.oName);
	var oSel=oEditor.document.selection.createRange();
	var sType=oEditor.document.selection.type;

	oUtil.useSelection=true;
	if(oSel.parentElement!=null)
		{
		if(!bInside(oSel.parentElement())) oUtil.useSelection=false;//(Kemungkinan 2)
		}
	else
		{
		if(!bInside(oSel.item(0))) oUtil.useSelection=false;//(Kemungkinan 2)
		}

	//Ini utk men-test posisi yg diambil
	//	oEl=oSel.parentElement()
	//	alert(oEl.tagName)
	if(oUtil.useSelection)//(Kemungkinan 1)
		{
		oUtil.oSel=oSel;
		oUtil.sType=sType;
		}
	}
function bInside(oElement)
	{
	while(oElement!=null)
		{
		if(oElement.contentEditable=="true")return true;
		oElement=oElement.parentElement;
		}
	return false;
	}

/*********************
	checkFocus() & focus()
**********************/
function checkFocus()
	{
	var oEditor=eval("idContent"+this.oName);
	var oSel=oEditor.document.selection.createRange();
	var sType=oEditor.document.selection.type;

	isInside=true;
	if(oSel.parentElement!=null)
		{
		if(!bInside(oSel.parentElement()))isInside=false;
		}
	else
		{
		if(!bInside(oSel.item(0)))isInside=false;
		}

	if(!isInside)
		{
		if(oUtil.useSelection)
			{
			oSel=oUtil.oSel;
			sType=oUtil.sType;
			try
				{
				if (oSel.parentElement)	oElement=oSel.parentElement();
				else oElement=oSel.item(0);
				}
			catch(e)
				{
				//oSel=null;sType=null;
				return false;
				}
			}
		else
			{
			//oSel=null;sType=null;
			return false;
			}
		}
	return true;
	}
function focus()
	{
	var oEditor=eval("idContent"+this.oName);
	oEditor.focus()
	}

/*********************
	EDITOR OBJECT
**********************/
function InnovaEditor(oName)
	{
	this.oName=oName;
	this.RENDER=RENDER;
	
	this.loadHTML=loadHTML;
	this.getHTMLBody=getHTMLBody;
	this.getXHTMLBody=getXHTMLBody;
	
	this.loadHTMLStatic=loadHTMLStatic;
	this.getHTML=getHTML;
	this.getXHTML=getXHTML;
	
	this.putHTML=putHTML; //internal use (html/xhtml dialog)

	this.doBlur=doBlur;//Focus stuff (FOR DIALOGS & EDITOR)
	this.bInside=bInside;//Focus stuff (FOR DIALOGS & EDITOR)
	this.checkFocus=checkFocus;
	this.focus=focus;

	this.doCmd=doCmd;
	this.applyParagraph=applyParagraph;
	this.applyFontName=applyFontName;
	this.applyFontSize=applyFontSize;

	this.hide=hide;
	this.dropShow=dropShow;

	this.publishingPath="";//ex."http://localhost/InnovaStudio/"

	this.width="465";
	this.height="350";

	this.scriptPath="include/";//spy aman, gunakan: relative to root

	this.runtimeBorder=runtimeBorder;
	this.runtimeBorderOn=runtimeBorderOn;
	this.runtimeBorderOff=runtimeBorderOff;
	this.IsRuntimeBorderOn=true;

	this.isFullHTML=false;//"true" is Not Recommended

	this.btnTextFormatting=false;  //true
         this.btnCssText=false;  //true
	this.btnParagraph=false;  //true
         this.btnFontName=false;   //true
         this.btnFontSize=false;   //true 
	this.btnCut=true;
         this.btnCopy=true;
         this.btnPaste=true;
         this.btnUndo=true;
         this.btnRedo=true;
	this.btnBold=true;
         this.btnItalic=true;
         this.btnUnderline=true;
	this.btnJustifyLeft=true;
         this.btnJustifyCenter=true;
         this.btnJustifyRight=true;
         this.btnJustifyFull=false;   //true
	this.btnNumbering=true;
         this.btnBullets=true;
	this.btnIndent=true;
         this.btnOutdent=true;
	this.btnForecolor=false;  //true
         this.btnBackcolor=false;  //true
	this.btnHyperlink=true;
	this.btnImage=true;
	this.btnTable=true;
         this.btnGuidelines=false;  //true
	this.btnPasteWord=true;
         this.btnLine=true;
         this.btnClean=false;  //true
	this.btnXHTMLSource=false;  //true 
	

	this.btnStyles=false;
	this.btnStrikethrough=false;
	this.btnSuperscript=false;
	this.btnSubscript=false;
	this.btnAssets=false;
	this.btnAssetManager=false;
	this.btnInternalLink=false;
	this.btnBorder=false;
	this.btnHTMLSource=false;
	this.btnClearAll=false;

	this.cmdAssets="modalDialogShow('assets.asp',617,480)";
	this.cmdAssetManager="modalDialogShow('assetmanager.asp',617,480)";
	
	this.pasteWord=pasteWord;
	this.insertHTML=insertHTML;
	this.cmdInternalLink="";
	this.insertLink=insertLink;
	this.clearAll=clearAll;

	this.arrStyle =	[];

	this.arrParagraph= [["Heading 1","H1"],
						["Heading 2","H2"],
						["Heading 3","H3"],
						["Heading 4","H4"],
						["Heading 5","H5"],
						["Heading 6","H6"],
						["Preformatted","PRE"],
						["Normal (P)","P"],
						["Normal (DIV)","DIV"]];

	this.arrFontName = ["Arial",
						"Arial Black",
						"Book Antiqua",
						"Comic Sans MS",
						"Courier New",
						"Georgia",
						"Impact",
						"Symbol",
						"Tahoma",
						"Times New Roman",
						"Trebuchet MS",
						"Verdana",
						"Webdings",
						"Wingdings",
						"serif",
						"sans-serif",
						"cursive",
						"fantasy",
						"monoscape"];

	this.arrFontSize = [["Size 1","1"],
						["Size 2","2"],
						["Size 3","3"],
						["Size 4","4"],
						["Size 5","5"],
						["Size 6","6"],
						["Size 7","7"]];
						
	this.initialRefresh = false;
	}

/*********************
	RENDER
**********************/
function RENDER()
	{
	/******** ICONS ********/
	var sHTMLDropMenus="";
	var sHTMLIcons="";
	
	var sTmp="";
	if(this.btnTextFormatting)
		sTmp+= "<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"text1.htm',window,'dialogWidth:505px;dialogHeight:565px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropStyle.style.display='none'\" " +
				"style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Text Formatting</td></tr>";

	if(this.btnStyles)
		sTmp+= "<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"styles.htm',window,'dialogWidth:357px;dialogHeight:390px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropStyle.style.display='none'\" " +
				"style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Styles</td></tr>";

	if(this.btnCssText)
		sTmp+= "<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"styles_cssText.htm',window,'dialogWidth:456px;dialogHeight:443px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropStyle.style.display='none'\" " +
				"style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Custom CSS</td></tr>";

	if(this.btnTextFormatting || this.btnStyles || this.btnCssText)
		{
		sHTMLIcons+=writeIcon("idStyle"+this.oName,"Styles & Formatting",this.oName+".dropShow('idStyle"+this.oName+"',dropStyle)",this.scriptPath+"icons/"+"btn_style.gif");

		if(!document.getElementById("dropStyle"))
			sHTMLDropMenus+="<table id=dropStyle cellpadding=0 cellspacing=0 style='z-index:1;display:none;position:absolute;border:#716F64 1 solid;cursor:default;background-color:#F8F8FF;' unselectable=on>" +
				sTmp + "</table>";
		}

	if(this.btnParagraph)
		{
		sHTMLDropMenus+= "<table id=dropParagraph"+this.oName+" cellpadding=0 cellspacing=0 style='z-index:1;display:none;position:absolute;border:#716F64 1 solid;cursor:default;background-color:ghostwhite;' unselectable=on>";
		for(var i=0;i<this.arrParagraph.length;i++)
			{
			sHTMLDropMenus+= "<tr><td  onclick=\""+this.oName+".applyParagraph('<"+this.arrParagraph[i][1]+">')\" " +
				"style=\"padding:0;padding-left:5;padding-right:5;font-family:tahoma;background-color:ghostwhite\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on align=center>" +
				"<"+this.arrParagraph[i][1]+" style=\"\margin-bottom:4\"  unselectable=on> " +
				this.arrParagraph[i][0] + "</"+this.arrParagraph[i][1]+"></td></tr>";
			}
		sHTMLDropMenus+= "</table>";

		sHTMLIcons+=writeIcon2("idParagraph"+this.oName,"Paragraph","Paragraph",this.oName+".dropShow('idParagraph"+this.oName+"',dropParagraph"+this.oName+")",this.scriptPath+"icons/"+"btn_paragraph.gif",89);
		}

	if(this.btnFontName)
		{
		sHTMLDropMenus+= "<table id=dropFontName"+this.oName+" cellpadding=0 cellspacing=0 style='z-index:1;display:none;position:absolute;border:#716F64 1 solid;cursor:default;background-color:ghostwhite;' unselectable=on>";
		for(var i=0;i<this.arrFontName.length;i++)
			{
			sHTMLDropMenus+= "<tr><td onclick=\""+this.oName+".applyFontName('"+this.arrFontName[i]+"')\" " +
				"style=\"padding:2;padding-top:1;font-family:"+ this.arrFontName[i] +";font-size:11;background-color:ghostwhite\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>" +
				this.arrFontName[i] + " <span  unselectable=on style='font-family:tahoma'>("+ this.arrFontName[i] +")</span></td></tr>";		
			}
		sHTMLDropMenus+= "</table>";

		sHTMLIcons+=writeIcon2("idFontName"+this.oName,"Font Name","Font Name",this.oName+".dropShow('idFontName"+this.oName+"',dropFontName"+this.oName+")",this.scriptPath+"icons/"+"btn_fontname.gif",90);
		}

	if(this.btnFontSize)
		{
		sHTMLDropMenus+= "<table id=dropFontSize"+this.oName+" cellpadding=0 cellspacing=0 style='z-index:1;display:none;position:absolute;border:#716F64 1 solid;cursor:default;background-color:ghostwhite;' unselectable=on>";
		for(var i=0;i<this.arrFontSize.length;i++)
			{
			sHTMLDropMenus+= "<tr><td onclick=\""+this.oName+".applyFontSize('"+this.arrFontSize[i][1]+"')\" " +
				"style=\"padding:0;padding-left:5;padding-right:5;font-family:tahoma;background-color:ghostwhite\" " +
				"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on align=center>" +
				"<font  unselectable=on size=\""+this.arrFontSize[i][1]+"\"> " +
				this.arrFontSize[i][0] + "</font></td></tr>";
			}
		sHTMLDropMenus+= "</table>";

		sHTMLIcons+=writeIcon2("idFontSize"+this.oName,"Font Size","Size",this.oName+".dropShow('idFontSize"+this.oName+"',dropFontSize"+this.oName+")",this.scriptPath+"icons/"+"btn_fontsize.gif",48);
		}

	if(this.btnCut) sHTMLIcons+=writeIcon("idCut"+this.oName,"Cut",this.oName+".doCmd('Cut')",this.scriptPath+"icons/"+"btn_cut.gif");
	if(this.btnCopy) sHTMLIcons+=writeIcon("idCopy"+this.oName,"Copy",this.oName+".doCmd('Copy')",this.scriptPath+"icons/"+"btn_copy.gif");
	if(this.btnPaste) sHTMLIcons+=writeIcon("idPaste"+this.oName,"Paste",this.oName+".doCmd('Paste')",this.scriptPath+"icons/"+"btn_paste.gif");
	if(this.btnUndo) sHTMLIcons+=writeIcon("idUndo"+this.oName,"Undo",this.oName+".doCmd('Undo')",this.scriptPath+"icons/"+"btn_undo.gif");
	if(this.btnRedo) sHTMLIcons+=writeIcon("idRedo"+this.oName,"Redo",this.oName+".doCmd('Redo')",this.scriptPath+"icons/"+"btn_redo.gif");
	if(this.btnBold) sHTMLIcons+=writeIcon("idBold"+this.oName,"Bold",this.oName+".doCmd('Bold')",this.scriptPath+"icons/"+"btn_bold.gif");
	if(this.btnItalic) sHTMLIcons+=writeIcon("idItalic"+this.oName,"Italic",this.oName+".doCmd('Italic')",this.scriptPath+"icons/"+"btn_italic.gif");
	if(this.btnUnderline) sHTMLIcons+=writeIcon("idUnderline"+this.oName,"Underline",this.oName+".doCmd('Underline')",this.scriptPath+"icons/"+"btn_underline.gif");
	if(this.btnStrikethrough) sHTMLIcons+=writeIcon("idStrikethrough"+this.oName,"Strikethrough",this.oName+".doCmd('Strikethrough')",this.scriptPath+"icons/"+"btn_strikethrough.gif");
	if(this.btnSuperscript) sHTMLIcons+=writeIcon("idSuperscript"+this.oName,"Superscript",this.oName+".doCmd('Superscript')",this.scriptPath+"icons/"+"btn_superscript.gif");
	if(this.btnSubscript) sHTMLIcons+=writeIcon("idSubscript"+this.oName,"Subscript",this.oName+".doCmd('Subscript')",this.scriptPath+"icons/"+"btn_subscript.gif");
	if(this.btnJustifyLeft) sHTMLIcons+=writeIcon("idJustifyLeft"+this.oName,"Justify Left",this.oName+".doCmd('JustifyLeft')",this.scriptPath+"icons/"+"btn_left.gif");
	if(this.btnJustifyCenter) sHTMLIcons+=writeIcon("idJustifyCenter"+this.oName,"Justify Center",this.oName+".doCmd('JustifyCenter')",this.scriptPath+"icons/"+"btn_center.gif");
	if(this.btnJustifyRight) sHTMLIcons+=writeIcon("idJustifyRight"+this.oName,"Justify Right",this.oName+".doCmd('JustifyRight')",this.scriptPath+"icons/"+"btn_right.gif");
	if(this.btnJustifyFull) sHTMLIcons+=writeIcon("idJustifyFull"+this.oName,"Justify Full",this.oName+".doCmd('JustifyFull')",this.scriptPath+"icons/"+"btn_full.gif");
	if(this.btnNumbering) sHTMLIcons+=writeIcon("idNumbering"+this.oName,"Numbering",this.oName+".doCmd('InsertOrderedList')",this.scriptPath+"icons/"+"btn_numbering.gif");
	if(this.btnBullets) sHTMLIcons+=writeIcon("idBullets"+this.oName,"Bullets",this.oName+".doCmd('InsertUnorderedList')",this.scriptPath+"icons/"+"btn_bullets.gif");
	if(this.btnIndent) sHTMLIcons+=writeIcon("idIndent"+this.oName,"Indent",this.oName+".doCmd('Indent')",this.scriptPath+"icons/"+"btn_indent.gif");
	if(this.btnOutdent) sHTMLIcons+=writeIcon("idOutdent"+this.oName,"Outdent",this.oName+".doCmd('Outdent')",this.scriptPath+"icons/"+"btn_outdent.gif");

	if(this.btnForecolor) sHTMLIcons+=writeIcon("idForecolor"+this.oName,"Foreground Color","modelessDialogShow('"+this.scriptPath+"colors_foreground.htm',380,292)",this.scriptPath+"icons/"+"btn_forecolor.gif");
	if(this.btnBackcolor) sHTMLIcons+=writeIcon("idBackcolor"+this.oName,"Background Color","modelessDialogShow('"+this.scriptPath+"colors_background.htm',380,292)",this.scriptPath+"icons/"+"btn_backcolor.gif");

	if(this.btnHyperlink) sHTMLIcons+=writeIcon("idHyperlink"+this.oName,"Hyperlink","modelessDialogShow('"+this.scriptPath+"hyperlink.htm',312,223)",this.scriptPath+"icons/"+"btn_hyperlink.gif");
	
	if(this.btnImage) sHTMLIcons+=writeIcon("idImage"+this.oName,"External Image","modelessDialogShow('"+this.scriptPath+"image.htm',416,283)",this.scriptPath+"icons/"+"btn_image.gif");
	if(this.btnAssets) sHTMLIcons+=writeIcon("idAssets"+this.oName,"Assets",this.cmdAssets,this.scriptPath+"icons/"+"btn_assets.gif");
	if(this.btnAssetManager) sHTMLIcons+=writeIcon("idAssetManager"+this.oName,"Asset Manager",this.cmdAssetManager,this.scriptPath+"icons/"+"btn_assetmanager.gif");
	
	if(this.btnInternalLink) sHTMLIcons+=writeIcon("idInternalLink"+this.oName,"Internal Link",this.cmdInternalLink,this.scriptPath+"icons/"+"btn_internallink.gif");

	if(this.btnTable)
		{
		if(!document.getElementById("dropTable"))
			sHTMLDropMenus+="<table id=dropTable cellpadding=0 cellspacing=0 style='display:none;position:absolute;border:#716F64 1 solid;cursor:default;background-color:#F8F8FF;' unselectable=on>" +
				"<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"table_insert.htm',window,'dialogWidth:391px;dialogHeight:393px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropTable.style.display='none'\" " +
				"		style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"		onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"		onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Insert Table </td></tr>" +
				"<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"table_edit.htm',window,'dialogWidth:432px;dialogHeight:382px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropTable.style.display='none'\" " +
				"		style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"		onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"		onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Edit Table </td></tr>" +
				"<tr><td onclick=\"window.showModelessDialog('"+this.scriptPath+"table_editCell.htm',window,'dialogWidth:433px;dialogHeight:460px;edge:Raised;center:Yes;help:No;resizable:No;status:No');dropTable.style.display='none'\" " +
				"		style=\"padding:2;padding-top:1;font-family:Tahoma;font-size:11;background-color:#F8F8FF\" " +
				"		onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" " +
				"		onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>Edit Cell </td></tr>" +
				"</table>";
				
		sHTMLIcons+=writeIcon("idTable"+this.oName,"Table",this.oName+".dropShow('idTable"+this.oName+"',dropTable)",this.scriptPath+"icons/"+"btn_table.gif");
		}

	if(this.btnBorder) sHTMLIcons+=writeIcon("iBorder"+this.oName,"Border & Shading","modelessDialogShow('"+this.scriptPath+"border1.htm',449,305)",this.scriptPath+"icons/"+"btn_border.gif");
	if(this.btnGuidelines) sHTMLIcons+= writeIcon("idGuidelines"+this.oName,"Show/Hide Guidelines",this.oName+".runtimeBorder(true)",this.scriptPath+"icons/"+"btn_guidelines.gif");

	if(this.btnPasteWord) sHTMLIcons+=writeIcon("idPasteWord"+this.oName,"Paste from Word",this.oName+".pasteWord()",this.scriptPath+"icons/"+"btn_pasteword.gif");
	if(this.btnLine) sHTMLIcons+=writeIcon("idLine"+this.oName,"Line",this.oName+".doCmd('InsertHorizontalRule')",this.scriptPath+"icons/"+"btn_line.gif");
	if(this.btnClean) sHTMLIcons+=writeIcon("idClean"+this.oName,"Clean",this.oName+".doCmd('RemoveFormat')",this.scriptPath+"icons/"+"btn_clean.gif");
	
	if(this.btnHTMLSource) sHTMLIcons+=writeIcon("idHTMLSource"+this.oName,"View/Edit Source","window.showModalDialog('"+this.scriptPath+"source_html.htm',window,'dialogWidth:600px;dialogHeight:555px;edge:Raised;center:Yes;help:No;resizable:Yes;status:No')",this.scriptPath+"icons/"+"btn_html.gif");
	if(this.btnXHTMLSource) sHTMLIcons+=writeIcon("idXHTMLSource"+this.oName,"View/Edit Source","window.showModalDialog('"+this.scriptPath+"source_xhtml.htm',window,'dialogWidth:600px;dialogHeight:555px;edge:Raised;center:Yes;help:No;resizable:Yes;status:No')",this.scriptPath+"icons/"+"btn_xhtml.gif");
	
	if(this.btnClearAll) sHTMLIcons+=writeIcon("idClearAll"+this.oName,"Clear All",this.oName+".clearAll()",this.scriptPath+"icons/"+"btn_clearall.gif");
	/******** /ICONS ********/
	
	var sHTML="";
	sHTML+="<table id=idArea"+this.oName+" name=idArea"+this.oName+" border=0 cellpadding=0 cellspacing=0 width='"+this.width+"' height='"+this.height+"'>" +
			"<tr><td bgcolor=#e0e0e0 style='padding-top:3;padding-left:1;filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#f1f1f1, endColorstr=#d4d4d4);'>" +
			"<span id=idIcons"+this.oName+" name=idIcons"+this.oName+">" +
				sHTMLIcons + //icons
				sHTMLDropMenus + //dropdown
			"</span>" +
			"</td></tr><tr><td valign=top height=100%>";

	//Add security='restricted' => Your current security settings prohibit running ActiveX controls on this page. As a result, the page may not display correctly.
	sHTML+="<iframe style='width:100%;height:100%;margin-top:1;' src='"+this.scriptPath+"icons/"+"blank.gif'" +
					" name=idContent"+ this.oName + " id=idContent"+ this.oName +
					" contentEditable=true onfocus=\"oUtil.oName='"+ this.oName +"';"+this.oName+".hide()\" onblur=\""+this.oName+".doBlur()\"></iframe>";

	//Paste From Word Temp. Area
	sHTML+="<iframe style='width:1;height:1;overflow:auto;' src='"+this.scriptPath+"icons/"+"blank.gif'" +
					" name=idContentWord"+ this.oName +" id=idContentWord"+ this.oName +
					" contentEditable=true onfocus='"+this.oName+".hide()'></iframe>";
					
	sHTML+="</td></tr></table>";
	
	document.write(sHTML)
	
	//paste from word temp storage
	var oWord = eval("idContentWord"+this.oName);
	oWord.document.designMode = "on";
	oWord.document.open("text/html","replace");
	oWord.document.write("<html><head></head><body></body></html>");
	oWord.document.close();

	//realTime
	if(!document.getElementById("btnRealTime"))
		{
		document.write("<input type=button style='width:1;height:1' id=btnRealTime name=btnRealTime>");
		}

	oUtil.oName=this.oName;//default active editor
	}


/*********************
	CONTENT
**********************/
function loadHTML(sHTML)//hanya utk first load.
	{
	var oEditor=eval("idContent"+this.oName);

	var oDoc = oEditor.document.open("text/html", "replace");
	if(this.publishingPath!="")
		sHTML="<BASE HREF=\""+this.publishingPath+"\"/>" + sHTML;
	oDoc.write(sHTML);
	oDoc.close();

	oEditor.document.body.contentEditable=true;
	oEditor.document.execCommand("2D-Position", true, true);//make focus
	oEditor.document.execCommand("MultipleSelection", true, true);//make focus
	oEditor.document.execCommand("LiveResize", true, true);//make focus

	//realTime
	oEditor.document.body.onkeydown = new Function("editorDoc_onkeydown('" + this.oName + "')");
	oEditor.document.body.onkeyup = new Function("editorDoc_onkeyup('" + this.oName + "')");
	oEditor.document.body.onmouseup = new Function("editorDoc_onmouseup('" + this.oName + "')");

	//Styles
	var oElement=oEditor.document.createElement("<STYLE>");
	oEditor.document.childNodes[0].childNodes[0].appendChild(oElement);
	for(var i=0;i<this.arrStyle.length;i++)
		{
		selector = this.arrStyle[i][0];
		style = this.arrStyle[i][3];
		oEditor.document.styleSheets(0).addRule(selector,style);
		}

	//*** RUNTIME BORDERS ***
	eval(this.oName).runtimeBorder(false);
	//***********************	
	
	//fix undisplayed content
	if(this.initialRefresh)
		{
		oEditor.document.execCommand("SelectAll")
		window.setTimeout("eval('idContentWord"+this.oName+"').document.execCommand('SelectAll');",0);
		}
	
	oEditor.document.body.style.width=50;
	oEditor.document.body.style.height=50;
	oEditor.document.body.style.width="";
	oEditor.document.body.style.height="";
	//oEditor.document.body.style.cssText="overflow-x:scroll;overflow-y:scroll";
	}

function loadHTMLStatic(sHTML)//Not Recommended
	{
	var oEditor=eval("idContent"+this.oName);

	var oDoc = oEditor.document.open("text/html", "replace");
	if(this.publishingPath!="")
		{
		if(sHTML.indexOf("<BASE")==-1)
			{
			sHTML="<BASE HREF=\""+this.publishingPath+"\"/>" + sHTML;
			}
		}
	oDoc.write(sHTML);
	oDoc.close();
	
	oEditor.document.body.contentEditable=true;
	oEditor.document.execCommand("2D-Position", true, true);//make focus
	oEditor.document.execCommand("MultipleSelection", true, true);//make focus
	oEditor.document.execCommand("LiveResize", true, true);//make focus

	//realTime
	oEditor.document.body.onkeydown = new Function("editorDoc_onkeydown('" + this.oName + "')");
	oEditor.document.body.onkeyup = new Function("editorDoc_onkeyup('" + this.oName + "')");
	oEditor.document.body.onmouseup = new Function("editorDoc_onmouseup('" + this.oName + "')");
	
	//*** RUNTIME BORDERS ***
	eval(this.oName).runtimeBorder(false);
	//***********************	
	}
	
function putHTML(sHTML)
	{
	var oEditor=eval("idContent"+this.oName);
	
	var oDoc = oEditor.document.open("text/html", "replace");
	oDoc.write(sHTML);	
	oDoc.close();
	oEditor.document.body.contentEditable=true;
	oEditor.document.execCommand("2D-Position", true, true);
	oEditor.document.execCommand("MultipleSelection", true, true);
	oEditor.document.execCommand("LiveResize", true, true);
	
	//realTime
	oEditor.document.body.onkeydown = new Function("editorDoc_onkeydown('" + this.oName + "')");
	oEditor.document.body.onkeyup = new Function("editorDoc_onkeyup('" + this.oName + "')");
	oEditor.document.body.onmouseup = new Function("editorDoc_onmouseup('" + this.oName + "')");
	}
function getHTML()//RICH Mode
	{
	var oEditor=eval("idContent"+this.oName);
	sHTML = oEditor.document.documentElement.outerHTML;
	sHTML = jsReplace(sHTML," contentEditable=true","");
	return sHTML;
	}
function getHTMLBody()//RICH Mode
	{
	var oEditor=eval("idContent"+this.oName);
	sHTML = oEditor.document.body.innerHTML;
	sHTML = jsReplace(sHTML," contentEditable=true","");
	return sHTML;
	}
function getXHTML()
	{
	var oEditor=eval("idContent"+this.oName);

	var sXHTMLTemplate = '<?xml version="1.0" encoding="iso-8859-1"?>\n'
	sXHTMLTemplate += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
	sXHTMLTemplate += '<html  xmlns="http://www.w3.org/1999/xhtml">'
	sHTML = sXHTMLTemplate;//sXHTMLTemplate can be changed here
	sHTML += recur(oEditor.document.documentElement,""); //content inside html tag (head, body)
	sHTML += "\n</html>";
	return sHTML;
	}
function getXHTMLBody()
	{
	var oEditor=eval("idContent"+this.oName);
	sHTML = recur(oEditor.document.body,""); //content inside html tag (head, body)
	return sHTML;
	}

/*********************
	REALTIME
**********************/
function editorDoc_onkeydown(oName)
	{
	realTime(oName);
	}
function editorDoc_onkeyup(oName)
	{
	realTime(oName);
	}
function editorDoc_onmouseup(oName)
	{
	realTime(oName);
	}
function realTime(oName)
	{
	document.all.btnRealTime.click()
	}

/*********************
	RUNTIME BORDERS
**********************/
function runtimeBorderOn()
	{
	eval(this.oName).runtimeBorderOff();//reset

	var oEditor=eval("idContent"+this.oName);
	var oTables = oEditor.document.getElementsByTagName("TABLE");
	for (i=0;i<oTables.length;i++)
		{
		if(oTables[i].border==0)
			{
			for(j=0;j<oTables[i].getElementsByTagName("TD").length;j++)
				{
				if(oTables[i].getElementsByTagName("TD")[j].style.borderLeftWidth=="0px"||
					oTables[i].getElementsByTagName("TD")[j].style.borderLeftWidth=="" ||
					oTables[i].getElementsByTagName("TD")[j].style.borderLeftWidth=="medium")
						{
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderLeftWidth=1;
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderLeftColor = "#BCBCBC";
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderLeftStyle = "dotted";
						}
				if(oTables[i].getElementsByTagName("TD")[j].style.borderRightWidth=="0px"||
					oTables[i].getElementsByTagName("TD")[j].style.borderRightWidth=="" ||
					oTables[i].getElementsByTagName("TD")[j].style.borderRightWidth=="medium")
						{
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderRightWidth=1;
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderRightColor = "#BCBCBC";
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderRightStyle = "dotted";
						}
				if(oTables[i].getElementsByTagName("TD")[j].style.borderTopWidth=="0px"||
					oTables[i].getElementsByTagName("TD")[j].style.borderTopWidth=="" ||
					oTables[i].getElementsByTagName("TD")[j].style.borderTopWidth=="medium")
						{
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderTopWidth=1;
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderTopColor = "#BCBCBC";
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderTopStyle = "dotted";
						}
				if(oTables[i].getElementsByTagName("TD")[j].style.borderBottomWidth=="0px"||
					oTables[i].getElementsByTagName("TD")[j].style.borderBottomWidth=="" ||
					oTables[i].getElementsByTagName("TD")[j].style.borderBottomWidth=="medium")
						{
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderBottomWidth=1;
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderBottomColor = "#BCBCBC";
						oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderBottomStyle = "dotted";
						}
					}
				}
			}
	}
function runtimeBorderOff()
	{
	var oEditor=eval("idContent"+this.oName);
	var oTables = oEditor.document.getElementsByTagName("TABLE");
	for (i=0;i<oTables.length;i++)
		{
		if(oTables[i].border==0)
			{
			for(j=0;j<oTables[i].getElementsByTagName("TD").length;j++)
				{
				oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderWidth = "";
				oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderColor = "";
				oTables[i].getElementsByTagName("TD")[j].runtimeStyle.borderStyle = "";
				}
			}
		}
	}
function runtimeBorder(bToggle)
	{
	if(bToggle)
		{
		if(this.IsRuntimeBorderOn)
			{
			this.runtimeBorderOff();
			this.IsRuntimeBorderOn=false;
			}
		else
			{
			this.runtimeBorderOn();
			this.IsRuntimeBorderOn=true;
			}
		}
	else
		{
		if(this.IsRuntimeBorderOn)
			{
			this.runtimeBorderOn();
			}
		else
			{
			this.runtimeBorderOff();
			}
		}
	}

/*********************
	TOOLBAR ICONS
**********************/
function writeIcon(id,title,command,img)
	{
	sHTML="" +
		"<span unselectable='on' id='span_"+id+"' style='margin-left:0;margin-right:1;margin-bottom:1;width:24;height:23;'>" +
		"<span unselectable='on' style='position:absolute;clip: rect(0 24 23 0)'>" +
		"<img unselectable='on' id='"+id+"' btntoggle=true title='"+title+"' src='"+img+"' style='position:absolute;top:-0;width:24'" +
		"	onmouseover='this.style.top=-23'" +
		"	onmouseout='this.style.top=0'" +
		"	onmousedown='this.style.top=-(2*23)'" +
		"	onmouseup=\"this.style.top=0;"+command+";\">" +
		"</span></span>";
	return sHTML;
	}
function writeIcon2(id,title,caption,command,img,width)
	{
	sHTML="" +
		"<span unselectable='on' id='span_"+id+"' style='margin-left:0;margin-right:1;margin-bottom:1;width:"+width+";height:23;'>" +
		"<span unselectable='on' style='position:absolute;clip: rect(0 "+width+" 23 0)'>" +
		"<img unselectable='on' id='"+id+"' btntoggle=true title='"+title+"' src='"+img+"' style='position:absolute;top:-0;width:"+width+"'" +
		"	onmouseover='this.style.top=-23'" +
		"	onmouseout='this.style.top=0'" +
		"	onmousedown='this.style.top=-(2*23)'" +
		"	onmouseup=\"this.style.top=0;"+command+";\">" +
		"</span></span>";
	return sHTML;
	}


/*********************
	OTHERS
**********************/
function doCmd(sCmd,sOption)
	{
	//Focus stuff
	if(!eval(this.oName).checkFocus())return;

	var oEditor=eval("idContent"+this.oName);
	var oSel=oEditor.document.selection.createRange();
	var sType=oEditor.document.selection.type;
	var oTarget=(sType=="None" ? oEditor.document : oSel);
	oTarget.execCommand(sCmd, false, sOption);
	}

function applyParagraph(val)
	{
	eval(this.oName).hide();
	eval("idContent"+this.oName).focus();

	eval(this.oName).doCmd("FormatBlock",val);
	}
function applyFontName(val)
	{
	eval(this.oName).hide();
	eval("idContent"+this.oName).focus();

	eval(this.oName).doCmd("fontname",val);
	}
function applyFontSize(val)
	{
	eval(this.oName).hide();
	eval("idContent"+this.oName).focus();

	eval(this.oName).doCmd("fontsize",val);
	}

function dropShow(btnID,box)
	{
	eval(this.oName).hide();

	box.style.display="block";

	var sTmp="";
	var nTop=0;
	while(eval("document.all." + btnID + sTmp).tagName!="BODY")
		{
		nTop +=eval("document.all." + btnID + sTmp).offsetTop;
		sTmp +=".offsetParent";
		}

	var nLeft=0; sTmp="";
	while(eval("document.all." + btnID + sTmp).tagName!="BODY")
		{
		nLeft +=eval("document.all." + btnID + sTmp).offsetLeft;
		sTmp +=".offsetParent";
		}

	box.style.left=nLeft;
	box.style.top=nTop + 24;
	box.focus();
	}

function modelessDialogShow(url,width,height)
	{
	window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;resizable:No;status:No");
	}
function modalDialogShow(url,width,height)
	{
	window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;resizable:No;status:No");
	}

function hide()
	{
	if(this.btnTextFormatting || this.btnStyles || this.btnCssText) eval("dropStyle").style.display="none";
	if(this.btnParagraph) eval("dropParagraph"+this.oName).style.display="none";
	if(this.btnFontName) eval("dropFontName"+this.oName).style.display="none";
	if(this.btnFontSize) eval("dropFontSize"+this.oName).style.display="none";
	if(this.btnTable) eval("dropTable").style.display="none";
	}

function jsReplace(sText, sFind, sReplace)
	{
	var arrTmp = sText.split(sFind);
	if (arrTmp.length > 1) sText = arrTmp.join(sReplace);
	return sText;
	}

function pasteWord()
	{
	//Focus stuff
	if(!eval(this.oName).checkFocus())return;

	var oEditor = eval("idContent"+this.oName);
	var oWord = eval("idContentWord"+this.oName);
	oEditor.focus();
	var oSel = oEditor.document.selection.createRange();

	if(oSel.parentElement)
		{
		oWord.focus();
		oWord.document.execCommand("SelectAll");
		oWord.document.execCommand("Paste");

		for (var i = 0; i < oWord.document.body.all.length; i++)
			{
			oWord.document.body.all[i].removeAttribute("className","",0);
			oWord.document.body.all[i].removeAttribute("style","",0);
			}
		var str = oWord.document.body.innerHTML;

		str = String(str).replace(/<\\?\?xml[^>]*>/g, "");
		str = String(str).replace(/<\/?o:p[^>]*>/g, "");	
		str = String(str).replace(/<\/?SPAN[^>]*>/g, "");	
		str = String(str).replace(/<\/?v:[^>]*>/g, "");
		str = String(str).replace(/<\/?o:[^>]*>/g, "");
		str = String(str).replace(/&nbsp;/g, "");

		oSel.pasteHTML(str);
		}
	}

function insertHTML(sHTML)
	{
	//Focus stuff
	if(!eval(this.oName).checkFocus())return;

	var oEditor = eval("idContent"+this.oName);
	var oSel = oEditor.document.selection.createRange();

	if(oSel.parentElement) oSel.pasteHTML(sHTML);
	else oSel.item(0).outerHTML = sHTML;
	}

function insertLink(url)
	{
	//Focus stuff
	if(!eval(this.oName).checkFocus())return;

	var oEditor = eval("idContent"+this.oName);
	var oSel = oEditor.document.selection.createRange();

	if(oSel.parentElement)
		{
		if(oSel.text=="")//If no (text) selection, then build selection using the typed URL
			{
			var oSelTmp=oSel.duplicate();
			oSel.text=url;
			oSel.setEndPoint("StartToStart",oSelTmp);
			oSel.select();
			}
		}
	oSel.execCommand("CreateLink",false,url);
	}
	
function clearAll()
	{
	if (confirm("Are you sure you wish to delete all content?") == true) 
		{
		var oEditor=eval("idContent"+this.oName);
		oEditor.document.body.innerHTML="";
		}
	}

/************************
	HTML to XHTML
************************/
function trimComment(sTmp)//hanya utk recur2() => SCRIPT & STYLE
	{
	//Remove <!-- --> and spaces at the beginning & end of text
	var arrTmp = sTmp.split("<!--<![CDATA[");
	if (arrTmp.length > 1) 
		{
		if(arrTmp[0].replace(/^\s+/,'').replace(/\s+$/,'')=="") 
			sTmp = arrTmp[1];
		}
	arrTmp = sTmp.split("]]>-->");
	if (arrTmp.length > 1) 
		{
		if(arrTmp[1].replace(/^\s+/,'').replace(/\s+$/,'')=="")
			sTmp = arrTmp[0]
		}
	sTmp=sTmp.replace(/^\s+/,'').replace(/\s+$/,'');
	return sTmp;
	}
function fixXMLa(s)//attribute
	{
	s = String(s).replace(/&/g, "&amp;");
	s = String(s).replace(/</g, "&lt;");
	s = String(s).replace(/"/g, "&quot;");
	return s;
	}
function fixXMLb(s)//node value
	{
	s = String(s).replace(/&/g, "&amp;");
	s = String(s).replace(/</g, "&lt;");
	return s;
	}
function recur(oEl)
	{
	var sHTML="";
	for(var i=0;i<oEl.childNodes.length;i++)
		{
		var oNode=oEl.childNodes(i);		
		if(oNode.nodeType==1)//tag
			{			
			//Extract Attributes
			var sAttrName = "";
			var arrAttrName = [];
			var sTmp = oNode.outerHTML.split(">")[0];
			for(var k=0;k<oNode.attributes.length;k++)
				{
				attrName=oNode.attributes[k].nodeName;							
				if(sTmp.indexOf(" "+attrName+"=")!=-1)
					{
					if(attrName.toLowerCase()!="contenteditable")
						sAttrName+=",'" + attrName + "'";
					}				
				}			
			if(sAttrName!="") arrAttrName = eval("["+sAttrName.substr(1)+"]");

			var sTagName = oNode.nodeName;	
			
			//special fix : <THEAD></THEAD><TBODY></TBODY><TR></TR>
			if(sTagName.substr(0,1)!="/") 
				{
				//OPENING TAG		
				sHTML+= "<" + sTagName.toLowerCase();
				
				/*****************************************************
								IMPORTANT
				******************************************************/
				
				//NAVIGATE THE ATTRIBUTES
				for(var j=0;j<arrAttrName.length;j++)
					{
					var sName = arrAttrName[j];
					
					if(sTagName.toLowerCase()=="hr")
						{
						if(sName.toLowerCase()=="noshade" || sName.toLowerCase()=="size")//UNSUPPORTED Attributes (LEAVE the Attributes)
							{
							sName="";
							}
						else
							{
							try {var sValue = eval("oNode.attributes."+arrAttrName[j]+".nodeValue");}//OK (Set the Value)
							catch(e) {sName="";}//UNSUPPORTED Attributes (LEAVE the Attributes)
							}
						}
					else if(sTagName.toLowerCase()=="a" && sName.toLowerCase()=="href")//FIX THE VALUE
						{
						sTmp=oNode.outerHTML;
						sTmp=sTmp.substring(sTmp.indexOf(" href=")+7);
						sTmp=sTmp.substring(0,sTmp.indexOf('"'));
						var arrTmp = sTmp.split("&amp;");
						if (arrTmp.length > 1) sTmp = arrTmp.join("&");		
						var sValue=sTmp	
						}					
					else if(sTagName.toLowerCase()=="img" && sName.toLowerCase()=="src")//FIX THE VALUE
						{
						sTmp=oNode.outerHTML;
						sTmp=sTmp.substring(sTmp.indexOf(" src=")+6);
						sTmp=sTmp.substring(0,sTmp.indexOf('"'));
						var arrTmp = sTmp.split("&amp;");
						if (arrTmp.length > 1) sTmp = arrTmp.join("&");		
						var sValue=sTmp	
						}
					else if(sName.toLowerCase()=="class")//FIX THE VALUE
						{
						var sValue = oNode.className;
						}
					else if(sName.toLowerCase()=="style")//FIX THE VALUE
						{
						var sValue=oNode.style.cssText;
						}	
					else
						{
						try {var sValue = eval("oNode.attributes."+arrAttrName[j]+".nodeValue");}//OK (Set the Value)
						catch(e) {sName="";}//UNSUPPORTED Attributes (LEAVE the Attributes)
						}												

					if(sName!="")//OK
						{			
						sHTML+= " " + sName.toLowerCase() + "=\"" + fixXMLa(sValue) + "\"";
						}
					}	
					
				//UNSUPPORTED; CATCH the UNSUPPORTED Attributes & Add before the closing tag
				if(sTagName.toLowerCase()=="hr")
					{
					if(oNode.noShade)
						{	
						sHTML+= " noshade=\"noshade\"";
						}
					if(oNode.size!="")
						{
						sHTML+= " size=\""+oNode.size+"\"";
						}
					}					
				if(oNode.outerHTML.indexOf(" CHECKED ")!=-1)
					if(oNode.nodeName!="BODY" && oNode.nodeName!="BASE") sHTML+= " checked=\"checked\"";//ternyata BODY ada attr CHECKED

				/*****************************************************
								/IMPORTANT
				******************************************************/
				
				//CLOSING TAG
				if(sTagName=="IMG" || sTagName=="BR" || sTagName=="AREA" || sTagName=="HR" || sTagName=="INPUT" || sTagName=="BASE")//If Element doesn't need Closing Tag
					sHTML+= " />"; //doesn't need closing tag
				else
					{		
					sHTML+= ">";
					if(sTagName=="SCRIPT") 
						{
						var sTmp=trimComment(oNode.innerHTML);
						sHTML+= "<!--<![CDATA[\n"+sTmp+"\n]]>-->";
						}
					else if(sTagName=="STYLE") 
						{
						var sTmp=trimComment(oNode.innerHTML);	
						sHTML+= "<!--<![CDATA[\n"+sTmp+"\n]]>-->";
						}
					else if(sTagName=="TITLE") 
						sHTML+= oNode.innerHTML; 
					else
						sHTML+=recur(oNode);
					sHTML+= "</" + sTagName.toLowerCase() + ">"; //example: </TABLE>
					}
				}
			}
		else if(oNode.nodeType==3)//text
			sHTML+= fixXMLb(oNode.nodeValue);
		else if(oNode.nodeType==8)//comments	
			{
			var sTmp=trimComment(oNode.nodeValue);			
			sHTML+= "<!--\n"+sTmp+"\n-->";
			}
		else
			sHTML+= "<!-- Not Processed :"+ sTagName + " - " + oNode.nodeValue+"-->";	
		}
	return sHTML;
	}
