﻿var http=system_http;

function checkTheFormSubmit(){
	var checkpriceid = document.getElementById("checkpriceid").value;
	if(checkpriceid){
		return true;	
	}
	else{
		alert("Please select the product!");
		return false;
	}
}

function showGoldProduct(obj)
{
	if(document.getElementById("goldserver").innerHTML == "")
		return;

	var p= posi(obj);
	var goldproduct = document.getElementById('goldproduct');
	if(document.getElementById('goldserverid').value>0)
	{
		goldproduct.style.display=goldproduct.style.display=='block'?'none':'block';
		if(!document.all){
			goldproduct.style.top=p.t+p.h+"px";
			goldproduct.style.left=p.l+"px";
		}else{
			goldproduct.style.top=p.t+p.h+"px";
			goldproduct.style.left=p.l+"px"; 
		}
		document.getElementById('goldserver').style.display='none';
		document.getElementById('goldgame').style.display='none';
	}
}
function showGoldServer(obj)
{
	if(document.getElementById("goldserver").innerHTML == "")
		return;

	var p= posi(obj);
	var goldserver = document.getElementById('goldserver');
	if(document.getElementById('goldgameid').value>0)
	{
		goldserver.style.display=goldserver.style.display=='block'?'none':'block';
		if(!document.all){
			goldserver.style.top=p.t+p.h+"px";
			goldserver.style.left=p.l+"px";
		}else{
			goldserver.style.top=p.t+p.h+"px";
			goldserver.style.left=p.l+"px"; 
		}
		document.getElementById('goldgame').style.display='none';
		document.getElementById('goldproduct').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 showGoldGame(obj,dwidth)
{
	var p= posi(obj);	
	var goldgame = document.getElementById("goldgame");	
	goldgame.style.display=goldgame.style.display=='block' ? 'none' : 'block';	
	if(!document.all)
	{
		goldgame.style.top=p.t + p.h + "px";
		goldgame.style.left=p.l + "px";
	}
	else
	{
		goldgame.style.top = p.t + p.h + "px";
		goldgame.style.left = p.l + 1 + "px"; 
	}
	goldgame.style.width ="156px";
	goldgame.style.height="300px";
}
function limover(obj)
{
	obj.style.backgroundColor = "#000099";
	obj.style.color = "white";
}

function limout(obj)
{
	obj.style.backgroundColor = "white";
	obj.style.color = "black";
}
function sgetGoldProducts(gameid,serverid,strs)
{ 
	var divwidth=strs.length;
	document.getElementById('goldserverid').value=serverid;
	document.getElementById('goldserver').style.display='none';
	document.getElementById('txtGoldServer').value=strs.length>23?strs.substr(0,23)+'...':strs;
	document.getElementById('txtGoldServer').title=strs;
	document.getElementById('txtProduct').value = '---Loading...---';
	
	var str=ReAjax.prototype.LoadUrl2(http + "/ajax/getProductList.cfm?gameid="+gameid+"&serverid="+serverid); 
	var arrayStr = str.split("|");
	var count = 0;
	var productlist = [];
	if(arrayStr.length-1>0)
	{
		document.getElementById('txtProduct').value = '--Please Select The Product--';
		var totalWidth = 0;	
		for(i=0;i<arrayStr.length-1;i++)
		{
			var arrayName=[];
			arrayName=arrayStr[i].split("@");
			productlist.push('<li nowrap id="' + arrayName[0] + '" onClick="selectGoldProduct('+arrayName[0]+',this.innerHTML);" onMouseOver="limover(this);" onMouseOut="limout(this);" title="'+arrayName[1]+'">'+arrayName[1]+'</li>');					
			if(i == 0)
			{
				totalWidth = arrayName[1].length;
			}
			else
			{
				if(arrayName[1].length > totalWidth)
				{
					totalWidth = arrayName[1].length;
				}
			}
			count++;
		}	
		document.getElementById('goldproduct').innerHTML = productlist.join('');	
		if(totalWidth * 6 < 156)
		{
			totalWidth = 156;
		}
		else
		{
			totalWidth = totalWidth * 6;
		}
		document.getElementById("goldproduct").style.width = totalWidth + 15 + "px";
		if(count > 23)
			document.getElementById('goldproduct').style.height = '300px';
		else
			document.getElementById('goldproduct').style.height = 'auto';
	}
}
function selectGoldProduct(pid,strs)
{
	var divwidth=strs.length;
	document.getElementById('checkpriceid').value=pid;
	document.getElementById('goldproduct').style.display='none';
	document.getElementById('txtProduct').value=strs.length>23?strs.substr(0,23)+'...':strs;
	document.getElementById('txtProduct').title=strs;
}
function getGoldServer(GID,strs)
{
	var divwidth = document.getElementById("txtGame").style.width + "px"; 
	document.getElementById('goldgameid').value=GID;
	document.getElementById('goldgame').style.display='none';
	document.getElementById('txtGame').value=strs.length>23?strs.substr(0,23)+'...':strs;
	document.getElementById('txtGame').title=strs;
	document.getElementById('txtGoldServer').value = '---Loading...---';
	var str = ReAjax.prototype.LoadUrl2(http + "/ajax/getServerList.cfm?gameid="+GID); 
	var arrayStr=str.split("|");
	var count = 0;
	var serverlist = [];
	if(arrayStr.length - 1 > 0)
	{
		document.getElementById('txtGoldServer').value = '--Please Select The Server--';
		document.getElementById('txtProduct').value = '--Please Select The Product--';
		document.getElementById('goldproduct').innerHTML = "";
		document.getElementById('goldproducttagnameid').value="0"; 
  		var totalWidth = 0;
 		for(var i = 0; i<arrayStr.length - 1 ; i++)
		{				
			var arrayName=[];
			arrayName=arrayStr[i].split("@");			
			serverlist.push('<li id="' + arrayName[0] + '" onclick="sgetGoldProducts('+GID+','+arrayName[0]+',this.innerHTML);" onMouseOver="limover(this);" onMouseOut="limout(this);" title="'+arrayName[1]+'">'+arrayName[1]+'</li>');
			
			if(i == 0)
			{
				totalWidth = arrayName[1].length;
			}
			else
			{
				if(arrayName[1].length > totalWidth)
				{
					totalWidth = arrayName[1].length;
				}
			}		
			count++;
		}
		document.getElementById('goldserver').innerHTML = serverlist.join('\n');
		if(totalWidth * 6 < 156)
		{
			totalWidth = 156;
		}
		else
		{
			totalWidth = totalWidth * 6;
		}
		document.getElementById("goldserver").style.width = totalWidth + 15 + "px";
		if(count > 23)
			document.getElementById('goldserver').style.height = '300px';
		else
			document.getElementById('goldserver').style.height = 'auto';
		var opt=document.createElement("OPTION");
		opt.text="--please select--";
		opt.value="";
		var lis = document.getElementById("goldserver").getElementsByTagName("li");
	}		
}