var hst_filterScript = true;
var hst_charset="gb2312";
var hst_bLoad=false
var hst_bTextMode=1;
var hst_Mode=1;
var hst_bIsIE5=document.all;
var hst_Mode = 3;
if (hst_bIsIE5){
}
else{
	var hst_bIsNC=true;
}
function hst_InitDocument(hiddenid, charset)
{
	if (charset!=null){hst_charset=charset;}
	var hst_bodyTag="<style type=\"text/css\" 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直接提交贴子\" >";
	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 ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	editor.document.write ('<html><head>');
	if (hst_bIsIE5){
	editor.document.write ('<script language="javascript" type="text/javascript">');
	editor.document.write ('function imgresize(o){');
	editor.document.write ('if(o.width > 500 ){');
	editor.document.write ('	o.style.width=\'500px\';');
	editor.document.write ('}');
	editor.document.write ('if(o.height > 800){');
	editor.document.write ('	o.style.height=\'800px\';');
	editor.document.write ('}');
	editor.document.write ('}');
	editor.document.write ('<\/script>');
	}
	editor.document.write(hst_bodyTag);
	if (h!="")
	{
		editor.document.write(unescape(h));
	}
	editor.document.write ("</body>");
	editor.document.write ("</html>");
	editor.document.close();
	editor.document.body.contentEditable = "True";
	editor.document.charset=hst_charset;
	hst_bLoad=true;
	hst_setStyle();
	editor.document.onkeyup = function() { editor_event(hiddenid); };
}

function editor_event(objname){
	var ispost=0;
	copy_preview();
	 var editEvent = IframeID ? IframeID.event : event;
	 if (editEvent && editEvent.keyCode) {
		if(((editEvent.ctrlKey && editEvent.keyCode == 13) || (editEvent.altKey && editEvent.keyCode == 83)) && ispost==0){
			hst_CopyData(objname);
			document.Dvform.submit();
		}
	 }
}


