
var width = document.body.scrollWidth/2-100;
var height = document.body.scrollHeight/2-150;
var vote_id;
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);
}
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(){
	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);
})

function showDiv(id,vid)
{
    
	//$('#hid').val(id);
	vote_id = vid;
	//$('#bg').width(document.body.scrollWidth).height(document.body.scrollHeight).css('opacity','0.3').show();
	$('#showaccount').fadeIn();
	//$('#vcode').val('');
	changeCode();
}
function checkinput()
{
	var account = $('#account').val();
	var area_id = $('#area_id').val();
	//var area = $("select[@name='area_id'] option[@selected]").text();
	var server_id = $('#server_id').val();
	//var server = $("select[@name='server_id'] option[@selected]").text();
	var code = $('#code').val();
	var id = $('#hid').val();
	if(account == '' || account == null){
		alert('Please input your Account ID');
		_('account').focus();
		return;
	}
	if(code == '' || code == null){
		alert('Please input validation code');
		_('code').focus();
		return;		
	}
	$.post(
		'?do=vote',
		{
            account:account,
            server_id:server_id,
            area_id:area_id,
            vote_id:vote_id,
            code:code
        },
		function(data)
		{
			if(data == 'ok'){
                _('account').value='';
                alert("Vote successfully!");
                top.location.reload();
            }else{
                alert(data);
                try
                {
                    _('_code').value = '';
                    _('_code').src='index.php?do=code&'+Math.random();                    
                }catch(e){}
            }
		}
	)
}
function closeDiv()
{
    _('account').value='';
    _('_code').value = '';
	$('#showaccount').hide();
	//$('#bg').fadeOut();
}
function goPage(id)
{
	location.href='page.php?id='+id;
}
function changeCode()
{
	_('_code').src='index.php?do=code&'+Math.random();
}

function dosearch(){
 
    return true;
}

