/**
 * function SearchBar()
 * @type  constructor
 * @memberOf SearchBar
 */
function SearchBar(combo_paesi, combo_sezioni, input_keyword, butt_cerca) {
//	trace("SearchBar("+combo_paesi+", "+combo_sezioni+", "+input_keyword+", "+butt_cerca+"): ");
//	EventDispatcher.call(this);
	this.comboSezioni = combo_sezioni;
	this.comboPaesi = combo_paesi;
	this.tfKeyword = input_keyword;
	this.buttCerca = butt_cerca;
	//
	this.init();
}
//
/** @type String */
SearchBar.EVT_ON_PAESE = "EVT_ON_PAESE";
/** @type String */
SearchBar.EVT_ON_SEZIONE = "EVT_ON_SEZIONE";
/** @type String */
SearchBar.EVT_ON_SEARCH = "EVT_ON_SEARCH";
/** @type String */
SearchBar.EVT_ON_RESET = "EVT_ON_RESET";
//
SearchBar.prototype = new EventDispatcher();
SearchBar.prototype.constructor = SearchBar;
/**
 * function init()
 * @memberOf SearchBar
 */
SearchBar.prototype.init = function() {
	var that = this;
	//
	this.comboPaesi.onchange = function (event) {
		var nome_paese = that.comboPaesi[that.comboPaesi.selectedIndex].value;
		that.broadcastMessage(SearchBar.EVT_ON_PAESE, {target:this,type:SearchBar.EVT_ON_PAESE, paese: nome_paese});
	}
	//
	this.buttCerca.onclick = function (event) {
		var nome_paese = that.comboPaesi.options.length ? that.comboPaesi[that.comboPaesi.selectedIndex].value : "";
		var nome_sezione = that.comboSezioni.options.length ? that.comboSezioni[that.comboSezioni.selectedIndex].value : "";
		var keyword = that.tfKeyword.value || "";
		that.broadcastMessage(SearchBar.EVT_ON_SEARCH, {target:this,type:SearchBar.EVT_ON_SEARCH, paese: nome_paese, sezione: nome_sezione, keyword: keyword});
	}
};
/**
 * property comboPaesi
 * @type select
 * @memberOf SearchBar
 */
SearchBar.prototype.comboPaesi = null;
/**
 * property comboSezioni
 * @type select
 * @memberOf SearchBar
 */
SearchBar.prototype.comboSezioni = null;
/**
 * property tfKeyword
 * @type input
 * @memberOf SearchBar
 */
SearchBar.prototype.tfKeyword = null;
/**
 * property buttCerca
 * @type input
 * @memberOf SearchBar
 */
SearchBar.prototype.buttCerca = null;
/**
 * function fillComboPaesi(arr_paesi)
 * @memberOf SearchBar
 * @param {Array} arr_paesi
 */
SearchBar.prototype.fillComboPaesi = function(arr_paesi) {
	
	this.comboPaesi.options.length = 0;
	if ((!arr_paesi)||(!arr_paesi.length)) return;
	for ( var i = 0; i < arr_paesi.length; i++) {
		var paese = arr_paesi[i];
		this.comboPaesi.options[i] = new Option(paese.label, paese.data);
	}
};
/**
 * function fillComboSezioni(arr_sezioni)
 * @memberOf SearchBar
 * @param {Array} arr_paesi
 */
SearchBar.prototype.fillComboSezioni = function(arr_sezioni) {
	this.comboSezioni.options.length = 0;
	if ((!arr_sezioni)||(!arr_sezioni.length)) return;
	for ( var i = 0; i < arr_sezioni.length; i++) {
		var sezione = arr_sezioni[i];
		this.comboSezioni.options[i] = new Option(sezione.label, sezione.data);
	}
};
/**
 * function reset()
 * @memberOf SearchBar
 */
SearchBar.prototype.reset = function(arr_sezioni) {
	this.fillComboSezioni();
	this.tfKeyword.value = "";
	this.fillComboPaesi();
	//
	this.broadcastMessage(SearchBar.EVT_ON_RESET, {target:this,type:SearchBar.EVT_ON_RESET});
};
