var Selector = function(){

	this.options = [];
	this.selector = null; 

	this.set = function(k,v){ this[k] = v; };

	this.get = function(k){ return this[k]; };

	this.makeOptions = function(lst){
		lst = eval("(" + lst + ")");
		var sel = this.selector;
		sel.options.length = null;	
		sel.options[0] = new Option('choose','');
		lst.map(function(x){ 
			var o = new Option(x['name'],x['id']);
			sel.options[sel.options.length] = o;
		});
	};
	var _this = this;
	this.reactsTo = function(id,evts,action){
		evts.map(function(evt){
			$(id)[evt] = function(){
				var val = $(id)[$(id).selectedIndex].value;
				call("?ajax="+action+"&id="+val,
					function(str){
						_this.makeOptions(str);
					});
			}
		});
	}
	return this;
}

addLoadEvent(function(){

	var city = new Selector();
	var province = new Selector();
	var type = new Selector();

	city.set("selector",$("city"));
	province.set("selector",$("province"));
	type.set("selector",$("type"));

	city.reactsTo('province',['onchange','onupdate'], "updateCities");
	//province.reactsTo('country',['onchange'], "updateProvinces");
});
