
var bodyID,htmlableID;

var yToolbars = new Array();

var YInitialized = false;

var filterScript = false;

var charset="UTF-8";

function document.onreadystatechange()
{
	if (YInitialized) return;
	YInitialized = true;
	
	var i, s, curr;
	
	for (i=0; i<document.body.all.length;	i++)
	{
		curr=document.body.all[i];
		if (curr.className == "yToolbar")
		{
			InitTB(curr);
			yToolbars[yToolbars.length] = curr;
		}
	}
}

function InitBtn(btn)
{
	btn.onmouseover = BtnMouseOver;
	btn.onmouseout = BtnMouseOut;
	btn.onmousedown = BtnMouseDown;
	btn.onmouseup	= BtnMouseUp;
	btn.ondragstart = YCancelEvent;
	btn.onselectstart = YCancelEvent;
	btn.onselect = YCancelEvent;
	btn.YUSERONCLICK = btn.onclick;
	btn.onclick = YCancelEvent;
	btn.YINITIALIZED = true;
	return true;
}

function InitTB(y)
{
	y.TBWidth = 0;
	if (!PopulateTB(y)) return false;
	y.style.posWidth = y.TBWidth;
	return true;
}


function YCancelEvent()
{
	event.returnValue=false;
	event.cancelBubble=true;
	return false;
}

function BtnMouseOver()
{
	if (event.srcElement.tagName != "IMG") return false;
	var image = event.srcElement;
	var element = image.parentElement;
	
	if (image.className == "Ico") element.className = "BtnMouseOverUp";
	else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";
	
	event.cancelBubble = true;
}

function BtnMouseOut()
{
	if (event.srcElement.tagName != "IMG") {
		event.cancelBubble = true;
		return false;
	}
	
	var image = event.srcElement;
	var element =	image.parentElement;
	yRaisedElement = null;
	
	element.className = "Btn";
	image.className = "Ico";
	
	event.cancelBubble = true;
}

function BtnMouseDown()
{
	if (event.srcElement.tagName != "IMG") {
		event.cancelBubble = true;
		event.returnValue=false;
		return false;
	}
	
	var image = event.srcElement;
	var element = image.parentElement;
	
	element.className = "BtnMouseOverDown";
	image.className = "IcoDown";
	
	event.cancelBubble = true;
	event.returnValue=false;
	return false;
}

function BtnMouseUp()
{
	if (event.srcElement.tagName != "IMG") {
		event.cancelBubble = true;
		return false;
	}
	
	var image = event.srcElement;
	var element = image.parentElement;
	
	if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
	
	element.className = "BtnMouseOverUp";
	image.className = "Ico";
	
	event.cancelBubble = true;
	return false;
}

function PopulateTB(y)
{
	var i, elements, element;
	
	elements = y.children;
	for (i=0; i<elements.length; i++) {
	element = elements[i];
	if (element.tagName== "SCRIPT" || element.tagName == "!") continue;
	
	switch (element.className) {
		case "Btn":
			if (element.YINITIALIZED == null) {
				if (! InitBtn(element))
					return false;
			}
			
			element.style.posLeft = y.TBWidth;
			y.TBWidth	+= element.offsetWidth + 1;
			break;
		
		case "Eu88_wkGen":
			element.style.posLeft = y.TBWidth;
			y.TBWidth	+= element.offsetWidth + 1;
			break;
		
			//default:
			//  return false;
		}
	}
	
	y.TBWidth += 1;
	return true;
}

function DebugObject(obj)
{
	var msg = "";
	for (var i in TB) {
		ans=prompt(i+"="+TB[i]+"\n");
		if (! ans) break;
	}
}


function validateMode()
{
	if (!bTextMode) return true;
	alert("请取消“查看HTML源代码”选项再使用系统编辑功能或者提交!");
	Composition.focus();
	return false;
}

function format1(what,opt)
{
	if (opt=="removeFormat")
	{
		what=opt;
		opt=null;
	}
	Composition.focus();
	if (opt==null)
	{
		Composition.document.execCommand(what);
	}else{
		Composition.document.execCommand(what,"",opt);
	}
	pureText = false;
	Composition.focus();
}

function format(what,opt)
{
	  if (!validateMode()) return;
	
	  format1(what,opt);
}

