require({cache:{
'url:chy/form/templates/chyComboBox.html':"<div class=\"dijit dijitReset dijitInline dijitLeft\" id=\"widget_${id}\" role=\"combobox\">\r\n\t<div class='dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer' data-dojo-attach-point=\"_buttonNode, _popupStateNode\" role=\"presentation\">\r\n\t\t<span class=\"dijitReset dijitInputField icon-chevron-down\" value=\"&#9660; \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\" ${_buttonInputDisabled}>\r\n\t\t\t<!--spacer-->\r\n\t\t\t</span>\r\n\t</div>\r\n\t<div class='dijitReset dijitValidationContainer'>\r\n\t\t<input class=\"dijitReset dijitInputField dijitValidationIcon dijitValidationInner\" value=\"&#935; \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"/>\r\n\t</div>\r\n\t<div class=\"dijitReset dijitInputField dijitInputContainer\">\r\n\t\t<input class='dijitReset dijitInputInner field' ${!nameAttrSetting} type=\"text\" autocomplete=\"off\" name=\"${id}\"\r\n\t\t\tdata-dojo-attach-point=\"textbox,focusNode\" role=\"textbox\" aria-haspopup=\"true\" placeholder=\"${html5placeHolder}\"/>\r\n\t</div>\r\n\t<input type=\"hidden\" id=\"${hiddenId}\" name=\"${hiddenId}\"></input>\r\n</div>\r\n"}});
define("chy/form/ComboBox", [
		"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/text!chy/form/templates/chyComboBox.html"
	], function(declare,ready, Memory,Cache, Json, ComboBox,request,dom,domc,lang,filter,when,reg,template){
		
		var filteringSelect = declare("chy.form.ComboBox",ComboBox,{
			templateString: template,
            store: null,
            searchAttr: "name",
            queryExpr:"${0}",
            autoComplete: false,
            required:false,
            isRequired:false,
            hasDownArrow:false,
            hasArrow:false,
            labelAttr: 'name',
            labelType: "html",
            dataUrl:'',
            useLabel:false,
            html5placeHolder:"",
            formId:null,
            hiddenId:null,
            
            //placeHolder : placeHolder,
            
            //
            constructor: function(args){
			   declare.safeMixin(this,args);
			   
		   		if (this.useLabel) {
					this.labelAttr = "label";	
				}
				
				this.html5placeHolder=this.placeHolder;
				//this.placeHolder=null;
				
				
				this.hasDownArrow=this.hasArrow;
				this.required=this.isRequired;
				this.hiddenId=this.id + "_id";
				
				if (this.dataUrl !='') {
					this.store=new Json({idProperty:"value"})
					this.store.target=this.dataUrl;
        			this.store.startLength=3;
				}
			   
			   this.inherited(arguments);
		    },
		    
		    postMixInProperties:function(){
		    	this.set("placeHolder","");
		    	
		    	this.inherited(arguments);
		    },
		    
		    buildRendering:function(){
		    	this.inherited(arguments);
		    	if (!this.hasArrow){
		    		this._buttonNode.style="display:none;";
		    	}
		    },
            
            _getDisplayQueryString: function(/*String*/ text){
            	if(text && text.replace) {
					return text.replace(/([\\\*\?])/g, "\\$1");
				}
				else { return ''; }
			},
            onChange: function(e)
            {
            	if(this.item==null)
            	{
            		var query = lang.clone(this.query);
            		// Generate query
			
					var qs = this._getDisplayQueryString(e), q;
					q = filter.patternToRegExp(qs, this.ignoreCase);
					q.toString = function(){ return qs; };
					this._lastQuery = query[this.searchAttr] = q;
					
					var options = {
						ignoreCase: this.ignoreCase,
						deep: true
					};
					
					lang.mixin(options, this.fetchProperties);
					this._fetchHandle = this.store.query(query, options);
					var _this = this;
					when(this._fetchHandle, function(result){
						_this._fetchHandle = null;
						0 && console.log(result);
						if (result.length)
						{
							_this.set('item',result[0]);
							dom.byId(_this.id+"_id").value=result[0].value;
						} else {
							dom.byId(_this.id+"_id").value=null;	
						}
					}, function(err){
						0 && console.error(err);
					});
		            		
            	} else {
            		if (this.store!=null) {
	            		var tmpitem = this.item;
	            		if(tmpitem.target && dom.byId(this.formId+"_target")) {
	            			dom.byId(this.formId+"_target").value = tmpitem.target;
	            		}
	            		if(this.item.disabled) {
	            			this.set('value',this._lastQuery);
	            		}
	            		else {
	            			dom.byId(this.id+"_id").value=tmpitem.value;
	            		}
	            		
	            		if(tmpitem.submit) {
	            			//alert('do post' + getForm(KPWindowFindParent(this)).id);
	            			getForm(KPWindowFindParent(this)).onsubmit();
	            			//KPWindowDoPost('kpwindowbordertop','search');
	            			//reg.byId(getForm(KPWindowFindParent(this)).id).submit();
	            		}
	            	} else {
	            		dom.byId(this.id+"_id").value=this.item.value;
	            	}
            	}
            }
        });


		return filteringSelect;
});
