var itemFontsizeValue=['8','10','12','14','18','24','32'];
var itemFontSize=['特小','极小','小','普通','大','极大','特大'];
var itemColors=['#ffffff','#000000','#eeece1','#1f497d','#4f81bd','#c0504d','#9bbb59','#8064a2','#4bacc6','#f79646',
'#f2f2f2','#7f7f7f','#ddd9c3','#c6d9f0','#dbe5f1','#f2dcdb','#ebf1dd','#e5e0ec','#dbeef3','#fdeada',
'#d8d8d8','#595959','#c4bd97','#8db3e2','#b8cce4','#e5b9b7','#d7e3bc','#ccc1d9','#b7dde8','#fbd5b5',
'#bfbfbf','#3f3f3f','#938953','#548dd4','#95b3d7','#d99694','#c3d69b','#b2a2c7','#92cddc','#fac08f',
'#a5a5a5','#262626','#494429','#17365d','#366092','#953734','#76923c','#5f497a','#31859b','#e36c09',
'#7f7f7f','#0c0c0c','#1d1b10','#0f243e','#244061','#632423','#4f6128','#3f3151','#205867','#974806',
'#c00000','#ff0000','#ffc000','#ffff00','#92d050','#00b050','#00b0f0','#0070c0','#002060','#7030a0'];
var itemFontFamily=['宋体','仿宋体','黑体','隶书','楷体','微软雅黑','Arial','Arial Narrow','Arial Black','Times New Roman','Verdana'];
var itemJustify=['左对齐','居中','右对齐','两端对齐'];
var itemJustifyValue=['Justifyleft','Justifycenter','Justifyright','Justifyfull'];
var nowPanelID="fontFamily";
var defaultValue="http://";
var fullScreenStat=false;
var htmlStat=false;
var range,sel,bookmark,SelTxt="",SelTxtLink="";

function deactivateEve(){
	sel=document.selection ? document.selection : window.getSelection();;
	range = sel.createRange ? sel.createRange() : sel.rangeCount > 0?sel.getRangeAt(0):null;
	bookmark= range.getBookmark();
	
	SelTxt=range.text;
	if(SelTxt!="")
	document.getElementById("linkTextSpan").style.display="none";
	else document.getElementById("linkTextSpan").style.display="block";
	
	parentElement = range.parentElement();
	if(parentElement.tagName=="A"){
	SelTxtLink = range.parentElement().attributes("href").value;
	document.getElementById("linkHref").value= SelTxtLink;
	}
	else document.getElementById("linkHref").value="http://";
}

function activeEve(){
if(bookmark){  
	range.moveToBookmark(bookmark);  
	range.select();  
	bookmark = null;  
}
}

function drawFontSizeMenu(){
for(num=0;num<7;num++)
	document.write("<span class='fontSizeSpan' style='font-size:12px;' onClick='setFontSize("+num+")' onMouseOver='ItemFocus(this);'onMouseOut='ItemNormal(this);'>"+itemFontSize[num]+"("+itemFontsizeValue[num]+"px)</span><br>");
}

function drawFontFamilyMenu(){
for(num=0;num<11;num++)
	document.write("<span class='fontFamilySpan' style='font-Family:"+itemFontFamily[num]+";' onMouseDown='setFontFamily("+num+")' onMouseOver='ItemFocus(this);'onMouseOut='ItemNormal(this);'>"+itemFontFamily[num]+"</span><br>");
}

function drawJustifyMenu(){
for(num=0;num<4;num++)
	document.write("<span class='JustifySpan' onMouseDown='setJustify("+num+")' onMouseOver='ItemFocus(this);'onMouseOut='ItemNormal(this);'>"+itemJustify[num]+"</span><br>");
}

function drawOrderedListMenu(){
document.write("<span class='JustifySpan' onMouseDown='insertOrderedList(0)' onMouseOver='ItemFocus(this);'onMouseOut='ItemNormal(this);'>数字列表</span><br>");
document.write("<span class='JustifySpan' onMouseDown='insertOrderedList(1)' onMouseOver='ItemFocus(this);'onMouseOut='ItemNormal(this);'>符号列表</span><br>");
}

function changeLinkStyleValue(obj){
document.getElementById("linkStyleValue").value=obj.options[obj.selectedIndex].getAttribute('value');
}