function setMode()
{
	bTextMode=!bTextMode;
	setTab();
	var cont;
	if (bTextMode) {
		document.all.Toolbars.style.display='none';
		cleanHtml();
		cont=Composition.document.body.innerHTML;
		cont=correctUrl(cont);
		if (filterScript)
			cont=FilterScript(cont);
		Composition.document.body.innerText=cont;
	} else {
		document.all.Toolbars.style.display='';
		cont=Composition.document.body.innerText;
		cont=correctUrl(cont);
		if (filterScript)
			cont=FilterScript(cont);
		Composition.document.body.innerHTML=cont;
	}
	setStyle();
	Composition.focus();
}

function setStyle()
{
	bs = Composition.document.body.runtimeStyle;
	//根据mode设置iframe样式表	
	if (bTextMode) {
		bs.fontFamily="Arial";
		bs.fontSize="10pt";
	}else{
		bs.fontFamily="Arial";
		bs.fontSize="10.5pt";
	}
	bs.scrollbar3dLightColor= '#D4D0C8';
	bs.scrollbarArrowColor= '#000000';
	bs.scrollbarBaseColor= '#D4D0C8';
	bs.scrollbarDarkShadowColor= '#D4D0C8';
	bs.scrollbarFaceColor= '#D4D0C8';
	bs.scrollbarHighlightColor= '#808080';
	bs.scrollbarShadowColor= '#808080';
	bs.scrollbarTrackColor= '#D4D0C8';
	bs.border='0';
}

function setTab()
{
	//html和design按钮的样式更改
	var mhtml=document.all.TabHtml;
	var mdesign=document.all.TabDesign;
	if (bTextMode)
	{
		mhtml.className="TabOn";
		mdesign.className="TabOff";
	}else{
		mhtml.className="TabOff";
		mdesign.className="TabOn";
	}
}

function getEl(sTag,start)
{
	while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
	return start;
}

function UserDialog(what)
{
	if (!validateMode()) return;
	Composition.focus();
	Composition.document.execCommand(what, true);
	
	//去掉添加图片时的src="file://
	if(what=="InsertImage")
	{
		Composition.document.body.innerHTML=(Composition.document.body.innerHTML).replace("src=\"file://","src=\"");
	}
	
	pureText = false;
	Composition.focus();
}

