define(function(require){
	var $ = require('jquery');
	require('grid')($);
    require('uriTemplate')($);
    require('dialog')($);
    require('datepicker')($);
    require('globalization');
    IFA = require('util');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	require('../../../styles/cim/cim-grid.css');
	require('../../../styles/cim/validation.css');
	require('../../../styles/cim/autoComplete.css');
	require('../../../js/seaJsExtends/autoComplete.js')($);
	$(function(){
		search();
		$("#searchBtn").bind("click",function(){
			if($('#searchForm').valid()){
				search();
			}else{
				$.msg.alert(i18n["Page.Dialog.content.inputError"]);
			}
		});
		$("#searchForm :input").bind("keydown",function(e){
			var e = e ? e : window.event;
			if(e.keyCode==13){
				if($('#searchForm').valid()){
					search();
				}else{
					$.msg.alert(i18n["Page.Dialog.content.inputError"]);
				}
			}
		});
		$('#searchForm').validate({
			rules:{
				startPaymentAmount:{
					regex:/^[+|-]?\d*\.?\d*$/
				},
				endPaymentAmount:{
					regex:/^[+|-]?\d*\.?\d*$/
				}
			},
			messages:{
				startPaymentAmount:{
					regex:i18n["Validation.billing.billingAmount"]
				},
				endPaymentAmount:{
					regex:i18n["Validation.billing.billingAmount"]
				}
			}
		});
	});

	function search(){
		var url=$("#searchUrl").val().trim();
		$("#journalList").grid({
			url:url,
			root:"journalList",
			pageTheme:'Theme1',
			isREST :false,
			method:"POST",
			defaultParams:{serialNumber:$('#serialNumber').val(),modifierName:$('#modifierName').val(),startDate:$('#startDate').val(),
				endDate:$('#endDate').val(),startPaymentAmount:$('#startPaymentAmount').val(),endPaymentAmount:$('#endPaymentAmount').val()},
			fields:[{name:i18ns("Entity.cash.serializNum"),style:{width:"10%"},style:{width:"10%"},id:"serialNumber",render:function(data){
		 			    return $('<a href="#" title='+data.serialNumber+' class="bb"/>').html(data.serialNumber).click(function(){
		  				    enterJournal(data.journalId);
		     			    });
			        }},
			        {name:i18ns("Page.workOrder.BankCode"),style:{width:"10%"},id:"bankNo"},
			        {name:i18ns("Page.workOrder.cash"),style:{width:"10%"},id:"paymentAmount",render:function(data){
				    	return  Globalize.format(data.paymentAmount,'n');
				    }
			        	},
			        {name:i18ns("Company.Profile.Creator"),style:{width:"10%"},id:"creatorName"},
			        {name:i18ns("Company.Profile.CreateTime"),style:{width:"15%"},id:"creationDate",render:function(data){
	  				  	var timeCheck = /^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}$/;
	  				  	if(!timeCheck.exec(data.creationDate)){
	  				  		 data.creationDate = new Date(data.creationDate).format("yyyy-MM-dd hh:mm");
	  				  	}
	  				  	return data.creationDate;
			        }},
			        {name:i18ns("journalLastSubmitter"),style:{width:"10%"},id:"modifierName"},
			        {name:i18ns("journalLastCommitTime"),style:{width:"15%"},id:"modificationDate",render:function(data){
	  				  	var timeCheck = /^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}$/;
	  				  	if(!timeCheck.exec(data.modificationDate)){
	  				  		 data.modificationDate = new Date(data.modificationDate).format("yyyy-MM-dd hh:mm");
	  				  	}
	  				  	return data.modificationDate;
			        }},
			        {name:i18n["Entity.Operation"],style:{width:"20%"},operation:[
			                                                  {text:i18ns("Entity.personprofile.enter"),action:function(data){
			                                                	  enterJournal(data.journalId);
			                                                  }}
			                                                  ]}
			        ]
			});
	}
		
		function enterJournal(id){
		      var urlVal = $('#detailsUrl').val();
		      var urlStr = new $.Template(urlVal);
			  var urlParam = {"id":id};
			  var url = urlStr.expand(urlParam);	
		      location.replace(url);	
		}
	    $("#startDate").datepicker({
		});
	    $("#endDate").datepicker({
		});
});