if(!dojo._hasResource["voila.form.DWRFilteringSelect"]){
	dojo._hasResource["voila.form.DWRFilteringSelect"] = true;
	dojo.provide("voila.form.DWRFilteringSelect");

	dojo.require("voila.form.FilteringSelect");
	dojo.require("voila.data.DWRReadStore");

	dojo.declare("voila.form.DWRFilteringSelect", [voila.form.FilteringSelect],{
		constructor: function(params, id){
			var id;
			if (id.id) {
				id = id.id;
			}
		    this.id = params.id || id;
		    var element = document.getElementById(this.id);
		    this.name = params.name || element.name || this.id;
		    this.autoComplete = params.autoComplete || false;
		    this.highlightMatch = params.highlightMatch || "start";
		    this.readOnly = params.readOnly || element.readOnly;
		    this.required = params.required || false; 
		    this.searchDelay = params.searchDelay || 100;
		    this.pageSize = params.pageSize || Infinity;
		    this.value = params.value || element.value;
		    this.store = params.store;
		    this["class"] = element.className;
		    this.searchAttr = params.searchAttr;
		    this.idAttr = params.idAttr || params.searchAttr;
		    if (!this.store) {
		    	this.store = new voila.data.DWRReadStore({
		        	dwrMethod: params.dwrMethod, 
		        	dwrDetailMethod: params.dwrDetailMethod, 
		            idAttr: this.idAttr
		        });
		    	if (this.searchAttr == this.idAttr) {
		    		this.store.fetchItemByIdentity = function(param){
		    			var item = {};
		    			item[this._idAttr] = param.identity;
		    			param.onItem(item);
		    	    };
		    	}
		    }
		    this.fetchProperties = params.fetchProperties || {};
		    if (!this.fetchProperties.orderBy) {
		    	this.fetchProperties.orderBy = this.searchAttr;
		    }
		    if (!this.fetchProperties.criteria) {
		    	this.fetchProperties.criteria = {};
		    }
		    if (!this.fetchProperties.criteria[this.searchAttr]) {
		    	this.fetchProperties.criteria[this.searchAttr] = 3;
		    }
		    if (this.fetchProperties.criteria[this.searchAttr] == 3 && !params.autoComplete) {
			    this.autoComplete = true;
		    }
		    if (this.fetchProperties.criteria[this.searchAttr] != 3 && !params.highlightMatch) {
			    this.highlightMatch = "all";
		    }
		    
		    if (this.store && params.labelFunc) {
		    	this.store.getValue = params.labelFunc;
		    }
		},
		
		toString: function(){
			// summary:
			//		Returns widget as a printable string using the widget's value
			// tags:
			//		protected
			var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
			return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
		}

	});
	
}
