// JavaScript Document
document.write("<table  cellpadding=0 cellspacing=0><tr><td height=12 >");
var FormatTextlist="bold bold|italic italic|underline underline|superscript superscript|subscript subscript|strikethrough strikethrough|Justifyleft Justifyleft|JustifyCenter JustifyCenter|JustifyRight JustifyRight|justifyfull justifyfull|cut cut|copy copy|paste paste|undo undo|redo redo"
var list= FormatTextlist.split ('|'); 
for(i=0;i<list.length;i++) {
if (list[i]=="<br>"){document.write("<br>");
}else{
var TextName= list[i].split (' '); 
document.write("<img align=left src=../liuyanbanimage/"+TextName[1]+".gif alt="+TextName[0]+" style=cursor:hand onClick=FormatText('"+TextName[1]+"')> ");
}
}

document.write("<img src=../liuyanbanimage/img.gif alt=\"insert image\" align=left style=cursor:hand;  onClick=img()>");
document.write("<img alt=\"insert emotion\" src=../liuyanbanimage/em.gif align=left style=cursor:hand onclick=em()>");
document.write("<img alt=\"insert website\" src=../liuyanbanimage/urldizhi.gif align=left style=cursor:hand onclick=urldizhi()>");
document.write("<img alt=\"font color\" src=../liuyanbanimage/color.gif  align=left style=cursor:hand onClick=foreColor()> ");
document.write("<img  alt=\"clear code\" src=../liuyanbanimage/CleanCode.gif  style=cursor:hand align=left onclick=CleanCode()  > ");

document.write("<select  id='fs' onchange=FormatText('FontSize',fs.value) align='left' ><option value='4' selected>font-size</option><option value='2'>size 2</option><option value='3'>size 3</option><option value='4'>size 4</option><option value='5'>size 5</option><option value='6'>size 6</option></select>");

document.write("</td></tr><td ><iframe ID='HtmlEditor' MARGINHEIGHT=0 MARGINWIDTH=0 width=530 height=140 ></iframe></td></tr></table>");

if (document.all){var IframeID=frames["HtmlEditor"];}else{}

IframeID.document.open();

IframeID.document.close();
IframeID.document.body.contentEditable = "True";




function em(){
var arr = showModalDialog("emotion.hta", "", "dialogWidth:20em; dialogHeight:9.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function CleanCode(){
	
var body = IframeID.document.body;
var html = IframeID.document.body.innerHTML;

html = html.replace(/\<p>/gi,"[$p]");
html = html.replace(/\<\/p>/gi,"[$\/p]");
html = html.replace(/\<br>/gi,"[$br]");
html = html.replace(/\<[^>]*>/g,"");
html = html.replace(/\[\$p\]/gi,"<p>");
html = html.replace(/\[\$\/p\]/gi,"<\/p>");
html = html.replace(/\[\$br\]/gi,"<br>");

IframeID.document.body.innerHTML = html;

}


function FormatText(command,option){IframeID.focus();IframeID.document.execCommand(command,true,option);}



function emoticon(theSmilie){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src=biaoqingimg/"+theSmilie+".gif>");
}

function DoTitle(addTitle) {
var revisedTitle;var currentTitle = document.newfile.topic.value;revisedTitle = addTitle+currentTitle;document.newfile.topic.value=revisedTitle;document.newfile.topic.focus();
}

function CheckForm(form){
form.nl.value=IframeID.document.body.innerHTML; 
MessageLength=IframeID.document.body.innerHTML.length;
if(MessageLength<2){alert("文章内容不能小于2个字符！");return false;}
if(MessageLength>5000000){alert("文章内容不能超过5000000个字符！");return false;}
document.newfile.submit1.disabled = true;
}

function Gopreview()
{
document.preview.nl.value=IframeID.document.body.innerHTML; 
window.open('', 'preview_page', 'resizable,scrollbars,width=750,height=450');
document.preview.submit()
}

function BackColor()
{
  var arr = showModalDialog("selcolor.hta", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('BackColor', arr);
  else IframeID.focus();
}

function foreColor()
{
  var arr = showModalDialog("selcolor.hta", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('forecolor', arr);
  else IframeID.focus();
}

//////替换内容
function replace()
{
  var arr = showModalDialog("../../inc/replace.html", "", "dialogWidth:22em;dialogHeight:10em;status:0;help:0");
	if (arr != null){
		var ss;
		ss = arr.split("*")
		a = ss[0];
		b = ss[1];
		i = ss[2];
		con = IframeID.document.body.innerHTML;
		if (i == 1)
		{
			con = bbsxp_rCode(con,a,b,true);
		}else{
			con = bbsxp_rCode(con,a,b);
		}
		IframeID.document.body.innerHTML = con;
	}
	else IframeID.focus();
}
function bbsxp_rCode(s,a,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); 
}
//////替换内容结束

function img(){
url=prompt("请输入图片文件地址:","http://");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src="+url+">");
}
function urldizhi(){
url=prompt("请输入网址,并且Http://不可省略:","http://");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<a href="+url+">"+url+"</a>");
}
function RealPlay(){
var arr = showModalDialog("../../inc/RealPlay.htm", "", "dialogWidth:22em; dialogHeight:9em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function MediaPlayer(){
var arr = showModalDialog("../../inc/MediaPlayer.htm", "", "dialogWidth:22em; dialogHeight:9em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function flash(){
var arr = showModalDialog("../../inc/flash.htm", "", "dialogWidth:22em; dialogHeight:9em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