function drawCreatelinkMenu(){
document.write("<div class='linkBox'>");
document.write("链接地址: <input name='linkHref' id='linkHref' type='text' class='inputStyle' value='http://'><br>");
document.write("<span id='linkTextSpan' style='display:block;'>链接文字: <input name='linkText' id='linkText' type='text' class='inputStyle'><br></span>");
document.write("<input type=hidden name='linkStyleValue'id='linkStyleValue' value='_blank'>");
document.write("链接方式: <select name='linkStyle' size=1 style='background:#FFFFFF;margin-bottom:3px;'onchange='changeLinkStyleValue(this)'");
document.write("<option>请选择<option value='_blank' selected>_blank<option value='_self'>_self</select><br>");
document.write("<input value='确认' onClick='creatLink()' type='button' class='buttonStyle'> <input value='取消' onMouseDown='closeMenu()' type='button' name='upfile' class='buttonStyle'></div>");
}

function drawInsertFlvMenu(){
document.write("<div class='linkBox'>");
document.write("视频地址: <input name='flvHref' id='flvHref' type='text' class='inputStyle' value='http://'><br>");
document.write("视频简介: <input name='flvText' id='flvText' type='text' class='inputStyle'><br>");
document.write("<input value='插入视频' onClick='creatFlv()' type='button' class='buttonStyle'> <input value='取消' onMouseDown='closeMenu()' type='button' name='upfile' class='buttonStyle'></div>");
}

function changeAlignStyleValue(obj){
document.getElementById("alignStyleValue").value=obj.options[obj.selectedIndex].getAttribute('value');
}

function drawInsertImgMenu(){
document.write("<div class='linkBox'>");
document.write("图片地址: <input name='imgHref' id='imgHref' type='text' class='inputStyle' value='http://'> 必填<br>");
document.write("<input type=hidden name='alignStyleValue'id='alignStyleValue' value=''>");
document.write("对齐方式: <select name='alignStyle' size=1 style='background:#FFFFFF;margin-bottom:3px;'onchange='changeAlignStyleValue(this)'");
document.write("<option>请选择<option value='' selected>默认方式<option value='left'>居左对齐<option value='right'>居右对齐</select><br>");
document.write("<input value='插入图片' onClick='creatImg()' type='button' class='buttonStyle'> <input value='取消' onMouseDown='closeMenu()' type='button' name='upfile' class='buttonStyle'></div>");
}

function drawInsertFileMenu(){
document.write("<div class='linkBox'>");
document.write("文件地址: <input name='fileHref' id='fileHref' type='text' class='inputStyle' value='http://'> 必填<br>");
document.write("文件名称: <input name='fileName' id='fileName' type='text' class='inputStyle'> 必填<br>");
document.write("<input value='插入文件' onClick='creatFile()' type='button' class='buttonStyle'> <input value='取消' onMouseDown='closeMenu()' type='button' name='upfile' class='buttonStyle'></div>");
}

function drawInsertTableMenu(){
document.write("<div class='linkBox'>");
document.write("行数列数:<input type='text' id='tableForRows' name='tableForRows' class='inputStyle' style='width:40px;' value='3'> ");
document.write(" &times; <input type='text' id='tableForCols' name='tableForCols' class='inputStyle'style='width:40px;'value='4'><br>");
document.write("宽度高度:<input type='text' id='tableForWidth' name='tableForWidth' class='inputStyle'style='width:40px;'value='160'> ");
document.write(" &times; <input type='text' id='tableForHeight' name='tableForHeight' class='inputStyle'style='width:40px;'value='40'><br>");
document.write("表格标题:<input type='text' id='tableForTitle' name='tableForTitle' class='inputStyle'style='width:104px;' value='请填写表格标题'><br>");
document.write("<input value='插入表格' onClick='insertTable()' type='button' class='buttonStyle'> <input value='取消' onMouseDown='closeMenu()' type='button' name='upfile' class='buttonStyle'></div>");
}

function drawAboutMenu(){
document.write("<div class='linkBox'>红豆编辑器 <FONT face='Times New Roman'>&copy;</font> 版权所有<br>书红开发设计");
}

function ItemFocus(Obj){
Obj.style.background='#ABABA8';
Obj.style.color='#FFFFFF';
}

