

function setToday() {
var now   = new Date();
var day   = now.getDate();
var month = now.getMonth();
var year  = now.getYear();
if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
this.focusDay = day;
document.calControl.month.selectedIndex = month;
document.calControl.year.value = year;
displayCalendar(month, year);
}
function isFourDigitYear(year) {
if (year.length != 4) {
alert ("Sorry, the year must be four-digits in length.");
document.calControl.year.select();
document.calControl.year.focus();
} else { return true; }
}
function selectDate() {
var year  = document.calControl.year.value;
if (isFourDigitYear(year)) {
var day   = 0;
var month = document.calControl.month.selectedIndex;
displayCalendar(month, year);
    }
}

function setPreviousYear() {
var year  = document.calControl.year.value;
if (isFourDigitYear(year)) {
var day   = 0;
var month = document.calControl.month.selectedIndex;
year--;
document.calControl.year.value = year;
displayCalendar(month, year);
   }
}
function setPreviousMonth() {
var year  = document.calControl.year.value;
if (isFourDigitYear(year)) {
var day   = 0;
var month = document.calControl.month.selectedIndex;
if (month == 0) {
month = 11;
if (year > 1000) {
year--;
document.calControl.year.value = year;
}
} else { month--; }
document.calControl.month.selectedIndex = month;
displayCalendar(month, year);
   }
}
function setNextMonth() {
var year  = document.calControl.year.value;
if (isFourDigitYear(year)) {
var day   = 0;
var month = document.calControl.month.selectedIndex;
if (month == 11) {
month = 0;
year++;
document.calControl.year.value = year;
} else { month++; }
document.calControl.month.selectedIndex = month;
displayCalendar(month, year);
   }
}
function setNextYear() {
var year = document.calControl.year.value;
if (isFourDigitYear(year)) {
var day = 0;
var month = document.calControl.month.selectedIndex;
year++;
document.calControl.year.value = year;
displayCalendar(month, year);
   }
}
function displayCalendar(month, year) {    
var now1   = new Date();
var day1   = now1.getDate();
var month1 = now1.getMonth();
var year1  = now1.getYear();
   
month = parseInt(month);
year = parseInt(year);
var i = 0;
var days = getDaysInMonth(month+1,year);
var firstOfMonth = new Date (year, month, 1);
var startingPos = firstOfMonth.getDay();
days += startingPos;
var txtvalue = '';
txtvalue = txtvalue + '<table border=0 width="90%" align="center"><tr class="boxheading" align="center"><td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr>';
txtvalue = txtvalue + '<tr class="boxtext" align="center">';
for (i = 0; i < startingPos; i++) {
	txtvalue = txtvalue + '<td></td>';
}
var chkdate = '0';
if(month==month1 && year==year1){
chkdate = '1';
}
for (i = startingPos; i < days; i++) {
	if ( i%7 == 0 ) txtvalue = txtvalue + '</tr><tr class="boxtext" align="center">';
	txtvalue = txtvalue + '<td>';
	if (i-startingPos+1 < 10)
	txtvalue = txtvalue + '0';
	if(i-startingPos+1 ==day1 && chkdate=='1'){
		txtvalue = txtvalue + '<b><font color=red>';
		txtvalue += i-startingPos+1;
		txtvalue = txtvalue + '</font></b>';
	}else{
		txtvalue += i-startingPos+1;
	}
	
	txtvalue = txtvalue + '</td>';
}
	for (i=days; i<42; i++)  {
		if ( i%7 == 0 ) txtvalue = txtvalue + '</tr><tr class="boxtext" align="center">';
		txtvalue = txtvalue + '<td>';
	}
	txtvalue = txtvalue + '</table>';
	document.getElementById('calendar1').innerHTML = txtvalue;
}

function getDaysInMonth(month,year)  {
var days;
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)  days=31;
else if (month==4 || month==6 || month==9 || month==11) days=30;
else if (month==2)  {
if (isLeapYear(year)) { days=29; }
else { days=28; }
}
return (days);
}
function isLeapYear (Year) {
if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
return (true);
} else { return (false); }
}


