/*
var requestRule = window.requestRule;


if(!requestRule){
	//系统配置
	requestRule = {
		//列表页面，多个拍品的请求频率配置，根据时间段
		muli : [
			{startTime:"02:00:00",endTime:"08:00:00",request_fz:10000},
			{startTime:"08:00:00",endTime:"09:00:00",request_fz:5000},
			{startTime:"09:00:00",endTime:"02:00:00",request_fz:2000}
		],
		//单个拍品，详细页面的请求频率配置，跟据剩余时间
		single : [
			{startTime:10*60*1000,endTime:0,request_fz:5000},
			{startTime:5*60*1000,endTime:10*60*1000,request_fz:2000},
			{startTime:-500000,endTime:5*60*1000,request_fz:1000}
		],
		//系统配置项，目前只有弹窗，默认不启用
		sys : {
			showwindow :{time:10*60*1000,isrun:false,msg:'您'+this.time/60000+'分钟都没操作了，您还继续吗？'}
		},
		//网站停止配置，停止后，跳转到错误提示页面
		stop : {isrun:false,jumper:'http://pai.500wan.com/stop.shtml'},
		//网站夜间暂停配置，开始与结束时间
		pause : {startTime:'00:00:00',endTime:'10:00:00'},
		//长时间暂停配置，过年的时候用过
		pauseLong : {startTime:'2011/2/1 00:00:00',endTime:'2011/2/11 10:00:00'}
	}
}
//将日期格式，改为年月号的形式
String.prototype.change2Date = function(){
	
	return this.substr(5).substr(0,10).replace('/','月').replace(' ','号')
}

//ping，测速
Pings.init();


//first time load system info
Y.ready(function(){
	//同步服务器的系统配置
	var data = Y.ajax(_Base.Base_Url+"/ajax/sysnotice.php?"+Math.random());
	try
	{
		data = String2Json(data.text);
		data.muli && (requestRule.muli = data.muli);
		data.single && (requestRule.single = data.single);
		data.sys && (requestRule.sys = data.sys);
		data.stop && (requestRule.stop = data.stop);
		data.pause && (requestRule.pause = data.pause);
	}
	catch(e){}
	
});
*/
//倒计时脚本的类
var countDown = {
	//是否出过价，出过价，会马上与服务器同步信息
	hasBid : false,
	//是否停止，用于用于长时间不操作，弹出提示，停止所有倒计时，目前尚未启用
	muliStop : false,
	//同步服务器配置，每隔一个时间段
	//is_ajax:是否需要请求服务器
	muliSysFn : function(is_ajax){
		//检测系统配置
		var checkSys = function(){
			//遍历系统配置的sys项目
			for(var name in requestRule.sys){
			
				if(requestRule.sys[name].isrun == true){
					eval('countDown.muli_'+name+'('+requestRule.sys[name].time+')');
				}
			}
			//网站停止，跳转页面
			if(requestRule.stop.isrun)window.location.href = requestRule.stop.jumper;
			//当前时间
			var now_time = new Date().toLocaleTimeString(),
			//临时开始时间，用于头部显示夜间暂停提示，默认应该是用pause.startTime
			tempStartTime = "21:00:00",
			//时间差，使客户端时间与服务器时间一致，此变量在header.html页面中定义
			dev = _Base.Base_ServerTime || 0;
			//补0
			if(now_time.length <=7)now_time = "0"+now_time;
			
			//now_time =time2TimeStamp(now_time,now_time<requestRule.pause.endTime && requestRule.pause.endTime<requestRule.pause.startTime);
			//获取当前时间戳
			now_time =time2TimeStamp(now_time,now_time<requestRule.pause.endTime && requestRule.pause.endTime<tempStartTime);
			
			//if(now_time >=time2TimeStamp(requestRule.pause.startTime)-15*60000 && now_time <time2TimeStamp(requestRule.pause.endTime,requestRule.pause.endTime<requestRule.pause.startTime)){
			//判断当前时间戳在长暂停时间范围内
			if(Date.parse(new Date())-dev >= Date.parse(new Date(requestRule.pauseLong.startTime))-2*28800000 && Date.parse(new Date())-dev <= Date.parse(new Date(requestRule.pauseLong.endTime)) ){
				//显示提示显示
				Y.one("#js_pai_tip .pai_tipC").innerHTML = requestRule.pauseLong.startTime.change2Date().substr(0,9)+"-"+requestRule.pauseLong.endTime.change2Date()+"为春节休息暂停时间,暂停期间所有商品倒数时间和当前价格不变，"+requestRule.pauseLong.endTime.change2Date()+"恢复时继续！";
				
				Y.one("#js_pai_tip").style.display = "";
				
				return false;
			}
			//判断当前时间戳在夜间暂停范围内
			if(now_time >=time2TimeStamp(tempStartTime)-15*60000 && now_time <time2TimeStamp(requestRule.pause.endTime,requestRule.pause.endTime<tempStartTime)){
			
				Y.one("#js_pai_tip .pai_tipC").innerHTML = "为了您的身体健康，全站于北京时间"+requestRule.pause.startTime.substr(0,5)+"-"+requestRule.pause.endTime.substr(0,5)+"暂停，暂停期间所有倒数时间和当前价格不变，"+requestRule.pause.endTime.substr(0,5)+"恢复时继续！";
				Y.one("#js_pai_tip").style.display = "";
			}
			//否则提示不显示
			else Y.one("#js_pai_tip").style.display = "none";
		}
		//请求服务器配置
		var ajax_check = function(){
			
			//ajax请求，修改sys
			Y.ajax(_Base.Base_Url+"/ajax/sysnotice.php?"+Math.random(),function(data){
				try
				{
					data = String2Json(data.text);
					data.muli && (requestRule.muli = data.muli);
					data.single && (requestRule.single = data.single);
					data.sys && (requestRule.sys = data.sys);
					data.stop && (requestRule.stop = data.stop);
					data.pause && (requestRule.pause = data.pause);
					checkSys();
				}
				catch(e){}
				
				setTimeout(ajax_check,20000);
			});
		}
		
		checkSys();
		if(is_ajax)ajax_check();
	},
	//弹出层提示
	muli_showwindow : function(){
		
		var timeId = 0;
		
		return function(time){
			
			if(!time){
				clearTimeout(timeId);
				return countDown.muliSysFn();
			}
			else {
				if(timeId)return;
			}
			
			timeId = setTimeout(function(){
				
				if(!requestRule.sys.showwindow.isrun)return;
				
				countDown.muliStop = true;
				alertMsg.pop({type:'alert',data:{html:requestRule.sys['showwindow'].msg,callback:'function(){countDown.muliStop=false;countDown.muliSysFn();}',button_msg:'继续'}});
			
			},time);
		}
	}(),
	//查找某dom元素的className的子元素
	getByClass : function(obj,csName){
		
		var finds = obj.getElementsByTagName('*');
		
		for(var i=0,l=finds.length;i<l;i++){
			if(finds[i].className.indexOf(csName) >= 0)return finds[i];
		}
		return null;
	},
	//替换数组中的特定值
	//例如：数组为[2001|1923.23,2021|234.12]，根据前面的2001，替换后面的1923.23
	findArrById : function(arr,id,value){
		
		for(var i=0,l=arr.length;i<l;i++){
			
			if(arr[i].indexOf(id+"|") >=0){
			
				if(arr[i].length <= id.length+1){
					arr[i] += value;
				}
				else
				{
					var rep = arr[i].substring(id.length+1);
					arr[i] = arr[i].replace(rep,value);
					break;
				}
			}
		}
		
	},
	//查找数组中的指定项，返回下标
	findArrByKey : function(arr,key){
		
		for(var i=0,l=arr.length;i<l;i++){
			if(arr[i][0] == key)return true;
		}
		return false;
	},
	//改变某dom元素的背景色，渐变的过程
	changeBgColor : function(obj){
		
		var arrColor = ['#ffffff','#fbd9d9','#fbb0b0','#ff9b9b','#fc6262','#fc6262','#ff9b9b','#fbb0b0','#fbd9d9','#ffffff'],nowIndex=0;
		
		//obj.style.backgroundColor = color;
		//setTimeout(function(){
			//obj.style.backgroundColor = '';
		//},500);
		
		var process = function(){
			
			obj.style.backgroundColor = arrColor[nowIndex];
			
			nowIndex += 1;
			
			if(nowIndex > 9)return;
			
			setTimeout(arguments.callee,50);
		}();
	},
	//根据时间戳，改变dom元素的颜色
	changeColor : function(content){
		
		var timespan = +content.timespan;
		
		if(timespan >= 60*1000 && timespan <= 10*60*1000){
			content.time.style.color = "#333";
		}else if(timespan < 60*1000 && timespan > 20*1000){
			content.time.style.color = "green";
		}else if(timespan <= 20 * 1000 && timespan > 0){
			content.time.style.color = "red";
		}
		
	},
	//多个拍品的列表页，修改对应的倒计时信息
	//content:一个json对象，在下面muliCountDown函数有定义，从那传过来
	//data:后台返回的json数据，对应某个拍品的倒计时数据
	//paiIds:拍品ID与最后修改时间的数组[2001|20123.23]
	modifyInfo : function(content,data,paiIds){
		//拍品暂停或结束，返回
		if(content.ispause || content.isover)return;
		//获取页面中旧的价格与最新的倒计时时间戳
		var old_price = +content.price.innerHTML.replace(/￥|,/g,""),
			timespan = (+data[1] > 0?+data[1]*1000:0);
		//恢复显示时间栏的时间
		content.time.className.indexOf('over')>0?content.time.className="time":"";
		//最后修改时间有变动，更新页面上的数据
		if(content.lastTime != data[5]){
			content.timespan = timespan;
			content.time.innerHTML = getTimeStamp(new Date(timespan));
			content.price.innerHTML = (+data[2]).rmb(true);
			content.user.innerHTML = data[3]||"--";
			content.lastTime = data[5];
			this.findArrById(paiIds,data[0].toString(),data[5]);
		}
		//否则，调用倒计时，只需要时间走动，其它不动
		else{
			this.updateTime(content);
			return false;
		}
		//拍品状态为进行中
		if(data[4] == "1")
		{
			//价格变动了，显示颜色渐变效果
			if(old_price != data[2])this.changeBgColor(content.price);
			this.changeColor(content);
		}
		//拍品状态为未开始
		else if(data[4] == "0")
		{
			content.btn.onclick = null;
			content.btn.className = content.overbtn;
		}
		//拍品状态为暂停中，以及记录在内存中的状态不为暂停，调用暂停函数
		else if(data[4] == "2" && !content.ispause){
			this.pauseBid(content);
		}
		//拍品状态为结束，以及记录在内存中的状态不为结束，调用多个拍品的结束函数
		else if(data[4] == "3" && !content.isover){
			this.muliTimeOver(content.time,content.btn,content.overbtn);
			content.isover=true;
		}
	},
	//更新倒计时，只是倒计时走动，其它不动
	updateTime : function(content){
		
		if(content.ispause || content.isover)return;
		
		var timespan = content.timespan - 1000;
		content.time.innerHTML = getTimeStamp(new Date(timespan<0?0:timespan));
		content.timespan = timespan;
		
		this.changeColor(content);

	},
	//多个拍品页面的结束函数
	muliTimeOver : function(time,btn,overbtn){
		
		time.className = "time over";
		btn.onclick = null;
		btn.className = overbtn;
	},
	//多个拍品页面异常处理拍品(禁用与恢复)
	exceptionBid : function(content, isRelease){
//ldh 2011-3-17 edit		
		for(var name in content){
			if(content.hasOwnProperty(name) && !content[name].ispause){
                /*
				    content[name].btn.onclick = null;
				    content[name].btn.className = content[name].overbtn;
                */
                var item = content[name];
                item.btn.style.display = isRelease ? '' : 'none';
                if (!item.errSpan) {
                    item.errSpan = item.btn.parentNode.appendChild(document.createElement('span'));
                    item.errSpan.innerHTML = '网络连接慢';
                    item.errSpan.style.cssText = 'color:#aaa;font-size:20px;height:32px';
                }
                item.errSpan.style.display= isRelease ? 'none' : 'block';
			}
		}
//ldh 2011-3-17 end
	},
	//多个拍品页面暂停拍品
	pauseBid : function(content){

		var temp = content.btn.parentNode;
		var dev =  _Base.Base_ServerTime|0;
		var now_time = new Date().toLocaleTimeString();
		if(now_time.length <=7)now_time = "0"+now_time;
		
		
		//
		if(Date.parse(new Date())-dev >= Date.parse(new Date(requestRule.pauseLong.startTime)) && Date.parse(new Date())-dev <= Date.parse(new Date(requestRule.pauseLong.endTime)) ){
			
			content.btn.parentNode.innerHTML = '<span class="pause_span">'+requestRule.pauseLong.startTime.change2Date().substr(0,9)+'&nbsp;暂停</span><br \>\
<span class="pause_span">'+requestRule.pauseLong.endTime.change2Date()+'&nbsp;继续</span>';
		}
		else{
		
			now_time =time2TimeStamp(now_time,now_time<requestRule.pause.endTime && requestRule.pause.endTime<requestRule.pause.startTime)-dev;
			
			if(now_time >=time2TimeStamp(requestRule.pause.startTime)-10*60000 && now_time <time2TimeStamp(requestRule.pause.endTime,requestRule.pause.endTime<requestRule.pause.startTime)+10*60000){
				content.btn.parentNode.innerHTML = '<span class="pause_span">'+requestRule.pause.startTime.substr(0,5)+'&nbsp;暂停</span><br \>\
	<span class="pause_span">'+requestRule.pause.endTime.substr(0,5)+'&nbsp;继续</span>';
			}
			else {
				content.btn.parentNode.innerHTML ='<span class="pause_span">故障暂停</span>';
			}
		}
		
		content.btn = temp;
		content.ispause=true;
	},
	//多个拍品页面恢复拍品的页面显示
	restoreBid : function(content,paiId){

		if(content.timespan <= 0)return;
		
		if(content.ispause){
//ldh 2011-3-17 edit
			content.btn.innerHTML = '<a class="'+content.overbtn.replace("over","pai")+'" href="javascript:;" hidefocus="true" onclick="bidPrice.call(this,'+paiId+')" style="text-decoration:none;">&nbsp;</a>';
			content.ispause=false;
			content.btn = content.btn.firstChild;
		}
		else if(!content.btn.onclick){
			content.btn.onclick = function(){bidPrice.call(this,paiId)};
			content.btn.className=content.btn.className.replace("over","");
		}
	},
	//列表倒计时，设计得通用，所以，参数就比较多
	//divId：最外层的div的ID
	//listParentTag：多个拍品的列表父级元素标签的className，多为ul
	//listTag：多个拍品的列表元素标签，多为li
	//time：时间标签的className
	//price：价格标签的className
	//user：用户标签的className
	//btn：出价按钮标签的className
	//overbtn：拍品结束时，按钮显示的className
	//paiId：拍品ID的标签className
	//lastTime：最后修改时间标签的className，这个不用的了，保留
	//callback：回调函数，当所有拍品都结束时调用
	muliCountDown : function(divId,listParentTag,listTag,time,price,user,btn,overbtn,paiId,lastTime,callback){
		//querys参数数组，lis为拍品的列表，paiIds为拍品ID的数组，content为保存所有拍品信息的对象
		var querys=[],A=arguments,lis=[],paiIds=[],content={},i,l,This = this,paiId;
		//如果是单个列表
		if(typeof divId == 'string'){
			querys = [{
				div:divId,
				ul:listParentTag,
				li:listTag,
				time:time,
				price:price,
				user:user,
				btn:btn,
				overbtn:overbtn,
				paiId:paiId,
				lastTime:lastTime}];
		}
		//或者是多个列表
		else {
			for(i=0,l=A.length;i<l;i++){querys.push(A[i]);}
			callback = A[0].callback;
		}
		//遍历参数列表
		for(i=0,l=querys.length;i<l;i++){
			//获取拍品列表
			lis = Y.get("#"+querys[i].div+" ."+querys[i].ul+" "+querys[i].li);
			//遍历拍品列表，ID为key，拍品的具体信息为value形式插入到content对象中，以及将拍品id插入到paiIds数组中。
			for(var k=0,ls=lis.length;k<ls;k++){
			
				paiId = this.getByClass(lis[k],querys[i].paiId);
				
				if(!paiId)continue;
				
				paiId = paiId.innerHTML;
				
				var price_dom = This.getByClass(lis[k],querys[i].price);
				content[paiId] = {
					time : This.getByClass(lis[k],querys[i].time),
					price : price_dom.getElementsByTagName('*').length?price_dom.getElementsByTagName('*')[0]:price_dom,
					user : This.getByClass(lis[k],querys[i].user),
					btn : This.getByClass(lis[k],querys[i].btn).firstChild,
					overbtn : querys[i].overbtn,
					lastTime:'',
					timespan : 0,
					ispause:false,
					isover:false
				}
				
				content[paiId].btn.onclick = function(paiId){return function(){bidPrice.call(this,paiId);}}(paiId);
				
				paiIds.push(paiId+"|"+content[paiId].lastTime);
			}
		}
		//不存在拍品，退出
		if(paiIds.length == 0)return;
		//获取多个拍品的请求配置,countTime为请求时间,isrequest为是否请求
		var rule = requestRule.muli,countTime = 0,isrequest=false;
		//处理拍品倒计时
		function process(){
			//当前时间戳
			var now_time =time2TimeStamp(new Date().toLocaleTimeString());
			
			if(countTime <= 0)
			{
				//判断当前时间戳在哪个范围中
				for(var i=0,l=rule.length;i<l;i++){
					
					if(now_time >=time2TimeStamp(rule[i].startTime) && now_time <time2TimeStamp(rule[i].endTime,rule[i].endTime<rule[i].startTime)){
					
						countTime = (+rule[i].request_fz)-1000;
						isrequest=true;
						break;
					}
				}
				//配置默认值
				if(i==rule.length){
					countTime = (+rule[i-1].request_fz)-1000;
					isrequest=true;
				}
			}
			else if(!This.muliStop){
				//更新时间
				for(var name in content){
					if(content.hasOwnProperty(name)){
						This.updateTime(content[name]);
					}
				}
				countTime -= 1000;
			}
			//满足请求后台数据条件
			if((isrequest || This.hasBid) && !This.muliStop)
			{
				isrequest=false;
				This.hasBid=false;
				
				//ping
				Pings.start('getAuctionInfo');
				
				Y.ajax(_Base.Base_Url+'/ajax/ajax.php?action=getAuctionInfo',function(data){
					
					//ping
					Pings.end('getAuctionInfo');
//ldh 2011-3-17 edit					
					try
					{
						data = String2Json(data.text);
					}
					catch(e){//异常处理
						This.exceptionBid(content);
                        requestRule.netException = true;
                        requestRule.oldCountTime = countTime;
						countTime = 5*1000;
						return false;
					}
                    //恢复异常状态
                    if (requestRule.netException) {
                        requestRule.netException = false;
                        This.exceptionBid(content, true);
                        countTime = requestRule.oldCountTime;
                    }
//ldh edit end
					//状态小于0，有错误,errorCode为errorCode.js
					if(+data.status < 0){
						return errorCode(data.status,data.msg);
					}
					else {
						//状态为1，代表数据有更新
						if(data.status === 1){
							
							data = data.content;
							for(var i=0,l=data.length;i<l;i++){
								if(data[i][4] == "1"){
									This.restoreBid(content[data[i][0]],data[i][0]);
									content[data[i][0]].isover=false;
								}
								This.modifyInfo(content[data[i][0]],data[i],paiIds);
								//if(data[i][4] == "1")This.restoreBid(content[data[i][0]],data[i][0]);
								
							}
						}
						//状态为2，代表全站暂停
						else if(data.status === 2){
							
							countTime = 60*1000;
							return false;
						}
						
						data = data.content?data.content:data;
						//更新后台没有发过来的需要更新的倒计时
						for(var name in content){
							if(content.hasOwnProperty(name)&& !This.findArrByKey(data,name)){
								This.updateTime(content[name]);
							}
						}
					}

				},{paiId:paiIds.join(','),_t:Math.random()},'GET');
			}
			var isover = true;
			
			for(var k in content){
				if(content[k].isover == false){
					isover=false;
					break;
				}
			}
			
			if(!isover)setTimeout(function(){process();},1000);
			else callback && callback();
		}
		process();
		//调用列表倒计时的系统函数
		this.muliSysFn(true);
	},
	//详细页面的倒计时
	singleCountDown : function(divId){
		
		var This = this;
		//初始化
		var single_data = {
			
			paiId : Y.one("#"+divId + " .paiId").innerHTML,
			price : Y.one("#"+divId+" .price"),
			user : Y.one("#"+divId+" .user"),
			time_w : Y.one("#"+divId+" .time_w"),
			time : Y.one("#"+divId+" .time"),
			btn : Y.one("#"+divId + " .btn").firstChild,
			lastTime : '',
			ispause : false,
			isover : false,
			timespan : null
		}
		//添加timeTips的元素在页面
		var timeTips = single_data.time_w.firstChild.className.indexOf('timeTips')>=0?single_data.time_w.firstChild:function(){
							var temp = document.createElement('div');
							temp.className = 'timeTips';
							temp.style.visibility = 'hidden';
							single_data.time_w.insertBefore(temp,single_data.time_w.firstChild);
							return temp;
						}();
		
		single_data['timeTips'] = timeTips;
		//--
		//绑定出价事件
		single_data.btn.onclick = function(){bidPrice.call(this,single_data.paiId);};
		//获取单个拍品的请求配置
		var rule = requestRule.single,countTime = 0,isrequest=true,old_price;
		//倒计时处理函数
		var process = function(){
			//请求频率小于0而且请求标志为false
			if(countTime <= 0 && !isrequest){
				//遍历当前拍品剩余时间戳在哪个配置范围内
				for(var i=0,l=rule.length;i<l;i++){
					
					if(single_data.timespan >= +rule[i].startTime && single_data.timespan < (+rule[i].endTime?rule[i].endTime:Number.MAX_VALUE)){
						countTime = (+rule[i].request_fz)-1000;
						isrequest=true;
						break;
					}
				}
				//设置默认
				if(i == rule.length){
					countTime = (+rule[i-1].request_fz)-1000;
					isrequest=true;
				}
			}
			else if(!isrequest){
			
				if(!single_data.ispause && !This.muliStop)
				{
					//更新倒计时
					This.singleUpdateTime(single_data);
					//更新单个拍品的倒计时相关信息
					This.updataSingle(single_data);
				}
				countTime -= 1000;
			}
			//同步后台数据
			if((isrequest || This.hasBid) && !This.muliStop){
				isrequest=false;
				This.hasBid=false;
				
				//ping start
				Pings.start('getAuctionInfo');
				
				Y.ajax(_Base.Base_Url+'/ajax/ajax.php?action=getAuctionInfo',function(data){
					
					//ping end
					Pings.end('getAuctionInfo');
					
					try
					{
						data = String2Json(data.text);
					}
					catch(e){
						if(single_data.ispause)return;
						countTime = 5*1000;
						return false;
					}
					
					if(data.msg){
						single_data.ispause=true;
						return alertMsg.pop(data.msg);
					}
					
					//状态为1，即数据有更新
					if(data.status === 1){
						data = data.content[0];
						
						old_price = single_data.price.innerHTML.replace(/,|￥/g,"")?+single_data.price.innerHTML.replace(/,|￥/g,""):'-1';
						
						if(!single_data.ispause && old_price != +data[2]){
							setTimeout(function(){reloadUserList(single_data.paiId)},0);
							
							//if(tp && old_price != +data[2])This.showPaiTips(0,(+data[2] - old_price).toFixed(2),+data[1]*1000-+time.getAttribute('timespan'),timeTips);
						}

						if(!single_data.timespan)setTimeout(function(){reloadPaiSave()},0);
						//是否更新数据
						if(!single_data.ispause && single_data.lastTime != data[5]){This.singleModify(single_data,data);reComputePaiSave(data[2]);}
						else This.singleUpdateTime(single_data);
						
						//恢复
						if(data[4] == "1"){
							if(single_data.ispause){
								single_data.ispause=false;
								single_data.btn.className = "btn";
								single_data.btn.innerHTML = '<a class="btn_pai_b" href="javascript:;" hidefocus="true" \
								onclick="bidPrice.call(this,'+single_data.paiId+');">出价</a>';
								single_data.btn = single_data.btn.firstChild;
								This.restoreRebot();
							}
							else if(single_data.btn.className == "btn_pai_bover" && +data[1]>=0){
								single_data.btn.className = "btn_pai_b";
								single_data.btn.onclick = function(){single_data.bidPrice.call(this,single_data.paiId);};
							}
							if(old_price != +data[2]){
								This.changeBgColor(single_data.time);
							}
						}
						//暂停
						else if(data[4] == "2"){
						
							This.singlePause(single_data);
							countTime = 5*1000;
						}
						//结束
						else if(data[4]=="3"){
							single_data.isover = true;
							This.disabledRebot();
						}
						
					}
					//状态为0，即数据没更新
					else if(data.status === 0){
						if(!ispause){
							
							This.singleUpdateTime(single_data);
						}
					}
					//状态为2，全站暂停
					else if(data.status === 2){
						countTime = 60*1000;
						return false;
					}
					
					if(!single_data.ispause)setTimeout(function(){This.updataSingle(single_data)},50);
					
				},{paiId:single_data.paiId+"|"+single_data.lastTime,flag:true,_t:Math.random()},"GET");
			}

			if(single_data.isover == false)setTimeout(function(){process();},1000);
			
		}
		process();
		
		//调用列表倒计时的系统函数
		this.muliSysFn(true);
	},
	//单个拍品暂停
	singlePause : function(single_data){
	
		if(single_data.ispause)return false;
		
		var temp = single_data.btn.parentNode;
		var dev = _Base.Base_ServerTime || 0;
		
		var now_time = new Date().toLocaleTimeString();
		if(now_time.length <=7)now_time = "0"+now_time;
		
		if(Date.parse(new Date()) -dev >= Date.parse(new Date(requestRule.pauseLong.startTime)) && Date.parse(new Date())-dev <= Date.parse(new Date(requestRule.pauseLong.endTime)) ){
			
			single_data.btn.parentNode.innerHTML = '<span class="pause_span">'+requestRule.pauseLong.startTime.change2Date()+'&nbsp;暂停</span><br \>\
<span class="pause_span">'+requestRule.pauseLong.endTime.change2Date()+'&nbsp;继续</span>';
		}
		else{
		
			now_time =time2TimeStamp(now_time,now_time<requestRule.pause.endTime && requestRule.pause.endTime<requestRule.pause.startTime) -dev;
			
			if(now_time >=time2TimeStamp(requestRule.pause.startTime)-10*60000 && now_time <time2TimeStamp(requestRule.pause.endTime,requestRule.pause.endTime<requestRule.pause.startTime)+10*60000){
				single_data.btn.parentNode.innerHTML = '<span class="pause_span">'+requestRule.pause.startTime.substr(0,5)+'&nbsp;暂停</span><br \>\
	<span class="pause_span">'+requestRule.pause.endTime.substr(0,5)+'&nbsp;继续</span>';
			}
			else {
				single_data.btn.parentNode.className = 'buyStop';
				single_data.btn.parentNode.innerHTML = '<div class="buyStotBg">\
					<div class="buyStotInfo red"> 故障暂停，给您造成的不便，请谅解\
					网站恢复时，倒数时间增加20分钟 </div>\
					</div>';
			}
		}

		this.disabledRebot();
		
		single_data.ispause = true;
		single_data.btn = temp;
	},
	//单个拍品页面，禁用助理
	disabledRebot:function(){

		var inputs = Y.get("#robot input");
		for(var i=0,l=inputs.length;i<l;i++){
			inputs[i].disabled='disabled';
		}
	},
	//单个拍品页面，恢复助理
	restoreRebot:function(){
		var inputs = Y.get("#robot input");
		inputs.each(function(item,index){item.disabled='';});
	},
	//单个拍品更新倒计时
	singleUpdateTime : function(single_data){
		
		if(single_data.ispause || single_data.isover)return;
		
		var timespan = (single_data.timespan - 1000 >= 0?single_data.timespan-1000:0);
		single_data.time.lastChild.innerHTML = getTimeStamp(new Date(timespan));
		single_data.timespan -= 1000;
	},
	//单个拍品更新倒计时的相关信息
	singleModify : function(single_data,data){
		var timespan = (+data[1]>0)?(+data[1] * 1000):0;
		single_data.timespan = +data[1]*1000;
		single_data.time.lastChild.innerHTML = getTimeStamp(new Date(timespan));
		single_data.price.innerHTML = (+data[2]).rmb(true);
		single_data.user.innerHTML = (data[3]||"--") +(data[6]==2?"(助理)":"");
		single_data.lastTime = data[5];
		
	},
	//单个拍品的提示结束信息
	flashTips : function(){
		
		var flashId = 0;
		
		var process = function(single_data,time){
			if(flashId)return;
			if(time){
				clearTimeout(flashId);
				single_data.timeTips.style.visibility = 'hidden';
			}
			
			single_data.timeTips.style.visibility = '';
			
			flashId = setTimeout(function(){
			
				if(single_data.timeTips.className != 'timeTips_over')return;
				if(time)return;
			
				if(+single_data.timespan > 20*1000 || +single_data.timespan  < 0){clearTimeout(flashId);single_data.timeTips.style.visibility = 'hidden';return false;}
				
				Y.fadeOut(single_data.timeTips);
				
				//single_data.timeTips.style.visibility = (single_data.timeTips.style.visibility=="hidden"?"":"hidden");
			},2000);
		}
		return process;
	}(),
	//单个拍品的提示拍点信息
	showPaiTips : function(){
		
		var flashId = 0;
		
		var process = function(painum,price,time,timeTips){
			
			clearTimeout(flashId);
			countDown.flashTips(timeTips,null);
			
			time = time<=0?0:time;
			
			timeTips.className = "timeTips";
			timeTips.style.visibility = "";
			timeTips.innerHTML = Math.floor(price*100)+"个拍点+"+(+price).rmb(true)+" + "+getTimeStamp(new Date(time));
			
			flashId = setTimeout(function(){timeTips.style.visibility="hidden";},2500);
		}
		return process;
	}(),
	//更新单个拍品的效果处理以及结束与否等
	updataSingle : function(single_data){
	
		//时间少于20秒且大于0
		if(single_data.timespan <= 20*1000 && single_data.timespan >=0){
			if((single_data.timeTips.className == "timeTips" && single_data.timeTips.style.visibility == "hidden") || single_data.timeTips.className == "timeTips_over"){
			
				single_data.timeTips.className = "timeTips_over";
				//提示效果
				this.flashTips(single_data);
			}
			
			single_data.time.className.indexOf("nomal")>=0?(single_data.time.className = "time"):"";
			
			var temp = single_data.timespan-1000>=0?single_data.timespan-1000:-1;
			if(temp >=0 && temp < 10000){
				//temp = ((temp+1000)/1000)<10?("0"+((temp+1000)/1000)):((temp+1000)/1000);
				//single_data.time.lastChild.innerHTML = "00:00:<span>"+temp+"</span>";
				this.daojishi(single_data);
			}
			else if(temp >= 10000){
				temp += 1000;
				temp = temp/1000<10?("0"+temp/1000):temp/1000;
				single_data.time.lastChild.innerHTML = "00:00:<span>"+temp+"</span>";
			}
			else single_data.time.lastChild.innerHTML = "00:00:<span>00</span>";
			
		}
		//时间大于20秒
		else if(single_data.timespan > 20*1000){

			single_data.time.className.indexOf("nomal")<0?single_data.time.className = "time nomal":"";
		}
		
		if(single_data.isover){
			single_data.timeTips.style.visibility = "hidden";
			single_data.time.className = "time over";
			single_data.btn.className = 'btn_pai_bover';
			single_data.btn.onclick = function(){return false;};
			
			var callback = function(){
				window.location.reload();
			}
			setTimeout(callback,5000);
		}
	},
	//显示毫秒，单个拍品
	daojishi : function(){
		
		var jishiId = 0;
		
		var process = function(single_data,flag){
			
			if(flag){
				clearInterval(jishiId);
				jishiId = 0;
				return false;
			}
			
			if(jishiId){
				clearInterval(jishiId);
				jishiId = 0;
			}
			
			var count = 9;
			
			jishiId = setInterval(function(){
				
				var temp = single_data.timespan-1000;
				
				if(temp >= 10000 || temp < 0){
					clearInterval(jishiId);
					jishiId = 0;
					return false;
				}
				
				temp = temp/1000<10?("0"+temp/1000):temp/1000;
				
				single_data.time.lastChild.innerHTML = "00:00:<span>"+temp+"</span><label>."+count+"</label>";
				
				count--;
				
				if(count <0){
					clearInterval(jishiId);
					jishiId= 0;
					count = 9;
					return false;
				}
				
			},90);
			
		}
		return process;
	}()
	
}

