$(document).ready(function(){
	var ctx = $("#ctx").val();//获取服务器地址
	
	/***************************   财务管理    ***************************/
	
	if($('#calendar_span').html()){
		$('#dateRangePicker').dateRangePicker();
		if($('#dateRangePicker').val() == ""){
			$('#dateRangePicker').val(getlastDate(1)+" to "+getlastDate(1));
			$("#date #yesterday").addClass('dateChange');
			$("#dateTab").val("yesterday");
		}
	}
	
	$('#dateChoose_span a').click(function(e){
      	inputForDate(e,$(this),$('#dateRangePicker'));
        $("#dateTab").val($(this).attr("value"));
        $(this).addClass('dateChange').siblings('.dateChange').removeClass('dateChange');
    });

	$('#dateChoose_span a').each(function(){
		var value = $(this).attr("value");
		if($("#dateTab").val() == value){
			$(this).addClass('dateChange');
		}
	});
	//点击日期控件的按钮时，去掉前面时间标签的样式
	$(".apply-btn").click(function(){
		$("#dateTab").val("");
		$('#dateChoose_span a').removeClass('dateChange');
	});
	/***************************   提现    ***************************/

	//初始校验表单
 	if($("#validateForm").html()){
 		$("#validateForm").autovalidate();
 	}
	
	$("#btn-deposit-save").click(function(){
		if (!$("#validateForm").validate()) {
			return false;
		}
		var falg = validateMoney();
		if(falg == false){
			return false;
		}
		$("#validateForm").submit();
		return false;
	});
	
	$("#btn-deposit-cancel").click(function(){
		window.location.href = ctx+"/operator/main/financial/financial-management/list";
	});
	
	$("#money").blur(function(){
		validateMoney();
	});
	
});

function exportExcel_list(){
	var searchValue = $("#searchValue").val();
	if(searchValue == "请输入关键字"){
		searchValue = "";
	}
	var param = "?selectedZoneId="+$("#selectedZoneId").val()+"&dateRangePicker="+$("#dateRangePicker").val()+"&searchValue="+searchValue;
	$("#exportExcel").attr("href",$("#ctx").val()+"/operator/main/financial/financial-management/list/exportExcel"+param);
	return false;
}

function validateMoney(){
	var reg=/^\d{1,8}\.?\d{0,2}$/;
	var $this = $("#money");
	if($this.val().match(reg)!=null){
		if(($this.val().indexOf('.') == -1 && $this.val().length > 8) || $this.val() <= 0){
			$this.css("box-shadow","0 0 6px #ff0000").attr('title','提现金额必须大于0且整数位最多8位');
			$this.parent("div").find("span.spanVaildate").html("提现金额必须大于0且整数位最多8位");
			return false;
		}if($this.val() > parseInt($("#availableMoney").val())){
			$this.css("box-shadow","0 0 6px #ff0000").attr('title','提现金额必须小于等于可用金额');
			$this.parent("div").find("span.spanVaildate").html("提现金额必须小于等于可用金额");
			return false;
		}else{
			$this.css("box-shadow","none").attr('title','');
			$this.parent("div").find("span.spanVaildate").html("");
		}
	}else{
		$this.css("box-shadow","0 0 6px #ff0000").attr('title','提现金额必须大于0整数位最多8位且最多有2位小数');
		$this.parent("div").find("span.spanVaildate").html("提现金额必须大于0整数位最多8位且最多有2位小数");
		return false;
	}
}