//请在要使用此文件的页面的onload事件中加入OnInit(txt)基中txt用内容文本框的ID代替
//比如：<body leftmargin="2" topmargin="2" marginwidth="0" marginheight="0" onLoad="OnInit('Message')" >
//请对编辑的内容框加入事件 onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);"
//比如：<asp:TextBox id="Txt" onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);"></asp:TextBox></FONT>
//引用此文件时注意字符集 <script language="javascript" src="js/func.js" charset="gb2312"></script>   


var objText;  
function OnInit(Txt)
{
  objText=document.getElementById(Txt);	
}

function smilieopen() 
{

	sx=window.prompt("请输入要调用的样式名","css_name");
	while (sx!=null)
	{
		if (sx=="")
		{
			alert("请您先输入调用样式名！");
			sx=window.prompt("请输入要调用的样式名","css_name");
		}
		px=window.prompt("请输入要应用样式的文字内容","content");
		if (sx!=null && px!=null)
		{
		temp_mp="[css:"+sx+"]"+px+"[/css]"
		AddText(temp_mp);
		}
		break;
	}

}

function viewubb() {msg=window.open("../Modules/UbbHelp.htm","","height=500,width=500,left=5,top=5,scrollbars=yes,toolbar=no,directories=no,status=no,menubar=no,resizable=yes");}
helpstat = false;
stprompt = true;
basic = false;
function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}
////////////////////////////////////////////////
function storeCaret (textEl) {
if (textEl.createTextRange) 
textEl.caretPos = document.selection.createRange().duplicate();    
}
function insertAtCaret (textEl, text) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text;      
}      
else        
textEl.value  = text;
    
}    
function AddText(NewCode) {
insertAtCaret(objText, NewCode)
}
///////////////////////////////////////////////////////
function email() {
	if (helpstat) {
		alert("Email Tag\nTurns an email address into a mailto hyperlink.\nUSE: [email]someone@anywhere.com[/email]\nUSE: [email=someone@anywhere.com]link text[/email]");
	} else if (basic) {
		AddTxt="[email][/email]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("请输入您要链接的邮箱名，若不填则默认显示为邮件地址。",""); 
		if (txt2!=null)
		{
			txt=prompt("请输入完全的电子邮箱地址：","name@domain.com");      
			while (txt!=null) 
			{
				if (txt=="")
				{
					alert("请您先输入电子邮箱地址！");
					txt=prompt("请输入完全的电子邮箱地址：","name@domain.com"); 
				}
				else
				{
					if (txt2=="")
					{
						AddTxt="[email]"+txt+"[/email]";
					} 
					else 
					{
						AddTxt="[email="+txt+"]"+txt2+"[/email]";
					} 
					AddText(AddTxt);
					break;
				}
			}
		}
	}
}

function showsize(size) {
	if (helpstat) {
		alert("Size Tag\nSets the text size.\nPossible values are 1 to 6.\n 1 being the smallest and 6 the largest.\nUSE: [size="+size+"]This is size "+size+" text[/size]");
	} else if (basic) {
		AddTxt="[size="+size+"][/size]";
		AddText(AddTxt);
	} else {                       
		txt=prompt("Text to be size "+size,"Text"); 
		if (txt!=null) {             
			AddTxt="[size="+size+"]"+txt+"[/size]";
			AddText(AddTxt);
		}        
	}
}

function bold() {
	if (helpstat) {
		alert("Bold Tag\nMakes the enlosed text bold.\nUSE: [b]This is some bold text[/b]");
	} else if (basic) {
		AddTxt="[b][/b]";
		AddText(AddTxt);
	} else {  
		txt=prompt("文本变粗体。","Text");     
		if (txt!=null) {           
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}       
	}
}

function italicize() {
	if (helpstat) {
		alert("Italicize Tag\nMakes the enlosed text italicized.\nUSE: [i]This is some italicized text[/i]");
	} else if (basic) {
		AddTxt="[i][/i]";
		AddText(AddTxt);
	} else {   
		txt=prompt("文本变斜体。","Text");     
		if (txt!=null) {           
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}	        
	}
}

