
function __EMP_CALENDAR_CLASS() {
	this._Weeks = new Array("\u65e5", "\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d");
	this._Days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	this._Months = new Array("1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708");
	this._CurDate = new Date();
	this._DaysTable;
	this._SelectMonth;
	this._SelectYear;
	this.ChangeDate = function () {
		var y = this._SelectYear.value;
		var m = this._SelectMonth.value;
		var d = this._DaysTable.getAttribute("EMP_CURRENT_DAY");
		this._SetNewDate(y, m, d);
		this._WriteDays();
	};
	this._SetNewDate = function () {
		var y = this._SelectYear.value;
		var m = this._SelectMonth.value;
		var d = this._DaysTable.getAttribute("EMP_CURRENT_DAY");
		this._CurDate = new Date(y, m, d);
	};
	this.SetDate = function (dateString) {
		var d1 = new Array();
		if (dateString.length == 8) {
			d1[0] = parseInt(dateString.substring(0, 4));
			d1[1] = parseInt(dateString.substring(4, 6));
			d1[2] = parseInt(dateString.substring(6, 8));
		}
		if (dateString.length == 6) {
			d1[0] = parseInt(dateString.substring(0, 2));
			d1[1] = parseInt(dateString.substring(2, 4));
			d1[2] = parseInt(dateString.substring(4, 6));
		}
		var d1 = dateString.split("-");
		if (d1.length < 3) {
			d1 = dateString.split("/");
		}
		if (d1.length < 3) {
			d1 = dateString.split("-");
		}
		if (d1.length == 3) {
			d1[0] = parseInt(d1[0]);
			if (d1[1].substring(0, 1) == "0") {
				d1[1] = d1[1].substring(1);
			}
			if (d1[2].substring(0, 1) == "0") {
				d1[2] = d1[2].substring(1);
			}
			d1[1] = parseInt(d1[1]);
			d1[2] = parseInt(d1[2]);
			if (!(d1[0] + "" == "NaN" || d1[1] + "" == "NaN" || d1[2] + "" == "NaN")) {
				this._CurDate = new Date(d1[0], d1[1] - 1, d1[2]);
			}
		}
	};
	this.CreateCalendar = function () {
		var obj = document.createElement("table");
		var otr = obj.insertRow(-1);
		var td = otr.insertCell(-1);
		td.height = 22;
		td.appendChild(this._CreateMonth());
		td = null;
		td = otr.insertCell(1);
		td.align = "right";
		td.appendChild(this._CreateYear());
		td.width = 100;
		otr = null;
		otr = obj.insertRow(1);
		td = null;
		td = otr.insertCell(-1);
		td.colSpan = 2;
		td.appendChild(this._CreateDaysTable());
		this._WriteDays();
		otr = null;
		otr = obj.insertRow(2);
		td = null;
		td = otr.insertCell(-1);
		td.colSpan = 2;
		td.appendChild(this._CreateToDay());
		td = null;
		otr = null;
		return obj;
	};
	this._CreateToDay = function () {
		var obj = document.createElement("table");
		obj.style.fontFamily = "arial";
		obj.style.fontSize = "12px";
		var otr = obj.insertRow(-1);
		var td = otr.insertCell(-1);
		td.innerHTML = "<div>\u4eca\u5929:</div>";
		td = null;
		td = otr.insertCell(-1);
		td.innerHTML = "<div style='cursor:pointer;' onclick='window.parent.__EMP_CALENDAR_PARENT_OBJ.value=this.innerHTML;window.parent.__EMP_CALENDAR_DIV.style.display = \"none\"'>" + this.GetDate(new Date()) + "</div>";
		td = null;
		otr = null;
		return obj;
	};
	this.MarkDay = function () {
		var day = this._DaysTable.getAttribute("EMP_CURRENT_DAY");
		for (var i = 1; i < this._DaysTable.rows.length; i++) {
			for (var m = 0; m < this._DaysTable.rows[i].cells.length; m++) {
				if (this._DaysTable.rows[i].cells[m].childNodes.length > 0 && this._DaysTable.rows[i].cells[m].childNodes[0].innerHTML == day) {
					this.MarkSelected(this._DaysTable.rows[i].cells[m]);
				} else {
					this.MarkUnSelected(this._DaysTable.rows[i].cells[m]);
				}
			}
		}
	};
	this.MarkSelected = function (obj) {
		obj.style.backgroundColor = "blue";
		obj.style.fontSize = "14px";
	};
	this.MarkUnSelected = function (obj) {
		obj.style.backgroundColor = "";
		obj.style.fontSize = "14px";
	};
	this.MarkBlur = function (obj) {
		obj.style.border = "1px solid #cdcdcd";
		obj.style.fontSize = "14px";
	};
	this.MarkUnBlur = function (obj) {
		obj.style.border = "1px solid #f1f1f1";
		obj.style.fontSize = "14px";
	};
	this._CreateMonth = function () {
		var oTable = this._CreatePervNext();
		var s1 = "<select onchange='EMP_CALENDAR.ChangeDate();'>";
		var s2;
		var curMonth = this._CurDate.getMonth();
		for (var i = 0; i < this._Months.length; i++) {
			if (i == curMonth) {
				s1 += "<option value='" + i + "' selected>" + this._Months[i] + "</option>";
			} else {
				s1 += "<option value='" + i + "'>" + this._Months[i] + "</option>";
			}
		}
		oTable.rows[0].cells[1].innerHTML = s1;
		this._SelectMonth = oTable.rows[0].cells[1].childNodes[0];
		return oTable;
	};
	this._CreateYear = function () {
		var y1 = 1900;
		var y2 = 2099;
		var curYear = this._CurDate.getFullYear();
		var oTable = this._CreatePervNext();
		var s1 = "<select style='font-size:12px;font-family:arial' onchange='EMP_CALENDAR.ChangeDate();'>";
		var s2;
		for (var i = y1; i <= y2; i++) {
			if (i == curYear) {
				s1 += "<option value='" + i + "' selected>" + i + "</option>";
			} else {
				s1 += "<option value='" + i + "'>" + i + "</option>";
			}
		}
		s1 += "</select>";
		oTable.rows[0].cells[1].innerHTML = s1;
		this._SelectYear = oTable.rows[0].cells[1].childNodes[0];
		return oTable;
	};
	this._CreatePervNext = function () {
		var oTable = document.createElement("table");
		oTable.cellPadding = 0;
		oTable.cellSpacing = 0;
		oTable.insertRow(-1);
		oTable.rows[0].insertCell(-1);
		oTable.rows[0].insertCell(-1);
		oTable.rows[0].insertCell(-1);
		var oPrev = document.createElement("div");
		oPrev.style.fontSize = "12px";
		oPrev.style.fontFamily = "arial";
		oPrev.innerHTML = "<b style='cursor:pointer'><font face=Wingdings>\xd7</font>&nbsp;";
		oPrev.onclick = function () {
			var o1 = this.parentNode.parentNode;
			var o2 = o1.cells[1].childNodes[0];
			var a1 = parseInt(o2.value);
			if (a1 == o2.options[0].value) {
				return;
			}
			a1 = a1 - 1;
			o2.value = a1;
			o2.onchange();
			o1 = null;
			o2 = null;
		};
		var oNext = document.createElement("div");
		oNext.style.fontSize = "12px";
		oNext.style.fontFamily = "arial";
		oNext.innerHTML = "<b style='cursor:pointer'>&nbsp;<font face=Wingdings>&Oslash;</font></b>";
		oNext.onclick = function () {
			var o1 = this.parentNode.parentNode;
			var o2 = o1.cells[1].childNodes[0];
			var a1 = parseInt(o2.value);
			if (a1 == o2.options[o2.options.length - 1].value) {
				return;
			}
			a1 = a1 + 1;
			o2.value = a1;
			o2.onchange();
			o1 = null;
			o2 = null;
		};
		oTable.rows[0].cells[0].appendChild(oPrev);
		oTable.rows[0].cells[2].appendChild(oNext);
		oPrev = null;
		oNext = null;
		return oTable;
	};
	this._WriteDays = function () {
		var mmm = this._CreateDays();
		var day = this._CurDate.getDate();
		var title = this._CurDate.getFullYear() + "-" + (this._CurDate.getMonth() + 1) + "-";
		var otd;
		for (var i = 1; i < this._DaysTable.rows.length; i++) {
			for (var m = 0; m < this._DaysTable.rows[i].cells.length; m++) {
				otd = this._DaysTable.rows[i].cells[m];
				if (mmm[i] == null || mmm[i][m] == null) {
					otd.innerHTML = "";
				} else {
					otd.innerHTML = "<div title='" + title + mmm[i][m] + "'>" + mmm[i][m] + "</div>";
				}
				otd = null;
			}
		}
		this.MarkDay();
	};
	this._CreateDaysTable = function () {
		var obj = document.createElement("table");
		with (obj) {
			align = "center";
			border = 0;
			bgColor = "#f1f1f1";
			setAttribute("EMP_CURRENT_DAY", this._CurDate.getDate());
			cellSpacing = 1;
			cellPadding = 1;
			with (style) {
				fontFamily = "arial";
				fontSize = "14px";
				borderTop = "1px solid darkgray";
				borderLeft = "1px solid darkgray";
				borderRight = "1px solid white";
				borderBottom = "1px solid white";
			}
		}
		document.body.bgColor = obj.bgColor;
		var otr;
		var otd;
		for (var i = 0; i < 7; i++) {
			otr = obj.insertRow(-1);
			for (var m = 0; m < 7; m++) {
				otd = otr.insertCell(-1);
				otd.align = "center";
				if (i == 0) {
					otd.bgColor = "#7B9ACB";
					otd.style.color = "#B3D3EC";
					otd.innerHTML = this._Weeks[m];
				} else {
					otd.style.width = "18px";
					otd.style.height = "18px";
					otd.style.border = "1px solid #f1f1f1";
					otd.style.cursor = "pointer";
					otd.onmouseover = function () {
						if (this.innerHTML == "") {
							return;
						}
						EMP_CALENDAR.MarkBlur(this);
					};
					otd.onmouseout = function () {
						if (this.innerHTML == "") {
							return;
						}
						EMP_CALENDAR.MarkUnBlur(this);
					};
					otd.onclick = function () {
						if (this.innerHTML == "") {
							return;
						}
						EMP_CALENDAR._DaysTable.setAttribute("EMP_CURRENT_DAY", this.childNodes[0].innerHTML);
						EMP_CALENDAR._SetNewDate();
						EMP_CALENDAR.MarkDay();
						window.parent.__EMP_CALENDAR_PARENT_OBJ.value = EMP_CALENDAR.GetDate();
						window.parent.__EMP_CALENDAR_DIV.style.display = "none";
					};
				}
				otd = null;
			}
			otr = null;
		}
		this._DaysTable = obj;
		return obj;
	};
	this.GetDate = function (d1) {
		if (d1 == null) {
			d1 = this._CurDate;
		}
		var y = d1.getFullYear();
		var m = d1.getMonth() + 1;
		var d = d1.getDate();
		if (m < 10) {
			m = "0" + m;
		}
		if (d < 10) {
			d = "0" + d;
		}
		return y + "-" + m + "-" + d;
	};
	this._CreateDays = function () {
		var baseDate = new Date(this._CurDate.getFullYear(), this._CurDate.getMonth(), 1);
		var week = baseDate.getDay();
		var a = 1;
		var arrayDays = new Array();
		arrayDays[0] = this._Weeks;
		var m = 1;
		var maxDays = this._getCurMonthDays();
		for (var i = 0; i < 49; i++) {
			if (i == 0 || week == 7) {
				arrayDays[m] = new Array();
				m++;
			}
			if (week == 7) {
				week = 0;
			}
			if (a <= maxDays) {
				arrayDays[m - 1][week] = a;
			} else {
				break;
			}
			a++;
			week++;
		}
		return arrayDays;
	};
	this._getCurMonthDays = function () {
		if ((this._CurDate.getFullYear() - 2008) % 4 == 0 && this._CurDate.getMonth() == 1) {
			return 29;
		} else {
			return this._Days[this._CurDate.getMonth()];
		}
	};
}
///--------------------------------------------------------------------------------------------
var __EMP_CALENDAR_DIV;
var __EMP_CALENDAR_PARENT_OBJ;
function __EMP_CALENDAR_POP(obj) {
	__EMP_CALENDAR_PARENT_OBJ = obj;
	if (__EMP_CALENDAR_DIV == null) {
		__EMP_CREATE_DIV();
	} else {
		window.frames["__EMP_CALENDAR_IFRAME"].aa();
	}
	var a1 = _EMP_CALENDAR_POSITION(obj);
	__EMP_CALENDAR_DIV.style.display = "";
	__EMP_CALENDAR_DIV.style.left = a1[0] + "px";
	__EMP_CALENDAR_DIV.style.top = a1[1] + "px";
}
function __EMP_CREATE_DIV() {
	var MaxIndex = 19721231;
	var aa = window.parent.__EMP_CONTEXT_PATH;
	if (aa == null) {
		aa = __EMP_CONTEXT_PATH;
	}
	var obj = document.createElement("div");
	var obja = document.createElement("div");
	var objb = document.createElement("div");
	with (obja.style) {
		width = "178px";
		height = "220px";
		position = "absolute";
		top = "0px";
		left = "0px";
		zIndex = MaxIndex;
		filter = "alpha(opacity=60)";
		opacity = 0.6;
	}
	with (objb.style) {
		width = "178px";
		height = "220px";
		position = "absolute";
		top = "4px";
		left = "4px";
		zIndex = MaxIndex - 1;
		backgroundColor = "black";
		filter = "alpha(opacity=30)";
		opacity = 0.3;
	}
	with (obj.style) {
		width = "182px";
		height = "224px";
		position = "absolute";
		display = "none";
		overflow = "hidden";
		zIndex = MaxIndex - 2;
	}
	obja.innerHTML = "<iframe name='__EMP_CALENDAR_IFRAME' id=name='__EMP_CALENDAR_IFRAME' frameborder=0 src='" + aa + "/EMP_STYLE/calendar/calendar.htm' scrolling=no width=100% height=100%></iframe>";
	obj.appendChild(obja);
	obj.appendChild(objb);
	obja.onmouseover = function () {
		this.style.filter = "alpha(opacity=100)";
		this.style.opacity = 1;
	};
	obja.onmouseout = function () {
		this.style.filter = "alpha(opacity=60)";
		this.style.opacity = 0.6;
	};
	document.body.appendChild(obj);
	__EMP_CALENDAR_DIV = obj;
	obj = null;
}
function _EMP_CALENDAR_POSITION(obj) {
	var o1 = obj;
	var x, y;
	x = y = 0;
	do {
		x += o1.offsetLeft * 1;
		y += o1.offsetTop * 1;
		if (o1.tagName == "DIV") {
			x -= o1.scrollLeft;
			y -= o1.scrollTop;
		}
		o1 = o1.offsetParent;
	} while (o1.tagName != "BODY");
	y += obj.offsetHeight * 1;
	return new Array(x, y);
}
//---------------------------------------------
function fPopCalendar(obj) {
	__EMP_CALENDAR_POP(obj);
}
function fPopUpCalendarDlg(obj) {
	__EMP_CALENDAR_POP(obj);
}
function __EMP_CALENDAR(obj) {
	if (obj == null) {
		return;
	}
	__EMP_CALENDAR_POP(obj);
}

