function CountryStatePair(country_id,state_id,states,selstate) {
    this.country_id = country_id;
    this.state_id = state_id;
    this.states = states;
    this.selstate = selstate;
    this.curcountry = null;
    
    this.render = function() {
        var state = $(this.state_id);

        if (state) {
            var list = new Array();
            for (var i=0; i<this.states.length; i++)
                if (this.states[i].c == this.curcountry)
                    list[list.length] = this.states[i];
                    
            state.options.length = 0;
            state.disabled = (list.length == 0);
            
            for (var i=0; i<list.length; i++) {
                var o = new Option(list[i].name, list[i].id);
                o.selected = (o.value == this.selstate);
                state.options.add(o);
            }
        }
    }
    
    this.initialize = function() {
        var country = $(this.country_id);
        
        
        if (country) {
            country.cs_pair = this;
            var ctrl = this;
            country.onchange = function() { ctrl.curcountry = this.options[this.selectedIndex].value; ctrl.render(); }
            this.curcountry = country.options[country.selectedIndex].value;
        }
        
        
        this.render();
    }
    
    this.initialize();
}