function quote() {
	if (helpstat){
		alert("Quote tag\nQuotes the enclosed text to reference something specific that someone has posted.\nUSE: [quote]This is a quote[/quote]");
	} else if (basic) {
		AddTxt="\r[quote]\r[/quote]";
		AddText(AddTxt);
	} else {   
		txt=prompt("请输入引用文字：","Text");     
		if(txt!=null) {          
			AddTxt="\r[quote]\r"+txt+"\r[/quote]";
			AddText(AddTxt);
		}	        
	}
}

function showcolor(color) {
	if (helpstat) {
		alert("Color Tag\nSets the text color.  Any named color can be used.\nUSE: [color="+color+"]This is some "+color+" text[/color]");
	} else if (basic) {
		AddTxt="[color="+color+"][/color]";
		AddText(AddTxt);
	} else {
		var color1;
		switch(color)
		{
			case "Black":
				color1="黑色";
				break;
			case "Red":
				color1="红色";
				break;
			case "Yellow":
				color1="黄色";
				break;
			case "Pink":
				color1="粉色";
				break;
			case "Green":
				color1="绿色";
				break;
			case "Orange":
				color1="橙色";
				break;
			case "Purple":
				color1="紫色";
				break;
			case "Blue":
				color1="蓝色";
				break;
			case "Beige":
				color1="米色";
				break;
			case "Brown":
				color1="棕色";
				break;
			case "Teal":
				color1="深绿色";
				break;
            case "Navy":
				color1="深蓝色";
				break;
            case "Maroon":
				color1="紫红色";
				break;
			case "LimeGreen":
				color1="鲜绿色";
				break;
		}
		
     	txt=prompt("请输入显示为"+color1+"的文字","Text");
		if(txt!=null) {
			AddTxt="[color="+color+"]"+txt+"[/color]";
			AddText(AddTxt);        
		} 
	}
}

function center() {
 	if (helpstat) {
		alert("Centered tag\nCenters the enclosed text.\nUSE: [center]This text is centered[/center]");
	} else if (basic) {
		AddTxt="[center][/center]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be centered","Text");     
		if (txt!=null) {          
			AddTxt="\r[center]"+txt+"[/center]";
			AddText(AddTxt);
		}	       
	}
}

function hyperlink() {
	if (helpstat) {
		alert("Hyperlink Tag\nTurns an url into a hyperlink.\nUSE: [url]http://www.anywhere.com[/url]\nUSE: [url=http://www.anywhere.com]link text[/url]");
	} else if (basic) {
		AddTxt="[url][/url]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("请输入您要链接的文字，若不填则默认显示为链接地址。",""); 
		if (txt2!=null) 
		{
			txt=prompt("请输入完全的URL链接地址:","http://");      
			while (txt!=null) 
			{
				if (txt=="" || txt=="http://")
				{
					alert("请您先输入链接地址！");
					txt=prompt("请输入完全的URL链接地址:","http://");
				}
				else
				{
					if (txt2=="") 
					{
						AddTxt="[url]"+txt+"[/url]";
						AddText(AddTxt);
					} 
					else 
					{
						AddTxt="[url="+txt+"]"+txt2+"[/url]";
						AddText(AddTxt);
					}
					break;
				}
			} 
		}
	}
}

function image() {
	if (helpstat){
		alert("Image Tag\nInserts an image into the post.\nUSE: [img]http:\www.anywhere.comimage.gif[/img]");
	} else if (basic) {
		AddTxt="[img][/img]";
		AddText(AddTxt);
	} else {  
		txt=prompt("插入图片地址","http://");    
		tp=prompt("输入图片对齐方式，可以输入l（左）或者r（右），默认请不填","");  
		if(txt!=null) {  
		if(tp==null) tp="";         
			AddTxt="\r["+tp+"img]"+txt+"[/"+tp+"img]";
			AddText(AddTxt);
		}	
	}
}