function ItemNormal(Obj){
Obj.style.background='#FFFFFF';
Obj.style.color='#000000';
}

function colorItemFocus(Obj){
Obj.style.border='1px solid #000000';
}

function colorItemNormal(Obj,ColorIndex){
Obj.style.border='1px solid '+itemColors[ColorIndex];
}

function drawColorMenu(){
document.write("<span style='font-size:12px;color:#888888;'>主题颜色:</span><br>");
for(col=0;col<10;col++)
	document.write("<span class='colorSpan' style='background:"+itemColors[col]+";margin-right:2px;margin-bottom:2px;border:1px solid "+itemColors[col]+";' onMouseDown='setSelForeColor("+(col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+col+")'>&nbsp;&nbsp;</span>");
document.write("<br>");
for(row=1;row<5;row++){
	for(col=0;col<10;col++)
		document.write("<span class='colorSpan' style='background:"+itemColors[10*row+col]+";border:1px solid "+itemColors[10*row+col]+";margin-right:2px;' onMouseDown='setSelForeColor("+(10*row+col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+(10*row+col)+")'>&nbsp;&nbsp;</span>");
	document.write("<br>");
}
document.write("<span style='font-size:12px;color:#888888;margin-top:2px;'>标准颜色:</span><br>");
for(col=60;col<70;col++)
	document.write("<span class='colorSpan' style='background:"+itemColors[col]+";margin-right:2px;margin-bottom:2px;border:1px solid "+itemColors[col]+";' onMouseDown='setSelForeColor("+(col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+col+")'>&nbsp;&nbsp;</span>");
}

function drawBackColorMenu(){
document.write("<span style='font-size:12px;color:#888888;'>主题颜色:</span><br>");
for(col=0;col<10;col++)
	document.write("<span class='colorSpan' style='background:"+itemColors[col]+";margin-right:2px;margin-bottom:2px;border:1px solid "+itemColors[col]+";' onMouseDown='setBackColor("+(col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+col+")'>&nbsp;&nbsp;</span>");
document.write("<br>");
for(row=1;row<5;row++){
	for(col=0;col<10;col++)
		document.write("<span class='colorSpan' style='background:"+itemColors[10*row+col]+";border:1px solid "+itemColors[10*row+col]+";margin-right:2px;' onMouseDown='setBackColor("+(10*row+col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+(10*row+col)+")'>&nbsp;&nbsp;</span>");
	document.write("<br>");
}
document.write("<span style='font-size:12px;color:#888888;magin-top:2px;'>标准颜色:</span><br>");
for(col=60;col<70;col++)
	document.write("<span class='colorSpan' style='background:"+itemColors[col]+";margin-right:2px;margin-bottom:2px;border:1px solid "+itemColors[col]+";' onMouseDown='setBackColor("+(col)+")' onMouseOver='colorItemFocus(this)' onMouseOut='colorItemNormal(this,"+col+")'>&nbsp;&nbsp;</span>");
}

function setSelForeColor(colorIndex){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("ForeColor","true",itemColors[colorIndex]); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("ForeColor","true",itemColors[colorIndex]);
} 
hiddenMenu(nowPanelID);
}

function setBackColor(colorIndex){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("BackColor","true",itemColors[colorIndex]); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("BackColor","true",itemColors[colorIndex]);
} 
hiddenMenu(nowPanelID);
}

function BarFocus(BarID){
if(BarID != nowPanelID)
hiddenMenu(nowPanelID);
document.getElementById(BarID+"Bar").className="BarFocus";
}

function BarNormal(BarID){
document.getElementById(BarID+"Bar").className="BarNormal";
}

function FullScreenBarNormal(BarID){
if(!fullScreenStat)
document.getElementById(BarID+"Bar").className="BarNormal";
}

function htmlBarNormal(BarID){
if(!htmlStat)
document.getElementById(BarID+"Bar").className="BarNormal";
}


var Sys = {};
var ua = navigator.userAgent.toLowerCase();
window.ActiveXObject ? Sys.ie = ua.match(/msie ([\d.]+)/)[1] :
document.getBoxObjectFor ? Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1] :
window.MessageEvent && !document.getBoxObjectFor ? Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1] :
window.opera ? Sys.opera = ua.match(/opera.([\d.]+)/)[1] :
window.openDatabase ? Sys.safari = ua.match(/version\/([\d.]+)/)[1] : 0;


function showMenu(PanelID){
if(PanelID != nowPanelID)hiddenMenu(nowPanelID);
nowPanelID=PanelID;
document.getElementById(PanelID+"Bar").className="BarMenuFocus";
document.getElementById(PanelID+"Menu").style.display="inline";

var obj = document.getElementById(PanelID+"Bar");
var menuBox = document.getElementById(PanelID+"Menu");
menuBox.style.position = "absolute";

if(document.selection && document.selection.createRange) { //如果是IE 
	if(Sys.ie == "8.0"){
		document.getElementById("toolBar").style.position = "relative";
		var leftValue = obj.offsetLeft;
		menuBox.style.left = (leftValue)+"px";
		menuBox.style.top = "24px";
	}
	else{
		var leftValue = obj.offsetLeft;
		while(obj = obj.offsetParent)
		{
			leftValue += obj.offsetLeft;
		}
		menuBox.style.left = (leftValue)+"px";
	}
} 
else {
	document.getElementById("toolBar").style.position = "relative";
	var leftValue = obj.offsetLeft;
	menuBox.style.left = (leftValue)+"px";
	menuBox.style.top = "24px";
}

}

function hiddenMenu(PanelID){
BarNormal(PanelID);
document.getElementById(PanelID+"Menu").style.display="none";
}

function closeMenu(){
hiddenMenu(nowPanelID);
}

function setBold(){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Bold", false, null); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Bold", false, null);
} 
	
}


