/*
* My97 DatePicker 4.2
* SITE: http://dp.my97.net
* BLOG: http://my97.cnblogs.com
* MAIL: smallcarrot@163.com
*/
var $c;
if ($FF) {
Event.prototype.__defineSetter__("returnValue",
function ($) {
if (!$) this.preventDefault();
return $
});
Event.prototype.__defineGetter__("srcElement",
function () {
var $ = this.target;
while ($.nodeType != 1) $ = $.parentNode;
return $
});
HTMLElement.prototype.attachEvent = function ($, _) {
var A = $.replace(/on/, "");
_._ieEmuEventHandler = function ($) {
window.event = $;
return _()
};
this.addEventListener(A, _._ieEmuEventHandler, false)
}
}
function My97DP() {
$c = this;
$dp.$w = window;
$dt = this.date = new DPDate();
this.QS = [];
$d = document.createElement("div");
$d.className = "WdateDiv";
$d.onmousedown = hideSel;
$d.innerHTML = "
";
attachTabEvent($d,
function () {
hideSel()
});
_();
this.init();
$();
$d.MI.attachEvent("onkeydown", A);
$d.yI.attachEvent("onkeydown", A);
$d.MI.onfocus = function ($) {
this.className = "yminputfocus";
this.value = getA(this, "realValue");
this.select();
$c._fM();
showB($d.MD)
};
$d.MI.onblur = function () {
var $;
if ($lastInput == this) {
$dt.M = pIntDef(this.value, $dt.M);
$ = true
}
c_M($dt.M, $);
this.className = "yminput";
hide($d.MD)
};
$d.yI.onfocus = function () {
this.className = "yminputfocus";
this.select();
$c._fy();
showB($d.yD)
};
$d.yI.onblur = function () {
var $;
if ($lastInput == this) {
$dt.y = pIntDef(this.value, $dt.y);
$ = true
}
c_y($dt.y, $);
this.className = "yminput";
hide($d.yD)
};
$d.HI.onfocus = function () {
$c.currFocus = this;
this.select();
$c._fH();
showB($d.HD)
};
$d.HI.onblur = function () {
var $;
if ($lastInput == this) {
$dt.H = pIntDef(this.value, $dt.H);
$ = true
}
c_H($dt.H, $);
hide($d.HD)
};
$d.mI.onfocus = function () {
$c.currFocus = this;
this.select();
$c._fm();
showB($d.mD)
};
$d.mI.onblur = function () {
var $;
if ($lastInput == this) {
$dt.m = pIntDef(this.value, $dt.m);
$ = true
}
c_m($dt.m, $);
hide($d.mD)
};
$d.sI.onfocus = function () {
$c.currFocus = this;
this.select();
$c._fs();
showB($d.sD)
};
$d.sI.onblur = function () {
var $;
if ($lastInput == this) {
$dt.s = pIntDef(this.value, $dt.s);
$ = true
}
c_s($dt.s, $);
hide($d.sD)
};
$d.HI.attachEvent("onkeydown", A);
$d.mI.attachEvent("onkeydown", A);
$d.sI.attachEvent("onkeydown", A);
$d.upButton.onclick = function () {
updownEvent(1)
};
$d.downButton.onmousedown = function () {
updownEvent(- 1)
};
$d.qsDiv.onclick = function () {
if ($d.qsDivSel.style.display != "block") {
$c._fillQS();
showB($d.qsDivSel)
} else hide($d.qsDivSel)
};
attachTabEvent($d.okI,
function () {
$d.MI.focus();
event.returnValue = false
});
document.body.appendChild($d);
function _() {
var A = $d.getElementsByTagName("div"),
$ = $d.getElementsByTagName("input"),
B = $d.getElementsByTagName("button"),
_ = $d.getElementsByTagName("span");
$d.navLeftImg = A[1];
$d.leftImg = A[2];
$d.rightImg = A[8];
$d.navRightImg = A[7];
$d.MI = $[0];
$d.yI = $[1];
$d.titleDiv = A[0];
$d.MD = A[4];
$d.yD = A[6];
$d.qsDivSel = A[9];
$d.dDiv = A[10];
$d.tDiv = A[11];
$d.HD = A[12];
$d.mD = A[13];
$d.sD = A[14];
$d.qsDiv = A[15];
$d.bDiv = A[16];
$d.HI = $[2];
$d.mI = $[4];
$d.sI = $[6];
$d.clearI = $[7];
$d.todayI = $[8];
$d.okI = $[9];
$d.upButton = B[0];
$d.downButton = B[1];
$d.timeSpan = _[0]
}
function $() {
$d.navLeftImg.onclick = function () {
$ny = $ny <= 0 ? $ny - 1 : -1;
if ($ny % 5 == 0) $d.yI.focus();
c_y($dt.y - 1)
};
$d.leftImg.onclick = function () {
var $ = $dt.M;
if ($ > 1) $ -= 1;
else {
$ = 12;
$dt.y -= 1
}
s_y($dt.y);
c_M($)
};
$d.rightImg.onclick = function () {
var $ = $dt.M;
if ($ < 12) $ += 1;
else {
$ = 1;
$dt.y += 1
}
s_y($dt.y);
c_M($)
};
$d.navRightImg.onclick = function () {
$ny = $ny >= 0 ? $ny + 1 : 1;
if ($ny % 5 == 0) $d.yI.focus();
c_y($dt.y + 1)
}
}
function A() {
var $ = event,
_ = ($.which == undefined) ? $.keyCode : $.which;
if (!$OPERA && !((_ >= 48 && _ <= 57) || (_ >= 96 && _ <= 105) || _ == 8 || _ == 46 || _ == 37 || _ == 39 || _ == 9)) $.returnValue = false;
$lastInput = $.srcElement
}
}
My97DP.prototype = {
init: function () {
$ny = 0;
$dp.cal = this;
if ($dp.readOnly && $dp.el.readOnly != null) {
$dp.el.readOnly = true;
$dp.el.blur()
}
$();
this.dateFmt = $dp.dateFmt;
this._dealFmt();
this.autoPickDate = $dp.autoPickDate || (($dp.has.st) ? false : true);
$tdt = this.tdate = new DPDate();
this.ddateRe = this._initRe("disabledDates");
this.ddayRe = this._initRe("disabledDays");
this.loadDate();
this.minDate = this.doCustomDate($dp.minDate, $dp.minDate != $dp.defMinDate ? $dp.realFmt : $dp.realFullFmt, $dp.defMinDate);
this.maxDate = this.doCustomDate($dp.maxDate, $dp.maxDate != $dp.defMaxDate ? $dp.realFmt : $dp.realFullFmt, $dp.defMaxDate);
if (this.minDate.compareWith(this.maxDate) > 0) $dp.errMsg = $lang.err_1;
this._makeDateInRange();
$sdt = this.sdate = new DPDate($dt.y, $dt.M, $dt.d, $dt.H, $dt.m, $dt.s);
if (!$dp.alwaysUseStartDate && $dp.el[$dp.elProp] != "") this.update();
this.oldValue = $dp.el[$dp.elProp];
setA($d.MI, "realValue", $dt.M);
$d.MI.value = $lang.aMonStr[$dt.M - 1];
$d.yI.value = $dt.y;
$d.HI.value = $dt.H;
$d.mI.value = $dt.m;
$d.sI.value = $dt.s;
$d.timeSpan.innerHTML = $lang.timeStr;
$d.clearI.value = $lang.clearStr;
$d.todayI.value = $lang.todayStr;
$d.okI.value = $lang.okStr;
this.initShowAndHide();
this.initBtn();
if ($dp.errMsg) alert($dp.errMsg);
this.redraw();
hideSel();
if ($dp.el.nodeType == 1) $dp.attachEvent($dp.el, "onkeydown",
function ($) {
if ($dp.dd.style.display != "none") {
k = ($.which == undefined) ? $.keyCode : $.which;
if (k == 9) {
if ($dp.el[$dp.elProp] != "") $c.update();
hide($dp.dd)
}
}
});
function $() {
var _, $;
for (_ = 0; ($ = document.getElementsByTagName("link")[_]); _++) if (getA($, "rel").indexOf("style") != -1 && getA($, "title")) {
$.disabled = true;
if (getA($, "title") == $dp.skin) $.disabled = false
}
}
},
splitDate: function (J, C, O, E, B, G, F, K, L) {
var $;
if (J && J.loadDate) $ = J;
else {
$ = new DPDate();
C = C || $dp.dateFmt;
var H, N = 0,
A = /yyyy|yyy|yy|y|MM|M|dd|d|HH|H|mm|m|ss|s/g,
M = J.split(/\W+/),
_ = C.match(A);
A.lastIndex = 0;
if (!L && M.length != _.length) {
var D = 0,
K = "^";
while ((M = A.exec(C)) !== null) {
D = M.index - D;
K += (D == 0) ? "" : (".{" + D + "}");
D = A.lastIndex;
switch (M[0]) {
case "yyyy":
K += "(\\d{4})";
break;
case "yyy":
K += "(\\d{3})";
break;
default:
K += "(\\d\\d?)";
break
}
}
K += ".*$";
M = new RegExp(K).exec(J);
N = 1
}
if (M) for (H = 0; H < _.length; H++) {
var I = M[H + N];
if (I) switch (_[H]) {
case "y":
case "yy":
I = pIntDef(I, 0);
if (I < 50) I += 2000;
else I += 1900;
$.y = I;
break;
case "yyy":
$.y = pIntDef(I, 0) + $dp.yearOffset;
break;
default:
$[_[H].slice(- 1)] = I;
break
}
}
}
$.coverDate(O, E, B, G, F, K);
return $
},
_initRe: function (_) {
var B, $ = $dp[_],
A = "(?:";
if ($) {
for (B = 0; B < $.length; B++) {
A += this.doExp($[B]);
if (B != $.length - 1) A += "|"
}
A = new RegExp(A + ")")
} else A = null;
return A
},
update: function () {
$dp.el[$dp.elProp] = this.getDateStr();
this.setRealValue()
},
setRealValue: function ($) {
var _ = $dp.$($dp.vel),
$ = rtn($, this.getDateStr($dp.realFmt));
if (_) _.value = $;
setA($dp.el, "realValue", $)
},
doExp: function (s) {
var ps = "yMdHms",
arr, tmpEval, re = /#\{(.*?)\}/;
s = s + "";
for (var i = 0; i < ps.length; i++) s = s.replace("%" + ps.charAt(i), this.getP(ps.charAt(i), null, $tdt));
if (s.substring(0, 3) == "#F{") {
s = s.substring(3, s.length - 1);
if (s.indexOf("return ") < 0) s = "return " + s;
s = $dp.win.eval("new Function(\"" + s + "\");");
s = s()
} else while ((arr = re.exec(s)) != null) {
arr.lastIndex = arr.index + arr[1].length + 2;
tmpEval = pInt(eval(arr[1]));
if (tmpEval < 0) tmpEval = "9700" + (- tmpEval);
s = s.substring(0, arr.index) + tmpEval + s.substring(arr.lastIndex + 1)
}
return s
},
doCustomDate: function (A, B, _) {
var $;
A = this.doExp(A);
if (!A || A == "") A = _;
if (typeof A == "object") $ = A;
else {
$ = this.splitDate(A, B, null, null, 1, 0, 0, 0, true);
$.y = ("" + $.y).replace(/^9700/, "-");
$.M = ("" + $.M).replace(/^9700/, "-");
$.d = ("" + $.d).replace(/^9700/, "-");
$.H = ("" + $.H).replace(/^9700/, "-");
$.m = ("" + $.m).replace(/^9700/, "-");
$.s = ("" + $.s).replace(/^9700/, "-");
if (A.indexOf("%ld") >= 0) {
A = A.replace(/%ld/g, "0");
$.d = 0;
$.M = pInt($.M) + 1
}
$.refresh()
}
return $
},
loadDate: function () {
var _, $;
if ($dp.alwaysUseStartDate || ($dp.startDate != "" && $dp.el[$dp.elProp] == "")) {
_ = this.doExp($dp.startDate);
$ = $dp.realFmt
} else {
_ = $dp.el[$dp.elProp];
$ = this.dateFmt
}
$dt.loadFromDate(this.splitDate(_, $));
if ($dp.has.sd && !this.isDate($dt)) {
$dt.y = $tdt.y;
$dt.M = $tdt.M;
$dt.d = $tdt.d
}
if ($dp.has.st && !this.isTime($dt)) {
$dt.H = $tdt.H;
$dt.m = $tdt.m;
$dt.s = $tdt.s
}
},
isDate: function ($) {
if ($.y != null) $ = doStr($.y, 4) + "-" + $.M + "-" + $.d;
return $.match(/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/)
},
isTime: function ($) {
if ($.H != null) $ = $.H + ":" + $.m + ":" + $.s;
return $.match(/^([0-9]|([0-1][0-9])|([2][0-3])):([0-9]|([0-5][0-9])):([0-9]|([0-5][0-9]))$/)
},
_makeDateInRange: function () {
var _ = this.checkRange(),
A = true;
if (_ != 0) {
A = false;
var $;
if (_ > 0) $ = this.maxDate;
else $ = this.minDate;
if ($dp.has.sd) {
$dt.y = $.y;
$dt.M = $.M;
$dt.d = $.d
}
if ($dp.has.st) {
$dt.H = $.H;
$dt.m = $.m;
$dt.s = $.s
}
}
return A
},
checkRange: function (A, $) {
$ = $ || $dt;
var _ = $.compareWith(this.minDate, A);
if (_ > 0) {
_ = $.compareWith(this.maxDate, A);
if (_ < 0) _ = 0
}
return _
},
checkValid: function ($, A, B) {
A = A || $dp.has.minUnit;
var _ = this.checkRange(A, $);
if (_ == 0) {
if (A == "d" && B == null) B = new Date($.y, $.M - 1, $.d).getDay();
_ = !this.testDay(B) && !this.testDate($)
} else _ = false;
return _
},
_fd: function () {
var F, D, E, L, H = new sb(),
G,
A,
I,
C,
K = "",
$ = "",
_ = new DPDate($dt.y, $dt.M, $dt.d, 0, 0, 0),
J = _.y,
B = _.M;
G = new Date(J, B - 1, 1).getDay();
A = 1 - G;
I = new Date(J, B, 0).getDay();
C = new Date(J, B, 0).getDate();
H.a("
");
H.a("
");
F = $dp.isShowWeek ? 0 : 1;
while (F < 8) H.a("
" + $lang.aWeekStr[F++] + "
");
H.a("
");
for (F = 1, D = A; F < 7; F++) {
H.a("
");
for (E = 0; E < 7; E++) {
_.loadDate(J, B, D++);
_.refresh();
if (_.M == B) {
L = true;
if (_.compareWith($sdt, "d") == 0) K = "Wselday";
else if (_.compareWith($tdt, "d") == 0) K = "Wtoday";
else K = (($dp.highLineWeekDay && (E == 0 || E == 6)) ? "Wwday" : "Wday");
$ = (($dp.highLineWeekDay && (E == 0 || E == 6)) ? "WwdayOn" : "WdayOn")
} else if ($dp.isShowOthers) {
L = true;
K = "WotherDay";
$ = "WotherDayOn"
} else L = false;
if ($dp.isShowWeek && E == 0 && (F < 4 || L)) H.a("
" + getWeek(_) + "
");
H.a("
" + _.d + "
")
} else H.a(">")
}
H.a("
")
}
H.a("
");
return H.j()
},
testDate: function (_) {
var $ = this.ddateRe && this.ddateRe.test(this.getDateStr($dp.realFmt, _));
if ($dp.disabledDates && $dp.opposite) $ = !$;
return $
},
testDay: function (_) {
var $ = this.ddayRe && this.ddayRe.test(_);
if ($dp.disabledDays && $dp.opposite) $ = !$;
return $
},
_f: function (p, c, r, e) {
var s = new sb();
bak = $dt[p];
s.a("