﻿var $_Game="WOW";
var $_Server="";
var $_ServerType="";
var $_Level=0;
var $_Race="";
var $_Occupation="";
var $_PageIndex=1;
var $_PageSize=50;



//公用方法
function $(node_id) { return document.getElementById(node_id); }

//绑定服务器下拉框列表
function BindServer(Game)
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_ServerList(Game,BindServer_CallBack);
}
function BindServer_CallBack(Response)
{
	var dt=Response.value;
	var drp=$("drpServer");
	drp.length=0;
	drp.options[drp.options.length]=new Option("请选择服务器","");
	for(var i=0;i<dt.Rows.length;i++)
	{
		drp.options[drp.options.length]=new Option(dt.Rows[i]["Server"],dt.Rows[i]["Server"]);
	}
	return;
}

//绑定服务器类型下拉框列表
function BindServerType()
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_ServerTypeList(BindServerType_CallBack);	
}
function BindServerType_CallBack(Response)
{
	var dt=Response.value;
	var drp=$("drpServerType");
	drp.length=0;
	drp.options[drp.options.length]=new Option("请选择服务器类型","");
	for(var i=0;i<dt.Rows.length;i++)
	{
		drp.options[drp.options.length]=new Option(dt.Rows[i]["ServerType"],dt.Rows[i]["ServerType"]);
	}
	return;
}

//绑定等级下拉框列表
function BindLevel()
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_LevelList(BindLevel_CallBack);
}

function BindLevel_CallBack(Response)
{
	var dt=Response.value;
	var drp=$("drpLevel");
	drp.length=0;
	drp.options[drp.options.length]=new Option("请选择等级","0");
	for(var i=0;i<dt.Rows.length;i++)
	{
		drp.options[drp.options.length]=new Option(dt.Rows[i]["Level"],dt.Rows[i]["Level"]);
	}
	return;
}

//绑定种族下拉框列表
function BindRace()
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_RaceList(BindRace_CallBack);
}

function BindRace_CallBack(Response)
{
	var dt=Response.value;
	var drp=$("drpRace");
	drp.length=0;
	drp.options[drp.options.length]=new Option("请选择种族","");
	for(var i=0;i<dt.Rows.length;i++)
	{
		drp.options[drp.options.length]=new Option(dt.Rows[i]["Race"],dt.Rows[i]["Race"]);
	}
	return;
}

//绑定职业下拉框列表
function BindOccupation()
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_OccupationList(BindOccupation_CallBack);	
}

function BindOccupation_CallBack(Response)
{
	var dt=Response.value;
	var drp=$("drpOccupation");
	drp.length=0;
	drp.options[drp.options.length]=new Option("请选择职业","");
	for(var i=0;i<dt.Rows.length;i++)
	{
		drp.options[drp.options.length]=new Option(dt.Rows[i]["Occupation"],dt.Rows[i]["Occupation"]);
	}
	return;
}

//搜索
function Search()
{
	$_Server=$("drpServer").value;
	$_ServerType=$("drpServerType").value;
	$_Level=$("drpLevel").value;
	$_Race=$("drpRace").value;
	$_Occupation=$("drpOccupation").value;
	$_PageIndex=1; 
	BindSearchList();
}

//绑定搜索数据
function BindSearchList()
{
	www17yoocom.AccountSale.index.Web_tbAccountInfo_Search($_PageIndex,$_PageSize,$_Game,$_Server,$_ServerType,parseInt($_Level),$_Race,$_Occupation,BindSearchList_CallBack);		
}

//转到 n  页
function goPage(n)
{
	$_PageIndex=n;
	BindSearchList();
}

function BindSearchList_CallBack(Response)
{
	var result=Response.value;
	var dtList=result.Tables[0];
	var showHTML=ShowList(dtList);
	var dtPage=result.Tables[1];
	showHTML += pagestr( dtPage );
	$("divList").innerHTML=showHTML;
}

//选择游戏
function SelectGame(Game)
{
	var tabWOW=$("tabWOW");
	var tabEUWOW=$("tabEUWOW");
	if(Game=="WOW")
	{
		tabWOW.style.backgroundImage="url(images/yoo_16.gif)";
		tabEUWOW.style.backgroundImage="url(images/yoo_14.gif)";		
	}
	else
	{
		tabWOW.style.backgroundImage="url(images/yoo_14.gif)";
		tabEUWOW.style.backgroundImage="url(images/yoo_16.gif)";			
	}
	$_Game=Game;
	$("drpServer").selectedIndex=0;
	$("drpServerType").selectedIndex=0;
	$("drpLevel").selectedIndex=0;
	$("drpRace").selectedIndex=0;
	$("drpOccupation").selectedIndex=0;	
	Search();
}

