function CountDownToTime(n,t,i,r,u){counters[r]=0;var e=new Date(i),o=new Date(t),f=(o.getTime()-e.getTime())/1e3;f>0&&(CountdownInterval=setInterval("UpdateTimeLeft('"+n+"', '"+f+"', '"+r+"', '"+u+"')",1e3))}function UpdateTimeLeft(n,t,i,r){if(t=t-counters[i],t<=0)n=="countdownTime0"?(blockUI("newDealLoading",!0,!0),clearInterval(OrderCount),UpdateDeals(r)):(blockUI("newDealText",!0,!0),clearInterval(OrderCount),UpdateDeals(r));else{var e=Math.floor(t/3600).toString(),u=Math.floor(t/60%60).toString(),f=Math.floor(t%60).toString();if(e==1&&u==0&&f==0){UpdateDeals(r);return}e.length<2&&(e="0"+e);u.length<2&&(u="0"+u);f.length<2&&(f="0"+f);CountdownTimerElement=document.getElementById(n);CountdownTimerElement.innerHTML=e==0?u==0?"00:00:"+f:"00:"+u+":"+f:e+":"+u+":"+f;counters[i]=counters[i]+1}}function QuantityLeft(n,t){UpdateCount(n,t);OrderCount=setInterval("UpdateCount('"+n+"', '"+t+"')",3e4)}function UpdateCount(n,t){$("#"+n).load("/dealoftheday/Deals/CheckOrderCount/",{DealID:t},function(n){n<=0&&(blockUI("newDealText",!0,!0),clearInterval(OrderCount),UpdateDeals(t))})}function UpdateDeals(n){var t;for($("#buyNow").attr("disabled","disabled"),t=0;t<CountdownInterval+1;t++)clearInterval(t);counters.length=0;var i=500,r=Math.floor(Math.random()*(5001-i))+i;n!=$("#hfDealID").val()&&$("#hfDealID").val()!=""&&setTimeout(function(){$.post("/dealoftheday/Deals/ExpireCurrentDeal",{DealID:$("#hfDealID").val()})},r);setTimeout(function(){$.ajax({url:"/dealoftheday/Deals/GetProductDetails",type:"POST",data:{DealID:n},dataType:"html",success:function(n){$("#ProductDetails").html("");$("#ProductDetails").html(n)},error:function(){window.location.reload(!0)},complete:function(){blockUI("newDealLoading",!0,!0);$.ajax({url:"/dealoftheday/Deals/GetProductCopy",type:"POST",data:{DealID:n},dataType:"html",success:function(n){$("#ProductCopy").html("");$("#ProductCopy").html(n)},error:function(){window.location.reload(!0)},complete:function(){$.unblockUI();$("#buyNow").removeAttr("disabled")}})}})},r)}var EndCountdownTime,CountdownTimerElement,CountdownInterval,counters=[],OrderCount