//document.getElementById
function _(element)
{
    if (arguments.length > 1)
    {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
          elements.push($(arguments[i]));
        return elements;
    }
    else
        return document.getElementById(element);
}

//init the server list
function areaChanged(value, type)
{
	oAreaId = _('area_id');
	oServerId = _('server_id');

    var area = serverList[0];
    for (var i=0; i<serverList.length; i++)
    {
        if (serverList[i].id == value)
		{
        	area = serverList[i];
        	break;
        }
    }

    if (area)
    {
        oServerId.options.length = 0;
        for (var i=0; i<area.sub.length; i++)
        {
        	oServerId.options.add(new Option(area.sub[i].name, area.sub[i].id));
        	if ('1' == area.sub[i].id)
        		oServerId.options[i].selected = true;
        }
    }
}
//初始化服务器列表
function initServerList()
{
	try
	{
		oAreaId = _('area_id');
		oServerId = _('server_id');
		oAreaId.options.length = 0;

		for (var i=0; i<serverList.length; i++)
		{
			oAreaId.options.add(new Option(serverList[i].name,serverList[i].id));
			if ('1' == serverList[i].id)
				oAreaId.options[i].selected = true;
		}

		areaChanged(1,0);
	}
	catch(e){}
}
function changeCode()
{
	_('_code').src='index.php?do=code&'+Math.random();
}
$(function()
		   {
			   initServerList();

		   }
)
function doLogin()
{
	var account = $('#account').val();
	var pws = $('#pws').val();
	var vcode = $('#vcode').val();

	if(account =='' || account == null)
	{
		alert('Please enter your account.');
		_('account').focus();
		return;
	}
	if(pws =='' || pws == null)
	{
		alert('Please enter your password.');
		_('pws').focus();
		return;
	}
	if(vcode =='' || vcode == null)
	{
		alert('Please enter your Validate_code.');
		_('vcode').focus();
		return;
	}
	$.getJSON
	(
	 	'index.php?do=login',
		{account:account,server_id:$('#server_id').val(),pws:pws,vcode:vcode},
		function(data)
		{
			if(data['txt']=='0')
			{
				alert(data['text']);
				return;
			}
			else
			{
				alert(data['text']);
				$('#link').val(data['link']);

				window.location.href="index.php";
				return;
			}
		}
	)
}
	/**
	 * 新玩家等级排行榜
	 */
	$(function(){
		$('#top1').load("listpage.php?do=leveltop100");
	})

	function ajaxPagel(url)
	{
		$('#top1').load(url,function (data){;});
	}
	/**
	 * 玩家推广排名
	 */
	$(function(){
		$('#top2').load("listpage.php?do=top100");
	})

	function ajaxPage(url)
	{
		$('#top2').load(url,function (data){;});
	}
	/*推广玩家得到奖品的js*/
	function togetPrize_old()
	{
		$('#pop_1').load("index.php?do=oldPrizelst",function(data){scroll(1000,1000);});
		$('#pop_1').show();
	}
	function getPrize_old()
	{
		$('#lingqi').hide();
		$.getJSON
		(
		 	'index.php?do=getPrizeold',
			{p_id:$('#action').val()},
			function(data)
			{
				if(data['txt']=='0')
				{
					alert(data['text']);
					$('#lingqi').show();
					return;
				}
				else
				{
					alert(data['text']);
					$('#lingqi').show();
					$('#pop_1').load("index.php?do=oldPrizelst",function(data){scroll(1000,1000);});
					return;
				}
			}
		);
	}
	/*新注册的玩家得到奖品的js*/
	function togetPrize_new()
	{
		$('#pop_2').load("index.php?do=newPrizelst",function(data){scroll(1000,1000);});
		$('#pop_2').show();
	}
	function getPrize_new()
	{
		//$('#lingqi1').attr('disabled','disabled');
		$('#lingqi1').hide();
		$.getJSON
		(
		 	'index.php?do=getPrizenew',
			{p_id:$('#action1').val()},
			function(data)
			{
				if(data['txt']=='0')
				{
					alert(data['text']);
					$('#lingqi1').show();
					return;
				}
				else
				{
					alert(data['text']);
					$('#lingqi1').show();
					$('#pop_2').load("index.php?do=newPrizelst",function(data){scroll(1000,1000);});
					return;
				}
			}
		);
	}

	function _logout(){
	    $.post(
	        'index.php?do=Logout',
	        function(data){
	           top.location.reload();
	        }
	    )
	}