//根据时间戳，获取日期
function getTimeStamp(d)
{
    var s,hours=(d.getUTCDate()-1)*24 + d.getUTCHours();
	
    s = ("0"+hours).slice(hours.toString().length==3?-3:-2) + ":";
    s += ("0"+d.getUTCMinutes()).slice(-2) + ":";
    s += ("0"+d.getUTCSeconds()).slice(-2);

    return s;
}
//根据日期，获取时间戳
function time2TimeStamp(time,flag){
	
	return flag?Date.parse(new Date("1970/01/02 "+time))+28800000:Date.parse(new Date("1970/01/01 "+time))+28800000;
	
}
//出价事件
function bidPrice(paiId,isredirect){
	
	if(this.disabled)return;
	
	if(window.data.username == "NOT_LOGIN"){
		return login();
	}
	
	//if(+Y.one("#head_bidpoint").innerHTML <= 0){
		//return errorCode(-11008);
	//}
	//弹出窗口中，暂停出价
	if(countDown.muliStop)return;
	
	//出价后，重新列表计时
	countDown.muli_showwindow();
	
	var self = this;
	self.disabled = 'disabled';
	
	Y.ajax(_Base.Base_Url+"/ajax/ajax.php?action=bid",function(_data){
	
		self.disabled = '';
		bidPriceEffect(self);
	
		try
		{
			_data = String2Json(_data.text);
		}
		catch(e){return false;}
		
		if(_data.status < 0){
			
			return errorCode(_data.status,_data.msg,_data.data);
		}
		else if(_data.status == 0){
			countDown.hasBid=true;
			
			_data = _data.data;
			
			if(_data.flag){
				reloadPaiSave(_data);
			}
			else{
				reloadPai(_data);
			}
		}
	},{pid:paiId,flag:Y.get("#mypainum").length,t:Math.random()},"POST");
	
	return false;
}
//出价成功后的效果,震动
function bidPriceEffect(btn){
	
	var time=6;
	
	function process(){
		
		time -= 1;
		if(time > 0){
			btn.style.marginLeft = (4*(time%2==0?1:-1))+'px';
			setTimeout(process,10);
		}
		else btn.style.margin = "0";
	}
	process();
}

