function addEvent (o,e,f) {
	if(window.addEventListener){o.addEventListener(e,f,false);}else if(window.attachEvent){r=o.attachEvent('on'+e,f);}
}
function $(s){return document.getElementById(s);}


addEvent(window,'load',function(){

if($('Weather')){
	var o=$('Weather');
	o.innerHTML='数据读取中...';
	AJAX_Send('/Ajax.asp?action=GetWeather',function(){
		var result=eval('('+this.responseText+')');
		var Getinfo="";
		Getinfo+=result.weatherinfo.date_y+" ";//年月日
//		Getinfo+=result.weatherinfo.date+" ";//农历年月日
		Getinfo+=result.weatherinfo.week+" ";//星期几
//		Getinfo+="<br />";//换行
		Getinfo+=result.weatherinfo.city;//获取城市名称
//		http://www.weather.com.cn/m2/i/icon_weather/21x15/d02.gif
		Getinfo+=" <img src=\"http://m.weather.com.cn/img/d"+result.weatherinfo.img1+".gif\"/> "//天气图片1
//		Getinfo+="<img src=\"http://m.weather.com.cn/img/d"+result.weatherinfo.img2+".gif\"/> ";//天气图片2
		Getinfo+=result.weatherinfo.weather1+" ";//天气情况
		Getinfo+=result.weatherinfo.temp1;//温度
		
		o.innerHTML=Getinfo;
	});
}

});


/*XMLHTTP=============================================================================*/
function AJAX_Send(URL,OnFinish)
{
	var request=new HttpRequest();
	request.onfinish=OnFinish;
	request.onerror=function(e){alert(e.message);}
	request.open("get",URL+"&math="+Math.random(),true);
	request.setRequestHeader('Content-Type','text/xml');
	request.setRequestHeader("Charset","utf-8");
	request.send(null);
}


function HttpRequest()
{
	if(this==window)throw new Error(0,"HttpRequest is unable to call as a function.")
	var me=this;
   	var asyncFlag=false;
   	var typeFlag=false;
	var r;
	function onreadystatechange()
	{
		if(me.onreadystatechange)me.onreadystatechange.call(r);
		if(r.readyState==4)
		{
			if(Number(r.status)>=300)
			{
				if(me.onerror)me.onerror.call(r,new Error(0,"Http error:"+r.status+" "+r.statusText));
				if(typeFlag)r.onreadystatechange=Function.prototype;
				else r.onReadyStateChange=Function.prototype;
				r=null;
				return;
			}
			me.status=r.status;
			me.statusText=r.statusText;
			me.responseText=r.responseText;
			me.responseBody=r.responseBody;
			me.responseXML=r.responseXML;
			me.readyState=r.readyState;
			if(typeFlag)r.onreadystatechange=Function.prototype;
			else r.onReadyStateChange=Function.prototype;
			r=null;
			if(me.onfinish)me.onfinish();
		}
	}
	function creatHttpRequest(){
		var e;
		try{
			r=new window.XMLHttpRequest();
			typeFlag=true;
		} catch(e) {			
			var ActiveXName=[
				'MSXML2.XMLHttp.6.0',
				'MSXML2.XMLHttp.3.0',
				'MSXML2.XMLHttp.5.0',
				'MSXML2.XMLHttp.4.0',
				'Msxml2.XMLHTTP',
				'MSXML.XMLHttp',
				'Microsoft.XMLHTTP'
			]
			function XMLHttpActiveX()
			{
				var e;
				for(var i=0;i<ActiveXName.length;i++)
				{
					try{
						var ret=new ActiveXObject(ActiveXName[i]);
						typeFlag=false;
					} catch(e) {
						continue;
					}
					return ret;
				}
				throw {"message":"XMLHttp ActiveX Unsurported."};
			}
			try{
				r=new XMLHttpActiveX();
				typeFlag=false;
			} catch(e) {
				throw new Error(0,"XMLHttpRequest Unsurported.");
			}
		}
	}
	creatHttpRequest();


	this.abort=function(){
		r.abort();
	}
	this.getAllResponseHeaders=function(){
		r.getAllResponseHeaders();
	}
	this.getResponseHeader=function(Header){
		r.getResponseHeader(bstrHeader);
	}
	this.open=function(Method,Url,Async,User,Password){
		asyncFlag=Async;
		try{
			r.open(Method,Url,Async,User,Password);
		} catch(e) {
			if(me.onerror)me.onerror(e);
			else throw e;
		}
	}
	this.send=function(Body){
		try{
			if(typeFlag)r.onreadystatechange=onreadystatechange;
			else r.onReadyStateChange=onreadystatechange;

			r.send(Body);
			//alert("sended");
			if(!asyncFlag){
				this.status=r.status;
				this.statusText=r.statusText;
				this.responseText=r.responseText;
				this.responseBody=r.responseBody;
				this.responseXML=r.responseXML;
				this.readyState=r.readyState;

				if(typeFlag)r.onreadystatechange=Function.prototype;
				else r.onReadyStateChange=Function.prototype;

				r=null;
			}
		} catch(e) {
			if(me.onerror)me.onerror(e);
			else throw e;
		}
		//alert("sended");
	}
	this.setRequestHeader=function(Name,Value){
		r.setRequestHeader(Name,Value);
	}
}
/*XMLHTTP-----------------------------------------------------------------------------*/


