function AddText(NewCode) {
	document.forms[0].txtContent.value+=NewCode;
	document.forms[0].txtContent.focus();
}

function fontchuli(){
if ((document.selection)&&(document.selection.type == "Text")) {
var range = document.selection.createRange();
var ch_text=range.text;
range.text = fontbegin + ch_text + fontend;
} 
else {
document.forms[0].txtContent.value=fontbegin+document.forms[0].txtContent.value+fontend;
document.forms[0].txtContent.focus();
}
}

function email() {
		txt2=prompt("请输入需要加上EMAIL链接的链接文字.\n若欲显示EMAIL链接地址，则不输入。","我的EMAIL地址"); 
		if (txt2!=null) {
			txt=prompt("请输入Email地址。","");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[email]"+txt+"[/email]";
				} else {
					AddTxt="[email="+txt+"]"+txt2+"[/email]";
				} 
				AddText(AddTxt);	        
			}
		}
}

function bold() {
fontbegin="[b]";
fontend="[/b]";
fontchuli();  
}

function italicize() {
fontbegin="[i]";
fontend="[/i]";
fontchuli();     
}

function center() {
fontbegin="[center]";
fontend="[/center]";
fontchuli();     
}

function hyperlink() {
		txt2=prompt("请输入需要加上超级链接的链接文字.\n若欲显示超级链接地址，则不输入。",""); 
		if (txt2!=null) {
			txt=prompt("超级链接的URL，也支持形如：FTP://………的形式。","http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url="+txt+"]"+txt2+"[/url]";
					AddText(AddTxt);
				}         
		}
	}
}

function image() {
		txt=prompt("请输入图片的地址。http://为必填代码请勿删除。在任一网站里的图上点右键，选择“属性”可查看此图地址，输入此地址即可。","http://");    
		if(txt!=null) {
			if (txt.substring(0,7).toLowerCase()=="http://")
			{
				AddTxt="\r[img]"+txt+"[/img]";
				AddText(AddTxt);
			}
			else{
				alert("你输入的不是正确的图片地址！")
			}
		}	
}

function flash() 
{
	txt2=prompt("flash宽度，高度","500,350"); 
	if (txt2!=null) 
	{
        	txt=prompt("Flash 文件的地址","http://");
		if (txt!=null) 
		{
                       	if (txt2=="")
			{             
				AddTxt="[flash=500,350]"+txt;
				AddText(AddTxt);
				AddTxt="[/flash]";
				AddText(AddTxt);
               		}
			else
			{
		       		AddTxt="[flash="+txt2+"]"+txt;
				AddText(AddTxt);
				AddTxt="[/flash]";
				AddText(AddTxt);
			 }        
	   	}  
       	}	
}
function sdir()
{
	txt2=prompt("视频的宽度，高度","500,350"); 
	if (txt2!=null) 
	{
        	txt=prompt("视频文件的地址","请输入地址");
		if (txt!=null) 
		{
                       	if (txt2=="")
			{             
				AddTxt="[dir=500,350]"+txt;
				AddText(AddTxt);
				AddTxt="[/dir]";
				AddText(AddTxt);
               		}
			else
			{
		       		AddTxt="[dir="+txt2+"]"+txt;
				AddText(AddTxt);
				AddTxt="[/dir]";
				AddText(AddTxt);
			 }        
	   	}  
       	}	
}
function rm()
{
	txt2=prompt("视频的宽度，高度，播放参数\r\n（播放参数：0=手动播放，1=自动播放）","500,350,1"); 
	if (txt2!=null) 
	{
        	txt=prompt("视频文件的地址","请输入地址");
		if (txt!=null) 
		{
                       	if (txt2=="")
			{             
				AddTxt="[rm=500,350,1]"+txt;
				AddText(AddTxt);
				AddTxt="[/rm]";
				AddText(AddTxt);
               		}
			else
			{
		       		AddTxt="[rm="+txt2+"]"+txt;
				AddText(AddTxt);
				AddTxt="[/rm]";
				AddText(AddTxt);
			 }        
	   	}  
       	}	
}
function mp()
{
	txt2=prompt("视频的宽度，高度，播放参数\r\n（播放参数：0=手动播放，1=自动播放）","500,350,1"); 
	if (txt2!=null) 
	{
        	txt=prompt("视频文件的地址","请输入地址");
		if (txt!=null) 
		{
                       	if (txt2=="")
			{             
				AddTxt="[mp=500,350,1]"+txt;
				AddText(AddTxt);
				AddTxt="[/mp]";
				AddText(AddTxt);
               		}
			else
			{
		       		AddTxt="[mp="+txt2+"]"+txt;
				AddText(AddTxt);
				AddTxt="[/mp]";
				AddText(AddTxt);
			 }        
	   	}  
       	}	
}
function qt()
{
	txt2=prompt("视频的宽度，高度","500,350"); 
	if (txt2!=null) 
	{
        	txt=prompt("视频文件的地址","请输入地址");
		if (txt!=null) 
		{
                       	if (txt2=="")
			{             
				AddTxt="[qt=500,350]"+txt;
				AddText(AddTxt);
				AddTxt="[/qt]";
				AddText(AddTxt);
               		}
			else
			{
		       		AddTxt="[qt="+txt2+"]"+txt;
				AddText(AddTxt);
				AddTxt="[/qt]";
				AddText(AddTxt);
			 }        
	   	}  
       	}	
}
function underline() {
fontbegin="[u]";
fontend="[/u]";
fontchuli();	        
}
function fly() {
fontbegin="[fly]";
fontend="[/fly]";
fontchuli();
}
function move() {
fontbegin="[move]";
fontend="[/move]";
fontchuli();
}
function glow() {
		txt2=prompt("请输入文字的长度，颜色，边界大小。","255,red,2"); 
		if (txt2!=null) {
			txt=prompt("要产生效果的文字","发光文字");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[glow=255,red,2]"+txt+"[/glow]";
					AddText(AddTxt);
				} else {
					AddTxt="[glow="+txt2+"]"+txt+"[/glow]";
					AddText(AddTxt);
				}         
		}
	}
}
function shadow() {
		txt2=prompt("请输入文字的长度，颜色，边界大小。","255,red,2"); 
		if (txt2!=null) {
			txt=prompt("要产生效果的文字","阴影文字");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[shadow=255,red,2]"+txt+"[/shadow]";
					AddText(AddTxt);
				} else {
					AddTxt="[shadow="+txt2+"]"+txt+"[/shadow]";
					AddText(AddTxt);
				}         
		}
	}
}
function CleanCode(){
		var html = document.forms[0].txtContent.value;
		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>");
		document.forms[0].txtContent.value = html;
}

function quote(){
fontbegin="[quote]";
fontend="[/quote]";
fontchuli();
}

function code(){
fontbegin="[code]";
fontend="[/code]";
fontchuli();
}

function html(){
fontbegin="[html]";
fontend="[/html]";
fontchuli();
}

function showsize(size){
fontbegin="[size="+size+"]";
fontend="[/size]";
fontchuli();
}

function showfont(font){
fontbegin="[face="+font+"]";
fontend="[/face]";
fontchuli();
}

function showcolor(color){
fontbegin="[color="+color+"]";
fontend="[/color]";
fontchuli();
}
function Previewing()
{
document.forms[1].title.value=document.forms[0].txtTitle.value;
document.forms[1].Content.value=document.forms[0].txtContent.value;
document.forms[1].submit()
}
