var Dvbbs_filterScript = true;
var Dvbbs_charset="UTF-8";
var Dvbbs_bLoad=false
var Dvbbs_bTextMode=3;

//var Dvbbs_bIsIE5=document.all
//if (Dvbbs_bIsIE5)
//{var IframeID=frames["Dvbbs_Composition"];}
//else
//{
//var IframeID=document.getElementById("Dvbbs_Composition").contentWindow;
//}
//Dvbbs_InitDocument('Body','gb2312')

function Dvbbs_InitDocument(hiddenid, charset)
{	
//Dvform
	if (charset!=null){Dvbbs_charset=charset;}
	if (Dvbbs_bIsIE5){
		var Dvbbs_bodyTag="<style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\" title=\"Ctrl+Enter直接提交贴子\" onkeydown=\"ctlent();\">";
	}else
	{
		var Dvbbs_bodyTag="<style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\" >";
	}
	var editor=IframeID
	var h=document.getElementById(hiddenid).value;
	if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){
	editor.document.designMode="On"
	}
	editor.document.open();
	editor.document.write ('<html><head>');
	if (Dvbbs_bIsIE5){
	editor.document.write ('<script language="javascript">');
	editor.document.write ('var ispost=0;');
	editor.document.write ('	function ctlent()');
	editor.document.write ('	{');
	editor.document.write ('		if(event.ctrlKey && window.event.keyCode==13&&ispost==0)');
	editor.document.write ('		{');
	editor.document.write ('			ispost=1;');
	editor.document.write ('			parent.Dvbbs_CopyData("'+hiddenid+'"); ');
	editor.document.write ('			parent.document.Dvform.submit();');
	editor.document.write ('		}');
	editor.document.write ('	}');
	editor.document.write ('<\/script>');
	}
	editor.document.write(Dvbbs_bodyTag);
	if (h!="")
	{
		h=Dvbbs_FilterScript(h);
		editor.document.write(h);
	}
	editor.document.write ("</body>");
	editor.document.write ("</html>");
	editor.document.close();
	editor.document.body.contentEditable = "True";
	editor.document.charset=Dvbbs_charset;
	Dvbbs_bLoad=true;
	Dvbbs_setStyle();
}

function Dvbbs_setStyle()
{
	//var bs = IframeID.document.body.runtimeStyle;
	var bs = IframeID.document.body.style;
	//根据mode设置iframe样式表	
	if (Dvbbs_bTextMode==2) {
		bs.fontFamily="Arial";
		bs.fontSize="10pt";
	}else{
		bs.fontFamily="Arial";
		bs.fontSize="10.5pt";
	}
	bs.scrollbar3dLightColor= '#D4D0C8';
	bs.scrollbarArrowColor= '#000000';
	bs.scrollbarBaseColor= '#D4D0C8';
	bs.scrollbarDarkShadowColor= '#D4D0C8';
	bs.scrollbarFaceColor= '#D4D0C8';
	bs.scrollbarHighlightColor= '#808080';
	bs.scrollbarShadowColor= '#808080';
	bs.scrollbarTrackColor= '#D4D0C8';
	bs.border='1';
}

function Dvbbs_CopyData(hiddenid)
{
	if (Dvbbs_bTextMode==2)
	{
	cont=IframeID.document.body.innerText;
	}else{
	cont=IframeID.document.body.innerHTML;  
	}
	var ChekEmptyCode=Dvbbs_ChekEmptyCode(cont);
	if (ChekEmptyCode=='' || ChekEmptyCode==null)
	{
		cont='';
	}
	else{
		cont=Dvbbs_correctUrl(cont);
		if (Dvbbs_filterScript)
		cont=Dvbbs_FilterScript(cont);
	}
	document.getElementById(hiddenid).value = cont;
}
//格式化链接
function Dvbbs_correctUrl(cont)
{
	var url=location.href.substring(0,location.href.lastIndexOf("/")+1);
	cont=Dvbbs_rCode(cont,location.href+"#","#");
	//cont=Dvbbs_rCode(cont,url,"");
	var	regExp = /<(a[^>]*) href=([^ |>]*)([^>]*)/gi
	cont = cont.replace(regExp, "<$1 href=$2 target=\"_blank\" ") ;
	return cont;
}

function Dvbbs_FilterScript(content)
{
	content = Dvbbs_rCode(content, 'javascript:', '<b>javascript</b> :');
	var RegExp = /<script[^>]*>(.*)<\/script>/ig;
	content = content.replace(RegExp, "<div class=HtmlCode>&lt;!-- Script 代码开始 --&gt;<br>$1<br>&lt;!-- Script 代码结束 --&gt;</div>");
	return content;
}

function Dvbbs_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 Dvbbs_ChekEmptyCode(html) {
	//html = html.replace(/&nbsp;|&lt;|&gt;/gi, "");
	html = html.replace(/\<[^>]*>/g,"");        ///过滤其它所有"<...>"标签
	html = html.replace(/&nbsp;/gi, "");
	html = html.replace(/o:/gi, "");
	html = html.replace(/\s/gi, "");
	return html;
}
