var Clocation = new Class({
	oOrszag: null,
	oVaros: null,
	oZona: null,
	initialize: function(oOrszag, oVaros, oZona){
		this.oOrszag=$(oOrszag);
		this.oVaros=$(oVaros);
		this.oZona=$(oZona);
		this.oOrszag.addEvent('change',this.orszagChange.bind(this));
		this.oVaros.addEvent('change',this.varosChange.bind(this));
	},
	loadVaros: function(orszagid, selected){
		var result = this.sendRequest('getVaros',{'country':orszagid});
		this.oVaros.empty();
		new Element('option', {'html':'- kérjük válasszon -', 'value':'0', 'selected':(selected == '0')}).inject(this.oVaros);
		if (result != null){
			result.each(function(item,index){
				new Element('option',{'html':item['destinationname'], 'value':item['destinationcode'], 'selected':(selected == item['destinationcode'])}).inject(this.oVaros);
			}.bind(this));
		}
	},
	loadZona: function(varosid, selected){
		if (this.oZona == null) return;
		var result = this.sendRequest('getZona',{'varos':varosid});
		this.oZona.empty();
		new Element('option', {'html':'- kérjük válasszon -', 'value':'0', 'selected':(selected == '0')}).inject(this.oZona);
		if (result != null){
			result.each(function(item,index){
				new Element('option', {'html':item['zonename'], 'value':item['zonecode'], 'selected':(selected == item['zonecode'])}).inject(this.oZona);
			}.bind(this));
		}
	},
	orszagChange: function(){
		this.loadVaros(this.oOrszag.get('value'),'0');
		this.varosChange();
	},
	varosChange: function(){
		this.loadZona(this.oVaros.get('value'),'0');
	},
	setOrszag: function(orszagkod){
		this.oOrszag.set('value',orszagkod);
	},
	setALL: function(orszagkod, varoskod, zonakod){
		this.oOrszag.set('value',orszagkod);
		this.loadVaros(orszagkod, varoskod);
		this.loadZona(varoskod,zonakod);
	},
	sendRequest: function(command,data){
		var ret;
		var myJSONRemote = new Request.JSON({
			url: '/hotels/ajax/location_helper.php',
			method:'post',
			async: false,
			data: {
				command:command,
				data:data
			},
			onComplete: function(obj,str){
				ret=obj;
			}
		}).send();
		return ret;
	}
});
