define(function(require){
	var $ = require('jquery');
	require('uriTemplate')($);
	require('dialog')($);
	require('datepicker')($);
	require('../../../js/seaJsExtends/autoComplete.js')($);
	var IFA = require('util');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	require('../../../styles/cim/autoComplete.css');
	$(function(){
		hotKeyDistrict();
		$('#searchBtn').click(function(){
			if($('#districtHokKey').val()==""){
				$('#districtId').attr("value","");
			}
			search();
		});
		$("#searchForm :input").bind("keydown",function(e){
			var e = e ? e : window.event;
			if(e.keyCode==13){
			   search();
			}
		});
	});
	
	function search(){
		var url = $('#searchUrl').val();
		$("#searchForm").attr("action",url);
		$("#searchForm").submit();
	}
	$('#exportBtn').click(function(){
		var url = $('#exportUrl').val().trim();
		$('#searchForm').attr("action",url);
		$('#searchForm').submit();
	});
    $("#startDate").datepicker({
    	onSelect:function(date){    	
    		var date=date.split("-").join("/");
    		$("#endDate").datepicker("option","minDate",new Date(date));
    	}
	});
    $("#endDate").datepicker({
    	onSelect:function(date){    	
    		var date=date.split("-").join("/");
    		$("#startDate").datepicker("option","maxDate",new Date(date));
    	}
	});
	function hotKeyDistrict(){
	  	$.ajax({
			type:"get",
			url:$("#districtUrl").val(),
			success:function(response){
			var acdata=response.district;
			$("#districtHokKey").autocomplete(acdata,
				      {
						caption: "&nbsp;&nbsp;"+i18ns("JS.districtHotKey.caption"),
						findCaption: "&nbsp;,"+i18ns("JS.districtHotKey.findCaption"),
						noFindCaption: "&nbsp;&nbsp;"+i18ns("JS.districtHotKey.noFindCaption")+":&nbsp; ",
						width: 200,
						max: 5,
						formatItem: function(row, i, max) {
							return '<span class="ac_code">{0}</span><span class="ac_Name">{1}</span>'.patchContent(row.districtHotkey, row.districtName);
						},
						formatMatch: function(row, i, max) {
							return "{0} {1}".patchContent(row.districtHotkey, row.districtName);
						},
						formatResult: function(row) {
							return "{0}".patchContent(row.districtName);
						}
					}).result(function(event, data, formatted) {
						//$(this).attr("code", data.districtId);
						$("#districtId").val(data.districtId);
						//$("#reservationForm").validate().element("#districtId");
					});
		}
		});
	}
});