$(document).ready(function(){
    //loading
    $('#loadingContainer').ajaxStart(function(){
	    $(this).show();
	    $('#loadingbackground').show().css({"opacity": "0.5"});
	}).ajaxStop(function(){
	    $(this).hide();
	});
	$('.datepicker').datepicker();
	Start();
	
	$('#ddlPaymentType').change(function(){
		var paymentTotal = SearchOrderAjax('OrderStatistical.aspx','type=ajax&Action=SearchOrderAjax&from=' + $.trim($('#txtDateTimeFrom').val()) + '&to=' + $.trim($('#txtDateTimeTo').val()) + '&ptype=' + $('#ddlPaymentType').val() + '&stype=');
		$('#paymentTotal').html(paymentTotal);
	});
	
	$('#ddlShippingType').change(function(){
		var shippingTotal = SearchOrderAjax('OrderStatistical.aspx','type=ajax&Action=SearchOrderAjax&from=' + $.trim($('#txtDateTimeFrom').val()) + '&to=' + $.trim($('#txtDateTimeTo').val()) + '&ptype=&stype=' + $('#ddlShippingType').val());
		$('#shippingTotal').html(shippingTotal);
	});
	
	$('#btnSearch').click(function(){
		Start();
	});
	
});

function Start()
{
	var orderTotal = SearchOrderAjax('OrderStatistical.aspx','type=ajax&Action=SearchOrderAjax&from=' + $.trim($('#txtDateTimeFrom').val()) + '&to=' + $.trim($('#txtDateTimeTo').val()) + '&ptype=&stype=');
	$('#orderTotal').html(orderTotal);
	var paymentTotal = SearchOrderAjax('OrderStatistical.aspx','type=ajax&Action=SearchOrderAjax&from=' + $.trim($('#txtDateTimeFrom').val()) + '&to=' + $.trim($('#txtDateTimeTo').val()) + '&ptype=' + $('#ddlPaymentType').val() + '&stype=');
	$('#paymentTotal').html(paymentTotal);
	var shippingTotal = SearchOrderAjax('OrderStatistical.aspx','type=ajax&Action=SearchOrderAjax&from=' + $.trim($('#txtDateTimeFrom').val()) + '&to=' + $.trim($('#txtDateTimeTo').val()) + '&ptype=&stype=' + $('#ddlShippingType').val());
	$('#shippingTotal').html(shippingTotal);
}

function SearchOrderAjax(weburl,urldata){
	var shtml = '';
	$.ajax({
        type:"get",
        url:weburl+'?NoCopyRight=1',
        data:urldata,
        cache:false,
		async:false,
        success:function(msg){
			var mmsg = msg.split(',');
			shtml += '<td>' + mmsg[0] + '<br/><font color=blue>（金额:' + mmsg[2] + '）</font></td>';
			shtml += '<td>' + mmsg[1] + '<br/><font color=blue>（金额:' + mmsg[3] + '）</font></td>';
			shtml += '<td>' + mmsg[4] + '%</td>';
        },
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!')}else{alert('error')};}
    });
	return shtml;
}