var SmallCalendar={
MonthNames:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
nCurrentYear: 0,
nCurrentMonth: 0,
nSelectedDay: 0,

init: function(calendarId) {
	var HTMLstr = "";
	
	HTMLstr += "<table width='250px' cellspacing='0' cellpadding='0' border='1' id='" + calendarId + "'>\n";
	HTMLstr += "<tr><td bgcolor='#620043'>\n";
	HTMLstr += "\n";
	HTMLstr += "<table border='0' width='100%' onmouseover=\"document.body.style.cursor='pointer';\" onmouseout=\"document.body.style.cursor='';\">\n";
	HTMLstr += "<tr>\n";
	HTMLstr += "<td align='left' width='20px'>\n";
	HTMLstr += "<a href=\"javascript:" + calendarId + ".previousMonth();\" style='text-decoration: none; color: #FFEFE0; font-weight: bold; font-size: -2px;'><<</a>\n";
	HTMLstr += "</td>\n";
	HTMLstr += "<td align='center' width='210px' id='calendarMain' onclick='" + calendarId + ".nSelectedDay=0;" + calendarId + ".setCurrentMonth()' style='color: #FFEFE0; font-weight: bold;'>1999</td>\n";
	HTMLstr += "<td align='right' width='20px'>\n";
	HTMLstr += "<a href=\"javascript:" + calendarId + ".nextMonth();\" style='text-decoration: none; color: #FFEFE0; font-weight: bold; font-size: -2px;'>>></a>\n";
	HTMLstr += "</td>\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "</td></tr>\n";
	HTMLstr += "\n";
	HTMLstr += "<tr height='150px'><td valign=\"top\">\n";
	HTMLstr += "\n";
	HTMLstr += "<table border=0 width='100%' style='padding-top: 5px'>\n";
	HTMLstr += "<tr>\n";
	HTMLstr += "<td width='2' align='center'></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Sun</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Mon</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Tue</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Wed</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Thu</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Fri</b></td>\n";
	HTMLstr += "<td width='35' align='center'><b>Sat</b></td>\n";
	HTMLstr += "<td width='3' align='center'></td>\n";
	HTMLstr += "</tr>\n";
	for (var week=1; week <= 6; week++) {
		HTMLstr += "<tr>\n";
		HTMLstr += "<td width='2' align='center'></td>\n";
		for (var date=1; date <= 7; date++) {
			var blockNumber = (((week - 1) * 7) + date);
			HTMLstr += "  <td onmouseover=\"document.body.style.cursor='pointer';\" onmouseout=\"document.body.style.cursor='';\" onclick='" + calendarId + ".calendarDateClicked(" + blockNumber + ")' id=\"idDate"+blockNumber+"\" val="+blockNumber+" style=\"text-align: center; font-weight: bold\">\n";
			HTMLstr += "  </td>\n";
		}
		HTMLstr += "<td width='3' align='center'></td>\n";
		HTMLstr += "</tr>\n";
	}
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "</td></tr>\n";
	HTMLstr += "</table>\n";
	document.writeln(HTMLstr);
	return this;
},

display: function() {
	this.setCurrentMonth();
},

calendarDateClicked:function (blockNumber) {
	var monthDate = document.getElementById("idDate"+blockNumber).innerHTML;
	if (monthDate != "") {
		var thisDate = this.nCurrentYear + "-" + (this.nCurrentMonth < 10 ? "0" : "") + this.nCurrentMonth + "-" + (monthDate < 10 ? "0" : "") + monthDate;
		this.nSelectedDay = monthDate;
		this.setYearMonth(this.nCurrentYear, this.nCurrentMonth);
		this.calendarDateChanged();
	}
},

calendarDateChanged:function () {
	if (window.onCalendarDateChanged) {
		var thisDate = this.nCurrentYear + "-" + (this.nCurrentMonth < 10 ? "0" : "") + this.nCurrentMonth + "-" + (this.nSelectedDay < 10 ? "0" : "") + this.nSelectedDay;
		onCalendarDateChanged(thisDate);
	}
},

setCurrentMonth:function() {
	date = new Date();
	currentyear=date.getYear();
	if (currentyear < 1000) {
		currentyear+=1900;
	}
	if (this.nSelectedDay == 0) {
		this.nSelectedDay = date.getDate();
	}
	this.setYearMonth(currentyear, date.getMonth()+1);
	this.calendarDateChanged();
},

setDate:function(nYear, nMonth, nDay) {
	this.nSelectedDay = nDay;
	this.setYearMonth(nYear, nMonth);
	this.calendarDateChanged();
},

setYearMonth:function(nYear, nMonth) {
	this.nCurrentYear = nYear;
	this.nCurrentMonth = nMonth;
	var cross_obj=document.getElementById("calendarMain");
	cross_obj.innerHTML  = "<font color=\"#FFEFE0\"><b>"+this.MonthNames[this.nCurrentMonth-1]+"</b></font> <font color=\"#FFEFE0\"><b>"+this.nCurrentYear+"</b></font>";
	
	var date   = new Date(this.nCurrentYear, this.nCurrentMonth-1, 1);
	var nWeek  = 1;
	var nDate;
	
	for (var x=1;x<=42;x++) {
		document.getElementById("idDate"+x).innerHTML = "";
		document.getElementById("idDate"+x).style.backgroundColor = "";
		document.getElementById("idDate"+x).style.border = "";
	}
	
	var thisSelectedDay = this.nSelectedDay;
	var checkDate = new Date(this.nCurrentYear, this.nCurrentMonth, 0);
	if (thisSelectedDay > checkDate.getDate()) {
		thisSelectedDay = checkDate.getDate();
	}

	while (date.getMonth() == this.nCurrentMonth-1) {
		nDate = date.getDate();
		nLastDate = nDate;

		var posDay = date.getDay();
		if (posDay == -1) posDay=6;
		var blockNumber = ((nWeek-1) * 7) + posDay + 1;
		document.getElementById("idDate"+blockNumber).innerHTML = nDate;
		var cross_obj3=document.getElementById("idDate"+blockNumber).style;
		if (nDate == thisSelectedDay) {
			cross_obj3.backgroundColor = "black";
		} else if (nDate == (new Date()).getDate() && date.getMonth() == (new Date()).getMonth()) {
			cross_obj3.border = "1px dashed gray";
		}
		if (date.getDay() == 0 || date.getDay() == 6) {
			cross_obj3.color  = "red";
		} else {
			if (nDate == thisSelectedDay) {
				cross_obj3.color  = "white";
			} else {
				cross_obj3.color  = "black";
			}
		}
	
		date = new Date(this.nCurrentYear, date.getMonth(), date.getDate()+1);
	
		if (posDay == 6) nWeek++;
	}
},

nextMonth:function() {
	this.nCurrentMonth++;
	if (this.nCurrentMonth > 12) {
		this.nCurrentMonth -= 12;
		this.nCurrentYear++;
	}
	this.setYearMonth(this.nCurrentYear, this.nCurrentMonth);
	this.calendarDateChanged();
},

previousMonth:function() {
	this.nCurrentMonth--;
	if (this.nCurrentMonth < 1) {
		this.nCurrentMonth += 12;
		this.nCurrentYear--;
	}
	this.setYearMonth(this.nCurrentYear, this.nCurrentMonth);
	this.calendarDateChanged();
}
}