function cimage() {
	if (helpstat){
		alert("Image Tag\nInserts an image into the post.\nUSE: [img]http://www.tiancity.com/images/top.gif[/img]");
	} else if (basic) {
		AddTxt="[img][/img]";
		AddText(AddTxt);
	} else {  
		txt=prompt("请输入正确的图片地址，以保证图片能被显示。","http://");  
		while (txt!=null)
		{
			if (txt=="" || txt=="http://")
			{
				alert("请您先输入图片地址！");
				txt=prompt("请输入正确的图片地址，以保证图片能被显示。","http://");
			}
			else
			{
				tp=prompt("输入图片对齐方式，可以输入l（左）或者r（右），默认请不填","");  
				//if(tp!=null)
				//{  
				if(tp==null) tp="";         
				AddTxt="\r["+tp+"img]"+txt+"[/"+tp+"img]";
				AddText(AddTxt);
				//}
				break;
			}
		}
	}
}

function showcode() {
	if (helpstat) {
		alert("Code Tag\nBlockquotes the text you reference and preserves the formatting.\nUsefull for posting code.\nUSE: [code]This is formated text[/code]");
	} else if (basic) {
		AddTxt="\r[code]\r[/code]";
		AddText(AddTxt);
	} else {   
		txt=prompt("请输入要插入的程序代码：","");     
		if (txt!=null) {          
			AddTxt="\r[code]"+txt+"[/code]";
			AddText(AddTxt);
		}	       
	}
}

function list() {
	if (helpstat) {
		alert("List Tag\nBuilds a bulleted, numbered, or alphabetical list.\nUSE: [list]\n[*]item1\n[*]item2\n[*]item3\n[/list]");
	} else if (basic) {
		AddTxt="\r[list]\r[*]\r[*]\r[*]\r[/list]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Type of list\nEnter 'A' for alphabetical, '1' for numbered, Leave blank for bulleted.","");               
		while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
			txt=prompt("ERROR!\nThe only possible values for type of list are blank 'A' and '1'.","");               
		}
		if (txt!=null) {
			if (txt=="") {
				AddTxt="\r[list]\r\n";
			} else {
				AddTxt="\r[list="+txt+"]\r";
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("List item\nLeave blank to end list",""); 
				if (txt!="") {             
					AddTxt+="[*]"+txt+"\r"; 
				}                   
			} 
			AddTxt+="[/list]\r\n";
			AddText(AddTxt); 
		}
	}
}

function underline() {
  	if (helpstat) {
		alert("Underline Tag\nUnderlines the enclosed text.\nUSE: [u]This text is underlined[/u]");
	} else if (basic) {
		AddTxt="[u][/u]";
		AddText(AddTxt);
	} else {  
		txt=prompt("添加下划线。","Text");     
		if (txt!=null) {           
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}	        
	}
}

function showfont(font) {
 	if (helpstat){
		alert("Font Tag\nSets the font face for the enclosed text.\nUSE: [font="+font+"]The font of this text is "+font+"[/font]");
	} else if (basic) {
		AddTxt="[font="+font+"][/font]";
		AddText(AddTxt);
	} else {                  
		txt=prompt("Text to be in "+font,"Text");
		if (txt!=null) {             
			AddTxt="[font="+font+"]"+txt+"[/font]";
			AddText(AddTxt);
		}        
	}  
}
function setsmiley(what) 
{ 
objText.value = objText.value+" "+what; 
objText.focus(); 
} 
function face(smile)
{
   
AddText(smile);

}

function swf()
{
	sx=window.prompt('输入 Flash 文件地址：','http://');
	while (sx!=null)
	{
		if (sx=="" || sx=="http://")
		{
			alert("请您先输入FLASH文件地址！");
			sx=window.prompt('输入 Flash 文件地址：','http://');
		}
		else
		{	
			vv=window.prompt('输入宽和高','350,280');
			if (!(sx=='' || sx==null || vv=='' || vv==null))
			{
			temp_swf="[swf="+vv+"]"+sx+"[/swf]"
			AddText(temp_swf);
			}
			break;
		}
	}
}

function cdir()
{
	sx=window.prompt('输入 Shockwave 文件地址：','http://');
	while (sx!=null)
	{
		if (sx=="" || sx=="http://")
		{
			alert("请您先输入shockwave文件地址！");
			sx=window.prompt('输入 Shockwave 文件地址：','http://');
		}
		else
		{
			vv=window.prompt('输入宽和高','350,280');
			if (!(sx=='' || sx==null || vv=='' || vv==null))
			{
			temp_swf="[dir="+vv+"]"+sx+"[/dir]"
			AddText(temp_swf);}
			break;
		}
	}
}