//加载用户竞拍记录
function reloadUserList(paiId){
	
	var tableRecord = Y.get("#cjTable tbody")[0] || Y.one("#cjTable");
	
	
	//ping start
	Pings.start('getList');
	
	Y.ajax(_Base.Base_Url+'/ajax/ajax.php?action=getList',function(data){
	
		Pings.end('getList');
	
		try{
			data = String2Json(data.text);
		}
		catch(e){return alertMsg.pop("服务器繁忙，请稍后重试！");}
		
		if(data.status< 0){
			return errorCode(data.status,data.msg);
		}
		
		data = data.data;
	
		while(tableRecord.rows[1]){tableRecord.removeChild(tableRecord.rows[1]);}
	
		var record = data.record,
			tr,td,df; 
		
		df = document.createDocumentFragment();
		//遍历用户竞拍记录
		for(var i=0,l=record.length;i<l;i++){
			
			tr = document.createElement('tr');
			(i%2!=0) && (tr.className = 'tr2');
			
			td = document.createElement('td');
			td.align = 'right';
			td.appendChild(document.createTextNode(Number(record[i].ctprice).rmb(true)));
			tr.appendChild(td);
			
			td = document.createElement('td');
			td.align = 'left';
			td.className = "td";
			td.title = record[i].username;
			td.appendChild(document.createTextNode(cutString(record[i].username,22,record[i].bidtype == 2)));
			tr.appendChild(td);
			
			df.appendChild(tr);
			
			if(i==0){
				
				//当前价格改变，击发事件
				if(typeof(eventPriceChange) !='undefined')
				{
					eventPriceChange(record[i].ctprice);
					
				}
				
				Y.one("#nowPrice").innerHTML = Number(record[i].ctprice).rmb(true);
				Y.one("#js_user").innerHTML = record[i].username+(record[i].bidtype == 2?"(助理)":"");
			}
		}
		tableRecord.appendChild(df);
		
	},{paiId:paiId,_t:Math.random()},"GET");
}

