//ubb标记
var text_enter_url      = "请输入连接网址";	
var text_enter_txt		= "请输入连接说明";
var error_no_url		= "您必须输入网址";
var error_no_txt        = "您必须连接说明";
var text_enter_guang1	= "文字的长度、颜色和边界大小";
var text_enter_guang2	= "要产生效果的文字！";
var error_no_email		= "您必须输入邮件网址";
var error_no_gset		= "必须正确按照各式输入！";
var error_no_gtxt		= "必须输入文字！";	
var text_enter_image	= "请输入图片网址";	


function TxBBS_ubb(code,value)
{
	if (value)
	{
		fontbegin="["+code+"="+value+"]";
	}else{
		fontbegin="["+code+"]";
	}
	fontend="[/"+code+"]";
	fontchuli();
}
function TxBBS_InsertStr(value)//在光标位置插入字符
{
	fontbegin = value;
	fontend = "";
	fontchuli();
}
function TxBBS_Curl()//添加超级链接
{
	var FoundErrors = '';
	var enterURL   = prompt(text_enter_url, "http://");
	var enterTxT   = prompt(text_enter_txt, enterURL);
	if (!enterURL)    {
	FoundErrors += "\n" + error_no_url;
	}
	if (!enterTxT)    {
	FoundErrors += "\n" + error_no_txt;
	}
	if (FoundErrors)  {
	alert("错误！"+FoundErrors);
	return;
	}
	fontbegin = "[URL="+enterURL+"]"+enterTxT+"[/URL]";
	fontend = "";
	fontchuli();
}
function TxBBS_Img()//插入图片
{
var FoundErrors = '';
	var enterSET   = prompt(text_enter_image, "http://");
	if (!enterSET)    {
	FoundErrors += "\n" + error_no_url;
	}
	if (FoundErrors)  {
	alert("错误！"+FoundErrors);
	return;
	}
	fontbegin = "[img]"+enterSET+"[/img]";
	fontend = "";
	fontchuli();
}
function TxBBS_Cguang()//发光字
{
	var FoundErrors = '';
	var enterSET   = prompt(text_enter_guang1, "255,red,2");
	//var enterTxT   = prompt(text_enter_guang2, "文字");
	if (!enterSET)    {
	FoundErrors += "\n" + error_no_gset;
	}
	/*
	if (!enterTxT)
	{
	FoundErrors += "\n" + error_no_gtxt;
	}
	*/
	if (FoundErrors)  {
	alert("错误！"+FoundErrors);
	return;
	}
	fontbegin = "[glow="+enterSET+"]";
	fontend = "[/glow]";
	fontchuli();
}
function TxBBS_Cying()//阴影字
{
	var FoundErrors = '';
	var enterSET   = prompt(text_enter_guang1, "255,blue,1");
	//var enterTxT   = prompt(text_enter_guang2, "文字");
	if (!enterSET)    {
	FoundErrors += "\n" + error_no_gset;
	}
	/*
	if (!enterTxT)    {
	FoundErrors += "\n" + error_no_gtxt;
	}
	*/
	if (FoundErrors)  {
	alert("错误！"+FoundErrors);
	return;
	}
	fontbegin = "[SHADOW="+enterSET+"]";
	fontend = "[/SHADOW]";
	fontchuli();
}

function fontchuli()
{
var ContentText = document.getElementById("Content");
var range = ContentText.pos;
if(range == undefined)
{
	ContentText.value += fontbegin + fontend;
}
else
{
	var ch_text=range.text;
	range.text = fontbegin + ch_text + fontend;
}
}

function TxBBS_FormatText(command, option)
{
	switch (command)
	{
		case 'fontsize':
			TxBBS_ubb("size",option)
			break;
		case 'fontname':
			TxBBS_ubb("face",option)
			break;
	}
	return;
}

