﻿
  function showTimeLimit(ntime,dtime,vid,showday,tt){
	    if(document.getElementById(tt)==null || document.getElementById(tt)==''){
	    	return;
	    }
	  	var runtimes = document.getElementById(tt).value;
        var now=new Date(dtime);
        var future= new Date(ntime);
		var lefttime = parseInt((now-future)/1000);
		var nMS = lefttime*1000-runtimes*1000;      
        days = (nMS) / 1000 / 60 / 60 / 24;
        dayNum = Math.floor(days);
        hours = (nMS) / 1000 / 60 / 60 - (24 * dayNum);
        houNum = Math.floor(hours);
        if(houNum < 10){
            houNum = "0" + houNum;
        }
        minutes = (nMS) / 1000 / 60 - (24 * 60 * dayNum) - (60 * houNum);
        minNum = Math.floor(minutes);
        if(minNum < 10){
            minNum = "0" + minNum;
        }
        seconds = (nMS) / 1000 - (24 * 60 * 60 * dayNum) - (60 * 60 * houNum) - (60 * minNum);
        secNum = Math.floor(seconds);
        if(secNum < 10){
            secNum = "0" + secNum;
        }
        millisec=(nMS)-(24*60*60*1000*dayNum)-(60*60*1000*houNum)-(60*1000*minNum)-(secNum*1000);
        milli=Math.floor(millisec/10);
        if(milli<10){
            milli="0"+milli;
        }
        if(dayNum>=0 && showday==1){
        	document.getElementById(vid).innerHTML = dayNum+" 天 "+ houNum + ":" + minNum + ":"+ secNum + "";
        }else if(dayNum<0 && showday==1){
        	document.getElementById(vid).innerHTML = "0 天 00:00:00";
        }
        
        if(dayNum>=0 && showday==0){
        	document.getElementById(vid).innerHTML = houNum + ":" + minNum + ":"+ secNum + "";
        }else if(dayNum<0 && showday==0){
        	document.getElementById(vid).innerHTML = "00:00:00";
        }
        runtimes++;
        document.getElementById(tt).value = runtimes;
    }
  
  function showMinuteLimit(ntime,dtime,vid,showday,tt){
	  var runtimes = document.getElementById(tt).value;
      var now=new Date(dtime);
      var future= new Date(ntime);
	  var lefttime = parseInt((now-future)/1000);
	  var nMS = lefttime*1000-runtimes*1000;      
      days = (nMS) / 1000 / 60 / 60 / 24;
      dayNum = Math.floor(days);
      hours = (nMS) / 1000 / 60 / 60 - (24 * dayNum);
      houNum = Math.floor(hours);
      if(houNum < 10){
          houNum = "0" + houNum;
      }
      minutes = (nMS) / 1000 / 60 - (24 * 60 * dayNum) - (60 * houNum);
      minNum = Math.floor(minutes);
      if(minNum < 10){
          minNum = "0" + minNum;
      }
      seconds = (nMS) / 1000 - (24 * 60 * 60 * dayNum) - (60 * 60 * houNum) - (60 * minNum);
      secNum = Math.floor(seconds);
      if(secNum < 10){
          secNum = "0" + secNum;
      }
      millisec=(nMS)-(24*60*60*1000*dayNum)-(60*60*1000*houNum)-(60*1000*minNum)-(secNum*1000);
      milli=Math.floor(millisec/10);
      if(milli<10){
          milli="0"+milli;
      }
      if(dayNum>=0 && showday==1){
      	document.getElementById(vid).innerHTML = dayNum+" 天 "+ houNum + ":" + minNum + ":"+ secNum + "";
      }else if(dayNum<0 && showday==1){
      	document.getElementById(vid).innerHTML = "0 天 00:00:00";
      }
      
      if(dayNum>=0 && showday==0){
    	  document.getElementById("otime").innerHTML = minNum;
      }else if(dayNum<0 && showday==0){
    	  document.getElementById("otime").innerHTML = "00";
      }
      runtimes++;
      document.getElementById(tt).value = runtimes;
  }
  
  
  function tag_time(tag_id,tid,tempval){
		$.ajax({
			url:"/activety/ajax",
			data:"tag_id=" + tag_id + "&id=" + tid,
			type:"POST",
			dataType:"html",
			timeout: 1000,
			success: function(html){
			$("#"+tid+"").html("<script>setInterval(\"showTimeLimit("+html+",'"+tempval+"')\",1000);</script>");
		    }
		});
	}
