var checked = false;

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 flush(t){
	_("flash_div").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" id="sample" width="1002" height="950"><param name="wmode" value="transparent" /><param name="movie" value="resource/flash/tree.swf?treeT='+t+'"><embed swliveconnect="true" wmode="transparent" name="sample" src="resource/flash/tree.swf?treeT='+t+'" quality="high" bgcolor="#FFFFFF" width="1002" height="950" type="application/x-shockwave-flash"></embed></object>';
	//location.reload();

}

function changetext(str){ 
	if(window.sample) window.document["sample"].SetVariable("treeT", str);
	if(document.sample) document.sample.SetVariable("treeT", str);
}

function checkbaobao(ispop){
	var baobao = _('baobao_name').value;
	$.get
	(
	   'index.php?do=checkbaobao',
	   {
		baobao_name: baobao
	   },
	   function(data){ if(data!='1'){alert('抱歉,该宝宝名称已被使用,请更换.');}else if(ispop==1){alert('恭喜,该名称可用!');} } 
	);
}




function senddata(input_content,input_time,wishX,wishY,treename,wishbg)
{
	if (!input_content || input_content=='undefined') {alert('Please input your gratitude & blessing !');flush('t0');}
	else {
		_('input_content').value = input_content;
		_('input_time').value = input_time;
		_('wishX').value = wishX;
		_('wishY').value = wishY;
		_('treename').value = treename;
		_('wishbg').value = wishbg;
		$('#login').show('normal');
		$('#ok').show('normal');
	}
}

function dosubmit(){
	_('ok').style.display='none';
	$.get
	(
	   'index.php?do=submit',
	   {
		input_content: _('input_content').value,
		input_time: _('input_time').value,
		wishX: _('wishX').value,
		wishY: _('wishY').value,
		treename: _('treename').value,
		wishbg: _('wishbg').value,
		account:_('account').value,
		password:_('password').value,
		area_id:_('area_id').value,
		server_id:_('server_id').value,
		code : _('code').value
	   },
	   function(data){ if(data!='OK'){alert(data);_('ok').style.display='';}else {$('#info').show('normal');$('#login').hide('normal');flush(_('treename').value); } } 
	);
}




$(document).ready(function (){initServerList();});
function initServerList()
{

	oAreaId = _('area_id');
	oServerId = _('server_id');	
		
	if (oAreaId != null)
	{
		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);
	}
}

//init the server list
function areaChanged(value,type)
{
	if(type==2)
	{
		oAreaId = _('area_id_2');
		oServerId = _('server_id_2');
	}else{
		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 changeCode()
{
	_('code_img').src='index.php?do=code&'+Math.random();
}