function TxBBS_foreColor()//调色版工具
{
	var arr = showModalDialog("selcolor.htm", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
	if (arr != null)
	{
		TxBBS_ubb("color",arr);
	}
}
function TxBBS_insertSpecialChar()//特殊字符工具
{
	var arr = showModalDialog("specialchar.htm", "","dialogWidth:25em; dialogHeight:15em; status:0; help:0");
	if (arr != null)
	{
		//Dvbbs_InsertSymbol(arr);
		fontbegin = arr;
		fontend = "";
		fontchuli();
	}
}
function TxBBS_replace()//替换工具
{
	var arr = showModalDialog("replace.htm", "", "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 = document.getElementById("Content").value;
		if (i == 1)
		{
			con = TxBBS_rCode(con,a,b,true);
		}else{
			con = TxBBS_rCode(con,a,b);
		}
		document.getElementById("Content").value = con;
	}
}

function TxBBS_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); 
}
function openEditScript(url, width, height){
	var Win = window.open(url,"openEditScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
}

/*心情图片 start*/
var Emot_PageSize = 8;
function ShowForum_Emot(thepage)
{
	var Emot_PageCount
	//var Emot_Count=Forum_Emot.length-2;
	var Emot_Count=499;
	if(Emot_Count%Emot_PageSize==0)
	{
		Emot_PageCount=(Emot_Count)/Emot_PageSize
	}else{
		Emot_PageCount=Math.floor((Emot_Count)/Emot_PageSize)+1
	}
	thepage=parseInt(thepage);
	if (thepage<=Emot_PageCount){
	var istr
	var EmotStr='&nbsp;';
	var EmotPath='images/emotion/';
	if (thepage!=1 && Emot_PageCount>1)
	{EmotStr+='<img style="cursor: pointer;" onClick="ShowForum_Emot('+(thepage-1)+');" src="images/ubb/Previous.gif" width="14" height="14" title="上一页">&nbsp;';}
	for(i=(thepage-1)*Emot_PageSize+1;i<(thepage-1)*Emot_PageSize+Emot_PageSize;i++)
	{
		if (i>Emot_Count){break}
		if (i<10)
			{
				ii='00'+i;
			}
			else if(i<100)
			{
				ii = '0'+i;
			}
			else
			{
				ii=i;
			}
			istr='em'+ii;
			/*
		if (i<9)
			{istr='em0'+(i+1)}
			else
			{istr='em'+(i+1)}
			*/
		EmotStr+='<img title="'+istr+'" style="cursor: pointer;" onClick=putEmot("'+istr+'"); src="'+EmotPath+ii+'.gif">&nbsp;';
	}
	if (thepage!=Emot_PageCount)
	{EmotStr+='<img style="cursor: pointer;" onClick="ShowForum_Emot('+(thepage+1)+');" src="images/ubb/Next.gif" width="14" height="14" title="下一页">&nbsp;';}
	EmotStr+='<br>分页：<b>'+thepage+'</b>/<b>'+Emot_PageCount+'</b>，共<b>'+(Emot_Count)+'</b>个';
	EmotStr+="<select id=emotpage onchange=\"ShowForum_Emot(this.value);\">";
	for (i=1; i<=Emot_PageCount;i++ )
	{
		EmotStr+="<option value=\""+i+"\">"+i;
	}
	EmotStr+="<\/select> <a href='#' onclick=\"openEditScript('smiley.htm',660,450);\">全部表情</a>";
	var Forum_EmotObj=document.getElementById("emot");
	Forum_EmotObj.innerHTML=EmotStr;
	document.getElementById('emotpage').options[thepage-1].selected=true;
	}
}
function putEmot(thenNo)
{
	var ToAdd = '['+thenNo+']';
	fontbegin = ToAdd;
	fontend = "";
	fontchuli();
}
/*心情图片 end*/

function TxBBS_CopyToClipboard(str)
{        
	window.clipboardData.setData('text',str);
}

function TxBBS_PayOrPrizePostHint(val)
{
	if (val.value == '5')
	{
		alert('收费帖要扣掉 100*金额 同种币种的保证金，待正常结贴后退还！');
	}
	else if (val.value == '6')
	{
		alert('悬赏贴要扣掉 同种金额 同种币种的保证金，待正常结贴后退还！');
	}
	else if (val.value == '8')
	{
		alert('赠送贴将把你指定数目的铁血币送给楼主！');
	}
}

function bbimg(o)
{
	var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
	return false;
}
var posti=0;
function storeCaret()//管理键盘快捷键发帖
{
	if(event.ctrlKey && window.event.keyCode==13)
	{
		Checkdata();
		if(ischeck==true)
		{
			posti++;
			if(posti>1)
			{
				alert('帖子正在发出，请耐心等待！');
				return false;
			}
			else
			{
				document.getElementById("submitpost").disabled = true;
				this.document.postform.submit();
			}
		}
	}
}

function AddImageToBox(imgurl)
{
	fontbegin = "[img]"+imgurl+"[/img]";
	fontend = "";
	fontchuli();
}