function cCalendar(_sName) {

	var oNow = new Date();

	this.sName = _sName;
	this.sId = "calendar" + _sName;
	this.nDay = oNow.getDate();
	this.nMonth = oNow.getMonth();
	this.nYear = oNow.getFullYear();
	this.fJumpToDate = fJumpToDate;
	this.fRender = fRender;
	this.fShow = fShow;
	this.fHide = fHide;
	this.fDrawDate = fDrawDate;
	this.onShow = new Function("return true;");
	this.onHide = new Function("return true;");
	this.onChooseDay = new Function("return true;");

	function fJumpToDate(_nMonth, _nYear) {
		this.nMonth = _nMonth;
		this.nYear = _nYear;
		this.fDrawDate();
	}

	function fRender() {

		var sHTML = "<div id=\"" + this.sId + "\" style=\"position: absolute; display: none; width: 140px; cursor: default; background-color: #E9E8F2; border: solid 1px #9B95A6; padding: 2px; \">";
		sHTML += "<table style=\"border-collapse: collapse; font-family: Verdana; font-size: 9px; color: #000000; text-align: center;\">";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "Prev\" style=\"border: #9B95A6 1px solid; cursor: pointer; text-align: center; font-weight: bold;\" onMouseOver=\"this.style.background='#8D9AA7'; this.style.color='#FFFFFF';\" onMouseOut=\"this.style.background=''; this.style.color='';\">&laquo;</td>";
		sHTML += "<td id=\"" + this.sId + "TitleMonth\" colspan=\"5\" style=\"text-align: center; font-weight: bold;\"></td>";
		sHTML += "<td id=\"" + this.sId + "Next\" style=\"border: #9B95A6 1px solid; cursor: pointer; text-align: center; font-weight: bold;\" onMouseOver=\"this.style.background='#8D9AA7'; this.style.color='#FFFFFF';\" onMouseOut=\"this.style.background=''; this.style.color='';\">&raquo;</td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "PrevYear\" style=\"border: #9B95A6 1px solid; cursor: pointer; text-align: center; font-weight: bold;\" onMouseOver=\"this.style.background='#8D9AA7'; this.style.color='#FFFFFF';\" onMouseOut=\"this.style.background=''; this.style.color='';\">&laquo;</td>";
		sHTML += "<td id=\"" + this.sId + "TitleYear\" colspan=\"5\" style=\"text-align: center; font-weight: bold;\"></td>";
		sHTML += "<td id=\"" + this.sId + "NextYear\" style=\"border: #9B95A6 1px solid; cursor: pointer; text-align: center; font-weight: bold;\" onMouseOver=\"this.style.background='#8D9AA7'; this.style.color='#FFFFFF';\" onMouseOut=\"this.style.background=''; this.style.color='';\">&raquo;</td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">L</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">M</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">X</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">J</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">V</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">S</td>";
		sHTML += "<td style=\"width: 18px; text-align: center;\">D</td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "1\"></td>";
		sHTML += "<td id=\"" + this.sId + "2\"></td>";
		sHTML += "<td id=\"" + this.sId + "3\"></td>";
		sHTML += "<td id=\"" + this.sId + "4\"></td>";
		sHTML += "<td id=\"" + this.sId + "5\"></td>";
		sHTML += "<td id=\"" + this.sId + "6\"></td>";
		sHTML += "<td id=\"" + this.sId + "7\"></td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "8\"></td>";
		sHTML += "<td id=\"" + this.sId + "9\"></td>";
		sHTML += "<td id=\"" + this.sId + "10\"></td>";
		sHTML += "<td id=\"" + this.sId + "11\"></td>";
		sHTML += "<td id=\"" + this.sId + "12\"></td>";
		sHTML += "<td id=\"" + this.sId + "13\"></td>";
		sHTML += "<td id=\"" + this.sId + "14\"></td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "15\"></td>";
		sHTML += "<td id=\"" + this.sId + "16\"></td>";
		sHTML += "<td id=\"" + this.sId + "17\"></td>";
		sHTML += "<td id=\"" + this.sId + "18\"></td>";
		sHTML += "<td id=\"" + this.sId + "19\"></td>";
		sHTML += "<td id=\"" + this.sId + "20\"></td>";
		sHTML += "<td id=\"" + this.sId + "21\"></td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "22\"></td>";
		sHTML += "<td id=\"" + this.sId + "23\"></td>";
		sHTML += "<td id=\"" + this.sId + "24\"></td>";
		sHTML += "<td id=\"" + this.sId + "25\"></td>";
		sHTML += "<td id=\"" + this.sId + "26\"></td>";
		sHTML += "<td id=\"" + this.sId + "27\"></td>";
		sHTML += "<td id=\"" + this.sId + "28\"></td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "29\"></td>";
		sHTML += "<td id=\"" + this.sId + "30\"></td>";
		sHTML += "<td id=\"" + this.sId + "31\"></td>";
		sHTML += "<td id=\"" + this.sId + "32\"></td>";
		sHTML += "<td id=\"" + this.sId + "33\"></td>";
		sHTML += "<td id=\"" + this.sId + "34\"></td>";
		sHTML += "<td id=\"" + this.sId + "35\"></td>";
		sHTML += "</tr>";
		sHTML += "<tr>";
		sHTML += "<td id=\"" + this.sId + "36\"></td>";
		sHTML += "<td id=\"" + this.sId + "37\"></td>";
		sHTML += "<td></td>";
		sHTML += "<td></td>";
		sHTML += "<td></td>";
		sHTML += "<td></td>";
		sHTML += "<td onClick=\"" + this.sName + ".fHide()\"style=\"border: #9B95A6 1px solid; cursor: pointer; text-align: center; font-weight: bold;\" onMouseOver=\"this.style.background='#8D9AA7'; this.style.color='#FFFFFF';\" onMouseOut=\"this.style.background=''; this.style.color='';\">X</td>";
		sHTML += "</tr>";
		sHTML += "</table>";
		sHTML += "</div>";

		document.write(sHTML);
	}

	function fDrawDate() {
		var oDate = new Date();
		var aMonths = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
		if(this.nMonth >= 0 && this.nYear >= 0) {
			oDate.setMonth(this.nMonth - 1);
			oDate.setYear(this.nYear);
		}
		var nMonth = oDate.getMonth();
		var nYear = oDate.getFullYear();
		fId(this.sId + "TitleMonth").innerHTML = aMonths[nMonth];
		fId(this.sId + "TitleYear").innerHTML = nYear;
		oDate.setDate(1);
		var nStartday = oDate.getDay();
		if(nStartday == 0) {
			nStartday = 7;
		}
		var oDateNow = new Date();
		for(i = 1; i <= 37; i++) {
			if(i - nStartday + 1> 0 && fCheckDate(i - nStartday + 1, nMonth, nYear)) {
				oDate.setDate(i - nStartday + 1);
				var nDate = i - nStartday + 1;
				fId(this.sId + i).innerHTML = "<center>" + nDate + "</center>";
				fId(this.sId + i).style.border = "#9B95A6 1px solid";
				fId(this.sId + i).style.cursor = "pointer";
				fId(this.sId + i).onclick = new Function(this.sName + ".nDay=" + nDate + "; " + this.sName + ".onChooseDay(); " + this.sName + ".fHide()");
				fId(this.sId + i).onmouseover = new Function("this.style.background = \"#8D9AA7\"; this.style.color = \"#FFFFFF\";");
				fId(this.sId + i).onmouseout = new Function("this.style.background = \"\"; this.style.color = \"\";");
			} else {
				fId(this.sId + i).innerHTML = "";
				fId(this.sId + i).style.border = "";
				fId(this.sId + i).onclick = new Function("return false");
				fId(this.sId + i).onmouseover = new Function("return false");
				fId(this.sId + i).onmouseout = new Function("return false");
			}
		}
		var nMonthPrev = nMonth;
		var nMonthNext = nMonth + 2;
		var nYearPrev = nYear;
		var nYearNext = nYear;
		if(nMonthPrev == 0) {
			nMonthPrev = 12;
			nYearPrev--;
		}
		if(nMonthNext == 13) {
			nMonthNext = 1;
			nYearNext++;
		}

		fId(this.sId + "Prev").onclick = new Function(this.sName + ".fJumpToDate(" + nMonthPrev + ", " + nYearPrev + ")");
		fId(this.sId + "Next").onclick = new Function(this.sName + ".fJumpToDate(" + nMonthNext + ", " + nYearNext + ")");


		fId(this.sId + "PrevYear").onclick = new Function(this.sName + ".fJumpToDate(" + (nMonth+1) + ", " + (nYearPrev-1) + ")");
		fId(this.sId + "NextYear").onclick = new Function(this.sName + ".fJumpToDate(" + (nMonth+1) + ", " + (nYear+1) + ")");
	}

	function fShow(_oElement) {

		this.fDrawDate();

		var nTop = 0;
		var nLeft = 0;

		var oElement = _oElement;
		while(oElement.tagName != "BODY" && oElement.tagName != "HTML") {
			if(oElement.style.top!="") {
				nTop += oElement.style.top.substring(1, oElement.style.top.length - 2) * 1;
			} else {
				nTop += oElement.offsetTop;
			}
			oElement = oElement.offsetParent;
		}
		nTop += _oElement.offsetHeight;

		oElement = _oElement;
		while(oElement.tagName != "BODY" && oElement.tagName != "HTML") {
			if(oElement.style.top!="") {
				nLeft += oElement.style.left.substring(1, oElement.style.left.length - 2) * 1;
			} else {
				nLeft += oElement.offsetLeft;
			}
			oElement = oElement.offsetParent;
		}

		document.getElementById(this.sId).style.left = nLeft + "px";
		document.getElementById(this.sId).style.top = nTop + "px";
		document.getElementById(this.sId).style.display = "block";

		this.onShow();

	}

	function fHide() {
		document.getElementById(this.sId).style.display = "none";
		this.onHide();
	}

}