/*
插件名称：论坛公告调用垂直滚动更新版(V2.0) For Dvbbs7.x
更新日期：2005-05-14
插件作者：stardy(斯大里) http://www.stardy.com
调用方法：<Script Language=Javascript Src="Std_News.Js"></Script>
*/
function news_create()
{
	//参数设置
	this.speed = 15								//滚动快慢(越小滚动越快)
	this.stayTime = 2							//停留时间(秒，可写小数)
	this.record = 5									//滚动数目，填0不限制
	this.num = 1 							//可见行数，填数字
	this.height = 19							//每行高度(px)
	//未载入公告时显示的欢迎语支持HTML
	this.welcome = '欢迎您！这里是『'+document.title+'』正在载入公告，请稍候...'
	this.delaytime = 1							//欢迎语显示时间
	this.newscolor = ["",""]						//链接字体颜色(首页颜色和非首页颜色)
	this.strong = "1" 							//是否默认为粗体(1=粗体,0-细体,空值-自适应)
	this.maxlen=0								//公告标题显示的最长长度（一个汉字长度是2）填0不限制
	this.id = "ScrollnewsTable"			//滚动对象唯一标识
	//参数设置End
	this.startTop = 0
	this.objectTop = this.num*this.height
	this.stopTime = 0
	this.stopScroll = false
	this.objectHeight = this.num*this.height
	this.url = self.location.search.toLowerCase()
	var re = /(.*)[\?|\&]boardid\=(\d)/i
	if(re.test(this.url))this.boardid = this.url.replace(re,"$2")
	else this.boardid = 0
	this.color = this.newscolor[this.boardid?1:0]
	if(this.color!="")this.color="color:"+this.color+";"
	if(this.strong!="")this.strong="font-weight:"+(this.strong==1?"800":"100")+";"
	this.styles=' style="'+this.color+this.strong+'height:'+this.height+'px;overflow:hidden;" '
	this.text = new Array()
	this.text[0]=this.welcome
	for(var i=1;i<=this.record;i++)
		this.text[i]="&nbsp;"
	this.start = news_init
	this.process = news_makeTable
	this.loadnews = news_load
	this.getReady = news_getReady
	this.srcollit = news_Scroll
}
function news_init()
{
	var s='<div onmouseover="bbsnews.stopScroll=true" onmouseout="bbsnews.stopScroll=false"'
	s+='oncontextmenu=return(false) id="'+this.id+'" style="overflow-y:hidden;width:100%;'
	s+='height:'+(this.height*this.num)+'px;font-weight:100" align=center>'
	//s+='<marquee onmouseover=this.stop() onmouseout=this.start() direction="right" behavior="alternate">'
	s+=this.text[0]
	//s+='</marquee>'
	s+='</div>'
	document.write(s)
	this.object=document.getElementById(this.id)
	if(this.object)setTimeout("bbsnews.loadnews()",this.delaytime*1000)
}
function news_makeTable()
{
	s=""
	for(var i=0;i<=this.record;i++)
		s+='<table cellpadding=0 width="100%" cellspacing=0 border=0><tr><td'+this.styles+'align="center" nowrap valign="center">'+this.text[i]+'</td></tr></table>'
	return s
}
function news_load()
{
	this.xml_news = new ActiveXObject("Microsoft.XMLDOM")
	this.xml_news.async = true
	this.xml_news.onreadystatechange = this.getReady
	this.xml_news.load("Std_News.asp?num="+this.record+"&boardid="+this.boardid)
}
function news_getReady()
{
	if(bbsnews.xml_news.readyState!=4)return
	if(bbsnews.xml_news.parseError.errorCode!=0)
	{
		delete(bbsnews.xml_news)
		bbsnews.object.innerHTML="对不起，xml公告加载出错！"
		return
	}
	bbsnews.text = new Array()
	bbsnews.record = bbsnews.xml_news.getElementsByTagName("news").length  //检索的记录数
	for (var i=0;i<bbsnews.record;i++){
		var title2 = bbsnews.xml_news.getElementsByTagName("newstitle").item(i).text
		var url = bbsnews.xml_news.getElementsByTagName("url").item(i).text
		var admin = bbsnews.xml_news.getElementsByTagName("writter").item(i).text
		var posttime = bbsnews.xml_news.getElementsByTagName("time").item(i).text
		var title=title2.strleft(bbsnews.maxlen)
		if(admin!="")admin="发布人："+admin
		if(title2!=title)admin="标　题："+title2.replace(/\.|\d/g,"")+(admin!=""?"&#13;"+admin:"")
		if(admin!="")admin=' title="'+admin+' '+posttime+'"'
		if(posttime=="")title+="(单击查看说明)"
		else posttime=" ("+posttime+")"
		bbsnews.text[i] ='<span style="font-family:Webdings;font-size:15px">X</span> '
		bbsnews.text[i] +='<a '+bbsnews.color+admin+' href=javascript:openScript("'+url+'",500,400)>'+title+'</a>'
		if(bbsnews.record>bbsnews.num&&i==bbsnews.record-1)bbsnews.text[bbsnews.record]=bbsnews.text[0]
	}
	delete(bbsnews.xml_news)
	bbsnews.record = bbsnews.text.length-1
	bbsnews.object.innerHTML = bbsnews.process()
	if(bbsnews.record<=bbsnews.num)return;
	bbsnews.object.scrollTop = 0
	bbsnews.ievent=window.setInterval("bbsnews.srcollit()",bbsnews.speed)
}
function news_Scroll(){
	if(this.stopScroll==true){this.stopTime=0;return;}
	this.objectTop++
	if(this.objectTop>this.objectHeight)
	{
		if(this.stopTime*this.speed>this.stayTime*1000){this.objectTop=0 ;	this.stopTime=0}
		else this.stopTime++
		} 
	else 
	{
		this.startTop = this.object.scrollTop
		this.object.scrollTop ++
		if(this.startTop==this.object.scrollTop)this.object.scrollTop= 1
 	}
}
String.prototype.strlen=function(){
	return this.replace(/[^\x00-\xff]/g,"12").length;
}
String.prototype.strleft=function(l){
	if(l==0)return this;
	var s="",j=0,sl=Math.min(l,this.strlen())-1;
	for(var xi=0;xi<this.length;xi++)
	{
		s += this.substr(xi,1)
		j += this.substr(xi,1).strlen()
		if(j>sl)break;
	}
	return s+(this.strlen()>l?"...":"");
}
var bbsnews = new news_create()
bbsnews.start()