// Cross-Browser Rich Text Editor
// http://www.kevinroth.com/rte/demo.htm
// Written by Kevin Roth (kevin@NOSPAMkevinroth.com - remove NOSPAM)
// Visit the support forums at http://www.kevinroth.com/forums/index.php?c=2
//init variables
//=========================
// Edit by Vuth
// Edit Date 07-Jan-2007
// Edit Font kh2004a
//=========================
var isRichText = false;
var rng;
var currentRTE;
var allRTEs = "";

var isIE;
var isGecko;
var isSafari;
var isKonqueror;

var imagesPath;
var includesPath;
var cssFile;
//============================Start Pop Up Function=======================================
var w3c=(document.getElementById)? true: false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;

var idlist=new Array();
idlist.btns=new Array();
idlist.btns[0]=new Image(); idlist.btns[0].src="min.gif";
idlist.btns[1]=new Image(); idlist.btns[1].src="max.gif";
idlist.btns[2]=new Image(); idlist.btns[2].src="close.gif";
idlist.btns[3]=new Image(); idlist.btns[3].src="resize.gif";

function truebody(){ //Dynamic Drive added function
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidebox(id){
if(w3c){
document.getElementById(id+'_b').style.display='none';
document.getElementById(id+'_s').style.display='none';
}}

function showbox(id,rte_id){
//getObj('txtpastfromword');
if(w3c){
var bx=document.getElementById(id+'_b').style;
var sh=document.getElementById(id+'_s').style;
bx.display='block';
sh.display='block';
sh.zIndex=++zdx;
bx.zIndex=++zdx;
}
initIFRAME();
document.getElementById('pastfw').value = rte_id;
}
//Enable Iframe Design Mode
//======Start=======
function initIFRAME() {
	var rte_pfw = document.getElementById('rte_pfw');
	rte_pfw.onload = null;
	clearTimeout(rte_pfw.onloadTimeout);
	var rte_pfw_content = rte_pfw.contentWindow.document;
	rte_pfw_content.designMode = 'on';
	setTimeout(function() {
	rte_pfw_content.body.innerHTML = '';
	rte_pfw_content.designMode = 'on';
	}, 0);
}
//======End=======
function minimize(){
if(w3c){
this.IDS[0].style.height=(ie5)? '28px':'24px';
this.IDS[3].style.height='28px';
this.IDS[2].style.display='none';
this.IDS[4].style.display='none';
setTimeout('ns6bugfix()',100);
}}

function restore(){
if(w3c){
var h=this.IDS[10];
this.IDS[0].style.height=h+'px'; //box
this.IDS[3].style.height=(ie5)? h+'px':h+5+'px'; //shd
this.IDS[2].style.display='block';
this.IDS[4].style.display='block'; 
setTimeout('ns6bugfix()',100);
}}

function ns6bugfix(){
self.resizeBy(0,1);
self.resizeBy(0,-1);
}

function trackmouse(evt){
mx=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
my=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
if(!ns6)movepopup();
if((currIDb!=null)||(currRS!=null))return false;
}

function movepopup(){
if((currIDb!=null)&&w3c){
var x=mx+xoff;
var y=my+yoff;
currIDb.style.left=x+'px';
currIDs.style.left=x+8+'px';
currIDb.style.top=y+'px';
currIDs.style.top=y+8+'px';
}
if((currRS!=null)&&w3c){
var rx=mx+rsxoff;
var ry=my+rsyoff;
var c=currRS;
c.style.left=Math.max(rx,((ie5)?88:92))+'px';
c.style.top=Math.max(ry,((ie5)?68:72))+'px';
c.IDS[0].style.width=Math.max(rx+((ie5)?12:8),100)+'px';
c.IDS[0].style.height=Math.max(ry+((ie5)?12:8),80)+'px';
c.IDS[1].style.width=Math.max(rx+((ie5)?4:3),((ns6)?95:92))+'px';
c.IDS[5].style.left=parseInt(c.IDS[1].style.width)-48+'px';
c.IDS[3].style.width=Math.max(rx+12,((ie5)?100:104))+'px';
c.IDS[3].style.height=Math.max(ry+((ie5)?12:13),((ie5)?80:86))+'px';
c.IDS[2].style.width=Math.max(rx-((ie5)?-5:5),((ie5)?92:87))+'px';
c.IDS[2].style.height=Math.max(ry-((ie5)?24:28),44)+'px';
c.IDS[10]=parseInt(c.IDS[0].style.height);
}}

function startRS(evt){
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(ns6)this.IDS[2].style.overflow='hidden';
return false;
}

function stopdrag(){
currIDb=null;
ns6bugfix();
}

function grab_id(evt){
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
xoff=parseInt(this.IDS[0].style.left)-ex;
yoff=parseInt(this.IDS[0].style.top)-ey;
currIDb=this.IDS[0];
currIDs=this.IDS[3];
return false;
}

function subBox(x,y,w,h,bgc,id){
var v=document.createElement('div');
v.setAttribute('id',id); 
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';
v.style.backgroundColor=bgc;
v.style.visibility='visible';
v.style.padding='0px 0px 0px 0px';
return v;
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}


function popUp(x,y,w,h,cid,text,bgcolor,textcolor,fontstyleset,title,titlecolor,titletextcolor,bordercolor,scrollcolor,shadowcolor,showonstart,isdrag,isresize,oldOK,POPPERSESSION){
var proceedtopop=false
if (POPPERSESSION){
if (get_cookie(cid)==""){
proceedtopop=true
document.cookie=cid+"=yes"
}
}
else
proceedtopop=true

if (proceedtopop){
if(w3c){
var tw, th;
w=Math.max(w,100);
h=Math.max(h,80);
var rdiv=new subBox(w-((ie5)?12:8),h-((ie5)?12:8),7,7,'',cid+'_rs');
if(isresize){
rdiv.innerHTML='<img src="'+imagesPath+'resize.gif" width="7" height="7">';
rdiv.style.cursor='move';
}
tw=(ie5)?w:w+4;
th=(ie5)?h:h+6;
var shadow=new subBox(x+8,y+8,tw,th,shadowcolor,cid+'_s');
if(ie5)shadow.style.filter="alpha(opacity=50)";
else shadow.style.MozOpacity=.5;
shadow.style.zIndex=++zdx;
var tw,th;
var outerdiv=new subBox(x,y,w,h,bordercolor,cid+'_b');
outerdiv.style.borderStyle="outset";
outerdiv.style.borderWidth="2px";
outerdiv.style.borderColor=bordercolor;
outerdiv.style.zIndex=++zdx;
tw=(ie5)?w-8:w-5;
th=(ie5)?h+4:h-4;
var titlebar=new subBox(2,2,tw,20,titlecolor,cid+'_t');
titlebar.style.overflow="hidden";
titlebar.style.cursor="default";
titlebar.innerHTML='<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><span id="'+cid+'_btt" style="position:absolute; width:48px; height:16px; left:'+(tw-48)+'px; top:2px;"><img src="'+imagesPath+'min.gif" width="16" height="16" id="'+cid+'_min"><img src="'+imagesPath+'max.gif" width="16" height="16"  id="'+cid+'_max"><img src="'+imagesPath+'close.gif" width="16" height="16" id="'+cid+'_cls"></span>';
tw=(ie5)?w-7:w-13;
th=(ie5)?h-36:h-36;
var content=new subBox(2,24,tw,th,bgcolor,cid+'_c');
content.style.borderColor=bordercolor;
content.style.borderStyle="inset";
content.style.borderWidth="2px";
content.style.overflow="auto";
content.style.padding="0px 2px 0px 4px";
content.style.font=fontstyleset;
content.style.color=textcolor;
if(ie5)content.style.scrollbarBaseColor=scrollcolor;
content.innerHTML=text;
outerdiv.appendChild(titlebar);
outerdiv.appendChild(content);
outerdiv.appendChild(rdiv);
document.body.appendChild(shadow);
document.body.appendChild(outerdiv);
if(!showonstart)hidebox(cid);
var IDS=new Array();
IDS[0]=document.getElementById(cid+'_b');
IDS[1]=document.getElementById(cid+'_t');
IDS[2]=document.getElementById(cid+'_c');
IDS[3]=document.getElementById(cid+'_s');
IDS[4]=document.getElementById(cid+'_rs');
IDS[5]=document.getElementById(cid+'_btt');
IDS[6]=document.getElementById(cid+'_min');
IDS[7]=document.getElementById(cid+'_max');
IDS[8]=document.getElementById(cid+'_cls');
IDS[9]=cid;
IDS[10]=h;
this.IDb=IDS[0]; this.IDb.IDS=IDS;
this.IDt=IDS[1]; this.IDt.IDS=IDS;
this.IDc=IDS[2]; this.IDc.IDS=IDS;
this.IDs=IDS[3]; this.IDs.IDS=IDS;
this.IDrs=IDS[4]; this.IDrs.IDS=IDS;
this.IDbtt=IDS[5]; this.IDbtt.IDS=IDS;
this.IDmin=IDS[6]; this.IDmin.IDS=IDS;
this.IDmax=IDS[7]; this.IDmax.IDS=IDS;
this.IDcls=IDS[8]; this.IDcls.IDS=IDS;
this.IDb.activecolor=titlecolor;
this.IDb.inactivecolor=scrollcolor;
if(oldac!=null)oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
oldac=this.IDb;
this.IDcls.onclick=new Function("hidebox('"+cid+"');");
if(isresize){
this.IDmin.onclick=minimize;
this.IDmax.onclick=restore;
this.IDrs.onmousedown=startRS;
this.IDrs.onmouseup=new Function("currRS=null");
}
this.IDb.onmousedown=function(){
   if(oldac!=null){
   oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
   }
   if(ns6)this.IDS[2].style.overflow='auto';
   oldac=this;
   this.IDS[1].style.backgroundColor=this.activecolor;
   this.IDS[3].style.zIndex=++zdx;
   this.style.zIndex=++zdx;
   }
if(isdrag){
this.IDt.onmousedown=grab_id;
this.IDt.onmouseup=stopdrag;
}
}else{
if(oldOK){
var ctr=new Date();
ctr=ctr.getTime();
var win=window.open("" , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable=yes,scrollbars=yes");
var t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
win.document.write(t);
win.document.close();
}}}}

if(ns6)setInterval('movepopup()',40);

if(w3c){
document.onmousemove=trackmouse;
document.onmouseup=new Function("currRS=null");
}
function getObj(name) { 
    return (document.getElementById && document.getElementById(name))||document[name]||(document.all && document.all[name]); 
} 
//============================End Pop Up Function=======================================
function initRTE(imgPath, incPath, css) {
	//set browser vars
	//alert(incPath);
		//alert("hello");
	var ua = navigator.userAgent.toLowerCase();
	isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	isGecko = (ua.indexOf("gecko") != -1);
	isSafari = (ua.indexOf("safari") != -1);
	isKonqueror = (ua.indexOf("konqueror") != -1);
	
	//check to see if designMode mode is available
	if (document.getElementById && document.designMode && !isSafari && !isKonqueror) {
		isRichText = true;
	}
	
	if (isIE) {
		document.onmouseover = raiseButton;
		document.onmouseout  = normalButton;
		document.onmousedown = lowerButton;
		document.onmouseup   = raiseButton;
	}
	
	//set paths vars
	imagesPath = imgPath;
	includesPath = incPath;
	cssFile = css;
	
	if (isRichText) document.writeln('<style type="text/css">@import "' + includesPath + 'rte.css";</style>');
	
	//for testing standard textarea, uncomment the following line
	//isRichText = false;
}

function writeRichText(rte, html, width, height, buttons, readOnly) {
	if (isRichText) {
		//alert("isRichText=true");
		if (allRTEs.length > 0) allRTEs += ";";
		allRTEs += rte;
		
		if (readOnly) buttons = false;
		
		//adjust minimum table widths
		if (isIE) {
			if (buttons && (width < 435)) width = 435;
			var tablewidth = width;
		} else {
			if (buttons && (width < 435)) width = 435;
			var tablewidth = width + 4;
		}
		
		document.writeln('<div class="rteDiv">');
		if (buttons == true) {
			document.writeln('<table class="rteBack" cellpadding=2 cellspacing=0 id="Buttons1_' + rte + '" width="' + tablewidth + '">');
			document.writeln('	<tr>');
			document.writeln('		<td>');
//			document.writeln('			<select id="formatblock_' + rte + '" onchange="selectFont(\'' + rte + '\', this.id);">');
//			document.writeln('				<option value="">[Style]</option>');
//			document.writeln('				<option value="<p>">Paragraph &lt;p&gt;</option>');
//			document.writeln('				<option value="<h1>">Heading 1 &lt;h1&gt;</option>');
//			document.writeln('				<option value="<h2>">Heading 2 &lt;h2&gt;</option>');
//			document.writeln('				<option value="<h3>">Heading 3 &lt;h3&gt;</option>');
//			document.writeln('				<option value="<h4>">Heading 4 &lt;h4&gt;</option>');
//			document.writeln('				<option value="<h5>">Heading 5 &lt;h5&gt;</option>');
//			document.writeln('				<option value="<h6>">Heading 6 &lt;h6&gt;</option>');
//			document.writeln('				<option value="<address>">Address &lt;ADDR&gt;</option>');
//			document.writeln('				<option value="<pre>">Formatted &lt;pre&gt;</option>');
//			document.writeln('			</select>');
//			document.writeln('		</td>');
			document.writeln('		<td>');
			document.writeln('			<select id="fontname_' + rte + '" onchange="selectFont(\'' + rte + '\', this.id)">');
			document.writeln('				<option value="Font" selected>[Font]</option>');
			document.writeln('				<option value="Verdana">English</option>');
			document.writeln('				<option value="Limon S1">Khmer</option>');
			document.writeln('			</select>');
			document.writeln('		</td>');
			document.writeln('		<td>');
			document.writeln('			<select unselectable="on" id="fontsize_' + rte + '" onchange="selectFont(\'' + rte + '\', this.id);">');
			document.writeln('				<option value="Size">[Size]</option>');
			document.writeln('				<option value="1">1</option>');
			document.writeln('				<option value="2">2</option>');
			document.writeln('				<option value="3">3</option>');
			document.writeln('				<option value="4">4</option>');
			document.writeln('				<option value="5">5</option>');
			document.writeln('				<option value="6">6</option>');
			document.writeln('				<option value="7">7</option>');
			
			document.writeln('			</select>');
			document.writeln('		</td>');
			document.writeln('		<td><img id="bold" class="rteImage" src="' + imagesPath + 'bold.gif" width="25" height="24" alt="Bold" title="Bold" onClick="rteCommand(\'' + rte + '\', \'bold\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'italic.gif" width="25" height="24" alt="Italic" title="Italic" onClick="rteCommand(\'' + rte + '\', \'italic\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'underline.gif" width="25" height="24" alt="Underline" title="Underline" onClick="rteCommand(\'' + rte + '\', \'underline\', \'\')"></td>');
				document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'left_just.gif" width="25" height="24" alt="Align Left" title="Align Left" onClick="rteCommand(\'' + rte + '\', \'justifyleft\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'centre.gif" width="25" height="24" alt="Center" title="Center" onClick="rteCommand(\'' + rte + '\', \'justifycenter\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'right_just.gif" width="25" height="24" alt="Align Right" title="Align Right" onClick="rteCommand(\'' + rte + '\', \'justifyright\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'justifyfull.gif" width="25" height="24" alt="Justify Full" title="Justify Full" onclick="rteCommand(\'' + rte + '\', \'justifyfull\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'hr.gif" width="25" height="24" alt="Horizontal Rule" title="Horizontal Rule" onClick="rteCommand(\'' + rte + '\', \'inserthorizontalrule\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'numbered_list.gif" width="25" height="24" alt="Ordered List" title="Ordered List" onClick="rteCommand(\'' + rte + '\', \'insertorderedlist\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'list.gif" width="25" height="24" alt="Unordered List" title="Unordered List" onClick="rteCommand(\'' + rte + '\', \'insertunorderedlist\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" onClick="rteCommand(\'' + rte + '\', \'outdent\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'indent.gif" width="25" height="24" alt="Indent" title="Indent" onClick="rteCommand(\'' + rte + '\', \'indent\', \'\')"></td>');

			document.writeln('		<td width="100%">');
			document.writeln('		</td>');
			
			document.writeln('	</tr>');
			document.writeln('</table>');
			document.writeln('<table class="rteBack" cellpadding="0" cellspacing="0" id="Buttons2_' + rte + '" width="' + tablewidth + '">');
			document.writeln('	<tr>');

			document.writeln('		<td><div id="forecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'textcolor.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="dlgColorPalette(\'' + rte + '\', \'forecolor\', \'\')"></div></td>');
			document.writeln('		<td><div id="hilitecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'bgcolor.gif" width="25" height="24" alt="Background Color" title="Background Color" onClick="dlgColorPalette(\'' + rte + '\', \'hilitecolor\', \'\')"></div></td>');
			document.writeln('		<td><div id="emotion_' + rte + '"><img class="rteImage" src="' + imagesPath + 'smiley.gif" width="25" height="24" alt="Emotion express" title="Emotion express" onClick="dlgEmotionPalette(\'' + rte + '\', \'emotion\', \'\')"></div></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'hyperlink.gif" width="25" height="24" alt="Insert Link" title="Insert Link" onClick="insertLink(\'' + rte + '\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'image.gif" width="25" height="24" alt="Add Image" title="Add Image" onClick="addImage(\'' + rte + '\')"></td>');
			document.writeln('		<td><div id="table_' + rte + '"><img class="rteImage" src="' + imagesPath + 'insert_table.gif" width="25" height="24" alt="Insert Table" title="Insert Table" onClick="dlgInsertTable(\'' + rte + '\', \'table\', \'\')"></div></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'pasteword.gif" width="20" height="20" alt="Past From Word" title="Past From Word" onClick="showbox(\'Div\',\'' + rte + '\')"></td>');
//			if (isIE) {
//				document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'spellcheck.gif" width="25" height="24" alt="Spell Check" title="Spell Check" onClick="checkspell()"></td>');
//			}
	//		document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
	//		document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'cut.gif" width="25" height="24" alt="Cut" title="Cut" onClick="rteCommand(\'' + rte + '\', \'cut\')"></td>');
	//		document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'copy.gif" width="25" height="24" alt="Copy" title="Copy" onClick="rteCommand(\'' + rte + '\', \'copy\')"></td>');
	//		document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'paste.gif" width="25" height="24" alt="Paste" title="Paste" onClick="rteCommand(\'' + rte + '\', \'paste\')"></td>');
	//		document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
	//		document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'undo.gif" width="25" height="24" alt="Undo" title="Undo" onClick="rteCommand(\'' + rte + '\', \'undo\')"></td>');
	//		document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'redo.gif" width="25" height="24" alt="Redo" title="Redo" onClick="rteCommand(\'' + rte + '\', \'redo\')"></td>');
			document.writeln('		<td width="100%"></td>');
			document.writeln('	</tr>');
			document.writeln('</table>');
		}
		
		document.writeln('<iframe id="' + rte + '" name="' + rte + '" width="' + width + 'px" height="' + height + 'px" src="' + includesPath + 'blank.htm" class="txtarea"></iframe>');
		
		//document.writeln('<textarea id="' + rte + '" name="' + rte + '" width="' + width + 'px" height="' + height + 'px" class="txtarea"></textarea>');
//		alert(rte);
		if (!readOnly) document.writeln('<br /><div align="left" style="padding-left:' + (width-100) + 'px;"><input type="checkbox" id="chkSrc' + rte + '" onclick="toggleHTMLSrc(\'' + rte + '\');" />&nbsp;View Source</div>');
		document.writeln('<iframe width="154" height="104" id="cp' + rte + '" name="cp' + rte + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" style="visibility:hidden; position: absolute;"></iframe>');
		document.writeln('<iframe width="154" height="174" id="em' + rte +'" name="em'+ rte + '" src="' + includesPath + 'emotion.html" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" style="visibility:hidden; position: absolute;"></iframe>');
		document.writeln('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
		document.writeln('</div>');
		
		document.getElementById('hdn' + rte).value = html;
		enableDesignMode(rte, html, readOnly);
	} else {
		if (!readOnly) {
		document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;">' + html + '</textarea>');
		} else {
		document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;" readonly>' + html + '</textarea>');
		}
	}
}

function enableDesignMode(rte, html, readOnly) {
	var frameHtml = "<html id=\"" + rte + "\" name=\"" + rte + "\">\n";
	frameHtml += "<head>\n";
	//to reference your stylesheet, set href property below to your stylesheet path and uncomment
	if (cssFile.length > 0) {
		frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + cssFile + "\" rel=\"stylesheet\">\n";
	} else {
		frameHtml += "<style>\n";
		frameHtml += "body {\n";
		frameHtml += "	background: #FFFFFF;\n";
		frameHtml += "	margin: 0px;\n";
		frameHtml += "	padding: 0px;\n";
		frameHtml += "}\n";
		frameHtml += "</style>\n";
	}
	frameHtml += "</head>\n";
	frameHtml += "<body>\n";
	frameHtml += html + "\n";
	frameHtml += "</body>\n";
	frameHtml += "</html>";
	//alert(frameHtml);
	if (document.all) {
		var oRTE = frames[rte].document;
		oRTE.open();
		oRTE.write(frameHtml);
		oRTE.close();
		if (!readOnly) oRTE.designMode = "On";
	} else {
		try {
			if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
			try {
				var oRTE = document.getElementById(rte).contentWindow.document;
				oRTE.open();
				oRTE.write(frameHtml);
				oRTE.close();
				if (isGecko && !readOnly) {
					//attach a keyboard handler for gecko browsers to make keyboard shortcuts work
					oRTE.addEventListener("keypress", kb_handler, true);
				}
			} catch (e) {
				alert("Error preloading content.");
			}
		} catch (e) {
			//gecko may take some time to enable design mode.
			//Keep looping until able to set.
			if (isGecko) {
				setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 10);
			} else {
				return false;
			}
		}
	}
}

function updateRTEs() {
	var vRTEs = allRTEs.split(";");
	for (var i = 0; i < vRTEs.length; i++) {
		updateRTE(vRTEs[i]);
	}
}

function updateRTE(rte) {
	if (!isRichText) return;
	
	//set message value
	var oHdnMessage = document.getElementById('hdn' + rte);
	var oRTE = document.getElementById(rte);
	//alert(oRTE.contentWindow.document.body.innerHTML);
	var readOnly = false;
	
	//check for readOnly mode
	if (document.all) {
	if (frames[rte].document.designMode != "On") readOnly = true;
	} else {
	// Change readOnly = false if can not get cotent in fire fox
	// If you changet this we don't need to comment the below if condition
	if (document.getElementById(rte).contentDocument.designMode != "on") readOnly = false;
	}


	if (isRichText && !readOnly) { //Comment this condition to use in fire fox other wish you can not get content
		//if viewing source, switch back to design view
		if (document.getElementById("chkSrc" + rte).checked) {
			document.getElementById("chkSrc" + rte).checked = false;
			toggleHTMLSrc(rte);
		}
		
		if (oHdnMessage.value == null) oHdnMessage.value = "";
		if (document.all) {
			oHdnMessage.value = frames[rte].document.body.innerHTML;
			//alert("Yeas document dot all"+oHdnMessage.value);
		} else {
			oHdnMessage.value = oRTE.contentWindow.document.body.innerHTML;
			//alert("Not docudment dot all"+oHdnMessage.value);
		}
		//if there is no content (other than formatting) set value to nothing
		if (stripHTML(oHdnMessage.value.replace("&nbsp;", " ")) == "" 
			&& oHdnMessage.value.toLowerCase().search("<hr") == -1
			&& oHdnMessage.value.toLowerCase().search("<img") == -1) oHdnMessage.value = "";
		//fix for gecko
		if (escape(oHdnMessage.value) == "%3Cbr%3E%0D%0A%0D%0A%0D%0A") oHdnMessage.value = "";
	}// Comment this breaket if you can not get content in fire fox
//	alert("read only");
}

function rteCommand(rte, command, option) {
	//function to perform command
	var oRTE;
	if (document.all) {
		oRTE = frames[rte];
	//	alert(oRTE.document.body.innerHTML);
	//  alert(oRTE);
	} else {
		oRTE = document.getElementById(rte).contentWindow;
	}
	
	try {
		oRTE.focus();
	  	oRTE.document.execCommand(command, false, option);
		oRTE.focus();
	} catch (e) {
//		alert(e);
//		setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
	}
}

function toggleHTMLSrc(rte) {
	//contributed by Bob Hutzel (thanks Bob!)
	var oRTE;
	if (document.all) {
		oRTE = frames[rte].document;
	} else {
		oRTE = document.getElementById(rte).contentWindow.document;
	}
	
	if (document.getElementById("chkSrc" + rte).checked) {
		showHideElement("Buttons1_" + rte, "hide");
		showHideElement("Buttons2_" + rte, "hide");
		if (document.all) {
			oRTE.body.innerText = oRTE.body.innerHTML;
		} else {
			var htmlSrc = oRTE.createTextNode(oRTE.body.innerHTML);
			oRTE.body.innerHTML = "";
			oRTE.body.appendChild(htmlSrc);
		}
	} else {
		showHideElement("Buttons1_" + rte, "show");
		showHideElement("Buttons2_" + rte, "show");
		if (document.all) {
			//fix for IE
			var output = escape(oRTE.body.innerText);
			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
			
			oRTE.body.innerHTML = unescape(output);
		} else {
			var htmlSrc = oRTE.body.ownerDocument.createRange();
			htmlSrc.selectNodeContents(oRTE.body);
			oRTE.body.innerHTML = htmlSrc.toString();
		}
	}
}

function dlgColorPalette(rte, command) {
	//function to display or hide color palettes
	setRange(rte);
	
	//get dialog position
	var oDialog = document.getElementById('cp' + rte);
	var buttonElement = document.getElementById(command + '_' + rte);
	var iLeftPos = getOffsetLeft(buttonElement);
	var iTopPos = getOffsetTop(buttonElement) + (buttonElement.offsetHeight + 4);
	oDialog.style.left = (iLeftPos) + "px";
	oDialog.style.top = (iTopPos) + "px";
	
	if ((command == parent.command) && (rte == currentRTE)) {
		//if current command dialog is currently open, close it
		if (oDialog.style.visibility == "hidden") {
			showHideElement(oDialog, 'show');
		} else {
			showHideElement(oDialog, 'hide');
		}
	} else {
		//if opening a new dialog, close all others
		var vRTEs = allRTEs.split(";");
		for (var i = 0; i < vRTEs.length; i++) {
			showHideElement('cp' + vRTEs[i], 'hide');
		}
		showHideElement(oDialog, 'show');
	}
	//save current values
	parent.command = command;
	currentRTE = rte;
}
function dlgEmotionPalette(rte){
	//function to show Emotion Palettes	
	setRange(rte)
	//get Emotion Palette position
	var eDialog = document.getElementById('em' + rte);
	var buttonPosition = document.getElementById('emotion_' + rte)
	var eLeftPos = getOffsetLeft(buttonPosition);
	var eTopPos = getOffsetTop(buttonPosition) + (buttonPosition.offsetHeight + 4);
	eDialog.style.left = (eLeftPos) + "px";
	eDialog.style.top = (eTopPos) + "px";
	if(eDialog.style.visibility == "hidden") {
		showHideElement(eDialog, 'show');
	} else {
		showHideElement(eDialog, 'hide');
	}
//save current values
	parent.command = command;
	currentRTE = rte;
}
function InsertEmotion(e_name) {
	var rte = currentRTE;
	var imagePath = "http://www.riikriey.com/blog/rtf/smilies/"+e_name+".gif";
	//var imagePath = "http://linux/newrr/rtf/smilies/"+e_name+".gif";
	//Set Image Emotion
	rteCommand(rte, 'InsertImage', imagePath);
	showHideElement('em' + rte, 'hide');
}
//function Opener(rte, command) {
//	//function to open/close insert table dialog
//	//save current values
//	setRange(rte);
//	parent.command = command;
//	currentRTE = rte;
//	var windowOptions = 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,width=360,height=200';
//	window.open(includesPath + 'upload.php', 'InsertImage', windowOptions);
//}
function dlgInsertTable(rte, command) {
	//function to open/close insert table dialog
	//save current values
	setRange(rte);
	parent.command = command;
	currentRTE = rte;
	var windowOptions = 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,width=360,height=200';
	window.open(includesPath + 'insert_table.htm', 'InsertTable', windowOptions);
}

function insertLink(rte) {
	//function to insert link
	var szURL = prompt("Enter a URL:", "");
	try {
		//ignore error for blank urls
		rteCommand(rte, "Unlink", null);
		rteCommand(rte, "CreateLink", szURL);
	} catch (e) {
		//do nothing
	}
}

function setColorRich(color) {
	//function to set color
	var rte = currentRTE;
	var parentCommand = parent.command;
	//alert(parent.command);
	if (document.all) {
		//retrieve selected range
		var sel = frames[rte].document.selection; 
		if (parentCommand == "hilitecolor") parentCommand = "backcolor";
		if (sel != null) {
			var newRng = sel.createRange();
			newRng = rng;
			newRng.select();
		}
	}
	rteCommand(rte, parentCommand, color);
	//alert(rte);
	//alert(parentCommand);
	//alert(color);
	showHideElement('cp' + rte, "hide");
}

function addImage(rte) {
	//function to add image
	imagePath = prompt('Enter Image URL:', 'http://');				
	if ((imagePath != null) && (imagePath != "")) {
		rteCommand(rte, 'InsertImage', imagePath);
	}
}
// Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
// KJR 11/12/2004 Changed to position palette based on parent div, so palette will always appear in proper location regardless of nested divs
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	var parents_up = 2; //the positioning div is 2 elements up the tree
	
	while(parents_up > 0) {
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetTop;
}

// Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
// KJR 11/12/2004 Changed to position palette based on parent div, so palette will always appear in proper location regardless of nested divs
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	var parents_up = 2;
	
	while(parents_up > 0) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetLeft;
}

function selectFont(rte, selectname) {
	//function to handle font changes
	var idx = document.getElementById(selectname).selectedIndex;
	// First one is always a label
	if (idx != 0) {
		var selected = document.getElementById(selectname).options[idx].value;
		var cmd = selectname.replace('_' + rte, '');
		rteCommand(rte, cmd, selected);
		//alert (idx);
//		if (idx==2){
			//document.getElementById(selectname).selectedIndex = idx;
			document.getElementById(selectname).selectedIndex = 0;
//		}else{
//			document.getElementById(selectname).selectedIndex = 1;
//		}
	}
}

function kb_handler(evt) {
	var rte = evt.target.id;
	
	//contributed by Anti Veeranna (thanks Anti!)
	if (evt.ctrlKey) {
		var key = String.fromCharCode(evt.charCode).toLowerCase();
		var cmd = '';
		switch (key) {
			case 'b': cmd = "bold"; break;
			case 'i': cmd = "italic"; break;
			case 'u': cmd = "underline"; break;
		};

		if (cmd) {
			rteCommand(rte, cmd, null);
			
			// stop the event bubble
			evt.preventDefault();
			evt.stopPropagation();
		}
 	}
}

function insertHTML(html) {
	//function to add HTML -- thanks dannyuk1982
	var rte = currentRTE;
	
	var oRTE;
	if (document.all) {
		oRTE = frames[rte];
	} else {
		oRTE = document.getElementById(rte).contentWindow;
	}
	
	oRTE.focus();
	if (document.all) {
		oRTE.document.selection.createRange().pasteHTML(html);
	} else {
		oRTE.document.execCommand('insertHTML', false, html);
	}
}

function showHideElement(element, showHide) {
	//function to show or hide elements
	//element variable can be string or object
	if (document.getElementById(element)) {
		element = document.getElementById(element);
	}
	
	if (showHide == "show") {
		element.style.visibility = "visible";
	} else if (showHide == "hide") {
		element.style.visibility = "hidden";
	}
}

function setRange(rte) {
	//function to store range of current selection
	var oRTE;
	if (document.all) {
		oRTE = frames[rte];
		var selection = oRTE.document.selection; 
		if (selection != null) rng = selection.createRange();
	} else {
		oRTE = document.getElementById(rte).contentWindow;
		var selection = oRTE.getSelection();
		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
	}
}

function stripHTML(oldString) {
	//function to strip all html
	var newString = oldString.replace(/(<([^>]+)>)/ig,"");
	
	//replace carriage returns and line feeds
   newString = newString.replace(/\r\n/g," ");
   newString = newString.replace(/\n/g," ");
   newString = newString.replace(/\r/g," ");
	
	//trim string
	newString = trim(newString);
	
	return newString;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length - 1);
      ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

//*****************
//IE-Only Functions
//*****************
function checkspell() {
	//function to perform spell check
	try {
		var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
		tmpis.CheckAllLinkedDocuments(document);
	}
	catch(exception) {
		if(exception.number==-2146827859) {
			if (confirm("ieSpell not detected.  Click Ok to go to download page."))
				window.open("http://www.iespell.com/download.php","DownLoad");
		} else {
			alert("Error Loading ieSpell: Exception " + exception.number);
		}
	}
}

function raiseButton(e) {
	//IE-Only Function
	var el = window.event.srcElement;
	
	className = el.className;
	if (className == 'rteImage' || className == 'rteImageLowered') {
		el.className = 'rteImageRaised';
	}
}

function normalButton(e) {
	//IE-Only Function
	var el = window.event.srcElement;
	
	className = el.className;
	if (className == 'rteImageRaised' || className == 'rteImageLowered') {
		el.className = 'rteImage';
	}
}

function lowerButton(e) {
	//IE-Only Function
	var el = window.event.srcElement;
	
	className = el.className;
	if (className == 'rteImage' || className == 'rteImageRaised') {
		el.className = 'rteImageLowered';
	}
}
//===========================
//Include from palette.js
//Get Object from paretn form
//===========================
// JavaScript Document
var palette,command,ell, color = ''; 
var bg_partern;
function setColor(c){ 
    eval(color+'="'+c+'"'); 
} 
function showPalette(el, prop, cmd){
//	alert(palette.style.visibility);
    var elx = (getObjX(el) + 47)+"px";
	var ely = (getObjY(el))+"px";
	if(cmd == "HeaderColor")
	{
		parent.document.forms["frm"].command.value = "HeaderColor";
	}else{
		parent.document.forms["frm"].command.value = "BC";
	}
    color = prop;
//	alert(color);
//	alert(palette.style.position);
	palette.style.left = elx;
//	alert(palette.style.left);
    palette.style.top = ely; 
	palette.style.visibility = 'visible'; 
}
function ShowBg_Partern(){
//	alert(parent.document.forms['frm'].background_image.name);
    var elx = (getObjX(parent.document.forms["frm"].background_image) + 95)+"px";
	var ely = (getObjY(parent.document.forms["frm"].background_image))+"px";
	bg_partern.style.left = elx;
//	alert(bg_partern.name);
//////	alert(bg_partern.name);
    bg_partern.style.top = ely; 
	bg_partern.style.visibility = 'visible'; 
}
function getObj(name) { 
    return (document.getElementById && document.getElementById(name))||document[name]||(document.all && document.all[name]); 
} 
function getObjX(el){ 
    var left = 0; 
    if(el.offsetParent){ 
        while(1){
            left += el.offsetLeft; 
            if(!el.offsetParent)break; 
            el = el.offsetParent; 
        } 
    }else if(el.x)left += el.x; 
    return left; 
} 

function getObjY(el){ 
    var top = 0; 
    if(el.offsetParent){ 
        while(1){ 
            top += el.offsetTop; 
            if(!el.offsetParent)break; 
            el = el.offsetParent; 
        } 
    }else if(el.y)top += el.y; 
    return top; 
} 
function init(){ 
    palette = getObj('palette'); 
	bg_partern = getObj('bg_partern');
	command = getObj('command');
	//tipDiv = getOpj('tipDiv');
} 

//**************************
// past data from word
// By vuth
//**************************

function pastdata()
{
	//alert(document.getElementById('txtpastfromword').value);
	//alert(rte_pfw.document.body.innerHTML);
	var rte_content = rte_pfw.document.body.innerHTML;
	//alert(rte_content);
	rte_content = rte_content.replace(/<o:p>\s*<\/o:p>/g, '') ;
	rte_content = rte_content.replace(/<o:p>.*?<\/o:p>/g, '&nbsp;') ;
	// Remove mso-xxx styles.
	rte_content = rte_content.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;
	// Remove margin styles.
	rte_content = rte_content.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, '' ) ;
	rte_content = rte_content.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

	rte_content = rte_content.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
	rte_content = rte_content.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

	rte_content = rte_content.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

	rte_content = rte_content.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

	rte_content = rte_content.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

	rte_content = rte_content.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
	rte_content = rte_content.replace( /\s*tab-stops:[^"]*/gi, '' ) ;
	// Remove Class attributes
	rte_content = rte_content.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	// Remove XML elements and declarations
	rte_content = rte_content.replace(/<\\?\?xml[^>]*>/gi, '' ) ;

	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	rte_content = rte_content.replace(/<\/?\w+:[^>]*>/gi, '' ) ;

	// Remove comments [SF BUG-1481861].
	rte_content = rte_content.replace(/<\!--.*?-->/g, '' ) ;

	rte_content = rte_content.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	rte_content = rte_content.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	// Remove "display:none" tags.
	rte_content = rte_content.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none(.*?)<\/\1>/ig, '' ) ;

	// Remove language tags
	rte_content = rte_content.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove onmouseover and onmouseout events (from MS Word comments effect)
	rte_content = rte_content.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
	rte_content = rte_content.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;
	// The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
	rte_content = rte_content.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;
	rte_content = rte_content.replace( /<br>/gi, '' ) ;

	// Word likes to insert extra <font> tags, when using MSIE. (Wierd).
	//alert(rte_content);
	rte_content = rte_content.replace( /<(H\d)><FONT[^>]*>(.*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
	rte_content = rte_content.replace( /<(H\d)><EM>(.*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
	rte_content = rte_content.replace( /<H1([^>]*)>/gi, '<div$1>' ) ;
	rte_content = rte_content.replace( /<H2([^>]*)>/gi, '<div$1>' ) ;
	rte_content = rte_content.replace( /<H3([^>]*)>/gi, '<div$1>' ) ;
	rte_content = rte_content.replace( /<H4([^>]*)>/gi, '<div$1>' ) ;
	rte_content = rte_content.replace( /<H5([^>]*)>/gi, '<div$1>' ) ;
	rte_content = rte_content.replace( /<H6([^>]*)>/gi, '<div$1>' ) ;

	rte_content = rte_content.replace( /<\/H\d>/gi, '<\/div>' ) ;

	// Transform <P> to <DIV>
	var re = new RegExp( '(<P)([^>]*>.*?)(<\/P>)', 'gi' ) ;	// Different because of a IE 5.0 error
	rte_content = rte_content.replace( re, '<div$2<\/div>' ) ;
	// Remove empty tags (three times, just to be sure).
	// This also removes any empty anchor
	rte_content = rte_content.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	rte_content = rte_content.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	rte_content = rte_content.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
	//alert(rte_content);
		//Replase Khmer Font
		//====================
		//.*? search all type behine the tage
		rte_content = rte_content.replace(/<div>/gi, '');
		rte_content = rte_content.replace(/<div .*?>/gi, '');
		rte_content = rte_content.replace(/<\/div>/gi, '');
		//Remove Color tage eg (COLOR: #FFGG66; ) to ''
		rte_content = rte_content.replace(/COLOR:\s\#\w{6}\;\s/gi, '');
		//Remove Color tage eg (COLOR: #FFGG66;) to ''
		rte_content = rte_content.replace(/COLOR:\s\#\w{6}\;/gi, '');
		//Remove Color tage eg (COLOR: #FFGG66) to ''
		rte_content = rte_content.replace(/COLOR:\s\#\w{6}/gi, '');
		//Remove Color tage eg (COLOR: black; ) to ''
		rte_content = rte_content.replace(/COLOR:\s\w{0,}\;\s/gi, '');
		//Remove Color tage eg (COLOR: black;) to ''
		rte_content = rte_content.replace(/COLOR:\s\w{0,}\;/gi, '');
		//Remove Color tage eg (COLOR: black") to ''
		rte_content = rte_content.replace(/COLOR:\s\w{0,}\"/gi, '\"');
	//alert(rte_content);
		//Remove LINE-HEIGHT eg(LINE-HEIGHT: 115%;)
		rte_content = rte_content.replace(/LINE-HEIGHT:\s\d{0,}\%\;\s/gi, '');
		rte_content = rte_content.replace(/LINE-HEIGHT:\s\d{0,}\%\;/gi, '');
		//Remove FONT-WEIGHT eg(FONT-WEIGHT: normal;)
		rte_content = rte_content.replace(/FONT-WEIGHT:\s\w{0,}\;\s/gi, '');
		//alert(rte_content);
		//Remove FontSize eg(FONT-SIZE: ) to ''
		rte_content = rte_content.replace(/FONT-SIZE:\s/gi, '');
		//Remove FontSize ex (21.5pt) or (21.5pt;) or (21.5pt ) or (21.5pt; )
		rte_content = rte_content.replace(/\d{0,}\.\d{0,}pt\;\s}/gi, '');
		rte_content = rte_content.replace(/\d{0,}\.\d{0,}pt\;/gi, '');
		rte_content = rte_content.replace(/\d{0,}\.\d{0,}pt\s/gi, '');
		rte_content = rte_content.replace(/\d{0,}\.\d{0,}pt/gi, '');
		//Remove FontSize ex(23pt; ) to ''
		rte_content = rte_content.replace(/\d{0,}pt\;\s/gi, '');
		//Remove FontSize ex(23pt;) to ''
		rte_content = rte_content.replace(/\d{0,}pt\;/gi, '');		
		//Remove FontSize ex(23pt) to ''
		rte_content = rte_content.replace(/\d{0,}pt/gi, '');
		//alert(rte_content);
		//Remove double Qoute ex(style="") to style="FONT-FAMILY: 'Times New Roman'"
		rte_content = rte_content.replace(/\"\"/gi, "\"FONT-FAMILY: 'Times New Roman'\"");
		//Remove language ex(lang=EN )
		rte_content = rte_content.replace(/lang=\w{0,}\s/gi, '');
		//Remove style eg ( style="")
	//alert(rte_content);
		rte_content = rte_content.replace(/style=/gi, 'class=');
		rte_content = rte_content.replace(/FONT-FAMILY:\s'Times\sNew\sRoman'\;/gi, "txtnormal");
		rte_content = rte_content.replace(/FONT-FAMILY:\s'Times\sNew\sRoman'/gi, "txtnormal");		
		rte_content = rte_content.replace(/FONT-FAMILY:\sLimonS1\;/gi, "khnormal2");
		rte_content = rte_content.replace(/FONT-FAMILY:\sLimonS1/gi, "khnormal2");		
		rte_content = rte_content.replace(/FONT-FAMILY:\s'Limon\sS1'\;/gi, "khnormal2");
		rte_content = rte_content.replace(/FONT-FAMILY:\s'Limon\sS1'/gi, "khnormal2");
		//alert(rte_content);		
		rte_content	= rte_content.replace(/<span class="khnormal2">/gi, '-RiikRieyKH-');
		rte_content	= rte_content.replace(/<span class="txtnormal">/gi, '-RiikRieyENG-');
		rte_content	= rte_content.replace(/<\/span>/gi, '-closetage-');
		rte_content = rte_content.replace(/<span>/gi, '-span-');
		rte_content = rte_content.replace(/<B>/gi, '');
		rte_content = Del(rte_content);
	//alert(rte_content);
	var rte_pfw_id = document.getElementById('pastfw').value;
	//alert(rte_pfw_id);
			var rte_transfer = document.getElementById(rte_pfw_id);
			rte_transfer.onload = null;
			clearTimeout(rte_transfer.onloadTimeout);
			var rte_pfw_content_tranfer = rte_transfer.contentWindow.document;
			rte_pfw_content_tranfer.designMode = 'on';
			setTimeout(function() {
			rte_pfw_content_tranfer.body.innerHTML = rte_content;
			rte_pfw_content_tranfer.designMode = 'on';
			}, 0);
	hidebox('Div');	
		rte_content = rte_content.replace(/-RiikRieyKH-/gi, '<SPAN style="FONT-SIZE: 25px; FONT-FAMILY: \'Limon S1\'">');
		rte_content = rte_content.replace(/-RiikRieyENG-/gi, '<SPAN style="FONT-SIZE: 12px; FONT-FAMILY: \'Tahoma\'">');
		rte_content = rte_content.replace(/-closetage-/gi, '</SPAN>');
		rte_content = rte_content.replace(/-span-/gi, '<span>');
	return rte_content;
}
function Del(Word) {
a = Word.indexOf("<");
b = Word.indexOf(">");
len = Word.length;
c = Word.substring(0, a);
if(b == -1)
b = a;
d = Word.substring((b + 1), len);
Word = c + d;
tagCheck = Word.indexOf("<");
if(tagCheck != -1)
Word = Del(Word);
return Word;
}
