CRegionsLoadChild = Class.create();

CRegionsLoadChild.prototype = Object.extend( (new CCnfDialog('logout-container')), {

   initialize: function( objConfig )
	{
		this.sStateId 			= objConfig['state_element'];
		this.sCityContainer		= objConfig['city_container'];
		this.url				= objConfig['url'];
		this.firstState			= (objConfig['default_content'])?objConfig['default_content']:'';
		this.isSetFirstStateToCities =(typeof objConfig['set_first_viewstate'] != 'undefined')?objConfig['set_first_viewstate']:true;
		this.init();
	},
	
	init: function()
	{
		if(!$(this.sStateId) ){
			return false;
		}
		if(!this.firstState){
			this.firstState = $(this.sCityContainer).innerHTML;
		}
		Event.observe($(this.sStateId), 'change', this.onChangeSelect.bindAsEventListener(this));
	},
	
	onChangeSelect: function(objEvent)
	{
		if( $(this.sStateId).value ==0 && this.isSetFirstStateToCities ){
			$(this.sCityContainer).update(this.firstState);
		} else {
			new Ajax.Request(this.url + $(this.sStateId).value, {
	    	    'onSuccess':this.successLoading.bind(this)
	            });
		}
		
	},
	
	successLoading: function(response)
	{
		$(this.sCityContainer).update(response.responseText);
		//Utils.removeLoadingEffect($('winContainer_loading'));
	}
	
});	
