var jsCalHoliday = new Array();
var jsCalOrientation = new Array();
var jsCalSessionStart = new Array();
var jsCalSessionEnd = new Array();
var jsEngMonth = new Array('', 'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER');

jsCalHoliday[0] = '1-1';    // New year
jsCalHoliday[1] = '2-15';   // President's day
jsCalHoliday[2] = '5-31';   // Memorial day
jsCalHoliday[3] = '7-4';    // Independense day
jsCalHoliday[4] = '7-5';    // Independense day observed
jsCalHoliday[5] = '9-6';    // Labor day
jsCalHoliday[6] = '11-25';  // Thanksgiving Day
jsCalHoliday[7] = '11-26';  // Day After Thanksgiving Day
jsCalHoliday[8] = '12-31';  // New year's eve

jsCalOrientation[0] = '1-4';
jsCalOrientation[1] = '2-2';
jsCalOrientation[2] = '3-3';
jsCalOrientation[3] = '4-1';
jsCalOrientation[4] = '4-30';
jsCalOrientation[5] = '6-1';
jsCalOrientation[6] = '6-30';
jsCalOrientation[7] = '7-29';
jsCalOrientation[8] = '8-27';
jsCalOrientation[9] = '9-27';
jsCalOrientation[10] = '10-26';
jsCalOrientation[11] = '11-24';

jsCalSessionStart[0] = '1-5';
jsCalSessionStart[1] = '2-3';
jsCalSessionStart[2] = '3-4';
jsCalSessionStart[3] = '4-2';
jsCalSessionStart[4] = '5-3';
jsCalSessionStart[5] = '6-2';
jsCalSessionStart[6] = '7-1';
jsCalSessionStart[7] = '7-30';
jsCalSessionStart[8] = '8-30';
jsCalSessionStart[9] = '9-28';
jsCalSessionStart[10] = '10-27';
jsCalSessionStart[11] = '11-29';

jsCalSessionEnd[0] = '2-1';
jsCalSessionEnd[1] = '3-2';
jsCalSessionEnd[2] = '3-31';
jsCalSessionEnd[3] = '4-29';
jsCalSessionEnd[4] = '5-28';
jsCalSessionEnd[5] = '6-29';
jsCalSessionEnd[6] = '7-28';
jsCalSessionEnd[7] = '8-26';
jsCalSessionEnd[8] = '9-24';
jsCalSessionEnd[9] = '10-25';
jsCalSessionEnd[10] = '11-23';
jsCalSessionEnd[11] = '12-24';

function inArray (arrValue, chkValue) {
	for (var i = 0, l = arrValue.length; i < l; i++) if (arrValue[i] == chkValue) return true;
	return false;
}

jsCal = function (innerId, year, month, arrDay, arrColor) {
	this.today = new Date();
	this.innerId = innerId;

	(!year) ? this.year = this.today.getFullYear() : this.year = year;
	(!month) ? this.month = this.today.getMonth() + 1 : this.month = month;
	this.engmonth = jsEngMonth[this.month];
	(!arrDay) ? this.arrDay = new Array('S', 'M', 'T', 'W', 'Th', 'F', 'Sa') : this.arrDay = arrDay;
	(!arrColor) ? this.arrColor = new Array('red', 'black', 'blue', 'green; font-weight:bold', 'red; font-weight:bold', 'blue; font-weight:bold; text-decoration: underline') : this.arrColor = arrColor;
}

jsCal.prototype.showCal = function () {
	var day = 1, color = '', todayMark = '';

	var firstday = new Date(this.year, this.month-1).getDay()+1, lastday = new Date(this.year, this.month, 0).getDate();

	var jsCalendar = '<div class="calTitle"><span class="calTitleMonth">' + this.engmonth + '</span></div>';

	jsCalendar += '<div class="calTbl">';

	for (var i = 0; i < 7; i++) {
		if (i == 0) color = this.arrColor[0];
		else if (i == 6) color = this.arrColor[2];
		else color = this.arrColor[1];

		jsCalendar += '<div class="calWeek" style="color:'+color+';">'+this.arrDay[i]+'</div>';
	}

	for (var i = 1; i < firstday+lastday; i++) {
		if (i < firstday) jsCalendar += '<div class="calDay"></div>';
		else {
			if (i == firstday) color = this.arrColor[1];

			if ((i%7) == 0) color = this.arrColor[2];
			else if ((i-1)%7 == 0) color = this.arrColor[0];
			else color = this.arrColor[1];

			if (inArray(jsCalHoliday, this.month+'-'+day)) color = this.arrColor[4];
			if (inArray(jsCalOrientation, this.month + '-' + day)) color = this.arrColor[3];
			if (inArray(jsCalSessionEnd, this.month + '-' + day)) color = this.arrColor[2];
			if (inArray(jsCalSessionStart, this.month + '-' + day)) color = this.arrColor[5];

			(this.today.getFullYear() == this.year && this.today.getMonth()+1 == this.month &&this.today.getDate() == day) ? todayMark = 'font-weight:bold;' : todayMark = '';

			jsCalendar += '<div class="calDay" style="color:'+color+';'+todayMark+'">'+day+'</div>';
			day++;
		}
	}

	jsCalendar += '</div>';

	document.getElementById(this.innerId).innerHTML = jsCalendar;
}
