function objectCreateCalendar(contain, width, height)
{
	//动态创建table
	this.table = document.createElement("table");
	this.table.cellPadding = "0";
	this.table.cellSpacing = "0";
	this.tbody = document.createElement("tbody");
	this.table.appendChild(this.tbody);
	contain.appendChild(this.table);
	for (var i=0; i<6;i++){
		var row = document.createElement("tr");
		for (var j=0; j<7;j++){
			var cell = document.createElement("td");
			cell.style.width = width + "px";
			cell.style.height = height + "px";
			cell.style.textAlign = "center";
			row.appendChild(cell);  //在每行里追加列;
		}
		this.tbody.appendChild(row);  //追加一行;
	}
	var data =  new Date();  //获取当前日期
	this.year = Number(data.getFullYear());  //当前的年份;
	this.month = Number(data.getMonth()) + 1; //当前的月份，默认月份从0算起;
	this.createDateIn(this.year, this.month);
	//this.nowDate();
	var month;
	if(this.month<=9)
	{
		 month = "0" + this.month;
	}
	document.getElementById("div_yd").innerHTML =  this.year + '.' + month;
}
objectCreateCalendar.prototype.createDateIn = function(year, month)
{
	this.clearTD(); //清空table的原始内容;
	if (!year){
		year = this.year;
	}
	if (!month){
		month = this.month;
	}
	
	this.data = new Date(year, month - 1, 1);
	var d = new Date(year, month, 0); 
	var maxDay = Number(d.getDate()); //获取该月的天数;
	var week = this.data.getDay();  //获取该月的第一天是星期几;
	var iRow = 0;
	for (var i=1; i <= maxDay + week; i++)
	{
		if (i > week){
			this.tbody.rows[iRow].cells[i - 1 - iRow*7].innerHTML = i - week; //向第iRow行的td里填充日期;
			iRow = (i - i%7)/7;
		}
	}
	this.nowDate();
	this.otherDateDone();
}
// 计算下一个月份，如果数值大于12，则将月份设为1，年份加1;
objectCreateCalendar.prototype.nextMonth = function(){
	this.month ++;
	this.createDateIn(this.year, this.month);
	var month;
	if(this.month > 12)
	{
		this.month = 1;
		this.year = this.year + 1;
	}
	if(this.month<=9)
	{
		month = "0" + this.month;
	}else{
		month = this.month;
	}
	document.getElementById("div_yd").innerHTML = this.year + '.' + month;
}
//计算上一个月份，如果数值小于1，则将月份设为12，年份减1;
objectCreateCalendar.prototype.prewMonth = function(){
	this.month --;
	this.createDateIn(this.year, this.month);
	var month;
	if(this.month < 1)
	{
		this.month = 12;
		this.year = this.year - 1;
	}
	if(this.month<=9)
	{
		 month = "0" + this.month;
	}else{
		month = this.month;
	}
	document.getElementById("div_yd").innerHTML = this.year + '.' + month;
}
//清空table的内容;
objectCreateCalendar.prototype.clearTD = function(){
	for (var i=0; i<6;i++){
		for (var j=0; j<7;j++){
			this.tbody.rows[i].cells[j].innerHTML = "";
			this.tbody.rows[i].cells[j].style.color = "";
			this.tbody.rows[i].cells[j].style.backgroundImage = "";
			//this.tbody.rows[i].cells[j].clearAttributes();
		}
	}
}
//设当前日期的颜色为红色;
objectCreateCalendar.prototype.nowDate = function()
{
	var data = new Date();
	var nowDate = data.getDate();
	if (this.year == data.getFullYear() && this.month == data.getMonth() + 1){
		for (var i=0; i<6;i++)
		{
			for (var j=0; j<7;j++)
			{
				if(this.tbody.rows[i].cells[j].innerHTML == nowDate)
				{					
					this.tbody.rows[i].cells[j].style.color = "#990000";
				}
			}
		}
	}
}
//设特殊日期的背景颜色
objectCreateCalendar.prototype.doingDate = function(data, bgURL, title, gotoUrl)
{
	var nowDate = data.getDate();
	if (this.year == data.getFullYear() && this.month == data.getMonth() + 1){
		for (var i=0; i<6;i++)
		{
			for (var j=0; j<7;j++)
			{
				if(this.tbody.rows[i].cells[j].innerHTML == nowDate)
				{
					if (bgURL){
						this.tbody.rows[i].cells[j].style.backgroundImage = "url("+bgURL+")";	
					}
					if (title){
						this.tbody.rows[i].cells[j].title = title;	
					}
					if (gotoUrl){
						this.tbody.rows[i].cells[j].innerHTML = "<a href=\"" + gotoUrl + "\" target=\"_blank\">" + this.tbody.rows[i].cells[j].innerHTML + "</a>";	
					}
				}
			}
		}
	}
}

objectCreateCalendar.prototype.otherDateDone = function()
{
	//doing
}

