var Prototype = { Version: "1.4.0", ScriptFragment: "(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)", emptyFunction: function () { }, K: function (a) { return a } }, Class = { create: function () { return function () { this.initialize.apply(this, arguments) } } }, Abstract = {}; Object.extend = function (a, b) { for (property in b) { a[property] = b[property] } return a }; Object.inspect = function (a) { try { if (a == undefined) { return "undefined" } if (a == null) { return "null" } return a.inspect ? a.inspect() : a.toString() } catch (b) { if (b instanceof RangeError) { return "..." } throw b } }; Function.prototype.bind = function () { var a = this, b = $A(arguments), c = b.shift(); return function () { return a.apply(c, b.concat($A(arguments))) } }; Function.prototype.bindAsEventListener = function (a) { var b = this; return function (c) { return b.call(a, c || window.event) } }; Object.extend(Number.prototype, { toColorPart: function () { var a = this.toString(16); if (this < 16) { return "0" + a } return a }, succ: function () { return this + 1 }, times: function (a) { $R(0, this, true).each(a); return this } }); var Try = { these: function () { for (var a, b = 0; b < arguments.length; b++) { var c = arguments[b]; try { a = c(); break } catch (d) { } } return a } }, PeriodicalExecuter = Class.create(); PeriodicalExecuter.prototype = { initialize: function (a, b) { this.callback = a; this.frequency = b; this.currentlyExecuting = false; this.registerCallback() }, registerCallback: function () { setInterval(this.onTimerEvent.bind(this), this.frequency * 1E3) }, onTimerEvent: function () { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; this.callback() } finally { this.currentlyExecuting = false } } } }; function $() { for (var a = [], b = 0; b < arguments.length; b++) { var c = arguments[b]; if (typeof c == "string") { c = document.getElementById(c) } if (arguments.length == 1) { return c } a.push(c) } return a } Object.extend(String.prototype, { stripTags: function () { return this.replace(/<\/?[^>]+>/gi, "") }, stripScripts: function () { return this.replace(RegExp(Prototype.ScriptFragment, "img"), "") }, extractScripts: function () { var a = RegExp(Prototype.ScriptFragment, "im"); return (this.match(RegExp(Prototype.ScriptFragment, "img")) || []).map(function (b) { return (b.match(a) || ["", ""])[1] }) }, evalScripts: function () { return this.extractScripts().map(eval) }, escapeHTML: function () { var a = document.createElement("div"), b = document.createTextNode(this); a.appendChild(b); return a.innerHTML }, unescapeHTML: function () { var a = document.createElement("div"); a.innerHTML = this.stripTags(); return a.childNodes[0] ? a.childNodes[0].nodeValue : "" }, toQueryParams: function () { return this.match(/^\??(.*)$/)[1].split("&").inject({}, function (a, b) { var c = b.split("="); a[c[0]] = c[1]; return a }) }, toArray: function () { return this.split("") }, camelize: function () { var a = this.split("-"); if (a.length == 1) { return a[0] } for (var b = this.indexOf("-") == 0 ? a[0].charAt(0).toUpperCase() + a[0].substring(1) : a[0], c = 1, d = a.length; c < d; c++) { var e = a[c]; b += e.charAt(0).toUpperCase() + e.substring(1) } return b }, inspect: function () { return "'" + this.replace("\\", "\\\\").replace("'", "\\'") + "'" } }); String.prototype.parseQuery = String.prototype.toQueryParams; var $break = {}, $continue = {}, Enumerable = { each: function (a) { var b = 0; try { this._each(function (d) { try { a(d, b++) } catch (e) { if (e != $continue) { throw e } } }) } catch (c) { if (c != $break) { throw c } } }, all: function (a) { var b = true; this.each(function (c, d) { b = b && !!(a || Prototype.K)(c, d); if (!b) { throw $break } }); return b }, any: function (a) { var b = true; this.each(function (c, d) { if (b = !!(a || Prototype.K)(c, d)) { throw $break } }); return b }, collect: function (a) { var b = []; this.each(function (c, d) { b.push(a(c, d)) }); return b }, detect: function (a) { var b; this.each(function (c, d) { if (a(c, d)) { b = c; throw $break } }); return b }, findAll: function (a) { var b = []; this.each(function (c, d) { a(c, d) && b.push(c) }); return b }, grep: function (a, b) { var c = []; this.each(function (d, e) { if (d.toString().match(a)) { c.push((b || Prototype.K)(d, e)) } }); return c }, include: function (a) { var b = false; this.each(function (c) { if (c == a) { b = true; throw $break } }); return b }, inject: function (a, b) { this.each(function (c, d) { a = b(a, c, d) }); return a }, invoke: function (a) { var b = $A(arguments).slice(1); return this.collect(function (c) { return c[a].apply(c, b) }) }, max: function (a) { var b; this.each(function (c, d) { c = (a || Prototype.K)(c, d); if (c >= (b || c)) { b = c } }); return b }, min: function (a) { var b; this.each(function (c, d) { c = (a || Prototype.K)(c, d); if (c <= (b || c)) { b = c } }); return b }, partition: function (a) { var b = [], c = []; this.each(function (d, e) { ((a || Prototype.K)(d, e) ? b : c).push(d) }); return [b, c] }, pluck: function (a) { var b = []; this.each(function (c) { b.push(c[a]) }); return b }, reject: function (a) { var b = []; this.each(function (c, d) { a(c, d) || b.push(c) }); return b }, sortBy: function (a) { return this.collect(function (b, c) { return { value: b, criteria: a(b, c)} }).sort(function (b, c) { var d = b.criteria, e = c.criteria; return d < e ? -1 : d > e ? 1 : 0 }).pluck("value") }, toArray: function () { return this.collect(Prototype.K) }, zip: function () { var a = Prototype.K, b = $A(arguments); if (typeof b.last() == "function") { a = b.pop() } var c = [this].concat(b).map($A); return this.map(function (d, e) { a(d = c.pluck(e)); return d }) }, inspect: function () { return "#<Enumerable:" + this.toArray().inspect() + ">" } }; Object.extend(Enumerable, { map: Enumerable.collect, find: Enumerable.detect, select: Enumerable.findAll, member: Enumerable.include, entries: Enumerable.toArray }); var $A = Array.from = function (a) { if (!a) { return [] } if (a.toArray) { return a.toArray() } else { for (var b = [], c = 0; c < a.length; c++) { b.push(a[c]) } return b } }; Object.extend(Array.prototype, Enumerable); Array.prototype._reverse = Array.prototype.reverse; Object.extend(Array.prototype, { _each: function (a) { for (var b = 0; b < this.length; b++) { a(this[b]) } }, clear: function () { this.length = 0; return this }, first: function () { return this[0] }, last: function () { return this[this.length - 1] }, compact: function () { return this.select(function (a) { return a != undefined || a != null }) }, flatten: function () { return this.inject([], function (a, b) { return a.concat(b.constructor == Array ? b.flatten() : [b]) }) }, without: function () { var a = $A(arguments); return this.select(function (b) { return !a.include(b) }) }, indexOf: function (a) { for (var b = 0; b < this.length; b++) { if (this[b] == a) { return b } } return -1 }, reverse: function (a) { return (a !== false ? this : this.toArray())._reverse() }, shift: function () { for (var a = this[0], b = 0; b < this.length - 1; b++) { this[b] = this[b + 1] } this.length--; return a }, inspect: function () { return "[" + this.map(Object.inspect).join(", ") + "]" } }); var Hash = { _each: function (a) { for (key in this) { var b = this[key]; if (typeof b != "function") { var c = [key, b]; c.key = key; c.value = b; a(c) } } }, keys: function () { return this.pluck("key") }, values: function () { return this.pluck("value") }, merge: function (a) { return $H(a).inject($H(this), function (b, c) { b[c.key] = c.value; return b }) }, toQueryString: function () { return this.map(function (a) { return a.map(encodeURIComponent).join("=") }).join("&") }, inspect: function () { return "#<Hash:{" + this.map(function (a) { return a.map(Object.inspect).join(": ") }).join(", ") + "}>" } }; function $H(a) { a = Object.extend({}, a || {}); Object.extend(a, Enumerable); Object.extend(a, Hash); return a } ObjectRange = Class.create(); Object.extend(ObjectRange.prototype, Enumerable); Object.extend(ObjectRange.prototype, { initialize: function (a, b, c) { this.start = a; this.end = b; this.exclusive = c }, _each: function (a) { var b = this.start; do { a(b); b = b.succ() } while (this.include(b)) }, include: function (a) { if (a < this.start) { return false } if (this.exclusive) { return a < this.end } return a <= this.end } }); var $R = function (a, b, c) { return new ObjectRange(a, b, c) }, Ajax = { getTransport: function () { return Try.these(function () { return new ActiveXObject("Msxml2.XMLHTTP") }, function () { return new ActiveXObject("Microsoft.XMLHTTP") }, function () { return new XMLHttpRequest }) || false }, activeRequestCount: 0 }; Ajax.Responders = { responders: [], _each: function (a) { this.responders._each(a) }, register: function (a) { this.include(a) || this.responders.push(a) }, unregister: function (a) { this.responders = this.responders.without(a) }, dispatch: function (a, b, c, d) { this.each(function (e) { if (e[a] && typeof e[a] == "function") { try { e[a].apply(e, [b, c, d]) } catch (f) { } } }) } }; Object.extend(Ajax.Responders, Enumerable); Ajax.Responders.register({ onCreate: function () { Ajax.activeRequestCount++ }, onComplete: function () { Ajax.activeRequestCount-- } }); Ajax.Base = function () { }; Ajax.Base.prototype = { setOptions: function (a) { this.options = { method: "post", asynchronous: true, parameters: "" }; Object.extend(this.options, a || {}) }, responseIsSuccess: function () { return this.transport.status == undefined || this.transport.status == 0 || this.transport.status >= 200 && this.transport.status < 300 }, responseIsFailure: function () { return !this.responseIsSuccess() } }; Ajax.Request = Class.create(); Ajax.Request.Events = ["Uninitialized", "Loading", "Loaded", "Interactive", "Complete"]; Ajax.Request.prototype = Object.extend(new Ajax.Base, { initialize: function (a, b) { this.transport = Ajax.getTransport(); this.setOptions(b); this.request(a) }, request: function (a) { var b = this.options.parameters || ""; if (b.length > 0) { b += "&_=" } try { this.url = a; if (this.options.method == "get" && b.length > 0) { this.url += (this.url.match(/\?/) ? "&" : "?") + b } Ajax.Responders.dispatch("onCreate", this, this.transport); this.transport.open(this.options.method, this.url, this.options.asynchronous); if (this.options.asynchronous) { this.transport.onreadystatechange = this.onStateChange.bind(this); setTimeout(function () { this.respondToReadyState(1) } .bind(this), 10) } this.setRequestHeaders(); var c = this.options.postBody ? this.options.postBody : b; this.transport.send(this.options.method == "post" ? c : null) } catch (d) { this.dispatchException(d) } }, setRequestHeaders: function () { var a = ["X-Requested-With", "XMLHttpRequest", "X-Prototype-Version", Prototype.Version]; if (this.options.method == "post") { a.push("Content-type", "application/x-www-form-urlencoded"); this.transport.overrideMimeType && a.push("Connection", "close") } this.options.requestHeaders && a.push.apply(a, this.options.requestHeaders); for (var b = 0; b < a.length; b += 2) { this.transport.setRequestHeader(a[b], a[b + 1]) } }, onStateChange: function () { this.transport.readyState != 1 && this.respondToReadyState(this.transport.readyState) }, header: function (a) { try { return this.transport.getResponseHeader(a) } catch (b) { } }, evalJSON: function () { try { return eval(this.header("X-JSON")) } catch (a) { } }, evalResponse: function () { try { return eval(this.transport.responseText) } catch (a) { this.dispatchException(a) } }, respondToReadyState: function (a) { a = Ajax.Request.Events[a]; var b = this.transport, c = this.evalJSON(); if (a == "Complete") { try { (this.options["on" + this.transport.status] || this.options["on" + (this.responseIsSuccess() ? "Success" : "Failure")] || Prototype.emptyFunction)(b, c) } catch (d) { this.dispatchException(d) } if ((this.header("Content-type") || "").match(/^text\/javascript/i)) { this.evalResponse() } } try { (this.options["on" + a] || Prototype.emptyFunction)(b, c); Ajax.Responders.dispatch("on" + a, this, b, c) } catch (e) { this.dispatchException(e) } if (a == "Complete") { this.transport.onreadystatechange = Prototype.emptyFunction } }, dispatchException: function (a) { (this.options.onException || Prototype.emptyFunction)(this, a); Ajax.Responders.dispatch("onException", this, a) } }); Ajax.Updater = Class.create(); Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { initialize: function (a, b, c) { this.containers = { success: a.success ? $(a.success) : $(a), failure: a.failure ? $(a.failure) : a.success ? null : $(a) }; this.transport = Ajax.getTransport(); this.setOptions(c); var d = this.options.onComplete || Prototype.emptyFunction; this.options.onComplete = function (e, f) { this.updateContent(); d(e, f) } .bind(this); this.request(b) }, updateContent: function () { var a = this.responseIsSuccess() ? this.containers.success : this.containers.failure, b = this.transport.responseText; this.options.evalScripts || (b = b.stripScripts()); if (a) { if (this.options.insertion) { new this.options.insertion(a, b) } else { Element.update(a, b) } } this.responseIsSuccess() && this.onComplete && setTimeout(this.onComplete.bind(this), 10) } }); Ajax.PeriodicalUpdater = Class.create(); Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base, { initialize: function (a, b, c) { this.setOptions(c); this.onComplete = this.options.onComplete; this.frequency = this.options.frequency || 2; this.decay = this.options.decay || 1; this.updater = {}; this.container = a; this.url = b; this.start() }, start: function () { this.options.onComplete = this.updateComplete.bind(this); this.onTimerEvent() }, stop: function () { this.updater.onComplete = undefined; clearTimeout(this.timer); (this.onComplete || Prototype.emptyFunction).apply(this, arguments) }, updateComplete: function (a) { if (this.options.decay) { this.decay = a.responseText == this.lastText ? this.decay * this.options.decay : 1; this.lastText = a.responseText } this.timer = setTimeout(this.onTimerEvent.bind(this), this.decay * this.frequency * 1E3) }, onTimerEvent: function () { this.updater = new Ajax.Updater(this.container, this.url, this.options) } }); document.getElementsByClassName = function (a, b) { var c = ($(b) || document.body).getElementsByTagName("*"); return $A(c).inject([], function (d, e) { e.className.match(RegExp("(^|\\s)" + a + "(\\s|$)")) && d.push(e); return d }) }; window.Element || (Element = {}); Object.extend(Element, { visible: function (a) { return $(a).style.display != "none" }, toggle: function () { for (var a = 0; a < arguments.length; a++) { var b = $(arguments[a]); Element[Element.visible(b) ? "hide" : "show"](b) } }, hide: function () { for (var a = 0; a < arguments.length; a++) { $(arguments[a]).style.display = "none" } }, show: function () { for (var a = 0; a < arguments.length; a++) { $(arguments[a]).style.display = "" } }, remove: function (a) { a = $(a); a.parentNode.removeChild(a) }, update: function (a, b) { $(a).innerHTML = b.stripScripts(); setTimeout(function () { b.evalScripts() }, 10) }, getHeight: function (a) { a = $(a); return a.offsetHeight }, classNames: function (a) { return new Element.ClassNames(a) }, hasClassName: function (a, b) { if (a = $(a)) { return Element.classNames(a).include(b) } }, addClassName: function (a, b) { if (a = $(a)) { return Element.classNames(a).add(b) } }, removeClassName: function (a, b) { if (a = $(a)) { return Element.classNames(a).remove(b) } }, cleanWhitespace: function (a) { a = $(a); for (var b = 0; b < a.childNodes.length; b++) { var c = a.childNodes[b]; c.nodeType == 3 && !/\S/.test(c.nodeValue) && Element.remove(c) } }, empty: function (a) { return $(a).innerHTML.match(/^\s*$/) }, scrollTo: function (a) { a = $(a); window.scrollTo(a.x ? a.x : a.offsetLeft, a.y ? a.y : a.offsetTop) }, getStyle: function (a, b) { a = $(a); var c = a.style[b.camelize()]; if (!c) { if (document.defaultView && document.defaultView.getComputedStyle) { c = (c = document.defaultView.getComputedStyle(a, null)) ? c.getPropertyValue(b) : null } else { if (a.currentStyle) { c = a.currentStyle[b.camelize()] } } } if (window.opera && ["left", "top", "right", "bottom"].include(b)) { if (Element.getStyle(a, "position") == "static") { c = "auto" } } return c == "auto" ? null : c }, setStyle: function (a, b) { a = $(a); for (name in b) { a.style[name.camelize()] = b[name] } }, getDimensions: function (a) { a = $(a); if (Element.getStyle(a, "display") != "none") { return { width: a.offsetWidth, height: a.offsetHeight} } var b = a.style, c = b.visibility, d = b.position; b.visibility = "hidden"; b.position = "absolute"; b.display = ""; var e = a.clientWidth; a = a.clientHeight; b.display = "none"; b.position = d; b.visibility = c; return { width: e, height: a} }, makePositioned: function (a) { a = $(a); var b = Element.getStyle(a, "position"); if (b == "static" || !b) { a._madePositioned = true; a.style.position = "relative"; if (window.opera) { a.style.top = 0; a.style.left = 0 } } }, undoPositioned: function (a) { a = $(a); if (a._madePositioned) { a._madePositioned = undefined; a.style.position = a.style.top = a.style.left = a.style.bottom = a.style.right = "" } }, makeClipping: function (a) { a = $(a); if (!a._overflow) { a._overflow = a.style.overflow; if ((Element.getStyle(a, "overflow") || "visible") != "hidden") { a.style.overflow = "hidden" } } }, undoClipping: function (a) { a = $(a); if (!a._overflow) { a.style.overflow = a._overflow; a._overflow = undefined } } }); var Toggle = {}; Toggle.display = Element.toggle; Abstract.Insertion = function (a) { this.adjacency = a }; Abstract.Insertion.prototype = { initialize: function (a, b) { this.element = $(a); this.content = b.stripScripts(); if (this.adjacency && this.element.insertAdjacentHTML) { try { this.element.insertAdjacentHTML(this.adjacency, this.content) } catch (c) { if (this.element.tagName.toLowerCase() == "tbody") { this.insertContent(this.contentFromAnonymousTable()) } else { throw c } } } else { this.range = this.element.ownerDocument.createRange(); this.initializeRange && this.initializeRange(); this.insertContent([this.range.createContextualFragment(this.content)]) } setTimeout(function () { b.evalScripts() }, 10) }, contentFromAnonymousTable: function () { var a = document.createElement("div"); a.innerHTML = "<table><tbody>" + this.content + "</tbody></table>"; return $A(a.childNodes[0].childNodes[0].childNodes) } }; var Insertion = {}; Insertion.Before = Class.create(); Insertion.Before.prototype = Object.extend(new Abstract.Insertion("beforeBegin"), { initializeRange: function () { this.range.setStartBefore(this.element) }, insertContent: function (a) { a.each(function (b) { this.element.parentNode.insertBefore(b, this.element) } .bind(this)) } }); Insertion.Top = Class.create(); Insertion.Top.prototype = Object.extend(new Abstract.Insertion("afterBegin"), { initializeRange: function () { this.range.selectNodeContents(this.element); this.range.collapse(true) }, insertContent: function (a) { a.reverse(false).each(function (b) { this.element.insertBefore(b, this.element.firstChild) } .bind(this)) } }); Insertion.Bottom = Class.create(); Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion("beforeEnd"), { initializeRange: function () { this.range.selectNodeContents(this.element); this.range.collapse(this.element) }, insertContent: function (a) { a.each(function (b) { this.element.appendChild(b) } .bind(this)) } }); Insertion.After = Class.create(); Insertion.After.prototype = Object.extend(new Abstract.Insertion("afterEnd"), { initializeRange: function () { this.range.setStartAfter(this.element) }, insertContent: function (a) { a.each(function (b) { this.element.parentNode.insertBefore(b, this.element.nextSibling) } .bind(this)) } }); Element.ClassNames = Class.create(); Element.ClassNames.prototype = { initialize: function (a) { this.element = $(a) }, _each: function (a) { this.element.className.split(/\s+/).select(function (b) { return b.length > 0 })._each(a) }, set: function (a) { this.element.className = a }, add: function (a) { this.include(a) || this.set(this.toArray().concat(a).join(" ")) }, remove: function (a) { this.include(a) && this.set(this.select(function (b) { return b != a }).join(" ")) }, toString: function () { return this.toArray().join(" ") } }; Object.extend(Element.ClassNames.prototype, Enumerable); var Field = { clear: function () { for (var a = 0; a < arguments.length; a++) { $(arguments[a]).value = "" } }, focus: function (a) { $(a).focus() }, present: function () { for (var a = 0; a < arguments.length; a++) { if ($(arguments[a]).value == "") { return false } } return true }, select: function (a) { $(a).select() }, activate: function (a) { a = $(a); a.focus(); a.select && a.select() } }, Form = { serialize: function (a) { a = Form.getElements($(a)); for (var b = [], c = 0; c < a.length; c++) { var d = Form.Element.serialize(a[c]); d && b.push(d) } return b.join("&") }, getElements: function (a) { a = $(a); var b = []; for (tagName in Form.Element.Serializers) { for (var c = a.getElementsByTagName(tagName), d = 0; d < c.length; d++) { b.push(c[d]) } } return b }, getInputs: function (a, b, c) { a = $(a); a = a.getElementsByTagName("input"); if (!b && !c) { return a } for (var d = [], e = 0; e < a.length; e++) { var f = a[e]; b && f.type != b || c && f.name != c || d.push(f) } return d }, disable: function (a) { a = Form.getElements(a); for (var b = 0; b < a.length; b++) { var c = a[b]; c.blur(); c.disabled = "true" } }, enable: function (a) { a = Form.getElements(a); for (var b = 0; b < a.length; b++) { a[b].disabled = "" } }, findFirstElement: function (a) { return Form.getElements(a).find(function (b) { return b.type != "hidden" && !b.disabled && ["input", "select", "textarea"].include(b.tagName.toLowerCase()) }) }, focusFirstElement: function (a) { Field.activate(Form.findFirstElement(a)) }, reset: function (a) { $(a).reset() } }; Form.Element = { serialize: function (a) { a = $(a); var b = a.tagName.toLowerCase(); if (a = Form.Element.Serializers[b](a)) { var c = encodeURIComponent(a[0]); if (c.length != 0) { if (a[1].constructor != Array) { a[1] = [a[1]] } return a[1].map(function (d) { return c + "=" + encodeURIComponent(d) }).join("&") } } }, getValue: function (a) { a = $(a); var b = a.tagName.toLowerCase(); if (a = Form.Element.Serializers[b](a)) { return a[1] } } }; Form.Element.Serializers = { input: function (a) { switch (a.type.toLowerCase()) { case "submit": ; case "hidden": ; case "password": ; case "text": return Form.Element.Serializers.textarea(a); case "checkbox": ; case "radio": return Form.Element.Serializers.inputSelector(a) } return false }, inputSelector: function (a) { if (a.checked) { return [a.name, a.value] } }, textarea: function (a) { return [a.name, a.value] }, select: function (a) { return Form.Element.Serializers[a.type == "select-one" ? "selectOne" : "selectMany"](a) }, selectOne: function (a) { var b = "", c; c = a.selectedIndex; if (c >= 0) { c = a.options[c]; b = c.value; if (!b && !("value" in c)) { b = c.text } } return [a.name, b] }, selectMany: function (a) { for (var b = [], c = 0; c < a.length; c++) { var d = a.options[c]; if (d.selected) { var e = d.value; if (!e && !("value" in d)) { e = d.text } b.push(e) } } return [a.name, b] } }; var $F = Form.Element.getValue; Abstract.TimedObserver = function () { }; Abstract.TimedObserver.prototype = { initialize: function (a, b, c) { this.frequency = b; this.element = $(a); this.callback = c; this.lastValue = this.getValue(); this.registerCallback() }, registerCallback: function () { setInterval(this.onTimerEvent.bind(this), this.frequency * 1E3) }, onTimerEvent: function () { var a = this.getValue(); if (this.lastValue != a) { this.callback(this.element, a); this.lastValue = a } } }; Form.Element.Observer = Class.create(); Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver, { getValue: function () { return Form.Element.getValue(this.element) } }); Form.Observer = Class.create(); Form.Observer.prototype = Object.extend(new Abstract.TimedObserver, { getValue: function () { return Form.serialize(this.element) } }); Abstract.EventObserver = function () { }; Abstract.EventObserver.prototype = { initialize: function (a, b) { this.element = $(a); this.callback = b; this.lastValue = this.getValue(); this.element.tagName.toLowerCase() == "form" ? this.registerFormCallbacks() : this.registerCallback(this.element) }, onElementEvent: function () { var a = this.getValue(); if (this.lastValue != a) { this.callback(this.element, a); this.lastValue = a } }, registerFormCallbacks: function () { for (var a = Form.getElements(this.element), b = 0; b < a.length; b++) { this.registerCallback(a[b]) } }, registerCallback: function (a) { if (a.type) { switch (a.type.toLowerCase()) { case "checkbox": ; case "radio": Event.observe(a, "click", this.onElementEvent.bind(this)); break; case "password": ; case "text": ; case "textarea": ; case "select-one": ; case "select-multiple": Event.observe(a, "change", this.onElementEvent.bind(this)) } } } }; Form.Element.EventObserver = Class.create(); Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver, { getValue: function () { return Form.Element.getValue(this.element) } }); Form.EventObserver = Class.create(); Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver, { getValue: function () { return Form.serialize(this.element) } }); window.Event || (Event = {}); Object.extend(Event, { KEY_BACKSPACE: 8, KEY_TAB: 9, KEY_RETURN: 13, KEY_ESC: 27, KEY_LEFT: 37, KEY_UP: 38, KEY_RIGHT: 39, KEY_DOWN: 40, KEY_DELETE: 46, element: function (a) { return a.target || a.srcElement }, isLeftClick: function (a) { return a.which && a.which == 1 || a.button && a.button == 1 }, pointerX: function (a) { return a.pageX || a.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) }, pointerY: function (a) { return a.pageY || a.clientY + (document.documentElement.scrollTop || document.body.scrollTop) }, stop: function (a) { if (a.preventDefault) { a.preventDefault(); a.stopPropagation() } else { a.returnValue = false; a.cancelBubble = true } }, findElement: function (a, b) { for (var c = Event.element(a); c.parentNode && (!c.tagName || c.tagName.toUpperCase() != b.toUpperCase()); ) { c = c.parentNode } return c }, observers: false, _observeAndCache: function (a, b, c, d) { if (!this.observers) { this.observers = [] } if (a.addEventListener) { this.observers.push([a, b, c, d]); a.addEventListener(b, c, d) } else { if (a.attachEvent) { this.observers.push([a, b, c, d]); a.attachEvent("on" + b, c) } } }, unloadCache: function () { if (Event.observers) { for (var a = 0; a < Event.observers.length; a++) { Event.stopObserving.apply(this, Event.observers[a]); Event.observers[a][0] = null } Event.observers = false } }, observe: function (a, b, c, d) { a = $(a); d = d || false; if (b == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || a.attachEvent)) { b = "keydown" } this._observeAndCache(a, b, c, d) }, stopObserving: function (a, b, c, d) { a = $(a); d = d || false; if (b == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || a.detachEvent)) { b = "keydown" } if (a.removeEventListener) { a.removeEventListener(b, c, d) } else { a.detachEvent && a.detachEvent("on" + b, c) } } }); Event.observe(window, "unload", Event.unloadCache, false); var Position = { includeScrollOffsets: false, prepare: function () { this.deltaX = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; this.deltaY = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 }, realOffset: function (a) { var b = 0, c = 0; do { b += a.scrollTop || 0; c += a.scrollLeft || 0; a = a.parentNode } while (a); return [c, b] }, cumulativeOffset: function (a) { var b = 0, c = 0; do { b += a.offsetTop || 0; c += a.offsetLeft || 0; a = a.offsetParent } while (a); return [c, b] }, positionedOffset: function (a) { var b = 0, c = 0; do { b += a.offsetTop || 0; c += a.offsetLeft || 0; if (a = a.offsetParent) { p = Element.getStyle(a, "position"); if (p == "relative" || p == "absolute") { break } } } while (a); return [c, b] }, offsetParent: function (a) { if (a.offsetParent) { return a.offsetParent } if (a == document.body) { return a } for (; (a = a.parentNode) && a != document.body; ) { if (Element.getStyle(a, "position") != "static") { return a } } return document.body }, within: function (a, b, c) { if (this.includeScrollOffsets) { return this.withinIncludingScrolloffsets(a, b, c) } this.xcomp = b; this.ycomp = c; this.offset = this.cumulativeOffset(a); return c >= this.offset[1] && c < this.offset[1] + a.offsetHeight && b >= this.offset[0] && b < this.offset[0] + a.offsetWidth }, withinIncludingScrolloffsets: function (a, b, c) { var d = this.realOffset(a); this.xcomp = b + d[0] - this.deltaX; this.ycomp = c + d[1] - this.deltaY; this.offset = this.cumulativeOffset(a); return this.ycomp >= this.offset[1] && this.ycomp < this.offset[1] + a.offsetHeight && this.xcomp >= this.offset[0] && this.xcomp < this.offset[0] + a.offsetWidth }, overlap: function (a, b) { if (!a) { return 0 } if (a == "vertical") { return (this.offset[1] + b.offsetHeight - this.ycomp) / b.offsetHeight } if (a == "horizontal") { return (this.offset[0] + b.offsetWidth - this.xcomp) / b.offsetWidth } }, clone: function (a, b) { a = $(a); b = $(b); b.style.position = "absolute"; var c = this.cumulativeOffset(a); b.style.top = c[1] + "px"; b.style.left = c[0] + "px"; b.style.width = a.offsetWidth + "px"; b.style.height = a.offsetHeight + "px" }, page: function (a) { var b = 0, c = 0, d = a; do { b += d.offsetTop || 0; c += d.offsetLeft || 0; if (d.offsetParent == document.body) { if (Element.getStyle(d, "position") == "absolute") { break } } } while (d = d.offsetParent); d = a; do { b -= d.scrollTop || 0; c -= d.scrollLeft || 0 } while (d = d.parentNode); return [c, b] }, clone: function (a, b, c) { c = Object.extend({ setLeft: true, setTop: true, setWidth: true, setHeight: true, offsetTop: 0, offsetLeft: 0 }, c || {}); a = $(a); var d = Position.page(a); b = $(b); var e = [0, 0], f = null; if (Element.getStyle(b, "position") == "absolute") { f = Position.offsetParent(b); e = Position.page(f) } if (f == document.body) { e[0] -= document.body.offsetLeft; e[1] -= document.body.offsetTop } if (c.setLeft) { b.style.left = d[0] - e[0] + c.offsetLeft + "px" } if (c.setTop) { b.style.top = d[1] - e[1] + c.offsetTop + "px" } if (c.setWidth) { b.style.width = a.offsetWidth + "px" } if (c.setHeight) { b.style.height = a.offsetHeight + "px" } }, absolutize: function (a) { a = $(a); if (a.style.position != "absolute") { Position.prepare(); var b = Position.positionedOffset(a), c = b[1]; b = b[0]; var d = a.clientWidth, e = a.clientHeight; a._originalLeft = b - parseFloat(a.style.left || 0); a._originalTop = c - parseFloat(a.style.top || 0); a._originalWidth = a.style.width; a._originalHeight = a.style.height; a.style.position = "absolute"; a.style.top = c + "px"; a.style.left = b + "px"; a.style.width = d + "px"; a.style.height = e + "px" } }, relativize: function (a) { a = $(a); if (a.style.position != "relative") { Position.prepare(); a.style.position = "relative"; var b = parseFloat(a.style.top || 0) - (a._originalTop || 0), c = parseFloat(a.style.left || 0) - (a._originalLeft || 0); a.style.top = b + "px"; a.style.left = c + "px"; a.style.height = a._originalHeight; a.style.width = a._originalWidth } } }; if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) { Position.cumulativeOffset = function (a) { var b = 0, c = 0; do { b += a.offsetTop || 0; c += a.offsetLeft || 0; if (a.offsetParent == document.body) { if (Element.getStyle(a, "position") == "absolute") { break } } a = a.offsetParent } while (a); return [c, b] } };