//显示列表
function ShowList(dt)
{
	var str="";
	str=str+"<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
	for(var i=0;i<dt.Rows.length;i++)
	{
		str=str+"<tr>";
		str=str+"<td style='border-bottom:1px solid #CDCDCD; padding:5px 10px 5px 10px;'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		str=str+"<tr>";
		str=str+"<td width='12%' rowspan='2' align='center' valign='middle' class='dahong'>"+dt.Rows[i]["Level"]+"<br />";
		str=str+"<img src='images/yoo_39.gif' width='28' height='11' vspace='3' /></td>";
		str=str+"<td width='22%' rowspan='2' align='center' valign='middle'><img src=\"images/list/"+dt.Rows[i]["Race"]+"_"+dt.Rows[i]["Occupation"]+"_"+(dt.Rows[i]["Sex"]==0?"0":"1")+".gif\" width='38' height='39' /><br />";
		str=str+dt.Rows[i]["Race"]+" "+dt.Rows[i]["Occupation"]+"<br /></td>";
		str=str+"<td width='31%' rowspan='2' align='center' valign='middle'><img src=\"images/"+(dt.Rows[i]["Server"].indexOf("Alliance")>-1?"Alliance.gif":"Horde.gif")+"\" width='34' height='34' /><br />";
		str=str+dt.Rows[i]["Server"].replace(new RegExp("-Alliance","gi"),"").replace(new RegExp("-Horde","gi"),"")+"<br />";
		str=str+"( "+dt.Rows[i]["ServerType"]+" ) <br /></td>";
		str=str+"<td width='19%' height='21' align='center' valign='middle' class='hui' ><a href=\""+dt.Rows[i]["Url"]+"\" target='_blank'>查看装备</a><br /></td>";
		str=str+"<td width='16%' rowspan='2' align='center' valign='middle'>"+dt.Rows[i]["Price"]+"<br />";
		str=str+"<img src='images/yoo_32.gif' vspace='5' style='cursor:pointer;' onclick=\"alert('此帐号能及时交易，请马上联系我方对应客服！');\" /></td>";
		str=str+"</tr>";
		str=str+"<tr>";
		str=str+"<td height='12' align='center' valign='top'><img src='images/yoo_36.gif' width='12' height='12'/><img src='images/yoo_36.gif' width='12' height='12' /><img src='images/yoo_36.gif' width='12' height='12' /><img src='images/yoo_36.gif' width='12' height='12' /><img src='images/yoo_36.gif' width='12' height='12' /></td>";
		str=str+"</tr>";
		str=str+"</table></td>";
		str=str+"</tr>";
	}
	str=str+"</table>";
	return str;
}

//分页
function pagestr(dt)
{
	var str="<div class=\"turnPage hui\">";
	pagesize=parseInt(dt.Rows[0].PageSize);
	var recordcount=parseInt(dt.Rows[0].RecordCount);
	if(recordcount==0) return "";	
	pageindex=parseInt(dt.Rows[0].PageIndex);
	$_PageIndex=pageindex;
	var pagecount=parseInt(dt.Rows[0].PageCount);

	var startpage=parseInt((pageindex-1)/5)*5+1;
	var endpage=startpage+4;
	endpage=endpage>pagecount?pagecount:endpage;

	str=str+"一共<strong>"+recordcount+"</strong>条记录，<strong>"+pageindex+"</strong>/"+pagecount+"页 ";
	
	if(pagecount>1)
	{	
		str=str+"<a href=\"javascript:goPage(1);\"><strong>首页</strong></a> ";
		if(pageindex>1)
		{
			t=parseInt(pageindex)-1;
			str=str+"<a href=\"javascript:goPage("+t+");\"><strong>上一页</strong></a> ";
		}
		for(i=startpage;i<=endpage;i++)
		{
			if(pageindex==i)
			{
				str=str+"[<strong>"+i+"</strong>] ";
			}
			else
			{
				str=str+"[<a href=\"javascript:goPage("+i+");\">"+i+"</a>] ";
			}
		}
		if(pageindex<pagecount)
		{
			t=pageindex+1;
			str=str+"<a href=\"javascript:goPage("+t+");\"><strong>下一页</strong></a> ";
		}
		str=str+"<a href=\"javascript:goPage("+pagecount+");\"><strong>尾页</strong></a>";
	}
	str+="</div>";
	return str;
}


function init()
{
	BindServer($_Game);
	BindServerType();
	BindLevel();
	BindRace();
	BindOccupation();
	SelectGame($_Game);
}

init();