﻿var hasAudio = !!document.createElement('audio').canPlayType;
function ResetReplyTitle(v,t){var _tempTtl = (window.newposterfrm.document.getElementById('ttl')!=null)?window.newposterfrm.document.getElementById('ttl'):$('ttl');_tempTtl.value=(_tempTtl.value.indexOf('复:')>0)?t:'回复:'+t;	}
function runCode(obj) {var w = window.open('', "_blank", '');w.document.open('text/html', 'replace');w.document.writeln(document.getElementById(obj).value);w.document.close();}
strIcons = "1"
strSmile="1"
ImgName="em"
picurl="../clzx/UBBicon/"
var _tempId=1;
function UBBCode(content,html){
st=new Date().getTime()
content=content.replace(/\[(\/)?phx_code\]/ig,"{$1phx_code}");
content=content.replace(/\[(\/)?phx_html\]/ig,"{$1phx_html}");
content="[phx_code]"+content+"[/phx_code]";          
content=content.replace(/(\[code\]([\s\S]+?)\[\/code\])/ig,"[/phx_code]$1[phx_code]");
content=content.replace(/\[phx_code\]([\s\S]*?)\[\/phx_code\]/ig,function($1,$2){if(html=="html"){return(HTMLCode($2));}else{return(trans($2));}});
content=content.replace(/\[code\](\r\n)?([\s\S]+?)\[\/code\]/ig,function($1,$2,$3){return("<PRE class=CodeSamp>"+DvbbsHtmlAn($3)+"</PRE>")});
content=content.replace(/\{(\/)?phx_code\}/ig,"[$1phx_code]");
content=content.replace(/\{(\/)?phx_html\}/ig,"[$1phx_html]");
_tempId++;
return(content);
}

function HTMLCode(content){		
content="[phx_html]"+content+"[/phx_html]";    
content=content.replace(/(\[html\]([\s\S]+?)\[\/html\])/ig,"[/phx_html]$1[phx_html]");
content=content.replace(/\[phx_html\]([\s\S]*?)\[\/phx_html\]/ig,function($1,$2){return(trans($2))});
content=content.replace(/\[html\]([\s\S]+?)\[\/html\]/ig,function($1,$2){return("<span><TEXTAREA id=\"code"+_tempId+"\" style=\"width: 95%;overflow:auto\" rows=12>"+hencode($2)+"</TEXTAREA><br><input type=button onclick=\$copy($v('code"+_tempId+"')) value=拷贝代码 /><INPUT onclick=runCode('code"+_tempId+"') type=button value=运行代码>[Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</span>")});
return(content);
}

function hencode(fString){
	fString = fString;
	fString = fString.replace(/<br \/>/ig,"\r\n");
	fString = fString.replace(/&apos;/ig,"\'");
return fString;
}

