PageSourceSearch

https://www.ima.or.jp/js/prototype.js

js ima.or.jp collected 2026-09-25 04:07:12 UTC 163,456 bytes, 6,082 lines download raw bytes

1/*  Prototype JavaScript framework, version 1.7
2 *  (c) 2005-2010 Sam Stephenson
3 *
4 *  Prototype is freely distributable under the terms of an MIT-style license.
5 *  For details, see the Prototype web site: http://www.prototypejs.org/
6 *
7 *--------------------------------------------------------------------------*/
8
9var Prototype = {
10
11  Version: '1.7',
12
13  Browser: (function(){
14    var ua = navigator.userAgent;
15    var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
16    return {
17      IE:             !!window.attachEvent && !isOpera,
18      Opera:          isOpera,
19      WebKit:         ua.indexOf('AppleWebKit/') > -1,
20      Gecko:          ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
21      MobileSafari:   /Apple.*Mobile/.test(ua)
22    }
23  })(),
24
25  BrowserFeatures: {
26    XPath: !!document.evaluate,
27
28    SelectorsAPI: !!document.querySelector,
29
30    ElementExtensions: (function() {
31      var constructor = window.Element || window.HTMLElement;
32      return !!(constructor && constructor.prototype);
33    })(),
34    SpecificElementExtensions: (function() {
35      if (typeof window.HTMLDivElement !== 'undefined')
36        return true;
37
38      var div = document.createElement('div'),
39          form = document.createElement('form'),
40          isSupported = false;
41
42      if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
43        isSupported = true;
44      }
45
46      div = form = null;
47
48      return isSupported;
49    })()
50  },
51
52  ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
53  JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
54
55  emptyFunction: function() { },
56
57  K: function(x) { return x }
58};
59
60if (Prototype.Browser.MobileSafari)
61  Prototype.BrowserFeatures.SpecificElementExtensions = false;
62/* Based on Alex Arnell's inheritance implementation. */
63
64var Class = (function() {
65
66  var IS_DONTENUM_BUGGY = (function(){
67    for (var p in { toString: 1 }) {
68      if (p === 'toString') return false;
69    }
70    return true;
71  })();
72
73  function subclass() {};
74  function create() {
75    var parent = null, properties = $A(arguments);
76    if (Object.isFunction(properties[0]))
77      parent = properties.shift();
78
79    function klass() {
80      this.initialize.apply(this, arguments);
81    }
82
83    Object.extend(klass, Class.Methods);
84    klass.superclass = parent;
85    klass.subclasses = [];
86
87    if (parent) {
88      subclass.prototype = parent.prototype;
89      klass.prototype = new subclass;
90      parent.subclasses.push(klass);
91    }
92
93    for (var i = 0, length = properties.length; i < length; i++)
94      klass.addMethods(properties[i]);
95
96    if (!klass.prototype.initialize)
97      klass.prototype.initialize = Prototype.emptyFunction;
98
99    klass.prototype.constructor = klass;
100    return klass;
101  }
102
103  function addMethods(source) {
104    var ancestor   = this.superclass && this.superclass.prototype,
105        properties = Object.keys(source);
106
107    if (IS_DONTENUM_BUGGY) {
108      if (source.toString != Object.prototype.toString)
109        properties.push("toString");
110      if (source.valueOf != Object.prototype.valueOf)
111        properties.push("valueOf");
112    }
113
114    for (var i = 0, length = properties.length; i < length; i++) {
115      var property = properties[i], value = source[property];
116      if (ancestor && Object.isFunction(value) &&
117          value.argumentNames()[0] == "$super") {
118        var method = value;
119        value = (function(m) {
120          return function() { return ancestor[m].apply(this, arguments); };
121        })(property).wrap(method);
122
123        value.valueOf = method.valueOf.bind(method);
124        value.toString = method.toString.bind(method);
125      }
126      this.prototype[property] = value;
127    }
128
129    return this;
130  }
131
132  return {
133    create: create,
134    Methods: {
135      addMethods: addMethods
136    }
137  };
138})();
139(function() {
140
141  var _toString = Object.prototype.toString,
142      NULL_TYPE = 'Null',
143      UNDEFINED_TYPE = 'Undefined',
144      BOOLEAN_TYPE = 'Boolean',
145      NUMBER_TYPE = 'Number',
146      STRING_TYPE = 'String',
147      OBJECT_TYPE = 'Object',
148      FUNCTION_CLASS = '[object Function]',
149      BOOLEAN_CLASS = '[object Boolean]',
150      NUMBER_CLASS = '[object Number]',
151      STRING_CLASS = '[object String]',
152      ARRAY_CLASS = '[object Array]',
153      DATE_CLASS = '[object Date]',
154      NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON &&
155        typeof JSON.stringify === 'function' &&
156        JSON.stringify(0) === '0' &&
157        typeof JSON.stringify(Prototype.K) === 'undefined';
158
159  function Type(o) {
160    switch(o) {
161      case null: return NULL_TYPE;
162      case (void 0): return UNDEFINED_TYPE;
163    }
164    var type = typeof o;
165    switch(type) {
166      case 'boolean': return BOOLEAN_TYPE;
167      case 'number':  return NUMBER_TYPE;
168      case 'string':  return STRING_TYPE;
169    }
170    return OBJECT_TYPE;
171  }
172
173  function extend(destination, source) {
174    for (var property in source)
175      destination[property] = source[property];
176    return destination;
177  }
178
179  function inspect(object) {
180    try {
181      if (isUndefined(object)) return 'undefined';
182      if (object === null) return 'null';
183      return object.inspect ? object.inspect() : String(object);
184    } catch (e) {
185      if (e instanceof RangeError) return '...';
186      throw e;
187    }
188  }
189
190  function toJSON(value) {
191    return Str('', { '': value }, []);
192  }
193
194  function Str(key, holder, stack) {
195    var value = holder[key],
196        type = typeof value;
197
198    if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') {
199      value = value.toJSON(key);
200    }
201
202    var _class = _toString.call(value);
203
204    switch (_class) {
205      case NUMBER_CLASS:
206      case BOOLEAN_CLASS:
207      case STRING_CLASS:
208        value = value.valueOf();
209    }
210
211    switch (value) {
212      case null: return 'null';
213      case true: return 'true';
214      case false: return 'false';
215    }
216
217    type = typeof value;
218    switch (type) {
219      case 'string':
220        return value.inspect(true);
221      case 'number':
222        return isFinite(value) ? String(value) : 'null';
223      case 'object':
224
225        for (var i = 0, length = stack.length; i < length; i++) {
226          if (stack[i] === value) { throw new TypeError(); }
227        }
228        stack.push(value);
229
230        var partial = [];
231        if (_class === ARRAY_CLASS) {
232          for (var i = 0, length = value.length; i < length; i++) {
233            var str = Str(i, value, stack);
234            partial.push(typeof str === 'undefined' ? 'null' : str);
235          }
236          partial = '[' + partial.join(',') + ']';
237        } else {
238          var keys = Object.keys(value);
239          for (var i = 0, length = keys.length; i < length; i++) {
240            var key = keys[i], str = Str(key, value, stack);
241            if (typeof str !== "undefined") {
242               partial.push(key.inspect(true)+ ':' + str);
243             }
244          }
245          partial = '{' + partial.join(',') + '}';
246        }
247        stack.pop();
248        return partial;
249    }
250  }
251
252  function stringify(object) {
253    return JSON.stringify(object);
254  }
255
256  function toQueryString(object) {
257    return $H(object).toQueryString();
258  }
259
260  function toHTML(object) {
261    return object && object.toHTML ? object.toHTML() : String.interpret(object);
262  }
263
264  function keys(object) {
265    if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
266    var results = [];
267    for (var property in object) {
268      if (object.hasOwnProperty(property)) {
269        results.push(property);
270      }
271    }
272    return results;
273  }
274
275  function values(object) {
276    var results = [];
277    for (var property in object)
278      results.push(object[property]);
279    return results;
280  }
281
282  function clone(object) {
283    return extend({ }, object);
284  }
285
286  function isElement(object) {
287    return !!(object && object.nodeType == 1);
288  }
289
290  function isArray(object) {
291    return _toString.call(object) === ARRAY_CLASS;
292  }
293
294  var hasNativeIsArray = (typeof Array.isArray == 'function')
295    && Array.isArray([]) && !Array.isArray({});
296
297  if (hasNativeIsArray) {
298    isArray = Array.isArray;
299  }
300
301  function isHash(object) {
302    return object instanceof Hash;
303  }
304
305  function isFunction(object) {
306    return _toString.call(object) === FUNCTION_CLASS;
307  }
308
309  function isString(object) {
310    return _toString.call(object) === STRING_CLASS;
311  }
312
313  function isNumber(object) {
314    return _toString.call(object) === NUMBER_CLASS;
315  }
316
317  function isDate(object) {
318    return _toString.call(object) === DATE_CLASS;
319  }
320
321  function isUndefined(object) {
322    return typeof object === "undefined";
323  }
324
325  extend(Object, {
326    extend:        extend,
327    inspect:       inspect,
328    toJSON:        NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON,
329    toQueryString: toQueryString,
330    toHTML:        toHTML,
331    keys:          Object.keys || keys,
332    values:        values,
333    clone:         clone,
334    isElement:     isElement,
335    isArray:       isArray,
336    isHash:        isHash,
337    isFunction:    isFunction,
338    isString:      isString,
339    isNumber:      isNumber,
340    isDate:        isDate,
341    isUndefined:   isUndefined
342  });
343})();
344Object.extend(Function.prototype, (function() {
345  var slice = Array.prototype.slice;
346
347  function update(array, args) {
348    var arrayLength = array.length, length = args.length;
349    while (length--) array[arrayLength + length] = args[length];
350    return array;
351  }
352
353  function merge(array, args) {
354    array = slice.call(array, 0);
355    return update(array, args);
356  }
357
358  function argumentNames() {
359    var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
360      .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
361      .replace(/\s+/g, '').split(',');
362    return names.length == 1 && !names[0] ? [] : names;
363  }
364
365  function bind(context) {
366    if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
367    var __method = this, args = slice.call(arguments, 1);
368    return function() {
369      var a = merge(args, arguments);
370      return __method.apply(context, a);
371    }
372  }
373
374  function bindAsEventListener(context) {
375    var __method = this, args = slice.call(arguments, 1);
376    return function(event) {
377      var a = update([event || window.event], args);
378      return __method.apply(context, a);
379    }
380  }
381
382  function curry() {
383    if (!arguments.length) return this;
384    var __method = this, args = slice.call(arguments, 0);
385    return function() {
386      var a = merge(args, arguments);
387      return __method.apply(this, a);
388    }
389  }
390
391  function delay(timeout) {
392    var __method = this, args = slice.call(arguments, 1);
393    timeout = timeout * 1000;
394    return window.setTimeout(function() {
395      return __method.apply(__method, args);
396    }, timeout);
397  }
398
399  function defer() {
400    var args = update([0.01], arguments);
401    return this.delay.apply(this, args);
402  }
403
404  function wrap(wrapper) {
405    var __method = this;
406    return function() {
407      var a = update([__method.bind(this)], arguments);
408      return wrapper.apply(this, a);
409    }
410  }
411
412  function methodize() {
413    if (this._methodized) return this._methodized;
414    var __method = this;
415    return this._methodized = function() {
416      var a = update([this], arguments);
417      return __method.apply(null, a);
418    };
419  }
420
421  return {
422    argumentNames:       argumentNames,
423    bind:                bind,
424    bindAsEventListener: bindAsEventListener,
425    curry:               curry,
426    delay:               delay,
427    defer:               defer,
428    wrap:                wrap,
429    methodize:           methodize
430  }
431})());
432
433
434
435(function(proto) {
436
437
438  function toISOString() {
439    return this.getUTCFullYear() + '-' +
440      (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
441      this.getUTCDate().toPaddedString(2) + 'T' +
442      this.getUTCHours().toPaddedString(2) + ':' +
443      this.getUTCMinutes().toPaddedString(2) + ':' +
444      this.getUTCSeconds().toPaddedString(2) + 'Z';
445  }
446
447
448  function toJSON() {
449    return this.toISOString();
450  }
451
452  if (!proto.toISOString) proto.toISOString = toISOString;
453  if (!proto.toJSON) proto.toJSON = toJSON;
454
455})(Date.prototype);
456
457
458RegExp.prototype.match = RegExp.prototype.test;
459
460RegExp.escape = function(str) {
461  return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
462};
463var PeriodicalExecuter = Class.create({
464  initialize: function(callback, frequency) {
465    this.callback = callback;
466    this.frequency = frequency;
467    this.currentlyExecuting = false;
468
469    this.registerCallback();
470  },
471
472  registerCallback: function() {
473    this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
474  },
475
476  execute: function() {
477    this.callback(this);
478  },
479
480  stop: function() {
481    if (!this.timer) return;
482    clearInterval(this.timer);
483    this.timer = null;
484  },
485
486  onTimerEvent: function() {
487    if (!this.currentlyExecuting) {
488      try {
489        this.currentlyExecuting = true;
490        this.execute();
491        this.currentlyExecuting = false;
492      } catch(e) {
493        this.currentlyExecuting = false;
494        throw e;
495      }
496    }
497  }
498});
499Object.extend(String, {
500  interpret: function(value) {
501    return value == null ? '' : String(value);
502  },
503  specialChar: {
504    '\b': '\\b',
505    '\t': '\\t',
506    '\n': '\\n',
507    '\f': '\\f',
508    '\r': '\\r',
509    '\\': '\\\\'
510  }
511});
512
513Object.extend(String.prototype, (function() {
514  var NATIVE_JSON_PARSE_SUPPORT = window.JSON &&
515    typeof JSON.parse === 'function' &&
516    JSON.parse('{"test": true}').test;
517
518  function prepareReplacement(replacement) {
519    if (Object.isFunction(replacement)) return replacement;
520    var template = new Template(replacement);
521    return function(match) { return template.evaluate(match) };
522  }
523
524  function gsub(pattern, replacement) {
525    var result = '', source = this, match;
526    replacement = prepareReplacement(replacement);
527
528    if (Object.isString(pattern))
529      pattern = RegExp.escape(pattern);
530
531    if (!(pattern.length || pattern.source)) {
532      replacement = replacement('');
533      return replacement + source.split('').join(replacement) + replacement;
534    }
535
536    while (source.length > 0) {
537      if (match = source.match(pattern)) {
538        result += source.slice(0, match.index);
539        result += String.interpret(replacement(match));
540        source  = source.slice(match.index + match[0].length);
541      } else {
542        result += source, source = '';
543      }
544    }
545    return result;
546  }
547
548  function sub(pattern, replacement, count) {
549    replacement = prepareReplacement(replacement);
550    count = Object.isUndefined(count) ? 1 : count;
551
552    return this.gsub(pattern, function(match) {
553      if (--count < 0) return match[0];
554      return replacement(match);
555    });
556  }
557
558  function scan(pattern, iterator) {
559    this.gsub(pattern, iterator);
560    return String(this);
561  }
562
563  function truncate(length, truncation) {
564    length = length || 30;
565    truncation = Object.isUndefined(truncation) ? '...' : truncation;
566    return this.length > length ?
567      this.slice(0, length - truncation.length) + truncation : String(this);
568  }
569
570  function strip() {
571    return this.replace(/^\s+/, '').replace(/\s+$/, '');
572  }
573
574  function stripTags() {
575    return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
576  }
577
578  function stripScripts() {
579    return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
580  }
581
582  function extractScripts() {
583    var matchAll = new RegExp(Prototype.ScriptFragment, 'img'),
584        matchOne = new RegExp(Prototype.ScriptFragment, 'im');
585    return (this.match(matchAll) || []).map(function(scriptTag) {
586      return (scriptTag.match(matchOne) || ['', ''])[1];
587    });
588  }
589
590  function evalScripts() {
591    return this.extractScripts().map(function(script) { return eval(script) });
592  }
593
594  function escapeHTML() {
595    return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
596  }
597
598  function unescapeHTML() {
599    return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
600  }
601
602
603  function toQueryParams(separator) {
604    var match = this.strip().match(/([^?#]*)(#.*)?$/);
605    if (!match) return { };
606
607    return match[1].split(separator || '&').inject({ }, function(hash, pair) {
608      if ((pair = pair.split('='))[0]) {
609        var key = decodeURIComponent(pair.shift()),
610            value = pair.length > 1 ? pair.join('=') : pair[0];
611
612        if (value != undefined) value = decodeURIComponent(value);
613
614        if (key in hash) {
615          if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
616          hash[key].push(value);
617        }
618        else hash[key] = value;
619      }
620      return hash;
621    });
622  }
623
624  function toArray() {
625    return this.split('');
626  }
627
628  function succ() {
629    return this.slice(0, this.length - 1) +
630      String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
631  }
632
633  function times(count) {
634    return count < 1 ? '' : new Array(count + 1).join(this);
635  }
636
637  function camelize() {
638    return this.replace(/-+(.)?/g, function(match, chr) {
639      return chr ? chr.toUpperCase() : '';
640    });
641  }
642
643  function capitalize() {
644    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
645  }
646
647  function underscore() {
648    return this.replace(/::/g, '/')
649               .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
650               .replace(/([a-z\d])([A-Z])/g, '$1_$2')
651               .replace(/-/g, '_')
652               .toLowerCase();
653  }
654
655  function dasherize() {
656    return this.replace(/_/g, '-');
657  }
658
659  function inspect(useDoubleQuotes) {
660    var escapedString = this.replace(/[\x00-\x1f\\]/g, function(ch
660aracter) {
661      if (character in String.specialChar) {
662        return String.specialChar[character];
663      }
664      return '\\u00' + character.charCodeAt().toPaddedString(2, 16);
665    });
666    if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
667    return "'" + escapedString.replace(/'/g, '\\\'') + "'";
668  }
669
670  function unfilterJSON(filter) {
671    return this.replace(filter || Prototype.JSONFilter, '$1');
672  }
673
674  function isJSON() {
675    var str = this;
676    if (str.blank()) return false;
677    str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@');
678    str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
679    str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
680    return (/^[\],:{}\s]*$/).test(str);
681  }
682
683  function evalJSON(sanitize) {
684    var json = this.unfilterJSON(),
685        cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
686    if (cx.test(json)) {
687      json = json.replace(cx, function (a) {
688        return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
689      });
690    }
691    try {
692      if (!sanitize || json.isJSON()) return eval('(' + json + ')');
693    } catch (e) { }
694    throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
695  }
696
697  function parseJSON() {
698    var json = this.unfilterJSON();
699    return JSON.parse(json);
700  }
701
702  function include(pattern) {
703    return this.indexOf(pattern) > -1;
704  }
705
706  function startsWith(pattern) {
707    return this.lastIndexOf(pattern, 0) === 0;
708  }
709
710  function endsWith(pattern) {
711    var d = this.length - pattern.length;
712    return d >= 0 && this.indexOf(pattern, d) === d;
713  }
714
715  function empty() {
716    return this == '';
717  }
718
719  function blank() {
720    return /^\s*$/.test(this);
721  }
722
723  function interpolate(object, pattern) {
724    return new Template(this, pattern).evaluate(object);
725  }
726
727  return {
728    gsub:           gsub,
729    sub:            sub,
730    scan:           scan,
731    truncate:       truncate,
732    strip:          String.prototype.trim || strip,
733    stripTags:      stripTags,
734    stripScripts:   stripScripts,
735    extractScripts: extractScripts,
736    evalScripts:    evalScripts,
737    escapeHTML:     escapeHTML,
738    unescapeHTML:   unescapeHTML,
739    toQueryParams:  toQueryParams,
740    parseQuery:     toQueryParams,
741    toArray:        toArray,
742    succ:           succ,
743    times:          times,
744    camelize:       camelize,
745    capitalize:     capitalize,
746    underscore:     underscore,
747    dasherize:      dasherize,
748    inspect:        inspect,
749    unfilterJSON:   unfilterJSON,
750    isJSON:         isJSON,
751    evalJSON:       NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON,
752    include:        include,
753    startsWith:     startsWith,
754    endsWith:       endsWith,
755    empty:          empty,
756    blank:          blank,
757    interpolate:    interpolate
758  };
759})());
760
761var Template = Class.create({
762  initialize: function(template, pattern) {
763    this.template = template.toString();
764    this.pattern = pattern || Template.Pattern;
765  },
766
767  evaluate: function(object) {
768    if (object && Object.isFunction(object.toTemplateReplacements))
769      object = object.toTemplateReplacements();
770
771    return this.template.gsub(this.pattern, function(match) {
772      if (object == null) return (match[1] + '');
773
774      var before = match[1] || '';
775      if (before == '\\') return match[2];
776
777      var ctx = object, expr = match[3],
778          pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
779
780      match = pattern.exec(expr);
781      if (match == null) return before;
782
783      while (match != null) {
784        var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1];
785        ctx = ctx[comp];
786        if (null == ctx || '' == match[3]) break;
787        expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
788        match = pattern.exec(expr);
789      }
790
791      return before + String.interpret(ctx);
792    });
793  }
794});
795Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
796
797var $break = { };
798
799var Enumerable = (function() {
800  function each(iterator, context) {
801    var index = 0;
802    try {
803      this._each(function(value) {
804        iterator.call(context, value, index++);
805      });
806    } catch (e) {
807      if (e != $break) throw e;
808    }
809    return this;
810  }
811
812  function eachSlice(number, iterator, context) {
813    var index = -number, slices = [], array = this.toArray();
814    if (number < 1) return array;
815    while ((index += number) < array.length)
816      slices.push(array.slice(index, index+number));
817    return slices.collect(iterator, context);
818  }
819
820  function all(iterator, context) {
821    iterator = iterator || Prototype.K;
822    var result = true;
823    this.each(function(value, index) {
824      result = result && !!iterator.call(context, value, index);
825      if (!result) throw $break;
826    });
827    return result;
828  }
829
830  function any(iterator, context) {
831    iterator = iterator || Prototype.K;
832    var result = false;
833    this.each(function(value, index) {
834      if (result = !!iterator.call(context, value, index))
835        throw $break;
836    });
837    return result;
838  }
839
840  function collect(iterator, context) {
841    iterator = iterator || Prototype.K;
842    var results = [];
843    this.each(function(value, index) {
844      results.push(iterator.call(context, value, index));
845    });
846    return results;
847  }
848
849  function detect(iterator, context) {
850    var result;
851    this.each(function(value, index) {
852      if (iterator.call(context, value, index)) {
853        result = value;
854        throw $break;
855      }
856    });
857    return result;
858  }
859
860  function findAll(iterator, context) {
861    var results = [];
862    this.each(function(value, index) {
863      if (iterator.call(context, value, index))
864        results.push(value);
865    });
866    return results;
867  }
868
869  function grep(filter, iterator, context) {
870    iterator = iterator || Prototype.K;
871    var results = [];
872
873    if (Object.isString(filter))
874      filter = new RegExp(RegExp.escape(filter));
875
876    this.each(function(value, index) {
877      if (filter.match(value))
878        results.push(iterator.call(context, value, index));
879    });
880    return results;
881  }
882
883  function include(object) {
884    if (Object.isFunction(this.indexOf))
885      if (this.indexOf(object) != -1) return true;
886
887    var found = false;
888    this.each(function(value) {
889      if (value == object) {
890        found = true;
891        throw $break;
892      }
893    });
894    return found;
895  }
896
897  function inGroupsOf(number, fillWith) {
898    fillWith = Object.isUndefined(fillWith) ? null : fillWith;
899    return this.eachSlice(number, function(slice) {
900      while(slice.length < number) slice.push(fillWith);
901      return slice;
902    });
903  }
904
905  function inject(memo, iterator, context) {
906    this.each(function(value, index) {
907      memo = iterator.call(context, memo, value, index);
908    });
909    return memo;
910  }
911
912  function invoke(method) {
913    var args = $A(arguments).slice(1);
914    return this.map(function(value) {
915      return value[method].apply(value, args);
916    });
917  }
918
919  function max(iterator, context) {
920    iterator = iterator || Prototype.K;
921    var result;
922    this.each(function(value, index) {
923      value = iterator.call(context, value, index);
924      if (result == null || value >= result)
925        result = value;
926    });
927    return result;
928  }
929
930  function min(iterator, context) {
931    iterator = iterator || Prototype.K;
932    var result;
933    this.each(function(value, index) {
934      value = iterator.call(context, value, index);
935      if (result == null || value < result)
936        result = value;
937    });
938    return result;
939  }
940
941  function partition(iterator, context) {
942    iterator = iterator || Prototype.K;
943    var trues = [], falses = [];
944    this.each(function(value, index) {
945      (iterator.call(context, value, index) ?
946        trues : falses).push(value);
947    });
948    return [trues, falses];
949  }
950
951  function pluck(property) {
952    var results = [];
953    this.each(function(value) {
954      results.push(value[property]);
955    });
956    return results;
957  }
958
959  function reject(iterator, context) {
960    var results = [];
961    this.each(function(value, index) {
962      if (!iterator.call(context, value, index))
963        results.push(value);
964    });
965    return results;
966  }
967
968  function sortBy(iterator, context) {
969    return this.map(function(value, index) {
970      return {
971        value: value,
972        criteria: iterator.call(context, value, index)
973      };
974    }).sort(function(left, right) {
975      var a = left.criteria, b = right.criteria;
976      return a < b ? -1 : a > b ? 1 : 0;
977    }).pluck('value');
978  }
979
980  function toArray() {
981    return this.map();
982  }
983
984  function zip() {
985    var iterator = Prototype.K, args = $A(arguments);
986    if (Object.isFunction(args.last()))
987      iterator = args.pop();
988
989    var collections = [this].concat(args).map($A);
990    return this.map(function(value, index) {
991      return iterator(collections.pluck(index));
992    });
993  }
994
995  function size() {
996    return this.toArray().length;
997  }
998
999  function inspect() {
1000    return '#<Enumerable:' + this.toArray().inspect() + '>';
1001  }
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011  return {
1012    each:       each,
1013    eachSlice:  eachSlice,
1014    all:        all,
1015    every:      all,
1016    any:        any,
1017    some:       any,
1018    collect:    collect,
1019    map:        collect,
1020    detect:     detect,
1021    findAll:    findAll,
1022    select:     findAll,
1023    filter:     findAll,
1024    grep:       grep,
1025    include:    include,
1026    member:     include,
1027    inGroupsOf: inGroupsOf,
1028    inject:     inject,
1029    invoke:     invoke,
1030    max:        max,
1031    min:        min,
1032    partition:  partition,
1033    pluck:      pluck,
1034    reject:     reject,
1035    sortBy:     sortBy,
1036    toArray:    toArray,
1037    entries:    toArray,
1038    zip:        zip,
1039    size:       size,
1040    inspect:    inspect,
1041    find:       detect
1042  };
1043})();
1044
1045function $A(iterable) {
1046  if (!iterable) return [];
1047  if ('toArray' in Object(iterable)) return iterable.toArray();
1048  var length = iterable.length || 0, results = new Array(length);
1049  while (length--) results[length] = iterable[length];
1050  return results;
1051}
1052
1053
1054function $w(string) {
1055  if (!Object.isString(string)) return [];
1056  string = string.strip();
1057  return string ? string.split(/\s+/) : [];
1058}
1059
1060Array.from = $A;
1061
1062
1063(function() {
1064  var arrayProto = Array.prototype,
1065      slice = arrayProto.slice,
1066      _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
1067
1068  function each(iterator, context) {
1069    for (var i = 0, length = this.length >>> 0; i < length; i++) {
1070      if (i in this) iterator.call(context, this[i], i, this);
1071    }
1072  }
1073  if (!_each) _each = each;
1074
1075  function clear() {
1076    this.length = 0;
1077    return this;
1078  }
1079
1080  function first() {
1081    return this[0];
1082  }
1083
1084  function last() {
1085    return this[this.length - 1];
1086  }
1087
1088  function compact() {
1089    return this.select(function(value) {
1090      return value != null;
1091    });
1092  }
1093
1094  function flatten() {
1095    return this.inject([], function(array, value) {
1096      if (Object.isArray(value))
1097        return array.concat(value.flatten());
1098      array.push(value);
1099      return array;
1100    });
1101  }
1102
1103  function without() {
1104    var values = slice.call(arguments, 0);
1105    return this.select(function(value) {
1106      return !values.include(value);
1107    });
1108  }
1109
1110  function reverse(inline) {
1111    return (inline === false ? this.toArray() : this)._reverse();
1112  }
1113
1114  function uniq(sorted) {
1115    return this.inject([], function(array, value, index) {
1116      if (0 == index || (sorted ? array.last() != value : !array.include(value)))
1117        array.push(value);
1118      return array;
1119    });
1120  }
1121
1122  function intersect(array) {
1123    return this.uniq().findAll(function(item) {
1124      return array.detect(function(value) { return item === value });
1125    });
1126  }
1127
1128
1129  function clone() {
1130    return slice.call(this, 0);
1131  }
1132
1133  function size() {
1134    return this.length;
1135  }
1136
1137  function inspect() {
1138    return '[' + this.map(Object.inspect).join(', ') + ']';
1139  }
1140
1141  function indexOf(item, i) {
1142    i || (i = 0);
1143    var length = this.length;
1144    if (i < 0) i = length + i;
1145    for (; i < length; i++)
1146      if (this[i] === item) return i;
1147    return -1;
1148  }
1149
1150  function lastIndexOf(item, i) {
1151    i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
1152    var n = this.slice(0, i).reverse().indexOf(item);
1153    return (n < 0) ? n : i - n - 1;
1154  }
1155
1156  function concat() {
1157    var array = slice.call(this, 0), item;
1158    for (var i = 0, length = arguments.length; i < length; i++) {
1159      item = arguments[i];
1160      if (Object.isArray(item) && !('callee' in item)) {
1161        for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
1162          array.push(item[j]);
1163      } else {
1164        array.push(item);
1165      }
1166    }
1167    return array;
1168  }
1169
1170  Object.extend(arrayProto, Enumerable);
1171
1172  if (!arrayProto._reverse)
1173    arrayProto._reverse = arrayProto.reverse;
1174
1175  Object.extend(arrayProto, {
1176    _each:     _each,
1177    clear:     clear,
1178    first:     first,
1179    last:      last,
1180    compact:   compact,
1181    flatten:   flatten,
1182    without:   without,
1183    reverse:   reverse,
1184    uniq:      uniq,
1185    intersect: intersect,
1186    clone:     clone,
1187    toArray:   clone,
1188    size:      size,
1189    inspect:   inspect
1190  });
1191
1192  var CONCAT_ARGUMENTS_BUGGY = (function() {
1193    return [].concat(arguments)[0][0] !== 1;
1194  })(1,2)
1195
1196  if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
1197
1198  if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
1199  if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
1200})();
1201function $H(object) {
1202  return new Hash(object);
1203};
1204
1205var Hash = Class.create(Enumerable, (function() {
1206  function initialize(object) {
1207    this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
1208  }
1209
1210
1211  function _each(iterator) {
1212    for (var key in this._object) {
1213      var value = this._object[key], pair = [key, value];
1214      pair.key = key;
1215      pair.value = value;
1216      iterator(pair);
1217    }
1218  }
1219
1220  function set(key, value) {
1221    return this._object[key] = value;
1222  }
1223
1224  function get(key) {
1225    if (this._object[key] !== Object.prototype[key])
1226      return this._object[key];
1227  }
1228
1229  function unset(key) {
1230    var value = this._object[key];
1231    delete this._object[key];
1232    return value;
1233  }
1234
1235  function toObject() {
1236    return Object.clone(this._object);
1237  }
1238
1239
1240
1241  function keys() {
1242    return this.pluck('key');
1243  }
1244
1245  function values() {
1246    return this.pluck('value');
1247  }
1248
1249  function index(value) {
1250    var match = this.detect(function(pair) {
1251      return pair.value === value;
1252    });
1253    return match && match.key;
1254  }
1255
1256  function merge(object) {
1257    return this.clone().update(object);
1258  }
1259
1260  function update(object) {
1261    return new Hash(object).inject(this, function(result, pair) {
1262      result.set(pair.key, pair.value);
1263      return result;
1264    });
1265  }
1266
1267  function toQueryPair(key, value) {
1268    if (Object.isUndefined(value)) return key;
1269    return key + '=' + encodeURIComponent(String.interpret(value));
1270  }
1271
1272  function toQueryString() {
1273    return this.inject([], function(results, pair) {
1274      var key = encodeURIComponent(pair.key), values = pair.value;
1275
1276      if (values && typeof values == 'object') {
1277        if (Object.isArray(values)) {
1278          var queryValues = [];
1279          for (var i = 0, len = values.length, value; i < len; i++) {
1280            value = values[i];
1281            queryValues.push(toQueryPair(key, value));
1282          }
1283          return results.concat(queryValues);
1284        }
1285      } else results.push(toQueryPair(key, values));
1286      return results;
1287    }).join('&');
1288  }
1289
1290  function inspect() {
1291    return '#<Hash:{' + this.map(function(pair) {
1292      return pair.map(Object.inspect).join(': ');
1293    }).join(', ') + '}>';
1294  }
1295
1296  function clone() {
1297    return new Hash(this);
1298  }
1299
1300  return {
1301    initialize:             initialize,
1302    _each:                  _each,
1303    set:                    set,
1304    get:                    get,
1305    unset:                  unset,
1306    toObject:               toObject,
1307    toTemplateReplacements: toObject,
1308    keys:                   keys,
1309    values:                 values,
1310    index:                  index,
1311    merge:                  merge,
1312    update:                 update,
1313    toQueryString:          toQueryString,
1314    inspect:                inspect,
1315    toJSON:                 toObject,
1316    clone:                  clone
1317  };
1318})());
1319
1320Hash.from = $H;
1321Object.extend(Number.prototype, (function() {
1322  function toColorPart() {
1323    return this.toPaddedString(2, 16);
1324  }
1325
1326  function succ() {
1327    return this + 1;
1328  }
1329
1330  function times(iterator, context) {
1331    $R(0, this, true).each(iterator, context);
1332    return this;
1333  }
1334
1335  function toPaddedString(length, radix) {
1336    var string = this.toString(radix || 10);
1337    return '0'.times(length - string.length) + string;
1338  }
1339
1340  function abs() {
1341    return Math.abs(this);
1342  }
1343
1344  function round() {
1345    return Math.round(this);
1346  }
1347
1348  function ceil() {
1349    return Math.ceil(this);
1350  }
1351
1352  function floor() {
1353    return Math.floor(this);
1354  }
1355
1356  return {
1357    toColorPart:    toColorPart,
1358    succ:           succ,
1359    times:          times,
1360    toPaddedString: toPaddedString,
1361    abs:            abs,
1362    round:          round,
1363    ceil:           ceil,
1364    floor:          floor
1365  };
1366})());
1367
1368function $R(start, end, exclusive) {
1369  return new ObjectRange(start, end, exclusive);
1370}
1371
1372var ObjectRange = Class.create(Enumerable, (function() {
1373  function initialize(start, end, exclusive) {
1374    this.start = start;
1375    this.end = end;
1376    this.exclusive = exclusive;
1377  }
1378
1379  function _each(iterator) {
1380    var value = this.start;
1381    while (this.include(value)) {
1382      iterator(value);
1383      value = value.succ();
1384    }
1385  }
1386
1387  function include(value) {
1388    if (value < this.start)
1389      return false;
1390    if (this.exclusive)
1391      return value < this.end;
1392    return value <= this.end;
1393  }
1394
1395  return {
1396    initialize: initialize,
1397    _each:      _each,
1398    include:    include
1399  };
1400})());
1401
1402
1403
1404var Abstract = { };
1405
1406
1407var Try = {
1408  these: function() {
1409    var returnValue;
1410
1411    for (var i = 0, length = arguments.length; i < length; i++) {
1412      var lambda = arguments[i];
1413      try {
1414        returnValue = lambda();
1415        break;
1416      } catch (e) { }
1417    }
1418
1419    return returnValue;
1420  }
1421};
1422
1423var Ajax = {
1424  getTransport: function() {
1425    return Try.these(
1426      function() {return new XMLHttpRequest()},
1427      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
1428      function() {return new ActiveXObject('Microsoft.XMLHTTP')}
1429    ) || false;
1430  },
1431
1432  activeRequestCount: 0
1433};
1434
1435Ajax.Responders = {
1436  responders: [],
1437
1438  _each: function(iterator) {
1439    this.responders._each(iterator);
1440  },
1441
1442  register: function(responder) {
1443    if (!this.include(responder))
1444      this.responders.push(responder);
1445  },
1446
1447  unregister: function(responder) {
1448    this.responders = this.responders.without(responder);
1449  },
1450
1451  dispatch: function(callback, request, transport, json) {
1452    this.each(function(responder) {
1453      if (Object.isFunction(responder[callback])) {
1454        try {
1455          responder[callback].apply(responder, [request, transport, json]);
1456        } catch (e) { }
1457      }
1458    });
1459  }
1460};
1461
1462Object.extend(Ajax.Responders, Enumerable);
1463
1464Ajax.Responders.register({
1465  onCreate:   function() { Ajax.activeRequestCount++ },
1466  onComplete: function() { Ajax.activeRequestCount-- }
1467});
1468Ajax.Base = Class.create({
1469  initialize: function(options) {
1470    this.options = {
1471      method:       'post',
1472      asynchronous: true,
1473      contentType:  'application/x-www-form-urlencoded',
1474      encoding:     'UTF-8',
1475      parameters:   '',
1476      evalJSON:     true,
1477      evalJS:       true
1478    };
1479    Object.extend(this.options, options || { });
1480
1481    this.options.method = this.options.method.toLowerCase();
1482
1483    if (Object.isHash(this.options.parameters))
1484      this.options.parameters = this.options.parameters.toObject();
1485  }
1486});
1487Ajax.Request = Class.create(Ajax.Base, {
1488  _complete: false,
1489
1490  initialize: function($super, url, options) {
1491    $super(options);
1492    this.transport = Ajax.getTransport();
1493    this.request(url);
1494  },
1495
1496  request: function(url) {
1497    this.url = url;
1498    this.method = this.options.method;
1499    var params = Object.isString(this.options.parameters) ?
1500          this.options.parameters :
1501          Object.toQueryString(this.options.parameters);
1502
1503    if (!['get', 'post'].include(this.method)) {
1504      params += (params ? '&' : '') + "_method=" + this.method;
1505      this.method = 'post';
1506    }
1507
1508    if (params && this.method === 'get') {
1509      this.url += (this.url.include('?') ? '&' : '?') + params;
1510    }
1511
1512    this.parameters = params.toQueryParams();
1513
1514    try {
1515      var response = new Ajax.Response(this);
1516      if (this.options.onCreate) this.options.onCreate(response);
1517      Ajax.Responders.dispatch('onCreate', this, response);
1518
1519      this.transport.open(this.method.toUpperCase(), this.url,
1520        this.options.asynchronous);
1521
1522      if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
1523
1524      this.transport.onreadystatechange = this.onStateChange.bind(this);
1525      this.setRequestHeaders();
1526
1527      this.body = this.method == 'post' ? (this.options.postBody || params) : null;
1528      this.transport.send(this.body);
1529
1530      /* Force Firefox to handle ready state 4 for synchronous requests */
1531      if (!this.options.asynchronous && this.transport.overrideMimeType)
1532        this.onStateChange();
1533
1534    }
1535    catch (e) {
1536      this.dispatchException(e);
1537    }
1538  },
1539
1540  onStateChange: function() {
1541    var readyState = this.transport.readyState;
1542    if (readyState > 1 && !((readyState == 4) && this._complete))
1543      this.respondToReadyState(this.transport.readyState);
1544  },
1545
1546  setRequestHeaders: function() {
1547    var headers = {
1548      'X-Requested-With': 'XMLHttpRequest',
1549      'X-Prototype-Version': Prototype.Version,
1550      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
1551    };
1552
1553    if (this.method == 'post') {
1554      headers['Content-type'] = this.options.contentType +
1555        (this.options.encoding ? '; charset=' + this.options.encoding : '');
1556
1557      /* Force "Connection: close" for older Mozilla browsers to work
1558       * around a bug where XMLHttpRequest sends an incorrect
1559       * Content-length header. See Mozilla Bugzilla #246651.
1560       */
1561      if (this.transport.overrideMimeType &&
1562          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
1563            headers['Connection'] = 'close';
1564    }
1565
1566    if (typeof this.options.requestHeaders == 'object') {
1567      var extras = this.options.requestHeaders;
1568
1569      if (Object.isFunction(extras.push))
1570        for (var i = 0, length = extras.length; i < length; i += 2)
1571          headers[extras[i]] = extras[i+1];
1572      else
1573        $H(extras).each(function(pair) { headers[pair.key] = pair.value });
1574    }
1575
1576    for (var name in headers)
1577      this.transport.setRequestHeader(name, headers[name]);
1578  },
1579
1580  success: function() {
1581    var status = this.getStatus();
1582    return !status || (status >= 200 && status < 300) || status == 304;
1583  },
1584
1585  getStatus: function() {
1586    try {
1587      if (this.transport.status === 1223) return 204;
1588      return this.transport.status || 0;
1589    } catch (e) { return 0 }
1590  },
1591
1592  respondToReadyState: function(readyState) {
1593    var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
1594
1595    if (state == 'Complete') {
1596      try {
1597        this._complete = true;
1598        (this.options['on' + response.status]
1599         || this.options['on' + (this.success() ? 'Success' : 'Failure')]
1600         || Prototype.emptyFunction)(response, response.headerJSON);
1601      } catch (e) {
1602        this.dispatchException(e);
1603      }
1604
1605      var contentType = response.getHeader('Content-type');
1606      if (this.options.evalJS == 'force'
1607          || (this.options.evalJS && this.isSameOrigin() && contentType
1608          && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
1609        this.evalResponse();
1610    }
1611
1612    try {
1613      (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
1614      Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
1615    } catch (e) {
1616      this.dispatchException(e);
1617    }
1618
1619    if (state == 'Complete') {
1620      this.transport.onreadystatechange = Prototype.emptyFunction;
1621    }
1622  },
1623
1624  isSameOrigin: function() {
1625    var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
1626    return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
1627      protocol: location.protocol,
1628      domain: document.domain,
1629      port: location.port ? ':' + location.port : ''
1630    }));
1631  },
1632
1633  getHeader: function(name) {
1634    try {
1635      return this.transport.getResponseHeader(name) || null;
1636    } catch (e) { return null; }
1637  },
1638
1639  evalResponse: function() {
1640    try {
1641      return eval((this.transport.responseText || '').unfilterJSON());
1642    } catch (e) {
1643      this.dispatchException(e);
1644    }
1645  },
1646
1647  dispatchException: function(exception) {
1648    (this.options.onException || Prototype.emptyFunction)(this, exception);
1649    Ajax.Responders.dispatch('onException', this, exception);
1650  }
1651});
1652
1653Ajax.Request.Events =
1654  ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
1655
1656
1657
1658
1659
1660
1661
1662
1663Ajax.Response = Class.create({
1664  initialize: function(request){
1665    this.request = request;
1666    var transport  = this.transport  = request.transport,
1667        readyState = this.readyState = transport.readyState;
1668
1669    if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
1670      this.status       = this.getStatus();
1671      this.statusText   = this.getStatusText();
1672      this.responseText = String.interpret(transport.responseText);
1673      this.headerJSON   = this._getHeaderJSON();
1674    }
1675
1676    if (readyState == 4) {
1677      var xml = transport.responseXML;
1678      this.responseXML  = Object.isUndefined(xml) ? null : xml;
1679      this.responseJSON = this._getResponseJSON();
1680    }
1681  },
1682
1683  status:      0,
1684
1685  statusText: '',
1686
1687  getStatus: Ajax.Request.prototype.getStatus,
1688
1689  getStatusText: function() {
1690    try {
1691      return this.transport.statusText || '';
1692    } catch (e) { return '' }
1693  },
1694
1695  getHeader: Ajax.Request.prototype.getHeader,
1696
1697  getAllHeaders: function() {
1698    try {
1699      return this.getAllResponseHeaders();
1700    } catch (e) { return null }
1701  },
1702
1703  getResponseHeader: function(name) {
1704    return this.transport.getResponseHeader(name);
1705  },
1706
1707  getAllResponseHeaders: function() {
1708    return this.transport.getAllResponseHeaders();
1709  },
1710
1711  _getHeaderJSON: function() {
1712    var json = this.getHeader('X-JSON');
1713    if (!json) return null;
1714    json = decodeURIComponent(escape(json));
1715    try {
1716      return json.evalJSON(this.request.options.sanitizeJSON ||
1717        !this.request.isSameOrigin());
1718    } catch (e) {
1719      this.request.dispatchException(e);
1720    }
1721  },
1722
1723  _getResponseJSON: function() {
1724    var options = this.request.options;
1725    if (!options.evalJSON || (options.evalJSON != 'force' &&
1726      !(this.getHeader('Content-type') || '').include('application/json')) ||
1727        this.responseText.blank())
1728          return null;
1729    try {
1730      return this.responseText.evalJSON(options.sanitizeJSON ||
1731        !this.request.isSameOrigin());
1732    } catch (e) {
1733      this.request.dispatchException(e);
1734    }
1735  }
1736});
1737
1738Ajax.Updater = Class.create(Ajax.Request, {
1739  initialize: function($super, container, url, options) {
1740    this.container = {
1741      success: (container.success || container),
1742      failure: (container.failure || (container.success ? null : container))
1743    };
1744
1745    options = Object.clone(options);
1746    var onComplete = options.onComplete;
1747    options.onComplete = (function(response, json) {
1748      this.updateContent(response.responseText);
1749      if (Object.isFunction(onComplete)) onComplete(response, json);
1750    }).bind(this);
1751
1752    $super(url, options);
1753  },
1754
1755  updateContent: function(responseText) {
1756    var receiver = this.container[this.success() ? 'success' : 'failure'],
1757        options = this.options;
1758
1759    if (!options.evalScripts) responseText = responseText.stripScripts();
1760
1761    if (receiver = $(receiver)) {
1762      if (options.insertion) {
1763        if (Object.isString(options.insertion)) {
1764          var insertion = { }; insertion[options.insertion] = responseText;
1765          receiver.insert(insertion);
1766        }
1767        else options.insertion(receiver, responseText);
1768      }
1769      else receiver.update(responseText);
1770    }
1771  }
1772});
1773
1774Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
1775  initialize: function($super, container, url, options) {
1776    $super(options);
1777    this.onComplete = this.options.onComplete;
1778
1779    this.frequency = (this.options.frequency || 2);
1780    this.decay = (this.options.decay || 1);
1781
1782    this.updater = { };
1783    this.container = container;
1784    this.url = url;
1785
1786    this.start();
1787  },
1788
1789  start: function() {
1790    this.options.onComplete = this.updateComplete.bind(this);
1791    this.onTimerEvent();
1792  },
1793
1794  stop: function() {
1795    this.updater.options.onComplete = undefined;
1796    clearTimeout(this.timer);
1797    (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
1798  },
1799
1800  updateComplete: function(response) {
1801    if (this.options.decay) {
1802      this.decay = (response.responseText == this.lastText ?
1803        this.decay * this.options.decay : 1);
1804
1805      this.lastText = response.responseText;
1806    }
1807    this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
1808  },
1809
1810  onTimerEvent: function() {
1811    this.updater = new Ajax.Updater(this.container, this.url, this.options);
1812  }
1813});
1814
1815
1816function $(element) {
1817  if (arguments.length > 1) {
1818    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
1819      elements.push($(arguments[i]));
1820    return elements;
1821  }
1822  if (Object.isString(element))
1823    element = document.getElementById(element);
1824  return Element.extend(element);
1825}
1826
1827if (Prototype.BrowserFeatures.XPath) {
1828  document._getElementsByXPath = function(expression, parentElement) {
1829    var results = [];
1830    var query = document.evaluate(expression, $(parentElement) || document,
1831      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
1832    for (var i = 0, length = query.snapshotLength; i < length; i++)
1833      results.push(Element.extend(query.snapshotItem(i)));
1834    return results;
1835  };
1836}
1837
1838/*--------------------------------------------------------------------------*/
1839
1840if (!Node) var Node = { };
1841
1842if (!Node.ELEMENT_NODE) {
1843  Object.extend(Node, {
1844    ELEMENT_NODE: 1,
1845    ATTRIBUTE_NODE: 2,
1846    TEXT_NODE: 3,
1847    CDATA_SECTION_NODE: 4,
1848    ENTITY_REFERENCE_NODE: 5,
1849    ENTITY_NODE: 6,
1850    PROCESSING_INSTRUCTION_NODE: 7,
1851    COMMENT_NODE: 8,
1852    DOCUMENT_NODE: 9,
1853    DOCUMENT_TYPE_NODE: 10,
1854    DOCUMENT_FRAGMENT_NODE: 11,
1855    NOTATION_NODE: 12
1856  });
1857}
1858
1859
1860
1861(function(global) {
1862  function shouldUseCache(tagName, attributes) {
1863    if (tagName === 'select') return false;
1864    if ('type' in attributes) return false;
1865    return true;
1866  }
1867
1868  var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
1869    try {
1870      var el = document.createElement('<input name="x">');
1871      return el.tagName.toLowerCase() === 'input' && el.name === 'x';
1872    }
1873    catch(err) {
1874      return false;
1875    }
1876  })();
1877
1878  var element = global.Element;
1879
1880  global.Element = function(tagName, attributes) {
1881    attributes = attributes || { };
1882    tagName = tagName.toLowerCase();
1883    var cache = Element.cache;
1884
1885    if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) {
1886      tagName = '<' + tagName + ' name="' + attributes.name + '">';
1887      delete attributes.name;
1888      return Element.writeAttribute(document.createElement(tagName), attributes);
1889    }
1890
1891    if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
1892
1893    var node = shouldUseCache(tagName, attributes) ?
1894     cache[tagName].cloneNode(false) : document.createElement(tagName);
1895
1896    return Element.writeAttribute(node, attributes);
1897  };
1898
1899  Object.extend(global.Element, element || { });
1900  if (element) global.Element.prototype = element.prototype;
1901
1902})(this);
1903
1904Element.idCounter = 1;
1905Element.cache = { };
1906
1907Element._purgeElement = function(element) {
1908  var uid = element._prototypeUID;
1909  if (uid) {
1910    Element.stopObserving(element);
1911    element._prototypeUID = void 0;
1912    delete Element.Storage[uid];
1913  }
1914}
1915
1916Element.Methods = {
1917  visible: function(element) {
1918    return $(element).style.display != 'none';
1919  },
1920
1921  toggle: function(element) {
1922    element = $(element);
1923    Element[Element.visible(element) ? 'hide' : 'show'](element);
1924    return element;
1925  },
1926
1927  hide: function(element) {
1928    element = $(element);
1929    element.style.display = 'none';
1930    return element;
1931  },
1932
1933  show: function(element) {
1934    element = $(element);
1935    element.style.display = '';
1936    return element;
1937  },
1938
1939  remove: function(element) {
1940    element = $(element);
1941    element.parentNode.removeChild(element);
1942    return element;
1943  },
1944
1945  update: (function(){
1946
1947    var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
1948      var el = document.createElement("select"),
1949          isBuggy = true;
1950      el.innerHTML = "<option value=\"test\">test</option>";
1951      if (el.options && el.options[0]) {
1952        isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
1953      }
1954      el = null;
1955      return isBuggy;
1956    })();
1957
1958    var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
1959      try {
1960        var el = document.createElement("table");
1961        if (el && el.tBodies) {
1962          el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
1963          var isBuggy = typeof el.tBodies[0] == "undefined";
1964          el = null;
1965          return isBuggy;
1966        }
1967      } catch (e) {
1968        return true;
1969      }
1970    })();
1971
1972    var LINK_ELEMENT_INNERHTML_BUGGY = (function() {
1973      try {
1974        var el = document.createElement('div');
1975        el.innerHTML = "<link>";
1976        var isBuggy = (el.childNodes.length === 0);
1977        el = null;
1978        return isBuggy;
1979      } catch(e) {
1980        return true;
1981      }
1982    })();
1983
1984    var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY ||
1985     TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY;
1986
1987    var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
1988      var s = document.createElement("script"),
1989          isBuggy = false;
1990      try {
1991        s.appendChild(document.createTextNode(""));
1992        isBuggy = !s.firstChild ||
1993          s.firstChild && s.firstChild.nodeType !== 3;
1994      } catch (e) {
1995        isBuggy = true;
1996      }
1997      s = null;
1998      return isBuggy;
1999    })();
2000
2001
2002    function update(element, content) {
2003      element = $(element);
2004      var purgeElement = Element._purgeElement;
2005
2006      var descendants = element.getElementsByTagName('*'),
2007       i = descendants.length;
2008      while (i--) purgeElement(descendants[i]);
2009
2010      if (content && content.toElement)
2011        content = content.toElement();
2012
2013      if (Object.isElement(content))
2014        return element.update().insert(content);
2015
2016      content = Object.toHTML(content);
2017
2018      var tagName = element.tagName.toUpperCase();
2019
2020      if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
2021        element.text = content;
2022        return element;
2023      }
2024
2025      if (ANY_INNERHTML_BUGGY) {
2026        if (tagName in Element._insertionTranslations.tags) {
2027          while (element.firstChild) {
2028            element.removeChild(element.firstChild);
2029          }
2030          Element._getContentFromAnonymousElement(tagName, content.stripScripts())
2031            .each(function(node) {
2032              element.appendChild(node)
2033            });
2034        } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf('<link') > -1) {
2035          while (element.firstChild) {
2036            element.removeChild(element.firstChild);
2037          }
2038          var nodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts(), true);
2039          nodes.each(function(node) { element.appendChild(node) });
2040        }
2041        else {
2042          element.innerHTML = content.stripScripts();
2043        }
2044      }
2045      else {
2046        element.innerHTML = content.stripScripts();
2047      }
2048
2049      content.evalScripts.bind(content).defer();
2050      return element;
2051    }
2052
2053    return update;
2054  })(),
2055
2056  replace: function(element, content) {
2057    element = $(element);
2058    if (content && content.toElement) content = content.toElement();
2059    else if (!Object.isElement(content)) {
2060      content = Object.toHTML(content);
2061      var range = element.ownerDocument.createRange();
2062      range.selectNode(element);
2063      content.evalScripts.bind(content).defer();
2064      content = range.createContextualFragment(content.stripScripts());
2065    }
2066    element.parentNode.replaceChild(content, element);
2067    return element;
2068  },
2069
2070  insert: function(element, insertions) {
2071    element = $(element);
2072
2073    if (Object.isString(insertions) || Object.isNumber(insertions) ||
2074        Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
2075          insertions = {bottom:insertions};
2076
2077    var content, insert, tagName, childNodes;
2078
2079    for (var position in insertions) {
2080      content  = insertions[position];
2081      position = position.toLowerCase();
2082      insert = Element._insertionTranslations[position];
2083
2084      if (content && content.toElement) content = content.toElement();
2085      if (Object.isElement(content)) {
2086        insert(element, content);
2087        continue;
2088      }
2089
2090      content = Object.toHTML(content);
2091
2092      tagName = ((position == 'before' || position == 'after')
2093        ? element.parentNode : element).tagName.toUpperCase();
2094
2095      childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
2096
2097      if (position == 'top' || position == 'after') childNodes.reverse();
2098      childNodes.each(insert.curry(element));
2099
2100      content.evalScripts.bind(content).defer();
2101    }
2102
2103    return element;
2104  },
2105
2106  wrap: function(element, wrapper, attributes) {
2107    element = $(element);
2108    if (Object.isElement(wrapper))
2109      $(wrapper).writeAttribute(attributes || { });
2110    else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
2111    else wrapper = new Element('div', wrapper);
2112    if (element.parentNode)
2113      element.parentNode.replaceChild(wrapper, element);
2114    wrapper.appendChild(element);
2115    return wrapper;
2116  },
2117
2118  inspect: function(element) {
2119    element = $(element);
2120    var result = '<' + element.tagName.toLowerCase();
2121    $H({'id': 'id', 'className': 'class'}).each(function(pair) {
2122      var property = pair.first(),
2123          attribute = pair.last(),
2124          value = (element[property] || '').toString();
2125      if (value) result += ' ' + attribute + '=' + value.inspect(true);
2126    });
2127    return result + '>';
2128  },
2129
2130  recursivelyCollect: function(element, property, maximumLength) {
2131    element = $(element);
2132    maximumLength = maximumLength || -1;
2133    var elements = [];
2134
2135    while (element = element[property]) {
2136      if (element.nodeType == 1)
2137        elements.push(Element.extend(element));
2138      if (elements.length == maximumLength)
2139        break;
2140    }
2141
2142    return elements;
2143  },
2144
2145  ancestors: function(element) {
2146    return Element.recursivelyCollect(element, 'parentNode');
2147  },
2148
2149  descendants: function(element) {
2150    return Element.select(element, "*");
2151  },
2152
2153  firstDescendant: function(element) {
2154    element = $(element).firstChild;
2155    while (element && element.nodeType != 1) element = element.nextSibling;
2156    return $(element);
2157  },
2158
2159  immediateDescendants: function(element) {
2160    var results = [], child = $(element).firstChild;
2161    while (child) {
2162      if (child.nodeType === 1) {
2163        results.push(Element.extend(child));
2164      }
2165      child = child.nextSibling;
2166    }
2167    return results;
2168  },
2169
2170  previousSiblings: function(element, maximumLength) {
2171    return Element.recursivelyCollect(element, 'previousSibling');
2172  },
2173
2174  nextSiblings: function(element) {
2175    return Element.recursivelyCollect(element, 'nextSibling');
2176  },
2177
2178  siblings: function(element) {
2179    element = $(element);
2180    return Element.previousSiblings(element).reverse()
2181      .concat(Element.nextSiblings(element));
2182  },
2183
2184  match: function(element, selector) {
2185    element = $(element);
2186    if (Object.isString(selector))
2187      return Prototype.Selector.match(element, selector);
2188    return selector.match(element);
2189  },
2190
2191  up: function(element, expression, index) {
2192    element = $(element);
2193    if (arguments.length == 1) return $(element.parentNode);
2194    var ancestors = Element.ancestors(element);
2195    return Object.isNumber(expression) ? ancestors[expression] :
2196      Prototype.Selector.find(ancestors, expression, index);
2197  },
2198
2199  down: function(element, expression, index) {
2200    element = $(element);
2201    if (arguments.length == 1) return Element.firstDescendant(element);
2202    return Object.isNumber(expression) ? Element.descendants(element)[expression] :
2203      Element.select(element, expression)[index || 0];
2204  },
2205
2206  previous: function(element, expression, index) {
2207    element = $(element);
2208    if (Object.isNumber(expression)) index = expression, expression = false;
2209    if (!Object.isNumber(index)) index = 0;
2210
2211    if (expression) {
2212      return Prototype.Selector.find(element.previousSiblings(), expression, index);
2213    } else {
2214      return element.recursivelyCollect("previousSibling", index + 1)[index];
2215    }
2216  },
2217
2218  next: function(element, expression, index) {
2219    element = $(element);
2220    if (Object.isNumber(expression)) index = expression, expression = false;
2221    if (!Object.isNumber(index)) index = 0;
2222
2223    if (expression) {
2224      return Prototype.Selector.find(element.nextSiblings(), expression, index);
2225    } else {
2226      var maximumLength = Object.isNumber(index) ? index + 1 : 1;
2227      return element.recursivelyCollect("nextSibling", index + 1)[index];
2228    }
2229  },
2230
2231
2232  select: function(element) {
2233    element = $(element);
2234    var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
2235    return Prototype.Selector.select(expressions, element);
2236  },
2237
2238  adjacent: function(element) {
2239    element = $(element);
2240    var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
2241    return Prototype.Selector.select(expressions, element.parentNode).without(element);
2242  },
2243
2244  identify: function(element) {
2245    element = $(element);
2246    var id = Element.readAttribute(element, 'id');
2247    if (id) return id;
2248    do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id));
2249    Element.writeAttribute(element, 'id', id);
2250    return id;
2251  },
2252
2253  readAttribute: function(element, name) {
2254    element = $(element);
2255    if (Prototype.Browser.IE) {
2256      var t = Element._attributeTranslations.read;
2257      if (t.values[name]) return t.values[name](element, name);
2258      if (t.names[name]) name = t.names[name];
2259      if (name.include(':')) {
2260        return (!element.attributes || !element.attributes[name]) ? null :
2261         element.attributes[name].value;
2262      }
2263    }
2264    return element.getAttribute(name);
2265  },
2266
2267  writeAttribute: function(element, name, value) {
2268    element = $(element);
2269    var attributes = { }, t = Element._attributeTranslations.write;
2270
2271    if (typeof name == 'object') attributes = name;
2272    else attributes[name] = Object.isUndefined(value) ? true : value;
2273
2274    for (var attr in attributes) {
2275      name = t.names[attr] || attr;
2276      value = attributes[attr];
2277      if (t.values[attr]) name = t.values[attr](element, value);
2278      if (value === false || value === null)
2279        element.removeAttribute(name);
2280      else if (value === true)
2281        element.setAttribute(name, name);
2282      else element.setAttribute(name, value);
2283    }
2284    return element;
2285  },
2286
2287  getHeight: function(element) {
2288    return Element.getDimensions(element).height;
2289  },
2290
2291  getWidth: function(element) {
2292    return Element.getDimensions(element).width;
2293  },
2294
2295  classNames: function(element) {
2296    return new Element.ClassNames(element);
2297  },
2298
2299  hasClassName: function(element, className) {
2300    if (!(element = $(element))) return;
2301    var elementClassName = element.className;
2302    return (elementClassName.length > 0 && (elementClassName == className ||
2303      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
2304  },
2305
2306  addClassName: function(element, className) {
2307    if (!(element = $(element))) return;
2308    if (!Element.hasClassName(element, className))
2309      element.className += (element.className ? ' ' : '') + className;
2310    return element;
2311  },
2312
2313  removeClassName: function(element, className) {
2314    if (!(element = $(element))) return;
2315    element.className = element.className.replace(
2316      new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
2317    return element;
2318  },
2319
2320  toggleClassName: function(element, className) {
2321    if (!(element = $(element))) return;
2322    return Element[Element.hasClassName(element, className) ?
2323      'removeClassName' : 'addClassName'](element, className);
2324  },
2325
2326  cleanWhitespace: function(element) {
2327    element = $(element);
2328    var node = element.firstChild;
2329    while (node) {
2330      var nextNode = node.nextSibling;
2331      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
2332        element.removeChild(node);
2333      node = nextNode;
2334    }
2335    return element;
2336  },
2337
2338  empty: function(element) {
2339    return $(element).innerHTML.blank();
2340  },
2341
2342  descendantOf: function(element, ancestor) {
2343    element = $(element), ancestor = $(ancestor);
2344
2345    if (element.compareDocumentPosition)
2346      return (element.compareDocumentPosition(ancestor) & 8) === 8;
2347
2348    if (ancestor.contains)
2349      return ancestor.contains(element) && ancestor !== element;
2350
2351    while (element = element.parentNode)
2352      if (element == ancestor) return true;
2353
2354    return false;
2355  },
2356
2357  scrollTo: function(element) {
2358    element = $(element);
2359    var pos = Element.cumulativeOffset(element);
2360    window.scrollTo(pos[0], pos[1]);
2361    return element;
2362  },
2363
2364  getStyle: function(element, style) {
2365    element = $(element);
2366    style = style == 'float' ? 'cssFloat' : style.camelize();
2367    var value = element.style[style];
2368    if (!value || value == 'auto') {
2369      var css = document.defaultView.getComputedStyle(element, null);
2370      value = css ? css[style] : null;
2371    }
2372    if (style == 'opacity') return value ? parseFloat(value) : 1.0;
2373    return value == 'auto' ? null : value;
2374  },
2375
2376  getOpacity: function(element) {
2377    return $(element).getStyle('opacity');
2378  },
2379
2380  setStyle: function(element, styles) {
2381    element = $(element);
2382    var elementStyle = element.style, match;
2383    if (Object.isString(styles)) {
2384      element.style.cssText += ';' + styles;
2385      return styles.include('opacity') ?
2386        element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
2387    }
2388    for (var property in styles)
2389      if (property == 'opacity') element.setOpacity(styles[property]);
2390      else
2391        elementStyle[(property == 'float' || property == 'cssFloat') ?
2392          (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
2393            property] = styles[property];
2394
2395    return element;
2396  },
2397
2398  setOpacity: function(element, value) {
2399    element = $(element);
2400    element.style.opacity = (value == 1 || value === '') ? '' :
2401      (value < 0.00001) ? 0 : value;
2402    return element;
2403  },
2404
2405  makePositioned: function(element) {
2406    element = $(element);
2407    var pos = Element.getStyle(element, 'position');
2408    if (pos == 'static' || !pos) {
2409      element._madePositioned = true;
2410      element.style.position = 'relative';
2411      if (Prototype.Browser.Opera) {
2412        element.style.top = 0;
2413        element.style.left = 0;
2414      }
2415    }
2416    return element;
2417  },
2418
2419  undoPositioned: function(element) {
2420    element = $(element);
2421    if (element._madePositioned) {
2422      element._madePositioned = undefined;
2423      element.style.position =
2424        element.style.top =
2425        element.style.left =
2426        element.style.bottom =
2427        element.style.right = '';
2428    }
2429    return element;
2430  },
2431
2432  makeClipping: function(element) {
2433    element = $(element);
2434    if (element._overflow) return element;
2435    element._overflow = Element.getStyle(element, 'overflow') || 'auto';
2436    if (element._overflow !== 'hidden')
2437      element.style.overflow = 'hidden';
2438    return element;
2439  },
2440
2441  undoClipping: function(element) {
2442    element = $(element);
2443    if (!element._overflow) return element;
2444    element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
2445    element._overflow = null;
2446    return element;
2447  },
2448
2449  clonePosition: function(element, source) {
2450    var options = Object.extend({
2451      setLeft:    true,
2452      setTop:     true,
2453      setWidth:   true,
2454      setHeight:  true,
2455      offsetTop:  0,
2456      offsetLeft: 0
2457    }, arguments[2] || { });
2458
2459    source = $(source);
2460    var p = Element.viewportOffset(source), delta = [0, 0], parent = null;
2461
2462    element = $(element);
2463
2464    if (Element.getStyle(element, 'position') == 'absolute') {
2465      parent = Element.getOffsetParent(element);
2466      delta = Element.viewportOffset(parent);
2467    }
2468
2469    if (parent == document.body) {
2470      delta[0] -= document.body.offsetLeft;
2471      delta[1] -= document.body.offsetTop;
2472    }
2473
2474    if (options.setLeft)   element.style.left  = (p[0] - delta[0] + options.offsetLeft) + 'px';
2475    if (options.setTop)    element.style.top   = (p[1] - delta[1] + options.offsetTop) + 'px';
2476    if (options.setWidth)  element.style.width = source.offsetWidth + 'px';
2477    if (options.setHeight) element.style.height = source.offsetHeight + 'px';
2478    return element;
2479  }
2480};
2481
2482Object.extend(Element.Methods, {
2483  getElementsBySelector: Element.Methods.select,
2484
2485  childElements: Element.Methods.immediateDescendants
2486});
2487
2488Element._attributeTranslations = {
2489  write: {
2490    names: {
2491      className: 'class',
2492      htmlFor:   'for'
2493    },
2494    values: { }
2495  }
2496};
2497
2498if (Prototype.Browser.Opera) {
2499  Element.Methods.getStyle = Element.Methods.getStyle.wrap(
2500    function(proceed, element, style) {
2501      switch (style) {
2502        case 'height': case 'width':
2503          if (!Element.visible(element)) return null;
2504
2505          var dim = parseInt(proceed(element, style), 10);
2506
2507          if (dim !== element['offset' + style.capitalize()])
2508            return dim + 'px';
2509
2510          var properties;
2511          if (style === 'height') {
2512            properties = ['border-top-width', 'padding-top',
2513             'padding-bottom', 'border-bottom-width'];
2514          }
2515          else {
2516            properties = ['border-left-width', 'padding-left',
2517             'padding-right', 'border-right-width'];
2518          }
2519          return properties.inject(dim, function(memo, property) {
2520            var val = proceed(element, property);
2521            return val === null ? memo : memo - parseInt(val, 10);
2522          }) + 'px';
2523        default: return proceed(element, style);
2524      }
2525    }
2526  );
2527
2528  Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
2529    function(proceed, element, attribute) {
2530      if (attribute === 'title') return element.title;
2531      return proceed(element, attribute);
2532    }
2533  );
2534}
2535
2536else if (Prototype.Browser.IE) {
2537  Element.Methods.getStyle = function(element, style) {
2538    element = $(element);
2539    style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
2540    var value = element.style[style];
2541    if (!value && element.currentStyle) value = element.currentStyle[style];
2542if(navigator.appVersion.match(/MSIE ([\d.]+)/)[1] < 10){
2543    if (style == 'opacity') {
2544      if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
2545        if (value[1]) return parseFloat(value[1]) / 100;
2546      return 1.0;
2547    }
2548}
2549    if (value == 'auto') {
2550      if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
2551        return element['offset' + style.capitalize()] + 'px';
2552      return null;
2553    }
2554    return value;
2555  };
2556if(navigator.appVersion.match(/MSIE ([\d.]+)/)[1] < 10){
2557  Element.Methods.setOpacity = function(element, value) {
2558    function stripAlpha(filter){
2559      return filter.replace(/alpha\([^\)]*\)/gi,'');
2560    }
2561    element = $(element);
2562    var currentStyle = element.currentStyle;
2563    if ((currentStyle && !currentStyle.hasLayout) ||
2564      (!currentStyle && element.style.zoom == 'normal'))
2565        element.style.zoom = 1;
2566
2567    var filter = element.getStyle('filter'), style = element.style;
2568    if (value == 1 || value === '') {
2569      (filter = stripAlpha(filter)) ?
2570        style.filter = filter : style.removeAttribute('filter');
2571      return element;
2572    } else if (value < 0.00001) value = 0;
2573    style.filter = stripAlpha(filter) +
2574      'alpha(opacity=' + (value * 100) + ')';
2575    return element;
2576  };
2577}
2578  Element._attributeTranslations = (function(){
2579
2580    var classProp = 'className',
2581        forProp = 'for',
2582        el = document.createElement('div');
2583
2584    el.setAttribute(classProp, 'x');
2585
2586    if (el.className !== 'x') {
2587      el.setAttribute('class', 'x');
2588      if (el.className === 'x') {
2589        classProp = 'class';
2590      }
2591    }
2592    el = null;
2593
2594    el = document.createElement('label');
2595    el.setAttribute(forProp, 'x');
2596    if (el.htmlFor !== 'x') {
2597      el.setAttribute('htmlFor', 'x');
2598      if (el.htmlFor === 'x') {
2599        forProp = 'htmlFor';
2600      }
2601    }
2602    el = null;
2603
2604    return {
2605      read: {
2606        names: {
2607          'class':      classProp,
2608          'className':  classProp,
2609          'for':        forProp,
2610          'htmlFor':    forProp
2611        },
2612        values: {
2613          _getAttr: function(element, attribute) {
2614            return element.getAttribute(attribute);
2615          },
2616          _getAttr2: function(element, attribute) {
2617            return element.getAttribute(attribute, 2);
2618          },
2619          _getAttrNode: function(element, attribute) {
2620            var node = element.getAttributeNode(attribute);
2621            return node ? node.value : "";
2622          },
2623          _getEv: (function(){
2624
2625            var el = document.createElement('div'), f;
2626            el.onclick = Prototype.emptyFunction;
2627            var value = el.getAttribute('onclick');
2628
2629            if (String(value).indexOf('{') > -1) {
2630              f = function(element, attribute) {
2631                attribute = element.getAttribute(attribute);
2632                if (!attribute) return null;
2633                attribute = attribute.toString();
2634                attribute = attribute.split('{')[1];
2635                attribute = attribute.split('}')[0];
2636                return attribute.strip();
2637              };
2638            }
2639            else if (value === '') {
2640              f = function(element, attribute) {
2641                attribute = element.getAttribute(attribute);
2642                if (!attribute) return null;
2643                return attribute.strip();
2644              };
2645            }
2646            el = null;
2647            return f;
2648          })(),
2649          _flag: function(element, attribute) {
2650            return $(element).hasAttribute(attribute) ? attribute : null;
2651          },
2652          style: function(element) {
2653            return element.style.cssText.toLowerCase();
2654          },
2655          title: function(element) {
2656            return element.title;
2657          }
2658        }
2659      }
2660    }
2661  })();
2662
2663  Element._attributeTranslations.write = {
2664    names: Object.extend({
2665      cellpadding: 'cellPadding',
2666      cellspacing: 'cellSpacing'
2667    }, Element._attributeTranslations.read.names),
2668    values: {
2669      checked: function(element, value) {
2670        element.checked = !!value;
2671      },
2672
2673      style: function(element, value) {
2674        element.style.cssText = value ? value : '';
2675      }
2676    }
2677  };
2678
2679  Element._attributeTranslations.has = {};
2680
2681  $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
2682      'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
2683    Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
2684    Element._attributeTranslations.has[attr.toLowerCase()] = attr;
2685  });
2686
2687  (function(v) {
2688    Object.extend(v, {
2689      href:        v._getAttr2,
2690      src:         v._getAttr2,
2691      type:        v._getAttr,
2692      action:      v._getAttrNode,
2693      disabled:    v._flag,
2694      checked:     v._flag,
2695      readonly:    v._flag,
2696      multiple:    v._flag,
2697      onload:      v._getEv,
2698      onunload:    v._getEv,
2699      onclick:     v._getEv,
2700      ondblclick:  v._getEv,
2701      onmousedown: v._getEv,
2702      onmouseup:   v._getEv,
2703      onmouseover: v._getEv,
2704      onmousemove: v._getEv,
2705      onmouseout:  v._getEv,
2706      onfocus:     v._getEv,
2707      onblur:      v._getEv,
2708      onkeypress:  v._getEv,
2709      onkeydown:   v._getEv,
2710      onkeyup:     v._getEv,
2711      onsubmit:    v._getEv,
2712      onreset:     v._getEv,
2713      onselect:    v._getEv,
2714      onchange:    v._getEv
2715    });
2716  })(Element._attributeTranslations.read.values);
2717
2718  if (Prototype.BrowserFeatures.ElementExtensions) {
2719    (function() {
2720      function _descendants(element) {
2721        var nodes = element.getElementsByTagName('*'), results = [];
2722        for (var i = 0, node; node = nodes[i]; i++)
2723          if (node.tagName !== "!") // Filter out comment nodes.
2724            results.push(node);
2725        return results;
2726      }
2727
2728      Element.Methods.down = function(element, expression, index) {
2729        element = $(element);
2730        if (arguments.length == 1) return element.firstDescendant();
2731        return Object.isNumber(expression) ? _descendants(element)[expression] :
2732          Element.select(element, expression)[index || 0];
2733      }
2734    })();
2735  }
2736
2737}
2738
2739else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
2740  Element.Methods.setOpacity = function(element, value) {
2741    element = $(element);
2742    element.style.opacity = (value == 1) ? 0.999999 :
2743      (value === '') ? '' : (value < 0.00001) ? 0 : value;
2744    return element;
2745  };
2746}
2747
2748else if (Prototype.Browser.WebKit) {
2749  Element.Methods.setOpacity = function(element, value) {
2750    element = $(element);
2751    element.style.opacity = (value == 1 || value === '') ? '' :
2752      (value < 0.00001) ? 0 : value;
2753
2754    if (value == 1)
2755      if (element.tagName.toUpperCase() == 'IMG' && element.width) {
2756        element.width++; element.width--;
2757      } else try {
2758        var n = document.createTextNode(' ');
2759        element.appendChild(n);
2760        element.removeChild(n);
2761      } catch (e) { }
2762
2763    return element;
2764  };
2765}
2766
2767if ('outerHTML' in document.documentElement) {
2768  Element.Methods.replace = function(element, content) {
2769    element = $(element);
2770
2771    if (content && content.toElement) content = content.toElement();
2772    if (Object.isElement(content)) {
2773      element.parentNode.replaceChild(content, element);
2774      return element;
2775    }
2776
2777    content = Object.toHTML(content);
2778    var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
2779
2780    if (Element._insertionTranslations.tags[tagName]) {
2781      var nextSibling = element.next(),
2782          fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
2783      parent.removeChild(element);
2784      if (nextSibling)
2785        fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
2786      else
2787        fragments.each(function(node) { parent.appendChild(node) });
2788    }
2789    else element.outerHTML = content.stripScripts();
2790
2791    content.evalScripts.bind(content).defer();
2792    return element;
2793  };
2794}
2795
2796Element._returnOffset = function(l, t) {
2797  var result = [l, t];
2798  result.left = l;
2799  result.top = t;
2800  return result;
2801};
2802
2803Element._getContentFromAnonymousElement = function(tagName, html, force) {
2804  var div = new Element('div'),
2805      t = Element._insertionTranslations.tags[tagName];
2806
2807  var workaround = false;
2808  if (t) workaround = true;
2809  else if (force) {
2810    workaround = true;
2811    t = ['', '', 0];
2812  }
2813
2814  if (workaround) {
2815    div.innerHTML = '&nbsp;' + t[0] + html + t[1];
2816    div.removeChild(div.firstChild);
2817    for (var i = t[2]; i--; ) {
2818      div = div.firstChild;
2819    }
2820  }
2821  else {
2822    div.innerHTML = html;
2823  }
2824  return $A(div.childNodes);
2825};
2826
2827Element._insertionTranslations = {
2828  before: function(element, node) {
2829    element.parentNode.insertBefore(node, element);
2830  },
2831  top: function(element, node) {
2832    element.insertBefore(node, element.firstChild);
2833  },
2834  bottom: function(element, node) {
2835    element.appendChild(node);
2836  },
2837  after: function(element, node) {
2838    element.parentNode.insertBefore(node, element.nextSibling);
2839  },
2840  tags: {
2841    TABLE:  ['<table>',                '</table>',                   1],
2842    TBODY:  ['<table><tbody>',         '</tbody></table>',           2],
2843    TR:     ['<table><tbody><tr>',     '</tr></tbody></table>',      3],
2844    TD:     ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
2845    SELECT: ['<select>',               '</select>',                  1]
2846  }
2847};
2848
2849(function() {
2850  var tags = Element._insertionTranslations.tags;
2851  Object.extend(tags, {
2852    THEAD: tags.TBODY,
2853    TFOOT: tags.TBODY,
2854    TH:    tags.TD
2855  });
2856})();
2857
2858Element.Methods.Simulated = {
2859  hasAttribute: function(element, attribute) {
2860    attribute = Element._attributeTranslations.has[attribute] || attribute;
2861    var node = $(element).getAttributeNode(attribute);
2862    return !!(node && node.specified);
2863  }
2864};
2865
2866Element.Methods.ByTag = { };
2867
2868Object.extend(Element, Element.Methods);
2869
2870(function(div) {
2871
2872  if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) {
2873    window.HTMLElement = { };
2874    window.HTMLElement.prototype = div['__proto__'];
2875    Prototype.BrowserFeatures.ElementExtensions = true;
2876  }
2877
2878  div = null;
2879
2880})(document.createElement('div'));
2881
2882Element.extend = (function() {
2883
2884  function checkDeficiency(tagName) {
2885    if (typeof window.Element != 'undefined') {
2886      var proto = window.Element.prototype;
2887      if (proto) {
2888        var id = '_' + (Math.random()+'').slice(2),
2889            el = document.createElement(tagName);
2890        proto[id] = 'x';
2891        var isBuggy = (el[id] !== 'x');
2892        delete proto[id];
2893        el = null;
2894        return isBuggy;
2895      }
2896    }
2897    return false;
2898  }
2899
2900  function extendElementWith(element, methods) {
2901    for (var property in methods) {
2902      var value = methods[property];
2903      if (Object.isFunction(value) && !(property in element))
2904        element[property] = value.methodize();
2905    }
2906  }
2907
2908  var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object');
2909
2910  if (Prototype.BrowserFeatures.SpecificElementExtensions) {
2911    if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) {
2912      return function(element) {
2913        if (element && typeof element._extendedByPrototype == 'undefined') {
2914          var t = element.tagName;
2915          if (t && (/^(?:object|applet|embed)$/i.test(t))) {
2916            extendElementWith(element, Element.Methods);
2917            extendElementWith(element, Element.Methods.Simulated);
2918            extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]);
2919          }
2920        }
2921        return element;
2922      }
2923    }
2924    return Prototype.K;
2925  }
2926
2927  var Methods = { }, ByTag = Element.Methods.ByTag;
2928
2929  var extend = Object.extend(function(element) {
2930    if (!element || typeof element._extendedByPrototype != 'undefined' ||
2931        element.nodeType != 1 || element == window) return element;
2932
2933    var methods = Object.clone(Methods),
2934        tagName = element.tagName.toUpperCase();
2935
2936    if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
2937
2938    extendElementWith(element, methods);
2939
2940    element._extendedByPrototype = Prototype.emptyFunction;
2941    return element;
2942
2943  }, {
2944    refresh: function() {
2945      if (!Prototype.BrowserFeatures.ElementExtensions) {
2946        Object.extend(Methods, Element.Methods);
2947        Object.extend(Methods, Element.Methods.Simulated);
2948      }
2949    }
2950  });
2951
2952  extend.refresh();
2953  return extend;
2954})();
2955
2956if (document.documentElement.hasAttribute) {
2957  Element.hasAttribute = function(element, attribute) {
2958    return element.hasAttribute(attribute);
2959  };
2960}
2961else {
2962  Element.hasAttribute = Element.Methods.Simulated.hasAttribute;
2963}
2964
2965Element.addMethods = function(methods) {
2966  var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
2967
2968  if (!methods) {
2969    Object.extend(Form, Form.Methods);
2970    Object.extend(Form.Element, Form.Element.Methods);
2971    Object.extend(Element.Methods.ByTag, {
2972      "FORM":     Object.clone(Form.Methods),
2973      "INPUT":    Object.clone(Form.Element.Methods),
2974      "SELECT":   Object.clone(Form.Element.Methods),
2975      "TEXTAREA": Object.clone(Form.Element.Methods),
2976      "BUTTON":   Object.clone(Form.Element.Methods)
2977    });
2978  }
2979
2980  if (arguments.length == 2) {
2981    var tagName = methods;
2982    methods = arguments[1];
2983  }
2984
2985  if (!tagName) Object.extend(Element.Methods, methods || { });
2986  else {
2987    if (Object.isArray(tagName)) tagName.each(extend);
2988    else extend(tagName);
2989  }
2990
2991  function extend(tagName) {
2992    tagName = tagName.toUpperCase();
2993    if (!Element.Methods.ByTag[tagName])
2994      Element.Methods.ByTag[tagName] = { };
2995    Object.extend(Element.Methods.ByTag[tagName], methods);
2996  }
2997
2998  function copy(methods, destination, onlyIfAbsent) {
2999    onlyIfAbsent = onlyIfAbsent || false;
3000    for (var property in methods) {
3001      var value = methods[property];
3002      if (!Object.isFunction(value)) continue;
3003      if (!onlyIfAbsent || !(property in destination))
3004        destination[property] = value.methodize();
3005    }
3006  }
3007
3008  function findDOMClass(tagName) {
3009    var klass;
3010    var trans = {
3011      "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
3012      "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
3013      "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
3014      "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
3015      "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
3016      "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
3017      "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
3018      "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
3019      "FrameSet", "IFRAME": "IFrame"
3020    };
3021    if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
3022    if (window[klass]) return window[klass];
3023    klass = 'HTML' + tagName + 'Element';
3024    if (window[klass]) return window[klass];
3025    klass = 'HTML' + tagName.capitalize() + 'Element';
3026    if (window[klass]) return window[klass];
3027
3028    var element = document.createElement(tagName),
3029        proto = element['__proto__'] || element.constructor.prototype;
3030
3031    element = null;
3032    return proto;
3033  }
3034
3035  var elementPrototype = window.HTMLElement ? HTMLElement.prototype :
3036   Element.prototype;
3037
3038  if (F.ElementExtensions) {
3039    copy(Element.Methods, elementPrototype);
3040    copy(Element.Methods.Simulated, elementPrototype, true);
3041  }
3042
3043  if (F.SpecificElementExtensions) {
3044    for (var tag in Element.Methods.ByTag) {
3045      var klass = findDOMClass(tag);
3046      if (Object.isUndefined(klass)) continue;
3047      copy(T[tag], klass.prototype);
3048    }
3049  }
3050
3051  Object.extend(Element, Element.Methods);
3052  delete Element.ByTag;
3053
3054  if (Element.extend.refresh) Element.extend.refresh();
3055  Element.cache = { };
3056};
3057
3058
3059document.viewport = {
3060
3061  getDimensions: function() {
3062    return { width: this.getWidth(), height: this.getHeight() };
3063  },
3064
3065  getScrollOffsets: function() {
3066    return Element._returnOffset(
3067      window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
3068      window.pageYOffset || document.documentElement.scrollTop  || document.body.scrollTop);
3069  }
3070};
3071
3072(function(viewport) {
3073  var B = Prototype.Browser, doc = document, element, property = {};
3074
3075  function getRootElement() {
3076    if (B.WebKit && !doc.evaluate)
3077      return document;
3078
3079    if (B.Opera && window.parseFloat(window.opera.version()) < 9.5)
3080      return document.body;
3081
3082    return document.documentElement;
3083  }
3084
3085  function define(D) {
3086    if (!element) element = getRootElement();
3087
3088    property[D] = 'client' + D;
3089
3090    viewport['get' + D] = function() { return element[property[D]] };
3091    return viewport['get' + D]();
3092  }
3093
3094  viewport.getWidth  = define.curry('Width');
3095
3096  viewport.getHeight = define.curry('Height');
3097})(document.viewport);
3098
3099
3100Element.Storage = {
3101  UID: 1
3102};
3103
3104Element.addMethods({
3105  getStorage: function(element) {
3106    if (!(element = $(element))) return;
3107
3108    var uid;
3109    if (element === window) {
3110      uid = 0;
3111    } else {
3112      if (typeof element._prototypeUID === "undefined")
3113        element._prototypeUID = Element.Storage.UID++;
3114      uid = element._prototypeUID;
3115    }
3116
3117    if (!Element.Storage[uid])
3118      Element.Storage[uid] = $H();
3119
3120    return Element.Storage[uid];
3121  },
3122
3123  store: function(element, key, value) {
3124    if (!(element = $(element))) return;
3125
3126    if (arguments.length === 2) {
3127      Element.getStorage(element).update(key);
3128    } else {
3129      Element.getStorage(element).set(key, value);
3130    }
3131
3132    return element;
3133  },
3134
3135  retrieve: function(element, key, defaultValue) {
3136    if (!(element = $(element))) return;
3137    var hash = Element.getStorage(element), value = hash.get(key);
3138
3139    if (Object.isUndefined(value)) {
3140      hash.set(key, defaultValue);
3141      value = defaultValue;
3142    }
3143
3144    return value;
3145  },
3146
3147  clone: function(element, deep) {
3148    if (!(element = $(element))) return;
3149    var clone = element.cloneNode(deep);
3150    clone._prototypeUID = void 0;
3151    if (deep) {
3152      var descendants = Element.select(clone, '*'),
3153          i = descendants.length;
3154      while (i--) {
3155        descendants[i]._prototypeUID = void 0;
3156      }
3157    }
3158    return Element.extend(clone);
3159  },
3160
3161  purge: function(element) {
3162    if (!(element = $(element))) return;
3163    var purgeElement = Element._purgeElement;
3164
3165    purgeElement(element);
3166
3167    var descendants = element.getElementsByTagName('*'),
3168     i = descendants.length;
3169
3170    while (i--) purgeElement(descendants[i]);
3171
3172    return null;
3173  }
3174});
3175
3176(function() {
3177
3178  function toDecimal(pctString) {
3179    var match = pctString.match(/^(\d+)%?$/i);
3180    if (!match) return null;
3181    return (Number(match[1]) / 100);
3182  }
3183
3184  function getPixelValue(value, property, context) {
3185    var element = null;
3186    if (Object.isElement(value)) {
3187      element = value;
3188      value = element.getStyle(property);
3189    }
3190
3191    if (value === null) {
3192      return null;
3193    }
3194
3195    if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) {
3196      return window.parseFloat(value);
3197    }
3198
3199    var isPercentage = value.include('%'), isViewport = (context === document.viewport);
3200
3201    if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) {
3202      var style = element.style.left, rStyle = element.runtimeStyle.left;
3203      element.runtimeStyle.left = element.currentStyle.left;
3204      element.style.left = value || 0;
3205      value = element.style.pixelLeft;
3206      element.style.left = style;
3207      element.runtimeStyle.left = rStyle;
3208
3209      return value;
3210    }
3211
3212    if (element && isPercentage) {
3213      context = context || element.parentNode;
3214      var decimal = toDecimal(value);
3215      var whole = null;
3216      var position = element.getStyle('position');
3217
3218      var isHorizontal = property.include('left') || property.include('right') ||
3219       property.include('width');
3220
3221      var isVertical =  property.include('top') || property.include('bottom') ||
3222        property.include('height');
3223
3224      if (context === document.viewport) {
3225        if (isHorizontal) {
3226          whole = document.viewport.getWidth();
3227        } else if (isVertical) {
3228          whole = document.viewport.getHeight();
3229        }
3230      } else {
3231        if (isHorizontal) {
3232          whole = $(context).measure('width');
3233        } else if (isVertical) {
3234          whole = $(context).measure('height');
3235        }
3236      }
3237
3238      return (whole === null) ? 0 : whole * decimal;
3239    }
3240
3241    return 0;
3242  }
3243
3244  function toCSSPixels(number) {
3245    if (Object.isString(number) && number.endsWith('px')) {
3246      return number;
3247    }
3248    return number + 'px';
3249  }
3250
3251  function isDisplayed(element) {
3252    var originalElement = element;
3253    while (element && element.parentNode) {
3254      var display = element.getStyle('display');
3255      if (display === 'none') {
3256        return false;
3257      }
3258      element = $(element.parentNode);
3259    }
3260    return true;
3261  }
3262
3263  var hasLayout = Prototype.K;
3264  if ('currentStyle' in document.documentElement) {
3265    hasLayout = function(element) {
3266      if (!element.currentStyle.hasLayout) {
3267        element.style.zoom = 1;
3268      }
3269      return element;
3270    };
3271  }
3272
3273  function cssNameFor(key) {
3274    if (key.include('border')) key = key + '-width';
3275    return key.camelize();
3276  }
3277
3278  Element.Layout = Class.create(Hash, {
3279    initialize: function($super, element, preCompute) {
3280      $super();
3281      this.element = $(element);
3282
3283      Element.Layout.PROPERTIES.each( function(property) {
3284        this._set(property, null);
3285      }, this);
3286
3287      if (preCompute) {
3288        this._preComputing = true;
3289        this._begin();
3290        Element.Layout.PROPERTIES.each( this._compute, this );
3291        this._end();
3292        this._preComputing = false;
3293      }
3294    },
3295
3296    _set: function(property, value) {
3297      return Hash.prototype.set.call(this, property, value);
3298    },
3299
3300    set: function(property, value) {
3301      throw "Properties of Element.Layout are read-only.";
3302    },
3303
3304    get: function($super, property) {
3305      var value = $super(property);
3306      return value === null ? this._compute(property) : value;
3307    },
3308
3309    _begin: function() {
3310      if (this._prepared) return;
3311
3312      var element = this.element;
3313      if (isDisplayed(element)) {
3314        this._prepared = true;
3315        return;
3316      }
3317
3318      var originalStyles = {
3319        position:   element.style.position   || '',
3320        width:      element.style.width      || '',
3321        visibility: element.style.visibility || '',
3322        display:    element.style.display    || ''
3323      };
3324
3325      element.store('prototype_original_styles', originalStyles);
3326
3327      var position = element.getStyle('position'),
3328       width = element.getStyle('width');
3329
3330      if (width === "0px" || width === null) {
3331        element.style.display = 'block';
3332        width = element.getStyle('width');
3333      }
3334
3335      var context = (position === 'fixed') ? document.viewport :
3336       element.parentNode;
3337
3338      element.setStyle({
3339        position:   'absolute',
3340        visibility: 'hidden',
3341        display:    'block'
3342      });
3343
3344      var positionedWidth = element.getStyle('width');
3345
3346      var newWidth;
3347      if (width && (positionedWidth === width)) {
3348        newWidth = getPixelValue(element, 'width', context);
3349      } else if (position === 'absolute' || position === 'fixed') {
3350        newWidth = getPixelValue(element, 'width', context);
3351      } else {
3352        var parent = element.parentNode, pLayout = $(parent).getLayout();
3353
3354        newWidth = pLayout.get('width') -
3355         this.get('margin-left') -
3356         this.get('border-left') -
3357         this.get('padding-left') -
3358         this.get('padding-right') -
3359         this.get('border-right') -
3360         this.get('margin-right');
3361      }
3362
3363      element.setStyle({ width: newWidth + 'px' });
3364
3365      this._prepared = true;
3366    },
3367
3368    _end: function() {
3369      var element = this.element;
3370      var originalStyles = element.retrieve('prototype_original_styles');
3371      element.store('prototype_original_styles', null);
3372      element.setStyle(originalStyles);
3373      this._prepared = false;
3374    },
3375
3376    _compute: function(property) {
3377      var COMPUTATIONS = Element.Layout.COMPUTATIONS;
3378      if (!(property in COMPUTATIONS)) {
3379        throw "Property not found.";
3380      }
3381
3382      return this._set(property, COMPUTATIONS[property].call(this, this.element));
3383    },
3384
3385    toObject: function() {
3386      var args = $A(arguments);
3387      var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
3388       args.join(' ').split(' ');
3389      var obj = {};
3390      keys.each( function(key) {
3391        if (!Element.Layout.PROPERTIES.include(key)) return;
3392        var value = this.get(key);
3393        if (value != null) obj[key] = value;
3394      }, this);
3395      return obj;
3396    },
3397
3398    toHash: function() {
3399      var obj = this.toObject.apply(this, arguments);
3400      return new Hash(obj);
3401    },
3402
3403    toCSS: function() {
3404      var args = $A(arguments);
3405      var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
3406       args.join(' ').split(' ');
3407      var css = {};
3408
3409      keys.each( function(key) {
3410        if (!Element.Layout.PROPERTIES.include(key)) return;
3411        if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return;
3412
3413        var value = this.get(key);
3414        if (value != null) css[cssNameFor(key)] = value + 'px';
3415      }, this);
3416      return css;
3417    },
3418
3419    inspect: function() {
3420      return "#<Element.Layout>";
3421    }
3422  });
3423
3424  Object.extend(Element.Layout, {
3425    PROPERTIES: $w('height width top left right bottom border-left border-right border-top border-bottom padding-left padding-right padding-top padding-bottom margin-top margin-bottom margin-left margin-right padding-box-width padding-box-height border-box-width border-box-height margin-box-width margin-box-height'),
3426
3427    COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'),
3428
3429    COMPUTATIONS: {
3430      'height': function(element) {
3431        if (!this._preComputing) this._begin();
3432
3433        var bHeight = this.get('border-box-height');
3434        if (bHeight <= 0) {
3435          if (!this._preComputing) this._end();
3436          return 0;
3437        }
3438
3439        var bTop = this.get('border-top'),
3440         bBottom = this.get('border-bottom');
3441
3442        var pTop = this.get('padding-top'),
3443         pBottom = this.get('padding-bottom');
3444
3445        if (!this._preComputing) this._end();
3446
3447        return bHeight - bTop - bBottom - pTop - pBottom;
3448      },
3449
3450      'width': function(element) {
3451        if (!this._preComputing) this._begin();
3452
3453        var bWidth = this.get('border-box-width');
3454        if (bWidth <= 0) {
3455          if (!this._preComputing) this._end();
3456          return 0;
3457        }
3458
3459        var bLeft = this.get('border-left'),
3460         bRight = this.get('border-right');
3461
3462        var pLeft = this.get('padding-left'),
3463         pRight = this.get('padding-right');
3464
3465        if (!this._preComputing) this._end();
3466
3467        return bWidth - bLeft - bRight - pLeft - pRight;
3468      },
3469
3470      'padding-box-height': function(element) {
3471        var height = this.get('height'),
3472         pTop = this.get('padding-top'),
3473         pBottom = this.get('padding-bottom');
3474
3475        return height + pTop + pBottom;
3476      },
3477
3478      'padding-box-width': function(element) {
3479        var width = this.get('width'),
3480         pLeft = this.get('padding-left'),
3481         pRight = this.get('padding-right');
3482
3483        return width + pLeft + pRight;
3484      },
3485
3486      'border-box-height': function(element) {
3487        if (!this._preComputing) this._begin();
3488        var height = element.offsetHeight;
3489        if (!this._preComputing) this._end();
3490        return height;
3491      },
3492
3493      'border-box-width': function(element) {
3494        if (!this._preComputing) this._begin();
3495        var width = element.offsetWidth;
3496        if (!this._preComputing) this._end();
3497        return width;
3498      },
3499
3500      'margin-box-height': function(element) {
3501        var bHeight = this.get('border-box-height'),
3502         mTop = this.get('margin-top'),
3503         mBottom = this.get('margin-bottom');
3504
3505        if (bHeight <= 0) return 0;
3506
3507        return bHeight + mTop + mBottom;
3508      },
3509
3510      'margin-box-width': function(element) {
3511        var bWidth = this.get('border-box-width'),
3512         mLeft = this.get('margin-left'),
3513         mRight = this.get('margin-right');
3514
3515        if (bWidth <= 0) return 0;
3516
3517        return bWidth + mLeft + mRight;
3518      },
3519
3520      'top': function(element) {
3521        var offset = element.positionedOffset();
3522        return offset.top;
3523      },
3524
3525      'bottom': function(element) {
3526        var offset = element.positionedOffset(),
3527         parent = element.getOffsetParent(),
3528         pHeight = parent.measure('height');
3529
3530        var mHeight = this.get('border-box-height');
3531
3532        return pHeight - mHeight - offset.top;
3533      },
3534
3535      'left': function(element) {
3536        var offset = element.positionedOffset();
3537        return offset.left;
3538      },
3539
3540      'right': function(element) {
3541        var offset = element.positionedOffset(),
3542         parent = element.getOffsetParent(),
3543         pWidth = parent.measure('width');
3544
3545        var mWidth = this.get('border-box-width');
3546
3547        return pWidth - mWidth - offset.left;
3548      },
3549
3550      'padding-top': function(element) {
3551        return getPixelValue(element, 'paddingTop');
3552      },
3553
3554      'padding-bottom': function(element) {
3555        return getPixelValue(element, 'paddingBottom');
3556      },
3557
3558      'padding-left': function(element) {
3559        return getPixelValue(element, 'paddingLeft');
3560      },
3561
3562      'padding-right': function(element) {
3563        return getPixelValue(element, 'paddingRight');
3564      },
3565
3566      'border-top': function(element) {
3567        return getPixelValue(element, 'borderTopWidth');
3568      },
3569
3570      'border-bottom': function(element) {
3571        return getPixelValue(element, 'borderBottomWidth');
3572      },
3573
3574      'border-left': function(element) {
3575        return getPixelValue(element, 'borderLeftWidth');
3576      },
3577
3578      'border-right': function(element) {
3579        return getPixelValue(element, 'borderRightWidth');
3580      },
3581
3582      'margin-top': function(element) {
3583        return getPixelValue(element, 'marginTop');
3584      },
3585
3586      'margin-bottom': function(element) {
3587        return getPixelValue(element, 'marginBottom');
3588      },
3589
3590      'margin-left': function(element) {
3591        return getPixelValue(element, 'marginLeft');
3592      },
3593
3594      'margin-right': function(element) {
3595        return getPixelValue(element, 'marginRight');
3596      }
3597    }
3598  });
3599
3600  if ('getBoundingClientRect' in document.documentElement) {
3601    Object.extend(Element.Layout.COMPUTATIONS, {
3602      'right': function(element) {
3603        var parent = hasLayout(element.getOffsetParent());
3604        var rect = element.getBoundingClientRect(),
3605         pRect = parent.getBoundingClientRect();
3606
3607        return (pRect.right - rect.right).round();
3608      },
3609
3610      'bottom': function(element) {
3611        var parent = hasLayout(element.getOffsetParent());
3612        var rect = element.getBoundingClientRect(),
3613         pRect = parent.getBoundingClientRect();
3614
3615        return (pRect.bottom - rect.bottom).round();
3616      }
3617    });
3618  }
3619
3620  Element.Offset = Class.create({
3621    initialize: function(left, top) {
3622      this.left = left.round();
3623      this.top  = top.round();
3624
3625      this[0] = this.left;
3626      this[1] = this.top;
3627    },
3628
3629    relativeTo: function(offset) {
3630      return new Element.Offset(
3631        this.left - offset.left,
3632        this.top  - offset.top
3633      );
3634    },
3635
3636    inspect: function() {
3637      return "#<Element.Offset left: #{left} top: #{top}>".interpolate(this);
3638    },
3639
3640    toString: function() {
3641      return "[#{left}, #{top}]".interpolate(this);
3642    },
3643
3644    toArray: function() {
3645      return [this.left, this.top];
3646    }
3647  });
3648
3649  function getLayout(element, preCompute) {
3650    return new Element.Layout(element, preCompute);
3651  }
3652
3653  function measure(element, property) {
3654    return $(element).getLayout().get(property);
3655  }
3656
3657  function getDimensions(element) {
3658    element = $(element);
3659    var display = Element.getStyle(element, 'display');
3660
3661    if (display && display !== 'none') {
3662      return { width: element.offsetWidth, height: element.offsetHeight };
3663    }
3664
3665    var style = element.style;
3666    var originalStyles = {
3667      visibility: style.visibility,
3668      position:   style.position,
3669      display:    style.display
3670    };
3671
3672    var newStyles = {
3673      visibility: 'hidden',
3674      display:    'block'
3675    };
3676
3677    if (originalStyles.position !== 'fixed')
3678      newStyles.position = 'absolute';
3679
3680    Element.setStyle(element, newStyles);
3681
3682    var dimensions = {
3683      width:  element.offsetWidth,
3684      height: element.offsetHeight
3685    };
3686
3687    Element.setStyle(element, originalStyles);
3688
3689    return dimensions;
3690  }
3691
3692  function getOffsetParent(element) {
3693    element = $(element);
3694
3695    if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
3696      return $(document.body);
3697
3698    var isInline = (Element.getStyle(element, 'display') === 'inline');
3699    if (!isInline && element.offsetParent) return $(element.offsetParent);
3700
3701    while ((element = element.parentNode) && element !== document.body) {
3702      if (Element.getStyle(element, 'position') !== 'static') {
3703        return isHtml(element) ? $(document.body) : $(element);
3704      }
3705    }
3706
3707    return $(document.body);
3708  }
3709
3710
3711  function cumulativeOffset(element) {
3712    element = $(element);
3713    var valueT = 0, valueL = 0;
3714    if (element.parentNode) {
3715      do {
3716        valueT += element.offsetTop  || 0;
3717        valueL += element.offsetLeft || 0;
3718        element = element.offsetParent;
3719      } while (element);
3720    }
3721    return new Element.Offset(valueL, valueT);
3722  }
3723
3724  function positionedOffset(element) {
3725    element = $(element);
3726
3727    var layout = element.getLayout();
3728
3729    var valueT = 0, valueL = 0;
3730    do {
3731      valueT += element.offsetTop  || 0;
3732      valueL += element.offsetLeft || 0;
3733      element = element.offsetParent;
3734      if (element) {
3735        if (isBody(element)) break;
3736        var p = Element.getStyle(element, 'position');
3737        if (p !== 'static') break;
3738      }
3739    } while (element);
3740
3741    valueL -= layout.get('margin-top');
3742    valueT -= layout.get('margin-left');
3743
3744    return new Element.Offset(valueL, valueT);
3745  }
3746
3747  function cumulativeScrollOffset(element) {
3748    var valueT = 0, valueL = 0;
3749    do {
3750      valueT += element.scrollTop  || 0;
3751      valueL += element.scrollLeft || 0;
3752      element = element.parentNode;
3753    } while (element);
3754    return new Element.Offset(valueL, valueT);
3755  }
3756
3757  function viewportOffset(forElement) {
3758    element = $(element);
3759    var valueT = 0, valueL = 0, docBody = document.body;
3760
3761    var element = forElement;
3762    do {
3763      valueT += element.offsetTop  || 0;
3764      valueL += element.offsetLeft || 0;
3765      if (element.offsetParent == docBody &&
3766        Element.getStyle(element, 'position') == 'absolute') break;
3767    } while (element = element.offsetParent);
3768
3769    element = forElement;
3770    do {
3771      if (element != docBody) {
3772        valueT -= element.scrollTop  || 0;
3773        valueL -= element.scrollLeft || 0;
3774      }
3775    } while (element = element.parentNode);
3776    return new Element.Offset(valueL, valueT);
3777  }
3778
3779  function absolutize(element) {
3780    element = $(element);
3781
3782    if (Element.getStyle(element, 'position') === 'absolute') {
3783      return element;
3784    }
3785
3786    var offsetParent = getOffsetParent(element);
3787    var eOffset = element.viewportOffset(),
3788     pOffset = offsetParent.viewportOffset();
3789
3790    var offset = eOffset.relativeTo(pOffset);
3791    var layout = element.getLayout();
3792
3793    element.store('prototype_absolutize_original_styles', {
3794      left:   element.getStyle('left'),
3795  top:    element.getStyle('top'),
3796  width:  element.getStyle('width'),
3797  height: element.getStyle('height'),
3798  position: element.getStyle('position')
3799    });
3800
3801    element.setStyle({
3802      position: 'absolute',
3803      top:    offset.top + 'px',
3804      left:   offset.left + 'px',
3805      width:  layout.get('width') + 'px',
3806      height: layout.get('height') + 'px'
3807    });
3808
3809    return element;
3810  }
3811
3812  function relativize(element) {
3813    element = $(element);
3814    if (Element.getStyle(element, 'position') === 'relative') {
3815      return element;
3816    }
3817
3818    var originalStyles =
3819     element.retrieve('prototype_absolutize_original_styles');
3820
3821    if (originalStyles) element.setStyle(originalStyles);
3822    return element;
3823  }
3824
3825  if (Prototype.Browser.IE) {
3826    getOffsetParent = getOffsetParent.wrap(
3827      function(proceed, element) {
3828        element = $(element);
3829
3830        if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
3831          return $(document.body);
3832
3833        var position = element.getStyle('position');
3834        if (position !== 'static') return proceed(element);
3835
3836        element.setStyle({ position: 'relative' });
3837        var value = proceed(element);
3838        element.setStyle({ position: position });
3839        return value;
3840      }
3841    );
3842
3843    positionedOffset = positionedOffset.wrap(function(proceed, element) {
3844      element = $(element);
3845      if (!element.parentNode) return new Element.Offset(0, 0);
3846      var position = element.getStyle('position');
3847      if (position !== 'static') return proceed(element);
3848
3849      var offsetParent = element.getOffsetParent();
3850      if (offsetParent && offsetParent.getStyle('position') === 'fixed')
3851        hasLayout(offsetParent);
3852
3853      element.setStyle({ position: 'relative' });
3854      var value = proceed(element);
3855      element.setStyle({ position: position });
3856      return value;
3857    });
3858  } else if (Prototype.Browser.Webkit) {
3859    cumulativeOffset = function(element) {
3860      element = $(element);
3861      var valueT = 0, valueL = 0;
3862      do {
3863        valueT += element.offsetTop  || 0;
3864        valueL += element.offsetLeft || 0;
3865        if (element.offsetParent == document.body)
3866          if (Element.getStyle(element, 'position') == 'absolute') break;
3867
3868        element = element.offsetParent;
3869      } while (element);
3870
3871      return new Element.Offset(valueL, valueT);
3872    };
3873  }
3874
3875
3876  Element.addMethods({
3877    getLayout:              getLayout,
3878    measure:                measure,
3879    getDimensions:          getDimensions,
3880    getOffsetParent:        getOffsetParent,
3881    cumulativeOffset:       cumulativeOffset,
3882    positionedOffset:       positionedOffset,
3883    cumulativeScrollOffset: cumulativeScrollOffset,
3884    viewportOffset:         viewportOffset,
3885    absolutize:             absolutize,
3886    relativize:             relativize
3887  });
3888
3889  function isBody(element) {
3890    return element.nodeName.toUpperCase() === 'BODY';
3891  }
3892
3893  function isHtml(element) {
3894    return element.nodeName.toUpperCase() === 'HTML';
3895  }
3896
3897  function isDocument(element) {
3898    return element.nodeType === Node.DOCUMENT_NODE;
3899  }
3900
3901  function isDetached(element) {
3902    return element !== document.body &&
3903     !Element.descendantOf(element, document.body);
3904  }
3905
3906  if ('getBoundingClientRect' in document.documentElement) {
3907    Element.addMethods({
3908      viewportOffset: function(element) {
3909        element = $(element);
3910        if (isDetached(element)) return new Element.Offset(0, 0);
3911
3912        var rect = element.getBoundingClientRect(),
3913         docEl = document.documentElement;
3914        return new Element.Offset(rect.left - docEl.clientLeft,
3915         rect.top - docEl.clientTop);
3916      }
3917    });
3918  }
3919})();
3920window.$$ = function() {
3921  var expression = $A(arguments).join(', ');
3922  return Prototype.Selector.select(expression, document);
3923};
3924
3925Prototype.Selector = (function() {
3926
3927  function select() {
3928    throw new Error('Method "Prototype.Selector.select" must be defined.');
3929  }
3930
3931  function match() {
3932    throw new Error('Method "Prototype.Selector.match" must be defined.');
3933  }
3934
3935  function find(elements, expression, index) {
3936    index = index || 0;
3937    var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i;
3938
3939    for (i = 0; i < length; i++) {
3940      if (match(elements[i], expression) && index == matchIndex++) {
3941        return Element.extend(elements[i]);
3942      }
3943    }
3944  }
3945
3946  function extendElements(elements) {
3947    for (var i = 0, length = elements.length; i < length; i++) {
3948      Element.extend(elements[i]);
3949    }
3950    return elements;
3951  }
3952
3953
3954  var K = Prototype.K;
3955
3956  return {
3957    select: select,
3958    match: match,
3959    find: find,
3960    extendElements: (Element.extend === K) ? K : extendElements,
3961    extendElement: Element.extend
3962  };
3963})();
3964/*!
3965 * Sizzle CSS Selector Engine - v1.0
3966 *  Copyright 2009, The Dojo Foundation
3967 *  Released under the MIT, BSD, and GPL Licenses.
3968 *  More information: http://sizzlejs.com/
3969 */
3970(function(){
3971
3972var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
3973	done = 0,
3974	toString = Object.prototype.toString,
3975	hasDuplicate = false,
3976	baseHasDuplicate = true;
3977
3978[0, 0].sort(function(){
3979	baseHasDuplicate = false;
3980	return 0;
3981});
3982
3983var Sizzle = function(selector, context, results, seed) {
3984	results = results || [];
3985	var origContext = context = context || document;
3986
3987	if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
3988		return [];
3989	}
3990
3991	if ( !selector || typeof selector !== "string" ) {
3992		return results;
3993	}
3994
3995	var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context),
3996		soFar = selector;
3997
3998	while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) {
3999		soFar = m[3];
4000
4001		parts.push( m[1] );
4002
4003		if ( m[2] ) {
4004			extra = m[3];
4005			break;
4006		}
4007	}
4008
4009	if ( parts.length > 1 && origPOS.exec( selector ) ) {
4010		if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
4011			set = posProcess( parts[0] + parts[1], context );
4012		} else {
4013			set = Expr.relative[ parts[0] ] ?
4014				[ context ] :
4015				Sizzle( parts.shift(), context );
4016
4017			while ( parts.length ) {
4018				selector = parts.shift();
4019
4020				if ( Expr.relative[ selector ] )
4021					selector += parts.shift();
4022
4023				set = posProcess( selector, set );
4024			}
4025		}
4026	} else {
4027		if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
4028				Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
4029			var ret = Sizzle.find( parts.shift(), context, contextXML );
4030			context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
4031		}
4032
4033		if ( context ) {
4034			var ret = seed ?
4035				{ expr: parts.pop(), set: makeArray(seed) } :
4036				Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
4037			set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
4038
4039			if ( parts.length > 0 ) {
4040				checkSet = makeArray(set);
4041			} else {
4042				prune = false;
4043			}
4044
4045			while ( parts.length ) {
4046				var cur = parts.pop(), pop = cur;
4047
4048				if ( !Expr.relative[ cur ] ) {
4049					cur = "";
4050				} else {
4051					pop = parts.pop();
4052				}
4053
4054				if ( pop == null ) {
4055					pop = context;
4056				}
4057
4058				Expr.relative[ cur ]( checkSet, pop, contextXML );
4059			}
4060		} else {
4061			checkSet = parts = [];
4062		}
4063	}
4064
4065	if ( !checkSet ) {
4066		checkSet = set;
4067	}
4068
4069	if ( !checkSet ) {
4070		throw "Syntax error, unrecognized expression: " + (cur || selector);
4071	}
4072
4073	if ( toString.call(checkSet) === "[object Array]" ) {
4074		if ( !prune ) {
4075			results.push.apply( results, checkSet );
4076		} else if ( context && context.nodeType === 1 ) {
4077			for ( var i = 0; checkSet[i] != null; i++ ) {
4078				if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
4079					results.push( set[i] );
4080				}
4081			}
4082		} else {
4083			for ( var i = 0; checkSet[i] != null; i++ ) {
4084				if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
4085					results.push( set[i] );
4086				}
4087			}
4088		}
4089	} else {
4090		makeArray( checkSet, results );
4091	}
4092
4093	if ( extra ) {
4094		Sizzle( extra, origContext, results, seed );
4095		Sizzle.uniqueSort( results );
4096	}
4097
4098	return results;
4099};
4100
4101Sizzle.uniqueSort = function(results){
4102	if ( sortOrder ) {
4103		hasDuplicate = baseHasDuplicate;
4104		results.sort(sortOrder);
4105
4106		if ( hasDuplicate ) {
4107			for ( var i = 1; i < results.length; i++ ) {
4108				if ( results[i] === results[i-1] ) {
4109					results.splice(i--, 1);
4110				}
4111			}
4112		}
4113	}
4114
4115	return results;
4116};
4117
4118Sizzle.matches = function(expr, set){
4119	return Sizzle(expr, null, null, set);
4120};
4121
4122Sizzle.find = function(expr, context, isXML){
4123	var set, match;
4124
4125	if ( !expr ) {
4126		return [];
4127	}
4128
4129	for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
4130		var type = Expr.order[i], match;
4131
4132		if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
4133			var left = match[1];
4134			match.splice(1,1);
4135
4136			if ( left.substr( left.length - 1 ) !== "\\" ) {
4137				match[1] = (match[1] || "").replace(/\\/g, "");
4138				set = Expr.find[ type ]( match, context, isXML );
4139				if ( set != null ) {
4140					expr = expr.replace( Expr.match[ type ], "" );
4141					break;
4142				}
4143			}
4144		}
4145	}
4146
4147	if ( !set ) {
4148		set = context.getElementsByTagName("*");
4149	}
4150
4151	return {set: set, expr: expr};
4152};
4153
4154Sizzle.filter = function(expr, set, inplace, not){
4155	var old = expr, result = [], curLoop = set, match, anyFound,
4156		isXMLFilter = set && set[0] && isXML(set[0]);
4157
4158	while ( expr && set.length ) {
4159		for ( var type in Expr.filter ) {
4160			if ( (match = Expr.match[ type ].exec( expr )) != null ) {
4161				var filter = Expr.filter[ type ], found, item;
4162				anyFound = false;
4163
4164				if ( curLoop == result ) {
4165					result = [];
4166				}
4167
4168				if ( Expr.preFilter[ type ] ) {
4169					match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
4170
4171					if ( !match ) {
4172						anyFound = found = true;
4173					} else if ( match === true ) {
4174						continue;
4175					}
4176				}
4177
4178				if ( match ) {
4179					for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
4180						if ( item ) {
4181							found = filter( item, match, i, curLoop );
4182							var pass = not ^ !!found;
4183
4184							if ( inplace && found != null ) {
4185								if ( pass ) {
4186									anyFound = true;
4187								} else {
4188									curLoop[i] = false;
4189								}
4190							} else if ( pass ) {
4191								result.push( item );
4192								anyFound = true;
4193							}
4194						}
4195					}
4196				}
4197
4198				if ( found !== undefined ) {
4199					if ( !inplace ) {
4200						curLoop = result;
4201					}
4202
4203					expr = expr.replace( Expr.match[ type ], "" );
4204
4205					if ( !anyFound ) {
4206						return [];
4207					}
4208
4209					break;
4210				}
4211			}
4212		}
4213
4214		if ( expr == old ) {
4215			if ( anyFound == null ) {
4216				throw "Syntax error, unrecognized expression: " + expr;
4217			} else {
4218				break;
4219			}
4220		}
4221
4222		old = expr;
4223	}
4224
4225	return curLoop;
4226};
4227
4228var Expr = Sizzle.selectors = {
4229	order: [ "ID", "NAME", "TAG" ],
4230	match: {
4231		ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
4232		CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
4233		NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,
4234		ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
4235		TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,
4236		CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
4237		POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
4238		PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
4239	},
4240	leftMatch: {},
4241	attrMap: {
4242		"class": "className",
4243		"for": "htmlFor"
4244	},
4245	attrHandle: {
4246		href: function(elem){
4247			return elem.getAttribute("href");
4248		}
4249	},
4250	relative: {
4251		"+": function(checkSet, part, isXML){
4252			var isPartStr = typeof part === "string",
4253				isTag = isPartStr && !/\W/.test(part),
4254				isPartStrNotTag = isPartStr && !isTag;
4255
4256			if ( isTag && !isXML ) {
4257				part = part.toUpperCase();
4258			}
4259
4260			for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
4261				if ( (elem = checkSet[i]) ) {
4262					while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
4263
4264					checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
4265						elem || false :
4266						elem === part;
4267				}
4268			}
4269
4270			if ( isPartStrNotTag ) {
4271				Sizzle.filter( part, checkSet, true );
4272			}
4273		},
4274		">": function(checkSet, part, isXML){
4275			var isPartStr = typeof part === "string";
4276
4277			if ( isPartStr && !/\W/.test(part) ) {
4278				part = isXML ? part : part.toUpperCase();
4279
4280				for ( var i = 0, l = checkSet.length; i < l; i++ ) {
4281					var elem = checkSet[i];
4282					if ( elem ) {
4283						var parent = elem.parentNode;
4284						checkSet[i] = parent.nodeName === part ? parent : false;
4285					}
4286				}
4287			} else {
4288				for ( var i = 0, l = checkSet.length; i < l; i++ ) {
4289					var elem = checkSet[i];
4290					if ( elem ) {
4291						checkSet[i] = isPartStr ?
4292							elem.parentNode :
4293							elem.parentNode === part;
4294					}
4295				}
4296
4297				if ( isPartStr ) {
4298					Sizzle.filter( part, checkSet, true );
4299				}
4300			}
4301		},
4302		"": function(checkSet, part, isXML){
4303			var doneName = done++, checkFn = dirCheck;
4304
4305			if ( !/\W/.test(part) ) {
4306				var nodeCheck = part = isXML ? part : part.toUpperCase();
4307				checkFn = dirNodeCheck;
4308			}
4309
4310			checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
4311		},
4312		"~": function(checkSet, part, isXML){
4313			var doneName = done++, checkFn = dirCheck;
4314
4315			if ( typeof part === "string" && !/\W/.test(part) ) {
4316				var nodeCheck = part = isXML ? part : part.toUpperCase();
4317				checkFn = dirNodeCheck;
4318			}
4319
4320			checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
4321		}
4322	},
4323	find: {
4324		ID: function(match, context, isXML){
4325			if ( typeof context.getElementById !== "undefined" && !isXML ) {
4326				var m = context.getElementById(match[1]);
4327				return m ? [m] : [];
4328			}
4329		},
4330		NAME: function(match, context, isXML){
4331			if ( typeof context.getElementsByName !== "undefined" ) {
4332				var ret = [], results = context.getElementsByName(match[1]);
4333
4334				for ( var i = 0, l = results.length; i < l; i++ ) {
4335					if ( results[i].getAttribute("name") === match[1] ) {
4336						ret.push( results[i] );
4337					}
4338				}
4339
4340				return ret.length === 0 ? null : ret;
4341			}
4342		},
4343		TAG: function(match, context){
4344			return context.getElementsByTagName(match[1]);
4345		}
4346	},
4347	preFilter: {
4348		CLASS: function(match, curLoop, inplace, result, not, isXML){
4349			match = " " + match[1].replace(/\\/g, "") + " ";
4350
4351			if ( isXML ) {
4352				return match;
4353			}
4354
4355			for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
4356				if ( elem ) {
4357					if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
4358						if ( !inplace )
4359							result.push( elem );
4360					} else if ( inplace ) {
4361						curLoop[i] = false;
4362					}
4363				}
4364			}
4365
4366			return false;
4367		},
4368		ID: function(match){
4369			return match[1].replace(/\\/g, "");
4370		},
4371		TAG: function(match, curLoop){
4372			for ( var i = 0; curLoop[i] === false; i++ ){}
4373			return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase();
4374		},
4375		CHILD: function(match){
4376			if ( match[1] == "nth" ) {
4377				var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
4378					match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
4379					!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
4380
4381				match[2] = (test[1] + (test[2] || 1)) - 0;
4382				match[3] = test[3] - 0;
4383			}
4384
4385			match[0] = done++;
4386
4387			return match;
4388		},
4389		ATTR: function(match, curLoop, inplace, result, not, isXML){
4390			var name = match[1].replace(/\\/g, "");
4391
4392			if ( !isXML && Expr.attrMap[name] ) {
4393				match[1] = Expr.attrMap[name];
4394			}
4395
4396			if ( match[2] === "~=" ) {
4397				match[4] = " " + match[4] + " ";
4398			}
4399
4400			return match;
4401		},
4402		PSEUDO: function(match, curLoop, inplace, result, not){
4403			if ( match[1] === "not" ) {
4404				if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
4405					match[3] = Sizzle(match[3], null, null, curLoop);
4406				} else {
4407					var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
4408					if ( !inplace ) {
4409						result.push.apply( result, ret );
4410					}
4411					return false;
4412				}
4413			} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
4414				return true;
4415			}
4416
4417			return match;
4418		},
4419		POS: function(match){
4420			match.unshift( true );
4421			return match;
4422		}
4423	},
4424	filters: {
4425		enabled: function(elem){
4426			return elem.disabled === false && elem.type !== "hidden";
4427		},
4428		disabled: function(elem){
4429			return elem.disabled === true;
4430		},
4431		checked: function(elem){
4432			return elem.checked === true;
4433		},
4434		selected: function(elem){
4435			elem.parentNode.selectedIndex;
4436			return elem.selected === true;
4437		},
4438		parent: function(elem){
4439			return !!elem.firstChild;
4440		},
4441		empty: function(elem){
4442			return !elem.firstChild;
4443		},
4444		has: function(elem, i, match){
4445			return !!Sizzle( match[3], elem ).length;
4446		},
4447		header: function(elem){
4448			return /h\d/i.test( elem.nodeName );
4449		},
4450		text: function(elem){
4451			return "text" === elem.type;
4452		},
4453		radio: function(elem){
4454			return "radio" === elem.type;
4455		},
4456		checkbox: function(elem){
4457			return "checkbox" === elem.type;
4458		},
4459		file: function(elem){
4460			return "file" === elem.type;
4461		},
4462		password: function(elem){
4463			return "password" === elem.type;
4464		},
4465		submit: function(elem){
4466			return "submit" === elem.type;
4467		},
4468		image: function(elem){
4469			return "image" === elem.type;
4470		},
4471		reset: function(elem){
4472			return "reset" === elem.type;
4473		},
4474		button: function(elem){
4475			return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
4476		},
4477		input: function(elem){
4478			return /input|select|textarea|button/i.test(elem.nodeName);
4479		}
4480	},
4481	setFilters: {
4482		first: function(elem, i){
4483			return i === 0;
4484		},
4485		last: function(elem, i, match, array){
4486			return i === array.length - 1;
4487		},
4488		even: function(elem, i){
4489			return i % 2 === 0;
4490		},
4491		odd: function(elem, i){
4492			return i % 2 === 1;
4493		},
4494		lt: function(elem, i, match){
4495			return i < match[3] - 0;
4496		},
4497		gt: function(elem, i, match){
4498			return i > match[3] - 0;
4499		},
4500		nth: function(elem, i, match){
4501			return match[3] - 0 == i;
4502		},
4503		eq: function(elem, i, match){
4504			return match[3] - 0 == i;
4505		}
4506	},
4507	filter: {
4508		PSEUDO: function(elem, match, i, array){
4509			var name = match[1], filter = Expr.filters[ name ];
4510
4511			if ( filter ) {
4512				return filter( elem, i, match, array );
4513			} else if ( name === "contains" ) {
4514				return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
4515			} else if ( name === "not" ) {
4516				var not = match[3];
4517
4518				for ( var i = 0, l = not.length; i < l; i++ ) {
4519					if ( not[i] === elem ) {
4520						return false;
4521					}
4522				}
4523
4524				return true;
4525			}
4526		},
4527		CHILD: function(elem, match){
4528			var type = match[1], node = elem;
4529			switch (type) {
4530				case 'only':
4531				case 'first':
4532					while ( (node = node.previousSibling) )  {
4533						if ( node.nodeType === 1 ) return false;
4534					}
4535					if ( type == 'first') return true;
4536					node = elem;
4537				case 'last':
4538					while ( (node = node.nextSibling) )  {
4539						if ( node.nodeType === 1 ) return false;
4540					}
4541					return true;
4542				case 'nth':
4543					var first = match[2], last = match[3];
4544
4545					if ( first == 1 && last == 0 ) {
4546						return true;
4547					}
4548
4549					var doneName = match[0],
4550						parent = elem.parentNode;
4551
4552					if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
4553						var count = 0;
4554						for ( node = parent.firstChild; node; node = node.nextSibling ) {
4555							if ( node.nodeType === 1 ) {
4556								node.nodeIndex = ++count;
4557							}
4558						}
4559						parent.sizcache = doneName;
4560					}
4561
4562					var diff = elem.nodeIndex - last;
4563					if ( first == 0 ) {
4564						return diff == 0;
4565					} else {
4566						return ( diff % first == 0 && diff / first >= 0 );
4567					}
4568			}
4569		},
4570		ID: function(elem, match){
4571			return elem.nodeType === 1 && elem.getAttribute("id") === match;
4572		},
4573		TAG: function(elem, match){
4574			return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
4575		},
4576		CLASS: function(elem, match){
4577			return (" " + (elem.className || elem.getAttribute("class")) + " ")
4578				.indexOf( match ) > -1;
4579		},
4580		ATTR: function(elem, match){
4581			var name = match[1],
4582				result = Expr.attrHandle[ name ] ?
4583					Expr.attrHandle[ name ]( elem ) :
4584					elem[ name ] != null ?
4585						elem[ name ] :
4586						elem.getAttribute( name ),
4587				value = result + "",
4588				type = match[2],
4589				check = match[4];
4590
4591			return result == null ?
4592				type === "!=" :
4593				type === "=" ?
4594				value === check :
4595				type === "*=" ?
4596				value.indexOf(check) >= 0 :
4597				type === "~=" ?
4598				(" " + value + " ").indexOf(check) >= 0 :
4599				!check ?
4600				value && result !== false :
4601				type === "!=" ?
4602				value != check :
4603				type === "^=" ?
4604				value.indexOf(check) === 0 :
4605				type === "$=" ?
4606				value.substr(value.length - check.length) === check :
4607				type === "|=" ?
4608				value === check || value.substr(0, check.length + 1) === check + "-" :
4609				false;
4610		},
4611		POS: function(elem, match, i, array){
4612			var name = match[2], filter = Expr.setFilters[ name ];
4613
4614			if ( filter ) {
4615				return filter( elem, i, match, array );
4616			}
4617		}
4618	}
4619};
4620
4621var origPOS = Expr.match.POS;
4622
4623for ( var type in Expr.match ) {
4624	Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
4625	Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source );
4626}
4627
4628var makeArray = function(array, results) {
4629	array = Array.prototype.slice.call( array, 0 );
4630
4631	if ( results ) {
4632		results.push.apply( results, array );
4633		return results;
4634	}
4635
4636	return array;
4637};
4638
4639try {
4640	Array.prototype.slice.call( document.documentElement.childNodes, 0 );
4641
4642} catch(e){
4643	makeArray = function(array, results) {
4644		var ret = results || [];
4645
4646		if ( toString.call(array) === "[object Array]" ) {
4647			Array.prototype.push.apply( ret, array );
4648		} else {
4649			if ( typeof array.length === "number" ) {
4650				for ( var i = 0, l = array.length; i < l; i++ ) {
4651					ret.push( array[i] );
4652				}
4653			} else {
4654				for ( var i = 0; array[i]; i++ ) {
4655					ret.push( array[i] );
4656				}
4657			}
4658		}
4659
4660		return ret;
4661	};
4662}
4663
4664var sortOrder;
4665
4666if ( document.documentElement.compareDocumentPosition ) {
4667	sortOrder = function( a, b ) {
4668		if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
4669			if ( a == b ) {
4670				hasDuplicate = true;
4671			}
4672			return 0;
4673		}
4674
4675		var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
4676		if ( ret === 0 ) {
4677			hasDuplicate = true;
4678		}
4679		return ret;
4680	};
4681} else if ( "sourceIndex" in document.documentElement ) {
4682	sortOrder = function( a, b ) {
4683		if ( !a.sourceIndex || !b.sourceIndex ) {
4684			if ( a == b ) {
4685				hasDuplicate = true;
4686			}
4687			return 0;
4688		}
4689
4690		var ret = a.sourceIndex - b.sourceIndex;
4691		if ( ret === 0 ) {
4692			hasDuplicate = true;
4693		}
4694		return ret;
4695	};
4696} else if ( document.createRange ) {
4697	sortOrder = function( a, b ) {
4698		if ( !a.ownerDocument || !b.ownerDocument ) {
4699			if ( a == b ) {
4700				hasDuplicate = true;
4701			}
4702			return 0;
4703		}
4704
4705		var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
4706		aRange.setStart(a, 0);
4707		aRange.setEnd(a, 0);
4708		bRange.setStart(b, 0);
4709		bRange.setEnd(b, 0);
4710		var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
4711		if ( ret === 0 ) {
4712			hasDuplicate = true;
4713		}
4714		return ret;
4715	};
4716}
4717
4718(function(){
4719	var form = document.createElement("div"),
4720		id = "script" + (new Date).getTime();
4721	form.innerHTML = "<a name='" + id + "'/>";
4722
4723	var root = document.documentElement;
4724	root.insertBefore( form, root.firstChild );
4725
4726	if ( !!document.getElementById( id ) ) {
4727		Expr.find.ID = function(match, context, isXML){
4728			if ( typeof context.getElementById !== "undefined" && !isXML ) {
4729				var m = context.getElementById(match[1]);
4730				return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
4731			}
4732		};
4733
4734		Expr.filter.ID = function(elem, match){
4735			var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
4736			return elem.nodeType === 1 && node && node.nodeValue === match;
4737		};
4738	}
4739
4740	root.removeChild( form );
4741	root = form = null; // release memory in IE
4742})();
4743
4744(function(){
4745
4746	var div = document.createElement("div");
4747	div.appendChild( document.createComment("") );
4748
4749	if ( div.getElementsByTagName("*").length > 0 ) {
4750		Expr.find.TAG = function(match, context){
4751			var results = context.getElementsByTagName(match[1]);
4752
4753			if ( match[1] === "*" ) {
4754				var tmp = [];
4755
4756				for ( var i = 0; results[i]; i++ ) {
4757					if ( results[i].nodeType === 1 ) {
4758						tmp.push( results[i] );
4759					}
4760				}
4761
4762				results = tmp;
4763			}
4764
4765			return results;
4766		};
4767	}
4768
4769	div.innerHTML = "<a href='#'></a>";
4770	if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
4771			div.firstChild.getAttribute("href") !== "#" ) {
4772		Expr.attrHandle.href = function(elem){
4773			return elem.getAttribute("href", 2);
4774		};
4775	}
4776
4777	div = null; // release memory in IE
4778})();
4779
4780if ( document.querySelectorAll ) (function(){
4781	var oldSizzle = Sizzle, div = document.createElement("div");
4782	div.innerHTML = "<p class='TEST'></p>";
4783
4784	if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
4785		return;
4786	}
4787
4788	Sizzle = function(query, context, extra, seed){
4789		context = context || document;
4790
4791		if ( !seed && context.nodeType === 9 && !isXML(context) ) {
4792			try {
4793				return makeArray( context.querySelectorAll(query), extra );
4794			} catch(e){}
4795		}
4796
4797		return oldSizzle(query, context, extra, seed);
4798	};
4799
4800	for ( var prop in oldSizzle ) {
4801		Sizzle[ prop ] = oldSizzle[ prop ];
4802	}
4803
4804	div = null; // release memory in IE
4805})();
4806
4807if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
4808	var div = document.createElement("div");
4809	div.innerHTML = "<div class='test e'></div><div class='test'></div>";
4810
4811	if ( div.getElementsByClassName("e").length === 0 )
4812		return;
4813
4814	div.lastChild.className = "e";
4815
4816	if ( div.getElementsByClassName("e").length === 1 )
4817		return;
4818
4819	Expr.order.splice(1, 0, "CLASS");
4820	Expr.find.CLASS = function(match, context, isXML) {
4821		if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
4822			return context.getElementsByClassName(match[1]);
4823		}
4824	};
4825
4826	div = null; // release memory in IE
4827})();
4828
4829function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
4830	var sibDir = dir == "previousSibling" && !isXML;
4831	for ( var i = 0, l = checkSet.length; i < l; i++ ) {
4832		var elem = checkSet[i];
4833		if ( elem ) {
4834			if ( sibDir && elem.nodeType === 1 ){
4835				elem.sizcache = doneName;
4836				elem.sizset = i;
4837			}
4838			elem = elem[dir];
4839			var match = false;
4840
4841			while ( elem ) {
4842				if ( elem.sizcache === doneName ) {
4843					match = checkSet[elem.sizset];
4844					break;
4845				}
4846
4847				if ( elem.nodeType === 1 && !isXML ){
4848					elem.sizcache = doneName;
4849					elem.sizset = i;
4850				}
4851
4852				if ( elem.nodeName === cur ) {
4853					match = elem;
4854					break;
4855				}
4856
4857				elem = elem[dir];
4858			}
4859
4860			checkSet[i] = match;
4861		}
4862	}
4863}
4864
4865function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
4866	var sibDir = dir == "previousSibling" && !isXML;
4867	for ( var i = 0, l = checkSet.length; i < l; i++ ) {
4868		var elem = checkSet[i];
4869		if ( elem ) {
4870			if ( sibDir && elem.nodeType === 1 ) {
4871				elem.sizcache = doneName;
4872				elem.sizset = i;
4873			}
4874			elem = elem[dir];
4875			var match = false;
4876
4877			while ( elem ) {
4878				if ( elem.sizcache === doneName ) {
4879					match = checkSet[elem.sizset];
4880					break;
4881				}
4882
4883				if ( elem.nodeType === 1 ) {
4884					if ( !isXML ) {
4885						elem.sizcache = doneName;
4886						elem.sizset = i;
4887					}
4888					if ( typeof cur !== "string" ) {
4889						if ( elem === cur ) {
4890							match = true;
4891							break;
4892						}
4893
4894					} else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
4895						match = elem;
4896						break;
4897					}
4898				}
4899
4900				elem = elem[dir];
4901			}
4902
4903			checkSet[i] = match;
4904		}
4905	}
4906}
4907
4908var contains = document.compareDocumentPosition ?  function(a, b){
4909	return a.compareDocumentPosition(b) & 16;
4910} : function(a, b){
4911	return a !== b && (a.contains ? a.contains(b) : true);
4912};
4913
4914var isXML = function(elem){
4915	return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
4916		!!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
4917};
4918
4919var posProcess = function(selector, context){
4920	var tmpSet = [], later = "", match,
4921		root = context.nodeType ? [context] : context;
4922
4923	while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
4924		later += match[0];
4925		selector = selector.replace( Expr.match.PSEUDO, "" );
4926	}
4927
4928	selector = Expr.relative[selector] ? selector + "*" : selector;
4929
4930	for ( var i = 0, l = root.length; i < l; i++ ) {
4931		Sizzle( selector, root[i], tmpSet );
4932	}
4933
4934	return Sizzle.filter( later, tmpSet );
4935};
4936
4937
4938window.Sizzle = Sizzle;
4939
4940})();
4941
4942Prototype._original_property = window.Sizzle;
4943
4944;(function(engine) {
4945  var extendElements = Prototype.Selector.extendElements;
4946
4947  function select(selector, scope) {
4948    return extendElements(engine(selector, scope || document));
4949  }
4950
4951  function match(element, selector) {
4952    return engine.matches(selector, [element]).length == 1;
4953  }
4954
4955  Prototype.Selector.engine = engine;
4956  Prototype.Selector.select = select;
4957  Prototype.Selector.match = match;
4958})(Sizzle);
4959
4960window.Sizzle = Prototype._original_property;
4961delete Prototype._original_property;
4962
4963var Form = {
4964  reset: function(form) {
4965    form = $(form);
4966    form.reset();
4967    return form;
4968  },
4969
4970  serializeElements: function(elements, options) {
4971    if (typeof options != 'object') options = { hash: !!options };
4972    else if (Object.isUndefined(options.hash)) options.hash = true;
4973    var key, value, submitted = false, submit = options.submit, accumulator, initial;
4974
4975    if (options.hash) {
4976      initial = {};
4977      accumulator = function(result, key, value) {
4978        if (key in result) {
4979          if (!Object.isArray(result[key])) result[key] = [result[key]];
4980          result[key].push(value);
4981        } else result[key] = value;
4982        return result;
4983      };
4984    } else {
4985      initial = '';
4986      accumulator = function(result, key, value) {
4987        return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + encodeURIComponent(value);
4988      }
4989    }
4990
4991    return elements.inject(initial, function(result, element) {
4992      if (!element.disabled && element.name) {
4993        key = element.name; value = $(element).getValue();
4994        if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
4995            submit !== false && (!submit || key == submit) && (submitted = true)))) {
4996          result = accumulator(result, key, value);
4997        }
4998      }
4999      return result;
5000    });
5001  }
5002};
5003
5004Form.Methods = {
5005  serialize: function(form, options) {
5006    return Form.serializeElements(Form.getElements(form), options);
5007  },
5008
5009  getElements: function(form) {
5010    var elements = $(form).getElementsByTagName('*'),
5011        element,
5012        arr = [ ],
5013        serializers = Form.Element.Serializers;
5014    for (var i = 0; element = elements[i]; i++) {
5015      arr.push(element);
5016    }
5017    return arr.inject([], function(elements, child) {
5018      if (serializers[child.tagName.toLowerCase()])
5019        elements.push(Element.extend(child));
5020      return elements;
5021    })
5022  },
5023
5024  getInputs: function(form, typeName, name) {
5025    form = $(form);
5026    var inputs = form.getElementsByTagName('input');
5027
5028    if (!typeName && !name) return $A(inputs).map(Element.extend);
5029
5030    for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
5031      var input = inputs[i];
5032      if ((typeName && input.type != typeName) || (name && input.name != name))
5033        continue;
5034      matchingInputs.push(Element.extend(input));
5035    }
5036
5037    return matchingInputs;
5038  },
5039
5040  disable: function(form) {
5041    form = $(form);
5042    Form.getElements(form).invoke('disable');
5043    return form;
5044  },
5045
5046  enable: function(form) {
5047    form = $(form);
5048    Form.getElements(form).invoke('enable');
5049    return form;
5050  },
5051
5052  findFirstElement: function(form) {
5053    var elements = $(form).getElements().findAll(function(element) {
5054      return 'hidden' != element.type && !element.disabled;
5055    });
5056    var firstByIndex = elements.findAll(function(element) {
5057      return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
5058    }).sortBy(function(element) { return element.tabIndex }).first();
5059
5060    return firstByIndex ? firstByIndex : elements.find(function(element) {
5061      return /^(?:input|select|textarea)$/i.test(element.tagName);
5062    });
5063  },
5064
5065  focusFirstElement: function(form) {
5066    form = $(form);
5067    var element = form.findFirstElement();
5068    if (element) element.activate();
5069    return form;
5070  },
5071
5072  request: function(form, options) {
5073    form = $(form), options = Object.clone(options || { });
5074
5075    var params = options.parameters, action = form.readAttribute('action') || '';
5076    if (action.blank()) action = window.location.href;
5077    options.parameters = form.serialize(true);
5078
5079    if (params) {
5080      if (Object.isString(params)) params = params.toQueryParams();
5081      Object.extend(options.parameters, params);
5082    }
5083
5084    if (form.hasAttribute('method') && !options.method)
5085      options.method = form.method;
5086
5087    return new Ajax.Request(action, options);
5088  }
5089};
5090
5091/*--------------------------------------------------------------------------*/
5092
5093
5094Form.Element = {
5095  focus: function(element) {
5096    $(element).focus();
5097    return element;
5098  },
5099
5100  select: function(element) {
5101    $(element).select();
5102    return element;
5103  }
5104};
5105
5106Form.Element.Methods = {
5107
5108  serialize: function(element) {
5109    element = $(element);
5110    if (!element.disabled && element.name) {
5111      var value = element.getValue();
5112      if (value != undefined) {
5113        var pair = { };
5114        pair[element.name] = value;
5115        return Object.toQueryString(pair);
5116      }
5117    }
5118    return '';
5119  },
5120
5121  getValue: function(element) {
5122    element = $(element);
5123    var method = element.tagName.toLowerCase();
5124    return Form.Element.Serializers[method](element);
5125  },
5126
5127  setValue: function(element, value) {
5128    element = $(element);
5129    var method = element.tagName.toLowerCase();
5130    Form.Element.Serializers[method](element, value);
5131    return element;
5132  },
5133
5134  clear: function(element) {
5135    $(element).value = '';
5136    return element;
5137  },
5138
5139  present: function(element) {
5140    return $(element).value != '';
5141  },
5142
5143  activate: function(element) {
5144    element = $(element);
5145    try {
5146      element.focus();
5147      if (element.select && (element.tagName.toLowerCase() != 'input' ||
5148          !(/^(?:button|reset|submit)$/i.test(element.type))))
5149        element.select();
5150    } catch (e) { }
5151    return element;
5152  },
5153
5154  disable: function(element) {
5155    element = $(element);
5156    element.disabled = true;
5157    return element;
5158  },
5159
5160  enable: function(element) {
5161    element = $(element);
5162    element.disabled = false;
5163    return element;
5164  }
5165};
5166
5167/*--------------------------------------------------------------------------*/
5168
5169var Field = Form.Element;
5170
5171var $F = Form.Element.Methods.getValue;
5172
5173/*--------------------------------------------------------------------------*/
5174
5175Form.Element.Serializers = (function() {
5176  function input(element, value) {
5177    switch (element.type.toLowerCase()) {
5178      case 'checkbox':
5179      case 'radio':
5180        return inputSelector(element, value);
5181      default:
5182        return valueSelector(element, value);
5183    }
5184  }
5185
5186  function inputSelector(element, value) {
5187    if (Object.isUndefined(value))
5188      return element.checked ? element.value : null;
5189    else element.checked = !!value;
5190  }
5191
5192  function valueSelector(element, value) {
5193    if (Object.isUndefined(value)) return element.value;
5194    else element.value = value;
5195  }
5196
5197  function select(element, value) {
5198    if (Object.isUndefined(value))
5199      return (element.type === 'select-one' ? selectOne : selectMany)(element);
5200
5201    var opt, currentValue, single = !Object.isArray(value);
5202    for (var i = 0, length = element.length; i < length; i++) {
5203      opt = element.options[i];
5204      currentValue = this.optionValue(opt);
5205      if (single) {
5206        if (currentValue == value) {
5207          opt.selected = true;
5208          return;
5209        }
5210      }
5211      else opt.selected = value.include(currentValue);
5212    }
5213  }
5214
5215  function selectOne(element) {
5216    var index = element.selectedIndex;
5217    return index >= 0 ? optionValue(element.options[index]) : null;
5218  }
5219
5220  function selectMany(element) {
5221    var values, length = element.length;
5222    if (!length) return null;
5223
5224    for (var i = 0, values = []; i < length; i++) {
5225      var opt = element.options[i];
5226      if (opt.selected) values.push(optionValue(opt));
5227    }
5228    return values;
5229  }
5230
5231  function optionValue(opt) {
5232    return Element.hasAttribute(opt, 'value') ? opt.value : opt.text;
5233  }
5234
5235  return {
5236    input:         input,
5237    inputSelector: inputSelector,
5238    textarea:      valueSelector,
5239    select:        select,
5240    selectOne:     selectOne,
5241    selectMany:    selectMany,
5242    optionValue:   optionValue,
5243    button:        valueSelector
5244  };
5245})();
5246
5247/*--------------------------------------------------------------------------*/
5248
5249
5250Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
5251  initialize: function($super, element, frequency, callback) {
5252    $super(callback, frequency);
5253    this.element   = $(element);
5254    this.lastValue = this.getValue();
5255  },
5256
5257  execute: function() {
5258    var value = this.getValue();
5259    if (Object.isString(this.lastValue) && Object.isString(value) ?
5260        this.lastValue != value : String(this.lastValue) != String(value)) {
5261      this.callback(this.element, value);
5262      this.lastValue = value;
5263    }
5264  }
5265});
5266
5267Form.Element.Observer = Class.create(Abstract.TimedObserver, {
5268  getValue: function() {
5269    return Form.Element.getValue(this.element);
5270  }
5271});
5272
5273Form.Observer = Class.create(Abstract.TimedObserver, {
5274  getValue: function() {
5275    return Form.serialize(this.element);
5276  }
5277});
5278
5279/*--------------------------------------------------------------------------*/
5280
5281Abstract.EventObserver = Class.create({
5282  initialize: function(element, callback) {
5283    this.element  = $(element);
5284    this.callback = callback;
5285
5286    this.lastValue = this.getValue();
5287    if (this.element.tagName.toLowerCase() == 'form')
5288      this.registerFormCallbacks();
5289    else
5290      this.registerCallback(this.element);
5291  },
5292
5293  onElementEvent: function() {
5294    var value = this.getValue();
5295    if (this.lastValue != value) {
5296      this.callback(this.element, value);
5297      this.lastValue = value;
5298    }
5299  },
5300
5301  registerFormCallbacks: function() {
5302    Form.getElements(this.element).each(this.registerCallback, this);
5303  },
5304
5305  registerCallback: function(element) {
5306    if (element.type) {
5307      switch (element.type.toLowerCase()) {
5308        case 'checkbox':
5309        case 'radio':
5310          Event.observe(element, 'click', this.onElementEvent.bind(this));
5311          break;
5312        default:
5313          Event.observe(element, 'change', this.onElementEvent.bind(this));
5314          break;
5315      }
5316    }
5317  }
5318});
5319
5320Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
5321  getValue: function() {
5322    return Form.Element.getValue(this.element);
5323  }
5324});
5325
5326Form.EventObserver = Class.create(Abstract.EventObserver, {
5327  getValue: function() {
5328    return Form.serialize(this.element);
5329  }
5330});
5331(function() {
5332
5333  var Event = {
5334    KEY_BACKSPACE: 8,
5335    KEY_TAB:       9,
5336    KEY_RETURN:   13,
5337    KEY_ESC:      27,
5338    KEY_LEFT:     37,
5339    KEY_UP:       38,
5340    KEY_RIGHT:    39,
5341    KEY_DOWN:     40,
5342    KEY_DELETE:   46,
5343    KEY_HOME:     36,
5344    KEY_END:      35,
5345    KEY_PAGEUP:   33,
5346    KEY_PAGEDOWN: 34,
5347    KEY_INSERT:   45,
5348
5349    cache: {}
5350  };
5351
5352  var docEl = document.documentElement;
5353  var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
5354    && 'onmouseleave' in docEl;
5355
5356
5357
5358  var isIELegacyEvent = function(event) { return false; };
5359
5360  if (window.attachEvent) {
5361    if (window.addEventListener) {
5362      isIELegacyEvent = function(event) {
5363        return !(event instanceof window.Event);
5364      };
5365    } else {
5366      isIELegacyEvent = function(event) { return true; };
5367    }
5368  }
5369
5370  var _isButton;
5371
5372  function _isButtonForDOMEvents(event, code) {
5373    return event.which ? (event.which === code + 1) : (event.button === code);
5374  }
5375
5376  var legacyButtonMap = { 0: 1, 1: 4, 2: 2 };
5377  function _isButtonForLegacyEvents(event, code) {
5378    return event.button === legacyButtonMap[code];
5379  }
5380
5381  function _isButtonForWebKit(event, code) {
5382    switch (code) {
5383      case 0: return event.which == 1 && !event.metaKey;
5384      case 1: return event.which == 2 || (event.which == 1 && event.metaKey);
5385      case 2: return event.which == 3;
5386      default: return false;
5387    }
5388  }
5389
5390  if (window.attachEvent) {
5391    if (!window.addEventListener) {
5392      _isButton = _isButtonForLegacyEvents;
5393    } else {
5394      _isButton = function(event, code) {
5395        return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) :
5396         _isButtonForDOMEvents(event, code);
5397      }
5398    }
5399  } else if (Prototype.Browser.WebKit) {
5400    _isButton = _isButtonForWebKit;
5401  } else {
5402    _isButton = _isButtonForDOMEvents;
5403  }
5404
5405  function isLeftClick(event)   { return _isButton(event, 0) }
5406
5407  function isMiddleClick(event) { return _isButton(event, 1) }
5408
5409  function isRightClick(event)  { return _isButton(event, 2) }
5410
5411  function element(event) {
5412    event = Event.extend(event);
5413
5414    var node = event.target, type = event.type,
5415     currentTarget = event.currentTarget;
5416
5417    if (currentTarget && currentTarget.tagName) {
5418      if (type === 'load' || type === 'error' ||
5419        (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
5420          && currentTarget.type === 'radio'))
5421            node = currentTarget;
5422    }
5423
5424    if (node.nodeType == Node.TEXT_NODE)
5425      node = node.parentNode;
5426
5427    return Element.extend(node);
5428  }
5429
5430  function findElement(event, expression) {
5431    var element = Event.element(event);
5432
5433    if (!expression) return element;
5434    while (element) {
5435      if (Object.isElement(element) && Prototype.Selector.match(element, expression)) {
5436        return Element.extend(element);
5437      }
5438      element = element.parentNode;
5439    }
5440  }
5441
5442  function pointer(event) {
5443    return { x: pointerX(event), y: pointerY(event) };
5444  }
5445
5446  function pointerX(event) {
5447    var docElement = document.documentElement,
5448     body = document.body || { scrollLeft: 0 };
5449
5450    return event.pageX || (event.clientX +
5451      (docElement.scrollLeft || body.scrollLeft) -
5452      (docElement.clientLeft || 0));
5453  }
5454
5455  function pointerY(event) {
5456    var docElement = document.documentElement,
5457     body = document.body || { scrollTop: 0 };
5458
5459    return  event.pageY || (event.clientY +
5460       (docElement.scrollTop || body.scrollTop) -
5461       (docElement.clientTop || 0));
5462  }
5463
5464
5465  function stop(event) {
5466    Event.extend(event);
5467    event.preventDefault();
5468    event.stopPropagation();
5469
5470    event.stopped = true;
5471  }
5472
5473
5474  Event.Methods = {
5475    isLeftClick:   isLeftClick,
5476    isMiddleClick: isMiddleClick,
5477    isRightClick:  isRightClick,
5478
5479    element:     element,
5480    findElement: findElement,
5481
5482    pointer:  pointer,
5483    pointerX: pointerX,
5484    pointerY: pointerY,
5485
5486    stop: stop
5487  };
5488
5489  var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
5490    m[name] = Event.Methods[name].methodize();
5491    return m;
5492  });
5493
5494  if (window.attachEvent) {
5495    function _relatedTarget(event) {
5496      var element;
5497      switch (event.type) {
5498        case 'mouseover':
5499        case 'mouseenter':
5500          element = event.fromElement;
5501          break;
5502        case 'mouseout':
5503        case 'mouseleave':
5504          element = event.toElement;
5505          break;
5506        default:
5507          return null;
5508      }
5509      return Element.extend(element);
5510    }
5511
5512    var additionalMethods = {
5513      stopPropagation: function() { this.cancelBubble = true },
5514      preventDefault:  function() { this.returnValue = false },
5515      inspect: function() { return '[object Event]' }
5516    };
5517
5518    Event.extend = function(event, element) {
5519      if (!event) return false;
5520
5521      if (!isIELegacyEvent(event)) return event;
5522
5523      if (event._extendedByPrototype) return event;
5524      event._extendedByPrototype = Prototype.emptyFunction;
5525
5526      var pointer = Event.pointer(event);
5527
5528      Object.extend(event, {
5529        target: event.srcElement || element,
5530        relatedTarget: _relatedTarget(event),
5531        pageX:  pointer.x,
5532        pageY:  pointer.y
5533      });
5534
5535      Object.extend(event, methods);
5536      Object.extend(event, additionalMethods);
5537
5538      return event;
5539    };
5540  } else {
5541    Event.extend = Prototype.K;
5542  }
5543
5544  if (window.addEventListener) {
5545    Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__;
5546    Object.extend(Event.prototype, methods);
5547  }
5548
5549  function _createResponder(element, eventName, handler) {
5550    var registry = Element.retrieve(element, 'prototype_event_registry');
5551
5552    if (Object.isUndefined(registry)) {
5553      CACHE.push(element);
5554      registry = Element.retrieve(element, 'prototype_event_registry', $H());
5555    }
5556
5557    var respondersForEvent = registry.get(eventName);
5558    if (Object.isUndefined(respondersForEvent)) {
5559      respondersForEvent = [];
5560      registry.set(eventName, respondersForEvent);
5561    }
5562
5563    if (respondersForEvent.pluck('handler').include(handler)) return false;
5564
5565    var responder;
5566    if (eventName.include(":")) {
5567      responder = function(event) {
5568        if (Object.isUndefined(event.eventName))
5569          return false;
5570
5571        if (event.eventName !== eventName)
5572          return false;
5573
5574        Event.extend(event, element);
5575        handler.call(element, event);
5576      };
5577    } else {
5578      if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED &&
5579       (eventName === "mouseenter" || eventName === "mouseleave")) {
5580        if (eventName === "mouseenter" || eventName === "mouseleave") {
5581          responder = function(event) {
5582            Event.extend(event, element);
5583
5584            var parent = event.relatedTarget;
5585            while (parent && parent !== element) {
5586              try { parent = parent.parentNode; }
5587              catch(e) { parent = element; }
5588            }
5589
5590            if (parent === element) return;
5591
5592            handler.call(element, event);
5593          };
5594        }
5595      } else {
5596        responder = function(event) {
5597          Event.extend(event, element);
5598          handler.call(element, event);
5599        };
5600      }
5601    }
5602
5603    responder.handler = handler;
5604    respondersForEvent.push(responder);
5605    return responder;
5606  }
5607
5608  function _destroyCache() {
5609    for (var i = 0, length = CACHE.length; i < length; i++) {
5610      Event.stopObserving(CACHE[i]);
5611      CACHE[i] = null;
5612    }
5613  }
5614
5615  var CACHE = [];
5616
5617  if (Prototype.Browser.IE)
5618    window.attachEvent('onunload', _destroyCache);
5619
5620  if (Prototype.Browser.WebKit)
5621    window.addEventListener('unload', Prototype.emptyFunction, false);
5622
5623
5624  var _getDOMEventName = Prototype.K,
5625      translations = { mouseenter: "mouseover", mouseleave: "mouseout" };
5626
5627  if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) {
5628    _getDOMEventName = function(eventName) {
5629      return (translations[eventName] || eventName);
5630    };
5631  }
5632
5633  function observe(element, eventName, handler) {
5634    element = $(element);
5635
5636    var responder = _createResponder(element, eventName, handler);
5637
5638    if (!responder) return element;
5639
5640    if (eventName.include(':')) {
5641      if (element.addEventListener)
5642        element.addEventListener("dataavailable", responder, false);
5643      else {
5644        element.attachEvent("ondataavailable", responder);
5645        element.attachEvent("onlosecapture", responder);
5646      }
5647    } else {
5648      var actualEventName = _getDOMEventName(eventName);
5649
5650      if (element.addEventListener)
5651        element.addEventListener(actualEventName, responder, false);
5652      else
5653        element.attachEvent("on" + actualEventName, responder);
5654    }
5655
5656    return element;
5657  }
5658
5659  function stopObserving(element, eventName, handler) {
5660    element = $(element);
5661
5662    var registry = Element.retrieve(element, 'prototype_event_registry');
5663    if (!registry) return element;
5664
5665    if (!eventName) {
5666      registry.each( function(pair) {
5667        var eventName = pair.key;
5668        stopObserving(element, eventName);
5669      });
5670      return element;
5671    }
5672
5673    var responders = registry.get(eventName);
5674    if (!responders) return element;
5675
5676    if (!handler) {
5677      responders.each(function(r) {
5678        stopObserving(element, eventName, r.handler);
5679      });
5680      return element;
5681    }
5682
5683    var i = responders.length, responder;
5684    while (i--) {
5685      if (responders[i].handler === handler) {
5686        responder = responders[i];
5687        break;
5688      }
5689    }
5690    if (!responder) return element;
5691
5692    if (eventName.include(':')) {
5693      if (element.removeEventListener)
5694        element.removeEventListener("dataavailable", responder, false);
5695      else {
5696        element.detachEvent("ondataavailable", responder);
5697        element.detachEvent("onlosecapture", responder);
5698      }
5699    } else {
5700      var actualEventName = _getDOMEventName(eventName);
5701      if (element.removeEventListener)
5702        element.removeEventListener(actualEventName, responder, false);
5703      else
5704        element.detachEvent('on' + actualEventName, responder);
5705    }
5706
5707    registry.set(eventName, responders.without(responder));
5708
5709    return element;
5710  }
5711
5712  function fire(element, eventName, memo, bubble) {
5713    element = $(element);
5714
5715    if (Object.isUndefined(bubble))
5716      bubble = true;
5717
5718    if (element == document && document.createEvent && !element.dispatchEvent)
5719      element = document.documentElement;
5720
5721    var event;
5722    if (document.createEvent) {
5723      event = document.createEvent('HTMLEvents');
5724      event.initEvent('dataavailable', bubble, true);
5725    } else {
5726      event = document.createEventObject();
5727      event.eventType = bubble ? 'ondataavailable' : 'onlosecapture';
5728    }
5729
5730    event.eventName = eventName;
5731    event.memo = memo || { };
5732
5733    if (document.createEvent)
5734      element.dispatchEvent(event);
5735    else
5736      element.fireEvent(event.eventType, event);
5737
5738    return Event.extend(event);
5739  }
5740
5741  Event.Handler = Class.create({
5742    initialize: function(element, eventName, selector, callback) {
5743      this.element   = $(element);
5744      this.eventName = eventName;
5745      this.selector  = selector;
5746      this.callback  = callback;
5747      this.handler   = this.handleEvent.bind(this);
5748    },
5749
5750    start: function() {
5751      Event.observe(this.element, this.eventName, this.handler);
5752      return this;
5753    },
5754
5755    stop: function() {
5756      Event.stopObserving(this.element, this.eventName, this.handler);
5757      return this;
5758    },
5759
5760    handleEvent: function(event) {
5761      var element = Event.findElement(event, this.selector);
5762      if (element) this.callback.call(this.element, event, element);
5763    }
5764  });
5765
5766  function on(element, eventName, selector, callback) {
5767    element = $(element);
5768    if (Object.isFunction(selector) && Object.isUndefined(callback)) {
5769      callback = selector, selector = null;
5770    }
5771
5772    return new Event.Handler(element, eventName, selector, callback).start();
5773  }
5774
5775  Object.extend(Event, Event.Methods);
5776
5777  Object.extend(Event, {
5778    fire:          fire,
5779    observe:       observe,
5780    stopObserving: stopObserving,
5781    on:            on
5782  });
5783
5784  Element.addMethods({
5785    fire:          fire,
5786
5787    observe:       observe,
5788
5789    stopObserving: stopObserving,
5790
5791    on:            on
5792  });
5793
5794  Object.extend(document, {
5795    fire:          fire.methodize(),
5796
5797    observe:       observe.methodize(),
5798
5799    stopObserving: stopObserving.methodize(),
5800
5801    on:            on.methodize(),
5802
5803    loaded:        false
5804  });
5805
5806  if (window.Event) Object.extend(window.Event, Event);
5807  else window.Event = Event;
5808})();
5809
5810(function() {
5811  /* Support for the DOMContentLoaded event is based on work by Dan Webb,
5812     Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */
5813
5814  var timer;
5815
5816  function fireContentLoadedEvent() {
5817    if (document.loaded) return;
5818    if (timer) window.clearTimeout(timer);
5819    document.loaded = true;
5820    document.fire('dom:loaded');
5821  }
5822
5823  function checkReadyState() {
5824    if (document.readyState === 'complete') {
5825      document.stopObserving('readystatechange', checkReadyState);
5826      fireContentLoadedEvent();
5827    }
5828  }
5829
5830  function pollDoScroll() {
5831    try { document.documentElement.doScroll('left'); }
5832    catch(e) {
5833      timer = pollDoScroll.defer();
5834      return;
5835    }
5836    fireContentLoadedEvent();
5837  }
5838
5839  if (document.addEventListener) {
5840    document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);
5841  } else {
5842    document.observe('readystatechange', checkReadyState);
5843    if (window == top)
5844      timer = pollDoScroll.defer();
5845  }
5846
5847  Event.observe(window, 'load', fireContentLoadedEvent);
5848})();
5849
5850
5851Element.addMethods();
5852/*------------------------------- DEPRECATED -------------------------------*/
5853
5854Hash.toQueryString = Object.toQueryString;
5855
5856var Toggle = { display: Element.toggle };
5857
5858Element.Methods.childOf = Element.Methods.descendantOf;
5859
5860var Insertion = {
5861  Before: function(element, content) {
5862    return Element.insert(element, {before:content});
5863  },
5864
5865  Top: function(element, content) {
5866    return Element.insert(element, {top:content});
5867  },
5868
5869  Bottom: function(element, content) {
5870    return Element.insert(element, {bottom:content});
5871  },
5872
5873  After: function(element, content) {
5874    return Element.insert(element, {after:content});
5875  }
5876};
5877
5878var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
5879
5880var Position = {
5881  includeScrollOffsets: false,
5882
5883  prepare: function() {
5884    this.deltaX =  window.pageXOffset
5885                || document.documentElement.scrollLeft
5886                || document.body.scrollLeft
5887                || 0;
5888    this.deltaY =  window.pageYOffset
5889                || document.documentElement.scrollTop
5890                || document.body.scrollTop
5891                || 0;
5892  },
5893
5894  within: function(element, x, y) {
5895    if (this.includeScrollOffsets)
5896      return this.withinIncludingScrolloffsets(element, x, y);
5897    this.xcomp = x;
5898    this.ycomp = y;
5899    this.offset = Element.cumulativeOffset(element);
5900
5901    return (y >= this.offset[1] &&
5902            y <  this.offset[1] + element.offsetHeight &&
5903            x >= this.offset[0] &&
5904            x <  this.offset[0] + element.offsetWidth);
5905  },
5906
5907  withinIncludingScrolloffsets: function(element, x, y) {
5908    var offsetcache = Element.cumulativeScrollOffset(element);
5909
5910    this.xcomp = x + offsetcache[0] - this.deltaX;
5911    this.ycomp = y + offsetcache[1] - this.deltaY;
5912    this.offset = Element.cumulativeOffset(element);
5913
5914    return (this.ycomp >= this.offset[1] &&
5915            this.ycomp <  this.offset[1] + element.offsetHeight &&
5916            this.xcomp >= this.offset[0] &&
5917            this.xcomp <  this.offset[0] + element.offsetWidth);
5918  },
5919
5920  overlap: function(mode, element) {
5921    if (!mode) return 0;
5922    if (mode == 'vertical')
5923      return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
5924        element.offsetHeight;
5925    if (mode == 'horizontal')
5926      return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
5927        element.offsetWidth;
5928  },
5929
5930
5931  cumulativeOffset: Element.Methods.cumulativeOffset,
5932
5933  positionedOffset: Element.Methods.positionedOffset,
5934
5935  absolutize: function(element) {
5936    Position.prepare();
5937    return Element.absolutize(element);
5938  },
5939
5940  relativize: function(element) {
5941    Position.prepare();
5942    return Element.relativize(element);
5943  },
5944
5945  realOffset: Element.Methods.cumulativeScrollOffset,
5946
5947  offsetParent: Element.Methods.getOffsetParent,
5948
5949  page: Element.Methods.viewportOffset,
5950
5951  clone: function(source, target, options) {
5952    options = options || { };
5953    return Element.clonePosition(target, source, options);
5954  }
5955};
5956
5957/*--------------------------------------------------------------------------*/
5958
5959if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
5960  function iter(name) {
5961    return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
5962  }
5963
5964  instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
5965  function(element, className) {
5966    className = className.toString().strip();
5967    var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
5968    return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
5969  } : function(element, className) {
5970    className = className.toString().strip();
5971    var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
5972    if (!classNames && !className) return elements;
5973
5974    var nodes = $(element).getElementsByTagName('*');
5975    className = ' ' + className + ' ';
5976
5977    for (var i = 0, child, cn; child = nodes[i]; i++) {
5978      if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
5979          (classNames && classNames.all(function(name) {
5980            return !name.toString().blank() && cn.include(' ' + name + ' ');
5981          }))))
5982        elements.push(Element.extend(child));
5983    }
5984    return elements;
5985  };
5986
5987  return function(className, parentElement) {
5988    return $(parentElement || document.body).getElementsByClassName(className);
5989  };
5990}(Element.Methods);
5991
5992/*--------------------------------------------------------------------------*/
5993
5994Element.ClassNames = Class.create();
5995Element.ClassNames.prototype = {
5996  initialize: function(element) {
5997    this.element = $(element);
5998  },
5999
6000  _each: function(iterator) {
6001    this.element.className.split(/\s+/).select(function(name) {
6002      return name.length > 0;
6003    })._each(iterator);
6004  },
6005
6006  set: function(className) {
6007    this.element.className = className;
6008  },
6009
6010  add: function(classNameToAdd) {
6011    if (this.include(classNameToAdd)) return;
6012    this.set($A(this).concat(classNameToAdd).join(' '));
6013  },
6014
6015  remove: function(classNameToRemove) {
6016    if (!this.include(classNameToRemove)) return;
6017    this.set($A(this).without(classNameToRemove).join(' '));
6018  },
6019
6020  toString: function() {
6021    return $A(this).join(' ');
6022  }
6023};
6024
6025Object.extend(Element.ClassNames.prototype, Enumerable);
6026
6027/*--------------------------------------------------------------------------*/
6028
6029(function() {
6030  window.Selector = Class.create({
6031    initialize: function(expression) {
6032      this.expression = expression.strip();
6033    },
6034
6035    findElements: function(rootElement) {
6036      return Prototype.Selector.select(this.expression, rootElement);
6037    },
6038
6039    match: function(element) {
6040      return Prototype.Selector.match(element, this.expression);
6041    },
6042
6043    toString: function() {
6044      return this.expression;
6045    },
6046
6047    inspect: function() {
6048      return "#<Selector: " + this.expression + ">";
6049    }
6050  });
6051
6052  Object.extend(Selector, {
6053    matchElements: function(elements, expression) {
6054      var match = Prototype.Selector.match,
6055          results = [];
6056
6057      for (var i = 0, length = elements.length; i < length; i++) {
6058        var element = elements[i];
6059        if (match(element, expression)) {
6060          results.push(Element.extend(element));
6061        }
6062      }
6063      return results;
6064    },
6065
6066    findElement: function(elements, expression, index) {
6067      index = index || 0;
6068      var matchIndex = 0, element;
6069      for (var i = 0, length = elements.length; i < length; i++) {
6070        element = elements[i];
6071        if (Prototype.Selector.match(element, expression) && index === matchIndex++) {
6072          return Element.extend(element);
6073        }
6074      }
6075    },
6076
6077    findChildElements: function(element, expressions) {
6078      var selector = expressions.toArray().join(', ');
6079      return Prototype.Selector.select(selector, element || document);
6080    }
6081  });
6082})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.