var _ESONCalendar = window.ESONCalendar = { hasFoot: false, weeks: "日一二三四五六", months: "一,二,三,四,五,六,七,八,九,十,十一,十二", start: 1950, end: 2050, color: { caption: "#A4B9D7", border: "#C0D0E8", tablebg: "#F6F6F6", selectedbg: "#FF9900", foot_co: "#003366", selectedco: "#ffffff" }, dateBox: [], splitChar: "-", splitChar2: ":", hotInput: null, initli: false, init: function() { return this.addStyle().addUI().hide(); }, uanv_tool_CE: function(type, id, parent, className, HTML) { var obj = document.createElement(type.toUpperCase()); id && (obj.id = id); className && (obj.className = className); HTML && (obj.innerHTML = HTML); parent || (parent = document.body); return parent.appendChild(obj); }, uanv_tool_getWeek: function(date, i) { var tmp = new Date(date); tmp.setDate(i); return tmp.getDay(); }, uanv_tool_isIn: function(o, parent) { try { while (o != parent && o != document.body) { o = o.parentNode }; return o != document.body; } catch (ex) { return false; } }, onselect: function(d) { this.hotInput && (this.hotInput.value = d.y + this.splitChar + ("0" + d.m).substr(("0" + d.m).length - 2, 2) + this.splitChar + ("0" + d.d).substr(("0" + d.d).length - 2, 2)); this.hide() }, addStyle: function() { var cssText = "#ESONCalendar_Win{background-color:" + this.color.caption + ";position:absolute;z-index:99999;width:190px;box-shadow:0px 0px 5px 2px #ccc}"; cssText += "#ESONCalendar_caption{text-align:center; height:24px; line-height:24px;padding:5px 0;background-color:" + this.color.caption + ";overflow:hidden;filter: progid:DXImageTransform.Microsoft.gradient( GradientType= 0 , startColorstr = '#686868', endColorstr = '#444' );" +"-ms-filter: progid:DXImageTransform.Microsoft.gradient( GradientType = 0,startColorstr = '#686868', endColorstr = '#444' );" +"background-image: -webkit-linear-gradient(top,#686868 0,#444 100%);" +"background-image: -mox-linear-gradient(top,#686868 0,#444 100%);" +"background-image: -o-linear-gradient(top,#686868 0,#444 100%);" +"background-image: linear-gradient(to bottom,#686868 0,#444 100%);}"; cssText += ".clear{clear:both}"; cssText += "#selMonth{width:80px}"; cssText += "#selYear{margin-right:5px; width:80px}"; cssText += "#ESONCalendar_table{width:190px;background-color:" + this.color.tablebg + ";border-collapse:collapse;border:1px solid #bbb}"; cssText += "#ESONCalendar_table th{font-weight:normal;filter: progid:DXImageTransform.Microsoft.gradient( GradientType= 0 , startColorstr = '#fefefe', endColorstr = '#dddddd' );" +"-ms-filter: progid:DXImageTransform.Microsoft.gradient( GradientType = 0,startColorstr = '#fefefe', endColorstr = '#dddddd' );" +"background-image: -webkit-linear-gradient(top,#fefefe 0,#dddddd 100%);" +"background-image: -mox-linear-gradient(top,#fefefe 0,#dddddd 100%);" +"background-image: -o-linear-gradient(top,#fefefe 0,#dddddd 100%);" +"background-image: linear-gradient(to bottom,#fefefe 0,#dddddd 100%);}"; cssText += "#ESONCalendar_week{background-color:" + this.color.border + "}"; cssText += "#ESONCalendar_week th{font-size:12px;height:14px;width:26px;}"; cssText += "#dateBox{font:normal 14px /120% 'arial';}"; cssText += "#dateBox th{width:16px;height:22px;border:1px #bbb solid; font-size:12px;font-weight:bold;}"; cssText += "#dateBox .unselected{cursor:pointer;background-color:" + this.color.tablebg + ";}"; cssText += "#dateBox .sunday{cursor:pointer;background-color:" + this.color.tablebg + ";color:red}"; cssText += "#dateBox .disabled{cursor:normal; background-image:none; background-color:#eee;color:#999}"; cssText += "#dateBox .current,#dateBox .selected{cursor:pointer;background-image:none;background-color:#666;color:#fff;}"; cssText += "#ESONCalendar_foot{padding:2px 0 2px 0;line-height:130%;text-align:center;font-size:11px;color:" + this.color.foot_co + ";background-color:" + this.color.border + "}"; cssText += "#ESONCalendar_Win iframe{position:absolute;z-index:-1;top:0;left:0}"; var STYLE = document.createElement('style'); STYLE.setAttribute("type", "text/css"); STYLE.styleSheet && (STYLE.styleSheet.cssText = cssText) || STYLE.appendChild(document.createTextNode(cssText)); document.getElementsByTagName('head')[0].appendChild(STYLE); return this; }, addUI: function() { if (this.initli) { return; } this.Win = this.uanv_tool_CE("div", "ESONCalendar_Win"); //KillSelectIframe=this.uanv_tool_CE("IFRAME",false,this.Win); var _caption = this.uanv_tool_CE("div", "ESONCalendar_caption", this.Win); var selYear = this.uanv_tool_CE("select", "selYear", _caption); var selMonth = this.uanv_tool_CE("select", "selMonth", _caption); this.selMonth = selMonth; this.selYear = selYear; selMonth.onchange = selYear.onchange = function() { ESONCalendar.dateUp(new Date(selYear.value, selMonth.value, ESONCalendar.d)) }; for (var i = 0; i < 12; i++) { var tmp = new Option(this.months.split(",")[i] + "月", i); selMonth.options.add(tmp); }; for (var i = this.start; i <= this.end; i++) { var tmp = new Option(i, i); selYear.options.add(tmp); }; this.uanv_tool_CE("div", false, _caption, "clear"); var table = this.uanv_tool_CE("table", "ESONCalendar_table", this.Win); var tbody = this.uanv_tool_CE("tbody", false, table); var tr = this.uanv_tool_CE("tr", "ESONCalendar_week", tbody); for (var i = 0; i < 7; i++) { var th = this.uanv_tool_CE("th", false, tr, false, new String(this.weeks).charAt(i)); } this.updatebox(6); if (this.hasFoot) { this.foot = this.uanv_tool_CE("div", "ESONCalendar_foot", this.Win, false, this.footText); this.foot.innerHTML = "UANV_日历 版权作者所有"; } //KillSelectIframe.frameBorder=0; //KillSelectIframe.width=this.Win.offsetWidth;KillSelectIframe.height=this.Win.offsetHeight; document.onclick = document.body.onclick = function(e) { e || (e = window.event); var src = e.target || e.srcElement; var tmp = src.nodeName.toUpperCase(); if (tmp == "HTML" || tmp == "BODY") { return ESONCalendar.hide(); } if (src == ESONCalendar.hotInput || ESONCalendar.uanv_tool_isIn(src, ESONCalendar.Win)) { return; } ESONCalendar.hide(); }; this.initli = true; return this; }, updatebox : function(lines){ this.dateBox.length=0; var tbody = document.getElementById("dateBox"); if(!tbody){ tbody = this.uanv_tool_CE("tbody", "dateBox", document.getElementById("ESONCalendar_table")); }else{ while(tbody.lastChild){ tbody.removeChild(tbody.lastChild); } } for (var i = 0; i < lines; i++) { tr = this.uanv_tool_CE("tr", false, tbody); for (var j = 0; j < 7; j++) { this.dateBox[i * 7 + j] = this.uanv_tool_CE("th", false, tr, false, " "); } }; }, dateUp: function(date, first) { var space = this.uanv_tool_getWeek(date, 1); var m2d = 31, index = 1; this.y = date.getFullYear(), this.m = date.getMonth() + 1, this.d = date.getDate(); this.h = date.getHours(); this.mi = date.getMinutes(); this.s = date.getSeconds(); this.selMonth.options[this.m - 1].selected = "selected"; this.selYear.options[this.y - this.start].selected = "selected"; var isRN = (this.y % 4 == 0 && this.y % 4 != 100 || this.y % 100 == 0 && this.y % 400 == 0); if (/-4|-6|-9|-11/.test("-" + this.m)) { m2d = 30 }; if (this.m == 2) { m2d = isRN ? 29 : 28 }; var days=m2d + space,lines = Math.ceil(days/7), boxs = lines * 7; this.updatebox(lines); for (var i = 0; i < boxs; i++) { var _this = this.dateBox[i]; _this.isSunday = _this.className = _this.isInMonth = _this.onmouseover = _this.onmouseout = _this.onclick = null; if (i < space || i > (days - 1)) { _this.uanv_tool_isInMonth = false; _this.innerHTML = " "; _this.className = "disabled"; continue }; _this.innerHTML = index++; _this.className = "unselected"; _this.isInMonth = true; var week = this.uanv_tool_getWeek(date, _this.innerHTML); if (week == 0 || week == 6) { _this.className = "sunday"; _this.isSunday = true; } if (first && (index - 1) == this.d) { _this.className = "selected"; } _this.onmouseover = function() { if (this.className != "selected") this.className = "current" }; _this.onmouseout = function() { if (this.className != "selected") this.className = this.isSunday ? "sunday" : "unselected" }; _this.onclick = function() { var allD = ESONCalendar.dateBox; for (var i = 0; i < allD.length; i++) { var _for = allD[i]; _for.className = ""; if (_for.isInMonth) { _for.className = "unselected"; } if (_for.isSunday) { _for.className = "sunday"; } }; this.className = "selected"; ESONCalendar.d = this.innerHTML; ESONCalendar.onselect({ y: ESONCalendar.y, m: ESONCalendar.m, d: this.innerHTML, h: ESONCalendar.h, mi: ESONCalendar.mi, s: ESONCalendar.s }); }; }; return this; }, showTo: function(obj) { var oldObj = obj; for (var pos = { x: 0, y: 0 }; obj; obj = obj.offsetParent) { pos.x += obj.offsetLeft; pos.y += obj.offsetTop }; this.Win.style.left = pos.x + "px"; this.Win.style.top = (pos.y + 2 + oldObj.offsetHeight) + "px"; this.Win.style.display = ""; return this; }, bind: function(input) { if (!this.initli) { this.init(); } "string" == typeof(input) && (input = document.getElementById(input)); if (!input.type || input.type.toUpperCase() != "TEXT") { return this; } if (typeof $ != "undefined") { $(input).focus(function() { var dates = this.value.split(ESONCalendar.splitChar); var bindD = this.value.length > 0 ? new Date(dates[0], dates[1] - 1, dates[2]) : new Date(); ESONCalendar.dateUp(bindD, true); ESONCalendar.showTo(ESONCalendar.hotInput = this); }); } else { input.onfocus = function() { var dates = this.value.split(ESONCalendar.splitChar); var bindD = this.value.length > 0 ? new Date(dates[0], dates[1] - 1, dates[2]) : new Date(); ESONCalendar.dateUp(bindD, true); ESONCalendar.showTo(ESONCalendar.hotInput = this); }; } return this; }, hide: function() { this.Win.style.display = "none"; return this }, setInfo: function(v) { this.foot.innerHTML = v; return this } };;