function DvbbsHtmlAn(fString){
if(fString=='')return('');
	fString=hencode(fString)
	fString = fString.replace(/\t/ig,"&nbsp;&nbsp;&nbsp;");
	fString = fString.replace(/"/ig,"&quot;");
	fString = fString.replace(/'/ig,"&#39;");
	fString = fString.replace(/\r/ig,"");
	fString = fString.replace(/\n\n/ig,"<P>");
	fString = fString.replace(/\n/ig,"<BR>");
	return(fString);
}

function trans(strContent){
var re;
strContent=DvbbsHtmlAn(strContent);
	
	re=/\[IMG\](.+?)\[\/IMG\]/ig;
	strContent=strContent.replace(re,"<a href=$1 target=_blank><IMG SRC=$1 border=0 alt=按此在新窗口浏览图片 onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\" galleryImg=no></a>");

	re=/\[v\](.*?)\[\/v\]/ig;
	strContent=(hasAudio)?strContent.replace(re,"<div class=\"post-ctrl\"><h5 onclick=\"playInAudio(&#39;$1&#39;,event);\">《$1》点击播放</b></h5></div>"):strContent.replace(re,"<div class=\"post-ctrl\"><h5 onclick=\"iplayer(&#39;$1&#39;,event);\">《$1》点击播放</b></h5></div>");
	
	re=/\[MP3\](.*?)\[\/MP3\]/ig
	//strContent= strContent.replace(re,"<h5 onclick=\"iplayer(&#39;$1&#39;);\"> 点击播放</b></h5><a href=\"$1\">下载这首歌<\/a>")
	strContent= strContent.replace(re,function($1){$1=$1.replace(/(\[mp3\])|(\[\/mp3\])/gi,'');var __;if($1.toLowerCase().indexOf('.mp3')!=-1){__='<div class="post-ctrl">'+((hasAudio)?'<audio onerror="this.style.display=\'none\';" onloadstart="this.nextsibling.style.display=\'none\';" src="'+$1+'" controls="true"></audio>':'<object id="Mp3Player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" style="width: 320px;height:35px;"><param name="quality" value="High" /><param name="bgcolor" value="#ffffff" /><param name="menu" value="false" /><param name="movie" value="../swf/mp3player.swf?soundFile='+$1+'&autostart=yes" /><param name="wmode" value="transparent" /><param name="play" value="false" /><embed quality="High" wmode="transparent" menu="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" style="width: 320px;height:35px;" bgcolor="#ffffff" name="Mp3Player" play="false" src="../swf/mp3player.swf?soundFile='+$1+'&autostart=yes" /></object>')+'<h5 onclick="iplayer(&#39;'+$1+'&#39;);">播放这首歌</h5>';}else{__='<div class="post-ctrl"><h5 onclick="iplayer(&#39;'+$1+'&#39;);"> 点击播放</b></h5>';};__+='<h5 class="download"><a href="'+$1+'">下载这首歌<\/a></h5><\/div>';return __;})

	re=/(\[FLASH\])(.*?)(\[\/FLASH\])/ig
	strContent= strContent.replace(re,"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=$2><PARAM NAME=quality VALUE=high><embed src=$2 quality=high pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=500 height=400>$2</embed></OBJECT>")
	re=/(\[FLASH=*([0-9]*),*([0-9]*)\])(.*?)(\[\/FLASH\])/ig
	strContent= strContent.replace(re,"<a href=$4 TARGET=_blank>[全屏欣赏]</a><br><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$2 height=$3><PARAM NAME=movie VALUE=$4><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=$4 quality=high menu=false pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></OBJECT>")

	re=/(\[SWF\])(.*?)(\[\/SWF\])/ig
	strContent= strContent.replace(re,"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=$2><PARAM NAME=quality VALUE=high><embed src=$2 quality=high pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=500 height=400>$2</embed></OBJECT>")
	re=/(\[SWF=*([0-9]*),*([0-9]*)\])(.*?)(\[\/SWF\])/ig
	strContent= strContent.replace(re,"<a href=$4 TARGET=_blank><IMG SRC=pic/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画!> [全屏欣赏]</a><br><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$2 height=$3><PARAM NAME=movie VALUE=$4><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=$4 quality=high menu=false pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></OBJECT>")

	re=/(\[URL\])(.*?)(\[\/URL\])/ig
	strContent= strContent.replace(re,"<A HREF=$2 TARGET=_blank>$2</A>")
	re=/(\[URL=(.[^\[]*)\])(.*?)(\[\/URL\])/ig
	strContent= strContent.replace(re,"<A HREF=$2 TARGET=_blank>$3</A>")

	re=/(\[i\])(.*?)(\[\/i\])/ig
	strContent=strContent.replace(re,"<i>$2</i>")
	re=/(\[u\])(.*?)(\[\/u\])/ig
	strContent=strContent.replace(re,"<u>$2</u>")
	re=/(\[b\])(.*?)(\[\/b\])/ig
	strContent=strContent.replace(re,"<b>$2</b>")

return(strContent);
}
function iplayer(s,u)
{
	var _e=window.event||u;
	var _eo=_e.srcElement||_e.target;
	if(u==1){g('iLzDtlDiv').className='undis';g('playerDiv').className='cLzCtt';g('iLzMy').className='cLzMn';g('iLzPlay').className='cLzHv';}
	var _s=(arguments.length>1)?'http://nihaoku.cn/mp3/url.php?'+s:s;
	var _t='<object align="middle" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase=" http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" class="OBJECT" width="300"><param name="defaultFrame" value="0" /><param name="autoStart" value="true" /><param name="playCount" value="1"><param name="URL" value="'+_s+'"><embed type="application\/x-mplayer2" src="'+_s+'" autoplay="true" playCount="100" src="'+_s+'" width="300"></embed></object><br/>'+((s.indexOf('http')==-1)?'听不到？点《<a href="#" onclick="play(this);return false;">'+s+'</a>》试听':'')+'<br\/>';
	(_eo.tagName=='H5')?_eo.outerHTML=_t:g('playerDiv').innerHTML=_t;
}
function playInAudio(s,u){
	var _e=window.event||u,_eo=_e.srcElement||_e.target;
	_eo.innerHTML='loading...';
	var id = _eo.parentNode.parentNode.id;
	lr.js('/mp3/audio.php?mp3='+s+'&callback=playAudio&arg='+id,'dt-js-api','');
}
function playAudio(u,id){
	g(id).innerHTML=u;
}
function StopAll(n){}
