function invoiceShow(){
	
	 var chkRadio = $('input:radio[name="invoiceType"]:checked').val();
     if (chkRadio == null) {
         alert("没有选中项");
         return false;
     } else if(chkRadio==1) {
    	 $('#plainInvoice_box').hide();
    	 $('#specialInvoice_box').show();
     }else if(chkRadio==0){
    	 $('#plainInvoice_box').show();
    	 $('#specialInvoice_box').hide();
     }
    
}

function settlementTypeShow(){
	var chkRadio = $('input:radio[name="settlementType"]:checked').val();
    if (chkRadio == null) {
        alert("没有选中项");
        return false;
    } else if(chkRadio=='TRAINING') {
   	 $('#trainingSelect').show();
    }else if(chkRadio=='SOFTWARE'){
   	 $('#trainingSelect').hide();
    }
}

function mailShow(){
	var chkRadio = $('input:radio[name="doPost"]:checked').val();
    if (chkRadio == null) {
        alert("没有选中项");
        return false;
    } else if(chkRadio==1) {
   	 $('#mail_box').show();
    }else if(chkRadio==0){
   	 $('#mail_box').hide();
    }
}

$(function () {
		
	$('#invoiceReceivablesRefund').validator({
	    timely: 3,
	    focusCleanup: true,
	    
	    fields: {///ajaxCheckInvoicePrice, iidKey:#inKey
		    refundCompany: 'required;'
		    ,refundNumber: 'required;'
			,refundPrice: 'required;digits;remote[/ajaxCheckInvoiceReceivablesRefund, iridKey:#iridKey]'
			
	    }
	});
	
	$('#invoice').validator({
	    timely: 3,
	    focusCleanup: true,
	    rules: {
	    	invoiceTitle: function() {
	    		return $('#invoicePlain').prop('checked');
	        },
	        invoiceCompany: function() {
	        	return $('#invoiceSpecial').prop('checked');
		        }
	        ,isMail: function() {
	        	return $('#isMail').prop('checked');
	        }
	        ,isSettlementType: function() {
	        	return $('#settlementType').prop('checked');
	        }
//	        ,isInvoicePrice: function() {
//	        	var invoicePrice=$('#isInvoicePrice').val();
//	        	console.log(invoicePrice);
//	        	if(invoicePrice>10000){
//	        		return false;
//	        	}
//	        	//return $('#isMail').prop('checked');
//	        }
	        
	    },
	    fields: {//tel(invoiceCompany);digits(invoiceCompany)  
	    	invoiceTitle: 'required(invoiceTitle);',
	    	invoiceCompany:'required(invoiceCompany);',
	    	TIN:'required(invoiceCompany);',
	    	address:'required(invoiceCompany);',
	    	phone:'required(invoiceCompany);',//mobile|tel;
	    	bank:'required(invoiceCompany);',
	    	bankAccount:'required(invoiceCompany);'
	    	,invoicePrice: 'match(lte, 10000)'
	    	,invoiceQuantity: ' required;'
	    	,invoiceUnitPrice: 'required; '
	    	
	    	,trainId:'required(isSettlementType); '
		    ,invoiceElement: 'required; '
		    ,invoiceType: 'required'
			,recipients: 'required(isMail); '
			,recipientsPhone: 'required(isMail); '//digits(isMail);
			,recipientsAddress: 'required(isMail); '
	    }
	});
	
	$("form[name='invoiceApproval']").validator({
		timely: 3,
	    focusCleanup: true,
	    theme:"yellow_top",
	    fields: {
	        //'opinion': 'required; '
	    }
	});
	
	$("form[name='invoicePrint']").validator({
		timely: 3,
	    focusCleanup: true,
	    theme:"yellow_top",
	    fields: {
	        'invoiceNo': 'required;remote[/ajaxCheckInvoiceNoUniqueness]'
	    }
	});

	$("form[name='invoiceExpress']").validator({
		timely: 3,
	    focusCleanup: true,
	    theme:"yellow_top",
	    fields: {
	        'actualItems': 'required; ',
	        'nu': 'required; ',
	        'express': 'required; '
	    }
	});
	
	$("form[name='untreadInvoice']").validator({
	    timely: 3,
	    focusCleanup: true,
	    rules: {
	        isUntread: function() {
	        	return $("input[node-untread='post']").prop('checked');
	        }
	    },
	    fields: {
	    	 untreadReason: 'required; '
		    ,untreadPost: 'required; '
			,untreadCompany: 'required(isUntread); '
			,untreadNumber: 'required(isUntread); '
			,untreadItems: 'required(isUntread); '
	    }
	});
	
	//培训班添加
	$("form[name='invoiceTraining']").validator({
	    timely: 3,
	    focusCleanup: true,
	    fields: {//remote[/ajaxCheckInvoicePrice] 
	    	trainName: 'required;'
		    ,trainDate: 'required; '
			
	    }
	});
	
	//收款录入
	$("form[name='receivablesInvoice']").validator({
	    timely: 3,
	    focusCleanup: true,
	    fields: {//remote[/ajaxCheckInvoicePrice] 
	    	receivablesPrice: 'required;'
		    ,receivablesMessage: 'required; '
			,receivablesBank: 'required '
			,receivablesDate: 'required '
			,receivablesCategory: 'required '
			,receivablesStaff: 'required '
	    }
	});
	
	//入账
	$("form[name='receivablesInvoiceBind']").validator({
//		dataFilter: function(data) {
//			console.log(data);
//			return "ddd";
////	        if (data.status === 200) return "2333";
////	        else return data.msg;
//	    },
	    timely: 3,
	    focusCleanup: true,
	    fields: {//remote(/ajaxCheckInvoicePrice, iidKey:#inKey);
	    	receivablesPrice: 'required;'
		    ,receivablesMessage: 'required; '
			,receivablesBank: 'required '
			,receivablesDate: 'required '
			,receivablesCategory: 'required '
			,receivablesStaff: 'required '
	    }
	});
	
	$("input[checkInvoicePrice=true]").on('input',function(e){  
		var inKey=$('#inKey').val();
		var receivablesPrice=$(this).val();
		var url = "/ajaxCheckInvoicePrice";
 		$.ajax({
 			url : url,
 			type : "post",
 			cache : false,
 			dataType : "json",
 			data : {
 				iidKey : inKey,
 				receivablesPrice:receivablesPrice
 			},
 			global : true,
 			success : function(data) {
 				
 				if(data!=null)
 					$('span[checkInvoicePrice=msg]').html(data.error);
 				else
 					$('span[checkInvoicePrice=msg]').html('');
 				
 				
 			},
 			error : function(err) {
 			}
 		});
	});
	
	
	$("form[name='receivablesAscription']").validator({
	    timely: 3,
	    focusCleanup: true,
	    fields: {
	    	recepitTitleMark: 'required '
	    }
	});
	
	$("#IPA").validator({
	    timely: 3,
	    focusCleanup: true,
	    fields: {
	    	invoiceCode: 'required;',
	    	invoiceNoStart: 'required;digits; ',
	    	invoiceNoTotal: 'required;digits; ',
	    }
	});
	
	$('#invoiceQuantity').on('input',function(e) {
    	var invoiceUnitPrice=$('#invoiceUnitPrice').val();
    	var invoiceQuantity=$(this).val();
    	var tp=invoiceUnitPrice*invoiceQuantity;
    	$("#tp").html('￥'+tp);
	});
	
	$('#invoiceUnitPrice').on('input',function(e) {
    	var invoiceUnitPrice=$('#invoiceQuantity').val();
    	var invoiceQuantity=$(this).val();
    	var tp=invoiceUnitPrice*invoiceQuantity;
    	$("#tp").html('￥'+tp);
	});
	
})