﻿function showGame(obj,dwidth)
	{
		var p= posi(obj);
		var two = document.getElementById('showgame');
		if(!document.all){			
			two.style.top=p.t+p.h+"px";
			two.style.left=p.l+"px";
		}else{			
			two.style.top=p.t+p.h+"px";
			two.style.left=p.l+1+"px"; 
		}
		document.getElementById('showgame').style.display=document.getElementById('showgame').style.display=='' ? 'none' : '';
		if((dwidth*5)<160)
			dwidth=160;
		else
			dwidth=dwidth*5;			
		
		document.getElementById('showgame').style.width=dwidth+'px';
		document.getElementById('showServer').style.display='none';		
		document.getElementById('showProduct').style.display='none';	
	}
	function showServer(obj)
	{
		var p= posi(obj);
		var two = document.getElementById('showServer');
		if(document.getElementById('GameNameListID').value>0)
		{
			document.getElementById('showServer').style.display=document.getElementById('showServer').style.display==''?'none':'';
			if(!document.all){
				two.style.top=p.t+p.h+"px";
				two.style.left=p.l+"px";
			}else{
				two.style.top=p.t+p.h+"px";
				two.style.left=p.l+"px"; 
			}
			document.getElementById('showgame').style.display='none';
			document.getElementById('showProduct').style.display='none';
		}
	}
	function showProduct(obj){
		var p= posi(obj);
		var two = document.getElementById('showProduct');
		if(document.getElementById('ServerNameListID').value>0)
		{
			document.getElementById('showProduct').style.display=document.getElementById('showProduct').style.display==''?'none':'';
			if(!document.all){
				two.style.top=p.t+p.h+"px";
				two.style.left=p.l+"px";
			}else{
				two.style.top=p.t+p.h+"px";
				two.style.left=p.l+"px"; 
			}
			document.getElementById('showServer').style.display='none';
			document.getElementById('showgame').style.display='none';
		}
	}
	//定位
	function posi(obj){
		var width=obj.offsetWidth;
		var height=obj.offsetHeight;
		var top=0,left=0;
		while(obj.offsetParent){
			top+=obj.offsetTop; 
			left+=obj.offsetLeft; 
			obj=obj.offsetParent;
		}
		return {"w":width,"h":height,"t":top,"l":left}
	}
	//取得游戏服务器列表组装
	function GetServerLists(GID,strs)
	{
		var divwidth=strs.lenght;
		document.getElementById('GameNameListID').value=GID;
		document.getElementById('showgame').style.display='none';
		document.getElementById('FSelectTypeIDs').value=strs.length>23?strs.substr(0,23)+'...':strs;
		document.getElementById('FSelectTypeIDs').title=strs;
		document.getElementById('txtServer').value = '---Loading...---';
		var str=ReAjax.prototype.LoadUrl2("/ajax/getServerList.cfm?gameid="+GID);
		var arrayStr=str.split("|");
		var count = 0;
		var tableStr = '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color:#FFFFFF; padding-left:4px">';
		if(arrayStr.length - 1 > 0){
			document.getElementById('txtServer').value = '--Please Select The Server--';
			document.getElementById('txtProducts').value = '--Please Select The Product--';
			document.getElementById('showProduct').innerHTML = "";
			document.getElementById('ProductNameListID').value="0";
			for(var i = 0; i<arrayStr.length - 1 ; i++){				
				var arrayName=new Array(1);
				arrayName=arrayStr[i].split("@");				
				tableStr = tableStr+'<tr><td nowrap onClick="getProductLists('+GID+','+arrayName[0]+',this.innerHTML);" onMouseOver="thiscolor(this);"onMouseOut="clearcolor(this);"style="cursor:default;color:#006699;" title="'+arrayName[1]+'">'+arrayName[1]+'</td></tr>';				
				count++;
			}
			tableStr = tableStr+ '</table>';
				document.getElementById('showServer').innerHTML = tableStr;	
			/*判断游戏数目,大于23款设置层的高度为300*/
			if(count > 23)
				document.getElementById('showServer').style.height = '300px';
			else
				document.getElementById('showServer').style.height = 'auto';
		}		
	}	
	//取得产品列表
	function getProductLists(gameid,serverid,strs){
		var divwidth=strs.lenght;
		document.getElementById('ServerNameListID').value=serverid;
		document.getElementById('showServer').style.display='none';
		document.getElementById('txtServer').value=strs.length>23?strs.substr(0,23)+'...':strs;
		document.getElementById('txtServer').title=strs;
		document.getElementById('txtProducts').value = '---Loading...---';
		var str=ReAjax.prototype.LoadUrl2("/ajax/getProductList.cfm?gameid="+gameid+"&serverid="+serverid);
		var arrayStr=str.split("|");
		var count = 0;
		var tableStr = '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color:#FFFFFF; padding-left:4px">';
		if(arrayStr.length-1>0)
		{
			document.getElementById('txtProducts').value = '--Please Select The Product--';
			for(i=0;i<arrayStr.length-1;i++)
			{
				var arrayName=new Array(1);
				arrayName=arrayStr[i].split("@");
				tableStr = tableStr+'<tr><td nowrap onClick="getProduct('+arrayName[0]+',this.innerHTML);" onMouseOver="thiscolor(this);"onMouseOut="clearcolor(this);"style="cursor:default;color:#006699;" title="'+arrayName[1]+'">'+arrayName[1]+'</td></tr>';				
				count++;
			}
			tableStr = tableStr+ '</table>';
			document.getElementById('showProduct').innerHTML = tableStr;	
			/*判断游戏数目,大于23款设置层的高度为300*/
			if(count > 23)
				document.getElementById('showProduct').style.height = '300px';
			else
				document.getElementById('showProduct').style.height = 'auto';
		}
		
	}
	function getProduct(pid,strs){
		var divwidth=strs.lenght;
		document.getElementById('ProductNameListID').value=pid;
		document.getElementById('showProduct').style.display='none';
		document.getElementById('txtProducts').value=strs.length>23?strs.substr(0,23)+'...':strs;
		document.getElementById('txtProducts').title=strs;
	}
	function checktocart(){
		if(document.getElementById('GameNameListID').value == 0)
		{alert('Please Select The Game!'); return false;}
		if(document.getElementById('ServerNameListID').value == 0)
		{alert('Please Select The Server!'); return false;}
		if(document.getElementById('ProductNameListID').value == 0)
		{alert('Please Select The Product!'); return false;}
	}
	function thiscolor(td)
	{
		td.bgColor='#004080';
		td.style.color='white';
	}
	function clearcolor(td)
	{
		td.bgColor='';
		td.style.color='#006699';
	}