/*图片切换=============================================================================*/
/*
n	ID
tag	标题标签[0-否,1-是](提取图片Title中<b></b>部份文字)
Txt	是否显示文字[0-否,1-是]
*/
function TransformView (n,tag,Txt){
	var TV=this,Banner=$(n),T='';
	Banner.innerHTML='<div class="AD_List">'+Banner.innerHTML+'</div>';
	this.index=0;

	this.Step=5;		//滑动变化率
	this.timer=10;		//定时器
	this.Up=true;		//是否向上(否则向左)
	this.Auto=true;		//是否自动转换
	this.Pause=3000;	//停顿时间(Auto为true时有效)
	this.target=0;		//目标参数
	
	this.slider=Banner.getElementsByTagName('UL')[0];
	this.Count=this.slider.getElementsByTagName('LI').length;/*切换数量*/
	this.Width=this.slider.getElementsByTagName('LI')[0].getElementsByTagName('IMG')[0].offsetWidth;
	this.Height=this.slider.getElementsByTagName('LI')[0].getElementsByTagName('IMG')[0].offsetHeight;
	
//	alert(this.slider.getElementsByTagName('LI')[0].innerHTML+'\n\n\n'+Banner.innerHTML);
	//文字描述层
	if(Txt==1){
		//背景层
		var div=document.createElement("div");div.className='AD_Text_BG';Banner.appendChild(div);
		//文字层
		var div=document.createElement("div");div.innerHTML=this.GetTitle(0);div.className='AD_Text';this.AD_Text=Banner.appendChild(div);
	}
	
	//生成Label
	var ul=document.createElement("ul");
	ul.className='ADNum';
	for(var i=1;i<this.Count+1;i++){
		var CL=document.createElement("li");
		T=i;
		//.split('</strong>')[0].substring(8)
		if(tag==1){T='<a>'+this.GetTitle(i-1)+'</a>';}
		CL.innerHTML=T;
		
		CL.onmouseover=(function(i,CL){return function(){CL.className='On';TV.index=i-1;TV.nextAd();}})(i,CL);
		CL.onmouseout=(function(i,CL){return function(){CL.className='';TV.index=i-1;TV.nextAd();}})(i,CL);
		ul.appendChild(CL);
	}
	Banner.appendChild(ul);
	this.AdNum=Banner.getElementsByTagName('UL')[1].getElementsByTagName('LI');
	TV.nextAd();
}


TransformView.prototype={
nextAd : function(){
	if(this.index<0){this.index=this.Count-1;}
	else if(this.index>=this.Count){this.index=0;}

	this.target=-1*(this.Up?this.Height:this.Width)*this.index;
	for(var i=0;i<this.AdNum.length;i++){this.AdNum[i].className='';}
	//切换描述文字
	if(this.AD_Text){this.AD_Text.innerHTML=(this.GetURL(this.index)=='')?this.GetTitle(this.index):'<a href="'+this.GetURL(this.index)+'" target="_blank">'+this.GetTitle(this.index)+'</a>';}
	this.AdNum[this.index].className='On';
	this.Move();
},
//移动
Move: function() {
	clearTimeout(this.timer);
	var oThis=this,style=this.Up?"top":"left",iNow=parseInt(this.slider.style[style])||0,iStep=this.GetStep(this.target,iNow);
	
	if(iStep!=0){
		this.slider.style[style]=(iNow+iStep)+"px";
		this.timer=setTimeout(function(){oThis.Move();},10);
	}else{
		this.slider.style[style]=this.target+"px";
		if(this.Auto){this.timer=setTimeout(function(){oThis.index++;oThis.nextAd();},this.Pause);}
	}
},
//获取步长
GetStep: function(iTarget, iNow) {
	var iStep=(iTarget-iNow)/this.Step;
	if(iStep==0)return 0;
	if(Math.abs(iStep)<1) return (iStep>0?1:-1);
	return iStep;
},
//获取alt[替换文本]
GetTitle: function(n){
	return this.slider.getElementsByTagName('LI')[n].getElementsByTagName('IMG')[0].alt;
},
//获取URL
GetURL: function(n){
	if(this.slider.getElementsByTagName('LI')[n].getElementsByTagName('A')[0])
	{return this.slider.getElementsByTagName('LI')[n].getElementsByTagName('A')[0].href;}
	else{return '';}
}
}
/*图片切换-----------------------------------------------------------------------------*/

