package BWP.MobileSale.MobileAdjustGoodsBill;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;


import org.forks.jsonrpc.JsonRpcException;
import org.forks.jsonrpc.ManyList;
import org.forks.jsonrpc.RpcFacade;
import org.forks.jsonrpc.RpcObject;

import BWP.MobileSale.LoginedActivity;
import BWP.MobileSale.R;
import BWP.MobileSale.SelectBuyerActivity;
import BWP.MobileSale.SelectGoodsActivity;
import BWP.MobileSale.SelectRemarkActivity;
import BWP.MobileSale.Config.LoginUserConfig;
import BWP.MobileSale.Order.OrderDetailEditActivity;
import BWP.MobileSale.Util.ActivityUtil;
import BWP.MobileSale.Util.CallableTask;
import BWP.MobileSale.Util.DateTimeUtil;
import BWP.MobileSale.Util.DialogUtil;
import BWP.MobileSale.Util.OnPromptListener;
import BWP.MobileSale.Util.StringUtil;
import BWP.MobileSale.Util.ViewOnClickTask;
import BWP.widget.SelectSimpleAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class MobileAdjustGoodsBillEditActivity extends LoginedActivity {
	static final int RequestCode_SelectOutBuyer = 1;
	static final int RequestCode_SelectGoods = 2;
	static final int RequestCode_Open = 3; // 打开单据
	static final int RequestCode_EditDetail = 4;
	static final int RequestCode_SelectRemark = 5;
	static final int RequestCode_SelectInBuyer = 6;

	private long mBillID;
	private RpcObject mDmo;
	private boolean mEnableSave = true;
	boolean mEnableDelete = false;
	boolean mEnableCheck = false;
	boolean mEnableLockAdjustOutDate = false;
	private TextView button_Date;
	private TextView textViewRemark;
	private ListView listView;
	private TextView textView_AdjustOutBuyerName;
	private TextView textView_AdjustInBuyerName;
	private TextView textViewDetailCount;
	private TextView textViewDetailNum;
	private int selectedPosition = -1;
	private int firstVisiblePosition;
	public static RpcObject EditingDetail;
	
	private static final int Option_FindDetail = 0;

	private static final int Option_ClearDetail = 1;
	private LoginUserConfig config = new LoginUserConfig(this);
	private boolean flag = false;
	
	CallableTask initBillTask = new CallableTask(this, "读取单据中...") {
		public Object call() throws Exception {
			String method2 = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/EnableLockAdjustOutDate";
			mEnableLockAdjustOutDate = RpcFacade.rpcCall(method2);
			if (mBillID > 0) {
				String method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/Load";
				mDmo = RpcFacade.rpcCall(method, mBillID);
				method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/EnableCheck";
				mEnableCheck = RpcFacade.rpcCall(method, mBillID);
			} else {
				mDmo = RpcObject.create("/Sale/Sale/BO/AdjustGoodsBill");
				mDmo.setDate("AdjustOutDate", new Date());
			}
			return null;
		}

		@Override
		protected void successUI() {
			mEnableSave = mDmo.getNamedValue("BillState").getValue() == 0;
			mEnableDelete = mDmo.getNamedValue("BillState").getValue() == 0;
			initControls();
			 applyToUI();
		}

	};
	
	private void applyToUI() {
		if (mDmo == null) {
			DialogUtil.Alert(MobileAdjustGoodsBillEditActivity.this, "当前可编辑的对象为空");
			finish();
			return;
		}

		if (mBillID > 0) {
			this.setTitle(String.format("%s-手机调货单No.%s(%s)",
					getString(R.string.app_name), mBillID,
					mDmo.getNamedValue("BillState")));
		}

		textView_AdjustOutBuyerName.setText(mDmo.getString("AdjustOutBuyer_Name"));
		String aaString = mDmo.getString("AdjustInBuyer_Name");
		TextView aaTextView = (TextView)findViewById(R.id.AdjustInBuyerName);
		aaTextView.setText(aaString);

		button_Date.setText(DateTimeUtil.FormatDate(mDmo.getDate("AdjustOutDate")));
		textViewRemark.setText(mDmo.getString("Remark"));
		ManyList details = mDmo.getManyList("OutDetails");

		BigDecimal allMoney = new BigDecimal(0);
		BigDecimal allNum = new BigDecimal(0);
		for (int i = 0; i < details.size(); i++) {
			RpcObject item = details.get(i);
			BigDecimal price = item.getMoney("Price");
			if (price == null) {
				price = new BigDecimal(0);
			}
			BigDecimal number = item.getMoney("UnitNum");
			if (number == null) {
				number = new BigDecimal(0);
			}
			allMoney = allMoney.add(price.multiply(number));
			allNum=allNum.add(number);
					
		}

		textViewDetailCount.setText(String.format("%s ￥%.2f", details.size(),
				allMoney));
		textViewDetailNum.setText(String.format("%s", allNum));

		SelectSimpleAdapter adapter = new SelectSimpleAdapter(
				MobileAdjustGoodsBillEditActivity.this, details,
				R.layout.return_edit_detail_list_item, new String[] {
						"Goods_Name", "UnitNum", "Price" }, new int[] {
						R.id.Goods_Name, R.id.Number, R.id.Price });
		adapter.setSelect(selectedPosition);
		listView.setAdapter(adapter);
		if (firstVisiblePosition == -1) {
			firstVisiblePosition = details.size() - 1;
		} else if (firstVisiblePosition > details.size() - 1) {
			firstVisiblePosition = details.size() - 1;
		}
		listView.setSelection(firstVisiblePosition);
	}
	

	private void initControls() {
		InitButtonReturn();

		InitButtonSave();

		InitButtonCheck();

		 InitButtonDelete();

		 InitListView();

		 InitRemark();

		 InitBuyer();

		 InitDate();
	}
	private void InitListView() {
		textViewDetailCount = ActivityUtil
				.Find(this, R.id.AdjustGoodsBill_TextView_DetailCount);
		textViewDetailNum=ActivityUtil.Find(this, R.id.AdjustGoodsBill_TextView_DetailNum);
		listView = ActivityUtil.Find(this, R.id.Order_ListView);
		Button selectGoods = ActivityUtil.Find(this, R.id.AdjustGoodsBill_Button_SelectGoods);
		selectGoods.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				if(mDmo.getLong("AdjustOutBuyer_ID") == null){
					Toast.makeText(getApplicationContext(), "请先选择调出购货客户！", 1).show();
					return;
				}
				if(mDmo.getDate("AdjustOutDate") == null){
					Toast.makeText(getApplicationContext(), "请先选择调出时间！", 1).show();
					return;
				}
				Intent intent = new Intent();
				intent.putExtra("Buyer_ID", mDmo.getLong("AdjustOutBuyer_ID"));
				//intent.putExtra("AccountingUnit_ID", mDmo.getLong("AccountingUnit_ID"));
				button_Date = (TextView)findViewById(R.id.AdjustGoodsBill_Button_Date);
				intent.putExtra("Date", button_Date.getText());
				intent.putExtra("IsOrNotShowSecond", false);
				intent.setClass(arg0.getContext(), SelectGoodsActivity.class);
				startActivityForResult(intent, RequestCode_SelectGoods);
			}

		});

		if (!mEnableSave) {
			selectGoods.setVisibility(View.GONE);
			return;
		}
		listView.setOnItemLongClickListener(new OnItemLongClickListener() {

			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					final int arg2, long arg3) {
				new AlertDialog.Builder(arg1.getContext()).setItems(
						new CharSequence[] { "删除", "取消" },
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								if (which == 0) {
									selectedPosition = -1;
									mDmo.getManyList("OutDetails").remove(arg2);
									applyToUI();
								}
							}

						}).show();
				
				return true;
			}

		});

		listView.setOnScrollListener(new OnScrollListener() {

			public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
				// TODO Auto-generated method stub

			}

			public void onScrollStateChanged(AbsListView arg0, int arg1) {
				if (arg1 == OnScrollListener.SCROLL_STATE_IDLE) {
					firstVisiblePosition = listView.getFirstVisiblePosition();
				}

			}

		});

		listView.setOnItemClickListener(new OnItemClickListener() {
				
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				
				if(button_Date.getText()==null || button_Date.getText() == ""){
					Toast.makeText(getApplicationContext(), "请先选调出日期！", 1).show();
				}
				selectedPosition = position;
				RpcObject result = mDmo.getManyList("OutDetails").get(position);
				EditingDetail = result;
				Intent intent = new Intent();
				intent.setClass(arg1.getContext(),
						MobileAdjustGoodsBillDetailEditActivity.class);
				HashMap<String, Object> map = new HashMap<String, Object>();
				Iterator<Entry<String, Object>> iterator = result.entrySet()
						.iterator();
				while (iterator.hasNext()) {
					Entry<String, Object> entry = iterator.next();
					String cccString = entry.getKey();
					if(cccString.equals("Goods_ConvertMode")){
						continue;
					}
					map.put(entry.getKey(), entry.getValue());
				}
				intent.putExtra("Detail", map);
				intent.putExtra("Position", position);
				startActivityForResult(intent, RequestCode_EditDetail);

			}

		});
	}
	
	private void InitDate() {
		button_Date = ActivityUtil.Find(this, R.id.AdjustGoodsBill_Button_Date);
		if (!mEnableSave) {
			button_Date.setHint("");
			return;
		}
		if(!mEnableLockAdjustOutDate){
			button_Date.setEnabled(false);
		}
		button_Date.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

					public void onDateSet(DatePicker datePicker, int year,
							int month, int day) {
						Calendar calendar = Calendar.getInstance();
						calendar.set(year, month, day);
						Date date = DateTimeUtil.RemoveTime(calendar.getTime());
						mDmo.setDate("AdjustOutDate", date);
						applyToUI();
					}

				};
				String dateStr = button_Date.getText().toString();
				Calendar calendar = DateTimeUtil.SafeParseCalendar(dateStr);

				new DatePickerDialog(arg0.getContext(), onDateSetListener,
						calendar.get(Calendar.YEAR), calendar
								.get(Calendar.MONTH), calendar
								.get(Calendar.DAY_OF_MONTH)).show();

			}

		});
	}
	private void InitBuyer() {
		
		//调出客户
		textView_AdjustOutBuyerName = ActivityUtil.Find(this, R.id.AdjustOutBuyerName);
		Button searchOutBuyerButton = ActivityUtil.FindButton(this,
				R.id.SelectAdjustOutBuyer);
		if (!mEnableSave) {
			searchOutBuyerButton.setVisibility(View.GONE);
			return;
		}

		searchOutBuyerButton.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.putExtra("BuyerType", "调出客户");
				intent.setClass(arg0.getContext(), SelectBuyerActivity.class);
				startActivityForResult(intent, RequestCode_SelectOutBuyer);
			}

		});
		//调入客户
		textView_AdjustInBuyerName = ActivityUtil.Find(this, R.id.AdjustInBuyerName);
		Button searchInBuyerButton = ActivityUtil.FindButton(this,
				R.id.SelectAdjustInBuyer);
		if (!mEnableSave) {
			searchInBuyerButton.setVisibility(View.GONE);
			return;
		}
		searchInBuyerButton.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.putExtra("UserVsCustomerSet", false);
				intent.setClass(arg0.getContext(), SelectBuyerActivity.class);
				startActivityForResult(intent, RequestCode_SelectInBuyer);
			}

		});
	}
	private void InitRemark() {
		if (mEnableSave) {
			textViewRemark = ActivityUtil.Find(this, R.id.AdjustGoodsBill_EditText_Remark);
			ActivityUtil.Find(this, R.id.AdjustGoodsBill_EditText_Remark).setVisibility(
					View.GONE);

			Button searchRemarkButton = ActivityUtil.FindButton(this,
					R.id.AdjustGoodsBill_Button_SelectRemark);

			searchRemarkButton.setOnClickListener(new OnClickListener() {

				public void onClick(View arg0) {
					Intent intent = new Intent();
					intent.setClass(arg0.getContext(),
							SelectRemarkActivity.class);
					startActivityForResult(intent, RequestCode_SelectRemark);
				}

			});
		} else {
			textViewRemark = ActivityUtil.Find(this, R.id.AdjustGoodsBill_EditText_Remark);
			textViewRemark.setVisibility(
					View.GONE);
			ActivityUtil.FindButton(this, R.id.AdjustGoodsBill_Button_SelectRemark).setVisibility(
					View.GONE);
		}
	}
	private void InitButtonDelete() {
		deleteTask.setPrompt("确定要删除吗?");
		Button buttonDelete = ActivityUtil.Find(this, R.id.AdjustGoodsBill_Delete);
		if (!mEnableDelete) {
			buttonDelete.setVisibility(View.GONE);
		}
		buttonDelete.setOnClickListener(deleteTask);
	}

	ViewOnClickTask deleteTask = new ViewOnClickTask(this, "删除中...") {

		public Object call() throws Exception {
			String method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/Delete";
			RpcFacade.rpcCall(method, mBillID);
			return null;
		}

		@Override
		protected void successUI() {
			DialogUtil.Alert(MobileAdjustGoodsBillEditActivity.this, "删除成功");
			Intent intent = new Intent();
			ActivityUtil.Finish(MobileAdjustGoodsBillEditActivity.this, intent);
		}
	};
	
	private void InitButtonCheck() {
		Button btnCheck = ActivityUtil.FindButton(this, R.id.AdjustGoodsBill_Check);
		if (!mEnableCheck) {
			btnCheck.setVisibility(View.GONE);
		}
		btnCheck.setOnClickListener(checkTask);
	}
	ViewOnClickTask checkTask = new ViewOnClickTask(this, "审核中...") {

		public Object call() throws Exception {
			String method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/Check";
			RpcFacade.rpcCall(method, mBillID);
			return null;
		}

		@Override
		protected void successUI() {
			DialogUtil.AutoHiddenAlert(MobileAdjustGoodsBillEditActivity.this, "审核成功");
			finish();
			Intent intent = new Intent();
			intent.putExtra("ID", mBillID);
			intent.setClass(MobileAdjustGoodsBillEditActivity.this, MobileAdjustGoodsBillEditActivity.class);
			startActivityIfNeeded(intent, MobileAdjustGoodsBillEditActivity.RequestCode_Open);

		}
	};
	private void InitButtonSave() {
		Button btnSave = ActivityUtil.FindButton(this, R.id.AdjustGoodsBill_Save);
		if (!mEnableSave) {
			btnSave.setVisibility(View.GONE);
		}
		btnSave.setOnClickListener(saveTask);
	}
	

	private void InitButtonReturn() {
		Button btnSave = ActivityUtil.FindButton(this, R.id.AdjustGoodsBill_Return);
		btnSave.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	
	ViewOnClickTask saveTask = new ViewOnClickTask(this, "保存中...") {
		public Object call() throws Exception {
			mDmo.setString("Remark", textViewRemark.getText().toString());
			if (mBillID > 0) {
				String userName = config.getStore().getString("Username", "");
				if(!userName.equals(mDmo.getString("CreateUser_Name"))){
					flag = true;
				}else{
				String method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/Update";
				RpcFacade.rpcCall(method, mDmo);
				}
			} else {
				String method = "/Sale/SaleXiWang/Rpcs/MobileAdjustGoodsBillRpc/Insert";
				mBillID = RpcFacade.rpcCall(method, mDmo);
			}
			return null;
		}

		@Override
		protected void successUI() {
			    if(flag){
			    	Toast.makeText(getApplicationContext(), "保存失败，不允许编辑别人的调货单！",2).show();
			    }else{
				Toast.makeText(getApplicationContext(), "保存成功", 1).show();
			    
				finish();
				Intent intent = new Intent();
				intent.putExtra("ID", mBillID);
				intent.setClass(MobileAdjustGoodsBillEditActivity.this, MobileAdjustGoodsBillEditActivity.class);
				startActivityIfNeeded(intent, MobileAdjustGoodsBillEditActivity.RequestCode_Open);
			    }
	};
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.mobileadjustgoodsbill_edit);
		Intent intent = getIntent();
		mBillID = intent.getLongExtra("ID", 0);
		initBillTask.execute();
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
		super.onActivityResult(requestCode, resultCode, intent);
		if (resultCode != Activity.RESULT_OK) {
			return;
		}
		

		switch (requestCode) {
		case RequestCode_SelectOutBuyer:
			ReceiveSelectOutBuyerResult(intent);
			break;
		case RequestCode_SelectInBuyer:
			ReceiveSelectInBuyerResult(intent);
			break;
		case RequestCode_SelectGoods:
			ReceiveSelectGoodsResult(intent);
			break;
		case RequestCode_EditDetail:
			ReceiveEditDetail(intent);
			break;
		case RequestCode_SelectRemark:
			ReceiveSelectRemarkResult(intent);
			break;
		}
	}
	
	
	@SuppressWarnings("unchecked")
	private void ReceiveEditDetail(Intent intent) {
		int position = intent.getIntExtra("Position", -1);
		HashMap<String, Object> map = (HashMap<String, Object>) intent
				.getSerializableExtra("Detail");
		RpcObject detail = mDmo.getManyList("OutDetails").get(position);
		detail.setMoney("UnitNum", (BigDecimal) map.get("UnitNum"));
		applyToUI();
	}

	private void ReceiveSelectGoodsResult(Intent intent) {
		firstVisiblePosition = listView.getBottom();
		Object[] result = (Object[]) intent.getSerializableExtra("Result");
		ManyList details = mDmo.getManyList("OutDetails");
		for (Object item : result) {
			@SuppressWarnings("unchecked")
			HashMap<String, Object> map = (HashMap<String, Object>) item;
			try {
				RpcObject detail = RpcObject.create("/Sale/Sale/BO/AdjustGoodsBill_OutDetail");
				detail.setLong("Goods_ID", (Long) map.get("ID"));
				detail.setString("Goods_Name", (String) map.get("Name"));
				detail.setString("Goods_Code", (String) map.get("Code"));
				detail.setString("Goods_Spell", (String) map.get("Spell"));
				detail.setMoney("UnitNum", (BigDecimal) map.get("Number"));
				detail.setMoney("Price", (BigDecimal) map.get("Price"));
				details.add(detail);
			} catch (JsonRpcException e) {
				e.printStackTrace();
			}
		}
		applyToUI();
	}
	@SuppressWarnings("unchecked")
	private void ReceiveSelectOutBuyerResult(Intent intent) {
		HashMap<String, Object> map = (HashMap<String, Object>) intent
				.getSerializableExtra("Result");
		mDmo.setString("AdjustOutBuyer_Name", (String) map.get("Name"));
		mDmo.setLong("AdjustOutBuyer_ID", (Long) map.get("ID"));
		applyToUI();
	}

	@SuppressWarnings("unchecked")
	private void ReceiveSelectInBuyerResult(Intent intent) {
		HashMap<String, Object> map = (HashMap<String, Object>) intent
				.getSerializableExtra("Result");
		mDmo.setString("AdjustInBuyer_Name", (String) map.get("Name"));
		mDmo.setLong("AdjustInBuyer_ID", (Long) map.get("ID"));
		applyToUI();
	}
	
	private void ReceiveSelectRemarkResult(Intent intent) {
		String Remark = (String) intent.getSerializableExtra("Result");
		mDmo.setString("Remark", Remark);
		applyToUI();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, Option_FindDetail, 0, "查找明细");
		menu.add(0, Option_ClearDetail, 1, "清空明细");
		return super.onCreateOptionsMenu(menu);
	}

	String detailSearchKey;
	CallableTask searchDetailTask = new CallableTask(this, "") {

		private int searchResult;

		public Object call() throws Exception {
			searchResult = -1;
			ManyList details = mDmo.getManyList("OutDetails");
			for (int i = 0; i < details.size(); i++) {
				RpcObject item = details.get(i);
				if (MatchDetail(item, detailSearchKey)) {
					searchResult = i;
					break;
				}
			}

			Log.d("OrderEdit", String.format("退货登记单明细搜索结果:%s", searchResult));

			// TODO Auto-generated method stub
			return null;
		}

		private boolean MatchDetail(RpcObject item, String detailSearchKey) {
			String spell = item.getString("Goods_Spell");
			if (spell.contains(detailSearchKey)) {
				return true;
			}
			String code = item.getString("Goods_Code");
			if (code.contains(detailSearchKey)) {
				return true;
			}
			String goodsName = item.getString("Goods_Name");
			if (goodsName.contains(detailSearchKey)) {
				return true;
			}
			return false;
		}

		@Override
		protected void successUI() {
			if (searchResult >= 0) {
				selectedPosition = searchResult;
				firstVisiblePosition = searchResult;
				applyToUI();
			} else {
				DialogUtil
						.AutoHiddenAlert(MobileAdjustGoodsBillEditActivity.this, "没有查找到匹配的明细");
			}
		}
	};
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case Option_FindDetail:
			DialogUtil.Prompt(MobileAdjustGoodsBillEditActivity.this, "存货明细查找", "支持名称编码拼音首字母",
					"", InputType.TYPE_CLASS_TEXT, new OnPromptListener() {
						public void OnPrompt(String prompt) {
							detailSearchKey = prompt;
							searchDetailTask.execute();
						}

						@Override
						public void OnPrompt2(HashMap<String, Object> prompt) {
							// TODO Auto-generated method stub
							
						}
					});
			break;
		case Option_ClearDetail:
			DialogUtil.Confirm(MobileAdjustGoodsBillEditActivity.this, "确定要清空明细吗?", "是", "否",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							selectedPosition = -1;
							mDmo.getManyList("OutDetails").clear();
							applyToUI();
						}
					});
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch(keyCode){
		case KeyEvent.KEYCODE_BACK:
			DialogUtil.Confirm(this, "您按了返回按钮,是否返回?", "是","否", new android.content.DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
				
			});
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}

	}

