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(){
		hotKeyCompany();
//		$('#searchBtn').click(function(){
//			if($('#cdpNo').val()==""){
//				$('#companyId').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();
	});
    $("#reportDate").datepicker({
	});
	function hotKeyCompany(){
	  	$.ajax({
			type:"get",
			url:$("#companyUrl").val(),
			success:function(response){
			$("#cdpNo").autocomplete(response.company,
				      {
						caption: "&nbsp;&nbsp;"+i18n["JS.districtHotKey.caption"],
						findCaption: "&nbsp;,"+i18n["JS.districtHotKey.findCaption"],
						noFindCaption: "&nbsp;&nbsp;"+i18n["JS.companyHotKey.noFindCaption"]+":&nbsp; ",
						max: 5,
						width: 200,
						formatItem: function(row, i, max) {
				             var cpdNo="cdpNo:"+row.cdpNo+"&#13;";
				             var companyName=i18n["JS.companyHotKey.coName"]+":"+row.companyName+"&#13;";
				             var companyHotkey=i18n["JS.companyHotKey"]+":"+row.companyHotkey+"&#13;";
				             var companyAddress=i18n["JS.companyHotKey.coAddr"]+":"+row.companyAddress+"&#13;";
				             var companyContact1st=i18n["JS.companyHotKey.coContact"]+":"+row.companyContact1st+"&#13;";
				             var title=cpdNo+companyName+companyHotkey+companyAddress+companyContact1st;
				             var companyName=row.companyName+"("+row.companyHotkey+")";
							return '<span title="{2}"><span class="ac_code" >{0}</span><span class="ac_Name">{1}</span></span>'.patchContent(row.cdpNo,companyName,title);
						},
						formatMatch: function(row, i, max) {
							return "{0} {1} {2}".patchContent(row.cdpNo,row.companyHotkey,row.companyName);
						},
						formatResult: function(row) {
							return "{0}".patchContent(row.cdpNo);
						}
					}).result(function(event, data, formatted) {
						$("#companyId").val(data.companyId);
					});
		}
		});
	}
});