(function (e) { var t = window.qtool || {}; window.qtool || (t.WINM = t.winbox = function (e, n) { return new t.winbox.fn.init(e, n) }, t.winbox.close = function (e) { this.fn.close(e) }), t.winbox.closeTmp = function (e) { this.fn.close(e) }, t.xdomain = t.xdomain || function () { function v(e, n) { r || o(); if (typeof e == "object") for (t in e) n || p(t), h(t, e[t]); else typeof e == "function" && (t = "xdomainDefaultKey", h(t, e)) } function m(e, t, n) { var r = ""; n ? r = n + "||" + t : r = t, window.postMessage ? e.postMessage(r, "*") : e.name = r } var t = "", n = "", r = !1, i = 0, s = 0, o = function () {}, u = [], a = function () {}, f = function () {}, l = function (e) {}, c = {}, h = function (e, t) {}, p = function (e) {}, d = function (e) { l(e.data) }; return o = function () { r = !0, u = [], c = {}, window.postMessage ? window.addEventListener ? (window.removeEventListener("message", d, !1), window.addEventListener("message", d, !1)) : window.attachEvent && (window.detachEvent("onmessage", d), window.attachEvent("onmessage", d)) : (window.name = "", i && clearTimeout(i), i = setTimeout(function () { a() }, 0), s && clearTimeout(s), s = setTimeout(function () { f() }, 0)) }, a = function () { window.name !== "" && (u.push(window.name), window.name = ""), i = setTimeout(function () { a() }, 100) }, f = function () { u.length && l(u.shift()), s = setTimeout(function () { f() }, 100) }, l = function (t) { var n = t.split("||"), r = "", i = ""; n[1] ? (r = n[0], i = n[1]) : (r = "xdomainDefaultKey", i = n[0]), c[r] && e.each(c[r], function (e, t) { t(i) }) }, h = function (e, t) { c[e] ? c[e].push(t) : c[e] = [t] }, p = function (e) { delete c[e] }, { init: o, listen: v, sendMessage: m } } (), t.WM = t.wbox = function (e, n) { return new t.wbox.fn.init(e, n) }, t.wbox.close = function () { this.fn.common.close() }, t.wbox.showMessage = t.wbox.showDialog = function (e, n) { if (!e) return !1; n = n || {}; var r = { style: {} }, i = n.iconcls; for (var s in n) s == "width" || s == "height" || s == "top" || s == "left" ? r.style[s] = n[s] : s == "func" ? r.onconfirm = n[s] : r[s] = n[s]; return i ? t.wbox.fn.init(e, r).showDialog(i).dom : t.wbox.fn.init(e, r).showMessage().dom }, e.extend(!0, t.winbox.fn = t.winbox.prototype, { version: 1, window_stack: [], lastClosedBox: [], LEVEL: 9999, IFRAME_MASK: e(''), DIV_MASK: e('
'), MASK_ID_PREFIX: "_mask_", BOX_ID_PREFIX: "_message_box_", getMask: function (t) { var n = this.DIV_MASK, r = this.IFRAME_MASK; return n.css({ opacity: .4 }), e.support.msie && e.support.version < 8 && n.html("").append(r.css("opacity", 0)), !!t && n.appendTo(document.body).show(), n }, resizeMask: function () { var e = navigator.userAgent.toString().indexOf("Chrome") == -1 ? document.documentElement : document.body, t = e.scrollHeight > e.clientHeight ? e.scrollHeight : e.clientHeight, n = e.scrollWidth > e.clientWidth ? e.scrollWidth : e.clientWidth; this.getMask().css({ height: t, width: n }) }, getLevel: function (e, t) { return (e && String(e) || "") + (this.LEVEL += 1) + (t && String(t) || "") }, positionBox: function (t, n) { var r, i; if (!t) return !1; n = n || e(t).data("pos_setting") || {}, r = n.left || (e(window).width() - t.width()) / 2, // i = n.top || (e(window).height() - t.height()) / 2 + e(window).scrollTop(), i = n.top || 0, e(t).css({ top: i, left: r, bottom: 0, margin: 'auto' }).data("pos_setting", n) }, reposBox: function (e) { var t = this; e = e || t.window_stack.length - 1, e > -1 && t.positionBox(t.window_stack[e].find("[id^=" + t.BOX_ID_PREFIX + "]")) }, createBox: function (n) { var r, i, s, o; if (typeof this.options == "object") { e.extend(!0, n, this.options); for (var u in n) this[u] = n[u] } return o = this.style, i = this.replacement || {}, r = e('
').append(this.getMask()).css("z-index", this.getLevel()).append(this.dom = s = e(t.template(this.tpl, i)).css(o).attr("id", this.getLevel(t.winbox.fn.BOX_ID_PREFIX))).appendTo(document.body), this.resizeMask(), this.positionBox(s.css("zIndex", "100"), o), this.window_stack.push(r), this }, bindBox: function (e) { var t = this, n = "cancel", r = "confirm"; e.on("click", "." + n, function () { return t.close(), t.oncancel(), !1 }), e.on("click", "." + r, function () { return t.close(), t.onconfirm(), !1 }) }, close: function (t) { var n = this, r = typeof t == "number" ? t : 1, i; for (var s = 0; s < r; s++) n.lastClosedBox.push(e(n.window_stack.pop()).remove()), (i = n.window_stack.length - 1) > -1 && n.positionBox(n.window_stack[i].append(n.getMask()).find("[id^=" + n.BOX_ID_PREFIX + "]")) }, init: function (t, n) { if (t === undefined) return this; if (typeof t == "string") return this.options = n || {}, this.tpl = t, this.showMessage = function () { var t = { oncancel: function () { return e.noop, !1 }, onconfirm: function () { return e.noop, !1 }, bodyid: this.getLevel("msg"), style: { position: "fixed" } }; return this.createBox.call(this, t), this.bindBox.call(this, this.dom), this }, this } }), t.winbox.fn.init.prototype = t.winbox.fn, t.wbox.fn = t.wbox.prototype = { version: .5, common: { window_stack: [], lastClosedBox: [], LEVEL: 9999, IFRAME_MASK: e(''), DIV_MASK: e('
'), MASK_ID_PREFIX: "_mask_", BOX_ID_PREFIX: "_message_box_", getMask: function (t) { var n = this.DIV_MASK, r = this.IFRAME_MASK; return n.css({ opacity: .4 }), e.support.msie && e.support.version < 8 && n.html("").append(r.css("opacity", 0)), !!t && n.appendTo(document.body).show(), n }, getLevel: function (e, t) { return (e && String(e) || "") + (this.LEVEL += 1) + (t && String(t) || "") }, resizeMask: function () { var e = document.documentElement, t = e.scrollHeight > e.clientHeight ? e.scrollHeight : e.clientHeight, n = e.scrollWidth > e.clientWidth ? e.scrollWidth : e.clientWidth; this.getMask().css({ height: t, width: n }) }, reposBox: function (e) { var t = this; (e = t.window_stack.length - 1) > -1 && t.positionBox(t.window_stack[e].find("[id^=" + t.BOX_ID_PREFIX + "]")) }, positionBox: function (t, n) { var r, i; if (!t) return !1; n = n || e(t).data("pos_setting") || {}, r = n.left || (e(window).width() - t.width()) / 2, // i = n.top || (e(window).height() - t.height()) / 2 + e(window).scrollTop(), i = n.top || 0, e(t).css({ top: i, left: r, bottom: 0, margin: 'auto' }).data("pos_setting", n) }, close: function (t) { var n = this, r = typeof t == "number" ? t : 1, i; for (var s = 0; s < r; s++) n.lastClosedBox.push(e(n.window_stack.pop()).remove()), (i = n.window_stack.length - 1) > -1 && n.positionBox(n.window_stack[i].append(n.getMask()).find("[id^=" + n.BOX_ID_PREFIX + "]")) }, createBox: function (n) { var r, i, s, o; if (typeof this.options == "object") { e.extend(!0, n, this.options); for (var u in n) this[u] = n[u]; this.dom = n.tpl_top + n.tpl_content + n.tpl_bottom } return o = this.style, this.iconcls ? i = [this.dom, { iconcls: this.iconcls, bodyid: this.bodyid } ] : i = [this.dom, { bodyid: this.bodyid } ], r = e('
').append(this.common.getMask()).css("z-index", this.common.getLevel()).append(this.dom = s = e(t.template.apply("", i)).css(o).attr("id", this.common.getLevel(t.wbox.BOX_ID_PREFIX))).appendTo(document.body), this.common.resizeMask(), r.find("#" + n.bodyid).html("").append(this.tpl), this.common.positionBox(s.css("zIndex", "100"), o), this.common.window_stack.push(r), this }, bindBox: function (e, t, n) { var r = this; t = t || "cancel", n = n || "confirm", e.on("click", "." + t, function () { return r.common.close(), r.oncancel(), !1 }), e.on("click", "." + n, function () { return r.common.close(), r.onconfirm(), !1 }) } }, init: function (t, n) { if (t === undefined) return this; if (typeof t == "string") return this.options = n || {}, this.tpl = t, this.showMessage = function () { var t = { tpl_top: '
', tpl_bottom: '
', tpl_content: '
', oncancel: function () { return e.noop, !1 }, onconfirm: function () { return e.noop, !1 }, bodyid: this.common.getLevel("msg"), style: { position: "absolute", height: "auto", width: "auto" } }; return this.common.createBox.call(this, t), this.common.bindBox.call(this, this.dom), this }, this.showDialog = function (t) { var n, r; switch (t) { case "suc": case "err": r = '\u786e\u5b9a'; break; case "remind": r = '\u786e\u5b9a\u53d6\u6d88'; break; default: r = "" } var i = { tpl_top: '
', tpl_bottom: '
', tpl_content: '
' + r + "
", oncancel: function () { return e.noop, !1 }, onconfirm: function () { return e.noop, !1 }, bodyid: this.common.getLevel("msg"), style: { height: "auto", width: "460px", height: "230px" } }; return this.iconcls = t, this.common.createBox.call(this, i), this.common.bindBox.call(this, this.dom), this }, this } }, t.wbox.fn.init.prototype = t.wbox.fn, e.extend(!0, t, { getQueryString: function (t) { var n = new RegExp("(^|&)" + t + "=([^&]*)(&|$)", "i"), r = window.location.search.substr(1).match(n); return r !== null ? unescape(r[2]) : null }, htmlEncode: function (e) { var t = document.createElement("div"), n = document.createTextNode(e); return t.appendChild(n), t.innerHTML }, htmlDecode: function (e) { var t = document.createElement("div"); return t.innerHTML = e, t.innerText || t.textContent }, subString: function (e, t) { return e.length <= t ? e : e.substr(0, t) + "..." }, setTextMaxLen: function (t, n) { n = e.extend({ maxlength: 0, onkeypress: function () {}, onkeydown: function () {}, onkeyup: function () {}, showlimit: function () {}, unchkkeys: /(8)|(13)|(16)|(17)|(18)/ }, n), t.each(function () { var t = e(this), r = n.maxlength || parseInt(t.attr("maxlength")); t.data("maxsize", r), t.off("keypress.restrict").on("keypress.restrict", function (e) { var r = e.keyCode || e.charCode, i = parseInt(t.val().length), s = t.data("maxsize"); if (!n.unchkkeys.test(r) && i >= s) return e.preventDefault && e.preventDefault(), !1; n.onkeypress.call(t, e), n.showlimit.call(t, s - i) }), t.off("keyup.restrict").on("keyup.restrict", function (e) { var r = t.val(), i = parseInt(r.length), s = t.data("maxsize"); if (i > s) { var o = r.substring(0, s); t.val(o), i = s } n.onkeyup.call(t, e), n.showlimit.call(t, s - i) }) }) }, locationhash: function (e) { return e ? (location.hash = e) && !1 : location.hash.replace("#", "") }, ns: function (t, n) { if (!t || !n) return; var r = String(t).split("."), i, s = window, o; if (r.length > 0) for (var u = 0; u < r.length; u++) o = r[u], s = !(o in s) && (s[o] = {}) || s[o], !u && (i = s); return e.isPlainObject(n) && e.extend(s, n), i }, template: function () { var t = Array.prototype.shift.call(arguments); return typeof arguments[0] == "object" && !e.isFunction(arguments[0]) ? e.each(arguments[0], function (e, n) { t = t.replace(new RegExp("{" + e + "}", "g"), this) }) && t.replace(/{.*?}/g, "") : e.each(arguments, function () { t = t.replace(/{.*?}/, this) }) && t.replace(/{.*?}/g, "") }, trim: e.trim, extend: function () { e.extend.apply(this, arguments) }, cursorPosition: { get: function (e) { e = e[0]; var t = { text: "", start: 0, end: 0 }; if (e.setSelectionRange) e.focus(), t.start = e.selectionStart, t.end = e.selectionEnd, t.text = t.start != t.end ? e.value.substring(t.start, t.end) : ""; else if (document.selection) { e.focus(); var n, r = document.selection.createRange(), i = document.body.createTextRange(); i.moveToElementText(e), t.text = r.text, t.bookmark = r.getBookmark(); for (n = 0; i.compareEndPoints("StartToStart", r) < 0 && r.moveStart("character", -1) !== 0; n++) e.value.charAt(n) == "\r" && n++; t.start = n, t.end = t.text.length + t.start } return t }, set: function (e, t) { e = e.nodeType ? e : e[0]; var n, r, i; t || alert("You must get cursor position first."), e.focus(), e.setSelectionRange ? e.setSelectionRange(t.start, t.end) : e.createTextRange && (n = e.createTextRange(), e.value.length === t.start ? (n.collapse(!1), n.select()) : (n.moveToBookmark(t.bookmark), n.select())) }, add: function (e, t, n) { e = e[0]; var r, i, s, o, u, a, f; this.set(e, t), e.setSelectionRange ? (r = e.value, i = r.substring(0, t.start) + n + r.substring(t.end), u = a = t.start + n.length, f = e.scrollTop, e.value = i, e.scrollTop != f && (e.scrollTop = f), e.setSelectionRange(u, a)) : e.createTextRange && (o = document.selection.createRange(), o.text = n, o.setEndPoint("StartToEnd", o), o.select()) } }, throttle: function (e, t) { var n = null; return function () { var r = this, i = arguments; clearTimeout(n), n = setTimeout(function () { e.apply(r, i) }, t) } } }); var n = window.qtool_wan || {}; e.extend(n, { beautify_wan: function (t, n, r) { if (!n) return this; t = t ? e(t) : e("body"); switch (n) { case "radio": case "checkbox": var i = "v3_comp_checkbox", s = "v3_comp_checkbox_on", o = "v3_comp_radio", u = "v3_comp_radio_on"; e(":" + n, t).each(function (t) { r = r || []; var a = e(this), f = r[t] || a.val() || ""; a.attr("checked") ? a.after('' + f + "") : a.after('' + f + ""), a.hide() }), e(":" + n + "+span", t).click(function () { var r = e(this), a = r.prev().attr("name"); n == "radio" && t.find("input:radio").filter('input[name="' + a + '"]').next().not(r).removeClass(u).addClass(o); if (!r.prev().is(":checked")) r.removeClass().addClass(n == "checkbox" ? s : u), r.prev()[0].checked = !0; else { if (n == "radio") return !1; r.removeClass().addClass(n == "checkbox" ? i : o), r.prev()[0].checked = !1 } return !1 }); break; case "select": e("select", t).each(function (t) { r = r || []; var n = e(this), i = r[t], s = i || n.find("option:selected").html() || n.find("option").eq(0).html(), o = e(this).find("option"), u = '
' + s + '
    '; e.each(o, function (t, r) { var s = e(r).html(), o = e(r).attr("value"); i == s && n.val(o), u += '
  • ' + s + "
  • " }), u += "
", n.hide().after(u) }), e("select+dl", t).on("click", "dt", function () { return e(this).siblings("dd").find("ul").toggle(), !1 }).on("click", "li", function () { var t = e(this), n = t.html(), r = t.attr("data-value"); return t.closest("dl").find("dt span em").html(n).end().prev().val(r), t.closest("dd").find("ul").hide(), !1 }); break; default: alert("invalid beautify type") } return this } }), e.extend(!0, t, { beautify: function (t, n, r) { if (!n) return this; t = t ? e(t) : e("body"); switch (n) { case "radio": case "checkbox": var i = "v3_comp_checkbox", s = "v3_comp_checkbox_on", o = "v3_comp_radio", u = "v3_comp_radio_on"; e(":" + n, t).each(function (t) { r = r || []; var a = e(this), f = r[t] || a.val() || ""; a.attr("checked") ? a.after('' + f + "") : a.after('' + f + ""), a.hide() }), e(":" + n + "+span", t).click(function () { var r = e(this), a = r.prev().attr("name"); n == "radio" && t.find("input:radio").filter('input[name="' + a + '"]').next().not(r).removeClass(u).addClass(o); if (!r.prev().is(":checked")) r.removeClass().addClass(n == "checkbox" ? s : u), r.prev()[0].checked = !0; else { if (n == "radio") return !1; r.removeClass().addClass(n == "checkbox" ? i : o), r.prev()[0].checked = !1 } return !1 }); break; case "select": e("select", t).each(function (t) { r = r || []; var n = e(this), i = r[t], s = i || n.find("option:selected").html() || n.find("option").eq(0).html(), o = e(this).find("option"), u = '
' + s + "
    "; e.each(o, function (t, r) { var s = e(r).html(), o = e(r).attr("value"); i == s && n.val(o), u += '
  • ' + s + "
  • " }), u += "
", n.hide().after(u) }), e("select+dl", t).on("click", "dt", function () { return e(this).siblings("dd").toggle(), !1 }).on("click", "li", function () { var t = e(this), n = t.html(), r = t.attr("data-value"); return t.closest("dl").find("dt span em").html(n).end().prev().val(r), t.closest("dd").hide(), !1 }); break; default: alert("invalid beautify type") } } }), e(window).bind("resize", function () { t.wbox.fn.common.resizeMask(), t.wbox.fn.common.reposBox(), t.winbox.fn.resizeMask(), t.winbox.fn.reposBox() }), e(window).bind("scroll", function () { t.throttle(function () { t.winbox.fn.resizeMask(), t.winbox.fn.reposBox() }, 200) }), window.qtool = window.QT = t, window.qtool_wan = n })(jQuery);