// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var TIMEINTER = null ;
var GDS_IDS = null ;//商品刷新id列表
var GDS_DTL = null ;//商品id详情
var RQDATA = null ;//商品取得的数据
var BIDSDT = null ;//出价详细数据
var TLKDT = null ;//商品聊天记录
var TLKSTART = false ;//聊天刷新功能
var TLKRQLOCK = false ;//聊天刷新数据锁定开关，当一个进程请求的时候锁定，禁止其他进程请求

var Notice = {};

Notice = {
	show: function(eleid,info){
		if($(eleid)){
			$(eleid).innerHTML = info ;
			Element.show(eleid);
			setTimeout('Effect.Fade("'+eleid+'");',1000);
		}
	}
};


//刷新商品信息功能代码
window.onload = function(){
	if(GDS_IDS||GDS_DTL){
		TIMEINTER = setInterval("req_goods();",1000);
	}
};

function req_goods(){
	var pars = "";
  //# ids=622,623,625,626,620_dtl=620_lbid=333938_tk=0
	//如果普通列表页面存在值则goods_ids应该存在值
	if(GDS_IDS){
		pars += "_ids="+GDS_IDS ;
	}
	//如果产品详细信息页面则goods_detail应该存在值
	if(GDS_DTL){
		pars += "_dtl="+GDS_DTL;
		lbdid = 0;
		if(BIDSDT){
			lbdid = BIDSDT[0].i;
		}
		pars += "_lbid="+lbdid;
		//处理聊天信息参数
		if( TLKSTART && (!TLKRQLOCK) ){
			ltkid = 0;
			if(TLKDT){
				ltkid = TLKDT[TLKDT.length-1].i;
			}
			pars += "_tk="+ltkid;
		}
	}
	if(pars==""){
		return false;
	}else{
		pars = pars.substring(1)
	}
//	alert(pars);
	//锁定聊天功能
	TLKRQLOCK = true ;
	var url = '/goods_status/' + pars ;//+ '.html?'+ Math.random();
	new Ajax.Request(url,{method:"get",parapmeters:pars,onComplete:show_goods_bid_info});
	return false;
}

function show_goods_bid_info(rq){
	var str = rq.responseText;
	var o = eval('('+str+')');
	if(o){
		for(i=0;i<o.g.length;i++){

			$("gdstime_"+o.g[i].i).innerHTML = formate(o.g[i].t) ;
			if(o.g[i].t<=10){
				$("gdstime_"+o.g[i].i).style.color = "#DD0000" ;
			}else{
				$("gdstime_"+o.g[i].i).style.color = "#000000" ;
			}
			if($("gdsprice_"+o.g[i].i).innerHTML!="¥"+o.g[i].p){
				new Effect.Highlight("gdsprice_"+o.g[i].i,{startcolor:'#ff0000',endcolor: '#ffffff'} )
			}
			$("gdsprice_"+o.g[i].i).innerHTML = "¥"+o.g[i].p ;
			if(o.g[i].m=="0"){
				$("gdsmember_"+o.g[i].i).innerHTML = "<a href=\"#temp\">暂无</a>" ;
			}else{
				$("gdsmember_"+o.g[i].i).innerHTML = "<a href=\"#temp\">"+o.g[i].m+"</a>" ;
			}
		}
		if(o.b){
			BIDSDT = o.b ; //赋值新的请求对象数据
			var bids_html = "" ;
			var ass = "";
			for(i=0;i<o.b.length;i++){
				ass = o.b[i].a==0 ? "普通出价" : "有拍秘书"
				bids_html += '<tr><td>'+o.b[i].m+'</td><td>¥'+o.b[i].p+'</td><td>'+ass+'</td></tr>'
			}
			bids_html = '<table><tr class="title"><td class="title_a">出价人</td><td class="title_b">价格</td><td class="title_c">出价方式</td></tr>'
							+bids_html+'</table>';
			if($("goods_bids_table"))
				$("goods_bids_table").innerHTML = bids_html ;
		}
		if(o.t){
			var lts_tk_id = 0;
			if(TLKDT){
				lts_tk_id = TLKDT[TLKDT.length-1].i
			}
			if(o.t[0].i>lts_tk_id){
				TLKDT = o.t ;//赋值新的聊天数据对象
				var talk_html = "";
				for(i=0;i<o.t.length;i++){
					talk_html += '<li id="tkmsg_'+o.t[i].i+'"><span>'+o.t[i].m+'</span>:'+o.t[i].s+'</li>';
				}
				var tk_el = $("talk-msg-list") ;
				if(tk_el){
					tk_el.innerHTML += talk_html;
					//$('tkmsg_'+o.t[o.t.length-1]).focus();
					//alert($("talk-list").scrollHeight);
					$("talk-list").scrollTop = $("talk-list").scrollHeight;
				}
			}
		}
		//解除聊天刷新锁
		TLKRQLOCK = false ;
	}
//	alert(str);
}

function formate(time_length){
	var hour = time_length/3600|0;
	var min = (time_length%3600)/60|0;
	var sec = (time_length%3600)%60;
	if(hour<10){
		hour = "0"+hour;
	}
	if(min<10){
		min = "0"+min;
	}
	if(sec<10){
		sec = "0"+sec;
	}
	return hour+":"+min+":"+sec;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