function setItalic(){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Italic", false, null); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Italic", false, null);
}
}

function setUnderline(){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Underline", false, null); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Underline", false, null);
}
}

function setStrikethrough(){
document.getElementById("contentBox").focus();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Strikethrough", false, null); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Strikethrough", false, null);
}
}

function setFontSize(FontSizeValue){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
FontFamilyStr="<span style='font-size:"+itemFontsizeValue[FontSizeValue]+"px;'>"+(window.getSelection().toString())+"</span>";
document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",FontFamilyStr); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
FontFamilyStr="<span style='font-size:"+itemFontsizeValue[FontSizeValue]+"px;'>"+(document.selection.createRange().text)+"</span>";
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.pasteHTML(FontFamilyStr);
} 
hiddenMenu(nowPanelID);
}

function setFontFamily(FontFamilyIndex){ 
var range = document.getElementById("contentBox").document.selection.createRange(); 
    range.execCommand("Fontname","true",itemFontFamily[FontFamilyIndex]);
	hiddenMenu(nowPanelID);
}

function setJustify(index){
document.getElementById("contentBox").focus();
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand(itemJustifyValue[index], false, null); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	//var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
	range.execCommand(itemJustifyValue[index], false, null);
}
hiddenMenu(nowPanelID);
}

function insertOrderedList(style){
document.getElementById("contentBox").focus();
if(style==0){
	if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
		document.getElementById('contentBox').contentWindow.document.execCommand("InsertOrderedList", false, null); 
	}
	else if(document.selection && document.selection.createRange) { //如果是IE 
		//var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
		range.execCommand("InsertOrderedList", false, null);
	}
}
else {
	if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
		document.getElementById('contentBox').contentWindow.document.execCommand("InsertUnorderedList", false, null); 
	}
	else if(document.selection && document.selection.createRange) { //如果是IE 
		//var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
		range.execCommand("InsertUnorderedList", false, null);
	}
}

hiddenMenu(nowPanelID);
}

function creatLink(){
linkHref=document.getElementById("linkHref").value;
linkText=document.getElementById("linkText").value;
if(SelTxt!="")
linkText=SelTxt;
linkStyleValue=document.getElementById("linkStyleValue").value;
linkStr="<a href='"+linkHref+"' target='"+linkStyleValue+"'>"+linkText+"</a>";

document.getElementById("contentBox").focus();
	
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",linkStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	range.pasteHTML(linkStr);
} 
document.getElementById("linkHref").value="http://";
document.getElementById("linkText").value="";
hiddenMenu(nowPanelID);
}

function unLink(){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Unlink"); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Unlink");
} 
hiddenMenu(nowPanelID);
}