//加载最新用户
function reloadLastUser(paiId){
	
	var tableUser = Y.get("#cjTable2 tbody")[0] || Y.one("#cjTable2");
	
	Y.ajax(_Base.Base_Url+'/ajax/ajax.php?action=getUser',function(data){
	
		try{
			data = String2Json(data.text);
		}
		catch(e){return alertMsg.pop("服务器繁忙，请稍后重试！");}
		
		if(data.status < 0){
			return errorCode(data.status,data.msg);
		}
		
		data = data.data;
	
		while(tableUser.rows[1]){tableUser.removeChild(tableUser.rows[1]);}
	
		var userlist = data.user,
			tr,td,df;
		
		df = document.createDocumentFragment();
		
		//遍历最新用户
		for(i=0,l=userlist.length;i<l;i+=2){
			
			tr = document.createElement('tr');
			(i%4!=0) && (tr.className = 'tr2');
			
			td = document.createElement('td');
			td.align = 'left';
			td.appendChild(document.createTextNode(userlist[i].username));
			tr.appendChild(td);
			
			if(userlist[i+1])
			{
			td = document.createElement('td');
			td.align = 'left';
			td.appendChild(document.createTextNode(userlist[i+1].username));
			tr.appendChild(td);
			}
			
			df.appendChild(tr);
		}
		tableUser.appendChild(df);
		
		Y.one("#js_total_user").innerHTML = (userlist.length>14?14:userlist.length);
		
	},{paiId:paiId,_t:Math.random()},"GET");
}
//获取字符串的实际长度，包含中文的
function getStringLength(string){
	
	var chinese = string.match(/[\u4E00-\u9FA5]/g);
	
	var chineseLength = chinese?chinese.length:0;
    return (string.length-chineseLength)+(chineseLength)*2;
}
//裁剪字符串
function cutString(string,count,flag){
	
	if(flag)count = count - 6;
	
	while(getStringLength(string) >= count){
		
		string = string.substr(0,string.length-1);
	}
	return string + (flag?"(助理)":"");
}