function hst_setStyle()
{
	if (hst_Mode==2)
	{
		hst_bTextMode=3;
	}
	var bs = IframeID.document.body.style;
	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 hst_CopyData(hiddenid)
{
	var con=OSWEBXHTML.GetXHTML(IframeID.document.body);
	document.getElementById(hiddenid).value = con.replace(/·/gi,".");
}
//格式化链接
function hst_correctUrl(cont)
{
	var regExp;
	regExp = /<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi
	cont = cont.replace(regExp, "<a href=$2 target=\"_blank\" ");
	regExp = /<a([^>]*)><\/a>/gi
	cont = cont.replace(regExp, "");
	return cont;
}

//----------------
function hst_formatimg()
{
		if (hst_bIsIE5){
			var tmp=IframeID.document.body.all.tags("IMG");
		}else{
			var tmp=IframeID.document.getElementsByTagName("IMG");
		}
		for(var i=0;i<tmp.length;i++){
			var tempstr='';
			if(tmp[i].align!=''){tempstr="align="+tmp[i].align;}
			if(tmp[i].border!=''){tempstr=tempstr+"border="+tmp[i].border;}
			tmp[i].outerHTML="<IMG src=\""+tmp[i].src+"\""+tempstr+">"
		}
}
//清理多余HTML代码
function hst_cleanHtml(content)
{
	if(hst_bTextMode!=1){
		content = content.replace(/<img([^>]*) (src\s*=\s*([^\s|>])*)([^>]*)>/gi,"<img $2>");
	}
	content = content.replace(/<p>&nbsp;<\/p>/gi,"")
	content = content.replace(/<p><\/p>/gi,"<p>")
	content = content.replace(/<div><\/\1>/gi,"")
	content = content.replace(/(\r\n){10,}/gi,"$1")
	content = content.replace(/(<br>\s*){10,}/gi,"<br>")
	content = content.replace(/(<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>)/gi, "");
	content = content.replace(/<\\?\?xml[^>]*>/gi, "") ;
	content = content.replace(/&nbsp;/gi, " ");
return content;
}

//代码过滤及JS提取
function hst_FilterScript(content)
{
	content = content.replace(/<(\w[^div|>]*) class\s*=\s*([^>|\s]*)([^>]*)/gi,"<$1$3") ;
	content = content.replace(/<(\w[^font|>]*) style\s*=\s*([^>|\s]*)([^>]*)/gi,"<$1$3") ;
	content = content.replace(/<(\w[^>]*) lang\s*=\s*([^>|\s]*)([^>]*)/gi,"<$1$3") ;
	var RegExp = /<(script[^>]*)>((.|\n)*)<\/script>/gi;
	content = content.replace(RegExp, "[code]&lt;$1&gt;<br>$2<br>&lt;\/script&gt;[\/code]");
	RegExp = /<(\w[^>|\s]*)([^>]*)(on(finish|mouse|Exit|error|click|key|load|change|focus|blur))(.[^>]*)/gi;
	content = content.replace(RegExp, "<$1")
	RegExp = /<(\w[^>|\s]*)([^>]*)(&#|window\.|javascript:|js:|about:|file:|Document\.|vbs:|cookie| name| id)(.[^>]*)/gi;
	content = content.replace(RegExp, "<$1")
	return content;
}

function hst_CleanCode(){
	var editor=IframeID;
	editor.focus();
	checkword=1;
	editor.document.body.innerHTML= OSWEBXHTML.GetXHTML(editor.document.body);
	checkword=0;

}

var colour
function FormatText(command, option)
{
var codewrite
if(hst_bTextMode==3&&command!="RemoveFormat"){
		switch (command)
		{
			case 'fontsize':
				hst_ubb("size",option);
				break;
			case 'fontname':
				hst_ubb("face",option);
				break;
			case 'bold':
				hst_ubb("B");
				break;
			case 'italic':
				hst_ubb("I");
				break;
			case 'underline':
				hst_ubb("U");
				break;
		}
	return
}

if (hst_bIsIE5){
		if (option=="removeFormat"){
		command=option;
		option=null;}
	  	IframeID.document.execCommand(command, false, option);
		hst_pureText = false;
		IframeID.focus();
		
}else{
		if ((command == 'forecolor') || (command == 'backcolor')) {
			parent.command = command;
			buttonElement = document.getElementById(command);
			IframeID.focus();
			document.getElementById("colourPalette").style.left = getOffsetLeft(buttonElement) + "px";
			document.getElementById("colourPalette").style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
		
			if (document.getElementById("colourPalette").style.visibility=="hidden")
				{document.getElementById("colourPalette").style.visibility="visible";
			}else {
				document.getElementById("colourPalette").style.visibility="hidden";
			}
			var sel = IframeID.document.selection; 
			if (sel != null) {
				colour = sel.createRange();
			}
		}
		else{
	  	IframeID.document.execCommand(command, false, option);
		hst_pureText = false;
		IframeID.focus();
		}
	}
}

function setColor(color)
{
	IframeID.document.execCommand(parent.command, false, color);
	IframeID.focus();
	document.getElementById("colourPalette").style.visibility="hidden";
}

function hst_doSelectClick(str, el)
{
	var Index = el.selectedIndex;
	if (Index != 0){
		el.selectedIndex = 0;
		FormatText(str,el.options[Index].value);
	}
}
function hst_validateMode()
{
	if (hst_bTextMode!=2) return true;
	alert("请取消“查看HTML源代码”选项再使用系统编辑功能或者提交!");
	IframeID.focus();
	return false;
}
function hst_foreColor()
{
	if (!hst_validateMode()) return;
	if (hst_bIsIE5){
		var arr = showModalDialog("images/post/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
		if (arr != null){
			if(hst_bTextMode==3){
				hst_ubb("color",arr);
			}else{
				FormatText('forecolor', arr);
			}
		}
		else{ IframeID.focus();}
	}else
		{
		FormatText('forecolor', '');
	}
}


function hst_backColor()
{
	if (!hst_validateMode()) return;
	if(hst_bTextMode==3){
		alert('当前编辑器不支持该UBB标记。');
		return ;
	}
	if (hst_bIsIE5)
	{
		var arr = showModalDialog("images/post/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0; help:0");
		if (arr != null) 
		{
			if(hst_bTextMode!=3){
			FormatText('backcolor', arr);
			}
		}
		else 
		{IframeID.focus();}
	}else
		{
		FormatText('backcolor', '');
		}
}
function hst_UserDialog(what)
{
	if (!hst_validateMode()) return;
	IframeID.focus();
	if(what == "InsertAlipay"){
		if (hst_bIsNC)
		{
		imagePath = prompt('请填写图片链接地址信息：', 'http://');			
		if ((imagePath != null) && (imagePath != "")) {
			IframeID.document.execCommand('InsertImage', false, imagePath);
		}
		IframeID.document.body.innerHTML = (IframeID.document.body.innerHTML).replace("src=\"file://","src=\"");
		}else{
		hst_foralipay();
		}
	}
	hst_pureText = false;
	IframeID.focus();
}
function hst_foralipay()
{
	var arr = showModalDialog("images/post/alipay.htm", window, "dialogWidth:20em; dialogHeight:34em; status:0; help:0");
	if (arr)
	{
		IframeID.document.body.innerHTML+=arr;
	}
	IframeID.focus();
}
function ShowForum_Emot(thepage)
{
	var Emot_PageCount;
	var Emot_Count=Forum_Emot.length-2;
	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=Forum_Emot[0];
	if (thepage!=1 && Emot_PageCount>1)
	{EmotStr+='<img style="cursor: pointer;" onClick="ShowForum_Emot('+(thepage-1)+');" src="Images/post/Previous.gif" width="14" height="14" title="上一页">&nbsp;';}
	for(i=(thepage-1)*Emot_PageSize;i<(thepage-1)*Emot_PageSize+Emot_PageSize;i++)
	{
		if (i==Emot_Count){break}
		if (i<9)
			{istr='em0'+(i+1)}
			else
			{istr='em'+(i+1)}
		EmotStr+='<img title="'+istr+'" style="cursor: pointer;padding:1px;" onload="if(this.width>30){this.width=30;Emot_PageSize=12;}" onClick=putEmot("'+istr+'"); src="'+EmotPath+Forum_Emot[i+1]+'">&nbsp;';
	}
	if (thepage!=Emot_PageCount)
	{EmotStr+='<img style="cursor: pointer;" onClick="Emot_PageSize=12;ShowForum_Emot('+(thepage+1)+');" src="Images/post/Next.gif" width="14" height="14" title="下一页">&nbsp;';}
	if (thepage<5 && Emot_PageCount>4)
	{EmotStr+='&nbsp;<img title="插入表情窗口" style="cursor: pointer;" onclick="ShadeDiv.ShowFrame(\'dispEmot.asp?action=disp&amp;&amp;sw=510&amp;sh=auto\');" src="'+EmotPath+Forum_Emot[50]+'" width="30" height="30" title="新表情 悠嘻猴">';}
	//EmotStr+='分页：<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>";
	var Forum_EmotObj=document.getElementById("emot")
	Forum_EmotObj.innerHTML=EmotStr;
	//document.getElementById('emotpage').options[thepage-1].selected=true;
	}
}

function putEmot(thenNo)
{
	var ToAdd = '['+thenNo+']';
	IframeID.document.body.innerHTML+=ToAdd;
}
function copy_preview(){
	var hst_preview=document.getElementById("hst_preview");
	if (hst_preview && readCookie("preview")==1) {
		var html=OSWEBXHTML.GetXHTML(IframeID.document.body);
		hst_preview.innerHTML=html;
		if (html==''|| html=='<p>&nbsp;</p>' || html=='<p></p>') hst_preview.innerHTML='<font color="#cccccc">回复效果预览</font> ';
		if (hst_preview.offsetHeight>200){
		hst_preview.style.overflow='auto';
		hst_preview.style.height='200px';
		}
}
}
function CheckCount(message,total)
{
hst_CopyData(message);
copy_preview();
var Getmessage=document.getElementById(message);
var Gettotal=document.getElementById(total);
	var max;
	max = Gettotal.value;
	if (Getmessage.value.length > max) {
	Getmessage.value = Getmessage.value.substring(0,max);
	alert("内容不能超过 " + max + " 个字!");
	document.Dvform.Submit.disabled=true;
	}
	else {
	document.Dvform.Submit.disabled=false;
	}
	
}

var ispost=0;
function ctlent(){
	if (event){
	if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83))
		{
		ispost=1;
		hst_CopyData('Body');
		document.Dvform.submit();
	}
	}
}
function Gopreview(){
document.preview.theBody.value=IframeID.document.body.innerHTML; 
var popupWin = window.open('', 'preview_page', 'scrollbars=yes,width=750,height=450');
document.preview.submit()
}
function Gopreview1(){
if (document.getElementById("hst_checkb1").checked){
		var hst_preview=document.getElementById("hst_preview");
		if(hst_preview){
		hst_preview.style.display='';
		createCookie("preview","1",365);
		}
	}else{
		var hst_preview=document.getElementById("hst_preview");
		if(hst_preview){
		hst_preview.style.display='none';
		createCookie("preview","",365);
		copy_preview();
		}
	}
}
function showtopic(){
	if (document.getElementById("hst_checkb2").checked){
		var hst_topic=document.getElementById("hst_topic");
		if(hst_topic){
		hst_topic.style.display='';
		createCookie("topic","1",365);
		}
	}else{
		var hst_topic=document.getElementById("hst_topic");
		if(hst_topic){
		hst_topic.style.display='none';
		createCookie("topic","",365);
		}
}
}
function showupload(){
	if (document.getElementById("hst_checkb3").checked){
		var hst_upload=document.getElementById("hst_upload");
		if(hst_upload){
		hst_upload.style.display='';
		createCookie("upload","1",365);
		}
	}else{
		var hst_upload=document.getElementById("hst_upload");
		if(hst_upload){
		hst_upload.style.display='none';
		createCookie("upload","",365);
		}
	}
}

function buildTemp(){
	if (readCookie("upload")=='1'){
			document.getElementById("hst_checkb3").checked = true;
			var hst_upload = document.getElementById("hst_upload");
			if(hst_upload){
			hst_upload.style.display='';
			}
		}else{
			document.getElementById("hst_checkb3").checked=false;
			var hst_upload=document.getElementById("hst_upload");
			if(hst_upload){
			hst_upload.style.display='none';
			}
	}
	if (readCookie("topic")=='1'){
			document.getElementById("hst_checkb2").checked=true;
			var hst_topic=document.getElementById("hst_topic");
			if(hst_topic){
			hst_topic.style.display='';
			}
		}else{
			document.getElementById("hst_checkb2").checked=false;
			var hst_topic=document.getElementById("hst_topic");
			if(hst_topic){
			hst_topic.style.display='none';
			}
		}
	if (readCookie("preview")=='1'){
			document.getElementById("hst_checkb1").checked=true;
			var hst_preview=document.getElementById("hst_preview");
			if(hst_preview){
			hst_preview.style.display='';
			}
		}else{
			document.getElementById("hst_checkb1").checked=false;
			var hst_preview=document.getElementById("hst_preview");
			if(hst_preview){
			hst_preview.style.display='none';
			}
		}

}