function getDays(month, year)
{ 
        //下面的这段代码是判断当前是否是闰年的 
	if (1 == month) 
	        return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28; 
        else 
	        return daysInMonth[month]; 
} 

function getToday()
{ 
        //得到今天的年,月,日 
	this.now = new Date(); 
	this.year = this.now.getFullYear(); 
	this.month = this.now.getMonth(); 
	this.day = this.now.getDate(); 
} 

today = new getToday(); 

function newCalendar( e ,  select_day , days )
{ 
        ie4 = (document.all) ? true : false;
	ns4 = (document.layers) ? true : false;
	ns6 = (document.getElementById && !document.all) ? true : false;

	today = new getToday(); 

	var parseYear = parseInt(document.form3.diary_year[document.form3.diary_year.selectedIndex].text); 
	var newCal = new Date(parseYear, document.form3.diary_month.selectedIndex, 1); 
	var day = -1; 
	var startDay = newCal.getDay(); 
	var daily = 0; 

	if (select_day == 0 )
	{
	        if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth())) 
		day = today.day;
	} 
	else
	{
	        day = days ;
	}


	//if( ns4 || ns6 )
	        var tableCal = document.getElementById("dayList") ;
	//else
	//        var tableCal = document.all.calendar.tBodies.dayList; 

	var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear()); 


	for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++) 
	        for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++) 
		{ 
		        var cell = tableCal.rows[intWeek].cells[intDay]; 
			if ((intDay == startDay) && (0 == daily)) 
			        daily = 1; 

			if (day == daily  && day != 0 ) 
			//今天，调用今天的Class 
			{
			        cell.className = "today"; 
			}

			if ((daily > 0) && (daily <= intDaysInMonth)) 
			{ 
			        cell.innerHTML=daily ; 
				daily++; 
			} 
			else 
			        cell.innerHTML= ""; 
		} 

	ShowDiary(day , startDay) ;

} 


function getDate( e )
{ 
        var sDate;
	var oEvent = (  ns4 || ns6 ) ? e.target : event.srcElement ;

	if ("TD" ==oEvent.tagName) 
	        if ("" !=oEvent.innerHTML) 
		{ 		        
		        if ( oEvent.className != "diary" )
			        return ;
		        newCalendar( e , 1) ;
			window.location = "/friends_diary/"+document.form3.login.value+"/"+document.form3.diary_year.value+
			                  "_"+document.form3.diary_month.value+"_"+oEvent.innerHTML+"/listview_0_yes_0_0.html" ;
                } 
} 
