
$ = function(id){
	return document.getElementById(id);
}

$$ = document.getElementsByClassName = function(classname){
	var elems = [];
	var alls = document.getElementsByTagName('*'); 
	for(var i=0; i<alls.length; i++){
		if(alls[i].className && alls[i].className == classname){
			elems.push(alls[i]);	
		}
	}
	return elems;
}



Timer = function(elem_id, current_ms, del_elem_id){
	this.current_ms = current_ms;
	this.elem = document.getElementById(elem_id);
	this.del_elem = (del_elem_id)? document.getElementById(del_elem_id) : null;
	this.count = 0;
	this.delay = false;
}
Timer.prototype.start = function(){
	this.showTime();
	if(this.count > 0) 
	{
		this.current_ms -= 1000;
		if(this.current_ms < 0 && this.current_ms >= -1000){
			location.href = location.href
		}else if(this.current_ms >= 0 && this.current_ms <= 5000){
			if(this.del_elem) this.del_elem.style.display = "none";
		}
		var _self = this;
		setTimeout(function(){_self.start()}, 1000);
	}

	else this.elem.innerHTML = "抢购结束";
}
Timer.prototype.showTime = function(){
	this.count ++;
	
	var ms = this.current_ms;
	var s = h = m = d = 0;
	
	if(ms == 0){
		if(this.del_elem) this.del_elem.style.display = "none";
		s = '<a href="#" title="事件排队处理中，请稍候刷新页面。" onclick="alert(\'事件排队处理中，请稍候刷新页面。\');return false;"><strong>?</strong></a>';
		this.count = 0;
	}else if(ms < 1000) s = 1;
	else s = Math.floor(ms/1000);

	if( ms > 0) {
		
		if(s>=60){
            m=Math.floor(s/60);
            
			s=s-m*60
			
			
        }
        if(m>=60){
            h=Math.floor(m/60);
            m=m-h*60
        }
        
		if(h>=24){
			d=Math.floor(h/24)
			h=h-d*24
		
		}
		if(s<10) s="0"+s;
        if(m<10) m="0"+m;
        if(h<10) h="0"+h;
		if(d<10) d="0"+d;

		this.elem.innerHTML = "抢购倒计时:"+d+"天"+h+"时"+m+"分"+s+"秒";
	}
}

// JavaScript Document