/*			var todaydate=new Date()
			var curmonth=todaydate.getMonth()+1 //get current month (1-12)
			var curyear=todaydate.getFullYear() //get current year

			document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
*/

function change2Bold(obj) {
	if (obj){
		this.style.fontWeight="bold"
		this.style.color="yellow"
	}
	alert('An onMouseOver event');
}

function getMonth(month) {
	if (month<=0){
		month=month+12
		year--
	}else if (month>12){
		month=month-12
		year++
	}
	return month;
}

function updateCal(month, year, brdr, spDate, note){
	if (month<=0){
		month=month+12
		year--
	}

	if (month>12){
		month=month-12
		year++
	}

	//var calendarstr=buildCal(getMonth(month), year, 0, spDate, note)
	var calendarstr=buildCal(month, year, 0, spDate, note)
	if (document.getElementById)
		document.getElementById("calendarspace").innerHTML=calendarstr
}

function buildCal(month, year, brdr, spDate, note){
	var monthName=['\u4E00\u6708','\u4E8C\u6708','\u4E09\u6708','\u56DB\u6708','\u4E94\u6708',
					'\u516D\u6708','\u4E03\u6708','\u516B\u6708','\u4E5D\u6708','\u5341\u6708',
					'\u5341\u4E00\u6708','\u5341\u4E8C\u6708']

/*	var monthName=['1\u6708','2\u6708','3\u6708','4\u6708','5\u6708',
					'6\u6708','7\u6708','8\u6708','9\u6708','10\u6708',
					'11\u6708','12\u6708']
*/
	var monthMaxDays=[31,0,31,30,31,30,31,31,30,31,30,31];


	var oD = new Date(year, month-1, 1); //DD replaced line to fix date bug when current day is 31st
	oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

	var todayDate=new Date() //DD added
	var getToday=(year==todayDate.getFullYear() && month==todayDate.getMonth()+1)? todayDate.getDate() : 0 //DD added

	var currentMonth=todayDate.getMonth()+1; //get current month (1-12)

	var leftColSpan=2;



	monthMaxDays[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
	var t='<div class="main">'+
			'<table class="main" width="240" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0">'+
				'<tr align="center">';

//* restrict displaying month down to previous month
	var isPrevYear=((month==12)&&(currentMonth==1))?true:false;
	var isNextYear=((month==1)&&(currentMonth==12))?true:false;
//	if (((month==1)&&(currentMonth==12)) || ((month==12)&&(currentMonth==1))){
//		diffYear=true
//	}

	if (((month>currentMonth-1) && !isPrevYear) || isNextYear){

//	if (((month>currentMonth-1) && !((month==12)&&(currentMonth==1))) || ((month==1)&&(currentMonth==12))){
		t+=			'<td  align="center" class="month">'+'<a href="javascript:updateCal('+(month-1)+','+year+','+brdr+',spDate, note)" >'+
						'<'+
					'</a></td>';
					leftColSpan=1;
	}

	t+=				'<td colspan="'+leftColSpan+'" align="center" class="month">'+
					'</td>';

//* display year and month name
	t+=				'<td colspan="3" align="center" class="month">'+
						monthName[month-1]+
					'</td>';

	t+=				'<td align="center" class="month">'+
					'</td>';

//* restrict displaying month up to next month
	if (((month<currentMonth+1) && !isNextYear) || isPrevYear){

//	if (((month<currentMonth+1) && !((month==1)&&(currentMonth==12))) || ((month==12)&&(currentMonth==1))){
		t+=			'<td  align="center" class="month">'+'<a href="javascript:updateCal('+(month+1)+','+year+','+brdr+',spDate, note)" >'+
						'>'+
					'</a></td>';
	}else {
		t+=			'<td colspan="2" align="center" class="month">'+
					'</td>';
	}

	t+=				'</tr>'+ 	//* display sunday with different color
					'<tr align="center">'+
						'<td class="sunday">'+
						"\u65E5"+
					'</td>';

	for(s=0;s<6;s++){	//* display other weekdays
		t+=			'<td class="daysofweek">'+
						"\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D".substr(s,1)+
					'</td>';
	}
	t+=			'</tr>'+
				'<tr align="center">';




	for(i=1;i<=42;i++){
		var calDate=((i-oD.od>=0)&&(i-oD.od<monthMaxDays[month-1]))? i-oD.od+1 : '&nbsp;';

		//* check special date
		var isSpToday=false;
		var isSpDate=false;
		for (n=0;n<spDate.length;n++){
			if (n%2==0){
				var spDay=spDate[n].substr(0,2)
				var spMonth=spDate[n].substr(2,2)
				var spYear=spDate[n].substr(4,4)
				if ((calDate==spDay)&&(calDate==getToday)&&(month==spMonth)&&(year==spYear)){	//* if special date is today
					isSpToday=true;
					var hyper=spDate[n+1];
				}else if ((calDate==spDay)&&(month==spMonth)&&(year==spYear)){		//* special date matches calender date
					isSpDate=true
					var hyper=spDate[n+1];
				}
			}
		}

		if (isSpToday){
			calDate='<span id="spToday"><a href="'+hyper+'">'+calDate+'</span>'
		}else if (isSpDate){
			calDate='<span id="spDate"><a href="'+hyper+'">'+calDate+'</a></span>'
		}else if (calDate==getToday){ //DD added
			calDate='<span id="today">'+calDate+'</span>'
		}

		t+='<td class="days">'+calDate+'</td>';
		if(((i)%7==0)&&(i<36)) {
			t+='</tr><tr align="center">';
		}
	}

	t+=		'</tr>';
	t+=		'<tr align="left" class="note">'+
				'<td colspan="7">'+
					note+
				'</td>'+
			'</tr>';
	return t+='</table></div>';
}

