
function calendar(objName,name,date,width,height){
	this.objName=objName;
	this.calendarName=name!=null?name.toString():'calendar';
	this.width=width!=null?width:'100%';
	this.height=height!=null?height:'100%';
	this.dayName=['日','一','二','三','四','五','六'];
	this.nowDate=new Date();
	this.dateTime=date!=null?date:new Date();
	this.str='';
	this.dateTable='';
	this.days=31;
	this.pastDays=0;
	this.generated=false;
	
	this.channel='news';

	this.generate=generate;
	this.getTable=getTable;
	this.focusDate=focusDate;
	this.attachLink=attachLink;
	this.refresh=refresh;
	this.previewMonth=previewMonth;
	this.nextMonth=nextMonth;
	this.setDate=setDate;
	this.afterRefresh=function(){};

	function generate(date){
		//蓝色边框
		this.str='<table border=0 bgcolor="#CCCCCC" cellspacing=2 cellpadding=0><tr><td bgcolor="#ffffff" width="150"><table id="'+this.calendarName+'" class="cal" cellspacing="1" cellpadding="2" border="0" width="'
			+this.width+'" height="'
			+this.width+'"><tr  bgcolor="#CCCCCC"><th onselectstart="return(false)"><font style="font-size:9pt ; color:#ffffff" >'
			+this.dayName.join('</th><th onselectstart="return(false)"><font style="font-size:9pt;color:#ffffff">')+'</font></th></tr>';
		this.dateTime=date!=null?new Date(date):this.dateTime;
		this.days=new Date(this.dateTime.getYear(),this.dateTime.getMonth()+1,0).getDate();
		this.pastDays=new Date(this.dateTime.getFullYear()+'/'+(this.dateTime.getMonth()+1)+'/1').getDay();
		this.str+='<tr><td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;" colspan="7" id="'+this.calendarName+'Td" style="filter:blendtrans(duration=0.1)">';
		//区取中间的table
		this.getTable();
		this.str+=this.dateTable+'</td></tr></table></td></tr></table><br>';
		this.generated=true;
		return this.str;
	}
	
	
	function getTable(){
		//
		this.dateTable='<table border="1" bordercolor="#f0f0f0" width="100%" height="100%" cellspacing="1" cellpadding="1" class="caltb"><tr>'
			+new Array(this.pastDays+1).join('<td style="line-height:16px;font-family: Arial, Helvetica, sans-serif;"></td>');
		for(var i=1;i<=this.days;i++){
		var monthValue = (this.dateTime.getMonth()+1);
		if(monthValue <10) monthValue="0"+monthValue;
		var dayValue = i;
		if(i<10) dayValue ="0"+dayValue;
		
		var openurl = '<td bgcolor="#F8F7E8" style="line-height:20px;font-family: Arial, Helvetica, sans-serif;" id="'+this.calendarName+i+'">'+'<a style="font-weight:bold; color:#000000" href="daynews.jsp'+'?NewsDate='+this.dateTime.getFullYear()+'-'+monthValue+'-'+dayValue+'" target="_self">'+i+'</a></td>';
		var ropenurl = '<td bgcolor="#FF9933" style="line-height:20px;font-family: Arial, Helvetica, sans-serif;" id="'+this.calendarName+i+'">'+'<a style="line-height:20px;" style="font-weight:bold" href="daynews.jsp'+'?NewsDate='+this.dateTime.getFullYear()+'-'+monthValue+'-'+dayValue+'" target="_self"><font color="ffffff">'+i+'</font></a></td>';
		var closeurl='<td style="line-height:20px;font-family: Arial, Helvetica, sans-serif;" id="'+this.calendarName+i+'">'+i+'</td>';
		
		if(this.dateTime.getFullYear() > this.nowDate.getFullYear())
		{
			this.dateTable+=closeurl;
		}
		else
		if(this.dateTime.getFullYear()== this.nowDate.getFullYear())
		{
			if(this.dateTime.getMonth() > this.nowDate.getMonth())
			{
				this.dateTable+=closeurl;
			}
			else
			if(this.dateTime.getMonth() == this.nowDate.getMonth())
			{
				if(i<=this.nowDate.getDate())
				{
					if(i == this.nowDate.getDate())
					{
						this.dateTable+=ropenurl;
					}
					else
					this.dateTable+=openurl;
				}
				else
				{
					this.dateTable+=closeurl;
				}
			}
			else
			{
				this.dateTable+=openurl;
			}
		}
		else
			this.dateTable+=openurl;
				if((i+this.pastDays)%7==0)this.dateTable+='</tr><tr>';
		}
		for(var i=1;i<=37-this.days-this.pastDays;i++){
			this.dateTable+='<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;"></td>';
			if((i+this.pastDays+this.days)%7==0)this.dateTable+='</tr><tr>';
		}
		if((this.dateTime.getFullYear()<=2004) && (this.dateTime.getMonth()<9))
		{
					this.dateTable+='<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;"><button style="border:0px solid #ffffff;background-color:#CCCCCC; color:#ffffff; font-weight:bold; width:15px;height:18px; cursor:hand;" hidefocus="true"><span><</span></button></td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;" colspan="2">'+this.dateTime.getFullYear().toString()+'</td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;">'+(this.dateTime.getMonth()+1).toString()+'</td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;"><button style="border:0px solid #ffffff;background-color:#CCCCCC; color:#ffffff; font-weight:bold; width:15px;height:18px; cursor:hand;" onmouseup="void('+this.objName+'.nextMonth())" hidefocus="true"><span>></span></button></td>'
			+'</tr></table>';
		}
		else
		{
		this.dateTable+='<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;"><button style="border:0px solid #ffffff;background-color:#CCCCCC; color:#ffffff; font-weight:bold; width:15px;height:18px; cursor:hand;" onmouseup="void('+this.objName+'.previewMonth())" hidefocus="true"><span><</span></button></td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;" colspan="2">'+this.dateTime.getFullYear().toString()+'</td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;">'+(this.dateTime.getMonth()+1).toString()+'</td>'
			+'<td style="line-height:18px;font-family: Arial, Helvetica, sans-serif;"><button onmouseup="void('+this.objName+'.nextMonth())" hidefocus="true" style="border:0px solid #ffffff;background-color:#CCCCCC; color:#ffffff; font-weight:bold; width:15px;height:18px; cursor:hand;"><span>></span></button></td>'
			+'</tr></table>';
		}
		return this.dateTable;
	}
	function focusDate(date){
		try{
			eval(this.calendarName+(date!=null?date|0:new Date().getDate())+'.className="focus"');
			return(true);
		} catch(e) { return(false); }
	}
	function attachLink(date,link,target,title){
		try{
			eval(this.calendarName+(date!=null?date|0:new Date().getDate())
				+'.innerHTML="<a href=\\"'+link+'\\"'
				+' target=\\"'+(target!=null?target:'_self')+'\\"'
				+' title=\\"'+(title!=null?title:'')+'\\">'+date.toString()+'</a>"');
			return(true);
		} catch(e) { alert(e.message);return(false); }
	}
	function refresh(){
		try{
			eval(this.calendarName+'Td.filters[0].apply()');
			eval(this.calendarName+'Td.innerHTML=\''+this.getTable()+'\'');
			eval(this.calendarName+'Td.filters[0].play()');
			this.afterRefresh();
			return(true);
		} catch(e) { return(false); }
	}
	function previewMonth(){
		try{
			this.dateTime.setMonth(this.dateTime.getMonth()-1)
			this.generate();
			this.refresh();
			return(true);
		} catch(e) { return(false); }
	}
	function nextMonth(){
		try{
			this.dateTime.setMonth(this.dateTime.getMonth()+1)
			this.generate();
			this.refresh();
			return(true);
		} catch(e) { return(false); }
	}
	function setDate(dateStr){
		try{
			this.dateTime=new Date(dateStr);
			return(true);
		} catch(e) { return(false); }
	}
}