﻿var flashtimer=null;
var img = new Image();
img.src="/pic/btnred.gif";
function Select_Before(){draw();Hot.set($("cart_total"),230,300);}
function mychoose(num,price){
	var sid=$("server")?$("server").value:myserverid;
	cart_type="Gold";
	cart_game=gid;
	if(cart_key!=sid+"-"+tid){
		cart={};
		cart_key=sid+"-"+tid;
		cart_server=$("goldserver").innerHTML;
	}
	var key=cart_key+"-"+num,o=cart[key];
	if(!o) o=cart[key]={count:0,price:0};
	o.sid=sid;
	o.tid=tid;
	o.count++;
	o.num=num;
	o.item=gitem;
	o.price+=price;
	save();
	draw(key);
	$("curflag").scrollIntoView();
	if(flashtimer==null) flashtimer=setInterval("flashbtn()",500);
	Hot.set($("goldnow"),230,300);
}
function flashbtn(){
	var o=$("checkbtn"),num=0;
	for(var e in cart){num++;break;}
	if(num==0){
		o.style.backgroundImage="url(/pic/btn.gif)";
		o.style.borderWidth="1px";
		o.style.borderStyle="solid";
		o.style.borderColor="black";
		o.style.color="black";
		clearInterval(flashtimer);
	}
	else{
		if(o.style.color!="red"){
			o.style.backgroundImage="url(/pic/btnred.gif)";
			o.style.borderWidth="1px";
			o.style.borderStyle="solid";
			o.style.borderColor="red";
			o.style.color="red";
		}
		else{
			o.style.backgroundImage="url(/pic/btn.gif)";
			o.style.borderWidth="1px";
			o.style.borderStyle="solid";
			o.style.borderColor="black";
			o.style.color="black";
		}
	}
}
function bar(n,v){
	var o=$(n),td=$$(o,"TD");
	if(isNaN(v))v=0;
	for(var i=0;i<td.length;i++){
		if(i<v) td[i].style.background=td[i].getAttribute("old");
		else td[i].style.background="#ccc";
	}
}
function listcolor(){
	var tr=$$($("list"),"TR");
	for(var i=0;i<tr.length;i++){
		tr[i].onmouseover=function(){
			this.bgColor="#CEE2FD";
		}
		tr[i].onmouseout=function(){
			this.bgColor="white";
		}
	}
}
function set_server(ev){
	document.body.focus();
	var a=$("server");
	var av=a?a.value:myserverid;
	if($("tab2")){
		var l=$$("tab2","A");
		for(var i=0;i<l.length;i++){
			l[i].href=l[i].href.replace(/s\d+/g,"s"+av);
		}
	}
	var m=money[av][tid],p=percent[gid],s=[],r=rate[currency];
	for(var e in p){
		var price=format(e/gnum*m*p[e]),tmp=format(price/r[0]);
		s.push("<tr>");
		s.push("<td nowrap><b style='color: #999'>"+gkey+" "+gcur+"</b></td>");
		s[s.length]="<td align=right width=60><b style='color:#0C4C8E'>"+e+"</b></td>";
		s[s.length]="<td width=100 nowrap><b style='color:#0C4C8E'>"+gitem+"</b></td>";
		s[s.length]="<td width=70 align=right><b>"+r[1]+" "+tmp+"</b></td>";
		s[s.length]="<td align=right width=110><input type=button onClick=\"mychoose("+e+","+price+")\" value='Add to cart' class=btn style='width:100px'></td></tr>";
	}
	$("list").innerHTML="<table width=100% cellspacing=0 cellpadding=2>"+s.join("")+"</table>";
	listcolor();
	var sname=gname;
	if(a&&a.length>1){
		sname+=" - "+a.options[a.selectedIndex].text;
		var stock=a.options[a.selectedIndex].getAttribute("stock"),hour=a.options[a.selectedIndex].getAttribute("hour");
		$("mystock").innerHTML=stock;
		$("myspeed").innerHTML=hour;
		bar("tblstock",parseInt(stock)/4500);
		bar("tblspeed",12-(parseInt(hour)/10));
	}
	if(tcount>1) sname+=" - " + tname;
		
	$("goldserver").text=$("goldserver").innerHTML=sname;
	setTimeout("Hot.set($('goldserver'),500,200)",50);
	cart={};
	Cookie.set("cart","");
	draw();
}
