function htmlspecialchars(text) {
    if (typeof(text) == 'undefined' || !text.toString) {
        return ''
    }
    return text.toString().replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#039;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
}
function elementX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent
        }
    } else if (obj.x) curleft += obj.x;
    return curleft
}
function elementY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent
        }
    } else if (obj.y) curtop += obj.y;
    return curtop
}
function set_inner_html(obj, html) {
    obj.innerHTML = html;
    var scripts = obj.getElementsByTagName('script');
    for (var i = 0; i < scripts.length; i++) {
        if (scripts[i].src) {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = scripts[i].src;
            document.body.appendChild(script)
        } else {
            eval(scripts[i].innerHTML)
        }
    }
}
function set_opacity(obj, opacity) {
    try {
        obj.style.opacity = (opacity == 1 ? '': opacity);
        obj.style.filter = (opacity == 1 ? '': 'alpha(opacity=' + opacity * 100 + ')')
    } catch(e) {}
    obj.setAttribute('opacity', opacity)
}
function get_opacity(obj) {
    return obj.opacity ? obj.opacity: 1
}
function getTableRowShownDisplayProperty() {
    if (ua.ie()) {
        return 'inline'
    } else {
        return 'table-row'
    }
}
function showTableRow() {
    for (var i = 0; i < arguments.length; i++) {
        var element = ge(arguments[i]);
        if (element && element.style) element.style.display = getTableRowShownDisplayProperty()
    }
    return false
}
function hide() {
    for (var i = 0; i < arguments.length; i++) {
        var element = ge(arguments[i]);
        if (element && element.style) element.style.display = 'none'
    }
    return false
}
function shown(el) {
    el = ge(el);
    return (el.style.display != 'none')
}
function array_indexOf(arr, val, index) {
    if (!index) {
        index = 0
    }
    for (var i = index; i < arr.length; i++) {
        if (arr[i] == val) {
            return i
        }
    }
    return - 1
}
var ua = {
    populate: function() {
        var agent = /(?:MSIE.(\d+\.\d+))|(?:Firefox.(\d+\.\d+))|(?:Opera.(\d+\.\d+))|(?:AppleWebKit.(\d+.\d+))/.exec(navigator.userAgent);
        if (!agent) {
            this._ie = this._firefox = this._opera = this._safari = 0
        }
        this._ie = parseFloat(agent[1] ? agent[1] : 0);
        this._firefox = parseFloat(agent[2] ? agent[2] : 0);
        this._opera = parseFloat(agent[3] ? agent[3] : 0);
        this._safari = parseFloat(agent[4] ? agent[4] : 0);
        this.populated = true
    },
    populated: false,
    ie: function() {
        if (!this.populated) this.populate();
        return this._ie
    },
    firefox: function() {
        if (!this.populated) this.populate();
        return this._firefox
    },
    opera: function() {
        if (!this.populated) this.populate();
        return this._opera
    },
    safari: function() {
        if (!this.populated) this.populate();
        return this._safari
    }
}
Function.prototype.extend = function(superclass) {
    var superprototype = __metaprototype(superclass, 0);
    var subprototype = __metaprototype(this, superprototype.prototype.__level + 1);
    subprototype.parent = superprototype
}
function __metaprototype(obj, level) {
    if (obj.__metaprototype) {
        return obj.__metaprototype
    }
    var metaprototype = new Function();
    metaprototype.construct = __metaprototype_construct;
    metaprototype.prototype.construct = __metaprototype_wrap(obj, level);
    metaprototype.prototype.__level = level;
    metaprototype.base = obj;
    obj.prototype.parent = metaprototype;
    obj.__metaprototype = metaprototype;
    return metaprototype
}
function __metaprototype_construct(instance) {
    __metaprototype_init(instance.parent);
    var parents = [];
    var obj = instance;
    while (obj.parent) {
        parents.push(new_obj = new obj.parent());
        new_obj.__instance = instance;
        obj = obj.parent
    }
    instance.parent = parents[1];
    parents.reverse();
    parents.pop();
    instance.__parents = parents;
    instance.__instance = instance;
    var args = [];
    for (var i = 1; i < arguments.length; i++) {
        args.push(arguments[i])
    }
    return instance.parent.construct.apply(instance.parent, args)
}
function __metaprototype_init(metaprototype) {
    if (metaprototype.initialized) return;
    var base = metaprototype.base.prototype;
    if (metaprototype.parent) {
        __metaprototype_init(metaprototype.parent);
        var parent_prototype = metaprototype.parent.prototype;
        for (i in parent_prototype) {
            if (i != '__level' && i != 'construct' && base[i] === undefined) {
                base[i] = metaprototype.prototype[i] = parent_prototype[i]
            }
        }
    }
    metaprototype.initialized = true;
    var level = metaprototype.prototype.__level;
    for (i in base) {
        if (i != 'parent') {
            base[i] = metaprototype.prototype[i] = __metaprototype_wrap(base[i], level)
        }
    }
}
function __metaprototype_wrap(method, level) {
    if (typeof method != 'function' || method.__prototyped) {
        return method
    }
    var func = function() {
        var instance = this.__instance;
        if (instance) {
            var old_parent = instance.parent;
            instance.parent = level ? instance.__parents[level - 1] : null;
            var ret = method.apply(instance, arguments);
            instance.parent = old_parent;
            return ret
        } else {
            return method.apply(this, arguments)
        }
    }
    func.__prototyped = true;
    return func
}
Function.prototype.bind = function(context) {
    var method = this;
    return function() {
        return method.apply(context, arguments)
    }
}
function autoindex(obj, source) {
    if (!autoindex.hacks) {
        autoindex.should_check_double_fire = autoindex.should_check_missing_events = navigator.userAgent.indexOf('AppleWebKit/4') != -1;
        autoindex.should_use_iframe = navigator.userAgent.indexOf('MSIE 6.0') != -1;
        autoindex.hacks = true
    }
    if (autoindex.instances) {
        autoindex.instances['i' + autoindex.instances.i] = this;
        autoindex.instances.i = (this.instance = autoindex.instances.i) + 1
    } else {
        autoindex.instances = {
            i0: this,
            i: 1
        };
        this.instance = 0
    }
    this.obj = obj;
    this.obj.indexhead = this;
    this.clear_placeholder();
    if (source) {
        this.set_source(source)
    }
    this.obj.onfocus = this._onfocus.bind(this);
    this.obj.onblur = this._onblur.bind(this);
    this.obj.onkeyup = function(event) {
        return this._onkeyup(event ? event: window.event)
    }.bind(this);
    this.obj.onkeydown = function(event) {
        return this._onkeydown(event ? event: window.event)
    }.bind(this);
    this.obj.onkeypress = function(event) {
        return this._onkeypress(event ? event: window.event)
    }.bind(this);
    this.anchor = this.setup_anchor();
    this.list = document.createElement('div');
    this.list.className = 'indexhead_list';
    this.list.style.width = (this.anchor.offsetWidth - 2) + 'px';
    this.list.style.display = 'none';
    this.anchor_block = this.anchor.tagName.toLowerCase() == 'div';
    document.body.appendChild(this.list);
    if (autoindex.should_use_iframe && !autoindex.iframe) {
        autoindex.iframe = document.createElement('iframe');
        autoindex.iframe.src = "/scripts/blank.htm";
        autoindex.iframe.className = 'indexhead_iframe';
        autoindex.iframe.style.display = 'none';
        autoindex.iframe.frameBorder = 0;
        document.body.appendChild(autoindex.iframe)
    }
    this.focused = true;
    if (this.source) {
        this.show();
        this.selectedindex = -1;
        this._onkeyup();
        this.set_class('');
        this.capture_submit()
    } else {
        this.hide()
    }
}
autoindex.prototype.max_results = 10;
autoindex.prototype.allow_placeholders = true;
autoindex.prototype.auto_select = true;
autoindex.prototype.set_source = function(source) {
    this.source = source;
    this.source.set_owner(this);
    this.status = 0;
    this.cache = {};
    this.last_search = 0;
    this.suggestions = []
}
autoindex.prototype.setup_anchor = function() {
    return this.obj
}
autoindex.prototype.destroy = function() {
    if (!this.anchor_block && this.anchor.nextSibling.tagName.toLowerCase() == 'br') {
        this.anchor.parentNode.removeChild(this.anchor.nextSibling)
    }
    if (this.list) {
        this.list.parentNode.removeChild(this.list)
    }
    this.obj.onfocus = this.obj.onblur = this.obj.onkeyup = this.obj.onkeydown = this.obj.onkeypress = null;
    this.obj.parentNode.removeChild(this.obj);
    this.anchor = this.obj = this.obj.indexhead = this.list = null;
    delete autoindex.instances['i' + this.instance]
}
autoindex.prototype._onkeyup = function(e) {
    this.last_key = e ? e.keyCode: -1;
    if (this.key_down == this.last_key) {
        this.key_down = 0
    }
    switch (this.last_key) {
    case 27:
        this.selectedindex = -1;
        this._onselect(false);
        this.hide();
        break;
    case undefined:
    case 0:
    case 13:
    case 37:
    case 38:
    case 39:
    case 40:
        break;
    default:
        this.dirty_results();
        if (autoindex.should_check_missing_events) {
            setTimeout(function() {
                this.dirty_results()
            }.bind(this), 50)
        }
        break
    }
}
autoindex.prototype._onkeydown = function(e) {
    this.key_down = this.last_key = e ? e.keyCode: -1;
    switch (this.last_key) {
    case 9:
        this.select_suggestion(this.selectedindex);
        break;
    case 13:
        if (this.select_suggestion(this.selectedindex)) {
            this.hide()
        }
        if (typeof(this.submit_keydown_return) != 'undefined') {
            this.submit_keydown_return = this._onsubmit(this.get_current_selection())
        }
        return this.submit_keydown_return;
    case 38:
        if (this.check_double_fire()) return;
        this.set_suggestion(this.selectedindex - 1);
        return false;
    case 40:
        if (this.check_double_fire()) return;
        this.set_suggestion(this.selectedindex + 1);
        return false
    }
}
autoindex.prototype._onkeypress = function(e) {
    this.last_key = e ? e.keyCode: -1;
    switch (this.last_key) {
    case 38:
    case 40:
        return false;
    case 13:
        var ret = null;
        if (typeof(this.submit_keydown_return) == 'undefined') {
            ret = this.submit_keydown_return = this._onsubmit(this.get_current_selection())
        } else {
            ret = this.submit_keydown_return;
            delete this.submit_keydown_return
        }
        return ret
    }
    return true
}
autoindex.prototype._onfound = function(obj) {
    return this.onfound ? this.onfound.call(this, obj) : true
}
autoindex.prototype._onsubmit = function(obj) {
    if (this.onsubmit) {
        var ret = this.onsubmit.call(this, obj);
        if (ret && this.obj.form) {
            if (!this.obj.form.onsubmit || this.obj.form.onsubmit()) {
                this.obj.form.submit()
            }
            return false
        }
        return ret
    } else {
        this.advance_focus();
        return false
    }
}
autoindex.prototype._onselect = function() {
    var obj = arguments[0];
    if (arguments.length == 1) {
        if (this.onselect) {
            this.onselect.call(this, obj)
        }
    } else if (arguments.length == 2) {
        if (this.onselect) {
            this.onselect.call(this, obj, arguments[1])
        }
    }
}
autoindex.prototype._onfocus = function() {
    this.focused = true;
    this.clear_placeholder();
    this.results_text = '';
    this.set_class('');
    this.dirty_results();
    this.show();
    this.capture_submit()
}
autoindex.prototype._onblur = function() {
    if (!this.suggestions) {
        this._onselect(false)
    }
    this.focused = false;
    this.hide();
    this.update_class();
    if (!this.get_value()) {
        var noinput = this.allow_placeholders ? '': this.source.gen_noinput();
        this.set_value(noinput ? noinput: '');
        this.set_class('indexhead_placeholder')
    }
}
autoindex.prototype.capture_submit = function() {
    if (!autoindex.should_check_missing_events) return;
    if ((!this.captured_form || this.captured_substitute != this.captured_form.onsubmit) && this.obj.form) {
        this.captured_form = this.obj.form;
        this.captured_event = this.obj.form.onsubmit;
        this.captured_substitute = this.obj.form.onsubmit = function() {
            return ((this.key_down && this.key_down != 13 && this.key_down != 9) ? this.submit_keydown_return: (this.captured_event ? this.captured_event.apply(arguments, this.captured_form) : true)) ? true: false
        }.bind(this)
    }
}
autoindex.prototype.check_double_fire = function() {
    if (!autoindex.should_check_double_fire) {
        return false
    } else {
        this.double_fire++;
        return this.double_fire % 2 == 1
    }
}
autoindex.prototype.double_fire = 0;
autoindex.prototype.set_suggestion = function(index) {
    if (!this.suggestions || this.suggestions.length <= index) {
        return
    }
    this.selectedindex = (index <= -1) ? -1: index;
    var nodes = this.list.childNodes;
    for (var i = 0; i < nodes.length; i++) {
        if (this.selectedindex == i) {
            nodes[i].className = nodes[i].className.replace(/\bindexhead_not_selected\b/, 'indexhead_selected')
        } else {
            nodes[i].className = nodes[i].className.replace(/\bindexhead_selected\b/, 'indexhead_not_selected')
        }
    }
    this._onfound(this.get_current_selection())
}
autoindex.prototype.get_current_selection = function() {
    return this.selectedindex == -1 ? false: this.suggestions[this.selectedindex]
}
autoindex.prototype.update_class = function() {
    if (this.suggestions && this.selectedindex != -1 && this.get_current_selection().t.toLowerCase() == this.get_value().toLowerCase()) {
        this.set_class('indexhead_found')
    } else {
        this.set_class('')
    }
}
autoindex.prototype.select_suggestion = function(index) {
    if (!this.suggestions || index == undefined || index === false || this.suggestions.length <= index || index < 0) {
        this._onfound(false);
        this._onselect(false);
        this.selectedindex = -1
    } else {
        this.selectedindex = index;
        this.set_value(this.suggestions[index].t);
        if (document.getElementById(this.obj.id+'hid')!=null) {
            document.getElementById(this.obj.id+'hid').value=this.suggestions[index].i;
        }
        //alert(this.suggestions[index].i);
        this.set_class('indexhead_found');
        this._onfound(this.suggestions[this.selectedindex]);
        if (this.onselect_args) {
            this._onselect(this.suggestions[this.selectedindex], this.onselect_args)
        } else {
            this._onselect(this.suggestions[this.selectedindex])
        }
    }
    return true
}
autoindex.prototype.set_value = function(value) {
    this.obj.value = value
}
autoindex.prototype.get_value = function() {
    return this.obj.value
}
autoindex.prototype.found_suggestions = function(suggestions, text, fake_data) {
    if (!fake_data) {
        this.status = 0;
        this.add_cache(text, suggestions)
    }
    if (this.get_value() == this.results_text) {
        return
    }
    if (!fake_data) {
        this.results_text = text.toLowerCase()
    }
    var current_selection = this.auto_select ? null: this.suggestions[this.selectedindex];
    this.suggestions = suggestions;
    if (suggestions.length > 0) {
        var html = [];
        for (var i = 0; i < suggestions.length; i++) {
            html.push('<div class="');
            if ((i == 0 && this.auto_select) || current_selection == suggestions[i]) {
                if (this.selectedindex != i) {
                    this._onfound(suggestions[i])
                }
                this.selectedindex = i;
                html.push('indexhead_suggestion indexhead_selected')
            } else {
                html.push('indexhead_suggestion indexhead_not_selected')
            }
            html.push('" onmouseout="autoindex.instances.i', this.instance, '.set_suggestion(-1)" ', 'onmouseover="autoindex.instances.i', this.instance, '.set_suggestion(', i, ')" ', 'onmousedown="autoindex.instances.i', this.instance, '.select_suggestion(', i, ')">', this.source.gen_html(suggestions[i], this.get_value()), '</div>')
        }
        this.list.innerHTML = html.join('');
        this.show();
        this.reset_iframe()
    } else {
        this.selectedindex = -1;
        this.set_message(this.status == 0 ? this.source.gen_nomatch() : this.source.gen_loading());
        this._onfound(false)
    }
    if (!fake_data && this.results_text != this.get_value().toLowerCase()) {
        this.dirty_results()
    }
}
autoindex.prototype.search_cache = function(text) {
    return this.cache[text.toLowerCase()]
}
autoindex.prototype.add_cache = function(text, results) {
    if (this.source.cache_results) {
        this.cache[text.toLowerCase()] = results
    }
}
autoindex.prototype.source_loaded = function() {
    if (!this.get_value().length) {
        this.set_message(this.source.gen_placeholder())
    }
    if (this.status == 2) {
        this.status = 0
    }
    this.dirty_results()
}
autoindex.prototype.set_class = function(name) {
    this.obj.className = (this.obj.className.replace(/indexhead_[^\s]+/g, '') + ' ' + name).replace(/ {2,}/g, ' ')
}
autoindex.prototype.dirty_results = function() {
    if (this.get_value().replace(' ', '') == '') {
        this.set_message(this.source.gen_placeholder());
        this.suggestions = [];
        this.selectedindex = -1;
        this.results_text = this.get_value();
        return
    } else if (this.results_text == this.get_value().toLowerCase()) {
        return
    }
    var time = (new Date).getTime();
    var cache;
    var updated = false;
    if (this.last_search <= (time - this.source.search_limit) && this.source.status == 0 && this.status == 0) {
        updated = this.perform_search()
    } else {
        if (this.status == 0 && this.source.status == 1) {
            this.set_message(this.source.gen_loading());
            this.status = 2
        } else if (this.status == 0 && this.source.status == 0) {
            if (!this.search_timeout) {
                this.search_timeout = setTimeout(function() {
                    this.search_timeout = false;
                    if (this.status == 0 && this.source.status == 0) {
                        updated = this.perform_search()
                    }
                }.bind(this), this.source.search_limit - (time - this.last_search))
            }
        }
    }
    if (this.suggestions && !updated) {
        var match = -1;
        var ttext = indexhead_source.indexchildize(this.get_value()).sort(indexhead_source._sort);
        this.found_suggestions(this.suggestions, this.get_value(), true);
        for (var i = 0; i < this.suggestions.length; i++) {
            if (indexhead_source.check_match(ttext, this.suggestions[i].t)) {
                match = i;
                break
            }
        }
        if (match != 0) {
            this.set_suggestion(match)
        }
    }
}
autoindex.prototype.perform_search = function() {
    if (this.get_value() == this.results_text) {
        return true
    }
    if (!this.get_value().length) {
        this.set_message(this.source.gen_placeholder());
        this.suggestions = [];
        this.results_text = '';
        this.selectedindex = -1
    } else if ((cache = this.search_cache(this.get_value())) !== undefined) {
        this.found_suggestions(cache, this.get_value(), false);
        this.show()
    } else if (!this.source.search_value(this.get_value())) {
        this.status = 1;
        this.last_search = (new Date).getTime();
        return false
    }
    return true
}
autoindex.prototype.set_message = function(text) {
    if (text) {
        this.list.innerHTML = '<div class="indexhead_message">' + text + '</div>';
        this.reset_iframe()
    } else {
        this.hide()
    }
}
autoindex.prototype.reset_iframe = function() {
    if (!autoindex.should_use_iframe) {
        return
    }
    autoindex.iframe.style.top = this.list.style.top;
    autoindex.iframe.style.left = this.list.style.left;
    autoindex.iframe.style.width = this.list.offsetWidth + 'px';
    autoindex.iframe.style.height = this.list.offsetHeight + 'px';
    autoindex.iframe.style.display = ''
}
autoindex.prototype.advance_focus = function() {
    var inputs = this.obj.form ? this.obj.form.getElementsByTagName('input') : document.getElementsByTagName('input');
    var next_inputs = false;
    for (var i = 0; i < inputs.length; i++) {
        if (next_inputs) {
            if (inputs[i].type != 'hidden' && inputs[i].tabIndex != -1 && inputs[i].offsetParent) {
                next_inputs.push(inputs[i])
            }
        } else if (inputs[i] == this.obj) {
            next_inputs = []
        }
    }
    setTimeout(function() {
        for (var i = 0; i < this.length; i++) {
            try {
                if (this[i].offsetParent) {
                    this[i].focus();
                    setTimeout(function() {
                        try {
                            this.focus()
                        } catch(e) {}
                    }.bind(this[i]), 0);
                    return
                }
            } catch(e) {}
        }
    }.bind(next_inputs ? next_inputs: []), 0)
}
autoindex.prototype.clear_placeholder = function() {
    if (this.obj.className.indexOf('indexhead_placeholder') != -1) {
        this.set_value('');
        this.set_class('')
    }
}
autoindex.prototype.clear = function() {
    this.set_value('', true);
    this.set_class('');
    this.dirty_results()
}
autoindex.prototype.hide = function() {
    this.list.style.display = 'none';
    this.list.innerHTML = '';
    if (autoindex.should_use_iframe) {
        autoindex.iframe.style.display = 'none'
    }
}
autoindex.prototype.show = function() {
    if (this.focused) {
        this.list.style.top = elementY(this.anchor) + this.anchor.offsetHeight + 'px';
        this.list.style.left = elementX(this.anchor) + 'px';
        this.list.style.display = '';
        if (autoindex.should_use_iframe) {
            autoindex.iframe.style.display = '';
            this.reset_iframe()
        }
    }
}
autoindex.prototype.focus = function() {
    this.obj.focus()
}
autoindex.kill_indexhead = function(obj) {
    if (obj.indexhead) {
        obj.parentNode.removeChild(obj.nextSibling);
        if (obj.indexhead.source) {
            obj.indexhead.source = obj.indexhead.source.owner = null
        }
        obj.onfocus = obj.onblur = obj.onkeypress = obj.onkeyup = obj.onkeydown = obj.indexhead = null
    }
}
function indexpar(obj, indexhead_source, nofocus) {
    if (navigator.userAgent.indexOf('AppleWebKit/4') == -1) {
        indexpar.valid_arrow_event = function() {
            return true
        }
    } else {
        indexpar.valid_arrow_count = 0;
        indexpar.valid_arrow_event = function() {
            return indexpar.valid_arrow_count++%2 == 0
        }
    }
    try {
        if (ua.ie()) {
            document.execCommand('BackgroundImageCache', false, true)
        }
    } catch(e) {}
    this.obj = obj;
    this.obj.indexpar = this;
    this.indexhead_source = indexhead_source;
    while (!/\bindexpar\b/.test(this.obj.className)) {
        this.obj = this.obj.parentNode
    }
    this.tab_stop = this.obj.getElementsByTagName('input')[0];
    this.inputs = [];
    this.obj.onmousedown = function(event) {
        return this._onmousedown(event ? event: window.event)
    }.bind(this);
    this.tab_stop.onfocus = function(event) {
        return this._onfocus(event ? event: window.event)
    }.bind(this);
    this.tab_stop.onblur = function(event) {
        return this.tab_stop_onblur(event ? event: window.event)
    }.bind(this);
    this.tab_stop.onkeydown = function(event) {
        return this.tab_stop_onkeydown(event ? event: window.event)
    }.bind(this);
    if (!nofocus && elementY(this.obj) > 0) {
        this._onfocus()
    }
}
indexpar.prototype.max_selections = 20;
indexpar.prototype.islock = false;
indexpar.is_empty = function(obj) {
    if (has_css_class_name(obj, 'indexpar_locked')) {
        return obj.getElementsByTagName('input').length == 0
    } else {
        return (!obj.indexpar || obj.indexpar.count_names() == 0)
    }
}
indexpar.prototype._onmousedown = function(event) {
    setTimeout(function() {
        if (!this.inputs.length) {
            if (this.max_selections > this.count_names()) {
                new indexpar_input(this)
            } else {
                var indexchilds = this.obj.getElementsByTagName('a');
                for (var i = indexchilds.length - 1; i >= 0; i--) {
                    if (typeof indexchilds[i].indexchild != 'undefined') {
                        indexchilds[i].indexchild.select();
                        break
                    }
                }
            }
        } else {
            this.inputs[0].focus()
        }
    }.bind(this), 0);
    event ? event.cancelBubble = true: false;
    return false
}
indexpar.prototype._onfocus = function(event) {
    if (this.tab_stop_ignore_focus) {
        this.tab_stop_ignore_focus = false;
        return
    }
    this._onmousedown()
}
indexpar.prototype.tab_stop_onblur = function(event) {
    this.selected_indexchild ? this.selected_indexchild.deselect() : false
}
indexpar.prototype.tab_stop_onkeydown = function(event) {
    if (!event.keyCode || !this.selected_indexchild) {
        return
    }
    switch (event.keyCode) {
    case 8:
    case 46:
        var tok = this.selected_indexchild;
        var prev = tok.element.previousSibling;
        if (prev && prev.input) {
            prev.input.element.focus()
        } else {
            new indexpar_input(this, tok.element)
        }
        tok.remove();
        return false;
    case 37:
        if (!indexpar.valid_arrow_event()) {
            break
        }
        var tok = this.selected_indexchild;
        var prev = tok.element.previousSibling;
        if (prev && prev.input) {
            prev.input.element.focus()
        } else if (this.max_selections > this.count_names()) {
            new indexpar_input(this, tok.element)
        } else {
            return false
        }
        tok.deselect();
        return false;
    case 39:
        if (!indexpar.valid_arrow_event()) {
            break
        }
        var tok = this.selected_indexchild;
        var next = tok.element.nextSibling;
        if (next && next.input) {
            next.input.focus()
        } else if (this.max_selections > this.count_names()) {
            new indexpar_input(this, tok.element.nextSibling)
        } else {
            return false
        }
        tok.deselect();
        return false
    }
}
indexpar.prototype.count_names = function() {
    var inputs = this.obj.getElementsByTagName('input');
    var count = 0;
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'hidden') {
            count++
        }
    }
    return count
}
indexpar.prototype.disable = function() {
    this.tab_stop.parentNode.removeChild(this.tab_stop);
    this.obj.className += ' indexpar_locked'
}
function indexpar_input(indexpar, caret) {
    if (indexpar.islock) {
        return
    }
    if (!indexpar_input.hacks) {
        indexpar_input.should_use_borderless_hack = navigator.userAgent.indexOf('AppleWebKit') != -1;
        indexpar_input.should_use_shadow_hack = navigator.userAgent.indexOf('MSIE') != -1 || navigator.userAgent.indexOf('Opera') != -1 || navigator.userAgent.indexOf('Firefox/1.5') || navigator.userAgent.indexOf('Firefox/1.0');
        indexpar_input.hacks = true
    }
    this.indexpar = indexpar;
    this.obj = document.createElement('input');
    this.obj.input = this;
    this.obj.tabIndex = -1;
    this.obj.size = 1;
    this.obj.onmousedown = function(event) { (event ? event: window.event).cancelBubble = true;
        return false
    }.bind(this);
    this.shadow = document.createElement('span');
    this.shadow.className = 'indexpar_input_shadow';
    this.element = document.createElement('div');
    indexpar_input.should_use_borderless_hack = 1;
    this.element.className = 'indexpar_input' + (indexpar_input.should_use_borderless_hack ? ' indexpar_input_borderless': '');
    this.element.appendChild(document.createElement('div'));
    this.element.firstChild.appendChild(this.obj); (indexpar_input.should_use_shadow_hack ? document.body: this.element.firstChild).appendChild(this.shadow);
    caret ? indexpar.obj.insertBefore(this.element, caret) : indexpar.obj.appendChild(this.element);
    this.indexpar.tab_stop.disabled = true;
    this.update_shadow();
    this.update_shadow = this.update_shadow.bind(this);
    this.indexpar.inputs.push(this);
    this.parent.construct(this, this.obj, this.indexpar.indexhead_source);
    this.focus();
    this.obj.select()
}
indexpar_input.extend(autoindex);
indexpar_input.prototype.gen_nomatch = indexpar_input.prototype.gen_loading = indexpar_input.prototype.gen_placeholder = indexpar_input.prototype.gen_noinput = '';
indexpar_input.prototype.setup_anchor = function() {
    return this.indexpar.obj
}
indexpar_input.prototype.update_shadow = function() {
    try {
        var val = this.obj.value
    } catch(e) {
        return
    };
    if (this.shadow_input != val) {
        this.shadow.innerHTML = htmlspecialchars((this.shadow_input = val) + '^_^');
        if (indexpar_input.should_use_shadow_hack) {
            this.obj.style.width = this.shadow.offsetWidth + 'px'
        }
    }
}
indexpar_input.prototype._onblur = function() {
    this.select_suggestion(this.selectedindex);
    this.parent._onblur();
    setTimeout(function() {
        this.disabled = false
    }.bind(this.indexpar.tab_stop), 0);
    this.destroy()
}
indexpar_input.prototype._onfocus = function() {
    this.indexpar.tab_stop.disabled = true;
    this.parent._onfocus();
    return true
}
indexpar_input.prototype._onkeydown = function(event) {
    switch (event.keyCode) {
    case 13:
        if (this.selectedindex < 0) {
            this.selectedindex = 0
        }
        break;
    case 37:
        if (!indexpar.valid_arrow_event()) {
            break
        }
    case 8:
        if (this.get_selection_start() != 0 || this.obj.value != '') {
            break
        }
        var prev = this.element.previousSibling;
        if (prev && prev.indexchild) {
            setTimeout(prev.indexchild.select.bind(prev.indexchild), 0)
        }
        break;
    case 39:
        if (!indexpar.valid_arrow_event()) {
            break
        }
    case 46:
        if (this.get_selection_start() != this.obj.value.length) {
            break
        }
        var next = this.element.nextSibling;
        if (next && next.indexchild) {
            setTimeout(next.indexchild.select.bind(next.indexchild), 0)
        }
        break;
    case 188:
        this.parent._onkeydown({
            keyCode:
            9
        });
        return false;
    case 9:
        if (this.obj.value) {
            this._onkeydown({
                keyCode:
                13
            });
            return false
        } else if (!event.shiftKey) {
            this.advance_focus();
            this.parent._onkeydown(event);
            return false
        }
        break
    }
    return this.parent._onkeydown(event)
}
indexpar_input.prototype._onkeypress = function(event) {
    switch (event.keyCode) {
    case 9:
        return false
    }
    setTimeout(this.update_shadow, 0);
    return this.parent._onkeypress(event)
}
indexpar_input.prototype.select_suggestion = function(index) {
    if (this.suggestions && index >= 0 && this.suggestions.length > index) {
        var inputs = this.indexpar.obj.getElementsByTagName('input');
        var id = this.suggestions[index].i;
        for (i = 0; i < inputs.length; i++) {
            if (inputs[i].name == 'autos[]' && inputs[i].value == id) {
                return false
            }
        }
    }
    return this.parent.select_suggestion(index)
}
indexpar_input.prototype.get_selection_start = function() {
    if (this.obj.selectionStart != undefined) {
        return this.obj.selectionStart
    } else {
        return Math.abs(document.selection.createRange().moveStart('character', -1024))
    }
}
indexpar_input.prototype.onselect = function(obj) {
    if (obj) {
        var inputs = this.indexpar.obj.getElementsByTagName('input');
        for (i = 0; i < inputs.length; i++) {
            if (inputs[i].name == 'autos[]' && inputs[i].value == obj.i) {
                return false
            }
        }
        new indexchild(obj, this.indexpar, this.element);
        if (this.indexpar.max_selections > this.indexpar.count_names()) {
            this.clear()
        } else {
            this.destroy();
            this.hide = function() {};
            return false
        }
    }
    if (typeof this.indexpar.onselect != 'undefined') {
        this.indexpar.onselect(obj)
    }
    return false
}
indexpar_input.prototype._onsubmit = function() {
    return false
}
indexpar_input.prototype.capture_submit = function() {
    return false
}
indexpar_input.prototype.clear = function() {
    this.parent.clear();
    this.update_shadow()
}
indexpar_input.prototype.destroy = function() {
    if (indexpar_input.should_use_shadow_hack) {
        this.shadow.parentNode.removeChild(this.shadow)
    }
    this.element.parentNode.removeChild(this.element);
    this.element = null;
    var index = array_indexOf(this.indexpar.inputs, this);
    if (index != -1) {
        this.indexpar.inputs.splice(index, 1)
    }
    this.indexpar = this.element = this.shadow = null;
    this.parent.destroy();
    return null
}
function indexchild(obj, indexpar, caret) {
    this.indexpar = indexpar;
    this.element = document.createElement('a');
    this.element.className = 'indexchild';
    this.element.href = '#';
    this.element.tabIndex = -1;
    this.element.onclick = function(event) {
        return this._onclick(event ? event: window.event)
    }.bind(this);
    this.element.onmousedown = function(event) { (event ? event: window.event).cancelBubble = true;
        return false
    };
    var inputs = '';
    if (obj.i) {
        inputs = ['<input type="hidden" name="', this.indexpar.obj.id, '[]" value="', obj.i, '" />'].join('')
    } else if (obj.is) {
        for (var i in obj.is) {
            inputs += ['<input type="hidden" name="', this.indexpar.obj.id, '[]" value="', obj.is[i], '" />'].join('')
        }
    }
    this.element.innerHTML = ['<span><span><span><span>', inputs, htmlspecialchars(obj.t), '<span onclick="this.parentNode.parentNode.parentNode.parentNode.parentNode.indexchild.remove(true); event.cancelBubble=true; return false;" ', 'onmouseover="this.className=\'x_hover\'" onmouseout="this.className=\'x\'" class="x">&nbsp;</span>', '</span></span></span></span>'].join('');
    this.element.indexchild = this;
    caret ? this.indexpar.obj.insertBefore(this.element, caret) : this.indexpar.obj.appendChild(this.element)
}
indexchild.prototype._onclick = function(event) {
    this.select();
    event.cancelBubble = true;
    return false
}
indexchild.prototype.select = function(again) {
    if (this.indexpar.selected_indexchild && !again) {
        this.indexpar.selected_indexchild.deselect()
    }
    this.element.className = trim(this.element.className.replace('indexchild_selected', '')) + ' indexchild_selected';
    this.indexpar.tab_stop_ignore_focus = true;
    if (this.indexpar.tab_stop.disabled) {
        this.indexpar.tab_stop.disabled = false
    }
    this.indexpar.tab_stop.focus();
    this.indexpar.selected_indexchild = this;
    if (again !== true) {
        setTimeout(function() {
            this.select(true)
        }.bind(this), 0)
    } else {
        setTimeout(function() {
            this.tab_stop_ignore_focus = false
        }.bind(this.indexpar), 0)
    }
}
indexchild.prototype.remove = function(focus) {
    this.element.parentNode.removeChild(this.element);
    this.element.indexchild = null;
    this.indexpar.selected_indexchild = null;
    if (focus) {
        this.indexpar._onmousedown()
    }
}
indexchild.prototype.deselect = function() {
    this.element.className = trim(this.element.className.replace('indexchild_selected', ''));
    this.indexpar.selected_indexchild = null
}
function indexhead_source() {}
indexhead_source.prototype.cache_results = false;
indexhead_source.prototype.search_limit = 10;
indexhead_source.check_match = function(search, value) {
    value = indexhead_source.indexchildize(value);
    for (var i in search) {
        if (search[i].length) {
            var found = false;
            for (var j in value) {
                if (value[j].length >= search[i].length && value[j].substring(0, search[i].length).toLowerCase() == search[i].toLowerCase()) {
                    found = true;
                    value[j] = '';
                    break
                }
            }
            if (!found) {
                return false
            }
        }
    }
    return true
}
indexhead_source.indexchildize = function(text) {
    return text.replace(indexhead_source.normalizer_regex, ' ').toLowerCase().split(' ')
}
indexhead_source.normalizer_regex = /(?: +['".\-]+ *)|(?: *['".\-]+ +)/g;
indexhead_source.prototype.set_owner = function(obj) {
    this.owner = obj
}
indexhead_source.prototype.highlight_found = function(result, search) {
    var html = [];
    result = result.split(' ');
    search = indexhead_source.indexchildize(search);
    search.sort(indexhead_source._sort);
    for (var i in result) {
        var found = false;
        for (var j in search) {
            if (search[j] && result[i].toLowerCase().lastIndexOf(search[j], 0) != -1) {
                html.push('<em>', htmlspecialchars(result[i].substring(0, search[j].length)), '</em>', htmlspecialchars(result[i].substring(search[j].length, result[i].length)), ' ');
                found = true;
                break
            }
        }
        if (!found) {
            html.push(htmlspecialchars(result[i]), ' ')
        }
    }
    return html.join('')
}
indexhead_source._sort = function(a, b) {
    return b.length - a.length
}
indexhead_source.prototype.gen_nomatch = function() {
    return this.text_nomatch != null ? this.text_nomatch: 'No matches found'
}
indexhead_source.prototype.gen_loading = function() {
    return this.text_loading != null ? this.text_loading: 'Loading...'
}
indexhead_source.prototype.gen_placeholder = function() {
    return this.text_placeholder != null ? this.text_placeholder: 'Start typing...'
}
indexhead_source.prototype.gen_noinput = function() {
    return this.text_noinput != null ? this.text_noinput: 'Start typing...'
}
function static_source() {
    this.values = null;
    this.index = null;
    this.parent.construct(this)
}
static_source.extend(indexhead_source);
static_source.prototype.build_index = function() {
    var index = [];
    var values = this.values;
    var gen_id = values.length && typeof values[0].i == 'undefined';
    for (var i in values) {
        var indexchilds = indexhead_source.indexchildize(values[i].t);
        for (var j in indexchilds) {
            index.push({
                t: indexchilds[j],
                o: values[i]
            })
        }
        if (gen_id) {
            values[i].i = i
        }
    }
    index.sort(static_source._sort_text_obj);
    this.index = index
}
static_source._sort_text_obj = function(a, b) {
    if (a.t == b.t) {
        return 0
    }
    return a.t < b.t ? -1: 1
}
static_source.prototype.search_value = function(text) {
    if (this.status != 0) {
        return
    }
    var ttext = indexhead_source.indexchildize(text).sort(indexhead_source._sort);
    var index = this.index;
    var lo = 0;
    var hi = this.index.length - 1;
    var p = Math.floor(hi / 2);
    while (lo <= hi) {
        if (index[p].t >= ttext[0]) {
            hi = p - 1
        } else {
            lo = p + 1
        }
        p = Math.floor(lo + ((hi - lo) / 2))
    }
    var results = [];
    var stale_keys = {};
    var check_ignore = typeof _ignoreList != 'undefined';
    for (var i = lo; i < index.length && index[i].t.lastIndexOf(ttext[0], 0) != -1; i++) {
        if (typeof stale_keys[index[i].o.i] != 'undefined') {
            continue
        } else {
            stale_keys[index[i].o.i] = true
        }
        if ((!check_ignore || !_ignoreList[index[i].o.i]) && (ttext.length == 1 || indexhead_source.check_match(ttext, index[i].o.t))) {
            results.push(index[i].o)
        }
    }
    results.sort(static_source._sort_text_obj);
    results = results.slice(0, this.search_limit);
    this.owner.found_suggestions(results, text, false);
    return true
}
function friend_source(get_param) {
    this.parent.construct(this);
    if (friend_source.friends) {
        this.status = 0;
        this.values = friend_source.friends;
        this.index = friend_source.friends_index
    } else {
        this.status = 1;
        $.get('/ajax/GetMyFriends.aspx?tem=' + Math.random(), 
        function(text) {
            eval(text);
            friend_source.friends = this.values = friends;
            this.build_index();
            friend_source.friends_index = this.index;
            this.status = 0;
            if (this.owner && this.owner.source_loaded) {
                this.owner.source_loaded()
            }
        }.bind(this))
    }
}
friend_source.extend(static_source);
friend_source.prototype.text_noinput = friend_source.prototype.text_placeholder = 'Please input your friend\'s name';
friend_source.prototype.gen_html = function(friend, highlight) {
    return ['<div>', this.highlight_found(friend.t, highlight), '</div><div><small>', friend.n, '</small></div>'].join('')
}
function members_source(get_param) {
    this.parent.construct(this);
    if (members_source.members) {
        this.status = 0;
        this.values = members_source.members;
        this.index = members_source.members_index
    } else {
        this.status = 1;
        $.get('/ajax/GetMembers.aspx?tem=' + Math.random(), 
        function(text) {
            eval(text);
            members_source.members = this.values = members;
            this.build_index();
            members_source.members_index = this.index;
            this.status = 0;
            if (this.owner && this.owner.source_loaded) {
                this.owner.source_loaded()
            }
        }.bind(this))
    }
}
members_source.extend(static_source);
members_source.prototype.text_noinput = members_source.prototype.text_placeholder = 'Please input member\'s name';
members_source.prototype.gen_html = function(friend, highlight) {
    return ['<div>', this.highlight_found(friend.t, highlight), '</div><div><small>', friend.n, '</small></div>'].join('')
}
function college_source(get_param) {
    this.status = 0;
    this.parent.construct(this)
}
college_source.extend(indexhead_source);
college_source.prototype.cache_results = false;
college_source.prototype.search_limit = 200;
college_source.prototype.text_placeholder = college_source.prototype.text_noinput = 'Enter a college.';
college_source.prototype.search_value = function(text) {
    this.search_text = text;
    $.get('/Ajax/GetColleges.aspx?key=' + this.search_text + "&tem=" + Math.random(), 
    function(text) {
        eval(text);
        this.owner.found_suggestions(colleges, this.search_text, false)
    }.bind(this))
}
college_source.prototype.gen_html = function(result, highlight) {
    return ['<div>', this.highlight_found(result.t, highlight), '</div><div><small>', this.highlight_found(result.s, highlight), '</small></div>'].join('')
}
function highcollege_source(get_param) {
    this.status = 0;
    this.parent.construct(this)
}
highcollege_source.extend(indexhead_source);
highcollege_source.prototype.cache_results = false;
highcollege_source.prototype.search_limit = 200;
highcollege_source.prototype.text_placeholder = highcollege_source.prototype.text_noinput = 'Enter a high school\'s name.';
highcollege_source.prototype.text_noinput = false;
highcollege_source.prototype.search_value = function(text) {
    this.search_text = text;
    $.get('/Ajax/Gethighcolleges.aspx?key=' + this.search_text + "&tem=" + Math.random(), 
    function(text) {
        eval(text);
        this.owner.found_suggestions(highcolleges, this.search_text, false)
    }.bind(this))
}
highcollege_source.prototype.gen_html = function(highcollegeresult, highlight) {
    return ['<div>', this.highlight_found(highcollegeresult.t, highlight), '</div><div><small>', highcollegeresult.city, ', ', highcollegeresult.state, '</small></div>'].join('')
}