﻿var AccountingList = new Class({
    Implements: Options,
    options: {
        dataHref: '/data/systems.aspx'
    },

    initialize: function(select) {
        this.select = $(select);
    },
    
    populate: function() {
        var state = this.loadState();
        new Request.JSON({ 'url': this.options.dataHref, 'method': 'get',
            'onSuccess': function(result) {
                    this.select.empty();
                    new Element('option', { 'value': '' }).inject(this.select);
                    result.each(function(s) {
                        new Element('option', { 'value': s }).set('text', s).inject(this.select);
                    }.bind(this));
                    if (state) this.select.value = state;
                }.bind(this), 'onFailure': function(result) {
            }.bind(this)}).send();
    },

    loadState: function() {
        var state = new Hash.Cookie('diagramState', { duration:365, path:'/' });
        if (state) {
            return state.get('source');
        }
    },
    
    setupAutoComplete: function(q, search) {
        q = $(q);
        search = $(search);
        new Autocompleter.Ajax.Json(q, '/data/partners.aspx', { postVar: 'q' });
    }
});
