elements[i].onclick = function(){
calendar.date = this.title.toDate();
calendar.valueSelected(calendar.date);
calendar.hide();
}
}
}
Calendar.prototype.selectThisYear= function(){
var calendar = this;
var curYear = this.date.getFullYear();
var beginYear = this.beginDate.getFullYear();
var endYear = this.endDate.getFullYear();
var spanObj = this.getElementById("selectThisYear");
var selectStr = "
for(var i = endYear; i >= beginYear; i--){
selectStr += "";
}
selectStr += "";
spanObj.innerHTML = selectStr;
var selectYearObj = spanObj.childNodes(0);
selectYearObj.value = curYear;
selectYearObj.onchange = function(){
calendar.date.setFullYear(selectYearObj.value);
calendar.draw();
}
}
Calendar.prototype.selectThisMonth= function(){
var calendar = this;
var curMonth = this.date.getMonth() + 1;
var curYear = this.date.getFullYear();
var endYear = this.endDate.getFullYear();
var endMonth = 12;
if(curYear == endYear){
endMonth = this.endDate.getMonth + 1;
}
var spanObj = this.getElementById("selectThisMonth");
var selectStr = "
for(var i = 1; i <= endMonth; i++){
selectStr += "";
}
selectStr += "";
spanObj.innerHTML = selectStr;
var selectMonthObj = spanObj.childNodes(0);
selectMonthObj.value = curMonth;
selectMonthObj.onchange = function(){
calendar.date.setMonth(selectMonthObj.value-1);
calendar.draw();
}
}
Calendar.prototype.valueSelected= function(date){
this.dateControl.value = date.format(this.dateFormatStyle);
}
/**
* SetAuto Height for Calendar Panel Div
*/
Calendar.prototype.setAutoHeight= function(){
var height = this.document.body.scrollHeight;
var width = this.getElementById("calendar").style.width;
width = (parseInt(width.substr(0,width.length-1)) + 2) +"px";
this.iframe.style.height = height;
this.panel.style.height = height;
this.panel.style.width = width;
}
//Extenddocument.getElementById(id)
Calendar.prototype.getElementById= function(id){
if (typeof(id) != "string" || id =="") return null;
if(null == this.document) return null;
if (this.document.getElementById) returnthis.document.getElementById(id);
if (this.document.all) returnthis.document.all(id);
try {return eval(id);} catch(e){ returnnull;}
}
//Extendobject.getElementsByTagName(tagName)
Calendar.prototype.getElementsByTagName= function(tagName){
if(null == this.document) return null;
if (this.document.getElementsByTagName)return this.document.getElementsByTagName(tagName);
if (this.document.all) returnthis.document.all.tags(tagName);
}
/**
* Find aHTML Object by TagName and className
* @paramoElm parentNode Object
* @paramstrTagName tag name want to find
* @paramstrClassName class name
*/
functiongetElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName =="*" && oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/-/g,"\-");
var oRegExp = newRegExp("(^|\s)" + strClassName + "(\s|$)");
var oElement;
for(var i=0; i < arrElements.length;i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
//findthe absolute position
Calendar.prototype.getAbsPoint= function (e){
var x = e.offsetLeft;
var y = e.offsetTop;
while(e = e.offsetParent){
x += e.offsetLeft;
y += e.offsetTop;
}
return {"x": x, "y":y};
}
//显示日历
Calendar.prototype.show= function () {
var xy = this.getAbsPoint(this.dateControl);
this.panel.style.left = xy.x +"px";
this.panel.style.top = (xy.y +this.dateControl.offsetHeight) + "px";
this.setDisplayStyle("select","hidden");
this.panel.style.visibility ="visible";
}
//HideCalendar
Calendar.prototype.hide= function() {
this.setDisplayStyle("select","visible");
this.panel.style.visibility ="hidden";
this.isFocus = false;
}
//SetCalendar Picker visible or invisible
Calendar.prototype.setDisplayStyle= function(tagName, style) {
var tags =this.getElementsByTagName(tagName)
for(var i = 0; i < tags.length; i++){
if (tagName.toLowerCase() =="select" &&
(tags[i].name =="calendarYear" ||
tags[i].name =="calendarMonth")){
continue;
}
tags[i].style.visibility = style;
}
}
document.write("
");