欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php+javascript的日历控件

程序员文章站 2022-06-15 23:26:17
复制代码 代码如下: js calendar
复制代码 代码如下:

<html>
<head>
<title>js calendar</title>
<script language="javascript">
/* copyright mihai bazon, 2002-2005 | www.bazon.net/mishoo
* -----------------------------------------------------------
*
* the dhtml calendar, version 1.0 "it is happening again"
*
* details and latest version at:
* www.dynarch.com/projects/calendar
*
* this script is developed by dynarch.com. visit us at www.dynarch.com.
*
* this script is distributed under the gnu lesser general public license.
* read the entire license text here: http://www.gnu.org/licenses/lgpl.html
*/
// $id: calendar.js,v 1.51 2005/03/07 16:44:31 mishoo exp $
/** the calendar object constructor. */
calendar = function (firstdayofweek, datestr, onselected, onclose) {
// member variables
this.activediv = null;
this.currentdateel = null;
this.getdatestatus = null;
this.getdatetooltip = null;
this.getdatetext = null;
this.timeout = null;
this.onselected = onselected || null;
this.onclose = onclose || null;
this.dragging = false;
this.hidden = false;
this.minyear = 1970;
this.maxyear = 2050;
this.dateformat = calendar._tt["def_date_format"];
this.ttdateformat = calendar._tt["tt_date_format"];
this.ispopup = true;
this.weeknumbers = true;
this.firstdayofweek = typeof firstdayofweek == "number" ? firstdayofweek : calendar._fd; // 0 for sunday, 1 for monday, etc.
this.showsothermonths = false;
this.datestr = datestr;
this.ar_days = null;
this.showstime = false;
this.time24 = true;
this.yearstep = 2;
this.hilitetoday = true;
this.multiple = null;
// html elements
this.table = null;
this.element = null;
this.tbody = null;
this.firstdayname = null;
// combo boxes
this.monthscombo = null;
this.yearscombo = null;
this.hilitedmonth = null;
this.activemonth = null;
this.hilitedyear = null;
this.activeyear = null;
// information
this.dateclicked = false;
// one-time initializations
if (typeof calendar._sdn == "undefined") {
// table of short day names
if (typeof calendar._sdn_len == "undefined")
calendar._sdn_len = 3;
var ar = new array();
for (var i = 8; i > 0;) {
ar[--i] = calendar._dn[i].substr(0, calendar._sdn_len);
}
calendar._sdn = ar;
// table of short month names
if (typeof calendar._smn_len == "undefined")
calendar._smn_len = 3;
ar = new array();
for (var i = 12; i > 0;) {
ar[--i] = calendar._mn[i].substr(0, calendar._smn_len);
}
calendar._smn = ar;
}
};
// ** constants
/// "static", needed for event handlers.
calendar._c = null;
/// detect a special case of "web browser"
calendar.is_ie = ( /msie/i.test(navigator.useragent) &&
!/opera/i.test(navigator.useragent) );
calendar.is_ie5 = ( calendar.is_ie && /msie 5\.0/i.test(navigator.useragent) );
/// detect opera browser
calendar.is_opera = /opera/i.test(navigator.useragent);
/// detect khtml-based browsers
calendar.is_khtml = /konqueror|safari|khtml/i.test(navigator.useragent);
// begin: utility functions; beware that these might be moved into a separate
// library, at some point.
calendar.getabsolutepos = function(el) {
var sl = 0, st = 0;
var is_div = /^div$/i.test(el.tagname);
if (is_div && el.scrollleft)
sl = el.scrollleft;
if (is_div && el.scrolltop)
st = el.scrolltop;
var r = { x: el.offsetleft - sl, y: el.offsettop - st };
if (el.offsetparent) {
var tmp = this.getabsolutepos(el.offsetparent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
};
calendar.isrelated = function (el, evt) {
var related = evt.relatedtarget;
if (!related) {
var type = evt.type;
if (type == "mouseover") {
related = evt.fromelement;
} else if (type == "mouseout") {
related = evt.toelement;
}
}
while (related) {
if (related == el) {
return true;
}
related = related.parentnode;
}
return false;
};
calendar.removeclass = function(el, classname) {
if (!(el && el.classname)) {
return;
}
var cls = el.classname.split(" ");
var ar = new array();
for (var i = cls.length; i > 0;) {
if (cls[--i] != classname) {
ar[ar.length] = cls[i];
}
}
el.classname = ar.join(" ");
};
calendar.addclass = function(el, classname) {
calendar.removeclass(el, classname);
el.classname += " " + classname;
};
// fixme: the following 2 functions totally suck, are useless and should be replaced immediately.
calendar.getelement = function(ev) {
var f = calendar.is_ie ? window.event.srcelement : ev.currenttarget;
while (f.nodetype != 1 || /^div$/i.test(f.tagname))
f = f.parentnode;
return f;
};
calendar.gettargetelement = function(ev) {
var f = calendar.is_ie ? window.event.srcelement : ev.target;
while (f.nodetype != 1)
f = f.parentnode;
return f;
};
calendar.stopevent = function(ev) {
ev || (ev = window.event);
if (calendar.is_ie) {
ev.cancelbubble = true;
ev.returnvalue = false;
} else {
ev.preventdefault();
ev.stoppropagation();
}
return false;
};
calendar.addevent = function(el, evname, func) {
if (el.attachevent) { // ie
el.attachevent("on" + evname, func);
} else if (el.addeventlistener) { // gecko / w3c
el.addeventlistener(evname, func, true);
} else {
el["on" + evname] = func;
}
};
calendar.removeevent = function(el, evname, func) {
if (el.detachevent) { // ie
el.detachevent("on" + evname, func);
} else if (el.removeeventlistener) { // gecko / w3c
el.removeeventlistener(evname, func, true);
} else {
el["on" + evname] = null;
}
};
calendar.createelement = function(type, parent) {
var el = null;
if (document.createelementns) {
// use the xhtml namespace; ie won't normally get here unless
// _they_ "fix" the dom2 implementation.
el = document.createelementns("http://www.w3.org/1999/xhtml", type);
} else {
el = document.createelement(type);
}
if (typeof parent != "undefined") {
parent.appendchild(el);
}
return el;
};
// end: utility functions
// begin: calendar static functions
/** internal -- adds a set of events to make some element behave like a button. */
calendar._add_evs = function(el) {
with (calendar) {
addevent(el, "mouseover", daymouseover);
addevent(el, "mousedown", daymousedown);
addevent(el, "mouseout", daymouseout);
if (is_ie) {
addevent(el, "dblclick", daymousedblclick);
el.setattribute("unselectable", true);
}
}
};
calendar.findmonth = function(el) {
if (typeof el.month != "undefined") {
return el;
} else if (typeof el.parentnode.month != "undefined") {
return el.parentnode;
}
return null;
};
calendar.findyear = function(el) {
if (typeof el.year != "undefined") {
return el;
} else if (typeof el.parentnode.year != "undefined") {
return el.parentnode;
}
return null;
};
calendar.showmonthscombo = function () {
var cal = calendar._c;
if (!cal) {
return false;
}
var cal = cal;
var cd = cal.activediv;
var mc = cal.monthscombo;
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, "hilite");
}
if (cal.activemonth) {
calendar.removeclass(cal.activemonth, "active");
}
var mon = cal.monthscombo.getelementsbytagname("div")[cal.date.getmonth()];
calendar.addclass(mon, "active");
cal.activemonth = mon;
var s = mc.style;
s.display = "block";
if (cd.navtype < 0)
s.left = cd.offsetleft + "px";
else {
var mcw = mc.offsetwidth;
if (typeof mcw == "undefined")
// konqueror brain-dead techniques
mcw = 50;
s.left = (cd.offsetleft + cd.offsetwidth - mcw) + "px";
}
s.top = (cd.offsettop + cd.offsetheight) + "px";
};
calendar.showyearscombo = function (fwd) {
var cal = calendar._c;
if (!cal) {
return false;
}
var cal = cal;
var cd = cal.activediv;
var yc = cal.yearscombo;
if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, "hilite");
}
if (cal.activeyear) {
calendar.removeclass(cal.activeyear, "active");
}
cal.activeyear = null;
var y = cal.date.getfullyear() + (fwd ? 1 : -1);
var yr = yc.firstchild;
var show = false;
for (var i = 12; i > 0; --i) {
if (y >= cal.minyear && y <= cal.maxyear) {
yr.innerhtml = y;
yr.year = y;
yr.style.display = "block";
show = true;
} else {
yr.style.display = "none";
}
yr = yr.nextsibling;
y += fwd ? cal.yearstep : -cal.yearstep;
}
if (show) {
var s = yc.style;
s.display = "block";
if (cd.navtype < 0)
s.left = cd.offsetleft + "px";
else {
var ycw = yc.offsetwidth;
if (typeof ycw == "undefined")
// konqueror brain-dead techniques
ycw = 50;
s.left = (cd.offsetleft + cd.offsetwidth - ycw) + "px";
}
s.top = (cd.offsettop + cd.offsetheight) + "px";
}
};
// event handlers
calendar.tablemouseup = function(ev) {
var cal = calendar._c;
if (!cal) {
return false;
}
if (cal.timeout) {
cleartimeout(cal.timeout);
}
var el = cal.activediv;
if (!el) {
return false;
}
var target = calendar.gettargetelement(ev);
ev || (ev = window.event);
calendar.removeclass(el, "active");
if (target == el || target.parentnode == el) {
calendar.cellclick(el, ev);
}
var mon = calendar.findmonth(target);
var date = null;
if (mon) {
date = new date(cal.date);
if (mon.month != date.getmonth()) {
date.setmonth(mon.month);
cal.setdate(date);
cal.dateclicked = false;
cal.callhandler();
}
} else {
var year = calendar.findyear(target);
if (year) {
date = new date(cal.date);
if (year.year != date.getfullyear()) {
date.setfullyear(year.year);
cal.setdate(date);
cal.dateclicked = false;
cal.callhandler();
}
}
}
with (calendar) {
removeevent(document, "mouseup", tablemouseup);
removeevent(document, "mouseover", tablemouseover);
removeevent(document, "mousemove", tablemouseover);
cal._hidecombos();
_c = null;
return stopevent(ev);
}
};
calendar.tablemouseover = function (ev) {
var cal = calendar._c;
if (!cal) {
return;
}
var el = cal.activediv;
var target = calendar.gettargetelement(ev);
if (target == el || target.parentnode == el) {
calendar.addclass(el, "hilite active");
calendar.addclass(el.parentnode, "rowhilite");
} else {
if (typeof el.navtype == "undefined" || (el.navtype != 50 && (el.navtype == 0 || math.abs(el.navtype) > 2)))
calendar.removeclass(el, "active");
calendar.removeclass(el, "hilite");
calendar.removeclass(el.parentnode, "rowhilite");
}
ev || (ev = window.event);
if (el.navtype == 50 && target != el) {
var pos = calendar.getabsolutepos(el);
var w = el.offsetwidth;
var x = ev.clientx;
var dx;
var decrease = true;
if (x > pos.x + w) {
dx = x - pos.x - w;
decrease = false;
} else
dx = pos.x - x;
if (dx < 0) dx = 0;
var range = el._range;
var current = el._current;
var count = math.floor(dx / 10) % range.length;
for (var i = range.length; --i >= 0;)
if (range[i] == current)
break;
while (count-- > 0)
if (decrease) {
if (--i < 0)
i = range.length - 1;
} else if ( ++i >= range.length )
i = 0;
var newval = range[i];
el.innerhtml = newval;
cal.onupdatetime();
}
var mon = calendar.findmonth(target);
if (mon) {
if (mon.month != cal.date.getmonth()) {
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, "hilite");
}
calendar.addclass(mon, "hilite");
cal.hilitedmonth = mon;
} else if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, "hilite");
}
} else {
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, "hilite");
}
var year = calendar.findyear(target);
if (year) {
if (year.year != cal.date.getfullyear()) {
if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, "hilite");
}
calendar.addclass(year, "hilite");
cal.hilitedyear = year;
} else if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, "hilite");
}
} else if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, "hilite");
}
}
return calendar.stopevent(ev);
};
calendar.tablemousedown = function (ev) {
if (calendar.gettargetelement(ev) == calendar.getelement(ev)) {
return calendar.stopevent(ev);
}
};
calendar.caldragit = function (ev) {
var cal = calendar._c;
if (!(cal && cal.dragging)) {
return false;
}
var posx;
var posy;
if (calendar.is_ie) {
posy = window.event.clienty + document.body.scrolltop;
posx = window.event.clientx + document.body.scrollleft;
} else {
posx = ev.pagex;
posy = ev.pagey;
}
cal.hideshowcovered();
var st = cal.element.style;
st.left = (posx - cal.xoffs) + "px";
st.top = (posy - cal.yoffs) + "px";
return calendar.stopevent(ev);
};
calendar.caldragend = function (ev) {
var cal = calendar._c;
if (!cal) {
return false;
}
cal.dragging = false;
with (calendar) {
removeevent(document, "mousemove", caldragit);
removeevent(document, "mouseup", caldragend);
tablemouseup(ev);
}
cal.hideshowcovered();
};
calendar.daymousedown = function(ev) {
var el = calendar.getelement(ev);
if (el.disabled) {
return false;
}
var cal = el.calendar;
cal.activediv = el;
calendar._c = cal;
if (el.navtype != 300) with (calendar) {
if (el.navtype == 50) {
el._current = el.innerhtml;
addevent(document, "mousemove", tablemouseover);
} else
addevent(document, calendar.is_ie5 ? "mousemove" : "mouseover", tablemouseover);
addclass(el, "hilite active");
addevent(document, "mouseup", tablemouseup);
} else if (cal.ispopup) {
cal._dragstart(ev);
}
if (el.navtype == -1 || el.navtype == 1) {
if (cal.timeout) cleartimeout(cal.timeout);
cal.timeout = settimeout("calendar.showmonthscombo()", 250);
} else if (el.navtype == -2 || el.navtype == 2) {
if (cal.timeout) cleartimeout(cal.timeout);
cal.timeout = settimeout((el.navtype > 0) ? "calendar.showyearscombo(true)" : "calendar.showyearscombo(false)", 250);
} else {
cal.timeout = null;
}
return calendar.stopevent(ev);
};
calendar.daymousedblclick = function(ev) {
calendar.cellclick(calendar.getelement(ev), ev || window.event);
if (calendar.is_ie) {
document.selection.empty();
}
};
calendar.daymouseover = function(ev) {
var el = calendar.getelement(ev);
if (calendar.isrelated(el, ev) || calendar._c || el.disabled) {
return false;
}
if (el.ttip) {
if (el.ttip.substr(0, 1) == "_") {
el.ttip = el.caldate.print(el.calendar.ttdateformat) + el.ttip.substr(1);
}
el.calendar.tooltips.innerhtml = el.ttip;
}
if (el.navtype != 300) {
calendar.addclass(el, "hilite");
if (el.caldate) {
calendar.addclass(el.parentnode, "rowhilite");
}
}
return calendar.stopevent(ev);
};
calendar.daymouseout = function(ev) {
with (calendar) {
var el = getelement(ev);
if (isrelated(el, ev) || _c || el.disabled)
return false;
removeclass(el, "hilite");
if (el.caldate)
removeclass(el.parentnode, "rowhilite");
if (el.calendar)
el.calendar.tooltips.innerhtml = _tt["sel_date"];
return stopevent(ev);
}
};
/**
* a generic "click" handler :) handles all types of buttons defined in this
* calendar.
*/
calendar.cellclick = function(el, ev) {
var cal = el.calendar;
var closing = false;
var newdate = false;
var date = null;
if (typeof el.navtype == "undefined") {
if (cal.currentdateel) {
calendar.removeclass(cal.currentdateel, "selected");
calendar.addclass(el, "selected");
closing = (cal.currentdateel == el);
if (!closing) {
cal.currentdateel = el;
}
}
cal.date.setdateonly(el.caldate);
date = cal.date;
var other_month = !(cal.dateclicked = !el.othermonth);
if (!other_month && !cal.currentdateel)
cal._togglemultipledate(new date(date));
else
newdate = !el.disabled;
// a date was clicked
if (other_month)
cal._init(cal.firstdayofweek, date);
} else {
if (el.navtype == 200) {
calendar.removeclass(el, "hilite");
cal.callclosehandler();
return;
}
date = new date(cal.date);
if (el.navtype == 0)
date.setdateonly(new date()); // today
// unless "today" was clicked, we assume no date was clicked so
// the selected handler will know not to close the calenar when
// in single-click mode.
// cal.dateclicked = (el.navtype == 0);
cal.dateclicked = false;
var year = date.getfullyear();
var mon = date.getmonth();
function setmonth(m) {
var day = date.getdate();
var max = date.getmonthdays(m);
if (day > max) {
date.setdate(max);
}
date.setmonth(m);
};
switch (el.navtype) {
case 400:
calendar.removeclass(el, "hilite");
var text = calendar._tt["about"];
if (typeof text != "undefined") {
text += cal.showstime ? calendar._tt["about_time"] : "";
} else {
// fixme: this should be removed as soon as lang files get updated!
text = "help and about box text is not translated into this language.\n" +
"if you know this language and you feel generous please update\n" +
"the corresponding file in \"lang\" subdir to match calendar-en.js\n" +
"and send it back to <mihai_bazon@yahoo.com> to get it into the distribution ;-)\n\n" +
"thank you!\n" +
"http://dynarch.com/mishoo/calendar.epl\n";
}
alert(text);
return;
case -2:
if (year > cal.minyear) {
date.setfullyear(year - 1);
}
break;
case -1:
if (mon > 0) {
setmonth(mon - 1);
} else if (year-- > cal.minyear) {
date.setfullyear(year);
setmonth(11);
}
break;
case 1:
if (mon < 11) {
setmonth(mon + 1);
} else if (year < cal.maxyear) {
date.setfullyear(year + 1);
setmonth(0);
}
break;
case 2:
if (year < cal.maxyear) {
date.setfullyear(year + 1);
}
break;
case 100:
cal.setfirstdayofweek(el.fdow);
return;
case 50:
var range = el._range;
var current = el.innerhtml;
for (var i = range.length; --i >= 0;)
if (range[i] == current)
break;
if (ev && ev.shiftkey) {
if (--i < 0)
i = range.length - 1;
} else if ( ++i >= range.length )
i = 0;
var newval = range[i];
el.innerhtml = newval;
cal.onupdatetime();
return;
case 0:
// today will bring us here
if ((typeof cal.getdatestatus == "function") &&
cal.getdatestatus(date, date.getfullyear(), date.getmonth(), date.getdate())) {
return false;
}
break;
}
if (!date.equalsto(cal.date)) {
cal.setdate(date);
newdate = true;
} else if (el.navtype == 0)
newdate = closing = true;
}
if (newdate) {
ev && cal.callhandler();
}
if (closing) {
calendar.removeclass(el, "hilite");
ev && cal.callclosehandler();
}
};
// end: calendar static functions
// begin: calendar object functions
/**
* this function creates the calendar inside the given parent. if _par is
* null than it creates a popup calendar inside the body element. if _par is
* an element, be it body, then it creates a non-popup calendar (still
* hidden). some properties need to be set before calling this function.
*/
calendar.prototype.create = function (_par) {
var parent = null;
if (! _par) {
// default parent is the document body, in which case we create
// a popup calendar.
parent = document.getelementsbytagname("body")[0];
this.ispopup = true;
} else {
parent = _par;
this.ispopup = false;
}
this.date = this.datestr ? new date(this.datestr) : new date();
var table = calendar.createelement("table");
this.table = table;
table.cellspacing = 0;
table.cellpadding = 0;
table.calendar = this;
calendar.addevent(table, "mousedown", calendar.tablemousedown);
var div = calendar.createelement("div");
this.element = div;
div.classname = "calendar";
if (this.ispopup) {
div.style.position = "absolute";
div.style.display = "none";
}
div.appendchild(table);
var thead = calendar.createelement("thead", table);
var cell = null;
var row = null;
var cal = this;
var hh = function (text, cs, navtype) {
cell = calendar.createelement("td", row);
cell.colspan = cs;
cell.classname = "button";
if (navtype != 0 && math.abs(navtype) <= 2)
cell.classname += " nav";
calendar._add_evs(cell);
cell.calendar = cal;
cell.navtype = navtype;
cell.innerhtml = "<div unselectable='on'>" + text + "</div>";
return cell;
};
row = calendar.createelement("tr", thead);
var title_length = 6;
(this.ispopup) && --title_length;
(this.weeknumbers) && ++title_length;
hh("?", 1, 400).ttip = calendar._tt["info"];
this.title = hh("", title_length, 300);
this.title.classname = "title";
if (this.ispopup) {
this.title.ttip = calendar._tt["drag_to_move"];
this.title.style.cursor = "move";
hh("×", 1, 200).ttip = calendar._tt["close"];
}
row = calendar.createelement("tr", thead);
row.classname = "headrow";
this._nav_py = hh("«", 1, -2);
this._nav_py.ttip = calendar._tt["prev_year"];
this._nav_pm = hh("‹", 1, -1);
this._nav_pm.ttip = calendar._tt["prev_month"];
this._nav_now = hh(calendar._tt["today"], this.weeknumbers ? 4 : 3, 0);
this._nav_now.ttip = calendar._tt["go_today"];
this._nav_nm = hh("›", 1, 1);
this._nav_nm.ttip = calendar._tt["next_month"];
this._nav_ny = hh("»", 1, 2);
this._nav_ny.ttip = calendar._tt["next_year"];
// day names
row = calendar.createelement("tr", thead);
row.classname = "daynames";
if (this.weeknumbers) {
cell = calendar.createelement("td", row);
cell.classname = "name wn";
cell.innerhtml = calendar._tt["wk"];
}
for (var i = 7; i > 0; --i) {
cell = calendar.createelement("td", row);
if (!i) {
cell.navtype = 100;
cell.calendar = this;
calendar._add_evs(cell);
}
}
this.firstdayname = (this.weeknumbers) ? row.firstchild.nextsibling : row.firstchild;
this._displayweekdays();
var tbody = calendar.createelement("tbody", table);
this.tbody = tbody;
for (i = 6; i > 0; --i) {
row = calendar.createelement("tr", tbody);
if (this.weeknumbers) {
cell = calendar.createelement("td", row);
}
for (var j = 7; j > 0; --j) {
cell = calendar.createelement("td", row);
cell.calendar = this;
calendar._add_evs(cell);
}
}
if (this.showstime) {
row = calendar.createelement("tr", tbody);
row.classname = "time";
cell = calendar.createelement("td", row);
cell.classname = "time";
cell.colspan = 2;
cell.innerhtml = calendar._tt["time"] || " ";
cell = calendar.createelement("td", row);
cell.classname = "time";
cell.colspan = this.weeknumbers ? 4 : 3;
(function(){
function maketimepart(classname, init, range_start, range_end) {
var part = calendar.createelement("span", cell);
part.classname = classname;
part.innerhtml = init;
part.calendar = cal;
part.ttip = calendar._tt["time_part"];
part.navtype = 50;
part._range = [];
if (typeof range_start != "number")
part._range = range_start;
else {
for (var i = range_start; i <= range_end; ++i) {
var txt;
if (i < 10 && range_end >= 10) txt = '0' + i;
else txt = '' + i;
part._range[part._range.length] = txt;
}
}
calendar._add_evs(part);
return part;
};
var hrs = cal.date.gethours();
var mins = cal.date.getminutes();
var t12 = !cal.time24;
var pm = (hrs > 12);
if (t12 && pm) hrs -= 12;
var h = maketimepart("hour", hrs, t12 ? 1 : 0, t12 ? 12 : 23);
var span = calendar.createelement("span", cell);
span.innerhtml = ":";
span.classname = "colon";
var m = maketimepart("minute", mins, 0, 59);
var ap = null;
cell = calendar.createelement("td", row);
cell.classname = "time";
cell.colspan = 2;
if (t12)
ap = maketimepart("ampm", pm ? "pm" : "am", ["am", "pm"]);
else
cell.innerhtml = " ";
cal.onsettime = function() {
var pm, hrs = this.date.gethours(),
mins = this.date.getminutes();
if (t12) {
pm = (hrs >= 12);
if (pm) hrs -= 12;
if (hrs == 0) hrs = 12;
ap.innerhtml = pm ? "pm" : "am";
}
h.innerhtml = (hrs < 10) ? ("0" + hrs) : hrs;
m.innerhtml = (mins < 10) ? ("0" + mins) : mins;
};
cal.onupdatetime = function() {
var date = this.date;
var h = parseint(h.innerhtml, 10);
if (t12) {
if (/pm/i.test(ap.innerhtml) && h < 12)
h += 12;
else if (/am/i.test(ap.innerhtml) && h == 12)
h = 0;
}
var d = date.getdate();
var m = date.getmonth();
var y = date.getfullyear();
date.sethours(h);
date.setminutes(parseint(m.innerhtml, 10));
date.setfullyear(y);
date.setmonth(m);
date.setdate(d);
this.dateclicked = false;
this.callhandler();
};
})();
} else {
this.onsettime = this.onupdatetime = function() {};
}
var tfoot = calendar.createelement("tfoot", table);
row = calendar.createelement("tr", tfoot);
row.classname = "footrow";
cell = hh(calendar._tt["sel_date"], this.weeknumbers ? 8 : 7, 300);
cell.classname = "ttip";
if (this.ispopup) {
cell.ttip = calendar._tt["drag_to_move"];
cell.style.cursor = "move";
}
this.tooltips = cell;
div = calendar.createelement("div", this.element);
this.monthscombo = div;
div.classname = "combo";
for (i = 0; i < calendar._mn.length; ++i) {
var mn = calendar.createelement("div");
mn.classname = calendar.is_ie ? "label-iefix" : "label";
mn.month = i;
mn.innerhtml = calendar._smn[i];
div.appendchild(mn);
}
div = calendar.createelement("div", this.element);
this.yearscombo = div;
div.classname = "combo";
for (i = 12; i > 0; --i) {
var yr = calendar.createelement("div");
yr.classname = calendar.is_ie ? "label-iefix" : "label";
div.appendchild(yr);
}
this._init(this.firstdayofweek, this.date);
parent.appendchild(this.element);
};
/** keyboard navigation, only for popup calendars */
calendar._keyevent = function(ev) {
var cal = window._dynarch_popupcalendar;
if (!cal || cal.multiple)
return false;
(calendar.is_ie) && (ev = window.event);
var act = (calendar.is_ie || ev.type == "keypress"),
k = ev.keycode;
if (ev.ctrlkey) {
switch (k) {
case 37: // key left
act && calendar.cellclick(cal._nav_pm);
break;
case 38: // key up
act && calendar.cellclick(cal._nav_py);
break;
case 39: // key right
act && calendar.cellclick(cal._nav_nm);
break;
case 40: // key down
act && calendar.cellclick(cal._nav_ny);
break;
default:
return false;
}
} else switch (k) {
case 32: // key space (now)
calendar.cellclick(cal._nav_now);
break;
case 27: // key esc
act && cal.callclosehandler();
break;
case 37: // key left
case 38: // key up
case 39: // key right
case 40: // key down
if (act) {
var prev, x, y, ne, el, step;
prev = k == 37 || k == 38;
step = (k == 37 || k == 39) ? 1 : 7;
function setvars() {
el = cal.currentdateel;
var p = el.pos;
x = p & 15;
y = p >> 4;
ne = cal.ar_days[y][x];
};setvars();
function prevmonth() {
var date = new date(cal.date);
date.setdate(date.getdate() - step);
cal.setdate(date);
};
function nextmonth() {
var date = new date(cal.date);
date.setdate(date.getdate() + step);
cal.setdate(date);
};
while (1) {
switch (k) {
case 37: // key left
if (--x >= 0)
ne = cal.ar_days[y][x];
else {
x = 6;
k = 38;
continue;
}
break;
case 38: // key up
if (--y >= 0)
ne = cal.ar_days[y][x];
else {
prevmonth();
setvars();
}
break;
case 39: // key right
if (++x < 7)
ne = cal.ar_days[y][x];
else {
x = 0;
k = 40;
continue;
}
break;
case 40: // key down
if (++y < cal.ar_days.length)
ne = cal.ar_days[y][x];
else {
nextmonth();
setvars();
}
break;
}
break;
}
if (ne) {
if (!ne.disabled)
calendar.cellclick(ne);
else if (prev)
prevmonth();
else
nextmonth();
}
}
break;
case 13: // key enter
if (act)
calendar.cellclick(cal.currentdateel, ev);
break;
default:
return false;
}
return calendar.stopevent(ev);
};
/**
* (re)initializes the calendar to the given date and firstdayofweek
*/
calendar.prototype._init = function (firstdayofweek, date) {
var today = new date(),
ty = today.getfullyear(),
tm = today.getmonth(),
td = today.getdate();
this.table.style.visibility = "hidden";
var year = date.getfullyear();
if (year < this.minyear) {
year = this.minyear;
date.setfullyear(year);
} else if (year > this.maxyear) {
year = this.maxyear;
date.setfullyear(year);
}
this.firstdayofweek = firstdayofweek;
this.date = new date(date);
var month = date.getmonth();
var mday = date.getdate();
var no_days = date.getmonthdays();
// calendar voodoo for computing the first day that would actually be
// displayed in the calendar, even if it's from the previous month.
// warning: this is magic. ;-)
date.setdate(1);
var day1 = (date.getday() - this.firstdayofweek) % 7;
if (day1 < 0)
day1 += 7;
date.setdate(-day1);
date.setdate(date.getdate() + 1);
var row = this.tbody.firstchild;
var mn = calendar._smn[month];
var ar_days = this.ar_days = new array();
var weekend = calendar._tt["weekend"];
var dates = this.multiple ? (this.datescells = {}) : null;
for (var i = 0; i < 6; ++i, row = row.nextsibling) {
var cell = row.firstchild;
if (this.weeknumbers) {
cell.classname = "day wn";
cell.innerhtml = date.getweeknumber();
cell = cell.nextsibling;
}
row.classname = "daysrow";
var hasdays = false, iday, dpos = ar_days[i] = [];
for (var j = 0; j < 7; ++j, cell = cell.nextsibling, date.setdate(iday + 1)) {
iday = date.getdate();
var wday = date.getday();
cell.classname = "day";
cell.pos = i << 4 | j;
dpos[j] = cell;
var current_month = (date.getmonth() == month);
if (!current_month) {
if (this.showsothermonths) {
cell.classname += " othermonth";
cell.othermonth = true;
} else {
cell.classname = "emptycell";
cell.innerhtml = " ";
cell.disabled = true;
continue;
}
} else {
cell.othermonth = false;
hasdays = true;
}
cell.disabled = false;
cell.innerhtml = this.getdatetext ? this.getdatetext(date, iday) : iday;
if (dates)
dates[date.print("%y%m%d")] = cell;
if (this.getdatestatus) {
var status = this.getdatestatus(date, year, month, iday);
if (this.getdatetooltip) {
var tooltip = this.getdatetooltip(date, year, month, iday);
if (tooltip)
cell.title = tooltip;
}
if (status === true) {
cell.classname += " disabled";
cell.disabled = true;
} else {
if (/disabled/i.test(status))
cell.disabled = true;
cell.classname += " " + status;
}
}
if (!cell.disabled) {
cell.caldate = new date(date);
cell.ttip = "_";
if (!this.multiple && current_month
&& iday == mday && this.hilitetoday) {
cell.classname += " selected";
this.currentdateel = cell;
}
if (date.getfullyear() == ty &&
date.getmonth() == tm &&
iday == td) {
cell.classname += " today";
cell.ttip += calendar._tt["part_today"];
}
if (weekend.indexof(wday.tostring()) != -1)
cell.classname += cell.othermonth ? " oweekend" : " weekend";
}
}
if (!(hasdays || this.showsothermonths))
row.classname = "emptyrow";
}
this.title.innerhtml = calendar._mn[month] + ", " + year;
this.onsettime();
this.table.style.visibility = "visible";
this._initmultipledates();
// profile
// this.tooltips.innerhtml = "generated in " + ((new date()) - today) + " ms";
};
calendar.prototype._initmultipledates = function() {
if (this.multiple) {
for (var i in this.multiple) {
var cell = this.datescells[i];
var d = this.multiple[i];
if (!d)
continue;
if (cell)
cell.classname += " selected";
}
}
};
calendar.prototype._togglemultipledate = function(date) {
if (this.multiple) {
var ds = date.print("%y%m%d");
var cell = this.datescells[ds];
if (cell) {
var d = this.multiple[ds];
if (!d) {
calendar.addclass(cell, "selected");
this.multiple[ds] = date;
} else {
calendar.removeclass(cell, "selected");
delete this.multiple[ds];
}
}
}
};
calendar.prototype.setdatetooltiphandler = function (unaryfunction) {
this.getdatetooltip = unaryfunction;
};
/**
* calls _init function above for going to a certain date (but only if the
* date is different than the currently selected one).
*/
calendar.prototype.setdate = function (date) {
if (!date.equalsto(this.date)) {
this._init(this.firstdayofweek, date);
}
};
/**
* refreshes the calendar. useful if the "disabledhandler" function is
* dynamic, meaning that the list of disabled date can change at runtime.
* just * call this function if you think that the list of disabled dates
* should * change.
*/
calendar.prototype.refresh = function () {
this._init(this.firstdayofweek, this.date);
};
/** modifies the "firstdayofweek" parameter (pass 0 for synday, 1 for monday, etc.). */
calendar.prototype.setfirstdayofweek = function (firstdayofweek) {
this._init(firstdayofweek, this.date);
this._displayweekdays();
};
/**
* allows customization of what dates are enabled. the "unaryfunction"
* parameter must be a function object that receives the date (as a js date
* object) and returns a boolean value. if the returned value is true then
* the passed date will be marked as disabled.
*/
calendar.prototype.setdatestatushandler = calendar.prototype.setdisabledhandler = function (unaryfunction) {
this.getdatestatus = unaryfunction;
};
/** customization of allowed year range for the calendar. */
calendar.prototype.setrange = function (a, z) {
this.minyear = a;
this.maxyear = z;
};
/** calls the first user handler (selectedhandler). */
calendar.prototype.callhandler = function () {
if (this.onselected) {
this.onselected(this, this.date.print(this.dateformat));
}
};
/** calls the second user handler (closehandler). */
calendar.prototype.callclosehandler = function () {
if (this.onclose) {
this.onclose(this);
}
this.hideshowcovered();
};
/** removes the calendar object from the dom tree and destroys it. */
calendar.prototype.destroy = function () {
var el = this.element.parentnode;
el.removechild(this.element);
calendar._c = null;
window._dynarch_popupcalendar = null;
};
/**
* moves the calendar element to a different section in the dom tree (changes
* its parent).
*/
calendar.prototype.reparent = function (new_parent) {
var el = this.element;
el.parentnode.removechild(el);
new_parent.appendchild(el);
};
// this gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown. if the click was outside the open
// calendar this function closes it.
calendar._checkcalendar = function(ev) {
var calendar = window._dynarch_popupcalendar;
if (!calendar) {
return false;
}
var el = calendar.is_ie ? calendar.getelement(ev) : calendar.gettargetelement(ev);
for (; el != null && el != calendar.element; el = el.parentnode);
if (el == null) {
// calls closehandler which should hide the calendar.
window._dynarch_popupcalendar.callclosehandler();
return calendar.stopevent(ev);
}
};
/** shows the calendar. */
calendar.prototype.show = function () {
var rows = this.table.getelementsbytagname("tr");
for (var i = rows.length; i > 0;) {
var row = rows[--i];
calendar.removeclass(row, "rowhilite");
var cells = row.getelementsbytagname("td");
for (var j = cells.length; j > 0;) {
var cell = cells[--j];
calendar.removeclass(cell, "hilite");
calendar.removeclass(cell, "active");
}
}
this.element.style.display = "block";
this.hidden = false;
if (this.ispopup) {
window._dynarch_popupcalendar = this;
calendar.addevent(document, "keydown", calendar._keyevent);
calendar.addevent(document, "keypress", calendar._keyevent);
calendar.addevent(document, "mousedown", calendar._checkcalendar);
}
this.hideshowcovered();
};
/**
* hides the calendar. also removes any "hilite" from the class of any td
* element.
*/
calendar.prototype.hide = function () {
if (this.ispopup) {
calendar.removeevent(document, "keydown", calendar._keyevent);
calendar.removeevent(document, "keypress", calendar._keyevent);
calendar.removeevent(document, "mousedown", calendar._checkcalendar);
}
this.element.style.display = "none";
this.hidden = true;
this.hideshowcovered();
};
/**
* shows the calendar at a given absolute position (beware that, depending on
* the calendar element style -- position property -- this might be relative
* to the parent's containing rectangle).
*/
calendar.prototype.showat = function (x, y) {
var s = this.element.style;
s.left = x + "px";
s.top = y + "px";
this.show();
};
/** shows the calendar near a given element. */
calendar.prototype.showatelement = function (el, opts) {
var self = this;
var p = calendar.getabsolutepos(el);
if (!opts || typeof opts != "string") {
this.showat(p.x, p.y + el.offsetheight);
return true;
}
function fixposition(box) {
if (box.x < 0)
box.x = 0;
if (box.y < 0)
box.y = 0;
var cp = document.createelement("div");
var s = cp.style;
s.position = "absolute";
s.right = s.bottom = s.width = s.height = "0px";
document.body.appendchild(cp);
var br = calendar.getabsolutepos(cp);
document.body.removechild(cp);
if (calendar.is_ie) {
br.y += document.body.scrolltop;
br.x += document.body.scrollleft;
} else {
br.y += window.scrolly;
br.x += window.scrollx;
}
var tmp = box.x + box.width - br.x;
if (tmp > 0) box.x -= tmp;
tmp = box.y + box.height - br.y;
if (tmp > 0) box.y -= tmp;
};
this.element.style.display = "block";
calendar.continuation_for_the_fucking_khtml_browser = function() {
var w = self.element.offsetwidth;
var h = self.element.offsetheight;
self.element.style.display = "none";
var valign = opts.substr(0, 1);
var halign = "l";
if (opts.length > 1) {
halign = opts.substr(1, 1);
}
// vertical alignment
switch (valign) {
case "t": p.y -= h; break;
case "b": p.y += el.offsetheight; break;
case "c": p.y += (el.offsetheight - h) / 2; break;
case "t": p.y += el.offsetheight - h; break;
case "b": break; // already there
}
// horizontal alignment
switch (halign) {
case "l": p.x -= w; break;
case "r": p.x += el.offsetwidth; break;
case "c": p.x += (el.offsetwidth - w) / 2; break;
case "l": p.x += el.offsetwidth - w; break;
case "r": break; // already there
}
p.width = w;
p.height = h + 40;
self.monthscombo.style.display = "none";
fixposition(p);
self.showat(p.x, p.y);
};
if (calendar.is_khtml)
settimeout("calendar.continuation_for_the_fucking_khtml_browser()", 10);
else
calendar.continuation_for_the_fucking_khtml_browser();
};
/** customizes the date format. */
calendar.prototype.setdateformat = function (str) {
this.dateformat = str;
};
/** customizes the tooltip date format. */
calendar.prototype.setttdateformat = function (str) {
this.ttdateformat = str;
};
/**
* tries to identify the date represented in a string. if successful it also
* calls this.setdate which moves the calendar to the given date.
*/
calendar.prototype.parsedate = function(str, fmt) {
if (!fmt)
fmt = this.dateformat;
this.setdate(date.parsedate(str, fmt));
};
calendar.prototype.hideshowcovered = function () {
if (!calendar.is_ie && !calendar.is_opera)
return;
function getvisib(obj){
var value = obj.style.visibility;
if (!value) {
if (document.defaultview && typeof (document.defaultview.getcomputedstyle) == "function") { // gecko, w3c
if (!calendar.is_khtml)
value = document.defaultview.
getcomputedstyle(obj, "").getpropertyvalue("visibility");
else
value = '';
} else if (obj.currentstyle) { // ie
value = obj.currentstyle.visibility;
} else
value = '';
}
return value;
};
var tags = new array("applet", "iframe", "select");
var el = this.element;
var p = calendar.getabsolutepos(el);
var ex1 = p.x;
var ex2 = el.offsetwidth + ex1;
var ey1 = p.y;
var ey2 = el.offsetheight + ey1;
for (var k = tags.length; k > 0; ) {
var ar = document.getelementsbytagname(tags[--k]);
var cc = null;
for (var i = ar.length; i > 0;) {
cc = ar[--i];
p = calendar.getabsolutepos(cc);
var cx1 = p.x;
var cx2 = cc.offsetwidth + cx1;
var cy1 = p.y;
var cy2 = cc.offsetheight + cy1;
if (this.hidden || (cx1 > ex2) || (cx2 < ex1) || (cy1 > ey2) || (cy2 < ey1)) {
if (!cc.__msh_save_visibility) {
cc.__msh_save_visibility = getvisib(cc);
}
cc.style.visibility = cc.__msh_save_visibility;
} else {
if (!cc.__msh_save_visibility) {
cc.__msh_save_visibility = getvisib(cc);
}
cc.style.visibility = "hidden";
}
}
}
};
/** internal function; it displays the bar with the names of the weekday. */
calendar.prototype._displayweekdays = function () {
var fdow = this.firstdayofweek;
var cell = this.firstdayname;
var weekend = calendar._tt["weekend"];
for (var i = 0; i < 7; ++i) {
cell.classname = "day name";
var realday = (i + fdow) % 7;
if (i) {
cell.ttip = calendar._tt["day_first"].replace("%s", calendar._dn[realday]);
cell.navtype = 100;
cell.calendar = this;
cell.fdow = realday;
calendar._add_evs(cell);
}
if (weekend.indexof(realday.tostring()) != -1) {
calendar.addclass(cell, "weekend");
}
cell.innerhtml = calendar._sdn[(i + fdow) % 7];
cell = cell.nextsibling;
}
};
/** internal function. hides all combo boxes that might be displayed. */
calendar.prototype._hidecombos = function () {
this.monthscombo.style.display = "none";
this.yearscombo.style.display = "none";
};
/** internal function. starts dragging the element. */
calendar.prototype._dragstart = function (ev) {
if (this.dragging) {
return;
}
this.dragging = true;
var posx;
var posy;
if (calendar.is_ie) {
posy = window.event.clienty + document.body.scrolltop;
posx = window.event.clientx + document.body.scrollleft;
} else {
posy = ev.clienty + window.scrolly;
posx = ev.clientx + window.scrollx;
}
var st = this.element.style;
this.xoffs = posx - parseint(st.left);
this.yoffs = posy - parseint(st.top);
with (calendar) {
addevent(document, "mousemove", caldragit);
addevent(document, "mouseup", caldragend);
}
};
// begin: date object patches
/** adds the number of days array to the date object. */
date._md = new array(31,28,31,30,31,30,31,31,30,31,30,31);
/** constants used for time computations */
date.second = 1000 /* milliseconds */;
date.minute = 60 * date.second;
date.hour = 60 * date.minute;
date.day = 24 * date.hour;
date.week = 7 * date.day;
date.parsedate = function(str, fmt) {
var today = new date();
var y = 0;
var m = -1;
var d = 0;
var a = str.split(/\w+/);
var b = fmt.match(/%./g);
var i = 0, j = 0;
var hr = 0;
var min = 0;
for (i = 0; i < a.length; ++i) {
if (!a[i])
continue;
switch (b[i]) {
case "%d":
case "%e":
d = parseint(a[i], 10);
break;
case "%m":
m = parseint(a[i], 10) - 1;
break;
case "%y":
case "%y":
y = parseint(a[i], 10);
(y < 100) && (y += (y > 29) ? 1900 : 2000);
break;
case "%b":
case "%b":
for (j = 0; j < 12; ++j) {
if (calendar._mn[j].substr(0, a[i].length).tolowercase() == a[i].tolowercase()) { m = j; break; }
}
break;
case "%h":
case "%i":
case "%k":
case "%l":
hr = parseint(a[i], 10);
break;
case "%p":
case "%p":
if (/pm/i.test(a[i]) && hr < 12)
hr += 12;
else if (/am/i.test(a[i]) && hr >= 12)
hr -= 12;
break;
case "%m":
min = parseint(a[i], 10);
break;
}
}
if (isnan(y)) y = today.getfullyear();
if (isnan(m)) m = today.getmonth();
if (isnan(d)) d = today.getdate();
if (isnan(hr)) hr = today.gethours();
if (isnan(min)) min = today.getminutes();
if (y != 0 && m != -1 && d != 0)
return new date(y, m, d, hr, min, 0);
y = 0; m = -1; d = 0;
for (i = 0; i < a.length; ++i) {
if (a[i].search(/[a-za-z]+/) != -1) {
var t = -1;
for (j = 0; j < 12; ++j) {
if (calendar._mn[j].substr(0, a[i].length).tolowercase() == a[i].tolowercase()) { t = j; break; }
}
if (t != -1) {
if (m != -1) {
d = m+1;
}
m = t;
}
} else if (parseint(a[i], 10) <= 12 && m == -1) {
m = a[i]-1;
} else if (parseint(a[i], 10) > 31 && y == 0) {
y = parseint(a[i], 10);
(y < 100) && (y += (y > 29) ? 1900 : 2000);
} else if (d == 0) {
d = a[i];
}
}
if (y == 0)
y = today.getfullyear();
if (m != -1 && d != 0)
return new date(y, m, d, hr, min, 0);
return today;
};
/** returns the number of days in the current month */
date.prototype.getmonthdays = function(month) {
var year = this.getfullyear();
if (typeof month == "undefined") {
month = this.getmonth();
}
if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
return 29;
} else {
return date._md[month];
}
};
/** returns the number of day in the year. */
date.prototype.getdayofyear = function() {
var now = new date(this.getfullyear(), this.getmonth(), this.getdate(), 0, 0, 0);
var then = new date(this.getfullyear(), 0, 0, 0, 0, 0);
var time = now - then;
return math.floor(time / date.day);
};
/** returns the number of the week in year, as defined in iso 8601. */
date.prototype.getweeknumber = function() {
var d = new date(this.getfullyear(), this.getmonth(), this.getdate(), 0, 0, 0);
var dow = d.getday();
d.setdate(d.getdate() - (dow + 6) % 7 + 3); // nearest thu
var ms = d.valueof(); // gmt
d.setmonth(0);
d.setdate(4); // thu in week 1
return math.round((ms - d.valueof()) / (7 * 864e5)) + 1;
};
/** checks date and time equality */
date.prototype.equalsto = function(date) {
return ((this.getfullyear() == date.getfullyear()) &&
(this.getmonth() == date.getmonth()) &&
(this.getdate() == date.getdate()) &&
(this.gethours() == date.gethours()) &&
(this.getminutes() == date.getminutes()));
};
/** set only the year, month, date parts (keep existing time) */
date.prototype.setdateonly = function(date) {
var tmp = new date(date);
this.setdate(1);
this.setfullyear(tmp.getfullyear());
this.setmonth(tmp.getmonth());
this.setdate(tmp.getdate());
};
/** prints the date in a string according to the given format. */
date.prototype.print = function (str) {
var m = this.getmonth();
var d = this.getdate();
var y = this.getfullyear();
var wn = this.getweeknumber();
var w = this.getday();
var s = {};
var hr = this.gethours();
var pm = (hr >= 12);
var ir = (pm) ? (hr - 12) : hr;
var dy = this.getdayofyear();
if (ir == 0)
ir = 12;
var min = this.getminutes();
var sec = this.getseconds();
s["%a"] = calendar._sdn[w]; // abbreviated weekday name [fixme: i18n]
s["%a"] = calendar._dn[w]; // full weekday name
s["%b"] = calendar._smn[m]; // abbreviated month name [fixme: i18n]
s["%b"] = calendar._mn[m]; // full month name
// fixme: %c : preferred date and time representation for the current locale
s["%c"] = 1 + math.floor(y / 100); // the century number
s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31)
s["%e"] = d; // the day of the month (range 1 to 31)
// fixme: %d : american date style: %m/%d/%y
// fixme: %e, %f, %g, %g, %h (man strftime)
s["%h"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
s["%i"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
s["%k"] = hr; // hour, range 0 to 23 (24h format)
s["%l"] = ir; // hour, range 1 to 12 (12h format)
s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
s["%m"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
s["%n"] = "\n"; // a newline character
s["%p"] = pm ? "pm" : "am";
s["%p"] = pm ? "pm" : "am";
// fixme: %r : the time in am/pm notation %i:%m:%s %p
// fixme: %r : the time in 24-hour notation %h:%m
s["%s"] = math.floor(this.gettime() / 1000);
s["%s"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59
s["%t"] = "\t"; // a tab character
// fixme: %t : the time in 24-hour notation (%h:%m:%s)
s["%u"] = s["%w"] = s["%v"] = (wn < 10) ? ("0" + wn) : wn;
s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = mon)
s["%w"] = w; // the day of the week (range 0 to 6, 0 = sun)
// fixme: %x : preferred date representation for the current locale without the time
// fixme: %x : preferred time representation for the current locale without the date
s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
s["%y"] = y; // year with the century
s["%%"] = "%"; // a literal '%' character
var re = /%./g;
if (!calendar.is_ie5 && !calendar.is_khtml)
return str.replace(re, function (par) { return s[par] || par; });
var a = str.match(re);
for (var i = 0; i < a.length; i++) {
var tmp = s[a[i]];
if (tmp) {
re = new regexp(a[i], 'g');
str = str.replace(re, tmp);
}
}
return str;
};
date.prototype.__msh_oldsetfullyear = date.prototype.setfullyear;
date.prototype.setfullyear = function(y) {
var d = new date(this);
d.__msh_oldsetfullyear(y);
if (d.getmonth() != this.getmonth())
this.setdate(28);
this.__msh_oldsetfullyear(y);
};
// end: date object patches
// global object that remembers the calendar
window._dynarch_popupcalendar = null;
//********* calendar.js end ********************
/* copyright mihai bazon, 2002, 2003 | http://dynarch.com/mishoo/
* ---------------------------------------------------------------------------
*
* the dhtml calendar
*
* details and latest version at:
* http://dynarch.com/mishoo/calendar.epl
*
* this script is distributed under the gnu lesser general public license.
* read the entire license text here: http://www.gnu.org/licenses/lgpl.html
*
* this file defines helper functions for setting up the calendar. they are
* intended to help non-programmers get a working calendar on their site
* quickly. this script should not be seen as part of the calendar. it just
* shows you what one can do with the calendar, while in the same time
* providing a quick and simple method for setting it up. if you need
* exhaustive customization of the calendar creation process feel free to
* modify this code to suit your needs (this is recommended and much better
* than modifying calendar.js itself).
*/
// $id: calendar-setup.js,v 1.25 2005/03/07 09:51:33 mishoo exp $
/**
* this function "patches" an input field (or other element) to use a calendar
* widget for date selection.
*
* the "params" is a single object that can have the following properties:
*
* prop. name | description
* -------------------------------------------------------------------------------------------------
* inputfield | the id of an input field to store the date
* displayarea | the id of a div or other element to show the date
* button | id of a button or other element that will trigger the calendar
* eventname | event that will trigger the calendar, without the "on" prefix (default: "click")
* ifformat | date format that will be stored in the input field
* daformat | the date format that will be used to display the date in displayarea
* singleclick | (true/false) wether the calendar is in single click mode or not (default: true)
* firstday | numeric: 0 to 6. "0" means display sunday first, "1" means display monday first, etc.
* align | alignment (default: "br"); if you don't know what's this see the calendar documentation
* range | array with 2 elements. default: [1900, 2999] -- the range of years available
* weeknumbers | (true/false) if it's true (default) the calendar will display week numbers
* flat | null or element id; if not null the calendar will be a flat calendar having the parent with the given id
* flatcallback | function that receives a js date object and returns an url to point the browser to (for flat calendar)
* disablefunc | function that receives a js date object and should return true if that date has to be disabled in the calendar
* onselect | function that gets called when a date is selected. you don't _have_ to supply this (the default is generally okay)
* onclose | function that gets called when the calendar is closed. [default]
* onupdate | function that gets called after the date is updated in the input field. receives a reference to the calendar.
* date | the date that the calendar will be initially displayed to
* showstime | default: false; if true the calendar will include a time selector
* timeformat | the time format; can be "12" or "24", default is "12"
* electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
* step | configures the step of the years in drop-down boxes; default: 2
* position | configures the calendar absolute position; default: null
* cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
* showothers | if "true" (but default: "false") it will show days from other months too
*
* none of them is required, they all have default values. however, if you
* pass none of "inputfield", "displayarea" or "button" you'll get a warning
* saying "nothing to setup".
*/
calendar.setup = function (params) {
function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
param_default("inputfield", null);
param_default("displayarea", null);
param_default("button", null);
param_default("eventname", "click");
param_default("ifformat", "%y/%m/%d");
param_default("daformat", "%y/%m/%d");
param_default("singleclick", true);
param_default("disablefunc", null);
param_default("datestatusfunc", params["disablefunc"]); // takes precedence if both are defined
param_default("datetext", null);
param_default("firstday", null);
param_default("align", "br");
param_default("range", [1900, 2999]);
param_default("weeknumbers", true);
param_default("flat", null);
param_default("flatcallback", null);
param_default("onselect", null);
param_default("onclose", null);
param_default("onupdate", null);
param_default("date", null);
param_default("showstime", false);
param_default("timeformat", "24");
param_default("electric", true);
param_default("step", 2);
param_default("position", null);
param_default("cache", false);
param_default("showothers", false);
param_default("multiple", null);
var tmp = ["inputfield", "displayarea", "button"];
for (var i in tmp) {
if (typeof params[tmp[i]] == "string") {
params[tmp[i]] = document.getelementbyid(params[tmp[i]]);
}
}
if (!(params.flat || params.multiple || params.inputfield || params.displayarea || params.button)) {
alert("calendar.setup:\n nothing to setup (no fields found). please check your code");
return false;
}
function onselect(cal) {
var p = cal.params;
var update = (cal.dateclicked || p.electric);
if (update && p.inputfield) {
p.inputfield.value = cal.date.print(p.ifformat);
if (typeof p.inputfield.onchange == "function")
p.inputfield.onchange();
}
if (update && p.displayarea)
p.displayarea.innerhtml = cal.date.print(p.daformat);
if (update && typeof p.onupdate == "function")
p.onupdate(cal);
if (update && p.flat) {
if (typeof p.flatcallback == "function")
p.flatcallback(cal);
}
if (update && p.singleclick && cal.dateclicked)
cal.callclosehandler();
};
if (params.flat != null) {
if (typeof params.flat == "string")
params.flat = document.getelementbyid(params.flat);
if (!params.flat) {
alert("calendar.setup:\n flat specified but can't find parent.");
return false;
}
var cal = new calendar(params.firstday, params.date, params.onselect || onselect);
cal.showsothermonths = params.showothers;
cal.showstime = params.showstime;
cal.time24 = (params.timeformat == "24");
cal.params = params;
cal.weeknumbers = params.weeknumbers;
cal.setrange(params.range[0], params.range[1]);
cal.setdatestatushandler(params.datestatusfunc);
cal.getdatetext = params.datetext;
if (params.ifformat) {
cal.setdateformat(params.ifformat);
}
if (params.inputfield && typeof params.inputfield.value == "string") {
cal.parsedate(params.inputfield.value);
}
cal.create(params.flat);
cal.show();
return false;
}
var triggerel = params.button || params.displayarea || params.inputfield;
triggerel["on" + params.eventname] = function() {
var dateel = params.inputfield || params.displayarea;
var datefmt = params.inputfield ? params.ifformat : params.daformat;
var mustcreate = false;
var cal = window.calendar;
if (dateel)
params.date = date.parsedate(dateel.value || dateel.innerhtml, datefmt);
if (!(cal && params.cache)) {
window.calendar = cal = new calendar(params.firstday,
params.date,
params.onselect || onselect,
params.onclose || function(cal) { cal.hide(); });
cal.showstime = params.showstime;
cal.time24 = (params.timeformat == "24");
cal.weeknumbers = params.weeknumbers;
mustcreate = true;
} else {
if (params.date)
cal.setdate(params.date);
cal.hide();
}
if (params.multiple) {
cal.multiple = {};
for (var i = params.multiple.length; --i >= 0;) {
var d = params.multiple[i];
var ds = d.print("%y%m%d");
cal.multiple[ds] = d;
}
}
cal.showsothermonths = params.showothers;
cal.yearstep = params.step;
cal.setrange(params.range[0], params.range[1]);
cal.params = params;
cal.setdatestatushandler(params.datestatusfunc);
cal.getdatetext = params.datetext;
cal.setdateformat(datefmt);
if (mustcreate)
cal.create();
cal.refresh();
if (!params.position)
cal.showatelement(params.button || params.displayarea || params.inputfield, params.align);
else
cal.showat(params.position[0], params.position[1]);
return false;
};
return cal;
};
//************ calendar-setup.js end *********************

// ** i18n
// calendar big5-utf8 language
// author: gary fu, <gary@garyfu.idv.tw>
// encoding: utf8
// distributed under the same terms as the calendar itself.
// for translators: please use utf-8 if possible. we strongly believe that
// unicode is the answer to a real internationalized world. also please
// include your contact information in the header, as can be seen above.
// full day names
calendar._dn = new array
("星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
"星期日");
// please note that the following array of short day names (and the same goes
// for short month names, _smn) isn't absolutely necessary. we give it here
// for exemplification on how one can customize the short day names, but if
// they are simply the first n letters of the full name you can simply say:
//
// calendar._sdn_len = n; // short day name length
// calendar._smn_len = n; // short month name length
//
// if n = 3 then this is not needed either since we assume a value of 3 if not
// present, to be compatible with translation files that were written before
// this feature.
// short day names
calendar._sdn = new array
("日",
"一",
"二",
"三",
"四",
"五",
"六",
"日");
// first day of the week. "0" means display sunday first, "1" means display
// monday first, etc.
calendar._fd = 0;
// full month names
calendar._mn = new array
("一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月");
// short month names
calendar._smn = new array
("一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月");
// tooltips
calendar._tt = {};
calendar._tt["info"] = "關於";
calendar._tt["about"] =
"dhtml date/time selector\n" +
"(c) dynarch.com 2002-2005 / author: mihai bazon\n" + // don't translate this this ;-)
"for latest version visit: http://www.dynarch.com/projects/calendar/\n" +
"distributed under gnu lgpl. see http://gnu.org/licenses/lgpl.html for details." +
"\n\n" +
"日期選擇方法:\n" +
"- 使用 \xab, \xbb 按鈕可選擇年份\n" +
"- 使用 " + string.fromcharcode(0x2039) + ", " + string.fromcharcode(0x203a) + " 按鈕可選擇月份\n" +
"- 按住上面的按鈕可以加快選取";
calendar._tt["about_time"] = "\n\n" +
"時間選擇方法:\n" +
"- 點擊任何的時間部份可增加其值\n" +
"- 同時按shift鍵再點擊可減少其值\n" +
"- 點擊並拖曳可加快改變的值";
calendar._tt["prev_year"] = "上一年 (按住選單)";
calendar._tt["prev_month"] = "上一月 (按住選單)";
calendar._tt["go_today"] = "到今日";
calendar._tt["next_month"] = " 下一月(按住選單)";
calendar._tt["next_year"] = "下一年 (按住選單)";
calendar._tt["sel_date"] = "選擇日期";
calendar._tt["drag_to_move"] = "拖曳";
calendar._tt["part_today"] = " (今日)";
// the following is to inform that "%s" is to be the first day of week
// %s will be replaced with the day name.
calendar._tt["day_first"] = "將 %s 顯示在前";
// this may be locale-dependent. it specifies the week-end days, as an array
// of comma-separated numbers. the numbers are from 0 to 6: 0 means sunday, 1
// means monday, etc.
calendar._tt["weekend"] = "0,6";
calendar._tt["close"] = "關閉";
calendar._tt["today"] = "今日";
calendar._tt["time_part"] = "點擊or拖曳可改變時間(同時按shift為減)";
// date formats
calendar._tt["def_date_format"] = "%y-%m-%d";
calendar._tt["tt_date_format"] = "%a, %b %e";
calendar._tt["wk"] = "週";
calendar._tt["time"] = "time:";
//************ calendar-big5-utf8.js end *******************
</script>
<style rel="stylesheet" type="text/css" >
/* distributed as part of the coolest dhtml calendar
author: mihai bazon, www.bazon.net/mishoo
copyright dynarch.com 2005, www.dynarch.com
*/
/* the main calendar widget. div containing a table. */
div.calendar { position: relative; }
.calendar, .calendar table {
border: 1px solid #bdb2bf;
font-size: 13px;
color: #000;
cursor: default;
background: "gray";
font-family: "trebuchet ms",verdana,tahoma,sans-serif;
}
.calendar {
border-color: #797979;
}
/* header part -- contains navigation buttons and day names. */
.calendar .button { /* "<<", "<", ">", ">>" buttons have this class */
text-align: center; /* they are the navigation buttons */
padding: 2px; /* make the buttons seem like they're pressing */
background: url("title-bg.gif") repeat-x 0 100%; color: #000;
font-weight: bold;
}
.calendar .nav {
font-family: verdana,tahoma,sans-serif;
}
.calendar .nav div {
background: transparent url("menuarrow.gif") no-repeat 100% 100%;
}
.calendar thead tr { background: url("title-bg.gif") repeat-x 0 100%; color: #000; }
.calendar thead .title { /* this holds the current "month, year" */
font-weight: bold; /* pressing it will take you to the current date */
text-align: center;
padding: 2px;
background: url("title-bg.gif") repeat-x 0 100%; color: #000;
}
.calendar thead .headrow { /* row <tr> containing navigation buttons */
}
.calendar thead .name { /* cells <td> containing the day names */
border-bottom: 1px solid #797979;
padding: 2px;
text-align: center;
color: #000;
}
.calendar thead .weekend { /* how a weekend day name shows in header */
color: #c44;
}
.calendar thead .hilite { /* how do the buttons in header appear when hover */
background: url("hover-bg.gif");
border-bottom: 1px solid #797979;
padding: 2px 2px 1px 2px;
}
.calendar thead .active { /* active (pressed) buttons in header */
background: url("active-bg.gif"); color: #fff;
padding: 3px 1px 0px 3px;
border-bottom: 1px solid #797979;
}
.calendar thead .daynames { /* row <tr> containing the day names */
background: url("dark-bg.gif");
}
/* the body part -- contains all the days in month. */
.calendar tbody .day { /* cells <td> containing month days dates */
font-family: verdana,tahoma,sans-serif;
width: 2em;
color: #000;
text-align: right;
padding: 2px 4px 2px 2px;
font-size: 13px;
}
.calendar tbody .day.othermonth {
font-size: 80%;
color: #999;
font-size: 13px;
}
.calendar tbody .day.othermonth.oweekend {
color: #f99;
font-size: 13px;
}
.calendar table .wn {
padding: 2px 3px 2px 2px;
border-right: 1px solid #797979;
background: url("dark-bg.gif");
}
.calendar tbody .rowhilite td,
.calendar tbody .rowhilite td.wn {
background: url("rowhover-bg.gif");
}
.calendar tbody td.today { font-weight: bold;
font-size: 13px;/* background: url("today-bg.gif") no-repeat 70% 50%; */ }
.calendar tbody td.hilite { /* hovered cells <td> */
background: url("hover-bg.gif");
padding: 1px 3px 1px 1px;
border: 1px solid #bbb;
}
.calendar tbody td.active { /* active (pressed) cells <td> */
padding: 2px 2px 0px 2px;
}
.calendar tbody td.weekend { /* cells showing weekend days */
color: #c44;
}
.calendar tbody td.selected { /* cell showing selected date */
font-weight: bold;
border: 1px solid #797979;
padding: 1px 3px 1px 1px;
background: url("active-bg.gif"); color: #fff;
}
.calendar tbody .disabled { color: #999; }
.calendar tbody .emptycell { /* empty cells (the best is to hide them) */
visibility: hidden;
}
.calendar tbody .emptyrow { /* empty row (some months need less than 6 rows) */
display: none;
}
/* the footer part -- status bar and "close" button */
.calendar tfoot .footrow { /* the <tr> in footer (only one right now) */
text-align: center;
background: #565;
color: #fff;
}
.calendar tfoot .ttip { /* tooltip (status bar) cell <td> */
padding: 2px;
background: url("status-bg.gif") repeat-x 0 0; color: #000;
}
.calendar tfoot .hilite { /* hover style for buttons in footer */
background: #afa;
border: 1px solid #084;
color: #000;
padding: 1px;
}
.calendar tfoot .active { /* active (pressed) style for buttons in footer */
background: #7c7;
padding: 2px 0px 0px 2px;
}
/* combo boxes (menus that display months/years for direct selection) */
.calendar .combo {
position: absolute;
display: none;
top: 0px;
left: 0px;
width: 4em;
cursor: default;
border-width: 0 1px 1px 1px;
border-style: solid;
border-color: #797979;
background: url("normal-bg.gif"); color: #000;
z-index: 100;
font-size: 90%;
}
.calendar .combo .label,
.calendar .combo .label-iefix {
text-align: center;
padding: 1px;
}
.calendar .combo .label-iefix {
width: 4em;
}
.calendar .combo .hilite {
background: url("hover-bg.gif"); color: #000;
}
.calendar .combo .active {
background: url("active-bg.gif"); color: #fff;
font-weight: bold;
}
.calendar td.time {
border-top: 1px solid #797979;
padding: 1px 0px;
text-align: center;
background: url("dark-bg.gif");
}
.calendar td.time .hour,
.calendar td.time .minute,
.calendar td.time .ampm {
padding: 0px 5px 0px 6px;
font-weight: bold;
background: url("normal-bg.gif"); color: #000;
}
.calendar td.time .hour,
.calendar td.time .minute {
font-family: monospace;
}
.calendar td.time .ampm {
text-align: center;
}
.calendar td.time .colon {
padding: 0px 2px 0px 3px;
font-weight: bold;
}
.calendar td.time span.hilite {
background: url("hover-bg.gif"); color: #000;
}
.calendar td.time span.active {
background: url("active-bg.gif"); color: #fff;
}
</style>
</head>
<body>
<form name="form1" action="?" method="post">
<table>
<?php
function disp_js_calendar($button_id, $output_id)
{
/* == sample & description ==
inputfield : "birthday", // the id of input field which you want to put "date" data, not name
ifformat : "%y-%m-%d", // date format
showstime : false, // also show time ?
button : "btn", // button's id, not name
singleclick : true, // how to start this function ? single-click or double-click
step : 1 // the interval of last year and next year
*/
echo '<script type="text/javascript">
calendar.setup({
inputfield : "'.$output_id.'",
ifformat : "%y-%m-%d",
showstime : false,
button : "'.$button_id.'",
singleclick : true,
step : 1
});
</script>';
}
echo '<tr><th class="header">date:</th>
<td><input type="text" name="src_date" value="'.$_post['src_date'].'">
<input type="button" id="btn" value="">';
disp_js_calendar("btn", "src_date");
echo '</td></tr>';
?>
</table>
</body>
</html>