//to json
var String2Json = function(){};
~function(){
	
	if(navigator.userAgent.toLowerCase().indexOf('msie') >=0){
		String2Json=function(string){return eval('('+string+')');}
	}
	else{
		String2Json = function(string){
			var fn = new Function('return '+string.trim());
			return fn();
		}
	}
	
}();
//重新加载单个拍品的节省钱信息
function reloadPaiSave(_data){

	var paiId = Y.one("#paiId").value,
		nowPrice = Y.one("#nowPrice").innerHTML.replace(/,|￥/g,""),
		goodscost = Y.one("#goodscost"),
		mypainum = Y.one("#mypainum"),
		mypaiprice = Y.one("#mypaiprice"),
		currentprice = Y.one("#currentprice"),
		saveprice = Y.one("#saveprice strong");
	
	if(window.data.username == "NOT_LOGIN"){
		
		saveprice.innerHTML  = Number(+goodscost.getAttribute("goodsvalue")-(+nowPrice)).rmb(true);
	}
	else{
		
		if(_data){
			mypainum.innerHTML = _data.bidpoint;
			mypaiprice.innerHTML = (+_data.bidpoint * +_data.perpoint).rmb(true);
			saveprice.innerHTML = Number(+goodscost.getAttribute("goodsvalue")-(+nowPrice)-(+_data.bidpoint * +_data.perpoint)).rmb(true);
				
			Y.one("#head_bidpoint").innerHTML = Y.one("#body_bidpoint").innerHTML = _data.nowbidpoint;
		}
		else{
		
			Y.ajax(_Base.Base_Url+'/ajax/ajax.php?action=getUserConsumed',function(_data){
				
				try{
					_data = String2Json(_data.text);
				}
				catch(e){return alertMsg.pop("服务器繁忙，请稍后重试！");}
				
				if(_data.msg){
					return alertMsg.pop(_data.msg);
				}
				else
				{
					_data = _data.data;
					mypainum.innerHTML = _data.bidpoint;
					mypaiprice.innerHTML = (+_data.bidpoint * +_data.perpoint).rmb(true);
					saveprice.innerHTML = Number(+goodscost.getAttribute("goodsvalue")-(+nowPrice)-(+_data.bidpoint * +_data.perpoint)).rmb(true);
					
					Y.one("#head_bidpoint").innerHTML = Y.one("#body_bidpoint").innerHTML = _data.nowbidpoint;
				}
				
			},{paiId:paiId,_t:Math.random()},"GET");
		}
	}
	
	goodscost.innerHTML = Number(goodscost.getAttribute("goodsvalue")).rmb(true);
	currentprice.innerHTML = (+nowPrice).rmb(true);
}
//重新计算用户节省的信息
function reComputePaiSave(nowPrice){
	
	var saveprice = Y.one("#saveprice strong"),
		currentprice = Y.one("#currentprice"),
		goodscost = Y.one("#goodscost"),
		mypaiprice = Y.one("#mypaiprice").innerHTML.replace(/,|￥/g,"");
	
	saveprice.innerHTML = Number(+goodscost.getAttribute("goodsvalue")-(+nowPrice)-(+mypaiprice)).rmb(true);
	currentprice.innerHTML = (+nowPrice).rmb(true);
	
}
//加载用户的拍点信息
function reloadPai(_data){
	
	Y.one("#head_bidpoint").innerHTML = +_data.bidpoint + +_data.prebidpoint;
	(Y.get("#body_bidpoint").length) && (Y.one("#body_bidpoint").innerHTML = +_data.bidpoint + +_data.prebidpoint);
	if(Y.get("#js_totalbidpoint").length){
		Y.one("#js_totalbidpoint").innerHTML = +_data.bidpoint + +_data.prebidpoint;
		Y.one("#js_bidpoint").innerHTML = _data.bidpoint;
		Y.one("#js_prebidpoint").innerHTML = _data.prebidpoint;
	}
}

