var PartNoQuery = Class.create();

Object.extend(PartNoQuery.prototype, CommonCodeQuery.prototype);
Object.extend(PartNoQuery.prototype, {
	inputFieldChangedEvent : function(evt) {
		// input field onchange .. 

		// 20060621 RickyChiang
		// no matter what's inputField's value, clear didplayField's innerHTML  
		this.displayField.innerHTML = "&nbsp;";

		if (this.inputField.value.trim().length>0 && this.inputField.value.trim().length<5) {
			CommonMessage.showNotification("S009");
			this.inputField.value = "";
			//this.displayField.innerHTML = "&nbsp;";
			
			Field.activate(this.inputField);
			return false;
		}		
		else {
			//this.queryObj.button.click();
		}
	},
	btnClick : function() {
		if (this.args==null) {
			alert("pls set query info first!!!");
			return false;
		}
		if (this.inputField.value.trim()=="") {
			CommonMessage.showNotification("H001");
			Field.activate(this.inputField.name);
			return false;
		}
		commonCodePopupUrl = 
			((this.args.mvcName==null)?"Common.CommonCodeList.mvc":this.args.mvcName);
		commonCodePopupUrl += (commonCodePopupUrl.indexOf("?")<0)?"?":"&";
		commonCodePopupUrl = commonCodePopupUrl
			+ "c_" + this.args.P1.replace(/[.]/g, "_")+ "=" + this.inputField.value 
			+ "&queryClass=" + this.args.P0
			+ "&popupProperty=" + escape(this.args.props)
			+ "&popupTitle=" + escape(this.args.titles);
		
		var returnValue = DialogCall(commonCodePopupUrl);
		if (returnValue==null) {
			//目前如果回傳值是 null, 不處理
			this.inputField.value = "";
			this.displayField.innerHTML = "&nbsp;";
			return false;
		}
		else if (!returnValue) {
			// 顯示 messageCode 設定的錯誤訊息
			CommonMessage.showNotification(this.messageCode);
			// 要先設定當前視窗的 Focus，才可以設定目前視窗內元件的 focus
			window.focus();
			
			this.inputField.value = "";
			this.displayField.innerHTML = "&nbsp;";
			Field.activate(this.inputField);
			return false;
		}
		else {
			try {
				this.inputField.value = eval("returnValue."+this.args.P1);
			}
			catch(E) {}
			// 20060512 Ricky Chiang Add clear "undefined" value
			if (this.inputField.value=="undefined") {
				this.inputField.value = "";
			}
			try {
				this.displayField.innerHTML = eval("returnValue."+this.args.P2) + "&nbsp;";
			}
			catch(E) {}
			// 20060512 Ricky Chiang Add clear "undefined" value
			if (this.displayField.innerText=="undefined") {
				this.displayField.innerHTML = "&nbsp;";
			}
		}
		
		if (this.returnProc && this.inputField.value != "") {
			this.returnProc.call(
				this, 
				new CommonCodeQuery.ReturnObj(this, returnValue)
			);
		}
	}
});