
function calendar(objName,name,date,width,height){
	this.objName=objName;

	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 cellspacing="0" cellpadding="1" width="248"><tr><td bgColor="#7e8173" align="center" height="25" class="batitle_01 z12">'+this.dayName.join('</td><td bgColor=#7e8173 align="center" class="batitle_01 z12">')+'</td></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 colspan="7" id="'+this.calendarName+'Td" style="filter:blendtrans(duration=0.1)">';
		this.getTable();
		this.str+=this.dateTable+'</td></tr></table>';
		this.generated=true;
		return this.str;
	}

	function getTable(){
		this.dateTable='<table width="100%" height="150" cellspacing="2" cellpadding="1" class="caltb"><tr>'
			+new Array(this.pastDays+1).join('<td  class="datek z12"></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 id="'+this.calendarName+i+'" class="datek" align="center">'+'<a href="http://www.cpd.com.cn/'+this.channel+'/'+this.dateTime.getFullYear()+'-'+monthValue+'/'+dayValue+'/node_14.htm" target="_blank" class="hetitle_01 z12">'+dayValue+'</a></td>';
		var ropenurl = '<td id="'+this.calendarName+i+'"  class="datek" align="center">'+'<a href="http://www.cpd.com.cn/'+this.channel+'/'+this.dateTime.getFullYear()+'-'+monthValue+'/'+dayValue+'/node_14.htm" target="_blank" class="hotitle_01 z12">'+dayValue+'</a></td>';
		var closeurl = '<td id="'+this.calendarName+i+'"  class="datek hutitle_01 z12" align="center">'+dayValue+'</td>';

		if(this.dateTime.getFullYear() > this.nowDate.getFullYear())
		{
			this.dateTable+=closeurl;
		}
		else
		if(this.dateTime.getFullYear()== this.nowDate.getFullYear())

		{
			if((i+this.pastDays-1)%7==7)
		{
		this.dateTable+=closeurl;

		}
		else
			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<=42-this.days-this.pastDays;i++){
			this.dateTable+='<td  class="datek"></td>';
			if((i+this.pastDays+this.days)%7==0)this.dateTable+='</tr></table>';
		}
		if((this.dateTime.getFullYear()<=2007) && (this.dateTime.getMonth()<12))
		{
					this.dateTable+='<table width="100%" height="25" cellspacing="2" cellpadding="1" class="caltb" background="images/044.jpg"  align="center"><tr><td><img src="../../../../img/d1.gif" /></td>'
			+'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
			+'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
			+'<td><span onmouseup="void('+this.objName+'.nextMonth())"><img src="../../../../img/d.gif" /></span></td>'
			+'</tr></table>';
		}
		else
		{
		this.dateTable+='<table width="100%" height="25" cellspacing="2" cellpadding="1" class="caltb" background="images/044.jpg" align="center"><tr><td><span onmouseup="void('+this.objName+'.previewMonth())"><img src="../../../../img/d1.gif" /></span></td>'
			+'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
			+'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
			+'<td><span onmouseup="void('+this.objName+'.nextMonth())"><img src="../../../../img/d.gif" /></span></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); }
	}
}