/*
计算时间差
*/

Date.prototype.diff=function (date,y)
{
	//var y=date-this,x=Math.abs(y),d,h,m,s;
	var x=t=date-y;
	d=parseInt(x/86400);
	x%=86400;
	h=parseInt(x/3600);
	x%=3600;
	m=parseInt(x/60);
	x%=60;
	s=parseInt(x/1);
	
	if(t<=0){ 
	return false;
	}
	var arrtime = new Array();
	
	arrtime[0]=d;
	arrtime[1]=('0'+h).replace(/0(\d\d)/g,'$1');
	arrtime[2]=('0'+m).replace(/0(\d\d)/g,'$1');
	arrtime[3]=('0'+s).replace(/0(\d\d)/g,'$1');
	return arrtime;

}

/*
计时器类:from:
*/
timer = function(from, num) {

    //from=new Date(from.replace(/-/g,'/'));
    var y = 0;

    (function() {
        y++;
        var diff = new Date().diff(from, y);
        if (diff == false) {
            //alert('本轮活动结束，下轮抢购即将开始！');
            //$('#sale_btn' + num).hide().fadeIn("slow");
            //$('#sale_btn' + num).html('<img src="images/sale_out_logo.gif" />');
            $('.limitcontent_d').hide().fadeIn("slow");
            //$('.limitcontent_d').html('<img src="/images/sale_out_logo.gif" />');
            $('.limitcontent_d').html('<span style="text-align: center;color:#fff;">本轮活动已结束。</span>');
            return false;
        }
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_d' + num).html(diff[0] ? diff[0] : '0');
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_h' + num).html(diff[1]);
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_m' + num).html(diff[2]);
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_s' + num).html(diff[3]);
        setTimeout(arguments.callee, 1000);
    })()
}

//产品详细页计时器
qglimit_item_timer = function(from, num) {

    var y = 0;

    if (parseFloat(from) < 0) {
        $('#promotion_limit_price').hide().fadeIn("slow");
        //$('#promotion_limit_price').html('限时抢购价：<span style="text-align: center;color:#000;">本轮活动已结束。</span>');
        return false;
    }

    (function() {
        y++;
        var diff = new Date().diff(from, y);
        if (diff == false) {
            $('#promotion_limit_price').hide().fadeOut("slow");
            //$('#promotion_limit_price').html('<span style="text-align: center;color:#000;">本轮活动已结束。</span>');
            return false;
        }
        $('#promotion_limit_price').show().fadeIn("slow");
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_d' + num).html(diff[0] ? diff[0] : '0');
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_h' + num).html(diff[1]);
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_m' + num).html(diff[2]);
        if ($('#ViewFrist_d' + num)) $('#ViewFrist_s' + num).html(diff[3]);
        setTimeout(arguments.callee, 1000);
    })()
}