function creatFlv(){
var flvHref=document.getElementById("flvHref").value;
var flvText=document.getElementById("flvText").value;

var flvStr = flvText + "<br><object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=400 height=300 id=Player>"
flvStr = flvStr + "<param name=movie value=player.swf />"
flvStr = flvStr + "<param name=quality value=high />"
flvStr = flvStr + "<param name=allowFullScreen value=true />"
flvStr = flvStr + "<param name=FlashVars value=file="+flvHref+"&autostart=true&volume=60&backcolor=&0x000000&frontcolor=0xCCCCCC&lightcolor=0x557722 />"
flvStr = flvStr + "<embed src=player.swf allowfullscreen=true  width=400 height=300  flashvars=file="+flvHref+"&autostart=true&volume=60&backcolor=&0x000000&frontcolor=0xCCCCCC&lightcolor=0x557722 quality=high  type=application/x-shockwave-flash ></embed>"
flvStr = flvStr + "</object>"

document.getElementById("contentBox").focus();
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",flvStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	range.pasteHTML(flvStr);
} 
hiddenMenu(nowPanelID);
}

function creatImg(){
imgHref=document.getElementById('imgHref').value;
alignStyle=document.getElementById('alignStyleValue').value;
imgStr="<img src=\""+imgHref+"\" align=\""+alignStyle+"\">";

document.getElementById("contentBox").focus();	
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",imgStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	range.pasteHTML(imgStr);
} 
hiddenMenu(nowPanelID);
}

function creatFile(){
fileHref=document.getElementById('fileHref').value;
fileName=document.getElementById('fileName').value;
fileStr="<a href='"+fileHref+"' target='_blank'>"+fileName+"</a>";

document.getElementById("contentBox").focus();	
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",fileStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	range.pasteHTML(fileStr);
} 
hiddenMenu(nowPanelID);
}

function Removeformat(){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("Removeformat"); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("Removeformat");
} 
}

function SelectAll(){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("SelectAll"); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.execCommand("SelectAll");
} 
}

function insertTable(){
tableRows=document.getElementById("tableForRows").value>2?document.getElementById("tableForRows").value:2;
tableCols=document.getElementById("tableForCols").value>2?document.getElementById("tableForCols").value:2;
tableWidth=document.getElementById("tableForWidth").value>160?document.getElementById("tableForWidth").value:160;
tableHeight=document.getElementById("tableForHeight").value>40?document.getElementById("tableForHeight").value:40;
tableTitle=document.getElementById("tableForTitle").value;
tableStr="<table cellspacing=0 cellpadding=0 style='font-size:13px;border-left:1px solid #AFAFA9;border-top:1px solid #AFAFA9;width:"+tableWidth+"px;height:"+tableHeight+"px;'><caption style='text-align:center;'>"+tableTitle+"</caption>";
for(rows=0;rows<tableRows;rows++){
	tableStr+="<tr>";
	for(cols=0;cols<tableCols;cols++)
	    tableStr+="<td style='border-right:1px solid #AFAFA9;border-bottom:1px solid #AFAFA9;padding:2px;'></td>";
	tableStr+="</tr>";
}
tableStr+="</table>"

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",tableStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
range.pasteHTML(tableStr);
} 
hiddenMenu(nowPanelID);
}

function insertTime(){
var now=new Date();

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",now.toLocaleString( ) ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.text=range.text+now.toLocaleString( );
} 

}

function insertHr(){
htStr = "<div style='width:650px;font-size:6px;border-top:1px solid #CCCCCC;margin-top:6px;'>";

if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",htStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.pasteHTML(htStr);
}
}

function insertFileText(FileStr){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
	document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","",FileStr ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
	range.pasteHTML(FileStr);
}
hiddenMenu(nowPanelID);
}

function setPageTag(){
if(window.getSelection) { //如果是Firefox、Chrome、Safari、Opera
document.getElementById('contentBox').contentWindow.document.execCommand("insertHtml","","<-分页符->" ); 
}
else if(document.selection && document.selection.createRange) { //如果是IE 
var range = document.getElementById('contentBox').contentWindow.document.selection.createRange(); 
range.text=range.text+"<-分页符->";
}
}

function fullScreen(){
if(!fullScreenStat){
fullScreenStat=true;
document.getElementById("fullScreenBar").className="BarFocus";
document.getElementById("HdEditorLayout").className='FullScreen';
document.getElementById("toolBar").className='FullScreen';
}
else{
fullScreenStat=false;
document.getElementById("fullScreenBar").className="BarNormal";
document.getElementById("HdEditorLayout").className='NormalScreen';
}
}

