
function __calendar()
{
	
	this.targetStyle	=	'position:absolute;width:168px;border:#000 1px solid;';
	this.path			=	'../Images/Calendar/';
	this.allMonth		=	[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31];
	this.allWeek		=	['日','一','二','三', '四', '五', '六'];
	Loader.setControlName("calendar");
	this.show		=	function(){
		var imgPrev		=	this.path+'cPrev.gif';
		var imgNext		=	this.path+'cNext.gif';
		var liStyle		=	'float:left;list-style-type:none;text-align:center;padding:0px;height:20px;';	
		var dateStyle	=	'width:115px;line-height:23px;color:#fff;font-weight:bold;'+liStyle;
		var titleStyle	=	'style="height:26px;background:url('+this.path+'cTitleBg.gif);"';
		var unionStyle	=	'width:22px;height:20px;border:#fff 1px solid;border-bottom-color:#999;'+
							'border-right-color:#999;line-height:20px;'+liStyle;
		var headerStyle =	unionStyle+'background:url('+this.path+'cHeaderBg.gif);';
		var itemBgStyle	=	unionStyle+'background:url('+this.path+'cItemBg.gif);'
		var itemBtStyle	=	unionStyle+'background:url('+this.path+'cItemBtn.gif);cursor:pointer;';
		var itemOvStyle	=	unionStyle+'background:url('+this.path+'cSelect.gif);color:#fff;cursor:pointer;';
		var selectStyle	=	unionStyle+'background:url('+this.path+'cItemOver.gif);';
		var o			=	this.o	=	arguments[0];
		this.textBox	=	arguments[1];
		var startDay	=	new Date(this.year,this.month,1).getDay();
		this.target		=	document.getElementById('cal_'+this.textBox.id)||
							this.textBox.parentNode.insertBefore(document.createElement("div"),this.textBox);
		this.target.id	=	'cal_'+this.textBox.id;
		this.target.style.cssText=this.targetStyle;
		var width=168-this.textBox.offsetWidth-o.offsetWidth;

		if((this.target.offsetLeft+173)>document.body.clientWidth)
				this.target.style.left=this.target.offsetLeft-width-3+'px';
		this.target.style.top=this.target.offsetTop+this.textBox.offsetHeight+'px';
		var strTitle	=	'<ul '+titleStyle+'><li style="'+liStyle+'cursor:pointer;" onclick="Calendar.update(0)">'+
							'<img src="'+imgPrev+'" align="top"/></li>'+'<li style="'+dateStyle+'">'+this.year+'-'+
							(this.month+1)+'</li><li style="'+liStyle+'cursor:pointer;" onclick="Calendar.update(1)"><img src="'+
							imgNext+'" align="top"/></li></ul>';
		var strHeader='<ul>',strItem='<ul>';
		var monthDay=this.allMonth[this.month]+startDay;
		var count=monthDay%7==0?monthDay:monthDay+7-monthDay%7;
		
		for(var i=0;i<count;i++){
			var strValue='',strAttr='',style=itemBgStyle;
			if(i<7) strHeader+='<li style="'+headerStyle+'">'+this.allWeek[i]+'</li>';
			if(i>=startDay && i<monthDay){
				strValue=i-startDay+1;
				style=strValue==this.today?selectStyle:itemBtStyle;
				strAttr=' onclick="Calendar.setTextBox(this)" onmouseover="this.style.cssText=\''+itemOvStyle+
						'\';" onmouseout="this.style.cssText=\''+style+'\';"';
			}
			strAttr+=' style="'+style+'"';
			strItem+='<li'+strAttr+'>'+strValue+'</li>';
			if(i+1%7==0) strItem+'</ul><ul>';
		}
		
		this.target.innerHTML=strTitle+strHeader+'</ul>'+strItem+'</ul>';
		
		PopMenu.add(o,this.target);
		var objEvt = new Object();
		objEvt.theCalendar=this;
		objEvt.onHide=function(e){
			if(e.target==this.theCalendar.target) this.theCalendar.setDate();
		}
		PopMenu.addEventListener("onHide",objEvt);
	}
	
	this.setTextBox=function(o){
		var month	=	this.month+1<10?'0'+(this.month+1):this.month+1;
		var day		=	o.innerHTML.length<2?'0'+o.innerHTML:o.innerHTML;
		if(this.textBox) this.textBox.value=this.year+'-'+month+'-'+day;
		this.hide();
	}
	
	this.update=function(isAdd){
		isAdd?this.month<11?this.month++:(this.month=0,this.year++):this.month>0?this.month--:(this.month=11,this.year--);	
		this.show(this.o,this.textBox);
	}
	
	this.hide=function(){
		this.setDate();
		PopMenu.setHide(this.target);
	}
	
	this.setDate=function(){
		var date	=	new Date();this.year=date.getFullYear(),this.month=date.getMonth(),this.today=date.getDate();
	}
	this.setDate();
}
var Calendar	=	new __calendar();