

function dyn_select() {
	this.selects = new Array();
    this.curr_source = '';
    this.onempty_func = '';
    this.onnonempty_func = '';
	
    this.onempty_callback = function(func) {
        this.onempty_func = func;     
    }
    
    this.onnonempty_callback = function(func) {
        this.onnonempty_func = func;
    }
    
	this.add_source = function(name) {
	    this.selects[name] = new obj_select();
        this.curr_source = name;
	}
    
    this.add_target_option = function(source_id, taget_name, target_value) {
        if(!this.selects[this.curr_source].options[source_id]) {
            this.selects[this.curr_source].add_option(source_id);    
        }
        this.selects[this.curr_source].options[source_id].create_option(taget_name, target_value);    
    }
    
	this.update_options = function(source, target) {
		var form = source.form;
		var target = form.elements[target];
		var value = source.options[source.selectedIndex].value;
		
		while(target.options.length) target.remove(0);
		
		if(!this.selects[source.name].options[value]) {
			if(this.onempty_func) {
                if (typeof(this.onempty_func)=="string") eval(this.onempty_func+"()");
		        else if (typeof(this.onempty_func)=="function") this.onempty_func();
            }
			return;
		}
		
		var data = this.selects[source.name].options[value].options;
		
		for(var x=0; x<data.length; x++) {
			try	{
				target.add(data[x]);
			}
			catch(e) {
				target.add(data[x], null);
			}
		}
		target.selectedIndex = 0;
        
         if(this.onnonempty_func) {
            if (typeof(this.onempty_func)=="string") eval(this.onnonempty_func+"()");
		    else if (typeof(this.onempty_func)=="function") this.onnonempty_func();
        } 
	}
}

function obj_select() {
	this.options = new Array();
	this.add_option = function(value) {
		this.options[value] = new obj_option();
	}
}

function obj_option() {
	this.options = new Array();
	this.create_option = function(name, value) {
	    this.options[this.options.length] = new Option(name, value);
	}
}