﻿// JavaScript Document
/*
Content: Common components;
Remark: index,active;
Version: v0.1;
Author: guanxin.com JF.Z;
Date: 2010-07-2
*/
var Times;
var T;
var now= new Date();
var myDate = now.toLocaleString();
//格式化时间
Date.prototype.format = function(format)   
{   
   var o = {   
     "M+" : this.getMonth()+1, //month   
     "d+" : this.getDate(),    //day   
     "h+" : this.getHours(),   //hour   
     "m+" : this.getMinutes(), //minute   
     "s+" : this.getSeconds(), //second   
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
     "S" : this.getMilliseconds() //millisecond   
   }   
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
     format = format.replace(RegExp.$1,   
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));   
   return format;   
} 
//时间差
function DateDiff(sDate1,sDate2){ //sDate1和sDate2是年-月-日格式
	var aDate,oDate1,oDate2,iDays;
	aDate=sDate1.split("-");
	oDate1=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]);//转换为月-日-年格式 
	aDate=sDate2.split("-");
	oDate2=new Date(aDate[1] + '-'+aDate[2]+'-'+aDate[0]);
	iDays=parseInt((oDate2-oDate1)/1000);
	return iDays;
}
/*function DateDiff(sDate1,sDate2){ //sDate1和sDate2是年-月-日格式
	var oDate1,oDate2,iDays;
	oDate1 = new Date(sDate1);
	oDate2 = new Date(sDate2);
	iDays = oDate2.getTime()-oDate1.getTime();
	//alert(iDays)
	return iDays;
	
}*/


$(function DataTime(){
	var Length = $(".hidden").length;
	for(var i = 0; i < Length; i++){
		if($(".hidden").eq(i).val() == ""){
			Times = DateDiff(new Date().format("yyyy-MM-dd hh:mm:ss"),$(".ClosingTime").eq(i).text());
		}else{
			Times = $(".hidden").eq(i).val();
		}
		clearInterval(T);
		Times = Times - 1;
		var second = Math.floor(Times % 60);
		var minite = Math.floor((Times/60) % 60); 
		var hour = Math.floor((Times / 3600) % 24); 
		var day = Math.floor((Times / 3600 ) / 24);
		if(Times > 0){
			$(".hidden").eq(i).val(Times);
			$(".MACCUTime").eq(i).text(day+"天"+hour+"时"+minite+"分"+second+"秒");
			T = setInterval(function(){DataTime()},1000);
		}
		else{
			$(".MACCUTime").eq(i).text("已过期")
			$(".MILSUBUl li:eq(" + i + ") a").click(function() {
				return false;
			})
			$(".MILSUBUl li:eq(" + i + ") img").css({ "-moz-opacity": ".1" })
			$(".MILSUBUl li:eq(" + i + ") img").css({ "opacity": "0.1" })
			$(".MILSUBUl li:eq(" + i + ") img").css({ "filter": "gray" })
			$(".Shopping").attr("disabled",true)
			$(".Shopping").unbind("click");
			clearInterval(T);
		}

	}
})
