//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();
			   if($.browser.msie)
			   {
				   _('describe').attachEvent("onpropertychange",textCount);
			   }
			   else
			   {
				   _('describe').addEventListener("input",textCount,false);
			   }
		   }
)
function ajaxFileUpload()
{
	/*$("#uploading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'./upload.php?do=upload',
			secureuri:false,
			fileElementId:'fileToUpload',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						alert(data.error);
					}
				}
			},
			error: function (data, status, e)
			{
				alert('Your image can not be over 3M, and the format should be jpg,gif or tif!');
				$('#fileToUpload').val('');
			}
		}
	)	
	return false;*/
	alert('The event ended');
	return;
}
function doSubmit()
{
	/*var account = $('#account').val();
	var title = $('#title').val();
	var country = $('#country').val();
	var email = $('#email').val();
	var image = $('#fileToUpload').val();
	var describe = $('#describe').val();
	var vcode = $('#vcode').val();
	if(account=='' || account==null)
	{
		alert('Please fill out your account');
		_('account').focus();
		return;
	}
	if(title=='' || title==null)
	{
		alert('Please fill out the title');
		_('title').focus();
		return;
	}
	else if(title.length<5)
	{
		alert('The title should be at least 5 letters');
		_('title').focus();
		return;		
	}
	if(country=='' || country==null)
	{
		alert('Please input your country');
		_('country').focus();
		return;
	}
	if(email=='' || email==null)
	{
		alert('Please fill out e-mail');
		_('email').focus();
		return;
	}	
	var isMail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);
	if(!isMail)
	{
		alert('please input a valid email');
		_('email').focus();
		return;
	}
	if(describe=='' || describe==null)
	{
		alert('Please leave the description');
		_('describe').focus();
		return;
	}	
	if(vcode=='' || vcode==null)
	{
		alert('Please input valadation code');
		_('vcode').focus();
		return;
	}

	$('#mysubmit').attr('disabled','disabled');
	$.post
	(
	 	'upload.php?do=submit',
		{account:account,vcode:vcode,area_id:$('#area_id').val(),server_id:$('#server_id').val(),gender:$('#gender').val(),title:title,country:country,email:email,image:image,describe:describe},
		function(data)
		{
			eval("var data="+data+";");
			if(data['txt']=='0')
			{
				alert(data['text']);
				changeCode();
				$('#mysubmit').attr('disabled','');
				return;
			}
			else
			{
				alert('You have submitted successfully, please wait for our auditing');
				window.location.replace('showList.php');
			}
		}
	)*/
	alert('The event ended');
	return;
}
function textCount()
{
	var obj = _('describe');
	var len = 200;
	if(obj.value.length>len)
	{
		alert('You can not input over 200 letters');
		obj.value = obj.value.substring(0,len);
	}
}