/** @name : laydate v1.1 日期控件 @author: 贤心 @date: 2014-06-25 @site:http://www.sucaijiayuan.com */ ;!function(a) { var b = { path: "", defskin: "default", format: "yyyy-mm-dd", min: "1900-01-01 00:00:00", max: "2099-12-31 23:59:59", isv: !1 }, c = {}, d = document, e = "createelement", f = "getelementbyid", g = "getelementsbytagname", h = ["laydate_box", "laydate_void", "laydate_click", "laydateskin", "skins/", "/laydate.css"]; a.laydate = function(b) { b = b || {}; try { a.event = a.event || laydate.caller.arguments[0] } catch (d) {} return a.event && (b.tagname = 1), c.run(b), laydate }, laydate.v = "1.1", c.getpath = function() { var a = document.scripts, c = a[a.length - 1].src; return b.path ? b.path : c.substring(0, c.lastindexof("/") + 1) }(), c.use = function(a, b) { var f = d[e]("link"); f.type = "text/css", f.rel = "stylesheet", f.href = c.getpath + a + h[5], b && (f.id = b), d[g]("head")[0].appendchild(f), f = null }, c.trim = function(a) { return a = a || "", a.replace(/^\s|\s$/g, "").replace(/\s+/g, " ") }, c.digit = function(a) { return 10 > a ? "0" + (0 | a) : a }, c.stopmp = function(b) { return b = b || a.event, b.stoppropagation ? b.stoppropagation() : b.cancelbubble = !0, this }, c.each = function(a, b) { for (var c = 0, d = a.length; d > c && b(c, a[c]) !== !1; c++); }, c.hasclass = function(a, b) { return a = a || {}, new regexp("\\b" + b + "\\b").test(a.classname) }, c.addclass = function(a, b) { return a = a || {}, c.hasclass(a, b) || (a.classname += " " + b), a.classname = c.trim(a.classname), this }, c.removeclass = function(a, b) { if (a = a || {}, c.hasclass(a, b)) { var d = new regexp("\\b" + b + "\\b"); a.classname = a.classname.replace(d, "") } return this }, c.removecssattr = function(a, b) { var c = a.style; c.removeproperty ? c.removeproperty(b) : c.removeattribute(b) }, c.shde = function(a, b) { a.style.display = b ? "none" : "block" }, c.query = function(a) { var e, b, h, i, j; return a = c.trim(a).split(" "), b = d[f](a[0].substr(1)), b ? a[1] ? /^\./.test(a[1]) ? (i = a[1].substr(1), j = new regexp("\\b" + i + "\\b"), e = [], h = d.getelementsbyclassname ? b.getelementsbyclassname(i) : b[g]("*"), c.each(h, function(a, b) { j.test(b.classname) && e.push(b) }), e[0] ? e : "") : (e = b[g](a[1]), e[0] ? b[g](a[1]) : "") : b : void 0 }, c.on = function(b, d, e) { return b.attachevent ? b.attachevent("on" + d, function() { e.call(b, a.even) }) : b.addeventlistener(d, e, !1), c }, c.stopmosup = function(a, b) { "mouseup" !== a && c.on(b, "mouseup", function(a) { c.stopmp(a) }) }, c.run = function(a) { var d, e, b = c.query; if (a.tagname) { if (d = a.elem ? b(a.elem) : event.target || event.srcelement, !d || d === c.elem) return; c.view(d, a), c.stopmosup(event.type, d), c.reshow() } else { if (d = b(a.elem), !d) return; e = a.event || "click", c.each((0 | d.length) > 0 ? d : [d], function(b, d) { c.on(d, e, function(b) { c.stopmp(b), d !== c.elem && (c.view(d, a), c.reshow()) }), c.stopmosup(e, d) }) } }, c.scroll = function(a) { return a = a ? "scrollleft" : "scrolltop", d.body[a] | d.documentelement[a] }, c.winarea = function(a) { return document.documentelement[a ? "clientwidth" : "clientheight"] }, c.isleap = function(a) { return 0 === a % 4 && 0 !== a % 100 || 0 === a % 400 }, c.checkvoid = function(a, b, d) { var e = []; return a = 0 | a, b = 0 | b, d = 0 | d, a < c.mins[0] ? e = ["y"] : a > c.maxs[0] ? e = ["y", 1] : a >= c.mins[0] && a <= c.maxs[0] && (a == c.mins[0] && (b < c.mins[1] ? e = ["m"] : b == c.mins[1] && d < c.mins[2] && (e = ["d"])), a == c.maxs[0] && (b > c.maxs[1] ? e = ["m", 1] : b == c.maxs[1] && d > c.maxs[2] && (e = ["d", 1]))), e }, c.timevoid = function(a, b) { if (c.ymd[1] + 1 == c.mins[1] && c.ymd[2] == c.mins[2]) { if (0 === b && a < c.mins[3]) return 1; if (1 === b && a < c.mins[4]) return 1; if (2 === b && a < c.mins[5]) return 1 } else if (c.ymd[1] + 1 == c.maxs[1] && c.ymd[2] == c.maxs[2]) { if (0 === b && a > c.maxs[3]) return 1; if (1 === b && a > c.maxs[4]) return 1; if (2 === b && a > c.maxs[5]) return 1 } return a > (b ? 59 : 23) ? 1 : void 0 }, c.check = function() { var a = c.options.format.replace(/yyyy|mm|dd|hh|mm|ss/g, "\\d+\\").replace(/\\$/g, ""), b = new regexp(a), d = c.elem[h.elemv], e = d.match(/\d+/g) || [], f = c.checkvoid(e[0], e[1], e[2]); if ("" !== d.replace(/\s/g, "")) { if (!b.test(d)) return c.elem[h.elemv] = "", c.msg("日期不符合格式,请重新选择。"), 1; if (f[0]) return c.elem[h.elemv] = "", c.msg("日期不在有效期内,请重新选择。"), 1; f.value = c.elem[h.elemv].match(b).join(), e = f.value.match(/\d+/g), e[1] < 1 ? (e[1] = 1, f.auto = 1) : e[1] > 12 ? (e[1] = 12, f.auto = 1) : e[1].length < 2 && (f.auto = 1), e[2] < 1 ? (e[2] = 1, f.auto = 1) : e[2] > c.months[(0 | e[1]) - 1] ? (e[2] = 31, f.auto = 1) : e[2].length < 2 && (f.auto = 1), e.length > 3 && (c.timevoid(e[3], 0) && (f.auto = 1), c.timevoid(e[4], 1) && (f.auto = 1), c.timevoid(e[5], 2) && (f.auto = 1)), f.auto ? c.creation([e[0], 0 | e[1], 0 | e[2]], 1) : f.value !== c.elem[h.elemv] && (c.elem[h.elemv] = f.value) } }, c.months = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], c.viewdate = function(a, b, d) { var f = (c.query, {}), g = new date; a < (0 | c.mins[0]) && (a = 0 | c.mins[0]), a > (0 | c.maxs[0]) && (a = 0 | c.maxs[0]), g.setfullyear(a, b, d), f.ymd = [g.getfullyear(), g.getmonth(), g.getdate()], c.months[1] = c.isleap(f.ymd[0]) ? 29 : 28, g.setfullyear(f.ymd[0], f.ymd[1], 1), f.fday = g.getday(), f.pday = c.months[0 === b ? 11 : b - 1] - f.fday + 1, f.nday = 1, c.each(h.tds, function(a, b) { var g, d = f.ymd[0], e = f.ymd[1] + 1; b.classname = "", a < f.fday ? (b.innerhtml = g = a + f.pday, c.addclass(b, "laydate_nothis"), 1 === e && (d -= 1), e = 1 === e ? 12 : e - 1) : a >= f.fday && a < f.fday + c.months[f.ymd[1]] ? (b.innerhtml = g = a - f.fday + 1, a - f.fday + 1 === f.ymd[2] && (c.addclass(b, h[2]), f.thisday = b)) : (b.innerhtml = g = f.nday++, c.addclass(b, "laydate_nothis"), 12 === e && (d += 1), e = 12 === e ? 1 : e + 1), c.checkvoid(d, e, g)[0] && c.addclass(b, h[1]), c.options.festival && c.festival(b, e + "." + g), b.setattribute("y", d), b.setattribute("m", e), b.setattribute("d", g), d = e = g = null }), c.valid = !c.hasclass(f.thisday, h[1]), c.ymd = f.ymd, h.year.value = c.ymd[0] + "年", h.month.value = c.digit(c.ymd[1] + 1) + "月", c.each(h.mms, function(a, b) { var d = c.checkvoid(c.ymd[0], (0 | b.getattribute("m")) + 1); "y" === d[0] || "m" === d[0] ? c.addclass(b, h[1]) : c.removeclass(b, h[1]), c.removeclass(b, h[2]), d = null }), c.addclass(h.mms[c.ymd[1]], h[2]), f.times = [0 | c.inymd[3] || 0, 0 | c.inymd[4] || 0, 0 | c.inymd[5] || 0], c.each(new array(3), function(a) { c.hmsin[a].value = c.digit(c.timevoid(f.times[a], a) ? 0 | c.mins[a + 3] : 0 | f.times[a]) }), c[c.valid ? "removeclass" : "addclass"](h.ok, h[1]) }, c.festival = function(a, b) { var c; switch (b) { case "1.1": c = "元旦"; break; case "3.8": c = "妇女"; break; case "4.5": c = "清明"; break; case "5.1": c = "劳动"; break; case "6.1": c = "儿童"; break; case "9.10": c = "教师"; break; case "10.1": c = "国庆" } c && (a.innerhtml = c), c = null }, c.viewyears = function(a) { var b = c.query, d = ""; c.each(new array(14), function(b) { d += 7 === b ? "
  • ' + a + "年
  • " : '
  • ' + (a - 7 + b) + "年
  • " }), b("#laydate_ys").innerhtml = d, c.each(b("#laydate_ys li"), function(a, b) { "y" === c.checkvoid(b.getattribute("y"))[0] ? c.addclass(b, h[1]) : c.on(b, "click", function(a) { c.stopmp(a).reshow(), c.viewdate(0 | this.getattribute("y"), c.ymd[1], c.ymd[2]) }) }) }, c.initdate = function() { var d = (c.query, new date), e = c.elem[h.elemv].match(/\d+/g) || []; e.length < 3 && (e = c.options.start.match(/\d+/g) || [], e.length < 3 && (e = [d.getfullyear(), d.getmonth() + 1, d.getdate()])), c.inymd = e, c.viewdate(e[0], e[1] - 1, e[2]) }, c.iswrite = function() { var a = c.query, b = { time: a("#laydate_hms") }; c.shde(b.time, !c.options.istime), c.shde(h.oclear, !("isclear" in c.options ? c.options.isclear : 1)), c.shde(h.otoday, !("istoday" in c.options ? c.options.istoday : 1)), c.shde(h.ok, !("issure" in c.options ? c.options.issure : 1)) }, c.orien = function(a, b) { var d, e = c.elem.getboundingclientrect(); a.style.left = e.left + (b ? 0 : c.scroll(1)) + "px", d = e.bottom + a.offsetheight / 1.5 <= c.winarea() ? e.bottom - 1 : e.top > a.offsetheight / 1.5 ? e.top - a.offsetheight + 1 : c.winarea() - a.offsetheight, a.style.top = d + (b ? 0 : c.scroll()) + "px" }, c.follow = function(a) { c.options.fixed ? (a.style.position = "fixed", c.orien(a, 1)) : (a.style.position = "absolute", c.orien(a)) }, c.viewtb = function() { var a, b = [], f = ["日", "一", "二", "三", "四", "五", "六"], h = {}, i = d[e]("table"), j = d[e]("thead"); return j.appendchild(d[e]("tr")), h.creath = function(a) { var b = d[e]("th"); b.innerhtml = f[a], j[g]("tr")[0].appendchild(b), b = null }, c.each(new array(6), function(d) { b.push([]), a = i.insertrow(0), c.each(new array(7), function(c) { b[d][c] = 0, 0 === d && h.creath(c), a.insertcell(c) }) }), i.insertbefore(j, i.children[0]), i.id = i.classname = "laydate_table", a = b = null, i.outerhtml.tolowercase() }(), c.view = function(a, f) { var i, g = c.query, j = {}; f = f || a, c.elem = a, c.options = f, c.options.format || (c.options.format = b.format), c.options.start = c.options.start || "", c.mm = j.mm = [c.options.min || b.min, c.options.max || b.max], c.mins = j.mm[0].match(/\d+/g), c.maxs = j.mm[1].match(/\d+/g), h.elemv = /textarea|input/.test(c.elem.tagname.tolocalelowercase()) ? "value" : "innerhtml", c.box ? c.shde(c.box) : (i = d[e]("div"), i.id = h[0], i.classname = h[0], i.style.csstext = "position: absolute;", i.setattribute("name", "laydate-v" + laydate.v), i.innerhtml = j.html = '
      ' + function() { var a = ""; return c.each(new array(12), function(b) { a += '' + c.digit(b + 1) + "月" }), a }() + "
      " + "
      " + "
      " + c.viewtb + '
      ' + '" + '
      ' + '
      ' + '清空' + '今天' + '确认' + "
      " + (b.isv ? 'laydate-v' + laydate.v + "" : "") + "
      ", d.body.appendchild(i), c.box = g("#" + h[0]), c.events(), i = null), c.follow(c.box), f.zindex ? c.box.style.zindex = f.zindex : c.removecssattr(c.box, "z-index"), c.stopmosup("click", c.box), c.initdate(), c.iswrite(), c.check() }, c.reshow = function() { return c.each(c.query("#" + h[0] + " .laydate_show"), function(a, b) { c.removeclass(b, "laydate_show") }), this }, c.close = function() { c.reshow(), c.shde(c.query("#" + h[0]), 1), c.elem = null }, c.parse = function(a, d, e) { return a = a.concat(d), e = e || (c.options ? c.options.format : b.format), e.replace(/yyyy|mm|dd|hh|mm|ss/g, function() { return a.index = 0 | ++a.index, c.digit(a[a.index]) }) }, c.creation = function(a, b) { var e = (c.query, c.hmsin), f = c.parse(a, [e[0].value, e[1].value, e[2].value]); c.elem[h.elemv] = f, b || (c.close(), "function" == typeof c.options.choose && c.options.choose(f)) }, c.events = function() { var b = c.query, e = { box: "#" + h[0] }; c.addclass(d.body, "laydate_body"), h.tds = b("#laydate_table td"), h.mms = b("#laydate_ms span"), h.year = b("#laydate_y"), h.month = b("#laydate_m"), c.each(b(e.box + " .laydate_ym"), function(a, b) { c.on(b, "click", function(b) { c.stopmp(b).reshow(), c.addclass(this[g]("div")[0], "laydate_show"), a || (e.yy = parseint(h.year.value), c.viewyears(e.yy)) }) }), c.on(b(e.box), "click", function() { c.reshow() }), e.tabyear = function(a) { 0 === a ? c.ymd[0]-- : 1 === a ? c.ymd[0]++ : 2 === a ? e.yy -= 14 : e.yy += 14, 2 > a ? (c.viewdate(c.ymd[0], c.ymd[1], c.ymd[2]), c.reshow()) : c.viewyears(e.yy) }, c.each(b("#laydate_yy .laydate_tab"), function(a, b) { c.on(b, "click", function(b) { c.stopmp(b), e.tabyear(a) }) }), e.tabmonth = function(a) { a ? (c.ymd[1]++, 12 === c.ymd[1] && (c.ymd[0]++, c.ymd[1] = 0)) : (c.ymd[1]--, -1 === c.ymd[1] && (c.ymd[0]--, c.ymd[1] = 11)), c.viewdate(c.ymd[0], c.ymd[1], c.ymd[2]) }, c.each(b("#laydate_mm .laydate_tab"), function(a, b) { c.on(b, "click", function(b) { c.stopmp(b).reshow(), e.tabmonth(a) }) }), c.each(b("#laydate_ms span"), function(a, b) { c.on(b, "click", function(a) { c.stopmp(a).reshow(), c.hasclass(this, h[1]) || c.viewdate(c.ymd[0], 0 | this.getattribute("m"), c.ymd[2]) }) }), c.each(b("#laydate_table td"), function(a, b) { c.on(b, "click", function(a) { c.hasclass(this, h[1]) || (c.stopmp(a), c.creation([0 | this.getattribute("y"), 0 | this.getattribute("m"), 0 | this.getattribute("d")])) }) }), h.oclear = b("#laydate_clear"), c.on(h.oclear, "click", function() { c.elem[h.elemv] = "", c.close() }), h.otoday = b("#laydate_today"), c.on(h.otoday, "click", function() { c.elem[h.elemv] = laydate.now(0, c.options.format), c.close() }), h.ok = b("#laydate_ok"), c.on(h.ok, "click", function() { c.valid && c.creation([c.ymd[0], c.ymd[1] + 1, c.ymd[2]]) }), e.times = b("#laydate_time"), c.hmsin = e.hmsin = b("#laydate_hms input"), e.hmss = ["小时", "分钟", "秒数"], e.hmsarr = [], c.msg = function(a, d) { var f = '
      ' + (d || "提示") + "×
      "; "string" == typeof a ? (f += "

      " + a + "

      ", c.shde(b("#" + h[0])), c.removeclass(e.times, "laydate_time1").addclass(e.times, "laydate_msg")) : (e.hmsarr[a] ? f = e.hmsarr[a] : (f += '
      ', c.each(new array(0 === a ? 24 : 60), function(a) { f += "" + a + "" }), f += "
      ", e.hmsarr[a] = f), c.removeclass(e.times, "laydate_msg"), c[0 === a ? "removeclass" : "addclass"](e.times, "laydate_time1")), c.addclass(e.times, "laydate_show"), e.times.innerhtml = f }, e.hmson = function(a, d) { var e = b("#laydate_hmsno span"), f = c.valid ? null : 1; c.each(e, function(b, e) { f ? c.addclass(e, h[1]) : c.timevoid(b, d) ? c.addclass(e, h[1]) : c.on(e, "click", function() { c.hasclass(this, h[1]) || (a.value = c.digit(0 | this.innerhtml)) }) }), c.addclass(e[0 | a.value], "laydate_click") }, c.each(e.hmsin, function(a, b) { c.on(b, "click", function(b) { c.stopmp(b).reshow(), c.msg(a, e.hmss[a]), e.hmson(this, a) }) }), c.on(d, "mouseup", function() { var a = b("#" + h[0]); a && "none" !== a.style.display && (c.check() || c.close()) }).on(d, "keydown", function(b) { b = b || a.event; var d = b.keycode; 13 === d && c.creation([c.ymd[0], c.ymd[1] + 1, c.ymd[2]]) }) }, c.init = function() { c.use("need"), c.use(h[4] + b.defskin, h[3]), c.skinlink = c.query("#" + h[3]) }(), laydate.reset = function() { c.box && c.elem && c.follow(c.box) }, laydate.now = function(a, b) { var d = new date(0 | a ? function(a) { return 864e5 > a ? +new date + 864e5 * a : a }(parseint(a)) : +new date); return c.parse([d.getfullyear(), d.getmonth() + 1, d.getdate()], [d.gethours(), d.getminutes(), d.getseconds()], b) }, laydate.skin = function(a) { c.skinlink.href = c.getpath + h[4] + a + h[5] } }(window);