define([
		"dojo/_base/declare",
		"dojo/ready", 
		"dojo/store/Memory", 
		"dojo/store/Cache",
		"chy/store/Json", 
		"dijit/form/ComboBox",
		"dojo/request",
		"dojo/dom",
		"dojo/dom-construct",
		"dojo/_base/lang",
		"dojo/data/util/filter",
		"dojo/when",
		"dijit/registry",
		"dojo/_base/array",
		"dojox/form/Manager",
		"dojo/date/locale",
		"dojo/on",
		"dojo/keys"
	], function(declare,ready, Memory,Cache, Json, ComboBox,request,dom,domc,lang,filter,when,reg,array,Manager,locale,on,keys){
		
		return declare("chy.form.SearchComboBox",ComboBox,{
            store: null,
            searchAttr: "name",
            queryExpr:"${0}",
            autoComplete: false,
            required:false,
			useLabel:true,
            labelAttr: 'label',
            labelType: "html",
            dataUrl:'',
			searchUrl: '',
            formId:null,
			placeHolder:'Zoeken...',
			
            constructor: function(args){
			   declare.safeMixin(this,args);
								
				if (this.dataUrl !='') {
					this.store=new Json({idProperty:"value"})
					this.store.target=this.dataUrl;
        			this.store.startLength=3;
				}	
			   
				this.inherited(arguments);
		    },
			
			startup: function(){
				this.inherited(arguments);
				//handel enter when no item select
				on(this, "keypress", function(e){
					var charOrCode = e.charCode || e.keyCode;
					if (charOrCode == keys.ENTER) {
						dojo.stopEvent(e);
						KPWindowClearElement('kpwindowb1');
						KPWindowLoad(this.searchUrl+this.get('value'),'kpwindowb2');
						this.set('value','');
					}
				});
			},
		    
            onChange: function(e)
            {
				if (this.item!=null) {
					KPWindowClearElement('kpwindowb1');
					KPWindowLoad(this.item.target,'kpwindowb2');
					this.set('value','');
				}
            }
        });
});