function foreColor()
{
	if (!validateMode()) return;
	var arr = showModalDialog("Eu88EditBox/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
	if (arr != null) format('forecolor', arr);
	else Composition.focus();
}

function backColor()
{
	if (!validateMode()) return;
	var arr = showModalDialog("Eu88EditBox/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
	if (arr != null) format('backcolor', arr);
	else Composition.focus();
}

function fortable()
{
	if (!validateMode())	return;
	var arr = showModalDialog("Eu88EditBox/table.html", "", "dialogWidth:14.5em; dialogHeight:16.5em; status:0; help:0");
	
	if (arr != null)
	{
		var ss;
		ss=arr.split("*")
		row=ss[0];
		if (row=="") row=1;
		col=ss[1];
		if (col=="") col=1;
		tbwidth=ss[2];
		if (tbwidth=="") tbwidth=500;
		tbborder=ss[3];
		if (tbborder=="") tbborder=1;
		celpadding=ss[4];
		if (celpadding=="") celpadding=2;
		bdcolor=ss[5];
		if (bdcolor=="") bdcolor="#CCCCCC";
		bgcolor=ss[6];
		if (bgcolor=="") bgcolor="#FFFFFF";
		tbalign=ss[7];
		if (tbalign=="") tbalign="center";
		var string;
		string="<table border="+ tbborder +" cellspacing=0 width="+tbwidth+" cellpadding="+ celpadding +" align="+tbalign+" bgcolor='"+ bgcolor +"' bordercolor="+ bdcolor +" style='border-collapse:collapse'>";
		for(i=1;i<=row;i++){
			string=string+"<tr>";
			for(j=1;j<=col;j++){
				string=string+"<td>&nbsp;</td>";
			}
			string=string+"</tr>";
		}
		string=string+"</table>";
		content=Composition.document.body.innerHTML;
		content=content+string;
		Composition.document.body.innerHTML=content;
	}
	else
		Composition.focus();
}

function forswf()
{
	var arr = showModalDialog("Eu88EditBox/swf.htm", "", "dialogWidth:15em; dialogHeight:13em; status:0; help:0");
	
	if (arr != null){
		var ss;
		ss=arr.split("*")
		path=ss[0];
		row=ss[1];
		col=ss[2];
		var string;
		string="<div align='center'><div style='width:640;text-align:left'><a href="+path+">[全屏查看]</a></div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
		content=Composition.document.body.innerHTML;
		content=content+string;
		Composition.document.body.innerHTML=content;
	}
	else Composition.focus();
}

function forwmv()
{
	var arr = showModalDialog("Eu88EditBox/wmv.htm", "", "dialogWidth:15.5em; dialogHeight:14em; status:0; help:0");
	
	if (arr != null){
		var ss;
		ss=arr.split("*")
		path=ss[0];
		width=ss[1];
		height=ss[2];
		var string;
		//string="<object align=center classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 hspace=5 vspace=5 width="+ width +" height="+ height +"><param name=Filename value="+ path +"><param name=ShowStatusBar value=1><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src="+ path +"  width="+ width +" height="+ height +"></embed></object>";
		string="<embed src='"+ path+"' width="+ width +" height="+ height +" autostart=true loop=false ></embed>";
		content=Composition.document.body.innerHTML;
		content=content+string;
		Composition.document.body.innerHTML=content;
	}
	else Composition.focus();
}


function forrm()
{
	var arr = showModalDialog("Eu88EditBox/rm.htm", "", "dialogWidth:15.5em; dialogHeight:14em; status:0; help:0");
	
	if (arr != null)
	{
		var ss;
		ss=arr.split("*")
		path=ss[0];
		row=ss[1];
		col=ss[2];
		var string;
		string="<object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width="+row+" height="+col+"><param name='CONTROLS' value='ImageWindow'><param name='CONSOLE' value='Clip1'><param name='AUTOSTART' value='-1'><param name=src value="+path+"></object><br><object classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'  width="+row+" height=60><param name='CONTROLS' value='ControlPanel,StatusBar'><param name='CONSOLE' value='Clip1'></object>";
		content=Composition.document.body.innerHTML;
		content=content+string;
		Composition.document.body.innerHTML=content;
	}
	else Composition.focus();
}

function InsertRow()
{
	editor = Composition;
	objReference=GetRangeReference(editor);
	objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
	switch(objReference.tagName)
	{
	case 'TABLE' :
	var newTable=objReference.cloneNode(true);
	var newRow= newTable.insertRow();
	
	for(x=0; x<newTable.rows[0].cells.length; x++)
	{
	var newCell = newRow.insertCell();
	}
	objReference.outerHTML=newTable.outerHTML;
	break;
	case 'TBODY' :
	var newTable=objReference.cloneNode(true);
	var newRow = newTable.insertRow();
	for(x=0; x<newTable.rows[0].cells.length; x++)
	{
	var newCell = newRow.insertCell();
	}
	objReference.outerHTML=newTable.outerHTML;
	break;
	case 'TR' :
	var rowIndex = objReference.rowIndex;
	var parentTable=objReference.parentElement.parentElement;
	var newTable=parentTable.cloneNode(true);
	var newRow = newTable.insertRow(rowIndex+1);
	for(x=0; x< newTable.rows[0].cells.length; x++)
	{
	var newCell = newRow.insertCell();
	}
	parentTable.outerHTML=newTable.outerHTML;
	break;
	case 'TD' :
	var parentRow=objReference.parentElement;
	var rowIndex = parentRow.rowIndex;
	var cellIndex=objReference.cellIndex;
	var parentTable=objReference.parentElement.parentElement.parentElement;
	var newTable=parentTable.cloneNode(true);
	var newRow = newTable.insertRow(rowIndex+1);
	for(x=0; x< newTable.rows[0].cells.length; x++)
	{
	var newCell = newRow.insertCell();
	if (x==cellIndex)newCell.id='ura';
	}
	parentTable.outerHTML=newTable.outerHTML;
	var r = editor.document.body.createTextRange();
	var item=editor.document.getElementById('ura');
	item.id='';
	r.moveToElementText(item);
	r.moveStart('character',r.text.length);
	r.select();
	break;
	default :
	return;
	}
}

function DeleteRow()
{
	editor=Composition;
	objReference=GetRangeReference(editor);
	objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
	switch(objReference.tagName)
	{
	case 'TR' :var rowIndex = objReference.rowIndex;//Get rowIndex
	var parentTable=objReference.parentElement.parentElement;
	parentTable.deleteRow(rowIndex);
	break;
	case 'TD' :var cellIndex=objReference.cellIndex;
	var parentRow=objReference.parentElement;//Get Parent Row
	var rowIndex = parentRow.rowIndex;//Get rowIndex
	var parentTable=objReference.parentElement.parentElement.parentElement;
	parentTable.deleteRow(rowIndex);
	if (rowIndex>=parentTable.rows.length)
	{
	rowIndex=parentTable.rows.length-1;
	}
	if (rowIndex>=0)
	{
	var r = editor.document.body.createTextRange();
	r.moveToElementText(parentTable.rows[rowIndex].cells[cellIndex]);
	r.moveStart('character',r.text.length);
	r.select();
	}
	else
	{
	parentTable.removeNode(true);
	}
	break;
	default :return;
	}
}


function InsertColumn()
{
	editor = Composition;
	objReference= GetRangeReference(editor);
	objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
	switch(objReference.tagName)
	{
	case 'TABLE' :// IF a table is selected, it adds a new column on the right hand side of the table.
	var newTable=objReference.cloneNode(true);
	for(x=0; x<newTable.rows.length; x++)
	{
	var newCell = newTable.rows[x].insertCell();
	}
	newCell.focus();
	objReference.outerHTML=newTable.outerHTML;
	break;
	case 'TBODY' :// IF a table is selected, it adds a new column on the right hand side of the table.
	var newTable=objReference.cloneNode(true);
	for(x=0; x<newTable.rows.length; x++)
	{
	var newCell = newTable.rows[x].insertCell();
	}
	objReference.outerHTML=newTable.outerHTML;
	break;
	case 'TR' :// IF a table is selected, it adds a new column on the right hand side of the table.
	objReference=objReference.parentElement.parentElement;
	var newTable=objReference.cloneNode(true);
	for(x=0; x<newTable.rows.length; x++)
	{
	var newCell = newTable.rows[x].insertCell();
	}
	objReference.outerHTML=newTable.outerHTML;
	break;
	case 'TD' :// IF the cursor is in a cell, or a cell is selected, it adds a new column to the right of that cell.
	var cellIndex = objReference.cellIndex;//Get cellIndex
	var rowIndex=objReference.parentElement.rowIndex;
	var parentTable=objReference.parentElement.parentElement.parentElement;
	var newTable=parentTable.cloneNode(true);
	for(x=0; x<newTable.rows.length; x++)
	{
	var newCell = newTable.rows[x].insertCell(cellIndex+1);
	if (x==rowIndex)newCell.id='ura';
	}
	parentTable.outerHTML=newTable.outerHTML;
	var r = editor.document.body.createTextRange();
	var item=editor.document.getElementById('ura');
	item.id='';
	r.moveToElementText(item);
	r.moveStart('character',r.text.length);
	r.select();
	break;
	default :
	return;
	}
}
 

function DeleteColumn()
{
	editor = Composition;
	objReference=GetRangeReference(editor);
	objReference=CheckTag(objReference,'/^(TABLE)|^(TR)|^(TD)|^(TBODY)/');
	switch(objReference.tagName)
	{
	
	case 'TD' :var rowIndex=objReference.parentElement.rowIndex;
	var cellIndex = objReference.cellIndex;//Get cellIndex
	var parentTable=objReference.parentElement.parentElement.parentElement;
	var newTable=parentTable.cloneNode(true);
	if (newTable.rows[0].cells.length==1)
	{
	parentTable.removeNode(true);
	return;
	}
	for(x=0; x<newTable.rows.length; x++)
	{
	if (newTable.rows[x].cells[cellIndex]=='[object]')
	{
	newTable.rows[x].deleteCell(cellIndex);
	}
	}
	if (cellIndex>=newTable.rows[0].cells.length)
	{
	cellIndex=newTable.rows[0].cells.length-1;
	}
	if (cellIndex>=0)  newTable.rows[rowIndex].cells[cellIndex].id='ura';
	parentTable.outerHTML=newTable.outerHTML;
	if (cellIndex>=0){
	var r = editor.document.body.createTextRange();
	var item=editor.document.getElementById('ura');
	item.id='';
	r.moveToElementText(item);
	r.moveStart('character',r.text.length);
	r.select();
	}
	break;
	default :return;
	}
}


function GetRangeReference(editor)
{
	editor.focus();
	var objReference = null;
	var RangeType = editor.document.selection.type;
	var selectedRange = editor.document.selection.createRange();
	
	switch(RangeType)
	{
	case 'Control' :
	if (selectedRange.length > 0 ) 
	{
	objReference = selectedRange.item(0);
	}
	break;
	
	case 'None' :
	objReference = selectedRange.parentElement();
	break;
	
	case 'Text' :
	objReference = selectedRange.parentElement();
	break;
	}
	return objReference
}

function CheckTag(item,tagName)
{
	if (item.tagName.search(tagName)!=-1)
	{
	return item;
	}
	if (item.tagName=='BODY')
	{
	return false;
	}
	item=item.parentElement;
	return CheckTag(item,tagName);
}

function code()
{
	specialtype("<div class=quote style='cursor:hand'; title='Click to run the code' onclick=\"preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();\">","</div>");	
}

function replace()
{
	var arr = showModalDialog("Eu88EditBox/replace.html", "", "dialogWidth:16.5em; dialogHeight:13em; status:0; help:0");
	
	if (arr != null){
		var ss;
		ss=arr.split("*")
		a=ss[0];
		b=ss[1];
		i=ss[2];
		con=Composition.document.body.innerHTML;
		if (i==1)
		{
			con=rCode(con,a,b,true);
		}else{
			con=rCode(con,a,b);
		}
		Composition.document.body.innerHTML=con;
	}
	else Composition.focus();
}


function CleanCode() {
	editor=Composition;
	editor.focus();
	// 0bject based cleaning
	var body = editor.document.body;
	for (var index = 0; index < body.all.length; index++) {
		tag = body.all[index];
		//if (tag.Attribute["className"].indexOf("mso") > -1)
		tag.removeAttribute("className","",0);
		tag.removeAttribute("style","",0);
	}

	// Regex based cleaning
	var html = editor.document.body.innerHTML;
	html = html.replace(/<o:p>&nbsp;<\/o:p>/gi, "");
	html = html.replace(/o:/gi, "");
	//html = html.replace(/<st1:[^>]*>/gi, "");

	// Final clean up of empty tags
	html = html.replace(/<font[^>]*>\s*<\/font>/gi, "");
	html = html.replace(/<span>\s*<\/span>/gi, "");
	
	editor.document.body.innerHTML = html;
}


function FilterScript(content)
{
	content = rCode(content, 'javascript:', 'javascript :');
	//var RegExp = /<script[^>]*>(.|\n)*<\/script>/ig;
	//content = content.replace(RegExp, "<!-- Script Filtered -->");
	var RegExp = /<script[^>]*>/ig;
	content = content.replace(RegExp, "<!-- Script Filtered/n");
	RegExp = /<\/script>/ig;
	content = content.replace(RegExp, "/n-->");
	return content;
}

function cleanHtml()
{
	var fonts = Composition.document.body.all.tags("FONT");
	var curr;
	for (var i = fonts.length - 1; i >= 0; i--) {
		curr = fonts[i];
		if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
	}
}

function getPureHtml()
{
	var str = "";
	//var paras = Composition.document.body.all.tags("P");
	//if (paras.length > 0){
	//  for	(var i=paras.length-1; i >= 0; i--) str= paras[i].innerHTML + "\n" + str;
	//} else {
	str = Composition.document.body.innerHTML;
	//}
	str=correctUrl(str);
	return str;
}


function correctUrl(cont)
{
	var url=location.href.substring(0,location.href.lastIndexOf("/")+1);
	cont=rCode(cont,location.href+"#","#");
	cont=rCode(cont,url,"");
	return cont;
}

var bLoad=false
var pureText=true
var bTextMode=false

public_description=new Editor

function Editor()
{
	this.put_HtmlMode=setMode;
	this.put_value=putText;
	this.get_value=getText;
}

function getText()
{
	if (bTextMode)
		return Composition.document.body.innerText;
	else
	{
		cleanHtml();
		return Composition.document.body.innerHTML;
	}
}

function putText(v)
{
	if (bTextMode)
		Composition.document.body.innerText = v;
	else
		Composition.document.body.innerHTML = v;
}

function InitDocument(hiddenid, charset)
{	
	if (charset!=null)
		charset=charset;
	var bodyTag="<html><head><style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\" >";
	var editor=Composition;
	var h=document.getElementById(hiddenid);
	editor.document.designMode="On"
	editor.document.open();
	editor.document.write(bodyTag);
	if (h.value!="")
	{
		editor.document.write(h.value);
	}
	editor.document.write("</html>");
	editor.document.close();
	editor.document.body.contentEditable = "True";
	editor.document.charset=charset;
	
	bLoad=true;
	setStyle();
	//eval("Composition.document.body.innerHTML+=(self.opener."+ htmlableID +".checked)?(self.opener."+bodyID+".value):(ubb2html(self.opener."+ bodyID +".value))");
}


function doSelectClick(str, el) {
	var Index = el.selectedIndex;
	if (Index != 0){
		el.selectedIndex = 0;
		format(str,el.options[Index].value);
	}
}

var bIsIE5 = (navigator.userAgent.indexOf("IE 5")  > -1) || (navigator.userAgent.indexOf("IE 6")  > -1);
var edit;	//selectRang
var RangeType;
var selection;

//应用html
function specialtype(Mark1, Mark2){
	var strHTML;
	if (bIsIE5) selectRange();
	if (RangeType == "Text"){
		if (Mark2==null)
		{
			strHTML = "<" + Mark1 + ">" + edit.htmlText + "</" + Mark1 + ">"; 
		}else{
			strHTML = Mark1 + edit.htmlText +  Mark2; 
		}
		edit.pasteHTML(strHTML);
		Composition.focus();
		edit.select();
	}		
}

//选择内容替换文本
function InsertSymbol(str1)
{
	Composition.focus();
	if (bIsIE5) selectRange();	
	edit.pasteHTML(str1);
}


function selectRange(){
	selection = Composition.document.selection;
	edit = Composition.document.selection.createRange();
	RangeType =  Composition.document.selection.type;
}

function rCode(s,a,b,i){
	//s原字串，a要换掉pattern，b换成字串，i是否区分大小写
	a = a.replace("?","\\?");
	if (i==null)
	{
		var r = new RegExp(a,"gi");
	}else if (i) {
		var r = new RegExp(a,"g");
	}
	else{
		var r = new RegExp(a,"gi");
	}
	return s.replace(r,b); 
}


//提交数据到opener，已无用
/*
function handin()
{
	if (!validateMode()) return;
	var strHTMLbegin;
	var strHTMLend;
	strHTMLbegin = "";
	strHTMLend = "";
//	eval("self.opener."+bodyID+".value=strHTMLbegin + getPureHtml(Composition.document.body.innerHTML) + strHTMLend;self.opener."+htmlableID+".checked=true;");
	self.close();
}
*/

function View()
{
	if (bTextMode) {
		cont=Composition.document.body.innerText;
	} else {
		cont=Composition.document.body.innerHTML;
	}
	cont=correctUrl(cont);
	bodyTag="<html><head><style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px; font-family:Arial; font-size:10.5pt}</style></head><BODY bgcolor=\"#FFFFFF\" >";
	if (filterScript)
		cont=FilterScript(cont);
	//cont=rCode(cont,"\\[dvnews_ad]","<img src='Eu88EditBox/images/pic_ad.jpg' vspace=10 hspace=10 align=left border=1 title='Advertising'>");
	//cont=rCode(cont,"\\[dvnews_page]","<br><br><hr size=2 width=95% align=left>&nbsp; <font color=red face='Tahoma,Arail' size=2><b>Next Page ...</b></font><br><hr size=2 width=95% align=left>");
	preWin=window.open('preview','','left=0,top=0,width=550,height=400,resizable=1,scrollbars=1, status=1, toolbar=1, menubar=0');
	preWin.document.open();
	preWin.document.write(bodyTag);
	preWin.document.write(cont);
	preWin.document.close();
	preWin.document.title="Preview";
	preWin.document.charset=charset;
}


// 修改编辑栏高度
function Size(num)
{
	var obj=document.all.Container;
	if (parseInt(obj.height)+num>=300) {
		obj.height = parseInt(obj.height) + num;	
	}
	if (num>0)
	{
		obj.width="100%";	
	}
}

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

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

// 拷贝数据到hidden
function CopyData(hiddenid)
{
	d = Composition.document;
	if (bTextMode)
	{
		cont=d.body.innerText;
	}else{
		cont=d.body.innerHTML;  
	}
	cont=correctUrl(cont);
	if (filterScript)
		cont=FilterScript(cont);
	document.getElementById(hiddenid).value = cont;  
	if (document.getElementById(hiddenid).value == '<P>&nbsp;</P>')
	{
		document.getElementById(hiddenid).value = '';
	}
}

function insert(cons)
{
	var Composition;
	Composition.document.body.innerHTML=cons;
}
function getver()
{
	window.open("http://www.wangkuan.com","","");
}

function help()
{
	showModalDialog("Eu88EditBox/help.html", "", "dialogWidth:13.5em; dialogHeight:12.5em; status:0; help:0");
}