function cmp()
{
	sx=window.prompt('输入 Windows media player 文件地址：','');
	while (sx!=null)
	{
		if (sx=="")
		{
			alert("请您先输入文件地址！");
			sx=window.prompt('输入 Windows media player 文件地址：','');
		}
		else
		{
			vv=window.prompt('输入宽和高','350,300');
			vc=window.prompt('是否自动播放，请输入小写的: y(是) or n(否)\n保持空表示默认为自动播放!','');
			if (!(vc=='' || vc==null))
			tvc=":"+vc;
			else
			tvc="";
			if (!(sx=='' || sx==null || vv=='' || vv==null))
			{
			temp_mp="[mp="+vv+tvc+"]"+sx+"[/mp]"
			AddText(temp_mp);}
			break;
		}
	}
}

function crm()
{
	sx=window.prompt('输入 RM 文件地址：','');
	while (sx!=null)
	{
		if (sx=="")
		{
			alert("请您先输入文件地址！");	
			sx=window.prompt('输入 RM 文件地址：','');
		}
		else
		{
			vv=window.prompt('输入宽和高','350,300');
			vc=window.prompt('是否自动播放，请输入小写的: y(是) or n(否)\n保持空表示默认为自动播放!','');
			if (!(vc=='' || vc==null))
			tvc=":"+vc;
			else
			tvc="";
			if (!(sx=='' || sx==null || vv=='' || vv==null))
			{
			temp_mp="[rm="+vv+tvc+"]"+sx+"[/rm]"
			AddText(temp_mp);}
			break;
		}
	}
}

function cqt()
{
	sx=window.prompt('输入 Quick Time 文件地址：','');
	while (sx!=null)
	{
		if (sx=="")
		{
			alert("请您先输入文件地址！");	
			sx=window.prompt('输入 Quick Time 文件地址：','');
		}
		else
		{
			vv=window.prompt('输入宽和高','350,300');
			vc=window.prompt('是否自动播放，请输入小写的: y(是) or n(否)\n保持空表示默认为自动播放!','');
			if (!(vc=='' || vc==null))
			tvc=":"+vc;
			else
			tvc="";
			if (!(sx=='' || sx==null || vv=='' || vv==null))
			{
			temp_mp="[qt="+vv+tvc+"]"+sx+"[/qt]"
			AddText(temp_mp);}
			break;
		}
	}
}

function cmove()
{
sx=window.prompt('请输入移动文字：','Text');
if (!(sx=='' || sx==null))
{
temp_mp="[move]"+sx+"[/move]"
AddText(temp_mp);}
}

function cfly()
{
sx=window.prompt('请输入飞行文字：','Text');
if (!(sx=='' || sx==null))
{
temp_mp="[fly]"+sx+"[/fly]"
AddText(temp_mp);}
}

function calign()
{
sx=window.prompt('输入内容：','Text');
if (!(sx=='' || sx==null))
{
temp_mp="[align=center]"+sx+"[/align]"
AddText(temp_mp);}
}
function pasteC(){
	alert("本还原操作将粘贴最近一次拷贝的内容！");
	objText.focus();
	objText.createTextRange().execCommand("Paste");
}
function imagesize(objImg)
{
var width=objImg.width;
var height=objImg.height;
	var i=width/height;	

if (width>400 && width>height) {
	width=400;
	height=width/i;
	objImg.width=width;
	objImg.height=height;
}else if (height>400) {
	height=400;
	width=height*i;
	objImg.width=width;
	objImg.height=height;
}
}
function writeface()
{
									var ct=0;
									ct=31;      //表情数量       
									mct='';
									for(i=1;i<=ct;i++)                                                  //在此修改表情的路径
									 mct=mct+"<a href=\"javascript:face(':em"+i.toString()+":')\"><img src='http://bbspopkart.tiancity.com/Modules/face/"+i.toString()+ ".gif' border=0></a>  ";
									return mct;
									}