function html(){
if(!htmlStat){
	htmlStat=true;
	document.getElementById("htmlBar").className="BarFocus";
    document.getElementById("contentBox").style.display="none";
	document.getElementById("contentTxt").style.display="block";
	document.getElementById("contentTxt").value=document.getElementById('contentBox').contentWindow.document.body.innerHTML;
	for(iconIndex=1;iconIndex<22;iconIndex++)
		document.getElementById("icon"+iconIndex).className="grayButton";
}
else{
	htmlStat=false;
	document.getElementById("htmlBar").className="BarNormal";
    document.getElementById("contentBox").style.display="block";
	document.getElementById("contentTxt").style.display="none";
	document.getElementById('contentBox').contentWindow.document.body.innerHTML=document.getElementById("contentTxt").value;	
	document.getElementById("grayBar").style.zIndex="97";
	for(iconIndex=1;iconIndex<22;iconIndex++)
		document.getElementById("icon"+iconIndex).className="unGrayButton";
}
}

function setClipboard(maintext) {
   if (window.clipboardData) {
      return (window.clipboardData.setData("Text", maintext));
   }
   else if (window.netscape) {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;
      trans.addDataFlavor('text/unicode');
      var str = new Object();
      var len = new Object();
      var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
      var copytext=maintext;
      str.data=copytext;
      trans.setTransferData("text/unicode",str,copytext.length*2);
      var clipid=Components.interfaces.nsIClipboard;
      if (!clip) return false;
      clip.setData(trans,null,clipid.kGlobalClipboard);
      return true;
   }
   return false;
}


function getClipboard() {
   if (window.clipboardData) {
      return(window.clipboardData.getData('Text'));
   }
   else if (window.netscape) {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;
      trans.addDataFlavor('text/unicode');
      clip.getData(trans,clip.kGlobalClipboard);
      var str = new Object();
      var len = new Object();
      try {
         trans.getTransferData('text/unicode',str,len);
      }
      catch(error) {
         return null;
      }
      if (str) {
         if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
         else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
         else str = null;
      }
      if (str) {
         return(str.data.substring(0,len.value / 2));
      }
   }
   return null;
}

// 清除WORD冗余格式并粘贴
function cleanAndPaste( html ) {
// Remove all SPAN tags
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
// Remove all A tags
//html = html.replace(/<\/?A[^>]*>/gi, "" );
// Remove all font tags
html = html.replace(/<\/?font[^>]*>/gi, "" );
// Remove all u tags
html = html.replace(/<\/?u[^>]*>/gi, "" );
// Remove onmouseover attributes
html = html.replace(/<(\w[^>]*) onmouseover=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove onmouseout attributes
html = html.replace(/<(\w[^>]*) onmouseout=([^ |>]*)([^>]*)/gi, "<$1$3") ;

// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Face attributes
html = html.replace(/<(\w[^>]*) face=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Size attributes
html = html.replace(/<(\w[^>]*) size=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove X:num attributes
html = html.replace(/<(\w[^>]*) x:num=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Width attributes
//html = html.replace(/<(\w[^>]*) width=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Height attributes
//html = html.replace(/<(\w[^>]*) height=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^  |>]*)([^>]*)/gi, "<$1$3") ;  
// Remove Style attributes
//html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
// Remove Lang attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove XML elements and declarations
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
// Replace the &nbsp;
html = html.replace(/&nbsp;/, " " );

// Transform <P> to <DIV>
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
html = html.replace( re, "<p$2</p>" ) ;

html=html.replace(/ x:num/g,"");

return html ;
}


function setFormatDataFuction(){
var editorRange=document.getElementById("contentBox").document.selection.createRange();//获得编辑器鼠标位置

filterDataObj=document.getElementById("filterDataDiv");//给过滤器存放原始文本数据
filterDataObj.focus();
filterDataObj.document.execCommand("Paste",false,null);

filterData=cleanAndPaste(filterDataDiv.innerHTML);//获取过滤后的清洁数据
editorRange.pasteHTML(filterData);//在编辑器鼠标位置插入过滤后的数据

filterDataDiv.innerHTML="";//清空过滤器中的数据
}