/**
 * City of Kingston JS Site Script / Mootools flavor sub app: Waste Lookup
 * Last edited: Oct. 11, 2009 - Web Paving / SRB
 * v1.0 
 */

document.addEvent('domready', function() {

    var WPWasteLookup = {
        CFG: {
            sAppUrl: '/residents/waste/lookup/',
            sSearchField: $('formName'),
            sServerSessionID: null
        },

           
        /**
         * Set up form input field for auto-complete functionality.
         * 
         * Requires: Harald Kirschner's Autocompleter 
         */
        initSearchField: function() {
            new Autocompleter.Request.HTML(this.CFG.sSearchField, this.CFG.sAppUrl, {
                indicatorClass: 'autocompleter-loading',
                minLength: 2,
                width: '26em',
                maxChoices: 12,
                // overflow: true,
                // overflowMargin: 24,
                postData: {
                    action: 'picklist',
                    ajax: true
                },
                injectChoice: function (choice) {
                    // choice is one <li> element
                    var text = choice.getFirst();
                    // the first element in this <li> is the <span> with the text
                    var value = text.innerHTML;
                    // inputValue saves value of the element for later selection
                    choice.inputValue = value;
                    // overrides the html with the marked query value (wrapped in a <span>)
                    text.set('html', this.markQueryValue(value));
                    // add the mouse events to the <li> element
                    this.addChoiceEvents(choice);
                }
            });
        } // End of initSearchField

    }; // End of WPWasteLookup

    // Kick-start this app
    
    WPWasteLookup.initSearchField();

});



